@thi.ng/axidraw 1.1.38 → 1.1.40

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/commands.js CHANGED
@@ -1,94 +1,58 @@
1
- export const START = ["start"];
2
- export const STOP = ["stop"];
3
- export const HOME = ["home"];
4
- export const RESET = ["reset"];
5
- export const ON = ["on"];
6
- export const OFF = ["off"];
7
- export const SAVE = ["save"];
8
- export const RESTORE = ["restore"];
9
- /**
10
- * Creates a {@link PenConfigCommand} using provided down/up positions.
11
- *
12
- * @param posDown
13
- * @param posUp
14
- */
15
- export const PEN = (posDown, posUp) => [
16
- "pen",
17
- posDown,
18
- posUp,
1
+ const START = ["start"];
2
+ const STOP = ["stop"];
3
+ const HOME = ["home"];
4
+ const RESET = ["reset"];
5
+ const ON = ["on"];
6
+ const OFF = ["off"];
7
+ const SAVE = ["save"];
8
+ const RESTORE = ["restore"];
9
+ const PEN = (posDown, posUp) => [
10
+ "pen",
11
+ posDown,
12
+ posUp
19
13
  ];
20
- /**
21
- * Creates a {@link PenUpDownCommand} to move the pen up. Both args are optional
22
- * and if omitted globally configured values are used.
23
- *
24
- * @param delay
25
- * @param level
26
- */
27
- export const UP = (delay, level) => [
28
- "u",
29
- delay,
30
- level,
14
+ const UP = (delay, level) => [
15
+ "u",
16
+ delay,
17
+ level
31
18
  ];
32
- /**
33
- * Creates a {@link PenUpDownCommand} to move the pen down. Both args are
34
- * optional and if omitted globally configured values are used.
35
- *
36
- * @param delay
37
- * @param level
38
- */
39
- export const DOWN = (delay, level) => [
40
- "d",
41
- delay,
42
- level,
19
+ const DOWN = (delay, level) => [
20
+ "d",
21
+ delay,
22
+ level
43
23
  ];
44
- /**
45
- * Creates a {@link MoveXYCommand} command (absolute coordinates).
46
- *
47
- * @param pos
48
- * @param speed
49
- */
50
- export const MOVE = (pos, speed = 1) => [
51
- "M",
52
- pos,
53
- speed,
24
+ const MOVE = (pos, speed = 1) => [
25
+ "M",
26
+ pos,
27
+ speed
54
28
  ];
55
- /**
56
- * Creates a {@link MoveRelCommand} command (relative coordinates).
57
- *
58
- * @param delta
59
- * @param speed
60
- */
61
- export const MOVE_REL = (delta, speed = 1) => [
62
- "m",
63
- delta,
64
- speed,
29
+ const MOVE_REL = (delta, speed = 1) => [
30
+ "m",
31
+ delta,
32
+ speed
65
33
  ];
66
- /**
67
- * Creates a {@link WaitCommand}. Default delay is 1000 ms.
68
- *
69
- * @param delay
70
- */
71
- export const WAIT = (delay = 1000) => ["w", delay];
72
- /**
73
- * Creates a {@link CommentCommand}.
74
- *
75
- * @param msg
76
- */
77
- export const COMMENT = (msg) => ["comment", msg];
78
- /**
79
- * Syntax sugar. Takes an iterable of draw commands, adds {@link START} as
80
- * prefix and {@link STOP} as suffix. I.e. it creates a "complete" drawing...
81
- *
82
- * @example
83
- * ```ts
84
- * [...complete([ MOVE([0, 0]) ])]
85
- * // [ ["start"], ["M", [0, 0]], ["stop"] ]
86
- * ```
87
- *
88
- * @param commands
89
- */
90
- export function* complete(commands) {
91
- yield START;
92
- yield* commands;
93
- yield STOP;
34
+ const WAIT = (delay = 1e3) => ["w", delay];
35
+ const COMMENT = (msg) => ["comment", msg];
36
+ function* complete(commands) {
37
+ yield START;
38
+ yield* commands;
39
+ yield STOP;
94
40
  }
41
+ export {
42
+ COMMENT,
43
+ DOWN,
44
+ HOME,
45
+ MOVE,
46
+ MOVE_REL,
47
+ OFF,
48
+ ON,
49
+ PEN,
50
+ RESET,
51
+ RESTORE,
52
+ SAVE,
53
+ START,
54
+ STOP,
55
+ UP,
56
+ WAIT,
57
+ complete
58
+ };
package/control.js CHANGED
@@ -1,35 +1,30 @@
1
1
  import { AxiDrawState } from "./api.js";
2
- /**
3
- * Default implementation with easy-to-use API to control the processing of draw
4
- * commands via {@link AxiDraw.draw}.
5
- *
6
- * @remarks
7
- * See {@link AxiDrawOpts.control} for further details.
8
- */
9
- export class AxiDrawControl {
10
- interval;
11
- state = AxiDrawState.CONTINUE;
12
- constructor(interval = 1000) {
13
- this.interval = interval;
2
+ class AxiDrawControl {
3
+ constructor(interval = 1e3) {
4
+ this.interval = interval;
5
+ }
6
+ state = AxiDrawState.CONTINUE;
7
+ deref() {
8
+ return this.state;
9
+ }
10
+ reset() {
11
+ this.state = AxiDrawState.CONTINUE;
12
+ return this;
13
+ }
14
+ pause() {
15
+ if (this.state === AxiDrawState.CONTINUE) {
16
+ this.state = AxiDrawState.PAUSE;
14
17
  }
15
- deref() {
16
- return this.state;
17
- }
18
- reset() {
19
- this.state = AxiDrawState.CONTINUE;
20
- return this;
21
- }
22
- pause() {
23
- if (this.state === AxiDrawState.CONTINUE) {
24
- this.state = AxiDrawState.PAUSE;
25
- }
26
- }
27
- resume() {
28
- if (this.state === AxiDrawState.PAUSE) {
29
- this.state = AxiDrawState.CONTINUE;
30
- }
31
- }
32
- cancel() {
33
- this.state = AxiDrawState.CANCEL;
18
+ }
19
+ resume() {
20
+ if (this.state === AxiDrawState.PAUSE) {
21
+ this.state = AxiDrawState.CONTINUE;
34
22
  }
23
+ }
24
+ cancel() {
25
+ this.state = AxiDrawState.CANCEL;
26
+ }
35
27
  }
28
+ export {
29
+ AxiDrawControl
30
+ };
package/dip.js CHANGED
@@ -1,52 +1,17 @@
1
1
  import { flatten1 } from "@thi.ng/transducers/flatten1";
2
2
  import { repeatedly } from "@thi.ng/transducers/repeatedly";
3
3
  import { DOWN, RESTORE, SAVE, UP } from "./commands.js";
4
- /**
5
- * Yields a **sequence** of `n` repetitions of {@link DOWN}, {@link UP}
6
- * commands, optionally interspersed with other user provided
7
- * {@link DrawCommand}s, e.g. for dipping & moving a brush a few times into a
8
- * paint reservoir to refill.
9
- *
10
- * @example
11
- * ```ts
12
- * // simple 2x up/down
13
- * [...DIP(2)]
14
- * // [
15
- * // [ "d", undefined ],
16
- * // [ "u", undefined ],
17
- * // [ "d", undefined ],
18
- * // [ "u", undefined ],
19
- * // ]
20
- *
21
- * // 3x dipping with custom up/down delays, each time at a random position
22
- * [...DIP(3, {
23
- * down: 300,
24
- * up: 400,
25
- * commands: () => [ MOVE([Math.random()* 5, Math.random()* 5]) ]
26
- * })]
27
- * // [
28
- * // [ "d", 300 ],
29
- * // [ "M", [ 3.996, 1.707 ], 1 ],
30
- * // [ "u", 400 ],
31
- * // [ "d", 300 ],
32
- * // [ "M", [ 4.747, 4.925 ], 1 ],
33
- * // [ "u", 400 ],
34
- * // [ "d", 300 ],
35
- * // [ "M", [ 1.751, 0.670 ], 1 ],
36
- * // [ "u", 400 ]
37
- * // ]
38
- * ```
39
- *
40
- * @param n
41
- * @param opts
42
- */
43
- export const dip = (n, opts = {}) => {
44
- const down = DOWN(opts.downDelay, opts.down);
45
- const up = UP(opts.upDelay, opts.up);
46
- const main = flatten1(repeatedly(opts.commands
47
- ? () => [down, ...opts.commands(), up]
48
- : () => [down, up], n));
49
- return opts.down !== undefined || opts.up !== undefined
50
- ? [SAVE, ...main, RESTORE]
51
- : main;
4
+ const dip = (n, opts = {}) => {
5
+ const down = DOWN(opts.downDelay, opts.down);
6
+ const up = UP(opts.upDelay, opts.up);
7
+ const main = flatten1(
8
+ repeatedly(
9
+ opts.commands ? () => [down, ...opts.commands(), up] : () => [down, up],
10
+ n
11
+ )
12
+ );
13
+ return opts.down !== void 0 || opts.up !== void 0 ? [SAVE, ...main, RESTORE] : main;
14
+ };
15
+ export {
16
+ dip
52
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/axidraw",
3
- "version": "1.1.38",
3
+ "version": "1.1.40",
4
4
  "description": "Minimal AxiDraw plotter/drawing machine controller for Node.js",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,21 +35,21 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.10",
37
- "@thi.ng/checks": "^3.4.10",
38
- "@thi.ng/compose": "^2.1.49",
39
- "@thi.ng/date": "^2.5.4",
40
- "@thi.ng/errors": "^2.4.4",
41
- "@thi.ng/logger": "^2.0.1",
42
- "@thi.ng/math": "^5.7.5",
43
- "@thi.ng/transducers": "^8.8.13",
44
- "@thi.ng/units": "^0.4.17",
45
- "@thi.ng/vectors": "^7.8.7",
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/checks": "^3.4.12",
40
+ "@thi.ng/compose": "^2.1.51",
41
+ "@thi.ng/date": "^2.5.6",
42
+ "@thi.ng/errors": "^2.4.6",
43
+ "@thi.ng/logger": "^2.0.2",
44
+ "@thi.ng/math": "^5.7.7",
45
+ "@thi.ng/transducers": "^8.8.15",
46
+ "@thi.ng/units": "^0.4.19",
47
+ "@thi.ng/vectors": "^7.8.9",
46
48
  "serialport": "^12.0.0"
47
49
  },
48
50
  "devDependencies": {
49
51
  "@microsoft/api-extractor": "^7.38.3",
50
- "@thi.ng/testament": "^0.4.3",
52
+ "esbuild": "^0.19.8",
51
53
  "rimraf": "^5.0.5",
52
54
  "tools": "^0.0.1",
53
55
  "typedoc": "^0.25.4",
@@ -114,5 +116,5 @@
114
116
  "status": "alpha",
115
117
  "year": 2022
116
118
  },
117
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
119
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
118
120
  }
package/palettes.js CHANGED
@@ -7,139 +7,75 @@ import { madd2 } from "@thi.ng/vectors/madd";
7
7
  import { maddN2 } from "@thi.ng/vectors/maddn";
8
8
  import { MOVE } from "./commands.js";
9
9
  import { dip } from "./dip.js";
10
- /**
11
- * Higher order {@link DrawCommand} sequence generator for working with paint
12
- * brushes. Takes an config object describing a linear paint palette layout and
13
- * behavior options for dipping the brush. Returns a function which takes a
14
- * palette slot index as argument and returns a command sequence moving the
15
- * plotter to the palette slot and dipping the brush to refill.
16
- *
17
- * @remarks
18
- * Can be used with
19
- * [InterleaveOpts](https://docs.thi.ng/umbrella/geom-axidraw/interfaces/InterleaveOpts.html)
20
- * of https://thi.ng/geom-axidraw.
21
- *
22
- * Also see:
23
- * - {@link LinearPaletteOpts} for options
24
- * - {@link radialPalette} for circular/elliptical palette layouts
25
- * - {@link dip} (used internally for dipping sequence)
26
- *
27
- * @example
28
- * ```ts
29
- * import { points } from "@thi.ng/geom";
30
- * import { asAxiDraw } from "@thi.ng/geom-axidraw";
31
- * import { repeatedly } from "@thi.ng/transducers";
32
- * import { randMinMax2 } from "@thi.ng/vectors";
33
- *
34
- * // configure palette
35
- * const palette = linearPalette({
36
- * // first palette slot is near the world origin (slight offset)
37
- * pos: [2, 0],
38
- * // palette has 5 paint slots
39
- * num: 5,
40
- * // each slot 40mm separation along Y-axis
41
- * // (needs to be measured/determined manually)
42
- * step: [0, 40],
43
- * // 2mm jitter radius (to not always move to exact same position)
44
- * jitter: 2,
45
- * // dip brush 3x each time
46
- * repeat: 3,
47
- * });
48
- *
49
- * // investigate command sequence for requesting slot #1
50
- * palette(1)
51
- * // [
52
- * // [ "M", [ 0.8949, 41.6697 ], 1 ],
53
- * // [ "d", undefined, undefined ],
54
- * // [ "u", undefined, undefined ],
55
- * // [ "d", undefined, undefined ],
56
- * // [ "u", undefined, undefined ],
57
- * // [ "d", undefined, undefined ],
58
- * // [ "u", undefined, undefined ]
59
- * // ]
60
- *
61
- * // define point cloud of 100 random points
62
- * // using a random palette slot each time (for each refill)
63
- * // assign axidraw-specific attribs to refill brush every 10 dots
64
- * const cloud = points(
65
- * [...repeatedly(() => randMinMax2([], [10, 10], [190, 190]), 100)],
66
- * {
67
- * __axi: {
68
- * interleave: {
69
- * num: 10,
70
- * commands: () => palette((Math.random() * 5) | 0)
71
- * }
72
- * }
73
- * }
74
- * );
75
- *
76
- * // AxiDraw setup
77
- * const axi = new AxiDraw();
78
- * ...
79
- *
80
- * // convert geometry into axidraw commands and send to plotter
81
- * axi.draw(asAxiDraw(cloud));
82
- * ```
83
- *
84
- * @param opts
85
- */
86
- export const linearPalette = (opts) => {
87
- const $opts = {
88
- pos: [0, 0],
89
- repeat: 1,
90
- jitter: 0,
91
- ...opts,
92
- };
93
- const dipOpts = __dipOpts($opts);
94
- return (id) => {
95
- if (id < 0 || id >= $opts.num) {
96
- illegalArgs(`invalid palette index: ${id}`);
97
- }
98
- return [
99
- MOVE(jitter(null, maddN2([], $opts.step, id, $opts.pos), $opts.jitter)),
100
- ...dip($opts.repeat, dipOpts),
101
- ];
102
- };
10
+ const linearPalette = (opts) => {
11
+ const $opts = {
12
+ pos: [0, 0],
13
+ repeat: 1,
14
+ jitter: 0,
15
+ ...opts
16
+ };
17
+ const dipOpts = __dipOpts($opts);
18
+ return (id) => {
19
+ if (id < 0 || id >= $opts.num) {
20
+ illegalArgs(`invalid palette index: ${id}`);
21
+ }
22
+ return [
23
+ MOVE(
24
+ jitter(
25
+ null,
26
+ maddN2([], $opts.step, id, $opts.pos),
27
+ $opts.jitter
28
+ )
29
+ ),
30
+ ...dip($opts.repeat, dipOpts)
31
+ ];
32
+ };
103
33
  };
104
- /**
105
- * Higher order {@link DrawCommand} sequence generator for working with paint
106
- * brushes. Similar to {@link linearPalette}, but for circular or elliptic
107
- * palette layouts.
108
- *
109
- * @remarks
110
- * Also see:
111
- * - {@link RadialPaletteOpts} for options
112
- * - {@link linearPalette} for more details & code example
113
- * - {@link dip} (used internally for dipping sequence)
114
- *
115
- * @param opts
116
- */
117
- export const radialPalette = (opts) => {
118
- const $opts = {
119
- repeat: 1,
120
- jitter: 0,
121
- startTheta: 0,
122
- endTheta: Math.PI * 2,
123
- ...opts,
124
- };
125
- const radius = isNumber($opts.radius)
126
- ? [$opts.radius, $opts.radius]
127
- : $opts.radius;
128
- const dipOpts = __dipOpts($opts);
129
- return (id) => {
130
- if (id < 0 || id >= $opts.num) {
131
- illegalArgs(`invalid palette index: ${id}`);
132
- }
133
- return [
134
- MOVE(jitter(null, madd2(null, cossin(mix($opts.startTheta, $opts.endTheta, id / $opts.num)), radius, $opts.pos), $opts.jitter)),
135
- ...dip($opts.repeat, dipOpts),
136
- ];
137
- };
34
+ const radialPalette = (opts) => {
35
+ const $opts = {
36
+ repeat: 1,
37
+ jitter: 0,
38
+ startTheta: 0,
39
+ endTheta: Math.PI * 2,
40
+ ...opts
41
+ };
42
+ const radius = isNumber($opts.radius) ? [$opts.radius, $opts.radius] : $opts.radius;
43
+ const dipOpts = __dipOpts($opts);
44
+ return (id) => {
45
+ if (id < 0 || id >= $opts.num) {
46
+ illegalArgs(`invalid palette index: ${id}`);
47
+ }
48
+ return [
49
+ MOVE(
50
+ jitter(
51
+ null,
52
+ madd2(
53
+ null,
54
+ cossin(
55
+ mix(
56
+ $opts.startTheta,
57
+ $opts.endTheta,
58
+ id / $opts.num
59
+ )
60
+ ),
61
+ radius,
62
+ $opts.pos
63
+ ),
64
+ $opts.jitter
65
+ )
66
+ ),
67
+ ...dip($opts.repeat, dipOpts)
68
+ ];
69
+ };
138
70
  };
139
71
  const __dipOpts = (opts) => ({
140
- down: opts.down,
141
- downDelay: opts.downDelay,
142
- up: opts.up,
143
- upDelay: opts.upDelay,
144
- commands: opts.commands,
72
+ down: opts.down,
73
+ downDelay: opts.downDelay,
74
+ up: opts.up,
75
+ upDelay: opts.upDelay,
76
+ commands: opts.commands
145
77
  });
78
+ export {
79
+ linearPalette,
80
+ radialPalette
81
+ };
package/polyline.js CHANGED
@@ -1,37 +1,27 @@
1
1
  import { DOWN, MOVE, PEN, UP } from "./commands.js";
2
- /**
3
- * Takes an array of 2D points and yields an iterable of {@link DrawCommand}s.
4
- * The drawing behavior can be customized via additional {@link PolylineOpts}
5
- * given.
6
- *
7
- * @remarks
8
- * The resulting command sequence assumes the pen is in the **up** position at
9
- * the beginning of the line. Each polyline will end with a {@link UP} command.
10
- *
11
- * @param pts
12
- * @param opts
13
- */
14
- export function* polyline(pts, opts) {
15
- if (!pts.length)
16
- return;
17
- const { speed, delayDown, delayUp, down, onlyGeo } = {
18
- speed: 1,
19
- onlyGeo: false,
20
- ...opts,
21
- };
22
- if (onlyGeo) {
23
- for (let p of pts)
24
- yield MOVE(p, speed);
25
- return;
26
- }
27
- yield MOVE(pts[0]);
28
- if (down !== undefined)
29
- yield PEN(down);
30
- yield DOWN(delayDown);
31
- for (let i = 1, n = pts.length; i < n; i++)
32
- yield MOVE(pts[i], speed);
33
- yield UP(delayUp);
34
- // reset pen to configured defaults
35
- if (down !== undefined)
36
- yield PEN();
2
+ function* polyline(pts, opts) {
3
+ if (!pts.length)
4
+ return;
5
+ const { speed, delayDown, delayUp, down, onlyGeo } = {
6
+ speed: 1,
7
+ onlyGeo: false,
8
+ ...opts
9
+ };
10
+ if (onlyGeo) {
11
+ for (let p of pts)
12
+ yield MOVE(p, speed);
13
+ return;
14
+ }
15
+ yield MOVE(pts[0]);
16
+ if (down !== void 0)
17
+ yield PEN(down);
18
+ yield DOWN(delayDown);
19
+ for (let i = 1, n = pts.length; i < n; i++)
20
+ yield MOVE(pts[i], speed);
21
+ yield UP(delayUp);
22
+ if (down !== void 0)
23
+ yield PEN();
37
24
  }
25
+ export {
26
+ polyline
27
+ };
package/registration.js CHANGED
@@ -2,35 +2,28 @@ import { map } from "@thi.ng/transducers/map";
2
2
  import { normRange } from "@thi.ng/transducers/norm-range";
3
3
  import { cartesian2 } from "@thi.ng/vectors/cartesian";
4
4
  import { DOWN, MOVE, UP } from "./commands.js";
5
- /**
6
- * Generates a {@link DrawCommand} sequence to draw a registration mark
7
- * (crosshair + circle) centered around `pos`.
8
- *
9
- * @example
10
- * ```ts
11
- * axi.draw(registrationMark([20, 20]))
12
- * ```
13
- *
14
- * @param pos
15
- * @param size
16
- * @param r
17
- */
18
- export const registrationMark = ([x, y], size = 5, r = size * 0.75) => [
19
- // crosshair
20
- // horizontal
21
- MOVE([x - size, y]),
22
- DOWN(),
23
- MOVE([x + size, y]),
24
- UP(),
25
- // vertical
26
- MOVE([x, y - size]),
27
- DOWN(),
28
- MOVE([x, y + size]),
29
- UP(),
30
- // circle
31
- MOVE([x + r, y]),
32
- DOWN(),
33
- ...map((t) => MOVE(cartesian2([], [r, t * Math.PI * 2], [x, y])), normRange(40)),
34
- UP(),
35
- MOVE([x, y]),
5
+ const registrationMark = ([x, y], size = 5, r = size * 0.75) => [
6
+ // crosshair
7
+ // horizontal
8
+ MOVE([x - size, y]),
9
+ DOWN(),
10
+ MOVE([x + size, y]),
11
+ UP(),
12
+ // vertical
13
+ MOVE([x, y - size]),
14
+ DOWN(),
15
+ MOVE([x, y + size]),
16
+ UP(),
17
+ // circle
18
+ MOVE([x + r, y]),
19
+ DOWN(),
20
+ ...map(
21
+ (t) => MOVE(cartesian2([], [r, t * Math.PI * 2], [x, y])),
22
+ normRange(40)
23
+ ),
24
+ UP(),
25
+ MOVE([x, y])
36
26
  ];
27
+ export {
28
+ registrationMark
29
+ };