@rulecad/shapes 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/package.json +8 -3
  2. package/shapes.d.mts +26 -0
  3. package/shapes.mjs +12 -0
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@rulecad/shapes",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Shape helpers for printed JSCAD designs: text that prints cleanly, anchors on a face, and clean local cuts.",
5
5
  "type": "module",
6
- "exports": "./shapes.mjs",
6
+ "exports": {
7
+ "types": "./shapes.d.mts",
8
+ "default": "./shapes.mjs"
9
+ },
7
10
  "files": [
8
11
  "shapes.mjs",
12
+ "shapes.d.mts",
9
13
  "README.md",
10
14
  "LICENSE"
11
15
  ],
@@ -34,5 +38,6 @@
34
38
  },
35
39
  "peerDependencies": {
36
40
  "@jscad/modeling": "^2.12.0"
37
- }
41
+ },
42
+ "types": "./shapes.d.mts"
38
43
  }
package/shapes.d.mts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Text as a 2D outline that prints: JSCAD's single-line font, a capital `height` tall, lines `stroke` wide.
3
+ * @param {{ text: string, height: number, stroke: number, segments?: number }} options
4
+ * @returns {object} a JSCAD geom2
5
+ */
6
+ export function text({ text: input, height, stroke, segments }: {
7
+ text: string;
8
+ height: number;
9
+ stroke: number;
10
+ segments?: number;
11
+ }): object;
12
+ /**
13
+ * Where something w × d goes on a face width × depth (centred on 0, y to the back).
14
+ * @param {{ width: number, depth: number }} face @param {[number, number]} size
15
+ * @param {'tl'|'tc'|'tr'|'ml'|'mc'|'mr'|'bl'|'bc'|'br'} [at]
16
+ * @returns {[number, number]}
17
+ */
18
+ export function anchor({ width, depth }: {
19
+ width: number;
20
+ depth: number;
21
+ }, [w, d]: [number, number], at?: "tl" | "tc" | "tr" | "ml" | "mc" | "mr" | "bl" | "bc" | "br"): [number, number];
22
+ /** a with b taken out, cutting only a's faces near b. @param {object} a JSCAD geom3 @param {object} b JSCAD geom3 @param {number} [margin] @returns {object} */
23
+ export function cut(a: object, b: object, margin?: number): object;
24
+ export function size(g: any): number[];
25
+ export const scale: typeof jscad.transforms.scale;
26
+ import jscad from '@jscad/modeling';
package/shapes.mjs CHANGED
@@ -18,6 +18,11 @@ function arrow(char, height) {
18
18
  return [[[0, -h], [0, h]], [[-head, h - head], [0, h], [head, h - head]]].map((l) => l.map(r));
19
19
  }
20
20
 
21
+ /**
22
+ * Text as a 2D outline that prints: JSCAD's single-line font, a capital `height` tall, lines `stroke` wide.
23
+ * @param {{ text: string, height: number, stroke: number, segments?: number }} options
24
+ * @returns {object} a JSCAD geom2
25
+ */
21
26
  export function text({ text: input, height, stroke, segments = 8 }) {
22
27
  if (!input) throw new Error('text: nothing to write');
23
28
  if (input in ARROWS) return union(...arrow(input, height).map((l) => expand({ delta: stroke / 2, corners: 'round', segments }, path2.fromPoints({}, l))));
@@ -46,6 +51,12 @@ export function text({ text: input, height, stroke, segments = 8 }) {
46
51
  return strokes.length > 1 ? union(...strokes) : strokes[0];
47
52
  }
48
53
 
54
+ /**
55
+ * Where something w × d goes on a face width × depth (centred on 0, y to the back).
56
+ * @param {{ width: number, depth: number }} face @param {[number, number]} size
57
+ * @param {'tl'|'tc'|'tr'|'ml'|'mc'|'mr'|'bl'|'bc'|'br'} [at]
58
+ * @returns {[number, number]}
59
+ */
49
60
  export function anchor({ width, depth }, [w, d], at = 'mc') {
50
61
  if (!ANCHORS.includes(at)) throw new Error(`anchor: one of ${ANCHORS.join(', ')} (got "${at}")`);
51
62
  const col = { l: -1, c: 0, r: 1 }[at[1]], row = { t: 1, m: 0, b: -1 }[at[0]];
@@ -55,6 +66,7 @@ export function anchor({ width, depth }, [w, d], at = 'mc') {
55
66
  // cut(a, b): a with b taken out, touching only a's faces near b. JSCAD's subtract splits every face of a along the
56
67
  // planes of b's faces, however far away, and the splits can leave tiny gaps (a keycap's skirt, cut by its legend 8 mm
57
68
  // above). Here the faces clear of b's box pass through unchanged, and only the rest are cut.
69
+ /** a with b taken out, cutting only a's faces near b. @param {object} a JSCAD geom3 @param {object} b JSCAD geom3 @param {number} [margin] @returns {object} */
58
70
  export function cut(a, b, margin = 0.05) {
59
71
  const { geom3 } = jscad.geometries, [lo, hi] = measureBoundingBox(b);
60
72
  const near = [], far = [];