@willcgage/module-schematic 0.35.0 → 0.37.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.
package/dist/index.cjs CHANGED
@@ -9,6 +9,12 @@ function endplateWidthInches(ep) {
9
9
  const w = ep?.widthInches;
10
10
  return typeof w === "number" && w > 0 ? w : FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES;
11
11
  }
12
+ function endLabels(o) {
13
+ return o === "north-south" ? { a: "S", b: "N" } : { a: "W", b: "E" };
14
+ }
15
+ function endLabelsLong(o) {
16
+ return o === "north-south" ? { a: "South", b: "North" } : { a: "West", b: "East" };
17
+ }
12
18
  function benchworkOutline(doc) {
13
19
  const pts = (doc?.outline ?? []).filter((p) => p && Number.isFinite(p.x) && Number.isFinite(p.y)).map((p) => ({
14
20
  x: p.x,
@@ -207,6 +213,35 @@ function sectionSpans(doc) {
207
213
  }
208
214
  return out;
209
215
  }
216
+ function sectionSpansOrWhole(doc, lengthInches) {
217
+ const L = lengthInches > 0 ? lengthInches : 0;
218
+ const spans = sectionSpans(doc);
219
+ if (!spans.length) return [{ id: WHOLE_MODULE_SECTION_ID, fromPos: 0, toPos: L }];
220
+ const out = spans.map((sp) => ({ ...sp }));
221
+ const last = out[out.length - 1];
222
+ if (L > last.toPos) last.toPos = L;
223
+ return out;
224
+ }
225
+ var WHOLE_MODULE_SECTION_ID = "module";
226
+ function toSectionRelative(pos, spans) {
227
+ if (!spans.length) return null;
228
+ const p = Math.max(spans[0].fromPos, Math.min(spans[spans.length - 1].toPos, pos));
229
+ for (const sp of spans) {
230
+ if (p >= sp.fromPos && p < sp.toPos)
231
+ return { sectionId: sp.id, offsetInches: round3(p - sp.fromPos) };
232
+ }
233
+ const last = spans[spans.length - 1];
234
+ return { sectionId: last.id, offsetInches: round3(last.toPos - last.fromPos) };
235
+ }
236
+ function fromSectionRelative(rel, spans) {
237
+ const sp = spans.find((x) => x.id === rel.sectionId);
238
+ if (!sp) return null;
239
+ return round3(sp.fromPos + Math.max(0, Math.min(sp.toPos - sp.fromPos, rel.offsetInches)));
240
+ }
241
+ function remapPos(pos, before, after) {
242
+ const rel = toSectionRelative(pos, before);
243
+ return rel ? fromSectionRelative(rel, after) : null;
244
+ }
210
245
  function sectionBreaksFromSections(doc) {
211
246
  const spans = sectionSpans(doc);
212
247
  return spans.slice(0, -1).map((sp) => sp.toPos);
@@ -483,6 +518,7 @@ function checkEndplateWidth(input) {
483
518
  return issues;
484
519
  }
485
520
  var round2 = (n) => Math.round(n * 100) / 100;
521
+ var round3 = (n) => Math.round(n * 1e3) / 1e3;
486
522
  function endplateWidthFor(widths, id) {
487
523
  const w = widths?.[id];
488
524
  return typeof w === "number" && w > 0 ? w : FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES;
@@ -529,6 +565,7 @@ function emptyEditorState(lengthInches) {
529
565
  outline: [],
530
566
  sectionBreaks: [],
531
567
  sections: [],
568
+ orientation: "east-west",
532
569
  controlPoints: [],
533
570
  industries: [],
534
571
  mainPath: []
@@ -765,6 +802,9 @@ function stateToDoc(state, recordNumber) {
765
802
  // Sections as objects — emitted only once the owner has some, so a module
766
803
  // that never used them keeps exactly the doc it had before (#96 phase 2).
767
804
  ...state.sections.length ? { sections: moduleSections({ sections: state.sections }) } : {},
805
+ // Emitted only when it isn't the east/west default, so existing docs are
806
+ // byte-identical.
807
+ ...state.orientation === "north-south" ? { orientation: state.orientation } : {},
768
808
  // Authored mainline path (module-local inches); only when it's a real path.
769
809
  ...state.mainPath.length >= 2 ? { mainPath: state.mainPath } : {}
770
810
  };
@@ -871,6 +911,7 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
871
911
  outline,
872
912
  sectionBreaks: (d.sectionBreaks ?? []).filter((n) => Number.isFinite(n)).map((n) => sc(n)),
873
913
  sections: moduleSections(d),
914
+ orientation: d.orientation === "north-south" ? "north-south" : "east-west",
874
915
  mainPath,
875
916
  crossings: (d.crossings ?? []).map((x) => ({
876
917
  id: x.id,
@@ -1393,6 +1434,7 @@ exports.MAIN2_TRACK_ID = MAIN2_TRACK_ID;
1393
1434
  exports.MAIN_TRACK_ID = MAIN_TRACK_ID;
1394
1435
  exports.N_CAR_LENGTH_INCHES = N_CAR_LENGTH_INCHES;
1395
1436
  exports.N_SCALE_RATIO = N_SCALE_RATIO;
1437
+ exports.WHOLE_MODULE_SECTION_ID = WHOLE_MODULE_SECTION_ID;
1396
1438
  exports.asModuleSchematic = asModuleSchematic;
1397
1439
  exports.benchworkBand = benchworkBand;
1398
1440
  exports.benchworkOutline = benchworkOutline;
@@ -1405,10 +1447,13 @@ exports.deriveEndplatePoses = deriveEndplatePoses;
1405
1447
  exports.divergeSideForHand = divergeSideForHand;
1406
1448
  exports.docToState = docToState;
1407
1449
  exports.emptyEditorState = emptyEditorState;
1450
+ exports.endLabels = endLabels;
1451
+ exports.endLabelsLong = endLabelsLong;
1408
1452
  exports.endplateFaceSegments = endplateFaceSegments;
1409
1453
  exports.endplateTrackOffsetFor = endplateTrackOffsetFor;
1410
1454
  exports.endplateTrackOffsetInches = endplateTrackOffsetInches;
1411
1455
  exports.endplateWidthInches = endplateWidthInches;
1456
+ exports.fromSectionRelative = fromSectionRelative;
1412
1457
  exports.geometryTurnDegrees = geometryTurnDegrees;
1413
1458
  exports.inchesToScaleFeet = inchesToScaleFeet;
1414
1459
  exports.isLoopDoc = isLoopDoc;
@@ -1421,6 +1466,7 @@ exports.moduleSections = moduleSections;
1421
1466
  exports.nextId = nextId;
1422
1467
  exports.poseNeedsManual = poseNeedsManual;
1423
1468
  exports.poseOverridesFromDoc = poseOverridesFromDoc;
1469
+ exports.remapPos = remapPos;
1424
1470
  exports.sampleBenchworkOutline = sampleBenchworkOutline;
1425
1471
  exports.samplePath = samplePath;
1426
1472
  exports.scaleFeetToInches = scaleFeetToInches;
@@ -1431,10 +1477,12 @@ exports.sectionComponents = sectionComponents;
1431
1477
  exports.sectionFootprints = sectionFootprints;
1432
1478
  exports.sectionNeighbours = sectionNeighbours;
1433
1479
  exports.sectionSpans = sectionSpans;
1480
+ exports.sectionSpansOrWhole = sectionSpansOrWhole;
1434
1481
  exports.sectionedCenterline = sectionedCenterline;
1435
1482
  exports.sectionedEndPose = sectionedEndPose;
1436
1483
  exports.sliceCenterline = sliceCenterline;
1437
1484
  exports.stateToDoc = stateToDoc;
1485
+ exports.toSectionRelative = toSectionRelative;
1438
1486
  exports.trackPath = trackPath;
1439
1487
  //# sourceMappingURL=index.cjs.map
1440
1488
  //# sourceMappingURL=index.cjs.map