@rangefoundry/svg-drawings 0.0.0-stage → 0.1.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 (68) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +22 -2
  3. package/dist/bullet/density.d.ts +65 -0
  4. package/dist/bullet/density.js +91 -0
  5. package/dist/bullet/figure.d.ts +34 -0
  6. package/dist/bullet/figure.js +50 -0
  7. package/dist/bullet/index.d.ts +4 -0
  8. package/dist/bullet/index.js +5 -0
  9. package/dist/bullet/outline.d.ts +144 -0
  10. package/dist/bullet/outline.js +683 -0
  11. package/dist/bullet/profile.d.ts +76 -0
  12. package/dist/bullet/profile.js +257 -0
  13. package/dist/cartridge/callouts.d.ts +18 -0
  14. package/dist/cartridge/callouts.js +153 -0
  15. package/dist/cartridge/detail.d.ts +34 -0
  16. package/dist/cartridge/detail.js +99 -0
  17. package/dist/cartridge/figure.d.ts +59 -0
  18. package/dist/cartridge/figure.js +113 -0
  19. package/dist/cartridge/figures.d.ts +47 -0
  20. package/dist/cartridge/figures.js +54 -0
  21. package/dist/cartridge/focus.d.ts +3 -0
  22. package/dist/cartridge/focus.js +7 -0
  23. package/dist/cartridge/index.d.ts +8 -0
  24. package/dist/cartridge/index.js +8 -0
  25. package/dist/cartridge/profile.d.ts +46 -0
  26. package/dist/cartridge/profile.js +630 -0
  27. package/dist/cartridge/regions.d.ts +28 -0
  28. package/dist/cartridge/regions.js +50 -0
  29. package/dist/core/advances.json +106 -0
  30. package/dist/core/annotate.d.ts +11 -0
  31. package/dist/core/annotate.js +715 -0
  32. package/dist/core/cache.d.ts +4 -0
  33. package/dist/core/cache.js +16 -0
  34. package/dist/core/face.d.ts +56 -0
  35. package/dist/core/face.js +54 -0
  36. package/dist/core/fillet.d.ts +7 -0
  37. package/dist/core/fillet.js +42 -0
  38. package/dist/core/geometry.d.ts +22 -0
  39. package/dist/core/geometry.js +136 -0
  40. package/dist/core/layout.d.ts +46 -0
  41. package/dist/core/layout.js +69 -0
  42. package/dist/core/placer.d.ts +60 -0
  43. package/dist/core/placer.js +291 -0
  44. package/dist/core/section.d.ts +32 -0
  45. package/dist/core/section.js +75 -0
  46. package/dist/core/text.d.ts +19 -0
  47. package/dist/core/text.js +38 -0
  48. package/dist/core/types.d.ts +185 -0
  49. package/dist/core/types.js +2 -0
  50. package/dist/core/units.d.ts +18 -0
  51. package/dist/core/units.js +26 -0
  52. package/dist/core/vector.d.ts +8 -0
  53. package/dist/core/vector.js +23 -0
  54. package/dist/index.d.ts +9 -0
  55. package/dist/index.js +10 -0
  56. package/dist/seating/chamber.d.ts +21 -0
  57. package/dist/seating/chamber.js +23 -0
  58. package/dist/seating/index.d.ts +3 -0
  59. package/dist/seating/index.js +4 -0
  60. package/dist/seating/preview.d.ts +12 -0
  61. package/dist/seating/preview.js +30 -0
  62. package/dist/seating/seating.d.ts +210 -0
  63. package/dist/seating/seating.js +284 -0
  64. package/dist/target/face.d.ts +68 -0
  65. package/dist/target/face.js +50 -0
  66. package/dist/target/index.d.ts +1 -0
  67. package/dist/target/index.js +2 -0
  68. package/package.json +64 -3
