@floless/app 0.174.0 → 0.175.0

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 (89) hide show
  1. package/autostart.mjs +117 -10
  2. package/dist/floless-server.cjs +2 -2
  3. package/dist/pdf-engine/floless_pdf/__init__.py +53 -0
  4. package/dist/pdf-engine/floless_pdf/backend_pdfium.py +823 -0
  5. package/dist/pdf-engine/floless_pdf/backend_pymupdf.py +245 -0
  6. package/dist/pdf-engine/floless_pdf/geometry.py +115 -0
  7. package/dist/pdf-engine/floless_pdf/images.py +75 -0
  8. package/dist/pdf-engine/floless_pdf/pages.py +136 -0
  9. package/dist/pdf-engine/floless_pdf/textrules.py +200 -0
  10. package/dist/schemas/steel.model.v2.schema.json +45 -1
  11. package/dist/skills/floless-app-approval/SKILL.md +28 -3
  12. package/dist/skills/floless-app-knowledge/SKILL.md +3 -2
  13. package/dist/skills/floless-app-sketches/SKILL.md +71 -0
  14. package/dist/skills/floless-app-sketches/references/steel-plate.md +15 -0
  15. package/dist/skills/floless-app-steel-model/SKILL.md +14 -1
  16. package/dist/skills/floless-app-steel-model/references/elements.md +90 -23
  17. package/dist/skills/floless-app-steel-takeoff/SKILL.md +18 -7
  18. package/dist/skills/floless-app-tweak-contract/SKILL.md +3 -2
  19. package/dist/web/agents.js +1 -1
  20. package/dist/web/app.css +120 -15
  21. package/dist/web/app.js +89 -38
  22. package/dist/web/aware-hold.js +10 -0
  23. package/dist/web/aware.js +405 -51
  24. package/dist/web/boot-watchdog.js +249 -0
  25. package/dist/web/card-details.js +88 -0
  26. package/dist/web/chat.css +29 -0
  27. package/dist/web/chat.js +430 -128
  28. package/dist/web/commands-connection-design.js +23 -0
  29. package/dist/web/commands-revit.js +3 -0
  30. package/dist/web/commands-shell.js +226 -10
  31. package/dist/web/commands-steel.js +95 -5
  32. package/dist/web/commands-tekla-parser.js +21 -1
  33. package/dist/web/connection-design-editor.html +71 -0
  34. package/dist/web/connection-design-editor.js +794 -61
  35. package/dist/web/connection-design-handles.js +9 -3
  36. package/dist/web/element-approval.js +74 -0
  37. package/dist/web/element-context.js +76 -6
  38. package/dist/web/element-geometry.js +8 -2
  39. package/dist/web/element-holds.js +68 -5
  40. package/dist/web/element-type-actions.js +22 -3
  41. package/dist/web/element-types.js +12 -5
  42. package/dist/web/element-words.js +15 -11
  43. package/dist/web/grid-place.js +51 -0
  44. package/dist/web/guide.js +2 -0
  45. package/dist/web/index.html +13 -16
  46. package/dist/web/instructor.js +5 -2
  47. package/dist/web/missed-routines.js +6 -1
  48. package/dist/web/model-change-findings.js +147 -32
  49. package/dist/web/model-change-review.js +435 -32
  50. package/dist/web/model-clash-check.css +100 -0
  51. package/dist/web/model-clash-check.js +681 -0
  52. package/dist/web/model-clip-box.js +204 -0
  53. package/dist/web/model-clip-list.js +153 -3
  54. package/dist/web/model-clip-session.js +3 -3
  55. package/dist/web/model-clip-three-overlay.js +135 -25
  56. package/dist/web/model-editor.css +2 -0
  57. package/dist/web/model-elements.js +273 -18
  58. package/dist/web/model-fit-checks.js +354 -0
  59. package/dist/web/model-spatial-panel.js +9 -3
  60. package/dist/web/model-spatial-tools.js +12 -3
  61. package/dist/web/model-tekla-selection.js +74 -0
  62. package/dist/web/model-view-query.js +70 -14
  63. package/dist/web/model-viewport-revit-adapter.js +8 -7
  64. package/dist/web/model-viewport-toolbar.js +8 -4
  65. package/dist/web/pages.js +78 -1
  66. package/dist/web/project-history.js +31 -1
  67. package/dist/web/revit-editor.css +34 -1
  68. package/dist/web/revit-editor.js +176 -55
  69. package/dist/web/run-history.js +8 -0
  70. package/dist/web/sketch-editor.js +141 -2
  71. package/dist/web/sketches.js +192 -6
  72. package/dist/web/start-place.js +46 -0
  73. package/dist/web/steel-3d-core.js +70 -0
  74. package/dist/web/steel-3d-view.js +288 -47
  75. package/dist/web/steel-change-review.css +29 -0
  76. package/dist/web/steel-custom-connection.js +6 -0
  77. package/dist/web/steel-editor.html +532 -33
  78. package/dist/web/steel-filter.html +8 -3
  79. package/dist/web/steel-model-checks.css +76 -0
  80. package/dist/web/steel-model-commands.js +1 -1
  81. package/dist/web/steel-model-v2-commands.js +17 -0
  82. package/dist/web/steel-view-generation.js +6 -2
  83. package/dist/web/teams.js +259 -19
  84. package/dist/web/tekla-editor.html +1 -0
  85. package/dist/web/terminal-requests.js +6 -0
  86. package/dist/web/vendor/connection-engine.js +890 -89
  87. package/dist/web/workspaces.js +630 -48
  88. package/package.json +4 -1
  89. package/preferences-file.mjs +27 -0
@@ -675,6 +675,15 @@ function expressionSyntaxFailure(src) {
675
675
  return { reason: "syntax", detail: error instanceof Error ? error.message : String(error) };
676
676
  }
677
677
  }
