@selvajs/selva 4.21.0-beta.24 → 4.21.0-beta.26

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.
Files changed (83) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/assets/0.Ct4dsf2W.css +2 -0
  3. package/build/client/_app/immutable/assets/0.Ct4dsf2W.css.br +0 -0
  4. package/build/client/_app/immutable/assets/0.Ct4dsf2W.css.gz +0 -0
  5. package/build/client/_app/immutable/chunks/BUxAHI7i.js +1 -0
  6. package/build/client/_app/immutable/chunks/BUxAHI7i.js.br +1 -0
  7. package/build/client/_app/immutable/chunks/BUxAHI7i.js.gz +0 -0
  8. package/build/client/_app/immutable/chunks/C4PDTpD1.js +6085 -0
  9. package/build/client/_app/immutable/chunks/C4PDTpD1.js.br +0 -0
  10. package/build/client/_app/immutable/chunks/C4PDTpD1.js.gz +0 -0
  11. package/build/client/_app/immutable/entry/{app.Dl3HM1mx.js → app.Bqmne5hV.js} +2 -2
  12. package/build/client/_app/immutable/entry/app.Bqmne5hV.js.br +0 -0
  13. package/build/client/_app/immutable/entry/app.Bqmne5hV.js.gz +0 -0
  14. package/build/client/_app/immutable/nodes/21.Dv262ba8.js +1 -0
  15. package/build/client/_app/immutable/nodes/21.Dv262ba8.js.br +1 -0
  16. package/build/client/_app/immutable/nodes/21.Dv262ba8.js.gz +0 -0
  17. package/build/client/_app/version.json +1 -1
  18. package/build/client/_app/version.json.br +0 -0
  19. package/build/client/_app/version.json.gz +0 -0
  20. package/build/runtime-meta.json +1 -1
  21. package/build/server/.vite/manifest.json +24 -21
  22. package/build/server/_app/immutable/assets/_layout.Ct4dsf2W.css +2 -0
  23. package/build/server/chunks/capture.js +1 -1
  24. package/build/server/chunks/compute-profile-D3g1Tuyd.js +92 -0
  25. package/build/server/chunks/compute-profile-D3g1Tuyd.js.map +1 -0
  26. package/build/server/chunks/compute.js +1 -1
  27. package/build/server/chunks/engine.server.js +1 -1
  28. package/build/server/chunks/errors.js +7 -30
  29. package/build/server/chunks/errors.js.map +1 -1
  30. package/build/server/chunks/grasshopper.js +6 -1
  31. package/build/server/chunks/grasshopper.js.map +1 -1
  32. package/build/server/chunks/handlers.js +5 -4
  33. package/build/server/chunks/handlers.js.map +1 -1
  34. package/build/server/chunks/instance.js +3 -3
  35. package/build/server/chunks/internal.js +1 -1
  36. package/build/server/chunks/ops.js +1 -1
  37. package/build/server/chunks/package.js +1 -1
  38. package/build/server/chunks/package.js.map +1 -1
  39. package/build/server/chunks/providers.server.js +48 -15
  40. package/build/server/chunks/providers.server.js.map +1 -1
  41. package/build/server/chunks/{limits.js → saved-values.js} +35 -2
  42. package/build/server/chunks/saved-values.js.map +1 -0
  43. package/build/server/chunks/server.js +134 -17
  44. package/build/server/chunks/server.js.map +1 -1
  45. package/build/server/chunks/solve.js +1 -1
  46. package/build/server/chunks/solve.server.js +8 -3
  47. package/build/server/chunks/solve.server.js.map +1 -1
  48. package/build/server/chunks/types2.js.map +1 -1
  49. package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +1 -1
  50. package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +5 -2
  51. package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js.map +1 -1
  52. package/build/server/entries/endpoints/api/v1/solves/_solveId_/_server.ts.js +1 -1
  53. package/build/server/entries/pages/library/_guid_/_page.server.ts.js +14 -3
  54. package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
  55. package/build/server/entries/pages/library/_guid_/_page.svelte.js +164 -38
  56. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  57. package/build/server/manifest-full.js +1 -1
  58. package/build/server/manifest.js +1 -1
  59. package/build/server/nodes/0.js +2 -2
  60. package/build/server/nodes/21.js +1 -1
  61. package/build/server/server.js +1 -1
  62. package/package.json +11 -11
  63. package/build/client/_app/immutable/assets/0.DOeouCe4.css +0 -2
  64. package/build/client/_app/immutable/assets/0.DOeouCe4.css.br +0 -0
  65. package/build/client/_app/immutable/assets/0.DOeouCe4.css.gz +0 -0
  66. package/build/client/_app/immutable/chunks/B58dPMPq.js +0 -1
  67. package/build/client/_app/immutable/chunks/B58dPMPq.js.br +0 -1
  68. package/build/client/_app/immutable/chunks/B58dPMPq.js.gz +0 -0
  69. package/build/client/_app/immutable/chunks/DtmN00GS.js +0 -6085
  70. package/build/client/_app/immutable/chunks/DtmN00GS.js.br +0 -0
  71. package/build/client/_app/immutable/chunks/DtmN00GS.js.gz +0 -0
  72. package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.br +0 -0
  73. package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.gz +0 -0
  74. package/build/client/_app/immutable/nodes/21.BZJQikE5.js +0 -1
  75. package/build/client/_app/immutable/nodes/21.BZJQikE5.js.br +0 -0
  76. package/build/client/_app/immutable/nodes/21.BZJQikE5.js.gz +0 -0
  77. package/build/server/_app/immutable/assets/_layout.DOeouCe4.css +0 -2
  78. package/build/server/chunks/async-solve-Doflh4BJ.js +0 -27
  79. package/build/server/chunks/async-solve-Doflh4BJ.js.map +0 -1
  80. package/build/server/chunks/limits.js.map +0 -1
  81. /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js → 0.BsaBi01M.js} +0 -0
  82. /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js.br → 0.BsaBi01M.js.br} +0 -0
  83. /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js.gz → 0.BsaBi01M.js.gz} +0 -0