@@ -0,0 +1,59 @@
1
+ import { type Drawn as CoreDrawn, type Medium, type ScaleBar } from '../core/layout.ts';
2
+ import type { Layout } from '../core/types.ts';
3
+ import type { LengthUnit } from '../core/units.ts';
4
+ import { type DetailSpec } from './detail.ts';
5
+ import { type Side } from './figures.ts';
6
+ import type { Profile } from './profile.ts';
7
+ import type { Region } from './regions.ts';
8
+ /** The sides of one cartridge figure. */
9
+ export type Drawn = CoreDrawn<Side, Profile>;
10
+ /** Everything one SVG of a figure draws, in mm; paths in the part frame. */
11
+ export interface FigureModel {
12
+ medium: Medium;
13
+ em: number;
14
+ /** viewBox of the outer frame in mm: x, y, width, height. */
15
+ frame: [number, number, number, number];
16
+ cartridge?: {
17
+ section: string;
18
+ edges: string;
19
+ } | undefined;
20
+ chamber?: {
21
+ cavity: string;
22
+ steel: string;
23
+ outline: string;
24
+ breaks: string;
25
+ edges: string;
26
+ /** The head face across the cavity mouth, where a head diameter lies inside the drawn head. */
27
+ face?: string | undefined;
28
+ } | undefined;
29
+ /** The dash-dot axis of each side, from just behind the head to just past its end or a station past it. */
30
+ axis: Partial<Record<Side, [number, number]>>;
31
+ /** The dimensions of each side; the region callouts of Combined. */
32
+ layers: Partial<Record<Side | 'combined', Layout>>;
33
+ /** The 1-2-5 scale bar and the unit note, in the outer frame. */
34
+ scale: ScaleBar;
35
+ /** Screen, when asked for: the detail views its letters open. */
36
+ details: Detail[];
37
+ }
38
+ /**
39
+ * Enlarged view of one feature of a side: `scale` times the half section, cropped to `window`
40
+ * ([minR, minZ, maxR, maxZ], mm at that scale).
41
+ */
42
+ export interface Detail {
43
+ side: Side;
44
+ letter: DetailSpec['letter'];
45
+ scale: number;
46
+ window: [number, number, number, number];
47
+ }
48
+ /** The smallest text size of at least 1.8 mm that renders 11 CSS px when the widest figure fills the 358 px phone column (`fitEm`). */
49
+ export declare const screenEm: (figures: Drawn[], unit?: LengthUnit) => number;
50
+ /**
51
+ * The model of one SVG: the sides laid out at em, in a frame of at least `across` mm across the
52
+ * medium's page direction (figures of one record share the screen width, so their scale), and
53
+ * with both sides the callouts of `regions` in the Combined layer. With `details` on screen, each
54
+ * side's layer gets the letters of its detail views, laid out in a second pass that keeps the
55
+ * frame and every other mark. Length texts in `unit`, the geometry in mm.
56
+ */
57
+ export declare function figureModel(drawn: Drawn, medium: Medium, em: number, across?: number, regions?: Region[], details?: boolean, unit?: LengthUnit): FigureModel;
58
+ /** The width of a figure across the screen column, in mm, at text size em (for the sweep). */
59
+ export declare const screenWidth: (drawn: Drawn, em: number, unit?: LengthUnit) => number;
@@ -0,0 +1,113 @@
1
+ import { annotate } from '../core/annotate.js';
2
+ import { layoutCache } from '../core/cache.js';
3
+ import * as face from '../core/face.js';
4
+ import { axisReach, figureFrame, fitEm, frameWidth, readingDirection, } from '../core/layout.js';
5
+ import { edgeLines, fullSection, headFace, steelBand, steelRadius, svgPath, } from '../core/section.js';
6
+ import { regionCallouts } from './callouts.js';
7
+ import { detailSpecs, detailWindow } from './detail.js';
8
+ import { flagged } from './figures.js';
9
+ /** Lays out the sides of one figure at text size em, once per figure, medium, size and unit. */
10
+ const layouts = layoutCache((drawn, medium, em, unit) => {
11
+ const layers = {};
12
+ const axis = {};
13
+ for (const { side, p } of drawn) {
14
+ axis[side] = axisReach(p);
15
+ layers[side] = annotate(partOf(drawn, side, p, unit), em, readingDirection(medium), axis[side]);
16
+ }
17
+ const boxes = [
18
+ ...Object.values(layers).map((l) => l.box),
19
+ ...Object.values(axis).map(([a, b]) => [a, 0, b, 0]),
20
+ ];
21
+ const box = [0, 1, 2, 3].map((k) => k < 2 ? Math.min(...boxes.map((b) => b[k])) : Math.max(...boxes.map((b) => b[k])));
22
+ return { layers, box, axis };
23
+ });
24
+ /** A side as `annotate()` takes it: its note flags, and the letters of `details`, as callouts. */
25
+ const partOf = (drawn, side, p, unit, details = []) => ({
26
+ points: p.points,
27
+ annotation: p.annotation,
28
+ unit,
29
+ ...(side === 'chamber' ? { outer: steelRadius(p.points) } : {}),
30
+ callouts: [
31
+ ...flagged(drawn).flatMap(({ side: s, note, n }) => s === side && note.at ? [{ owner: `flag ${n}`, text: String(n), at: note.at }] : []),
32
+ ...details.map((d) => ({ owner: `detail ${d.letter}`, text: d.letter, at: d.anchor, letter: true })),
33
+ ],
34
+ });
35
+ /** The smallest text size of at least 1.8 mm that renders 11 CSS px when the widest figure fills the 358 px phone column (`fitEm`). */
36
+ export const screenEm = (figures, unit = 'mm') => fitEm((em) => Math.max(...figures.map((d) => frameWidth(layouts(d, 'screen', em, unit).box, 'screen', em, unit))));
37
+ /**
38
+ * The model of one SVG: the sides laid out at em, in a frame of at least `across` mm across the
39
+ * medium's page direction (figures of one record share the screen width, so their scale), and
40
+ * with both sides the callouts of `regions` in the Combined layer. With `details` on screen, each
41
+ * side's layer gets the letters of its detail views, laid out in a second pass that keeps the
42
+ * frame and every other mark. Length texts in `unit`, the geometry in mm.
43
+ */
44
+ export function figureModel(drawn, medium, em, across = 0, regions = [], details = false, unit = 'mm') {
45
+ const laid = layouts(drawn, medium, em, unit);
46
+ const { axis } = laid;
47
+ const [cartridge, chamber] = ['cartridge', 'chamber'].map((side) => drawn.find((d) => d.side === side)?.p);
48
+ const combined = cartridge && chamber && regions.length
49
+ ? regionCallouts(cartridge, chamber, regions, em, laid.box, unit)
50
+ : undefined;
51
+ const layers = { ...laid.layers, ...(combined ? { combined } : {}) };
52
+ const box = combined ? combined.box : laid.box;
53
+ const turned = medium === 'screen';
54
+ const { frame, scale } = figureFrame(box, medium, em, across, unit);
55
+ const model = { medium, em, frame, axis, layers, scale, details: [] };
56
+ if (details && turned)
57
+ addDetails(model, drawn, unit);
58
+ for (const { side, p } of drawn)
59
+ if (side === 'cartridge')
60
+ model.cartridge = cartridgeModel(p);
61
+ else
62
+ model.chamber = chamberModel(p, em);
63
+ return model;
64
+ }
65
+ /** Adds the detail views of each side to a screen model: their letters laid out in a second pass that keeps the frame and every other mark, and their windows. */
66
+ function addDetails(model, drawn, unit) {
67
+ const { layers, em, medium, axis } = model;
68
+ for (const { side, p } of drawn) {
69
+ const specs = detailSpecs(side, p);
70
+ const layer = layers[side];
71
+ if (!specs.length || !layer)
72
+ continue;
73
+ const lettered = annotate(partOf(drawn, side, p, unit, specs), em, readingDirection(medium), axis[side] ?? [0, 0]);
74
+ const letter = (x) => x.owner.startsWith('detail ');
75
+ layers[side] = {
76
+ ...layer,
77
+ labels: [...layer.labels, ...lettered.labels.filter(letter)],
78
+ segs: [...layer.segs, ...lettered.segs.filter(letter)],
79
+ };
80
+ // the scale at the main view's px per mm on the 390 px page
81
+ const pxPerMm = Math.min(face.pxPerMm, face.phoneColumn / model.frame[2]);
82
+ for (const spec of specs)
83
+ model.details.push({ side, letter: spec.letter, ...detailWindow(spec, pxPerMm) });
84
+ }
85
+ }
86
+ /** The cartridge section and its edge lines, as SVG paths. */
87
+ function cartridgeModel(p) {
88
+ const rMax = Math.max(...p.points.map(([r]) => r));
89
+ return {
90
+ section: svgPath(fullSection(p.points), true),
91
+ edges: edgeLines(p.annotation.edges, rMax)
92
+ .map((l) => svgPath(l))
93
+ .join(''),
94
+ };
95
+ }
96
+ /** The chamber cavity, the steel band, its outline and break lines, the edges and head face, as SVG paths. */
97
+ function chamberModel(p, em) {
98
+ const band = steelBand(p.points, em);
99
+ const head = headFace(p.points, p.annotation);
100
+ return {
101
+ cavity: svgPath(fullSection(p.points), true),
102
+ steel: band.sides.map((s) => svgPath(s.polygon, true)).join(''),
103
+ outline: band.sides.map((s) => svgPath(s.stroke)).join(''),
104
+ breaks: band.sides.map((s) => svgPath(s.zig)).join(''),
105
+ edges: edgeLines(p.annotation.edges, band.outer)
106
+ .map((l) => svgPath(l))
107
+ .join(''),
108
+ ...(head ? { face: svgPath(head) } : {}),
109
+ };
110
+ }
111
+ /** The width of a figure across the screen column, in mm, at text size em (for the sweep). */
112
+ export const screenWidth = (drawn, em, unit = 'mm') => frameWidth(layouts(drawn, 'screen', em, unit).box, 'screen', em, unit);
113
+ //# sourceMappingURL=figure.js.map
@@ -0,0 +1,47 @@
1
+ import type { SpecValue } from '../core/types.ts';
2
+ import { type Profile } from './profile.ts';
3
+ /** The two sides of a record that a figure draws. */
4
+ export type Side = 'cartridge' | 'chamber';
5
+ /** The display name of each side, used in the texts about a side that is not drawn. */
6
+ export declare const sideName: {
7
+ cartridge: string;
8
+ chamber: string;
9
+ };
10
+ /** One figure of a record: the sides drawn (none when no side draws) and the caption notes. */
11
+ export interface Figure {
12
+ /** `<record id>-drawing`, or `<record id>-drawing-<k>` for the variant at index k. */
13
+ id: string;
14
+ variant?: string | undefined;
15
+ drawn: {
16
+ side: Side;
17
+ p: Profile;
18
+ }[];
19
+ /**
20
+ * closedFront first, then per side its missing symbols (code `missing`) or its notes; a note of
21
+ * a drawn side carries the number of its flag.
22
+ */
23
+ notes: {
24
+ code: string;
25
+ text: string;
26
+ flagNumber?: number;
27
+ }[];
28
+ }
29
+ /** The notes of the drawn sides, numbered from 1 in caption order, or by their figure: each has a flag. */
30
+ export declare const flagged: (drawn: {
31
+ side: Side;
32
+ p: Profile;
33
+ }[]) => {
34
+ side: Side;
35
+ note: import("../core/types.ts").Note<import("./profile.ts").NoteCode>;
36
+ n: number;
37
+ }[];
38
+ /**
39
+ * The figures drawn for a cartridge record (`id`: its C.I.P. sheet id): CIP tables I to V and VIII
40
+ * to X one figure (the chamber only behind a closed front), table VII one per variant of l.
41
+ */
42
+ export declare function recordFigures(spec: {
43
+ id: string;
44
+ standard: string;
45
+ table?: string | undefined;
46
+ values: SpecValue[];
47
+ }): Figure[];
@@ -0,0 +1,54 @@
1
+ import { cipProfile, closedFront, drawnTables, shotshellProfile, shotshellVariants, } from './profile.js';
2
+ /** The display name of each side, used in the texts about a side that is not drawn. */
3
+ export const sideName = { cartridge: 'Cartridge', chamber: 'Chamber' };
4
+ /** The notes of the drawn sides, numbered from 1 in caption order, or by their figure: each has a flag. */
5
+ export const flagged = (drawn) => drawn
6
+ .flatMap(({ side, p }) => p.notes.map((note) => ({ side, note })))
7
+ .map((f, k) => ({ ...f, n: f.note.flagNumber ?? k + 1 }));
8
+ /**
9
+ * The figures drawn for a cartridge record (`id`: its C.I.P. sheet id): CIP tables I to V and VIII
10
+ * to X one figure (the chamber only behind a closed front), table VII one per variant of l.
11
+ */
12
+ export function recordFigures(spec) {
13
+ const cip = spec.standard === 'CIP';
14
+ const shotshells = cip && spec.table === 'VII';
15
+ const drawable = cip && drawnTables.has(spec.table ?? '');
16
+ const closed = drawable ? closedFront(spec.values) : undefined;
17
+ const sideList = closed ? ['chamber'] : ['cartridge', 'chamber'];
18
+ return (shotshells ? shotshellVariants(spec.values) : [undefined]).map((variant, k) => {
19
+ let flags = 0;
20
+ // each note of a drawn side numbered in the figure, so a side drawn alone keeps its numbers
21
+ const sides = (shotshells
22
+ ? sideList.map((side) => ({ side, p: shotshellProfile(spec.values, side, variant) }))
23
+ : drawable
24
+ ? sideList.map((side) => ({ side, p: cipProfile(spec.values, side, spec.table) }))
25
+ : []).map(({ side, p }) => ({
26
+ side,
27
+ p: 'missing' in p
28
+ ? p
29
+ : { ...p, notes: p.notes.map((note) => ({ ...note, flagNumber: ++flags })) },
30
+ }));
31
+ const drawn = sides.flatMap(({ side, p }) => ('missing' in p ? [] : [{ side, p }]));
32
+ return {
33
+ // the index in the variant list keeps each figure's id whether or not others draw
34
+ id: variant === undefined ? `${spec.id}-drawing` : `${spec.id}-drawing-${k}`,
35
+ variant,
36
+ drawn,
37
+ notes: [
38
+ ...(closed ? [closed] : []),
39
+ ...sides.flatMap(({ side, p }) => 'missing' in p
40
+ ? [
41
+ {
42
+ code: 'missing',
43
+ text: `${sideName[side]} not drawn: missing ${p.missing.join(', ')}.`,
44
+ },
45
+ ]
46
+ : p.notes),
47
+ ].map((note) => {
48
+ const { flagNumber: n } = note;
49
+ return { code: note.code, text: note.text, ...(n ? { flagNumber: n } : {}) };
50
+ }),
51
+ };
52
+ });
53
+ }
54
+ //# sourceMappingURL=figures.js.map
@@ -0,0 +1,3 @@
1
+ import type { Side } from './figures.ts';
2
+ /** The id of a values table row: letters, digits and hyphens. */
3
+ export declare const rowId: (spec: string, side: Side, symbol: string, variant?: string) => string;
@@ -0,0 +1,7 @@
1
+ /** The id of a values table row: letters, digits and hyphens. */
2
+ export const rowId = (spec, side, symbol, variant) => [spec, side, symbol, variant]
3
+ .filter((x) => x !== undefined)
4
+ .join('-')
5
+ .replace(/[^A-Za-z0-9]+/g, '-')
6
+ .replace(/^-|-$/g, '');
7
+ //# sourceMappingURL=focus.js.map
@@ -0,0 +1,8 @@
1
+ export type { SpecValue } from '../core/types.ts';
2
+ export * from './callouts.ts';
3
+ export * from './detail.ts';
4
+ export * from './figure.ts';
5
+ export * from './figures.ts';
6
+ export * from './focus.ts';
7
+ export * from './profile.ts';
8
+ export * from './regions.ts';
@@ -0,0 +1,8 @@
1
+ export * from './callouts.js';
2
+ export * from './detail.js';
3
+ export * from './figure.js';
4
+ export * from './figures.js';
5
+ export * from './focus.js';
6
+ export * from './profile.js';
7
+ export * from './regions.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,46 @@
1
+ import type { Note as CoreNote, Profile as CoreProfile, SpecValue } from '../core/types.ts';
2
+ import type { Side } from './figures.ts';
3
+ /** The codes of the notes of a cartridge or chamber outline. */
4
+ export type NoteCode = 'cartridgeR' | 'headBelowP1' | 'grooveAngle' | 'grooveDerivedE' | 'beltSkipped' | 'mouthCone' | 'mouthStep' | 'noLeade' | 'noG1' | 'leadeStartBelowH' | 'leadeStartPastG' | 'leadeAngle' | 'throatDatum' | 'iInvalid' | 'closedFront' | 'shoulderOrder' | 'shoulderPartial' | 'shoulderAngle' | 'filletSkipped' | 'chamferSkipped';
5
+ /** A note of a cartridge or chamber outline, coded by `NoteCode`. */
6
+ export type Note = CoreNote<NoteCode>;
7
+ /** The profile of a cartridge or chamber side, with `NoteCode` notes. */
8
+ export type Profile = CoreProfile<NoteCode>;
9
+ /**
10
+ * CIP tables whose symbol meanings were checked against the geometry and
11
+ * that `cipProfile` draws; table VII is drawn by `shotshellProfile`.
12
+ */
13
+ export declare const drawnTables: Set<string>;
14
+ /**
15
+ * The value of a symbol on a side as drawn: with a value, of `variant` when given and stored,
16
+ * else without a variant.
17
+ */
18
+ export declare const storedValue: (values: SpecValue[], side: string, symbol: string, variant?: string | undefined) => SpecValue | undefined;
19
+ /**
20
+ * Names a cartridge whose L3 lies over 0.3 mm past chamber L3 + h, or whose L6 is below its own
21
+ * L3: its front is closed or crimped (blanks, shot), so the cartridge side is not drawn.
22
+ */
23
+ export declare function closedFront(values: SpecValue[]): Note | undefined;
24
+ /**
25
+ * Simplified half-section outline of one side of a CIP record: lengths draw, angles
26
+ * check, and each disagreement becomes a note. Values with a variant are ignored.
27
+ * The chamber recess ends at the chamber's own E, else its own R, else the cartridge R; it is
28
+ * never narrower than P1.
29
+ */
30
+ export declare function cipProfile(values: SpecValue[], side: Side, table?: string | undefined): Profile | {
31
+ missing: string[];
32
+ };
33
+ /** Variants of the cartridge l of a table VII record, or [undefined] when l has none. */
34
+ export declare function shotshellVariants(values: SpecValue[]): (string | undefined)[];
35
+ /**
36
+ * Half section of one side of a CIP table VII record (shotshell): rim g to t, then the body from d
37
+ * at t to h at l (chamber G, T, D, H, L); with l1 and l2 a cone from d at l1 to d2 at l2 (chamber
38
+ * D1 to B). The chamber goes on with the forcing cone from H at L to the bore B at the included
39
+ * angle alpha1, a max limit, so the shortest cone. l and L take the value of the variant, the
40
+ * other symbols their value without one. No head height or crimp: no value gives them.
41
+ */
42
+ export declare function shotshellProfile(values: SpecValue[], side: Side, variant?: string | undefined): Profile | {
43
+ missing: string[];
44
+ };
45
+ /** Symbol, stored value, then tolerance (signed) or limit, as the description gives them. */
46
+ export declare function valueParts(value: SpecValue): string[];