678
+ var EXPRESSION_FUNCTIONS = FUNCTIONS;
679
+ function parseExpressionTree(src) {
680
+ try {
681
+ return { tree: parse(src) };
682
+ } catch (error) {
683
+ if (error instanceof Fail) return { reason: error.reason, ...error.detail ? { detail: error.detail } : {} };
684
+ return { reason: "syntax", detail: error instanceof Error ? error.message : String(error) };
685
+ }
686
+ }
678
687
  function expressionUsesOperators(src) {
679
688
  let node;
680
689
  try {
@@ -1027,6 +1036,7 @@ var KNOWN_CAPABILITIES = Object.freeze([
1027
1036
  "templates/1",
1028
1037
  "declared/1",
1029
1038
  "rules/1",
1039
+ "rules/2",
1030
1040
  "anchor-kit/1",
1031
1041
  "route/1",
1032
1042
  "order/1",
@@ -1064,6 +1074,11 @@ var CONN_GROUP_KEYS = Object.freeze([
1064
1074
  ]);
1065
1075
  var EXT_CHECK_CODES = Object.freeze([
1066
1076
  "bolt-gauge-adjusted",
1077
+ "bolt-grid-adjusted",
1078
+ "plate-fit-adjusted",
1079
+ "plate-fit-failed",
1080
+ "plate-edge-short",
1081
+ "support-face-partial",
1067
1082
  "custom-geometry-empty",
1068
1083
  "main-role-invalid",
1069
1084
  "main-axis-unusable",
@@ -1105,8 +1120,37 @@ var RULE_FNS = Object.freeze({
1105
1120
  supportStation: { args: { support: "role", at: "frame.end" }, outputs: ["ok", "x", "y", "z"], total: true },
1106
1121
  aiscBoltLength: { args: { grip: "expr", dia: "expr" }, outputs: ["mm"], total: true },
1107
1122
  // Total: on an absent support it answers `ok = 0`, exactly as today's `braceSetback(member, undefined, at)` answers null.
1108
- braceSetback: { args: { member: "role", support: "role", at: "frame.at" }, outputs: ["ok", "mm", "skew"], total: true }
1123
+ braceSetback: { args: { member: "role", support: "role", at: "frame.at" }, outputs: ["ok", "mm", "skew"], total: true },
1124
+ // `rules/2`, the shipped shear plate's own (#3997, #4011). The stored-definition schema does not name them.
1125
+ supportFlange: { args: { beam: "role", support: "role", at: "frame.at", n: "expr", thickness: "expr", halfHeight: "expr" }, outputs: ["ok", "flange", "u0", "partial"], total: true },
1126
+ boltHole: { args: { dia: "expr" }, outputs: ["ok", "clearance"], total: true },
1127
+ plateFit: {
1128
+ args: {
1129
+ beam: "role",
1130
+ support: "role",
1131
+ at: "frame.at",
1132
+ rows: "expr",
1133
+ pitch: "expr",
1134
+ builtPitch: "expr",
1135
+ builtEdge: "expr",
1136
+ edge: "expr",
1137
+ height: "expr",
1138
+ dia: "expr",
1139
+ holeClearance: "expr",
1140
+ kClear: "expr",
1141
+ firstBolt: "expr",
1142
+ lastBolt: "expr",
1143
+ plateEnd: "expr",
1144
+ topDepth: "expr",
1145
+ topLength: "expr",
1146
+ bottomDepth: "expr",
1147
+ bottomLength: "expr"
1148
+ },
1149
+ outputs: ["ok", "on", "failed", "rows", "pitch", "centre", "height", "edge", "room", "need", "byHeight", "copeEdge", "short"],
1150
+ total: true
1151
+ }
1109
1152
  });
1153
+ var RULES_2 = Object.freeze(["supportFlange", "plateFit", "boltHole"]);
1110
1154
  function coerceLegacy(coerce, raw, d, spec = {}) {
1111
1155
  const num2 = () => typeof raw === "number" && isFinite(raw) ? raw : d();
1112
1156
  switch (coerce) {
@@ -1294,6 +1338,7 @@ function deriveRequires(def) {
1294
1338
  const params = arr(def.params).filter(isObj2);
1295
1339
  if (params.some((p) => p.kind === "enum" || p.kind === "flag" || p.kind === "text" || p.onInvalid !== void 0 || p.coerce !== void 0)) tags.add("enum/1");
1296
1340
  if (arr(def.rules).length) tags.add("rules/1");
1341
+ if (arr(def.rules).some((r) => isObj2(r) && RULES_2.includes(r.fn))) tags.add("rules/2");
1297
1342
  if (arr(def.checks).length) tags.add("when/1");
1298
1343
  if (def.emit === "feature-order") tags.add("order/1");
1299
1344
  const features = arr(def.features).filter(isObj2);
@@ -5827,6 +5872,13 @@ var SNAP_QUANTUM_MM = {
5827
5872
  coarse: { "ft-in": IN_TO_MM / 2, mm: 10 }
5828
5873
  };
5829
5874
 
5875
+ // ../web/model-clip-box.js
5876
+ var CLIP_BOX_AXES = Object.freeze(["x", "y", "z"]);
5877
+ var AXIS_INDEX = Object.freeze({ x: 0, y: 1, z: 2 });
5878
+ var RAD = Math.PI / 180;
5879
+ var CORNER_SIGNS = Object.freeze([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]);
5880
+ var EDGE_PAIRS = Object.freeze([[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4], [1, 5], [2, 6], [3, 7]]);
5881
+
5830
5882
  // ../web/model-spatial-tools.js
5831
5883
  var MODEL_SPATIAL_LIMITS = Object.freeze({ savedViews: 256, frames: 128, clips: 64 });
5832
5884
  var EPS = 1e-9;
@@ -6111,17 +6163,17 @@ function projectOnSegment(p, a, b, rule, dims, norm) {
6111
6163
  if (!rule || !DEGENERACY_MODES.has(rule.mode) || rule.mode !== "unitDenominator" && !(typeof rule.len2 === "number" && rule.len2 >= 0)) {
6112
6164
  throw new TypeError("projectPointOnSegment: pass a rule built with SEG_DEGENERACY");
6113
6165
  }
6114
- let len2 = 0, dot3 = 0;
6166
+ let len2 = 0, dot4 = 0;
6115
6167
  for (let i = 0; i < dims; i++) {
6116
6168
  const d = b[i] - a[i];
6117
6169
  len2 += d * d;
6118
- dot3 += (p[i] - a[i]) * d;
6170
+ dot4 += (p[i] - a[i]) * d;
6119
6171
  }
6120
6172
  const clamp2 = (v) => Math.max(0, Math.min(1, v));
6121
6173
  let t;
6122
- if (rule.mode === "unitDenominator") t = clamp2(dot3 / (len2 || 1));
6123
- else if (rule.mode === "below") t = len2 < rule.len2 ? 0 : clamp2(dot3 / len2);
6124
- else t = len2 > rule.len2 ? clamp2(dot3 / len2) : 0;
6174
+ if (rule.mode === "unitDenominator") t = clamp2(dot4 / (len2 || 1));
6175
+ else if (rule.mode === "below") t = len2 < rule.len2 ? 0 : clamp2(dot4 / len2);
6176
+ else t = len2 > rule.len2 ? clamp2(dot4 / len2) : 0;
6125
6177
  const closest = dims === 2 ? [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t] : [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
6126
6178
  const distance = dims === 2 ? norm(p[0] - closest[0], p[1] - closest[1]) : norm(p[0] - closest[0], p[1] - closest[1], p[2] - closest[2]);
6127
6179
  return { distance, t, closest };
@@ -6432,11 +6484,12 @@ var GIRDER = "support.bound and support.isBeam and not support.isBrace and suppo
6432
6484
  var BUILTIN_SHEAR_PLATE = {
6433
6485
  type: "steel.connection/v1",
6434
6486
  id: "builtin-shear-plate",
6435
- version: 1,
6487
+ version: 2,
6488
+ // 2 (#4053): rows drop to the beam's flat web at a column
6436
6489
  name: "Shear plate (fin plate)",
6437
6490
  family: "shear-plate",
6438
6491
  description: "A vertical fin plate lapped on one face of the supported beam end, bolted through the beam web and welded to the support. An optional stiffener and the cope(s) the real clash with the support asks for.",
6439
- requires: ["declared/1", "enum/1", "optional-role/1", "ops/1", "order/1", "route/1", "rules/1", "templates/1", "when/1"],
6492
+ requires: ["declared/1", "enum/1", "optional-role/1", "ops/1", "order/1", "route/1", "rules/1", "rules/2", "templates/1", "when/1"],
6440
6493
  emit: "feature-order",
6441
6494
  roles: [{ id: "beam", end: true }, { id: "support", optional: true }],
6442
6495
  params: [
@@ -6447,7 +6500,7 @@ var BUILTIN_SHEAR_PLATE = {
6447
6500
  legacy("boltRows", "count", "int-min1", 3),
6448
6501
  legacy("boltPitch", "length", "pos", 70),
6449
6502
  legacy("boltColPitch", "length", "pos", "boltPitch"),
6450
- legacy("holeClearance", "number", "num", 2),
6503
+ legacy("holeClearance", "number", "num", "bh.clearance"),
6451
6504
  legacy("edgeDist", "length", "nonneg", "max(1.5*boltDia, 30)"),
6452
6505
  legacy("weldLeg", "number", "num", 6),
6453
6506
  legacy("clearance", "length", "nonneg", 12.7),
@@ -6468,12 +6521,19 @@ var BUILTIN_SHEAR_PLATE = {
6468
6521
  derived("pV", "number", "boltRows > 1 ? min(boltPitch, max(0, plateHeight - 2*edgeV)/(boltRows - 1)) : 0"),
6469
6522
  derived("edgeU", "number", "min(edgeDist, plateWidth*0.4)"),
6470
6523
  derived("regHi", "number", "max(edgeU, plateWidth - edgeU)"),
6471
- derived("regLo", "number", "min(clearance + edgeU, regHi)"),
6524
+ // On a flange face the beam's drawn end may already stand past its setback (`u0` is then negative).
6525
+ derived("regLo", "number", "sf.flange == 1 ? min(max(clearance, -u0) + edgeU, regHi) : min(clearance + edgeU, regHi)"),
6472
6526
  derived("cU", "number", "(regLo + regHi)/2"),
6473
6527
  derived("pU", "number", "boltCols > 1 ? min(boltColPitch, (regHi - regLo)/(boltCols - 1)) : 0"),
6474
- // Where the plate bears: the support web face, and the lapped ply of the beam.
6475
- derived("u0", "number", "sw.tw / 2"),
6528
+ // Where the plate bears: the support's web face, or the outer face of the column flange it frames to (#3997), and the
6529
+ // lapped ply of the beam.
6530
+ derived("u0", "number", "sf.flange == 1 ? sf.u0 : sw.tw / 2"),
6476
6531
  derived("pOff", "number", "lap.lapN + lap.sideDir*(plateThickness/2)"),
6532
+ // What is BUILT vertically: as authored, unless the support's flange or the beam's cope is in the way (#4011). The
6533
+ // authored values stay in the joint; these are never written back.
6534
+ derived("rowsB", "number", "fit.on == 1 ? fit.rows : boltRows"),
6535
+ derived("heightB", "number", "fit.on == 1 ? fit.height : plateHeight"),
6536
+ derived("plateOffset", "number", "fit.on == 1 ? fit.centre : 0"),
6477
6537
  derived("plateOuterN", "number", "lap.lapN + lap.sideDir*plateThickness"),
6478
6538
  derived("nOuter", "number", "pOff + (lap.sideDir*plateThickness)/2"),
6479
6539
  derived("nInner", "number", "pOff - (lap.sideDir*plateThickness)/2"),
@@ -6489,7 +6549,34 @@ var BUILTIN_SHEAR_PLATE = {
6489
6549
  { id: "lap", fn: "lapFace", args: { member: "beam", side: "webSide", atEnd1: "frame.atEnd1", n: "frame.n" } },
6490
6550
  { id: "sw", fn: "supportWeb", args: { support: "support" } },
6491
6551
  { id: "copes", fn: "beamCopes", args: { beam: "beam", support: "support", at: "frame.at", clearance: "clearance", copeKClear: "copeKClear", copeMinLength: "copeMinLength" } },
6492
- { id: "st", fn: "supportStation", args: { support: "support", at: "frame.end" } }
6552
+ { id: "sf", fn: "supportFlange", args: { beam: "beam", support: "support", at: "frame.at", n: "pOff", thickness: "plateThickness", halfHeight: "plateHeight/2" } },
6553
+ {
6554
+ id: "fit",
6555
+ fn: "plateFit",
6556
+ args: {
6557
+ beam: "beam",
6558
+ support: "support",
6559
+ at: "frame.at",
6560
+ rows: "boltRows",
6561
+ pitch: "boltPitch",
6562
+ builtPitch: "pV",
6563
+ builtEdge: "edgeV",
6564
+ edge: "edgeDist",
6565
+ height: "plateHeight",
6566
+ dia: "boltDia",
6567
+ holeClearance: "holeClearance",
6568
+ kClear: "copeKClear",
6569
+ firstBolt: "u0 + cU - (boltCols - 1)/2*pU",
6570
+ lastBolt: "u0 + cU + (boltCols - 1)/2*pU",
6571
+ plateEnd: "u0 + plateWidth",
6572
+ topDepth: "copes.topDepth",
6573
+ topLength: "copes.topLength + clearance",
6574
+ bottomDepth: "copes.bottomDepth",
6575
+ bottomLength: "copes.bottomLength + clearance"
6576
+ }
6577
+ },
6578
+ { id: "st", fn: "supportStation", args: { support: "support", at: "frame.end" } },
6579
+ { id: "bh", fn: "boltHole", args: { dia: "boltDia" } }
6493
6580
  ],
6494
6581
  refusalFields: [BEAM_ID],
6495
6582
  checks: [
@@ -6506,10 +6593,35 @@ var BUILTIN_SHEAR_PLATE = {
6506
6593
  warn: "bolt-gauge-adjusted",
6507
6594
  fields: [{ key: "field", param: "boltColPitch" }, { key: "authored", expr: "boltColPitch" }, { key: "built", expr: "pU" }, BEAM_ID]
6508
6595
  },
6596
+ // A SET plate size squeezes the grid, and it is said (#4053). Where the fit rebuilt the layout, its own warnings say it.
6597
+ { when: "boltRows > 1 and fit.on != 1 and fit.failed != 1 and pV < boltPitch - 1e-6", warn: "bolt-grid-adjusted", fields: [{ key: "field", param: "boltPitch" }, { key: "authored", expr: "boltPitch" }, { key: "built", expr: "pV" }, BEAM_ID] },
6598
+ { when: "boltRows > 1 and fit.on != 1 and fit.failed != 1 and plateHeight/2 - (boltRows - 1)*pV/2 < edgeDist - 1e-6", warn: "bolt-grid-adjusted", fields: [{ key: "field", param: "plateHeight" }, { key: "authored", expr: "edgeDist" }, { key: "built", expr: "plateHeight/2 - (boltRows - 1)*pV/2" }, BEAM_ID] },
6599
+ { when: "edgeU < edgeDist - 1e-6", warn: "bolt-grid-adjusted", fields: [{ key: "field", param: "plateWidth" }, { key: "authored", expr: "edgeDist" }, { key: "built", expr: "edgeU" }, BEAM_ID] },
6600
+ { when: "support.bound and sf.partial == 1", warn: "support-face-partial", fields: [BEAM_ID, SUPPORT_ID] },
6601
+ ...[
6602
+ ["boltRows", "boltRows", "rowsB", "fit.rows < boltRows"],
6603
+ ["plateHeight", "plateHeight", "heightB", "abs(fit.height - plateHeight) > 1e-6"],
6604
+ ["plateOffset", "0", "plateOffset", "abs(fit.centre) > 1e-6"],
6605
+ ["edgeDist", "edgeDist", "fit.edge", "abs(fit.edge - edgeDist) > 1e-6"]
6606
+ ].map(([field, authored, built, when]) => ({
6607
+ when: `fit.on == 1 and ${when}`,
6608
+ warn: "plate-fit-adjusted",
6609
+ fields: [{ key: "field", param: field }, { key: "authored", expr: authored }, { key: "built", expr: built }, BEAM_ID, SUPPORT_ID]
6610
+ })),
6611
+ { when: "fit.short == 1", warn: "plate-edge-short", fields: [{ key: "field", param: "edgeDist" }, { key: "authored", expr: "edgeDist" }, { key: "built", expr: "fit.copeEdge" }, BEAM_ID, SUPPORT_ID] },
6612
+ { when: "fit.failed == 1 and fit.byHeight == 1", warn: "plate-fit-failed", fields: [{ key: "field", param: "plateHeight" }, { key: "authored", expr: "fit.need" }, { key: "built", expr: "fit.room" }, BEAM_ID, SUPPORT_ID] },
6613
+ { when: "fit.failed == 1 and fit.byHeight == 0", warn: "plate-fit-failed", fields: [{ key: "authored", expr: "fit.need" }, { key: "built", expr: "fit.room" }, BEAM_ID, SUPPORT_ID] },
6509
6614
  { when: "stiffener and girderOk and sw.rawOk == 0", refuse: "bearing-face-unresolved", fields: [SUPPORT_ID], after: "weld-far" },
6510
6615
  { when: 'copes.reason == "main-rolled-unsupported"', refuse: "main-rolled-unsupported", fields: [SUPPORT_ID], after: "stiffener-opposite-weld" },
6511
6616
  { when: 'copes.reason == "support-rolled-unsupported"', refuse: "support-rolled-unsupported", fields: [SUPPORT_ID], after: "stiffener-opposite-weld" }
6512
6617
  ],
6618
+ // The beam stops `clearance` short of the support face the plate welds to (#3550). The face is `u0` from the work
6619
+ // point (the support's real web half-thickness, from its designation; 0 when there is no I-section support), so the
6620
+ // cut is `u0 + clearance`. It used to be `clearance` from the WORK POINT, which left the beam end `u0 - clearance`
6621
+ // short of the setback: 8.4 mm from a W10X49 web instead of 12.7, and with a thicker web the beam would run into it.
6622
+ // Measured along the member axis, which is exact for a level beam. A beam drawn short of a column flange's face by more than
6623
+ // its clearance is not cut at all (a trim never lengthens a member).
6624
+ trims: [{ member: "beam", mm: "sf.flange == 1 ? max(0, u0 + clearance) : u0 + clearance" }],
6513
6625
  features: [
6514
6626
  {
6515
6627
  id: "plate",
@@ -6518,10 +6630,10 @@ var BUILTIN_SHEAR_PLATE = {
6518
6630
  frame: { type: "legacy-beam-end" },
6519
6631
  ids: "{joint}:plate",
6520
6632
  group: "shear-plate",
6521
- label: "Shear plate {round(plateWidth)}×{round(plateHeight)}×{round(plateThickness)}",
6522
- center: { u: "u0 + plateWidth/2", v: 0, n: "pOff" },
6633
+ label: "Shear plate {round(plateWidth)}×{round(heightB)}×{round(plateThickness)}",
6634
+ center: { u: "u0 + plateWidth/2", v: "plateOffset", n: "pOff" },
6523
6635
  width: "plateWidth",
6524
- depth: "plateHeight",
6636
+ depth: "heightB",
6525
6637
  thickness: "plateThickness",
6526
6638
  material: { param: "plateMaterial", emit: "always" }
6527
6639
  },
@@ -6534,9 +6646,9 @@ var BUILTIN_SHEAR_PLATE = {
6534
6646
  holeClearance: "holeClearance",
6535
6647
  grid: {
6536
6648
  a: { count: "boltCols", value: "cU + (i - (boltCols - 1)/2)*pU", offset: "a - cU" },
6537
- b: { count: "boltRows", value: "(i - (boltRows - 1)/2)*pV" }
6649
+ b: { count: "rowsB", value: "fit.on == 1 ? fit.centre + (i - (fit.rows - 1)/2)*fit.pitch : (i - (boltRows - 1)/2)*pV", offset: "b - plateOffset" }
6538
6650
  },
6539
- origin: { u: "u0 + cU", v: 0 },
6651
+ origin: { u: "u0 + cU", v: "plateOffset" },
6540
6652
  at: { u: "u0 + a", v: "b" },
6541
6653
  planeAt: "pOff",
6542
6654
  headAt: "plateOuterN",
@@ -6558,7 +6670,7 @@ var BUILTIN_SHEAR_PLATE = {
6558
6670
  partToBoltTo: { feature: "plate" },
6559
6671
  partToBeBolted: { role: "beam" },
6560
6672
  holeEffects: [{ ply: { feature: "plate" }, id: "{instance}:hole:plate" }, { ply: { role: "beam" }, id: "{instance}:hole:member" }],
6561
- plateHoles: [{ feature: "plate", id: "{joint}:plate-hole{k}", u: "a - plateWidth/2", v: "b" }]
6673
+ plateHoles: [{ feature: "plate", id: "{joint}:plate-hole{k}", u: "a - plateWidth/2", v: "b - plateOffset" }]
6562
6674
  },
6563
6675
  // The fillet weld(s) along the plate-to-support edge, on the plate face(s). OPEN polylines: a wrapped 2-point weld
6564
6676
  // doubles back into a cusp and renders as nothing.
@@ -6571,7 +6683,7 @@ var BUILTIN_SHEAR_PLATE = {
6571
6683
  ids: "{joint}:weld",
6572
6684
  group: "weld",
6573
6685
  label: 'Fillet {weldLeg} ({weldSide == "both" ? "both sides" : weldSide == "near" ? "near side" : "far side"})',
6574
- path: [{ u: "u0", v: "-plateHeight/2", n: "nOuter" }, { u: "u0", v: "plateHeight/2", n: "nOuter" }],
6686
+ path: [{ u: "u0", v: "plateOffset - heightB/2", n: "nOuter" }, { u: "u0", v: "plateOffset + heightB/2", n: "nOuter" }],
6575
6687
  closed: false,
6576
6688
  leg: "weldLeg",
6577
6689
  route: "named-support",
@@ -6587,7 +6699,7 @@ var BUILTIN_SHEAR_PLATE = {
6587
6699
  ids: "{joint}:weld2",
6588
6700
  group: "weld",
6589
6701
  label: 'Fillet {weldLeg} ({weldSide == "both" ? "both sides" : weldSide == "near" ? "near side" : "far side"})',
6590
- path: [{ u: "u0", v: "-plateHeight/2", n: "nInner" }, { u: "u0", v: "plateHeight/2", n: "nInner" }],
6702
+ path: [{ u: "u0", v: "plateOffset - heightB/2", n: "nInner" }, { u: "u0", v: "plateOffset + heightB/2", n: "nInner" }],
6591
6703
  closed: false,
6592
6704
  leg: "weldLeg",
6593
6705
  route: "named-support",
@@ -6636,10 +6748,10 @@ var BUILTIN_SHEAR_PLATE = {
6636
6748
  when: "stiffener and not girderOk",
6637
6749
  ids: "{joint}:stiff",
6638
6750
  group: "stiffener",
6639
- label: "Stiffener {round(plateWidth)}×{round(plateHeight)}×{round(plateThickness)}",
6640
- center: { u: "u0 + plateWidth/2", v: 0, n: "oppOff" },
6751
+ label: "Stiffener {round(plateWidth)}×{round(heightB)}×{round(plateThickness)}",
6752
+ center: { u: "u0 + plateWidth/2", v: "plateOffset", n: "oppOff" },
6641
6753
  width: "plateWidth",
6642
- depth: "plateHeight",
6754
+ depth: "heightB",
6643
6755
  thickness: "plateThickness",
6644
6756
  material: { param: "plateMaterial", emit: "always" }
6645
6757
  },
@@ -6652,7 +6764,7 @@ var BUILTIN_SHEAR_PLATE = {
6652
6764
  ids: "{joint}:stiffweld",
6653
6765
  group: "weld",
6654
6766
  label: "Fillet {weldLeg}",
6655
- path: [{ u: "u0", v: "-plateHeight/2", n: "oppOff" }, { u: "u0", v: "plateHeight/2", n: "oppOff" }],
6767
+ path: [{ u: "u0", v: "plateOffset - heightB/2", n: "oppOff" }, { u: "u0", v: "plateOffset + heightB/2", n: "oppOff" }],
6656
6768
  closed: false,
6657
6769
  leg: "weldLeg",
6658
6770
  route: "named-support",
@@ -6665,7 +6777,7 @@ var BUILTIN_SHEAR_PLATE = {
6665
6777
  type: "cut",
6666
6778
  placement: "declared",
6667
6779
  frame: { type: "legacy-beam-end" },
6668
- when: "copes.topDepth > 1",
6780
+ when: "copes.topDepth > 1 and sf.flange == 0",
6669
6781
  member: "beam",
6670
6782
  ids: "{joint}:cope-top",
6671
6783
  group: "cope",
@@ -6682,7 +6794,7 @@ var BUILTIN_SHEAR_PLATE = {
6682
6794
  type: "cut",
6683
6795
  placement: "declared",
6684
6796
  frame: { type: "legacy-beam-end" },
6685
- when: "copes.bottomDepth > 1",
6797
+ when: "copes.bottomDepth > 1 and sf.flange == 0",
6686
6798
  member: "beam",
6687
6799
  ids: "{joint}:cope-bottom",
6688
6800
  group: "cope",
@@ -6914,17 +7026,18 @@ var BUILTIN_BASE_PLATE = {
6914
7026
  legacy("bottomNut", "flag", "flag-not-false", void 0),
6915
7027
  legacy("anchorRodProjection", "length", "pos", "6.35"),
6916
7028
  // ¼ in. thread stick-out (25.4 / 4, exactly this double)
6917
- derived("seat", "number", "0.5"),
6918
- derived("embed", "number", "1"),
6919
7029
  derived("washerInner", "number", "boltDia + 3"),
6920
- // The rod's below-plate length: the scheduled grout + embedment, else the render stub, but never shorter than the bottom hardware.
6921
- derived("rodBelow", "number", "max(embedment > 0 ? grout + embedment : projBelow, anchorRodProjection + nutHeight + anchorPlateThickness + seat)"),
6922
- derived("plateTop", "number", "frame.baseZ + embed"),
7030
+ // The rod's below-plate length: the scheduled grout + embedment, else the render stub, but never shorter than the
7031
+ // hardware under the plate (the leveling nut, then the bottom nut and the anchor plate above the stick-out), so a
7032
+ // short embedment cannot drive the anchor plate up into the leveling nut or the plate.
7033
+ derived("rodBelow", "number", "max(embedment > 0 ? grout + embedment : projBelow, anchorRodProjection + nutHeight + anchorPlateThickness + (levelingNut ? nutHeight : 0))"),
7034
+ // The column bears on the plate's top face: no overlap, no gap (#3998).
7035
+ derived("plateTop", "number", "frame.baseZ"),
6923
7036
  derived("plateBottom", "number", "plateTop - thickness"),
6924
7037
  derived("halfU", "number", "max(0, plateWidth/2 - edgeDist)"),
6925
7038
  derived("halfV", "number", "max(0, plateDepth/2 - edgeDist)"),
6926
- // The seated z-stack: washer plate, washer, fixing nut above the plate; a leveling nut just below its bottom face.
6927
- derived("wpBot", "number", "plateTop + seat"),
7039
+ // The seated z-stack: washer plate, washer, fixing nut bearing on the plate's top face; a leveling nut bearing on its bottom face.
7040
+ derived("wpBot", "number", "plateTop"),
6928
7041
  derived("wpTop", "number", "wpBot + washerPlateThickness"),
6929
7042
  derived("washerTop", "number", "wpTop + washerThickness"),
6930
7043
  derived("fnTop", "number", "washerTop + nutHeight"),
@@ -6932,8 +7045,8 @@ var BUILTIN_BASE_PLATE = {
6932
7045
  derived("rodBotZ", "number", "plateBottom - rodBelow"),
6933
7046
  // Top of concrete = the plate's underside minus the grout pad (grout only applies with a real embedment).
6934
7047
  derived("concreteTopZ", "number", "plateBottom - (embedment > 0 ? grout : 0)"),
6935
- derived("lnBot", "number", "plateBottom - seat - nutHeight"),
6936
- derived("lnTop", "number", "plateBottom - seat"),
7048
+ derived("lnBot", "number", "plateBottom - nutHeight"),
7049
+ derived("lnTop", "number", "plateBottom"),
6937
7050
  // The bottom nut seats a stick-out above the rod tip; the bearing plate seats on it, or on the tip when the nut is off.
6938
7051
  derived("nutBotZ", "number", "rodBotZ + anchorRodProjection"),
6939
7052
  derived("apBotZ", "number", "nutBotZ + (bottomNut ? nutHeight : 0)")
@@ -7290,6 +7403,181 @@ var LIMITS_DATA = {
7290
7403
  "text": "d + 5/16 in.",
7291
7404
  "units": "in.",
7292
7405
  "clause": "AISC 360-22 Table J3.3 (= RCSC 2020 Table 3.1)"
7406
+ },
7407
+ "edge.m12": {
7408
+ "value": 18,
7409
+ "rule": "bolt.edge.min.m12",
7410
+ "text": "18 mm",
7411
+ "units": "mm",
7412
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7413
+ },
7414
+ "edge.m16": {
7415
+ "value": 22,
7416
+ "rule": "bolt.edge.min.m16",
7417
+ "text": "22 mm",
7418
+ "units": "mm",
7419
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7420
+ },
7421
+ "edge.m20": {
7422
+ "value": 26,
7423
+ "rule": "bolt.edge.min.m20",
7424
+ "text": "26 mm",
7425
+ "units": "mm",
7426
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7427
+ },
7428
+ "edge.m22": {
7429
+ "value": 28,
7430
+ "rule": "bolt.edge.min.m22",
7431
+ "text": "28 mm",
7432
+ "units": "mm",
7433
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7434
+ },
7435
+ "edge.m24": {
7436
+ "value": 30,
7437
+ "rule": "bolt.edge.min.m24",
7438
+ "text": "30 mm",
7439
+ "units": "mm",
7440
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7441
+ },
7442
+ "edge.m27": {
7443
+ "value": 34,
7444
+ "rule": "bolt.edge.min.m27",
7445
+ "text": "34 mm",
7446
+ "units": "mm",
7447
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7448
+ },
7449
+ "edge.m30": {
7450
+ "value": 38,
7451
+ "rule": "bolt.edge.min.m30",
7452
+ "text": "38 mm",
7453
+ "units": "mm",
7454
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7455
+ },
7456
+ "edge.m36": {
7457
+ "value": 46,
7458
+ "rule": "bolt.edge.min.m36",
7459
+ "text": "46 mm",
7460
+ "units": "mm",
7461
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7462
+ },
7463
+ "hole.std.m12": {
7464
+ "value": 14,
7465
+ "rule": "bolt.hole.standard.m12",
7466
+ "text": "14 mm",
7467
+ "units": "mm",
7468
+ "clause": "AISC 360-22 Table J3.3M"
7469
+ },
7470
+ "hole.over.m12": {
7471
+ "value": 16,
7472
+ "rule": "bolt.hole.oversize.m12",
7473
+ "text": "16 mm",
7474
+ "units": "mm",
7475
+ "clause": "AISC 360-22 Table J3.3M"
7476
+ },
7477
+ "hole.std.m16": {
7478
+ "value": 18,
7479
+ "rule": "bolt.hole.standard.m16",
7480
+ "text": "18 mm",
7481
+ "units": "mm",
7482
+ "clause": "AISC 360-22 Table J3.3M"
7483
+ },
7484
+ "hole.over.m16": {
7485
+ "value": 20,
7486
+ "rule": "bolt.hole.oversize.m16",
7487
+ "text": "20 mm",
7488
+ "units": "mm",
7489
+ "clause": "AISC 360-22 Table J3.3M"
7490
+ },
7491
+ "hole.std.m20": {
7492
+ "value": 22,
7493
+ "rule": "bolt.hole.standard.m20",
7494
+ "text": "22 mm",
7495
+ "units": "mm",
7496
+ "clause": "AISC 360-22 Table J3.3M"
7497
+ },
7498
+ "hole.over.m20": {
7499
+ "value": 24,
7500
+ "rule": "bolt.hole.oversize.m20",
7501
+ "text": "24 mm",
7502
+ "units": "mm",
7503
+ "clause": "AISC 360-22 Table J3.3M"
7504
+ },
7505
+ "hole.std.m22": {
7506
+ "value": 24,
7507
+ "rule": "bolt.hole.standard.m22",
7508
+ "text": "24 mm",
7509
+ "units": "mm",
7510
+ "clause": "AISC 360-22 Table J3.3M"
7511
+ },
7512
+ "hole.over.m22": {
7513
+ "value": 28,
7514
+ "rule": "bolt.hole.oversize.m22",
7515
+ "text": "28 mm",
7516
+ "units": "mm",
7517
+ "clause": "AISC 360-22 Table J3.3M"
7518
+ },
7519
+ "hole.std.m24": {
7520
+ "value": 27,
7521
+ "rule": "bolt.hole.standard.m24",
7522
+ "text": "27 mm (Table J3.3M note [a]: clearance allows a 1 in. bolt)",
7523
+ "units": "mm",
7524
+ "clause": "AISC 360-22 Table J3.3M"
7525
+ },
7526
+ "hole.over.m24": {
7527
+ "value": 30,
7528
+ "rule": "bolt.hole.oversize.m24",
7529
+ "text": "30 mm",
7530
+ "units": "mm",
7531
+ "clause": "AISC 360-22 Table J3.3M"
7532
+ },
7533
+ "hole.std.m27": {
7534
+ "value": 30,
7535
+ "rule": "bolt.hole.standard.m27",
7536
+ "text": "30 mm",
7537
+ "units": "mm",
7538
+ "clause": "AISC 360-22 Table J3.3M"
7539
+ },
7540
+ "hole.over.m27": {
7541
+ "value": 35,
7542
+ "rule": "bolt.hole.oversize.m27",
7543
+ "text": "35 mm",
7544
+ "units": "mm",
7545
+ "clause": "AISC 360-22 Table J3.3M"
7546
+ },
7547
+ "hole.std.m30": {
7548
+ "value": 33,
7549
+ "rule": "bolt.hole.standard.m30",
7550
+ "text": "33 mm",
7551
+ "units": "mm",
7552
+ "clause": "AISC 360-22 Table J3.3M"
7553
+ },
7554
+ "hole.over.m30": {
7555
+ "value": 38,
7556
+ "rule": "bolt.hole.oversize.m30",
7557
+ "text": "38 mm",
7558
+ "units": "mm",
7559
+ "clause": "AISC 360-22 Table J3.3M"
7560
+ },
7561
+ "hole.std.m36.clearance": {
7562
+ "value": 3,
7563
+ "rule": "bolt.hole.standard.ge.m36",
7564
+ "text": "d + 3 mm",
7565
+ "units": "mm",
7566
+ "clause": "AISC 360-22 Table J3.3M"
7567
+ },
7568
+ "hole.over.m36.clearance": {
7569
+ "value": 8,
7570
+ "rule": "bolt.hole.oversize.ge.m36",
7571
+ "text": "d + 8 mm",
7572
+ "units": "mm",
7573
+ "clause": "AISC 360-22 Table J3.3M"
7574
+ },
7575
+ "edge.over.m36.factor": {
7576
+ "value": 1.25,
7577
+ "rule": "bolt.edge.min.over.m36",
7578
+ "text": "1.25d",
7579
+ "units": "× bolt diameter d",
7580
+ "clause": "AISC 360-22 §J3.5, Table J3.4M"
7293
7581
  }
7294
7582
  }
7295
7583
  },
@@ -7913,7 +8201,7 @@ var LIMITS_DATA = {
7913
8201
  }
7914
8202
  }
7915
8203
  };
7916
- var LIMITS_DIGEST = "sha256:433371a229714abe8191a2c27cf75fe4c1a70106e1df68cba40248b9d68d0a03";
8204
+ var LIMITS_DIGEST = "sha256:3e1e086c7a77266d254772b359717fa52392b5a5033257379ce05d30f7a0ca3c";
7917
8205
 
7918
8206
  // connection-limits.ts
7919
8207
  var SIZE_TOL_MM = 0.01;
@@ -7966,7 +8254,33 @@ function badOption(clause, options) {
7966
8254
  }
7967
8255
  var fmtMm = (mm) => `${Math.round(mm * 100) / 100} mm`;
7968
8256
  var fmtIn = (inch) => `${Math.round(inch * 1e4) / 1e4} in.`;
8257
+ var ISO_SIZES = [5, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 42, 45, 48, 52, 56, 60, 64];
8258
+ var isIso = (d) => ISO_SIZES.some((s) => Math.abs(s - d) <= SIZE_TOL_MM);
8259
+ var sixteenths = (d) => {
8260
+ const n = Math.round(d / (IN_TO_MM / 16));
8261
+ return !isIso(d) && n > 0 && Math.abs(n * IN_TO_MM / 16 - d) <= SIZE_TOL_MM ? n : null;
8262
+ };
8263
+ var isInchBolt = (dMm) => sixteenths(dMm) !== null;
8264
+ function boltName(dMm) {
8265
+ const n = sixteenths(dMm);
8266
+ if (n === null) return isIso(dMm) ? `M${Math.round(dMm)}` : fmtMm(dMm);
8267
+ const whole = Math.floor(n / 16);
8268
+ let top = n % 16, bottom = 16;
8269
+ while (top && top % 2 === 0) {
8270
+ top /= 2;
8271
+ bottom /= 2;
8272
+ }
8273
+ return `${[...whole ? [String(whole)] : [], ...top ? [`${top}/${bottom}`] : []].join(" ")} in.`;
8274
+ }
8275
+ function nearestSizes(dMm, sizes) {
8276
+ if (dMm > Math.max(...sizes) + SIZE_TOL_MM) return [];
8277
+ const best = sizes.reduce((x, y) => Math.abs(y - dMm) < Math.abs(x - dMm) - 1e-9 || Math.abs(Math.abs(y - dMm) - Math.abs(x - dMm)) <= 1e-9 && y > x ? y : x);
8278
+ const up = sizes.find((x) => x > dMm);
8279
+ return [best, ...best < dMm && up !== void 0 ? [up] : []].map((mm) => ({ mm, name: boltName(mm), smaller: mm < dMm }));
8280
+ }
8281
+ var labelled = (r, code, said) => r.valueMm === null ? r : { ...r, clause: `${r.clause} (${said})`, warnings: [...r.warnings, { code, message: said }] };
7969
8282
  var AISC_ROWS = [0.5, 0.625, 0.75, 0.875, 1, 1.125, 1.25];
8283
+ var AISC_METRIC_ROWS = [12, 16, 20, 22, 24, 27, 30, 36];
7970
8284
  var AISC_OVERSIZE_ROWS = [0.5, 0.625, 0.75, 0.875, 1];
7971
8285
  var AISC_SIZES = [0.5, 0.625, 0.75, 0.875, 1, 1.125, 1.25, 1.375, 1.5];
7972
8286
  function aiscRow(dMm, rows, what) {
@@ -7978,7 +8292,7 @@ function aiscRow(dMm, rows, what) {
7978
8292
  row: larger,
7979
8293
  warnings: [{
7980
8294
  code: "out-of-range",
7981
- message: `A ${fmtMm(dMm)} bolt is not an inch size ${what} lists, and its metric table is not in the rule data; the minimum for the next larger size, ${fmtIn(larger)}, is used, which is never less than the bolt's own.`
8295
+ message: `A ${fmtMm(dMm)} bolt is not an inch size ${what} lists, so the next larger size, ${fmtIn(larger)}, is used, which is never less than the bolt's own.`
7982
8296
  }]
7983
8297
  };
7984
8298
  }
@@ -7995,11 +8309,11 @@ function aiscLimits() {
7995
8309
  const bad = badOption(HOLE_CLAUSE, { holeKind });
7996
8310
  if (bad) return bad;
7997
8311
  if (!isPositive(boltDiaMm)) return invalid("bolt diameter", boltDiaMm, HOLE_CLAUSE);
7998
- if (!isAiscSize(boltDiaMm)) {
7999
- return none("AISC 360-22 Table J3.3M", {
8000
- code: "not-tabulated",
8001
- message: `A ${fmtMm(boltDiaMm)} bolt is not an inch size Table J3.3 lists. Metric bolts use Table J3.3M, which the rule data does not have, so the hole size has to be given.`
8002
- }, "aware-aeco/aware#796");
8312
+ if (holeKind !== "slotted" && !isInchBolt(boltDiaMm)) {
8313
+ const kind = holeKind === "oversized" ? "over" : "std", row = AISC_METRIC_ROWS.find((x) => x >= boltDiaMm - SIZE_TOL_MM) ?? 36;
8314
+ const e = pick(env, row === 36 ? `hole.${kind}.m36.clearance` : `hole.${kind}.m${row}`), exact2 = Math.abs(row - boltDiaMm) <= SIZE_TOL_MM;
8315
+ const r2 = result(row === 36 ? boltDiaMm + e.value : exact2 ? e.value : boltDiaMm + (e.value - row), [e]);
8316
+ return exact2 || boltDiaMm > 36 ? r2 : labelled(r2, "next-size", `${boltName(boltDiaMm)} not in AISC Table J3.3M: hole clearance taken from M${row}`);
8003
8317
  }
8004
8318
  if (holeKind === "slotted") {
8005
8319
  return none("AISC 360-22 Table J3.3 (slotted holes)", {
@@ -8012,18 +8326,23 @@ function aiscLimits() {
8012
8326
  const c2 = pick(env, "hole.over.large.clearance");
8013
8327
  return result(boltDiaMm + c2.value * IN_TO_MM, [c2]);
8014
8328
  }
8015
- const r = aiscRow(boltDiaMm, AISC_OVERSIZE_ROWS, "AISC 360-22 Table J3.3");
8016
- if (!r) return invalid("bolt diameter", boltDiaMm, HOLE_CLAUSE);
8017
- const e = pick(env, `hole.over.${rowKey(r.row)}`);
8018
- return result(e.value * IN_TO_MM, [e], r.warnings);
8329
+ const r2 = aiscRow(boltDiaMm, AISC_OVERSIZE_ROWS, "AISC 360-22 Table J3.3");
8330
+ if (!r2) return invalid("bolt diameter", boltDiaMm, HOLE_CLAUSE);
8331
+ const e = pick(env, `hole.over.${rowKey(r2.row)}`);
8332
+ return result(e.value * IN_TO_MM, [e], r2.warnings);
8019
8333
  }
8020
8334
  const exact = AISC_ROWS.slice(0, 5).find((row) => Math.abs(row * IN_TO_MM - boltDiaMm) <= SIZE_TOL_MM);
8021
8335
  if (exact !== void 0) {
8022
8336
  const e = pick(env, `hole.std.${rowKey(exact)}`);
8023
8337
  return result(e.value * IN_TO_MM, [e]);
8024
8338
  }
8025
- const c = boltDiaMm <= 0.875 * IN_TO_MM + SIZE_TOL_MM ? pick(env, "hole.std.small.clearance") : pick(env, "hole.std.large.clearance");
8026
- return result(boltDiaMm + c.value * IN_TO_MM, [c]);
8339
+ if (isAiscSize(boltDiaMm)) {
8340
+ const c2 = pick(env, "hole.std.large.clearance");
8341
+ return result(boltDiaMm + c2.value * IN_TO_MM, [c2]);
8342
+ }
8343
+ const next = [...AISC_ROWS.slice(0, 5), ...AISC_SIZES].find((row) => row * IN_TO_MM > boltDiaMm);
8344
+ const c = pick(env, next !== void 0 && next < 1 ? "hole.std.small.clearance" : "hole.std.large.clearance"), r = result(boltDiaMm + c.value * IN_TO_MM, [c]);
8345
+ return next === void 0 ? r : labelled(r, "next-size", `${boltName(boltDiaMm)} not in AISC Table J3.3: hole clearance taken from ${boltName(next * IN_TO_MM)}`);
8027
8346
  }
8028
8347
  return {
8029
8348
  env: "us",
@@ -8038,17 +8357,19 @@ function aiscLimits() {
8038
8357
  message: `Table J3.4 is for standard holes; an ${holeKind} hole adds the increment C2 from Table J3.5, which the rule data does not have.`
8039
8358
  }, "aware-aeco/aware#796");
8040
8359
  }
8041
- if (boltDiaMm > 1.25 * IN_TO_MM + SIZE_TOL_MM) {
8042
- const f = pick(env, "edge.over1.25.factor");
8043
- return result(f.value * boltDiaMm, [f], nonStandardAisc(boltDiaMm));
8044
- }
8045
- const r = aiscRow(boltDiaMm, AISC_ROWS, "AISC 360-22 Table J3.4");
8046
- if (!r) return invalid("bolt diameter", boltDiaMm, EDGE_CLAUSE);
8047
- if (boltDiaMm < AISC_ROWS[0] * IN_TO_MM - SIZE_TOL_MM) {
8048
- r.warnings = [{ code: "out-of-range", message: `A ${fmtMm(boltDiaMm)} bolt is smaller than the smallest size Table J3.4 lists (½ in.); the ½ in. value is used.` }];
8360
+ const inch = isInchBolt(boltDiaMm);
8361
+ if (boltDiaMm > (inch ? 1.25 * IN_TO_MM : 36) + SIZE_TOL_MM) {
8362
+ const f = pick(env, inch ? "edge.over1.25.factor" : "edge.over.m36.factor");
8363
+ return result(f.value * boltDiaMm, [f], inch ? nonStandardAisc(boltDiaMm) : []);
8049
8364
  }
8050
- const e = pick(env, `edge.${rowKey(r.row)}`);
8051
- return result(e.value * IN_TO_MM, [e], r.warnings);
8365
+ const rows = inch ? AISC_ROWS.map((x) => x * IN_TO_MM) : [...AISC_METRIC_ROWS], row = rows.find((x) => x >= boltDiaMm - SIZE_TOL_MM);
8366
+ const e = pick(env, inch ? `edge.${rowKey(AISC_ROWS[rows.indexOf(row)])}` : `edge.m${row}`), r = result(e.value * (inch ? IN_TO_MM : 1), [e]);
8367
+ return Math.abs(row - boltDiaMm) <= SIZE_TOL_MM ? r : labelled(r, "next-size", `${boltName(boltDiaMm)} not in AISC Table ${inch ? "J3.4" : "J3.4M"}: minimum taken from ${boltName(row)}`);
8368
+ },
8369
+ boltSize(boltDiaMm) {
8370
+ const name = boltName(boltDiaMm), inch = isInchBolt(boltDiaMm), rows = inch ? AISC_ROWS.map((x) => x * IN_TO_MM) : [...AISC_METRIC_ROWS];
8371
+ if (!isPositive(boltDiaMm) || boltDiaMm > rows[rows.length - 1] + SIZE_TOL_MM || rows.some((x) => Math.abs(x - boltDiaMm) <= SIZE_TOL_MM)) return { name, listed: true, use: [] };
8372
+ return { name, listed: false, said: `${name} is not listed in AISC Table ${inch ? "J3.4" : "J3.4M"}: minimum end distance taken from ${boltName(rows.find((x) => x > boltDiaMm))}`, use: nearestSizes(boltDiaMm, rows) };
8052
8373
  },
8053
8374
  minWeldLeg(thinnerPlyMm) {
8054
8375
  const first = pick(env, "weld.min.to0.25");
@@ -8113,6 +8434,7 @@ function eurocodeLimits(env, prefix) {
8113
8434
  }
8114
8435
  return { d0: d + entry.value, entry, warnings };
8115
8436
  }
8437
+ const holeSaid = (d, d0Mm) => !isIso(d) ? `hole size not defined by EN 1090-2 for ${boltName(d)}: d0 = ${fmtMm(d0Mm)} assumed` : d < 12 - SIZE_TOL_MM ? `${boltName(d)} not in EN 1090-2 Table 11: hole clearance taken from M12` : null;
8116
8438
  return {
8117
8439
  env,
8118
8440
  standard: `${prefix}EN 1993-1-8:2005`,
@@ -8121,8 +8443,15 @@ function eurocodeLimits(env, prefix) {
8121
8443
  if (bad) return bad;
8122
8444
  const factor = holeKind === "slotted" ? pick(env, "edge.slot.factor") : pick(env, edgeKind === "side" ? "edge.side.factor" : "edge.end.factor");
8123
8445
  if (!isPositive(boltDiaMm)) return invalid("bolt diameter", boltDiaMm, factor.clause);
8124
- const h = d0(boltDiaMm, holeKind === "oversized" ? "oversized" : "standard");
8125
- return result(factor.value * h.d0, [factor, h.entry], h.warnings);
8446
+ const h = d0(boltDiaMm, holeKind === "oversized" ? "oversized" : "standard"), r = result(factor.value * h.d0, [factor, h.entry], h.warnings);
8447
+ const said = holeSaid(boltDiaMm, h.d0);
8448
+ return said ? labelled(r, "assumed-hole", said) : r;
8449
+ },
8450
+ boltSize(boltDiaMm) {
8451
+ const name = boltName(boltDiaMm);
8452
+ if (!isPositive(boltDiaMm)) return { name, listed: true, use: [] };
8453
+ const said = holeSaid(boltDiaMm, d0(boltDiaMm, "standard").d0);
8454
+ return said ? { name, listed: false, said: isIso(boltDiaMm) ? said : `${name} is not an EN 14399 size: ${said}`, use: nearestSizes(boltDiaMm, BOLT_ROW_SIZES) } : { name, listed: true, use: [] };
8126
8455
  },
8127
8456
  minWeldLeg(thinnerPlyMm) {
8128
8457
  const aMin = pick(env, "weld.throat.min");
@@ -8211,6 +8540,7 @@ function unknownLimits(env) {
8211
8540
  env,
8212
8541
  standard: "",
8213
8542
  minEdge: answer,
8543
+ boltSize: (d) => ({ name: boltName(d), listed: true, use: [] }),
8214
8544
  minWeldLeg: answer,
8215
8545
  minPitch: answer,
8216
8546
  maxPitch: answer,
@@ -8307,16 +8637,33 @@ function subtractConvex(piece, tool) {
8307
8637
  }
8308
8638
  return out;
8309
8639
  }
8310
- function edgeDirs(c) {
8311
- const dirs = [];
8640
+ var edgeCache = /* @__PURE__ */ new WeakMap();
8641
+ function edgesOf(c) {
8642
+ const kept = edgeCache.get(c);
8643
+ if (kept) return kept;
8644
+ const out = { dirs: [], ends: [] };
8645
+ const on = [];
8646
+ for (const p of c.planes) {
8647
+ const vs = [];
8648
+ for (const v of c.verts) if (Math.abs(dot2(p.n, v) - p.d) < 1e-6) vs.push(v);
8649
+ on.push(vs);
8650
+ }
8312
8651
  for (let i = 0; i < c.planes.length; i++) for (let j = i + 1; j < c.planes.length; j++) {
8313
- const pi = c.planes[i], pj = c.planes[j];
8314
- const shared = c.verts.filter((v) => Math.abs(dot2(pi.n, v) - pi.d) < 1e-6 && Math.abs(dot2(pj.n, v) - pj.d) < 1e-6);
8652
+ const pi = c.planes[i], pj = c.planes[j], shared = [];
8653
+ for (const v of on[i]) if (on[j].includes(v)) shared.push(v);
8315
8654
  if (shared.length < 2) continue;
8316
8655
  const d = unit2(cross2(pi.n, pj.n));
8317
- if (d && !dirs.some((e) => Math.abs(Math.abs(dot2(e, d)) - 1) < 1e-9)) dirs.push(d);
8656
+ if (!d) continue;
8657
+ if (!out.dirs.some((e) => Math.abs(Math.abs(dot2(e, d)) - 1) < 1e-9)) out.dirs.push(d);
8658
+ let lo = shared[0], hi = shared[0];
8659
+ for (const v of shared) {
8660
+ if (dot2(d, v) < dot2(d, lo)) lo = v;
8661
+ if (dot2(d, v) > dot2(d, hi)) hi = v;
8662
+ }
8663
+ if (dot2(d, hi) - dot2(d, lo) > GEOM_EPS) out.ends.push([lo, hi]);
8318
8664
  }
8319
- return dirs;
8665
+ edgeCache.set(c, out);
8666
+ return out;
8320
8667
  }
8321
8668
  var project = (c, axis) => {
8322
8669
  let lo = Infinity, hi = -Infinity;
@@ -8331,7 +8678,7 @@ function separation(a, b) {
8331
8678
  if (a.round && !b.round) return roundSeparation(a.round, b);
8332
8679
  if (b.round && !a.round) return roundSeparation(b.round, a);
8333
8680
  const axes = [...a.planes.map((p) => p.n), ...b.planes.map((p) => p.n)];
8334
- const ea = edgeDirs(a), eb = edgeDirs(b);
8681
+ const ea = edgesOf(a).dirs, eb = edgesOf(b).dirs;
8335
8682
  for (const x of ea) for (const y of eb) {
8336
8683
  const n = unit2(cross2(x, y));
8337
8684
  if (n) axes.push(n);
@@ -8577,6 +8924,184 @@ function roundSeparation(R, P) {
8577
8924
  return -Math.min(axial, radial);
8578
8925
  }
8579
8926
 
8927
+ // bolt-hole.ts
8928
+ function holeOver(limits, dia) {
8929
+ const d0 = dia > 0 ? limits?.holeDia(dia).valueMm : null;
8930
+ return typeof d0 === "number" && Number.isFinite(d0) ? d0 - dia : 2;
8931
+ }
8932
+
8933
+ // section-flat-web.ts
8934
+ function usableRootRadius(xs, rootRadius) {
8935
+ if (xs.shape !== "i" || typeof rootRadius !== "number" || !Number.isFinite(rootRadius) || rootRadius <= 0) return 0;
8936
+ return rootRadius < (xs.bf - xs.tw) / 2 && rootRadius < (xs.d - 2 * xs.tf) / 2 ? rootRadius : 0;
8937
+ }
8938
+ function flatHalfWeb(xs, rootRadius) {
8939
+ if (xs.shape !== "i" && xs.shape !== "channel") return null;
8940
+ const root = usableRootRadius(xs, rootRadius);
8941
+ return { half: xs.d / 2 - xs.tf - root, root };
8942
+ }
8943
+
8944
+ // shear-plate-fit.ts
8945
+ var FLANGE_GAP_MM = IN_TO_MM / 16;
8946
+ var FILLET_CLEAR_MM = IN_TO_MM / 8;
8947
+ var SQUARE_SIN = 87265e-7;
8948
+ var LEVEL_HOLE_MOVE = { mm: 0.1, source: "FloLess default — set your company standard" };
8949
+ var EPS2 = 1e-9;
8950
+ var dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
8951
+ var clean = (x) => Math.abs(x) < EPS2 ? 0 : x;
8952
+ function planFrame(beam, at2) {
8953
+ const end = at2 === "end1" ? beam.to : beam.from, far = at2 === "end1" ? beam.from : beam.to;
8954
+ const x = far[0] - end[0], y = far[1] - end[1], l = hypot(x, y);
8955
+ if (!(l > 1e-6)) return null;
8956
+ return { end, U: [x / l, y / l, 0], N: [y / l, -x / l, 0] };
8957
+ }
8958
+ function flangePlane(beam, support, at2, n) {
8959
+ if (support.role !== "column" || support.isBrace || !support.xs || !finite3(support.from) || !finite3(support.to) || rolledOffVertical(support)) return null;
8960
+ const xs = support.xs, ax = sectionAxes(support), f = planFrame(beam, at2);
8961
+ if (xs.shape !== "i" || !ax || !f || !(Math.abs(ax.x[2]) > 0.5)) return null;
8962
+ const { end, U, N } = f;
8963
+ const hd = xs.d / 2, hb = xs.bf / 2, inner = hd - xs.tf;
8964
+ const rel = [end[0] - ax.from[0], end[1] - ax.from[1], end[2] - ax.from[2]];
8965
+ const uD = clean(dot3(U, ax.d)), uW = clean(dot3(U, ax.w)), nD = clean(dot3(N, ax.d)), nW = clean(dot3(N, ax.w));
8966
+ const d0 = dot3(rel, ax.d), w0 = dot3(rel, ax.w);
8967
+ if (uD === 0) return null;
8968
+ const dAt = (u) => d0 + n * nD + u * uD, wAt = (u) => w0 + n * nW + u * uW;
8969
+ const s = uD > 0 ? 1 : -1;
8970
+ const outer = (s * hd - d0 - n * nD) / uD;
8971
+ const overFlange = Math.abs(wAt(outer)) <= hb + EPS2;
8972
+ let other = -Infinity;
8973
+ if (uW !== 0) {
8974
+ const sw = uW > 0 ? 1 : -1;
8975
+ const tip = (sw * hb - w0 - n * nW) / uW, web = (sw * (xs.tw / 2) - w0 - n * nW) / uW;
8976
+ if (Math.abs(dAt(tip)) <= hd && Math.abs(dAt(tip)) >= inner) other = Math.max(other, tip);
8977
+ if (Math.abs(dAt(web)) < inner) other = Math.max(other, web);
8978
+ }
8979
+ if (overFlange ? outer < other - EPS2 : other > -Infinity) return null;
8980
+ if (!overFlange && !(Math.abs(uD) * hb >= Math.abs(uW) * inner)) return null;
8981
+ return { base: (s * hd - d0) / uD, slopeV: clean(-ax.d[2] / uD), slopeN: clean(-nD / uD), w0, wPerU: uW, wPerN: nW, halfW: hb };
8982
+ }
8983
+ function supportFlangeFace(beam, support, at2, n, thickness, halfHeight) {
8984
+ if (!support) return null;
8985
+ const p = flangePlane(beam, support, at2, n);
8986
+ if (!p) return null;
8987
+ const stations = [-1, 1].flatMap((sv) => [-1, 1].map((sn) => p.base + p.slopeV * sv * halfHeight + p.slopeN * (n + sn * thickness / 2)));
8988
+ const u0 = Math.max(...stations);
8989
+ const past = [-1, 1].some((sn) => Math.abs(p.w0 + p.wPerU * u0 + p.wPerN * (n + sn * thickness / 2)) > p.halfW + 1e-6);
8990
+ return { u0, partial: past || u0 - Math.min(...stations) > FLANGE_GAP_MM };
8991
+ }
8992
+ function holeOutOfSteel(q, s, topFloor, bottomFloor) {
8993
+ const reach = (q.rows - 1) * q.builtPitch / 2 + s.hole;
8994
+ return reach > Math.min(topFloor, bottomFloor, q.height / 2, s.own) + 1e-6;
8995
+ }
8996
+ function plateInSupport(q, s) {
8997
+ return q.height / 2 > s.steelTop + 1e-6 || -q.height / 2 < s.steelBot - 1e-6;
8998
+ }
8999
+ function columnFit(beam, support, at2, q, asIs) {
9000
+ if (support.role !== "column" || support.isBrace || !finite3(support.from) || !finite3(support.to) || rolledOffVertical(support) || rolledOffVertical(beam)) return asIs;
9001
+ const bx = beam.xs, f = planFrame(beam, at2), sa = sectionAxes(support);
9002
+ if (!bx || support.xs?.shape !== "i" || !f || !sa || Math.abs(sa.x[2]) < 1 - 1e-9) return asIs;
9003
+ const run2 = hypot(beam.to[0] - beam.from[0], beam.to[1] - beam.from[1]), slope = Math.abs(beam.to[2] - beam.from[2]) / run2;
9004
+ if (!(slope * Math.abs(q.lastBolt) < LEVEL_HOLE_MOVE.mm)) return asIs;
9005
+ if (Math.min(Math.abs(dot3(f.U, sa.d)), Math.abs(dot3(f.U, sa.w))) > SQUARE_SIN) return asIs;
9006
+ const flat = flatHalfWeb(bx, beam.taperFlange ? null : beam.rootMm ?? null);
9007
+ if (!flat) return asIs;
9008
+ const own = flat.half - slope * Math.max(Math.abs(q.lastBolt), Math.abs(q.plateEnd)), hole = (q.dia + q.holeClearance) / 2;
9009
+ if ((q.rows - 1) * q.builtPitch / 2 + hole < own - 1e-6) return asIs;
9010
+ const least = hole + 1, E = Math.max(q.edge, least), tail = Math.max(0, (q.height - (q.rows - 1) * q.pitch) / 2);
9011
+ const flange = ["top", "bottom"].map((side) => ({ what: "beam-flange", side, ...flat.root > 0 ? {} : { noRoot: true } }));
9012
+ const column = {};
9013
+ const make = (rows, edge, want) => {
9014
+ const S = (rows - 1) * q.pitch, height = Math.min(want, 2 * own), more = S + q.pitch;
9015
+ const why = {
9016
+ heightSet: q.heightAuthored,
9017
+ offset: [],
9018
+ failed: [],
9019
+ column,
9020
+ rows: rows < q.rows ? [...q.heightAuthored && q.height < more + 2 * E - EPS2 ? [{ what: "set-height" }] : [], ...more / 2 + E > own + EPS2 ? flange : []] : [],
9021
+ height: height < want - 1e-6 || edge < E - 1e-6 ? flange : [{ what: "bolts" }]
9022
+ };
9023
+ return { ...asIs, state: "adjusted", rows, pitch: q.pitch, centre: 0, height, edge, why };
9024
+ };
9025
+ for (let r = Math.min(q.rows, 1024); r >= 1; r -= 1) {
9026
+ const S = (r - 1) * q.pitch;
9027
+ if (r === 1 && q.rows > 1) {
9028
+ const height = Math.min(q.heightAuthored ? q.height : Infinity, 2 * own), end = (height - q.pitch) / 2;
9029
+ if (end >= least - EPS2) {
9030
+ if (!q.edgeSet && (q.endMin === null || end >= q.endMin - 1e-6)) return make(2, end, height);
9031
+ if (!q.edgeSet) column.endForTwo = end;
9032
+ }
9033
+ }
9034
+ if (q.heightAuthored && q.height < S + 2 * E - EPS2 || S / 2 + E > own + EPS2) continue;
9035
+ return make(r, E, q.heightAuthored ? q.height : S + 2 * Math.max(tail, E));
9036
+ }
9037
+ const byHeight = q.heightAuthored && q.height < 2 * own;
9038
+ return { ...asIs, state: "failed", room: byHeight ? q.height : 2 * own, need: 2 * E, byHeight, why: { heightSet: q.heightAuthored, rows: [], height: [], offset: [], failed: byHeight ? [{ what: "set-height" }] : flange, column } };
9039
+ }
9040
+ function plateFit(beam, support, at2, q) {
9041
+ const asIs = { state: "as-authored", rows: q.rows, pitch: q.builtPitch, centre: 0, height: q.height, edge: q.builtEdge, room: 0, need: 0, byHeight: false, copeEdge: 0, shortEdge: false };
9042
+ if (support && support.role === "column") return columnFit(beam, support, at2, q, asIs);
9043
+ if (!support || support.role !== "beam" || support.isBrace || !finite3(support.from) || !finite3(support.to)) return asIs;
9044
+ if (rolledOffVertical(support) || rolledOffVertical(beam)) return asIs;
9045
+ if (!support.xs || !beam.xs || support.xs.shape !== "i") return asIs;
9046
+ const sx = support.xs, bx = beam.xs, f = planFrame(beam, at2), sa = sectionAxes(support);
9047
+ if (!f || !sa || Math.abs(dot3(f.U, sa.x)) > SQUARE_SIN) return asIs;
9048
+ const end = at2 === "end1" ? beam.to : beam.from;
9049
+ const mid = supportStationAt(support, end)[2] - end[2];
9050
+ const webHalf = sx.d / 2 - sx.tf;
9051
+ const hb = beam.dims.d / 2;
9052
+ const half = webHalf - Math.max(q.kClear, support.rootMm ?? 0);
9053
+ if (!(half > 0 && hb > mid - half && -hb < mid + half)) return asIs;
9054
+ const floorOf = (c, e) => c.depth > 1 && q.firstBolt - e < c.length ? hb - c.depth : Infinity;
9055
+ const around = {
9056
+ own: bx.shape === "i" || bx.shape === "channel" ? hb - bx.tf - (beam.rootMm ?? 0) : hb,
9057
+ steelTop: mid + webHalf - (support.rootMm ?? 0),
9058
+ steelBot: mid - webHalf + (support.rootMm ?? 0),
9059
+ hole: (q.dia + q.holeClearance) / 2
9060
+ };
9061
+ if (!holeOutOfSteel(q, around, floorOf(q.topCope, around.hole), floorOf(q.bottomCope, around.hole)) && !plateInSupport(q, around)) {
9062
+ const e = Math.max(q.edge, q.minEdge);
9063
+ const copeEdge = Math.min(floorOf(q.topCope, e), floorOf(q.bottomCope, e)) - (q.rows - 1) * q.builtPitch / 2;
9064
+ return Number.isFinite(copeEdge) && copeEdge < e - 1e-6 ? { ...asIs, copeEdge, shortEdge: true } : asIs;
9065
+ }
9066
+ const E = Math.max(q.edge, around.hole + 1);
9067
+ const tail = Math.max(0, (q.height - (q.rows - 1) * q.pitch) / 2);
9068
+ const fillet = support.rootMm === void 0 ? 0 : support.rootMm + FILLET_CLEAR_MM;
9069
+ const clears = [Math.max(q.kClear, fillet), fillet].filter((c, i, all) => i === 0 || c < all[0]);
9070
+ const topFloor = floorOf(q.topCope, E), botFloor = floorOf(q.bottomCope, E);
9071
+ const windows = clears.map((clear) => {
9072
+ const T = Math.min(mid + webHalf - clear, around.own), B = Math.max(mid - webHalf + clear, -around.own);
9073
+ const hi = Math.min(T - E, topFloor - E), lo = Math.max(B + E, E - botFloor);
9074
+ const flange = (side) => fillet > 0 && clear === fillet ? { what: "support-fillet", side, clearMm: FILLET_CLEAR_MM } : { what: "support-flange", side, clearMm: clear };
9075
+ const atT = [...mid + webHalf - clear <= T + 1e-6 ? [flange("top")] : [], ...around.own <= T + 1e-6 ? [{ what: "beam-flange", side: "top" }] : []];
9076
+ const atB = [...mid - webHalf + clear >= B - 1e-6 ? [flange("bottom")] : [], ...-around.own >= B - 1e-6 ? [{ what: "beam-flange", side: "bottom" }] : []];
9077
+ const atHi = [...T - E <= hi + 1e-6 ? atT : [], ...topFloor - E <= hi + 1e-6 ? [{ what: "beam-cope", side: "top", clearMm: E }] : []];
9078
+ const atLo = [...B + E >= lo - 1e-6 ? atB : [], ...E - botFloor >= lo - 1e-6 ? [{ what: "beam-cope", side: "bottom", clearMm: E }] : []];
9079
+ return { T, B, hi, lo, atT, atB, atHi, atLo };
9080
+ });
9081
+ const widest = windows[windows.length - 1];
9082
+ const why = { heightSet: q.heightAuthored, rows: [], height: [], offset: [], failed: [] };
9083
+ for (let r = Math.min(q.rows, 1024); r >= 1; r -= 1) {
9084
+ const S = (r - 1) * q.pitch;
9085
+ if (q.heightAuthored && q.height < S + 2 * E - EPS2) continue;
9086
+ for (const w of windows) {
9087
+ if (S > w.hi - w.lo + EPS2) continue;
9088
+ const c = Math.min(Math.max(0, w.lo + S / 2), w.hi - S / 2);
9089
+ const want = q.heightAuthored ? q.height : S + 2 * Math.max(tail, E);
9090
+ const height = Math.min(want, 2 * (w.T - c), 2 * (c - w.B));
9091
+ if (r < q.rows) {
9092
+ if (q.heightAuthored && q.height < S + q.pitch + 2 * E - EPS2) why.rows.push({ what: "set-height" });
9093
+ if (S + q.pitch > widest.hi - widest.lo + EPS2) why.rows.push(...widest.atHi, ...widest.atLo);
9094
+ }
9095
+ why.height = height < want - 1e-6 ? [...2 * (w.T - c) <= height + 1e-6 ? w.atT : [], ...2 * (c - w.B) <= height + 1e-6 ? w.atB : []] : [{ what: "bolts" }];
9096
+ why.offset = c > 1e-6 ? w.atLo : c < -1e-6 ? w.atHi : [];
9097
+ return { ...asIs, state: "adjusted", rows: r, pitch: q.pitch, centre: c, height, edge: E, why };
9098
+ }
9099
+ }
9100
+ const web = Math.max(0, Math.min(widest.T - widest.B, widest.hi - widest.lo + 2 * E));
9101
+ const byHeight = q.heightAuthored && q.height < web;
9102
+ return { ...asIs, state: "failed", room: byHeight ? q.height : web, need: 2 * E, byHeight, why: { ...why, failed: byHeight ? [{ what: "set-height" }] : [...widest.atHi, ...widest.atLo].map(({ what, side, clearMm }) => what === "beam-cope" ? { what, side } : { what, side, clearMm }) } };
9103
+ }
9104
+
8580
9105
  // connection-declared.ts
8581
9106
  var LENGTH_ASSUMED_NOTE = "length rests on an assumption, see warning";
8582
9107
  var Stop = class extends Error {
@@ -8593,7 +9118,7 @@ var CUSTOM_GRID_CAP = 32;
8593
9118
  var BUILTIN_GRID_CAP = 1024;
8594
9119
  var BUILTIN_BUDGET = Object.freeze({ maxSteps: 2e7, maxTemplateChars: 64 * 1024 * 1024 });
8595
9120
  var validity = /* @__PURE__ */ new WeakMap();
8596
- var finite3 = (a) => Array.isArray(a) && a.length >= 3 && a.every((n) => typeof n === "number" && isFinite(n));
9121
+ var finite32 = (a) => Array.isArray(a) && a.length >= 3 && a.every((n) => typeof n === "number" && isFinite(n));
8597
9122
  var sinkSafeLabel = (s) => s.length <= 256 && !/[\u0000-\u001f\u007f-\u009f<>&]/.test(s);
8598
9123
  var ID_REST = /^[A-Za-z0-9_.:\-]{1,128}$/;
8599
9124
  function expandDeclared(def, bindings, overridesIn, memberGeo, env) {
@@ -8754,7 +9279,7 @@ function run(def, bindings, overrides, memberGeo, env) {
8754
9279
  case "shape":
8755
9280
  return sectionOf(m).shape;
8756
9281
  case "geomOk":
8757
- return finite3(m.from) && finite3(m.to) && !!m.dims && m.dims.d > 0 && m.dims.w > 0 ? 1 : 0;
9282
+ return finite32(m.from) && finite32(m.to) && !!m.dims && m.dims.d > 0 && m.dims.w > 0 ? 1 : 0;
8758
9283
  default:
8759
9284
  return roleProperty(roleId, prop);
8760
9285
  }
@@ -8838,6 +9363,41 @@ function run(def, bindings, overrides, memberGeo, env) {
8838
9363
  const st = host.supportStationAt(m, endPt);
8839
9364
  return { ok: 1, x: st[0], y: st[1], z: st[2] };
8840
9365
  }
9366
+ case "supportFlange": {
9367
+ const beam = role.get(rule.args.beam), support = role.get(rule.args.support);
9368
+ const face = beam && support && host.supportFlangeFace ? host.supportFlangeFace(beam, support, atEnd1 ? "end1" : "end0", argNum(rule, "n"), argNum(rule, "thickness"), argNum(rule, "halfHeight")) : null;
9369
+ return face ? { ok: 1, flange: 1, u0: face.u0, partial: face.partial ? 1 : 0 } : { ok: 1, flange: 0, u0: 0, partial: 0 };
9370
+ }
9371
+ case "boltHole":
9372
+ return { ok: 1, clearance: holeOver(env.limits, argNum(rule, "dia")) };
9373
+ case "plateFit": {
9374
+ const beam = role.get(rule.args.beam), support = role.get(rule.args.support);
9375
+ if (!beam || !support || !host.plateFit) return { ok: 1, on: 0, failed: 0, rows: 1, pitch: 0, centre: 0, height: 0, edge: 0, room: 0, need: 0, byHeight: 0, copeEdge: 0, short: 0 };
9376
+ const dia = argNum(rule, "dia"), min = dia > 0 ? env.limits?.minEdge(dia).valueMm : void 0;
9377
+ const n = (name) => argNum(rule, name);
9378
+ const r = host.plateFit(beam, support, atEnd1 ? "end1" : "end0", {
9379
+ rows: n("rows"),
9380
+ pitch: n("pitch"),
9381
+ builtPitch: n("builtPitch"),
9382
+ builtEdge: n("builtEdge"),
9383
+ edge: n("edge"),
9384
+ height: n("height"),
9385
+ // Set by the person, not worked out: equal to the worked-out height is still set.
9386
+ heightAuthored: typeof overrides.plateHeight === "number" && Number.isFinite(overrides.plateHeight) && overrides.plateHeight > 0,
9387
+ dia,
9388
+ holeClearance: n("holeClearance"),
9389
+ minEdge: typeof min === "number" && Number.isFinite(min) ? min : 0,
9390
+ endMin: typeof min === "number" && Number.isFinite(min) ? min : null,
9391
+ edgeSet: typeof overrides.edgeDist === "number" && Number.isFinite(overrides.edgeDist),
9392
+ kClear: n("kClear"),
9393
+ firstBolt: n("firstBolt"),
9394
+ lastBolt: n("lastBolt"),
9395
+ plateEnd: n("plateEnd"),
9396
+ topCope: { depth: n("topDepth"), length: n("topLength") },
9397
+ bottomCope: { depth: n("bottomDepth"), length: n("bottomLength") }
9398
+ });
9399
+ return { ok: 1, on: r.state === "adjusted" ? 1 : 0, failed: r.state === "failed" ? 1 : 0, rows: r.rows, pitch: r.pitch, centre: r.centre, height: r.height, edge: r.edge, room: r.room, need: r.need, byHeight: r.byHeight ? 1 : 0, copeEdge: r.copeEdge, short: r.shortEdge ? 1 : 0 };
9400
+ }
8841
9401
  case "aiscBoltLength":
8842
9402
  return { mm: host.aiscBoltLength(argNum(rule, "grip"), argNum(rule, "dia")) };
8843
9403
  case "braceSetback": {
@@ -9410,7 +9970,9 @@ function run(def, bindings, overrides, memberGeo, env) {
9410
9970
  fit: { facts, unresolved: [...measuresItself ? ["declared-fit-clash-not-measured"] : [], ...unresolved] }
9411
9971
  };
9412
9972
  }
9413
- var memberIdentityOf = (m) => ({
9973
+ var memberIdentityOf = (m, withRoot) => ({
9974
+ ...withRoot && m.rootMm !== void 0 ? { rootMm: m.rootMm } : {},
9975
+ ...withRoot && m.taperFlange ? { taperFlange: true } : {},
9414
9976
  profile: m.profile,
9415
9977
  section: sectionOf(m),
9416
9978
  from: m.from,
@@ -9431,9 +9993,10 @@ var hashableValue = (v) => typeof v === "number" ? Number.isFinite(v) ? v : `non
9431
9993
  function extendedIdentity(def, bindings, overrides, memberGeo, env) {
9432
9994
  const bound = Object.entries(bindings ?? {}).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
9433
9995
  const members = {};
9996
+ const withRoot = (def.rules ?? []).some((r) => r.fn === "plateFit");
9434
9997
  for (const [, id] of bound) {
9435
9998
  const m = memberGeo.get(id);
9436
- members[id] = m ? memberIdentityOf(m) : null;
9999
+ members[id] = m ? memberIdentityOf(m, withRoot) : null;
9437
10000
  }
9438
10001
  let defHash;
9439
10002
  try {
@@ -9461,7 +10024,7 @@ function num(params, key, def) {
9461
10024
  const v = params?.[key];
9462
10025
  return typeof v === "number" && isFinite(v) ? v : def;
9463
10026
  }
9464
- function finite32(a) {
10027
+ function finite3(a) {
9465
10028
  return Array.isArray(a) && a.length >= 3 && a.every((n) => typeof n === "number" && isFinite(n));
9466
10029
  }
9467
10030
  var profileKind = (profile) => sectionKindOf(profile);
@@ -9556,8 +10119,8 @@ function supportStationAt(support, pt) {
9556
10119
  }
9557
10120
  var supportWorkZAt = (support, pt) => supportStationAt(support, pt)[2];
9558
10121
  function beamCopes(beam, support, at2, params) {
9559
- if (!support || !finite32(support.from) || !finite32(support.to) || !support.dims || !(support.dims.d > 0) || !(support.dims.w > 0)) return {};
9560
- if (!finite32(beam.from) || !finite32(beam.to) || !beam.dims || !(beam.dims.d > 0) || !(beam.dims.w > 0)) return {};
10122
+ if (!support || !finite3(support.from) || !finite3(support.to) || !support.dims || !(support.dims.d > 0) || !(support.dims.w > 0)) return {};
10123
+ if (!finite3(beam.from) || !finite3(beam.to) || !beam.dims || !(beam.dims.d > 0) || !(beam.dims.w > 0)) return {};
9561
10124
  if (profileKind(support.profile) !== "I") return { reason: "support-section-unsupported" };
9562
10125
  if (rolledOffVertical(beam)) return { reason: "main-rolled-unsupported" };
9563
10126
  if (rolledOffVertical(support)) return { reason: "support-rolled-unsupported" };
@@ -9608,6 +10171,8 @@ var DECLARED_HOST = {
9608
10171
  braceSetback,
9609
10172
  rolledOffVertical,
9610
10173
  profileKind,
10174
+ supportFlangeFace,
10175
+ plateFit,
9611
10176
  sectionOutline: (member) => profileOutline(member.profile, member.dims.w, member.dims.d, member.dims.round, member.xs),
9612
10177
  aiscBoltLength,
9613
10178
  builtinBoltLength,
@@ -9621,9 +10186,10 @@ var DECLARED_HOST = {
9621
10186
  return typeof v === "number" && Number.isFinite(v) ? v : null;
9622
10187
  }
9623
10188
  };
10189
+ var BOLT_SIZES = { in: [1.25, 1.125, 1, 0.875, 0.75, 0.625, 0.5].map((x) => x * IN_TO_MM), mm: [36, 30, 27, 24, 22, 20, 16, 12] };
9624
10190
  function braceSetback(member, support, at2) {
9625
- if (!support || !finite32(support.from) || !finite32(support.to)) return null;
9626
- if (!finite32(member.from) || !finite32(member.to)) return null;
10191
+ if (!support || !finite3(support.from) || !finite3(support.to)) return null;
10192
+ if (!finite3(member.from) || !finite3(member.to)) return null;
9627
10193
  const halfW = (support.dims?.w ?? 0) / 2;
9628
10194
  if (!(halfW > 0)) return null;
9629
10195
  const endPt = at2 === "end1" ? member.to : member.from;
@@ -10016,7 +10582,7 @@ function build(def, bindings, overrides, memberGeo, env, warnings) {
10016
10582
  if (def.family !== "custom") throw new Refuse({ code: "definition-family-unsupported", detail: def.family });
10017
10583
  const jid = env.jointId;
10018
10584
  const layout = env.mode === "layout";
10019
- const trace = env.trace ? { values: {}, frames: {}, fieldSources: {}, witnesses: {}, anchors: {}, faces: {} } : null;
10585
+ const trace = env.trace ? { values: {}, frames: {}, fieldSources: {}, witnesses: {}, anchors: {}, faces: {}, plates: {} } : null;
10020
10586
  const facts = [];
10021
10587
  const unresolved = [];
10022
10588
  const limitUses = [];
@@ -10404,6 +10970,7 @@ function build(def, bindings, overrides, memberGeo, env, warnings) {
10404
10970
  };
10405
10971
  parts.push(part);
10406
10972
  plates.set(p.id, { feature: p, part, pieces, origin, A, B, C, s0, s1, outline, thickness });
10973
+ if (trace) trace.plates[p.id] = { origin, A, B, C, s0, s1, outline: outline.map((q) => [q[0], q[1]]), ...p.on ? { bearing: { role: p.on.role, face: p.on.face } } : {} };
10407
10974
  }
10408
10975
  const plyOf = (ref, featureId) => {
10409
10976
  if ("feature" in ref) {
@@ -11217,12 +11784,12 @@ function gridFor(kind, units) {
11217
11784
  if (kind === "count") return { step: 1, coarse: 1, integer: true, min: 1, max: 32 };
11218
11785
  return units === "ft-in" ? { step: IN_TO_MM / 16, coarse: IN_TO_MM / 4, integer: false, min: 0, max: null } : { step: 1, coarse: 5, integer: false, min: 0, max: null };
11219
11786
  }
11220
- var clean = (v) => Math.round(v * 1e9) / 1e9 + 0;
11787
+ var clean2 = (v) => Math.round(v * 1e9) / 1e9 + 0;
11221
11788
  function snapValue(x, g, coarse = false) {
11222
11789
  const step = coarse && !g.integer ? g.coarse : g.step;
11223
- let v = clean(Math.round(x / step) * step);
11224
- if (v < g.min) v = clean(Math.ceil(g.min / step - 1e-9) * step);
11225
- if (g.max !== null && v > g.max) v = clean(Math.floor(g.max / step + 1e-9) * step);
11790
+ let v = clean2(Math.round(x / step) * step);
11791
+ if (v < g.min) v = clean2(Math.ceil(g.min / step - 1e-9) * step);
11792
+ if (g.max !== null && v > g.max) v = clean2(Math.floor(g.max / step + 1e-9) * step);
11226
11793
  return v;
11227
11794
  }
11228
11795
  var SAMPLE_BUDGET = 64;
@@ -11268,7 +11835,7 @@ function buildTrack(ctx, x0) {
11268
11835
  const g = ctx.grid;
11269
11836
  const got = /* @__PURE__ */ new Map();
11270
11837
  const take = (k) => {
11271
- if (!got.has(k)) got.set(k, sampleAt(ctx, clean(k * g.step)));
11838
+ if (!got.has(k)) got.set(k, sampleAt(ctx, clean2(k * g.step)));
11272
11839
  };
11273
11840
  if (ctx.kind === "count") {
11274
11841
  for (let k = 1; k <= COUNT_MAX; k++) take(k);
@@ -11283,7 +11850,7 @@ function buildTrack(ctx, x0) {
11283
11850
  const outer = SAMPLE_BUDGET - (kHi - kLo + 1);
11284
11851
  const lowShare = lowLen + highLen <= 0 ? 0 : highLen <= 0 ? outer : lowLen <= 0 ? 0 : Math.round(outer * lowLen / (lowLen + highLen));
11285
11852
  const highShare = highLen <= 0 ? 0 : outer - lowShare;
11286
- const cov = [{ fromMm: clean(kLo * g.step), toMm: clean(kHi * g.step), stepMm: g.step, label: "checked at every grid step here" }];
11853
+ const cov = [{ fromMm: clean2(kLo * g.step), toMm: clean2(kHi * g.step), stepMm: g.step, label: "checked at every grid step here" }];
11287
11854
  const spread = (side, len2, share) => {
11288
11855
  if (share <= 0 || len2 <= 0) return;
11289
11856
  const stride = Math.max(1, Math.ceil(len2 / share / g.step - 1e-9));
@@ -11294,7 +11861,7 @@ function buildTrack(ctx, x0) {
11294
11861
  take(k);
11295
11862
  }
11296
11863
  const far = side === "low" ? Math.max(0, kLo - stride * share) : kHi + stride * share;
11297
- cov.push(side === "low" ? { fromMm: clean(far * g.step), toMm: clean(kLo * g.step), stepMm: clean(stride * g.step), label: `checked every ${clean(stride * g.step)} mm here` } : { fromMm: clean(kHi * g.step), toMm: clean(far * g.step), stepMm: clean(stride * g.step), label: `checked every ${clean(stride * g.step)} mm here` });
11864
+ cov.push(side === "low" ? { fromMm: clean2(far * g.step), toMm: clean2(kLo * g.step), stepMm: clean2(stride * g.step), label: `checked every ${clean2(stride * g.step)} mm here` } : { fromMm: clean2(kHi * g.step), toMm: clean2(far * g.step), stepMm: clean2(stride * g.step), label: `checked every ${clean2(stride * g.step)} mm here` });
11298
11865
  };
11299
11866
  spread("low", lowLen, lowShare);
11300
11867
  spread("high", highLen, highShare);
@@ -11312,12 +11879,12 @@ function extendTrack(ctx, track, side) {
11312
11879
  const k = side === "low" ? kEdge - stride * i : kEdge + stride * i;
11313
11880
  if (k < 0) break;
11314
11881
  if (!got.has(k)) {
11315
- got.set(k, sampleAt(ctx, clean(k * g.step)));
11882
+ got.set(k, sampleAt(ctx, clean2(k * g.step)));
11316
11883
  evaluations++;
11317
11884
  }
11318
11885
  }
11319
11886
  const far = side === "low" ? Math.max(0, kEdge - stride * EXTENSION_SAMPLES) : kEdge + stride * EXTENSION_SAMPLES;
11320
- const cov = side === "low" ? { fromMm: clean(far * g.step), toMm: clean(kEdge * g.step), stepMm: clean(stride * g.step), label: `checked every ${clean(stride * g.step)} mm here` } : { fromMm: clean(kEdge * g.step), toMm: clean(far * g.step), stepMm: clean(stride * g.step), label: `checked every ${clean(stride * g.step)} mm here` };
11887
+ const cov = side === "low" ? { fromMm: clean2(far * g.step), toMm: clean2(kEdge * g.step), stepMm: clean2(stride * g.step), label: `checked every ${clean2(stride * g.step)} mm here` } : { fromMm: clean2(kEdge * g.step), toMm: clean2(far * g.step), stepMm: clean2(stride * g.step), label: `checked every ${clean2(stride * g.step)} mm here` };
11321
11888
  return withMarks(ctx, sortSamples(got), [...track.coverage, cov], evaluations, track.extensions + 1);
11322
11889
  }
11323
11890
  function solveTarget(ctx, track, t, direct, coarse = false) {
@@ -11361,7 +11928,7 @@ function solveTarget(ctx, track, t, direct, coarse = false) {
11361
11928
  const ka = Math.round(a.x / g.step), kb = Math.round(b.x / g.step);
11362
11929
  if (kb - ka <= 1) break;
11363
11930
  const km = Math.round((ka + kb) / 2);
11364
- const m = sampleAt(ctx, clean(km * g.step));
11931
+ const m = sampleAt(ctx, clean2(km * g.step));
11365
11932
  spent++;
11366
11933
  if (m.q === null) break;
11367
11934
  if (Math.abs(m.q - t) < Math.abs(best.q - t)) best = m;
@@ -11430,7 +11997,7 @@ function planDrag(def, handle, exp, workspace, evaluate2, units) {
11430
11997
  const v = valueOfParam(y2, exp);
11431
11998
  const moved = [v + grid2.step, v - grid2.step].some((trial) => {
11432
11999
  if (trial < grid2.min || grid2.max !== null && trial > grid2.max) return false;
11433
- const q = handleValueIn(handle, evaluate2({ [id]: clean(trial) }));
12000
+ const q = handleValueIn(handle, evaluate2({ [id]: clean2(trial) }));
11434
12001
  return q !== null && before !== null && Math.abs(q - before) > 1e-9;
11435
12002
  });
11436
12003
  if (moved) candidates.push(id);
@@ -11493,6 +12060,238 @@ function decisionStatuses(entries2, ctx) {
11493
12060
  }
11494
12061
  var acceptedFactIds = (views) => new Set(views.filter((v) => v.status === "active").map((v) => v.decision.fact.id));
11495
12062
 
12063
+ // connection-rule.ts
12064
+ var PROP_WORDS = Object.freeze({
12065
+ d: "depth",
12066
+ bf: "flange width",
12067
+ tw: "web thickness",
12068
+ tf: "flange thickness",
12069
+ b: "width",
12070
+ t: "thickness",
12071
+ w: "width",
12072
+ len: "length"
12073
+ });
12074
+ var RULE_KINDS = /* @__PURE__ */ new Set(["length", "count", "number"]);
12075
+ var ARITY = Object.freeze({
12076
+ min: [1, Infinity],
12077
+ max: [1, Infinity],
12078
+ round: [1, 1],
12079
+ ceil: [1, 1],
12080
+ floor: [1, 1],
12081
+ abs: [1, 1],
12082
+ fill: [2, 2],
12083
+ lookup: [2, 2],
12084
+ minEdge: [1, 1],
12085
+ minWeldLeg: [1, 1],
12086
+ minPitch: [1, 1],
12087
+ holeDia: [1, 1],
12088
+ boltLength: [2, 2]
12089
+ });
12090
+ var listWords = (xs, max = 10) => {
12091
+ const shown = xs.slice(0, max);
12092
+ const tail = xs.length > max ? ` and ${xs.length - max} more` : "";
12093
+ if (shown.length <= 1) return `${shown.join("")}${tail}`;
12094
+ return `${shown.slice(0, -1).join(", ")}${tail ? `, ${shown.at(-1)}${tail}` : ` and ${shown.at(-1)}`}`;
12095
+ };
12096
+ var isExtended = (d) => Array.isArray(d.requires) && d.requires.length > 0;
12097
+ function cycleThrough(draft, paramId, rule) {
12098
+ const deps = /* @__PURE__ */ new Map();
12099
+ for (const p of draft.params ?? []) {
12100
+ const src = p.id === paramId ? rule : p.state === "derived" && typeof p.rule === "string" ? p.rule : null;
12101
+ deps.set(p.id, src ? expressionDependencies(src).params : []);
12102
+ }
12103
+ const path = [];
12104
+ const seen = /* @__PURE__ */ new Set();
12105
+ const walk = (id) => {
12106
+ if (path.length && id === paramId) {
12107
+ path.push(id);
12108
+ return true;
12109
+ }
12110
+ if (seen.has(id)) return false;
12111
+ seen.add(id);
12112
+ path.push(id);
12113
+ for (const q of deps.get(id) ?? []) if (walk(q)) return true;
12114
+ path.pop();
12115
+ return false;
12116
+ };
12117
+ return walk(paramId) ? path.join(" → ") : null;
12118
+ }
12119
+ function ruleIssue(draft, paramId, rule) {
12120
+ const params = draft.params ?? [];
12121
+ const p = params.find((x) => x.id === paramId);
12122
+ if (!p) return { code: "unknown-param", message: `This connection has no param "${paramId}".` };
12123
+ if (!RULE_KINDS.has(String(p.kind))) return { code: "not-a-number", message: `${p.description ?? p.id} is a choice, not a number, so it has no rule. Pick its value instead.` };
12124
+ if (typeof rule !== "string" || !rule.trim()) return { code: "rule-empty", message: "Write the rule, for example (rows - 1) * pitch + 2 * edge." };
12125
+ const text = rule.trim();
12126
+ if (text.length > EXPRESSION_LIMITS.maxLength) return { code: "rule-too-long", message: `A rule is at most ${EXPRESSION_LIMITS.maxLength} characters; this one has ${text.length}. Split it over a second param.` };
12127
+ const parsed = parseExpressionTree(text);
12128
+ if (!("tree" in parsed)) {
12129
+ if (parsed.reason === "too-deep") return { code: "rule-too-deep", message: "This rule nests too many brackets or calls inside each other. Split it over a second param." };
12130
+ if (parsed.reason === "too-long") return { code: "rule-too-long", message: `A rule is at most ${EXPRESSION_LIMITS.maxLength} characters. Split it over a second param.` };
12131
+ return { code: "rule-syntax", message: `FloLess cannot read this rule: ${syntaxWords(parsed.detail)}. Write it with numbers, param names, member sizes such as beam.d, + - * / and brackets.` };
12132
+ }
12133
+ const paramIds = new Set(params.map((x) => x.id));
12134
+ const roleIds = new Set((draft.roles ?? []).map((r) => r.id));
12135
+ const extended = isExtended(draft);
12136
+ let issue = null;
12137
+ const walk = (n) => {
12138
+ if (issue) return;
12139
+ switch (n.t) {
12140
+ case "name":
12141
+ if (n.v === paramId) {
12142
+ issue = { code: "rule-self", message: `A rule cannot follow itself: this rule reads ${paramId}. Use the other values it depends on.` };
12143
+ return;
12144
+ }
12145
+ if (!paramIds.has(n.v)) {
12146
+ issue = roleIds.has(n.v) ? { code: "rule-role-bare", message: `"${n.v}" is a member. Name one of its sizes, such as ${n.v}.d (its depth) or ${n.v}.tw (its web thickness).` } : { code: "rule-unknown-name", message: `There is no param named "${n.v}". This connection's params are ${listWords(params.map((x) => x.id).filter((x) => x !== paramId))}.` };
12147
+ }
12148
+ return;
12149
+ case "prop":
12150
+ if (extended && !roleIds.has(n.role)) return;
12151
+ if (!roleIds.has(n.role)) {
12152
+ issue = { code: "rule-unknown-member", message: `"${n.role}" is not a member of this connection. Its members are ${listWords([...roleIds])}.` };
12153
+ return;
12154
+ }
12155
+ if (!ROLE_PROPERTIES.includes(n.prop)) {
12156
+ if (extended) return;
12157
+ issue = { code: "rule-unknown-size", message: `"${n.role}.${n.prop}" is not a size FloLess reads. Use ${listWords(ROLE_PROPERTIES.map((k) => `${n.role}.${k} (${PROP_WORDS[k]})`))}.` };
12158
+ }
12159
+ return;
12160
+ case "call": {
12161
+ if (!EXPRESSION_FUNCTIONS.has(n.fn)) {
12162
+ issue = { code: "rule-unknown-function", message: `"${n.fn}" is not a function FloLess knows. It knows ${listWords([...EXPRESSION_FUNCTIONS], 20)}.` };
12163
+ return;
12164
+ }
12165
+ const [lo, hi] = ARITY[n.fn] ?? [0, Infinity];
12166
+ if (n.args.length < lo || n.args.length > hi) {
12167
+ const want = lo === hi ? `${lo} value${lo === 1 ? "" : "s"}` : `at least ${lo} value${lo === 1 ? "" : "s"}`;
12168
+ issue = { code: "rule-arity", message: `${n.fn} takes ${want}; this rule gives it ${n.args.length}.` };
12169
+ return;
12170
+ }
12171
+ if (n.fn !== "lookup") n.args.forEach(walk);
12172
+ return;
12173
+ }
12174
+ case "neg":
12175
+ case "not":
12176
+ walk(n.a);
12177
+ return;
12178
+ case "bin":
12179
+ case "cmp":
12180
+ case "logic":
12181
+ walk(n.a);
12182
+ walk(n.b);
12183
+ return;
12184
+ case "tern":
12185
+ walk(n.c);
12186
+ walk(n.a);
12187
+ walk(n.b);
12188
+ return;
12189
+ default:
12190
+ return;
12191
+ }
12192
+ };
12193
+ walk(parsed.tree);
12194
+ if (issue) return issue;
12195
+ const loop = cycleThrough(draft, paramId, text);
12196
+ if (loop) return { code: "rule-cycle", message: `This rule would follow itself: ${loop}. Fix one of those values first (Fixed at this value), then write the rule.` };
12197
+ return null;
12198
+ }
12199
+ function syntaxWords(detail) {
12200
+ if (!detail) return "it is not written the way a rule is";
12201
+ const expected = /^expected '(.)'$/.exec(detail);
12202
+ if (expected) return expected[1] === ")" ? "a bracket is opened and never closed" : `a "${expected[1]}" is missing`;
12203
+ if (detail === "unexpected end of expression") return "it stops before it is finished";
12204
+ if (detail === "unexpected trailing input") return "there is something after the end of the rule (a bracket closed too early, or a missing + - * /)";
12205
+ const unexpected = /^unexpected '(.+)'$/.exec(detail);
12206
+ if (unexpected) return `"${unexpected[1]}" is in a place it cannot be`;
12207
+ if (detail === "comparisons do not chain") return 'two comparisons are joined; write them with "and"';
12208
+ if (/^bad number/.test(detail)) return "a number is written wrongly";
12209
+ return detail;
12210
+ }
12211
+ var PREC = Object.freeze({ tern: 0, logic: 1, not: 2, cmp: 3, "+": 4, "-": 4, "*": 5, "/": 5, neg: 6 });
12212
+ var fmtNum = (v) => String(Math.round(v * 1e4) / 1e4);
12213
+ var nameOf = (draft, id) => (draft.params ?? []).find((p) => p.id === id)?.description ?? id;
12214
+ var EQUAL_SPACING = /^\(\s*([A-Za-z_]\w*)\s*-\s*2\s*\*\s*([A-Za-z_]\w*)\s*\)\s*\/\s*(?:max\(\s*([A-Za-z_]\w*)\s*-\s*1\s*,\s*1\s*\)|([0-9.]+))$/;
12215
+ var FILL = /^fill\(\s*([A-Za-z_]\w*)\s*-\s*2\s*\*\s*([A-Za-z_]\w*)\s*,\s*([A-Za-z_]\w*|[0-9.]+)\s*\)$/;
12216
+ var TIED = /^([A-Za-z_]\w*)\.([A-Za-z]+)$/;
12217
+ function describeRule(rule, draft) {
12218
+ const text = rule.trim();
12219
+ const eq = EQUAL_SPACING.exec(text);
12220
+ if (eq) return `equal spacing over the ${nameOf(draft, eq[1])}, less the ${nameOf(draft, eq[2])} at each end`;
12221
+ const fill = FILL.exec(text);
12222
+ if (fill) return `as many as fit in the ${nameOf(draft, fill[1])}, less the ${nameOf(draft, fill[2])} at each end, ${/^[0-9.]/.test(fill[3]) ? `${fill[3]} mm` : nameOf(draft, fill[3])} apart`;
12223
+ const tied = TIED.exec(text);
12224
+ if (tied && PROP_WORDS[tied[2]]) return `the ${tied[1]}'s ${PROP_WORDS[tied[2]]}`;
12225
+ const parsed = parseExpressionTree(text);
12226
+ if (!("tree" in parsed)) return text;
12227
+ const say = (n, outer = -1) => {
12228
+ const wrap = (s, prec) => prec < outer ? `(${s})` : s;
12229
+ switch (n.t) {
12230
+ case "num":
12231
+ return fmtNum(n.v);
12232
+ case "str":
12233
+ return `"${n.v}"`;
12234
+ case "name":
12235
+ return nameOf(draft, n.v);
12236
+ case "prop":
12237
+ return PROP_WORDS[n.prop] && (draft.roles ?? []).some((r) => r.id === n.role) ? `the ${n.role}'s ${PROP_WORDS[n.prop]}` : `${n.role}.${n.prop}`;
12238
+ case "neg":
12239
+ return wrap(`minus ${say(n.a, PREC.neg)}`, PREC.neg);
12240
+ case "bin": {
12241
+ const prec = PREC[n.op];
12242
+ const op = n.op === "*" ? "×" : n.op === "/" ? "÷" : n.op === "-" ? "−" : "+";
12243
+ return wrap(`${say(n.a, prec)} ${op} ${say(n.b, prec + (n.op === "-" || n.op === "/" ? 1 : 0))}`, prec);
12244
+ }
12245
+ case "cmp": {
12246
+ const words = { "<": "is less than", "<=": "is at most", ">": "is more than", ">=": "is at least", "==": "is", "!=": "is not" };
12247
+ return wrap(`${say(n.a, PREC.cmp + 1)} ${words[n.op]} ${say(n.b, PREC.cmp + 1)}`, PREC.cmp);
12248
+ }
12249
+ case "logic":
12250
+ return wrap(`${say(n.a, PREC.logic)} ${n.op} ${say(n.b, PREC.logic + 1)}`, PREC.logic);
12251
+ case "not":
12252
+ return wrap(`not ${say(n.a, PREC.not)}`, PREC.not);
12253
+ case "tern":
12254
+ return wrap(`${say(n.a, 1)} when ${say(n.c, 1)}, otherwise ${say(n.b, 1)}`, PREC.tern);
12255
+ case "call": {
12256
+ const a = n.args.map((x) => say(x, 0));
12257
+ switch (n.fn) {
12258
+ case "max":
12259
+ return a.length === 1 ? a[0] : `the larger of ${listWords(a, 99).replace(/, ([^,]*)$/, " and $1")}`;
12260
+ case "min":
12261
+ return a.length === 1 ? a[0] : `the smaller of ${listWords(a, 99).replace(/, ([^,]*)$/, " and $1")}`;
12262
+ case "round":
12263
+ return `${a[0]} rounded`;
12264
+ case "ceil":
12265
+ return `${a[0]} rounded up`;
12266
+ case "floor":
12267
+ return `${a[0]} rounded down`;
12268
+ case "abs":
12269
+ return `the size of ${a[0]}`;
12270
+ case "fill":
12271
+ return `how many fit along ${a[0]}, ${a[1]} apart`;
12272
+ case "minEdge":
12273
+ return `the rule-minimum edge distance for ${a[0]}`;
12274
+ case "minWeldLeg":
12275
+ return `the rule-minimum weld size for ${a[0]}`;
12276
+ case "minPitch":
12277
+ return `the rule-minimum bolt spacing for ${a[0]}`;
12278
+ case "holeDia":
12279
+ return `the hole size for ${a[0]}`;
12280
+ case "boltLength":
12281
+ return `the bolt length for a grip of ${a[0]}`;
12282
+ case "lookup":
12283
+ return "a value from a table";
12284
+ default:
12285
+ return `${n.fn}(${a.join(", ")})`;
12286
+ }
12287
+ }
12288
+ default:
12289
+ return text;
12290
+ }
12291
+ };
12292
+ return say(parsed.tree);
12293
+ }
12294
+
11496
12295
  // connection-design-engine.ts
11497
12296
  var rigDigestOf = (rig) => domainHash("floless:connection-design-rig:v1", {
11498
12297
  members: rig.members.map((m) => ({ id: m.id, profile: m.profile, role: m.role, from: m.from, to: m.to, rot: m.rot ?? null, xs: m.xs })),
@@ -11680,6 +12479,7 @@ export {
11680
12479
  buildTrack,
11681
12480
  createDragSession,
11682
12481
  decisionStatuses,
12482
+ describeRule,
11683
12483
  expandDraft,
11684
12484
  geoDigestOf,
11685
12485
  gridFor,
@@ -11691,6 +12491,7 @@ export {
11691
12491
  nearestPassing,
11692
12492
  planDrag,
11693
12493
  rigDigestOf,
12494
+ ruleIssue,
11694
12495
  snapToMark,
11695
12496
  snapValue,
11696
12497
  solveTarget,