@willcgage/module-schematic 0.27.0 → 0.28.1

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.
package/dist/index.cjs CHANGED
@@ -186,8 +186,13 @@ function moduleFootprint(input) {
186
186
  outline: authored ? sampleBenchworkOutline(authored) : null
187
187
  };
188
188
  }
189
- function endplateTrackOffsetFor(config) {
190
- return config === "double" ? FREEMO_TRACK_SPACING_INCHES / 2 : 0;
189
+ function endplateTrackOffsetFor(config, authoredTrackOffset) {
190
+ const v = -endplateTrackOffsetInches(authoredTrackOffset, config);
191
+ return v === 0 ? 0 : v;
192
+ }
193
+ function endplateTrackOffsetInches(authored, config) {
194
+ if (typeof authored === "number" && Number.isFinite(authored)) return authored;
195
+ return config === "double" ? -FREEMO_TRACK_SPACING_INCHES / 2 : 0;
191
196
  }
192
197
  function checkEndplateWidth(input) {
193
198
  const width = endplateWidthInches(input);
@@ -199,8 +204,8 @@ function checkEndplateWidth(input) {
199
204
  requiredInches: FREEMO_ENDPLATE_WIDTH_MIN_INCHES
200
205
  });
201
206
  }
202
- const off = input.trackOffsetInches ?? 0;
203
- const centres = input.config === "double" ? [off - FREEMO_TRACK_SPACING_INCHES / 2, off + FREEMO_TRACK_SPACING_INCHES / 2] : [off];
207
+ const off = endplateTrackOffsetInches(input.trackOffsetInches, input.config ?? void 0);
208
+ const centres = input.config === "double" ? [off, off + FREEMO_TRACK_SPACING_INCHES] : [off];
204
209
  const worst = Math.max(...centres.map((c) => Math.abs(c)));
205
210
  const clearance = width / 2 - worst;
206
211
  if (clearance < FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES) {
@@ -256,6 +261,7 @@ function emptyEditorState(lengthInches) {
256
261
  branches: [],
257
262
  poseOverrides: {},
258
263
  endplateWidths: {},
264
+ endplateTrackOffsets: {},
259
265
  outline: [],
260
266
  sectionBreaks: [],
261
267
  controlPoints: [],
@@ -338,10 +344,14 @@ function withPoses(endplates, overrides) {
338
344
  (e) => overrides[e.id] ? { ...e, pose: overrides[e.id] } : e
339
345
  );
340
346
  }
341
- function withWidths(endplates, widths) {
347
+ function withWidths(endplates, widths, offsets = {}) {
342
348
  return endplates.map((e) => {
343
349
  const w = widths[e.id];
344
- return typeof w === "number" && w > 0 ? { ...e, widthInches: w } : e;
350
+ const o = offsets[e.id];
351
+ let out = e;
352
+ if (typeof w === "number" && w > 0) out = { ...out, widthInches: w };
353
+ if (typeof o === "number" && Number.isFinite(o)) out = { ...out, trackOffsetInches: o };
354
+ return out;
345
355
  });
346
356
  }
347
357
  function stateToDoc(state, recordNumber) {
@@ -390,7 +400,8 @@ function stateToDoc(state, recordNumber) {
390
400
  ],
391
401
  state.poseOverrides
392
402
  ),
393
- state.endplateWidths
403
+ state.endplateWidths,
404
+ state.endplateTrackOffsets
394
405
  ),
395
406
  tracks: [
396
407
  state.loop ? (
@@ -549,9 +560,12 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
549
560
  );
550
561
  const poseOverrides = poseOverridesFromDoc(d);
551
562
  const endplateWidths = {};
563
+ const endplateTrackOffsets = {};
552
564
  for (const e of d.endplates ?? []) {
553
565
  if (typeof e.widthInches === "number" && e.widthInches > 0)
554
566
  endplateWidths[e.id] = e.widthInches;
567
+ if (typeof e.trackOffsetInches === "number" && Number.isFinite(e.trackOffsetInches))
568
+ endplateTrackOffsets[e.id] = e.trackOffsetInches;
555
569
  }
556
570
  const outline = (d.outline ?? []).filter((p) => p && Number.isFinite(p.x) && Number.isFinite(p.y)).map((p) => ({
557
571
  x: p.x,
@@ -575,6 +589,7 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
575
589
  })),
576
590
  poseOverrides,
577
591
  endplateWidths,
592
+ endplateTrackOffsets,
578
593
  outline,
579
594
  sectionBreaks: (d.sectionBreaks ?? []).filter((n) => Number.isFinite(n)).map((n) => sc(n)),
580
595
  mainPath,
@@ -1100,6 +1115,7 @@ exports.docToState = docToState;
1100
1115
  exports.emptyEditorState = emptyEditorState;
1101
1116
  exports.endplateFaceSegments = endplateFaceSegments;
1102
1117
  exports.endplateTrackOffsetFor = endplateTrackOffsetFor;
1118
+ exports.endplateTrackOffsetInches = endplateTrackOffsetInches;
1103
1119
  exports.endplateWidthInches = endplateWidthInches;
1104
1120
  exports.geometryTurnDegrees = geometryTurnDegrees;
1105
1121
  exports.inchesToScaleFeet = inchesToScaleFeet;