@@ -2,7 +2,7 @@ import { a as isDynamicValueListWidget, c as isTextWidget, i as isDropdownWidget
2
2
  import { n as getInputItems, r as getLayoutItems, t as getGroups } from "../../../../chunks/traversal.js";
3
3
  import { n as keepHiddenPicks, r as withRowPick, t as buildFormModel } from "../../../../chunks/dynamic-value-list.js";
4
4
  import { _ as subFolderSegments, m as downloadFileDataByRoot, p as decodeBase64ToBinary$1, r as GrasshopperResponseProcessor } from "../../../../chunks/grasshopper.js";
5
- import { a as serverSourcedInputIds, i as raceAbort, r as KEEPALIVE_PREFERENCE, t as ASYNC_PREFERENCE } from "../../../../chunks/async-solve-Doflh4BJ.js";
5
+ import { a as raceAbort, d as isDisplayItemType$1, f as readFrame, i as KEEPALIVE_PREFERENCE, n as COMPUTE_PROFILE_HEADER, o as serverSourcedInputIds, s as BINARY_SOLVE_MEDIA_TYPE, t as ASYNC_PREFERENCE, u as isBlobRef } from "../../../../chunks/compute-profile-D3g1Tuyd.js";
6
6
  import { i as outcomeFromComputeMessages, n as decodeOutcome, r as finalizeResult, t as decodeDiagnostic } from "../../../../chunks/outcome-D28FgvFK.js";
7
7
  import { Ft as run, Lt as escape_html, Ot as attr, _ as setContext, a as derived, d as spread_props, f as stringify, h as getContext, i as bind_props, kt as clsx$1, l as props_id, n as attr_style, o as element$1, ot as snapshot, p as html, r as attributes, s as ensure_array_like, t as attr_class } from "../../../../chunks/server4.js";
8
8
  import { c as watch$1, s as Context, t as FOOTER_CONTEXT_KEY } from "../../../../chunks/footerContext.svelte.js";
@@ -5831,29 +5831,34 @@ function CalculateButton($$renderer, $$props) {
5831
5831
  $$renderer.component(($$renderer) => {
5832
5832
  const locale = getLocaleContext();
5833
5833
  const t = derived(() => locale.messages);
5834
+ /** While set, the button is disabled and shows this instead: the app is not ready to solve. */
5834
5835
  /** Beside the button, sharing its row: the panel footer's actions menu. */
5835
- let { hasPendingChanges, hasNeverSolved = false, isSolving, oncalculate, trailing } = $$props;
5836
+ let { hasPendingChanges, hasNeverSolved = false, isSolving, hold, oncalculate, trailing } = $$props;
5836
5837
  $$renderer.push(`<div class="bottom-0 mt-3 pb-3 pt-2 backdrop-blur-sm px-2 sticky border-t border-border"><span class="sr-only" role="status" aria-live="polite">${escape_html("")}</span> <div class="gap-2 flex">`);
5837
5838
  Button($$renderer, {
5838
5839
  variant: hasPendingChanges ? "default" : "ghost",
5839
5840
  size: "lg",
5840
- onclick: () => !isSolving && oncalculate(),
5841
- disabled: !hasPendingChanges && !isSolving,
5841
+ onclick: () => !isSolving && !hold && oncalculate(),
5842
+ disabled: !!hold || !hasPendingChanges && !isSolving,
5842
5843
  "aria-busy": isSolving,
5843
5844
  class: `gap-2 font-medium min-w-0 flex-1 transition-all duration-200
5844
5845
  ${hasPendingChanges && !isSolving ? "shadow-md" : ""}
5845
5846
  ${!hasPendingChanges && !isSolving ? "text-muted-foreground" : ""}`,
5846
5847
  children: ($$renderer) => {
5847
- if (isSolving) {
5848
+ if (hold && !isSolving) {
5848
5849
  $$renderer.push("<!--[0-->");
5849
5850
  Loader_circle($$renderer, { class: "h-4 w-4 animate-spin" });
5851
+ $$renderer.push(`<!----> ${escape_html(hold)}`);
5852
+ } else if (isSolving) {
5853
+ $$renderer.push("<!--[1-->");
5854
+ Loader_circle($$renderer, { class: "h-4 w-4 animate-spin" });
5850
5855
  $$renderer.push(`<!----> ${escape_html(t().solvingEllipsis)} <kbd class="px-1 rounded-sm border border-current/30 font-sans text-2xs opacity-70"${attr("title", t().solveMessagesEscHint)}>Esc</kbd>`);
5851
5856
  } else if (hasNeverSolved) {
5852
- $$renderer.push("<!--[1-->");
5857
+ $$renderer.push("<!--[2-->");
5853
5858
  Play($$renderer, { class: "h-4 w-4" });
5854
5859
  $$renderer.push(`<!----> ${escape_html(t().pressToCalculate)}`);
5855
5860
  } else if (hasPendingChanges) {
5856
- $$renderer.push("<!--[2-->");
5861
+ $$renderer.push("<!--[3-->");
5857
5862
  Zap($$renderer, { class: "h-4 w-4" });
5858
5863
  $$renderer.push(`<!----> ${escape_html(t().calculate)}`);
5859
5864
  } else $$renderer.push(`<!--[-1--><span class="size-1.5 shrink-0 rounded-full bg-success" aria-hidden="true"></span> ${escape_html(t().upToDate)}`);
@@ -11582,10 +11587,17 @@ function finishGeometry(geometry, members) {
11582
11587
  const tangents = creased.uvs ? grainTangents(creased.positions, creased.normals, creased.indices, creased.uvs) : null;
11583
11588
  return {
11584
11589
  ...creased,
11590
+ normals: packNormals(creased.normals),
11585
11591
  closed,
11586
11592
  tangents
11587
11593
  };
11588
11594
  }
11595
+ /** Self-contained: stringified into the assembly worker. */
11596
+ function packNormals(normals) {
11597
+ const packed = new Int16Array(normals.length);
11598
+ for (let i = 0; i < normals.length; i++) packed[i] = Math.round(normals[i] * 32767);
11599
+ return packed;
11600
+ }
11589
11601
  function assembleGeometries(input) {
11590
11602
  const { isFloat32, deltaEncoded, planarByteSplit, uint16Indices, origin, scale, uvs, colors, jobs } = input;
11591
11603
  const unzigzag = (zz) => zz >>> 1 ^ -(zz & 1);
@@ -11732,6 +11744,7 @@ function meshAssemblyWorkerSource() {
11732
11744
  `const isClosedSolid = ${isClosedSolid.toString()};`,
11733
11745
  `const splitCreases = ${splitCreases.toString()};`,
11734
11746
  `const grainTangents = ${grainTangents.toString()};`,
11747
+ `const packNormals = ${packNormals.toString()};`,
11735
11748
  `self.onmessage = (event) => {`,
11736
11749
  ` const { id, input } = event.data;`,
11737
11750
  ` try {`,
@@ -11743,7 +11756,7 @@ function meshAssemblyWorkerSource() {
11743
11756
  ` : isClosedSolid(g.positions, g.indices, windows.map((w) => w.indexCount));`,
11744
11757
  ` const c = splitCreases(g.positions, g.indices, g.uvs, g.colors);`,
11745
11758
  ` const tangents = c.uvs ? grainTangents(c.positions, c.normals, c.indices, c.uvs) : null;`,
11746
- ` return { ...c, closed, tangents };`,
11759
+ ` return { ...c, normals: packNormals(c.normals), closed, tangents };`,
11747
11760
  ` });`,
11748
11761
  ` const transfer = [];`,
11749
11762
  ` for (const g of geometries) {`,
@@ -12543,7 +12556,7 @@ function createMergedMesh(group, allVertices, allIndices, pickMaterial, allUvs =
12543
12556
  function geometryFrom(finished) {
12544
12557
  const geometry = new THREE.BufferGeometry();
12545
12558
  geometry.setAttribute("position", new THREE.BufferAttribute(finished.positions, 3));
12546
- geometry.setAttribute("normal", new THREE.BufferAttribute(finished.normals, 3));
12559
+ geometry.setAttribute("normal", new THREE.BufferAttribute(finished.normals, 3, true));
12547
12560
  geometry.setIndex(new THREE.BufferAttribute(finished.indices, 1));
12548
12561
  if (finished.uvs) geometry.setAttribute("uv", new THREE.BufferAttribute(finished.uvs, 2));
12549
12562
  if (finished.tangents) geometry.setAttribute("tangent", new THREE.BufferAttribute(finished.tangents, 4));
@@ -12767,7 +12780,7 @@ async function parseMeshBatchObject(batch, options, telemetry) {
12767
12780
  parseTime,
12768
12781
  decodeTime: performance.now() - decodeStart,
12769
12782
  perfStart,
12770
- blobBytes: debug ? approximateBase64DecodedBytes(batch.compressedData) : 0,
12783
+ blobBytes: !debug ? 0 : typeof batch.compressedData === "string" ? approximateBase64DecodedBytes(batch.compressedData) : batch.compressedData.byteLength,
12771
12784
  fallback: {
12772
12785
  materials: batch.materials,
12773
12786
  groups: batch.groups
@@ -13050,6 +13063,9 @@ var SCALE_FACTORS = {
13050
13063
  var DISPLAY_COMPONENT_TYPE = "Display";
13051
13064
  var DISPLAY_BATCH_TYPE = "DisplayBatch";
13052
13065
  /**
13066
+ * Must match `isDisplayItemType` in `@selvajs/solve/shared`, which picks the batches a binary
13067
+ * response carries as raw bytes.
13068
+ *
13053
13069
  * True when a wire `type` denotes a Display payload: one of its dot-separated tokens is exactly
13054
13070
  * `Display` or `DisplayBatch`. Matches the bare `Display` used by older servers and the namespaced
13055
13071
  * `Selva.GH.Features.Display.Services.DisplayBatch`, but not e.g. `System.DisplayText` — matching
@@ -13082,7 +13098,7 @@ async function getThreeObjectsFromComputeResponse(data, options) {
13082
13098
  handleError(error, objects);
13083
13099
  throw error;
13084
13100
  } finally {
13085
- if (debug) logProcessingTime(startTime);
13101
+ if (debug) logProcessingTime(startTime, objects);
13086
13102
  }
13087
13103
  }
13088
13104
  /**
@@ -13157,9 +13173,26 @@ function handleError(error, meshes) {
13157
13173
  function disposeMeshes(meshes) {
13158
13174
  for (const mesh of meshes) disposeObjectTree(mesh);
13159
13175
  }
13160
- function logProcessingTime(startTime) {
13176
+ /** Time plus what the result costs to hold: the same bytes again on the GPU once uploaded. */
13177
+ function logProcessingTime(startTime, objects) {
13161
13178
  const elapsed = performance.now() - startTime;
13162
- getLogger().info("Time to process meshes:", `${elapsed.toFixed(2)}ms`);
13179
+ let triangles = 0;
13180
+ let vertices = 0;
13181
+ let bytes = 0;
13182
+ const seen = /* @__PURE__ */ new Set();
13183
+ for (const root of objects) root.traverse((object) => {
13184
+ const geometry = object.geometry;
13185
+ if (!geometry?.isBufferGeometry || seen.has(geometry)) return;
13186
+ seen.add(geometry);
13187
+ const position = geometry.getAttribute("position");
13188
+ if (!position) return;
13189
+ vertices += position.count;
13190
+ if (object.isMesh) triangles += (geometry.index ? geometry.index.count : position.count) / 3;
13191
+ for (const attribute of Object.values(geometry.attributes)) bytes += attribute.array.byteLength;
13192
+ if (geometry.index) bytes += geometry.index.array.byteLength;
13193
+ });
13194
+ const mb = (bytes / 1048576).toFixed(1);
13195
+ getLogger().info(`Time to process meshes: ${elapsed.toFixed(2)}ms | ${triangles.toLocaleString("en")} triangles, ${vertices.toLocaleString("en")} vertices, ${mb} MB of geometry`);
13163
13196
  }
13164
13197
  // ../ui/src/lib/components/viewer/ViewerDock.svelte
13165
13198
  function ViewerDock($$renderer, $$props) {
@@ -14426,6 +14459,8 @@ function createSolveSession(args) {
14426
14459
  let lastDispatched = null;
14427
14460
  const state = createInitialState(currentSchema, args.scopeKey, readExternalValue);
14428
14461
  let disposed = false;
14462
+ let held = false;
14463
+ let dispatchHeld = false;
14429
14464
  const listeners = /* @__PURE__ */ new Set();
14430
14465
  const emit = () => notifyAll(listeners, void 0);
14431
14466
  const driverSolveFiles = args.driver.solveFiles;
@@ -14503,6 +14538,10 @@ function createSolveSession(args) {
14503
14538
  }
14504
14539
  function dispatch() {
14505
14540
  if (disposed) return;
14541
+ if (held) {
14542
+ dispatchHeld = true;
14543
+ return emit();
14544
+ }
14506
14545
  dropHeld();
14507
14546
  lastSent = { ...pickInputValues(currentSchema, state.values) };
14508
14547
  lastDispatched = lastSent;
@@ -14589,6 +14628,10 @@ function createSolveSession(args) {
14589
14628
  },
14590
14629
  solve,
14591
14630
  ensureSolved() {
14631
+ if (held) {
14632
+ dispatchHeld = true;
14633
+ return nextSettlement();
14634
+ }
14592
14635
  const busy = args.driver.isSolving || args.driver.hasQueued === true;
14593
14636
  const step = ensureSolvedStep(state, busy);
14594
14637
  if (step === "wait") return nextSettlement();
@@ -14603,6 +14646,13 @@ function createSolveSession(args) {
14603
14646
  diagnostics: state.diagnostics
14604
14647
  });
14605
14648
  },
14649
+ hold(on) {
14650
+ if (held === on) return;
14651
+ held = on;
14652
+ if (on || !dispatchHeld) return;
14653
+ dispatchHeld = false;
14654
+ dispatch();
14655
+ },
14606
14656
  onSettled(listener) {
14607
14657
  settledListeners.add(listener);
14608
14658
  return () => settledListeners.delete(listener);
@@ -14615,6 +14665,7 @@ function createSolveSession(args) {
14615
14665
  if (disposed) return;
14616
14666
  abandon();
14617
14667
  currentSchema = schema;
14668
+ dispatchHeld = false;
14618
14669
  lastSent = null;
14619
14670
  lastDispatched = null;
14620
14671
  args.driver.reset?.();
@@ -15015,7 +15066,8 @@ function parseServerTiming(header) {
15015
15066
  *
15016
15067
  * `compute` is the whole call to Rhino.Compute. A server that reports its own timing splits it
15017
15068
  * into `solve` (of which `grasshopper` is the definition running), `decode`, `encode`, and
15018
- * `queue+link`: the rest, network plus the wait for a free worker. `prep` is what the app did
15069
+ * `queue+link`: the rest, network plus the wait for a free worker, which the fork's proxy reports
15070
+ * on its own. `prep` is what the app did
15019
15071
  * before the solve, slowest step first, steps under 1 ms left out.
15020
15072
  */
15021
15073
  function describeServerTiming(header) {
@@ -15025,7 +15077,7 @@ function describeServerTiming(header) {
15025
15077
  let compute = `compute ${ms(t.solve)}`;
15026
15078
  if (t.rhino_solve !== void 0) {
15027
15079
  const grasshopper = t.rhino_gh === void 0 ? "" : ` (grasshopper ${ms(t.rhino_gh)})`;
15028
- compute += `: solve ${ms(t.rhino_solve)}${grasshopper}, decode ${ms(t.rhino_decode)}, encode ${ms(t.rhino_encode)}, queue+link ${ms(t.compute_link)}`;
15080
+ compute += `: solve ${ms(t.rhino_solve)}${grasshopper}, decode ${ms(t.rhino_decode)}, encode ${ms(t.rhino_encode)}, queue+link ${ms(t.compute_link)}` + (t.rhino_wait === void 0 ? "" : ` (waiting for a free child ${ms(t.rhino_wait)})`);
15029
15081
  }
15030
15082
  const parts = [compute];
15031
15083
  const prep = Object.entries(t).filter(([name]) => name.startsWith("p_"));
@@ -15040,6 +15092,60 @@ function describeServerTiming(header) {
15040
15092
  return parts.join(" | ");
15041
15093
  }
15042
15094
  /**
15095
+ * The `X-Compute-Profile` header as one log line, slowest first. Null without one. Entries that
15096
+ * aren't `{ name, ms }` are dropped: a proxy can send anything, and a debug line must not fail a solve.
15097
+ */
15098
+ function describeComputeProfile(header) {
15099
+ if (!header) return null;
15100
+ let entries;
15101
+ try {
15102
+ entries = JSON.parse(header);
15103
+ } catch {
15104
+ return null;
15105
+ }
15106
+ if (!Array.isArray(entries)) return null;
15107
+ const valid = entries.filter((e) => typeof e === "object" && e !== null && typeof e.name === "string" && typeof e.ms === "number");
15108
+ if (valid.length === 0) return null;
15109
+ return valid.map((e) => typeof e.nick === "string" && e.nick && e.nick !== e.name ? `${e.name} "${e.nick}" ${e.ms}` : `${e.name} ${e.ms}`).join(", ");
15110
+ }
15111
+ /** Null where the browser can't gunzip the JSON section, so the client must not ask for binary. */
15112
+ var BINARY_ACCEPT_HEADER = typeof DecompressionStream === "undefined" ? null : `${BINARY_SOLVE_MEDIA_TYPE}, application/json;q=0.9`;
15113
+ function isBinarySolveResponse(res) {
15114
+ return (res.headers.get("Content-Type") ?? "").startsWith(BINARY_SOLVE_MEDIA_TYPE);
15115
+ }
15116
+ /**
15117
+ * The response JSON with each display item's `data` parsed into its batch object, its
15118
+ * `compressedData` the blob's bytes. The blobs are views over `bytes`, so they keep it alive.
15119
+ */
15120
+ async function decodeBinarySolveResponse(bytes) {
15121
+ const { flags, json, blobs } = readFrame(bytes);
15122
+ const jsonBytes = flags & 1 ? await gunzip(json) : json;
15123
+ const parsed = JSON.parse(new TextDecoder().decode(jsonBytes));
15124
+ const values = parsed?.values;
15125
+ if (!Array.isArray(values)) return parsed;
15126
+ for (const value of values) for (const tree of [value?.InnerTree, value?.innerTree]) {
15127
+ if (!tree || typeof tree !== "object") continue;
15128
+ for (const branch of Object.values(tree)) if (Array.isArray(branch)) for (const item of branch) attachBlob(item, blobs);
15129
+ }
15130
+ return parsed;
15131
+ }
15132
+ function attachBlob(item, blobs) {
15133
+ const display = item;
15134
+ if (typeof display?.type !== "string" || typeof display.data !== "string") return;
15135
+ if (!isDisplayItemType$1(display.type)) return;
15136
+ const batch = JSON.parse(display.data);
15137
+ if (isBlobRef(batch.compressedData)) {
15138
+ const blob = blobs[batch.compressedData.$blob];
15139
+ if (!blob) throw new Error("Malformed binary solve response: a batch names a missing blob");
15140
+ batch.compressedData = blob;
15141
+ }
15142
+ display.data = batch;
15143
+ }
15144
+ async function gunzip(bytes) {
15145
+ const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("gzip"));
15146
+ return new Uint8Array(await new Response(stream).arrayBuffer());
15147
+ }
15148
+ /**
15043
15149
  * A ready-made `SolveFn` that POSTs to a `/api/compute`-shaped endpoint (the wire contract
15044
15150
  * `SolveEngine` produces) and unpacks the result, with 429 cooldown, session-expiry detection,
15045
15151
  * a bad-response guard, and abort handling at every await.
@@ -15048,6 +15154,12 @@ function describeServerTiming(header) {
15048
15154
  * consumer supplies `meshes.extract` (typically `getThreeObjectsFromComputeResponse` from
15049
15155
  * `@selvajs/visualization/parse`).
15050
15156
  */
15157
+ /** Said once a page: the same Compute server stays silent on every solve. */
15158
+ var warnedNoRhinoTiming = false;
15159
+ function formatBytes(bytes) {
15160
+ if (bytes >= 1048576) return `${(bytes / 1048576).toFixed(1)} MB`;
15161
+ return `${(bytes / 1024).toFixed(0)} KB`;
15162
+ }
15051
15163
  /** Applied to a 429 that names no wait. */
15052
15164
  var DEFAULT_RETRY_AFTER_S = 5;
15053
15165
  /** A server's hint, not a lock: past this the client tries again anyway. */
@@ -15156,6 +15268,7 @@ function createComputeFetchSolveFn(opts) {
15156
15268
  method: "POST",
15157
15269
  headers: {
15158
15270
  "Content-Type": "application/json",
15271
+ ...opts.meshes && BINARY_ACCEPT_HEADER ? { Accept: BINARY_ACCEPT_HEADER } : {},
15159
15272
  ...auth,
15160
15273
  ...prefer ? { Prefer: prefer } : {}
15161
15274
  },
@@ -15219,10 +15332,11 @@ function createComputeFetchSolveFn(opts) {
15219
15332
  });
15220
15333
  }
15221
15334
  const ttfbMs = performance.now() - solveStart;
15335
+ const binary = isBinarySolveResponse(res);
15222
15336
  const downloadStart = performance.now();
15223
- let bodyText;
15337
+ let body;
15224
15338
  try {
15225
- bodyText = await res.text();
15339
+ body = binary ? new Uint8Array(await res.arrayBuffer()) : await res.text();
15226
15340
  } catch (err) {
15227
15341
  if (signal.aborted) {
15228
15342
  log("[Compute] solve aborted mid-download — empty result discarded");
@@ -15231,23 +15345,27 @@ function createComputeFetchSolveFn(opts) {
15231
15345
  throw new Error("The connection dropped while receiving the result. Please try again.", { cause: err });
15232
15346
  }
15233
15347
  const downloadMs = performance.now() - downloadStart;
15234
- const bodyChars = bodyText.length;
15348
+ const wireBytes = typeof body === "string" ? Number(res.headers.get("Content-Length")) || null : body.byteLength;
15235
15349
  const invalidResponse = (cause) => new Error("Received an invalid response from the server. Reload the page and try again.", { cause });
15350
+ const parseStart = performance.now();
15236
15351
  let parsed;
15237
15352
  try {
15238
- parsed = JSON.parse(bodyText);
15353
+ parsed = typeof body === "string" ? JSON.parse(body) : await decodeBinarySolveResponse(body);
15239
15354
  } catch (err) {
15240
15355
  throw invalidResponse(err);
15241
15356
  }
15357
+ const parseMs = performance.now() - parseStart;
15242
15358
  if (!isPlainObject(parsed)) throw invalidResponse();
15243
15359
  const solved = parsed;
15244
15360
  const processor = new GrasshopperResponseProcessor(solved);
15245
15361
  const outcome = decodeOutcome(solved.selva?.outcome) ?? outcomeFromComputeMessages(solved.errors ?? [], solved.warnings ?? []);
15246
15362
  const rejected = outcome.blocked || outcome.aborted;
15363
+ const meshesStart = performance.now();
15247
15364
  const meshes = opts.meshes && !rejected && !call.skipMeshes ? await opts.meshes.extract(processor.response, {
15248
15365
  debug,
15249
15366
  signal
15250
15367
  }) : [];
15368
+ const meshesMs = performance.now() - meshesStart;
15251
15369
  const resultOutputs = {};
15252
15370
  for (const o of rejected ? [] : outputs) {
15253
15371
  const byId = processor.getValue({ byId: o.id }, { parseValues: true });
@@ -15259,18 +15377,25 @@ function createComputeFetchSolveFn(opts) {
15259
15377
  const serverTiming = parseServerTiming(timingHeader);
15260
15378
  const serverTotal = serverTiming.total ?? 0;
15261
15379
  const networkMs = Math.max(0, ttfbMs - serverTotal);
15262
- const sizeMB = bodyChars / 1048576;
15263
- const size = sizeMB >= 1 ? `${sizeMB.toFixed(2)} MB` : `${(bodyChars / 1024).toFixed(0)} KB`;
15264
- const mbps = downloadMs > 0 ? (sizeMB / (downloadMs / 1e3)).toFixed(1) : "∞";
15265
15380
  const heapBytes = performance.memory?.usedJSHeapSize;
15266
- const heap = heapBytes !== void 0 ? ` | heap=${(heapBytes / 1048576).toFixed(0)} MB` : "";
15267
- log(`[Compute] req=${(payload.length / 1024).toFixed(0)}KB (values ${(valuesBytes / 1024).toFixed(0)}KB) | ttfb=${ttfbMs.toFixed(0)}ms (network≈${networkMs.toFixed(0)} + server ${serverTotal.toFixed(0)}) | download=${downloadMs.toFixed(0)}ms (${size} @ ${mbps} MB/s)${heap}`);
15381
+ const heap = heapBytes !== void 0 ? ` | heap=${formatBytes(heapBytes)}` : "";
15382
+ log(`[Compute] req=${formatBytes(payload.length)} (values ${formatBytes(valuesBytes)}) | ttfb=${ttfbMs.toFixed(0)}ms (network≈${networkMs.toFixed(0)} + server ${serverTotal.toFixed(0)})${heap}`);
15268
15383
  const breakdown = describeServerTiming(timingHeader);
15269
15384
  if (breakdown) log(`[Compute] └─ server: ${breakdown}`);
15385
+ const slowest = describeComputeProfile(res.headers.get(COMPUTE_PROFILE_HEADER));
15386
+ if (slowest) log(`[Compute] └─ slowest components (ms): ${slowest}`);
15270
15387
  if (serverTiming.selva_cache !== void 0) {
15271
15388
  const cacheMsg = serverTiming.selva_cache ? "HIT — served without calling compute" : serverTiming.rhino_cache ? "HIT — Rhino.Compute's result cache, solved nothing" : "miss — solved on Rhino.Compute";
15272
15389
  log(`[Compute] └─ cache: ${cacheMsg}`);
15273
15390
  }
15391
+ if (!serverTiming.selva_cache && (serverTiming.solve ?? 0) > 0 && serverTiming.rhino_solve === void 0 && !warnedNoRhinoTiming) {
15392
+ warnedNoRhinoTiming = true;
15393
+ log("[Compute] └─ note: Rhino.Compute sent no timing of its own, so `compute` above is Grasshopper, definition load and queue wait together. A recent VektorNode fork sends it, with the slowest components.");
15394
+ }
15395
+ const bodyBytes = typeof body === "string" ? new TextEncoder().encode(body).byteLength : body.byteLength;
15396
+ const wire = wireBytes === null ? `${formatBytes(bodyBytes)} ${binary ? "binary" : "json"}` : `${formatBytes(wireBytes)} ${binary ? "binary" : "json"} on the wire` + (binary ? "" : `, ${formatBytes(bodyBytes)} unpacked`);
15397
+ const rate = downloadMs > 0 ? `${formatBytes((wireBytes ?? bodyBytes) / (downloadMs / 1e3))}/s` : "∞";
15398
+ log(`[Compute] └─ client: download ${downloadMs.toFixed(0)}ms (${wire} @ ${rate}) | parse ${parseMs.toFixed(0)}ms | meshes ${meshesMs.toFixed(0)}ms (${meshes.length} objects)`);
15274
15399
  }
15275
15400
  return finalizeResult({
15276
15401
  outputs: resultOutputs,
@@ -15299,7 +15424,7 @@ function SolvingIndicator($$renderer, $$props) {
15299
15424
  /** The raw flag: times the solve, and acknowledges one too short to show. */
15300
15425
  /** `createSolvingIndicator(...).show`. */
15301
15426
  /** `createSolvingIndicator(...).slow`. */
15302
- /** Live progress for the card. Without it the card's bar is indeterminate. */
15427
+ /** Live progress: the card names the current step and its count. */
15303
15428
  /** Without it the card has no Abort button; Esc still works where the host handles it. */
15304
15429
  /**
15305
15430
  * The page can't repaint mid-solve (see `createSolvingIndicator`): the pill says Esc aborts
@@ -15310,10 +15435,6 @@ function SolvingIndicator($$renderer, $$props) {
15310
15435
  const t = derived(() => locale.messages);
15311
15436
  const progress = createLiveProgress(() => live ?? EMPTY_LIVE_SOLVE);
15312
15437
  const head = derived(() => progress.headline ?? progress.progress[0]);
15313
- const bar = derived(() => head()?.fraction === void 0 ? void 0 : progress.bars[head().source ?? ""] ?? {
15314
- width: head().fraction,
15315
- ms: 150
15316
- });
15317
15438
  let elapsed = 0;
15318
15439
  let finished = null;
15319
15440
  const mode = derived(() => show ? slow && !freezesDuringSolve ? "card" : "work" : "idle");
@@ -15323,7 +15444,7 @@ function SolvingIndicator($$renderer, $$props) {
15323
15444
  }));
15324
15445
  const fmt = (ms) => `${seconds().format(ms / 1e3)} s`;
15325
15446
  const announcement = derived(() => mode() === "work" || mode() === "card" ? t().solvingEllipsis : mode() === "done" ? t().solveDone : "");
15326
- $$renderer.push(`<div class="h-10 min-w-0 relative flex-1"><div role="status" aria-live="polite" aria-atomic="true" class="sr-only">${escape_html(announcement())}</div> <div${attr_class(`inset-x-0 bottom-0 backdrop-blur-md ease-out absolute z-10 overflow-hidden border border-border-strong transition-all duration-300 motion-reduce:transition-none ${mode() === "card" ? "h-24 shadow-md rounded-lg bg-card/75" : mode() === "idle" ? "h-10 shadow-sm rounded-md bg-card/90" : "h-10 shadow-md rounded-md bg-card/75"}`)} data-testid="solve-status"${attr("data-state", mode())}>`);
15447
+ $$renderer.push(`<div class="h-10 min-w-0 relative flex-1"><div role="status" aria-live="polite" aria-atomic="true" class="sr-only">${escape_html(announcement())}</div> <div${attr_class(`inset-x-0 bottom-0 backdrop-blur-md ease-out absolute z-10 overflow-hidden border border-border-strong transition-all duration-300 motion-reduce:transition-none ${mode() === "card" ? "h-20 shadow-md rounded-lg bg-card/75" : mode() === "idle" ? "h-10 shadow-sm rounded-md bg-card/90" : "h-10 shadow-md rounded-md bg-card/75"}`)} data-testid="solve-status"${attr("data-state", mode())}>`);
15327
15448
  if (mode() === "card") {
15328
15449
  $$renderer.push(`<!--[0--><div class="px-3 gap-2 flex h-full flex-col justify-center"><div class="gap-2 min-w-0 flex items-center">`);
15329
15450
  Loader_circle($$renderer, {
@@ -15333,12 +15454,6 @@ function SolvingIndicator($$renderer, $$props) {
15333
15454
  $$renderer.push(`<!----> <span class="text-sm font-medium min-w-0 flex-1 truncate">${escape_html(head()?.label ?? t().solving)}</span> `);
15334
15455
  if (head()?.done !== void 0 && head()?.total !== void 0) $$renderer.push(`<!--[0--><span class="text-xs shrink-0 text-muted-foreground tabular-nums">${escape_html(head().done)} / ${escape_html(head().total)}</span>`);
15335
15456
  else $$renderer.push("<!--[-1-->");
15336
- $$renderer.push(`<!--]--></div> <div class="h-1 overflow-hidden rounded-full bg-muted" role="progressbar"${attr("aria-label", head()?.label ?? t().solving)}${attr("aria-valuemin", 0)}${attr("aria-valuemax", 100)}${attr("aria-valuenow", bar() ? Math.round(bar().width * 100) : void 0)}>`);
15337
- if (bar()) $$renderer.push(`<!--[0--><div class="h-full w-(--bar-width) rounded-full bg-primary transition-all duration-(--bar-ms) ease-linear"${attr_style("", {
15338
- "--bar-width": `${stringify(bar().width * 100)}%`,
15339
- "--bar-ms": `${stringify(bar().ms)}ms`
15340
- })}></div>`);
15341
- else $$renderer.push(`<!--[-1--><div class="animate-pulse h-full w-1/3 rounded-full bg-primary/60"></div>`);
15342
15457
  $$renderer.push(`<!--]--></div> <div class="gap-2 flex items-center"><span class="text-xs text-muted-foreground tabular-nums">${escape_html(fmt(elapsed))}</span> `);
15343
15458
  if (onabort) {
15344
15459
  $$renderer.push("<!--[0-->");
@@ -22056,12 +22171,13 @@ function AppLayout($$renderer, $$props) {
22056
22171
  /** As passed to `createSolvingIndicator`. */
22057
22172
  /** @deprecated Ignored: the solving status always sits in the action row. */
22058
22173
  /** Rendered above the action row, for a host that keeps the solve's messages in the flow. */
22174
+ /** See `ComputeApp`'s `solveHold`. */
22059
22175
  /**
22060
22176
  * The result for the current inputs, solving if it must (`session.ensureSolved`). Needed
22061
22177
  * by `solvesFirst` actions; without it they run straight away.
22062
22178
  */
22063
22179
  /** A visible button beside Calculate, for the host's one main commit action. */
22064
- let { schema, showViewer: hasViewer, meshes = [], isSolving, showSolvingIndicator = false, solveIsSlow = false, live, onabort, freezesDuringSolve = false, solveMessages, hasPendingChanges = false, hasNeverSolved = false, isViewerFullscreen = false, oncalculate = () => {}, ensureSolved, values, onValueChange, onLoadValues, panelActions = [], primaryAction, showSaveButton = true, showLoadButton = true, onSaveState, onListStates, presetLabels, viewerConfig = {}, logoUrl, onViewerReady } = $$props;
22180
+ let { schema, showViewer: hasViewer, meshes = [], isSolving, showSolvingIndicator = false, solveIsSlow = false, live, onabort, freezesDuringSolve = false, solveMessages, hasPendingChanges = false, hasNeverSolved = false, solveHold, isViewerFullscreen = false, oncalculate = () => {}, ensureSolved, values, onValueChange, onLoadValues, panelActions = [], primaryAction, showSaveButton = true, showLoadButton = true, onSaveState, onListStates, presetLabels, viewerConfig = {}, logoUrl, onViewerReady } = $$props;
22065
22181
  const presetText = derived(() => ({
22066
22182
  ...DEFAULT_PRESET_LABELS,
22067
22183
  ...presetLabels
@@ -22296,6 +22412,7 @@ function AppLayout($$renderer, $$props) {
22296
22412
  hasPendingChanges,
22297
22413
  hasNeverSolved,
22298
22414
  isSolving,
22415
+ hold: solveHold,
22299
22416
  oncalculate,
22300
22417
  trailing: hasMenu() || primaryAction ? footerActions : void 0
22301
22418
  });
@@ -22870,6 +22987,7 @@ function useSolveSession(args) {
22870
22987
  setValue: (id, value, forceSolve) => session.setValue(id, value, forceSolve),
22871
22988
  solve: () => session.solve(),
22872
22989
  ensureSolved: () => session.ensureSolved(),
22990
+ hold: (on) => session.hold(on),
22873
22991
  onSettled: (listener) => session.onSettled(listener),
22874
22992
  loadValues: (incoming) => session.loadValues(incoming),
22875
22993
  rebuild: (schema, scopeKey) => session.rebuild(schema, scopeKey),
@@ -23634,6 +23752,10 @@ function ComputeApp($$renderer, $$props) {
23634
23752
  * have finished.
23635
23753
  */
23636
23754
  /**
23755
+ * While set, the app is not ready to solve: the calculate button is disabled and shows this
23756
+ * text, and every solve waits until it clears (`SolveSession.hold`).
23757
+ */
23758
+ /**
23637
23759
  * Live events for the solves this app runs (`createSolveEventStream`). Pair it with
23638
23760
  * `streamId` on the `createComputeFetchSolveFn` that backs `onSolve`, or the server has
23639
23761
  * no stream to route to. Without it the app works as before, just with no mid-solve news.
@@ -23668,7 +23790,7 @@ function ComputeApp($$renderer, $$props) {
23668
23790
  * placeholder in the default is filled the same way in an override. The preset manager's
23669
23791
  * strings come from `presetLabels` instead.
23670
23792
  */
23671
- let { schema, onSolve, definitionKey = "", title, logo, isEmbedded, primaryColor, showModeToggle = false, panelActions = [], primaryAction, showSaveButton = true, showLoadButton = true, onSaveState, onListStates, presetLabels, copyrightName, footerText, solveDeadlineMs, events, footerComponent, footerComponentProps, footerItemId = "footer-item", footerItemPriority = 0, headerRight, navItems, homeUrl, brandName, header, onReady, onSolved, onViewerReady, loadRhino, viewerConfig = {}, externalScopeKey, clientSlot, lang, messages } = $$props;
23793
+ let { schema, onSolve, definitionKey = "", title, logo, isEmbedded, primaryColor, showModeToggle = false, panelActions = [], primaryAction, showSaveButton = true, showLoadButton = true, onSaveState, onListStates, presetLabels, copyrightName, footerText, solveDeadlineMs, solveHold, events, footerComponent, footerComponentProps, footerItemId = "footer-item", footerItemPriority = 0, headerRight, navItems, homeUrl, brandName, header, onReady, onSolved, onViewerReady, loadRhino, viewerConfig = {}, externalScopeKey, clientSlot, lang, messages } = $$props;
23672
23794
  setClientSlot(clientSlot);
23673
23795
  const locale = layerLocaleContext(() => lang, () => messages);
23674
23796
  const t = derived(() => locale.messages);
@@ -23684,6 +23806,7 @@ function ComputeApp($$renderer, $$props) {
23684
23806
  scopeKey: externalScopeKey || definitionKey || schema?.id || "",
23685
23807
  driver
23686
23808
  });
23809
+ session.hold(!!solveHold);
23687
23810
  setDeferredFilesContext({
23688
23811
  get files() {
23689
23812
  return session.files;
@@ -23795,6 +23918,7 @@ function ComputeApp($$renderer, $$props) {
23795
23918
  onabort: () => session.abort(),
23796
23919
  hasPendingChanges: session.hasPendingChanges,
23797
23920
  hasNeverSolved: session.hasNeverSolved,
23921
+ solveHold,
23798
23922
  values: session.values,
23799
23923
  logoUrl: logo,
23800
23924
  onViewerReady: handleViewerReady,
@@ -23902,6 +24026,7 @@ function _page($$renderer, $$props) {
23902
24026
  return held.schema;
23903
24027
  });
23904
24028
  function handleReady(api) {}
24029
+ let readingSavedValues = run(() => data.defaultsPending);
23905
24030
  {
23906
24031
  function navItems($$renderer) {
23907
24032
  if (isAuthed()) {
@@ -23939,6 +24064,7 @@ function _page($$renderer, $$props) {
23939
24064
  brandName: pageData().branding?.name,
23940
24065
  homeUrl: "/",
23941
24066
  solveDeadlineMs: data.solveDeadlineMs,
24067
+ solveHold: readingSavedValues ? "Reading saved values…" : void 0,
23942
24068
  events: liveEvents ?? void 0,
23943
24069
  loadRhino,
23944
24070
  footerComponent: ServerFooter,