@willcgage/module-schematic 0.37.0 → 0.39.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,12 +9,6 @@ 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
- }
18
12
  function benchworkOutline(doc) {
19
13
  const pts = (doc?.outline ?? []).filter((p) => p && Number.isFinite(p.x) && Number.isFinite(p.y)).map((p) => ({
20
14
  x: p.x,
@@ -565,10 +559,10 @@ function emptyEditorState(lengthInches) {
565
559
  outline: [],
566
560
  sectionBreaks: [],
567
561
  sections: [],
568
- orientation: "east-west",
569
562
  controlPoints: [],
570
563
  industries: [],
571
- mainPath: []
564
+ mainPath: [],
565
+ main2Path: []
572
566
  };
573
567
  }
574
568
  function isTransitionTurnout(t) {
@@ -594,15 +588,17 @@ function main2Track(state) {
594
588
  const bothDouble = state.configA === "double" && state.configB === "double";
595
589
  const sws = state.turnouts.filter((t) => isTransitionTurnout(t) && t.divergeTrack === MAIN2_TRACK_ID).sort((a, b) => a.pos - b.pos);
596
590
  const lane = state.mainsSwapped ? 0 : 1;
591
+ const authored = state.main2Path.length >= 2 ? { path: state.main2Path } : {};
597
592
  if (bothDouble || !sws.length) {
598
- return { id: MAIN2_TRACK_ID, role: "main", lane, from: "A", to: "B" };
593
+ return { id: MAIN2_TRACK_ID, role: "main", lane, from: "A", to: "B", ...authored };
599
594
  }
600
595
  const track = (fromPos, toPos) => ({
601
596
  id: MAIN2_TRACK_ID,
602
597
  role: "main",
603
598
  lane,
604
599
  fromPos,
605
- toPos
600
+ toPos,
601
+ ...authored
606
602
  });
607
603
  if (state.configA === "double") return track(0, sws[0].pos);
608
604
  if (state.configB === "double") return track(sws[0].pos, state.lengthInches);
@@ -802,11 +798,9 @@ function stateToDoc(state, recordNumber) {
802
798
  // Sections as objects — emitted only once the owner has some, so a module
803
799
  // that never used them keeps exactly the doc it had before (#96 phase 2).
804
800
  ...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 } : {},
808
801
  // Authored mainline path (module-local inches); only when it's a real path.
809
- ...state.mainPath.length >= 2 ? { mainPath: state.mainPath } : {}
802
+ ...state.mainPath.length >= 2 ? { mainPath: state.mainPath } : {},
803
+ ...state.main2Path.length >= 2 ? { main2Path: state.main2Path } : {}
810
804
  };
811
805
  }
812
806
  function docToState(doc, fallbackLength, moduleTracks = []) {
@@ -891,6 +885,8 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
891
885
  ...Number.isFinite(p.bulge) && p.bulge ? { bulge: p.bulge } : {}
892
886
  }));
893
887
  const mainPath = trackPath(d.mainPath) ?? [];
888
+ const main2Track_ = (d.tracks ?? []).find((t) => t.id === MAIN2_TRACK_ID);
889
+ const main2Path = trackPath(d.main2Path ?? main2Track_?.path) ?? [];
894
890
  return {
895
891
  lengthInches: len,
896
892
  loop,
@@ -911,8 +907,8 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
911
907
  outline,
912
908
  sectionBreaks: (d.sectionBreaks ?? []).filter((n) => Number.isFinite(n)).map((n) => sc(n)),
913
909
  sections: moduleSections(d),
914
- orientation: d.orientation === "north-south" ? "north-south" : "east-west",
915
910
  mainPath,
911
+ main2Path,
916
912
  crossings: (d.crossings ?? []).map((x) => ({
917
913
  id: x.id,
918
914
  name: x.name ?? "",
@@ -1447,8 +1443,6 @@ exports.deriveEndplatePoses = deriveEndplatePoses;
1447
1443
  exports.divergeSideForHand = divergeSideForHand;
1448
1444
  exports.docToState = docToState;
1449
1445
  exports.emptyEditorState = emptyEditorState;
1450
- exports.endLabels = endLabels;
1451
- exports.endLabelsLong = endLabelsLong;
1452
1446
  exports.endplateFaceSegments = endplateFaceSegments;
1453
1447
  exports.endplateTrackOffsetFor = endplateTrackOffsetFor;
1454
1448
  exports.endplateTrackOffsetInches = endplateTrackOffsetInches;