@willcgage/module-schematic 0.28.0 → 0.29.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 +30 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -3
- package/dist/index.d.ts +66 -3
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17,6 +17,24 @@ function benchworkOutline(doc) {
|
|
|
17
17
|
}));
|
|
18
18
|
return pts.length >= 3 ? pts : null;
|
|
19
19
|
}
|
|
20
|
+
function moduleSections(doc) {
|
|
21
|
+
return (doc?.sections ?? []).filter((sec) => sec && typeof sec.id === "string" && sec.id !== "").map((sec) => {
|
|
22
|
+
const outline = benchworkOutline({ outline: sec.outline });
|
|
23
|
+
const name = typeof sec.name === "string" ? sec.name.trim() : "";
|
|
24
|
+
return {
|
|
25
|
+
id: sec.id,
|
|
26
|
+
...name ? { name } : {},
|
|
27
|
+
...outline ? { outline } : {}
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function sectionFootprints(doc) {
|
|
32
|
+
return moduleSections(doc).filter((sec) => sec.outline).map((sec) => ({
|
|
33
|
+
id: sec.id,
|
|
34
|
+
...sec.name ? { name: sec.name } : {},
|
|
35
|
+
outline: sampleBenchworkOutline(sec.outline)
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
20
38
|
function sampleBenchworkOutline(pts, segsPerArc = 20) {
|
|
21
39
|
const n = pts.length;
|
|
22
40
|
if (n < 2) return pts.map((p) => ({ x: p.x, y: p.y }));
|
|
@@ -179,11 +197,13 @@ function moduleFootprint(input) {
|
|
|
179
197
|
const authored = benchworkOutline(input);
|
|
180
198
|
const offA = input.endplateTrackOffsets?.["A"] ?? 0;
|
|
181
199
|
const offB = input.endplateTrackOffsets?.["B"] ?? 0;
|
|
200
|
+
const sectionOutlines = sectionFootprints(input);
|
|
182
201
|
return {
|
|
183
202
|
centerline,
|
|
184
203
|
band: benchworkBand(centerline, widthA, widthB, offA, offB),
|
|
185
204
|
endplateFaces: endplateFaceSegments(centerline, widthA, widthB, offA, offB),
|
|
186
|
-
outline: authored ? sampleBenchworkOutline(authored)
|
|
205
|
+
outline: sectionOutlines.length || !authored ? null : sampleBenchworkOutline(authored),
|
|
206
|
+
sectionOutlines
|
|
187
207
|
};
|
|
188
208
|
}
|
|
189
209
|
function endplateTrackOffsetFor(config, authoredTrackOffset) {
|
|
@@ -204,8 +224,8 @@ function checkEndplateWidth(input) {
|
|
|
204
224
|
requiredInches: FREEMO_ENDPLATE_WIDTH_MIN_INCHES
|
|
205
225
|
});
|
|
206
226
|
}
|
|
207
|
-
const off = input.trackOffsetInches ?? 0;
|
|
208
|
-
const centres = input.config === "double" ? [off
|
|
227
|
+
const off = endplateTrackOffsetInches(input.trackOffsetInches, input.config ?? void 0);
|
|
228
|
+
const centres = input.config === "double" ? [off, off + FREEMO_TRACK_SPACING_INCHES] : [off];
|
|
209
229
|
const worst = Math.max(...centres.map((c) => Math.abs(c)));
|
|
210
230
|
const clearance = width / 2 - worst;
|
|
211
231
|
if (clearance < FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES) {
|
|
@@ -264,6 +284,7 @@ function emptyEditorState(lengthInches) {
|
|
|
264
284
|
endplateTrackOffsets: {},
|
|
265
285
|
outline: [],
|
|
266
286
|
sectionBreaks: [],
|
|
287
|
+
sections: [],
|
|
267
288
|
controlPoints: [],
|
|
268
289
|
industries: [],
|
|
269
290
|
mainPath: []
|
|
@@ -487,6 +508,9 @@ function stateToDoc(state, recordNumber) {
|
|
|
487
508
|
...state.outline.length >= 3 ? { outline: state.outline } : {},
|
|
488
509
|
// Internal section joints (inches from A), when the module has more than one.
|
|
489
510
|
...state.sectionBreaks.length ? { sectionBreaks: state.sectionBreaks } : {},
|
|
511
|
+
// Sections as objects — emitted only once the owner has some, so a module
|
|
512
|
+
// that never used them keeps exactly the doc it had before (#96 phase 2).
|
|
513
|
+
...state.sections.length ? { sections: moduleSections({ sections: state.sections }) } : {},
|
|
490
514
|
// Authored mainline path (module-local inches); only when it's a real path.
|
|
491
515
|
...state.mainPath.length >= 2 ? { mainPath: state.mainPath } : {}
|
|
492
516
|
};
|
|
@@ -592,6 +616,7 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
|
|
|
592
616
|
endplateTrackOffsets,
|
|
593
617
|
outline,
|
|
594
618
|
sectionBreaks: (d.sectionBreaks ?? []).filter((n) => Number.isFinite(n)).map((n) => sc(n)),
|
|
619
|
+
sections: moduleSections(d),
|
|
595
620
|
mainPath,
|
|
596
621
|
crossings: (d.crossings ?? []).map((x) => ({
|
|
597
622
|
id: x.id,
|
|
@@ -1124,12 +1149,14 @@ exports.isTransitionTurnout = isTransitionTurnout;
|
|
|
1124
1149
|
exports.moduleCenterline = moduleCenterline;
|
|
1125
1150
|
exports.moduleFeatures = moduleFeatures;
|
|
1126
1151
|
exports.moduleFootprint = moduleFootprint;
|
|
1152
|
+
exports.moduleSections = moduleSections;
|
|
1127
1153
|
exports.nextId = nextId;
|
|
1128
1154
|
exports.poseNeedsManual = poseNeedsManual;
|
|
1129
1155
|
exports.poseOverridesFromDoc = poseOverridesFromDoc;
|
|
1130
1156
|
exports.sampleBenchworkOutline = sampleBenchworkOutline;
|
|
1131
1157
|
exports.samplePath = samplePath;
|
|
1132
1158
|
exports.scaleFeetToInches = scaleFeetToInches;
|
|
1159
|
+
exports.sectionFootprints = sectionFootprints;
|
|
1133
1160
|
exports.stateToDoc = stateToDoc;
|
|
1134
1161
|
exports.trackPath = trackPath;
|
|
1135
1162
|
//# sourceMappingURL=index.cjs.map
|