@phun-ky/arclace 0.2.0 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.0](https://github.com/phun-ky/arclace/compare/0.3.0...1.0.0) (2026-11-04)
4
+
5
+ ### Documentation
6
+
7
+ * ✏️ 1.0 release notes, banners and policies ([e929cea](https://github.com/phun-ky/arclace/commit/e929ceace112eca7bc265b9bd57210d40a9ed347)), closes [#21](https://github.com/phun-ky/arclace/issues/21)
8
+ * ✏️ a docs site design to match the Bow mark ([a769977](https://github.com/phun-ky/arclace/commit/a769977f01a220e30da64c02422a11775053d838)), closes [#75](https://github.com/phun-ky/arclace/issues/75)
9
+ * ✏️ a logo for Arclace ([84b5dae](https://github.com/phun-ky/arclace/commit/84b5dae26ac836e4369506cd7e76351714386e24)), closes [#73](https://github.com/phun-ky/arclace/issues/73), references [#73](https://github.com/phun-ky/arclace/issues/73)
10
+ * ✏️ meet AA text contrast on the docs site ([793ae66](https://github.com/phun-ky/arclace/commit/793ae66f53f1e999e8d2fdcd7b7f82ae25a14d6e)), closes [#68](https://github.com/phun-ky/arclace/issues/68), references [#99acb2](https://github.com/phun-ky/arclace/issues/99acb2) [#5d747b](https://github.com/phun-ky/arclace/issues/5d747b) [#2865f0](https://github.com/phun-ky/arclace/issues/2865f0) [#f2f6ff](https://github.com/phun-ky/arclace/issues/f2f6ff)
11
+ * ✏️ record signed releases from 0.3.0 on ([7d84dfc](https://github.com/phun-ky/arclace/commit/7d84dfc53074013a9d360bbf08f140a9b8ce0f1b)), closes [#66](https://github.com/phun-ky/arclace/issues/66)
12
+ * ✏️ say how the lines work with assistive technology ([f4b8419](https://github.com/phun-ky/arclace/commit/f4b84197b6f216d76cfda9f9884104555e12b8cf)), closes [#60](https://github.com/phun-ky/arclace/issues/60), references [#68](https://github.com/phun-ky/arclace/issues/68)
13
+ * ✏️ switch the logo to the Bow mark ([9b3f6ac](https://github.com/phun-ky/arclace/commit/9b3f6ac5d57b219b6faa81f702ebd239d99fb33b)), references [#73](https://github.com/phun-ky/arclace/issues/73) [#73](https://github.com/phun-ky/arclace/issues/73)
14
+
15
+ ### Refactoring
16
+
17
+ * 💡 share the Chrome renderer between the logo and the banners ([d626118](https://github.com/phun-ky/arclace/commit/d626118eba5efb3e17408e225079c0a634d86037)), references [#21](https://github.com/phun-ky/arclace/issues/21)
18
+
19
+ ## [0.3.0](https://github.com/phun-ky/arclace/compare/0.2.0...0.3.0) (2026-11-04)
20
+
21
+ ### ⚠ BREAKING CHANGES
22
+
23
+ * Update code that uses the following:
24
+
25
+ - stop is now end: stopElement is endElement, stopSide is endSide,
26
+ geometry.stop and geometry.stopSide are geometry.end and
27
+ geometry.endSide, .arc-anchor-stop is .arc-anchor-end, and
28
+ data-stop-side is data-end-side
29
+ - options are checked before anything is added. Wrong types throw a
30
+ TypeError (strokeWidth: '3', label: 0, dashed: 'no', an empty or
31
+ non-string id) and values out of range a RangeError (type: 'wavy',
32
+ arrow: 'yes', an unknown side, a negative strokeWidth, spacing,
33
+ radius or offset). defaults can't set an id, and autoUpdate must be
34
+ true, false or 'frame'
35
+ - failures throw ArclaceError, exported, instead of Error. An invalid
36
+ selector throws an ArclaceError with the SyntaxError as its cause
37
+ - find() returns [] for a selector that matches nothing, instead of
38
+ throwing
39
+ - disconnect() throws a TypeError for a target that is not a
40
+ connection, a string, an element, null or undefined
41
+ - setOptions() throws after the connection was removed or its
42
+ instance destroyed, and when given an id
43
+ - DEFAULT_CONNECTION_OPTIONS is frozen, and geometry is a read-only
44
+ frozen object
45
+ - the Connection constructor is private in the types; connections
46
+ come from connect() and connectAll(). ArcConnectionParamsType and
47
+ ArcOptionalKeysType are no longer exported
48
+ - the path builders check their points (finite x and y) and sides
49
+
50
+ ### Documentation
51
+
52
+ * ✏️ assurance case and VEX statements ([73b4fe6](https://github.com/phun-ky/arclace/commit/73b4fe6bd0e1e553de71c8817d9720b1b27cc360)), references [#19](https://github.com/phun-ky/arclace/issues/19)
53
+ * ✏️ governance, roadmap and a contributing guide for Arclace ([5f5b33a](https://github.com/phun-ky/arclace/commit/5f5b33a54fa331e6ebf428f1773a0bd28013a6f2)), references [#20](https://github.com/phun-ky/arclace/issues/20) [#21](https://github.com/phun-ky/arclace/issues/21) [#19](https://github.com/phun-ky/arclace/issues/19) [#60](https://github.com/phun-ky/arclace/issues/60) [#19](https://github.com/phun-ky/arclace/issues/19)
54
+ * ✏️ link the ArclaceError source in the API reference ([d22f104](https://github.com/phun-ky/arclace/commit/d22f104088255aaa66037ee3e162c7ed8e4e575a)), references [#20](https://github.com/phun-ky/arclace/issues/20)
55
+ * ✏️ record the API review in the assurance case and OpenSSF answers ([e4cc02f](https://github.com/phun-ky/arclace/commit/e4cc02f294bc523da5c1f993972adab1e2a1a927)), closes [#20](https://github.com/phun-ky/arclace/issues/20), references [#21](https://github.com/phun-ky/arclace/issues/21)
56
+
57
+ ### Refactoring
58
+
59
+ * 💡 review the API for 1.0 ([94f3569](https://github.com/phun-ky/arclace/commit/94f3569d6be4ae66bd2ddc81b546a40301f24104)), references [#20](https://github.com/phun-ky/arclace/issues/20) [#20](https://github.com/phun-ky/arclace/issues/20)
60
+
3
61
  ## [0.2.0](https://github.com/phun-ky/arclace/compare/0.1.0...0.2.0) (2026-11-04)
4
62
 
5
63
  ### ⚠ BREAKING CHANGES
package/README.md CHANGED
@@ -1,7 +1,18 @@
1
1
  # @phun-ky/arclace
2
2
 
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="./docs/public/logo/banner-dark.png">
5
+ <img alt="Arclace: a tied lace with two loops and two tails, with the tagline: draw SVG lines between DOM elements" src="./docs/public/logo/banner-light.png">
6
+ </picture>
7
+
8
+ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/16333/badge)](https://www.bestpractices.dev/projects/16333)
9
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/phun-ky/arclace/badge)](https://scorecard.dev/viewer/?uri=github.com/phun-ky/arclace)
10
+
3
11
  > Draw SVG lines between DOM elements.
4
12
 
13
+ **1.0 is out:** [release notes](https://phun-ky.net/arclace/guide/releases/1.0)
14
+ and [upgrading from 0.x](https://phun-ky.net/arclace/guide/upgrading).
15
+
5
16
  Point it at two elements and it draws a line between them: a curve, a straight
6
17
  line or an orthogonal "circuit board" line, with optional arrows, labels and
7
18
  anchors. The lines follow the elements when they move, resize, scroll or get
@@ -60,8 +71,8 @@ import { createConnections } from '@phun-ky/arclace';
60
71
 
61
72
  const arclace = createConnections(
62
73
  [
63
- { startElement: '#a', stopElement: '#b' },
64
- { startElement: '#b', stopElement: '#c', label: 'then' }
74
+ { startElement: '#a', endElement: '#b' },
75
+ { startElement: '#b', endElement: '#c', label: 'then' }
65
76
  ],
66
77
  { container: '#diagram', defaults: { type: 'orthogonal', arrow: 'end' } }
67
78
  );
@@ -86,7 +97,8 @@ const arclace = createConnections(
86
97
 
87
98
  Each instance adds one `<svg class="arc-svg">` to its container, absolutely
88
99
  positioned over the container's content, and draws every line into it. The
89
- overlay doesn't block clicks (`pointer-events: none`).
100
+ overlay doesn't block clicks (`pointer-events: none`), and is hidden from
101
+ assistive technology (`aria-hidden`); see [Accessibility](#accessibility).
90
102
 
91
103
  - Put all the elements you connect inside the container. If the container is
92
104
  `position: static` it is changed to `position: relative` so the overlay
@@ -109,60 +121,78 @@ overlay doesn't block clicks (`pointer-events: none`).
109
121
  | `defaults` | [Connection options](#connection-options) | `{}` | Defaults for every connection made by this instance. |
110
122
  | `className` | `string` | | Extra classes for the overlay. |
111
123
 
112
- | Member | Description |
113
- | -------------------------------- | -------------------------------------------------------------------------------- |
114
- | `connect(start, stop, options?)` | Connects two elements (or selectors) and draws the line. Returns a `Connection`. |
115
- | `connectAll(definitions)` | Connects many `{ startElement, stopElement, ...options }` pairs in one go. |
116
- | `get(id)` | The connection with that id. |
117
- | `find(element)` | Every connection that starts or stops at an element. |
118
- | `disconnect(target)` | Removes a connection, a connection by id, or every connection of an element. |
119
- | `clear()` | Removes every connection. |
120
- | `update()` | Remeasures and redraws everything. |
121
- | `destroy()` | Removes everything and stops listening for changes. |
122
- | `connections` | All connections, in the order they were made. |
123
- | `container`, `svg` | The container and the overlay. |
124
+ | Member | Description |
125
+ | ------------------------------- | ------------------------------------------------------------------------------------------------------------- |
126
+ | `connect(start, end, options?)` | Connects two elements (or selectors) and draws the line. Returns a `Connection`. |
127
+ | `connectAll(definitions)` | Connects many `{ startElement, endElement, ...options }` pairs in one go: all of them or, if one fails, none. |
128
+ | `get(id)` | The connection with that id. |
129
+ | `find(element)` | Every connection that starts or ends at an element. `[]` when a selector matches nothing. |
130
+ | `disconnect(target)` | Removes a connection, a connection by id, or every connection of an element. |
131
+ | `clear()` | Removes every connection. |
132
+ | `update()` | Remeasures and redraws everything. |
133
+ | `destroy()` | Removes everything and stops listening for changes. |
134
+ | `connections` | All connections, in the order they were made. |
135
+ | `container`, `svg` | The container and the overlay. |
124
136
 
125
137
  ### `Connection`
126
138
 
127
- | Member | Description |
128
- | ----------------------------------- | ------------------------------------------------------------------------------------------------ |
129
- | `setOptions(options)` | Changes options and redraws. |
130
- | `remove()` | Removes the connection. |
131
- | `update()` | Redraws (all connections of the instance, since spreading depends on the others). |
132
- | `options` | The options in effect, with defaults filled in. |
133
- | `geometry` | `{ start, stop, startSide, stopSide, labelPoint, d }` from the last draw, or `null` when hidden. |
134
- | `id`, `startElement`, `stopElement` | |
135
- | `element`, `path` | The connection's `<g>` and `<path>`, for styling or event listeners. |
139
+ | Member | Description |
140
+ | ---------------------------------- | ---------------------------------------------------------------------------------------------- |
141
+ | `setOptions(options)` | Changes options and redraws. |
142
+ | `remove()` | Removes the connection. |
143
+ | `update()` | Redraws (all connections of the instance, since spreading depends on the others). |
144
+ | `options` | The options in effect, with defaults filled in. |
145
+ | `geometry` | `{ start, end, startSide, endSide, labelPoint, d }` from the last draw, or `null` when hidden. |
146
+ | `id`, `startElement`, `endElement` | |
147
+ | `element`, `path` | The connection's `<g>` and `<path>`, for styling or event listeners. |
136
148
 
137
149
  A connection is hidden while one of its elements is detached or `display: none`,
138
150
  and shown again when it comes back.
139
151
 
140
152
  ### Connection options
141
153
 
142
- | Option | Type | Default | Description |
143
- | ------------- | -------------------------------------------------- | ---------- | ------------------------------------------------------------------------------ |
144
- | `id` | `string` | generated | Unique id, for `get()` and `disconnect()`. |
145
- | `type` | `'bezier' \| 'straight' \| 'orthogonal'` | `'bezier'` | How the line is drawn. |
146
- | `startSide` | `'auto' \| 'top' \| 'right' \| 'bottom' \| 'left'` | `'auto'` | Side of the start element. `auto` picks the side facing the other element. |
147
- | `stopSide` | same as `startSide` | `'auto'` | Side of the stop element. |
148
- | `arrow` | `'none' \| 'start' \| 'end' \| 'both'` | `'none'` | Arrow heads. |
149
- | `label` | `string` | | Text in the middle of the line. |
150
- | `color` | `string` | | Line color. Without it, lines use `--arc-color` or the container's text color. |
151
- | `strokeWidth` | `number` | `2` | Line width in pixels. Arrows and anchors scale with it. |
152
- | `dashed` | `boolean` | `false` | Dashed line. |
153
- | `animated` | `boolean` | `false` | Dashes flowing from start to stop. Needs `style.css`. |
154
- | `anchors` | `boolean` | `false` | Dots where the line meets the elements. |
155
- | `className` | `string` | | Extra classes for the connection's `<g>`. |
156
- | `gap` | `number` | `0` | Space between the element edge and the line end. |
157
- | `spread` | `boolean` | `true` | Spread lines that share a side of an element. |
158
- | `spacing` | `number` | `16` | Distance between spread lines. Shrinks to fit the side. |
159
- | `curvature` | `number` | `1` | `bezier`: how far the curve bulges out. |
160
- | `radius` | `number` | `8` | `orthogonal`: corner radius. `0` for sharp corners. |
161
- | `offset` | `number` | `20` | `orthogonal`: how far the line goes straight out of an element before turning. |
154
+ | Option | Type | Default | Description |
155
+ | ------------- | -------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------- |
156
+ | `id` | `string` | generated | Unique id, for `get()` and `disconnect()`. |
157
+ | `type` | `'bezier' \| 'straight' \| 'orthogonal'` | `'bezier'` | How the line is drawn. |
158
+ | `startSide` | `'auto' \| 'top' \| 'right' \| 'bottom' \| 'left'` | `'auto'` | Side of the start element. `auto` picks the side facing the other element. |
159
+ | `endSide` | same as `startSide` | `'auto'` | Side of the end element. |
160
+ | `arrow` | `'none' \| 'start' \| 'end' \| 'both'` | `'none'` | Arrow heads. |
161
+ | `label` | `string` | | Text in the middle of the line. |
162
+ | `color` | `string` | | Line color. Without it, lines use `--arc-color` or the container's text color. |
163
+ | `strokeWidth` | `number` | `2` | Line width in pixels, `0` or more. Arrows and anchors scale with it. |
164
+ | `dashed` | `boolean` | `false` | Dashed line. |
165
+ | `animated` | `boolean` | `false` | Dashes flowing from start to end. Needs `style.css`. |
166
+ | `anchors` | `boolean` | `false` | Dots where the line meets the elements. |
167
+ | `className` | `string` | | Extra classes for the connection's `<g>`. |
168
+ | `gap` | `number` | `0` | Space between the element edge and the line end. Negative moves the end into the element. |
169
+ | `spread` | `boolean` | `true` | Spread lines that share a side of an element. |
170
+ | `spacing` | `number` | `16` | Distance between spread lines, `0` or more. Shrinks to fit the side. |
171
+ | `curvature` | `number` | `1` | `bezier`: how far the curve bulges out. Negative bulges the other way. |
172
+ | `radius` | `number` | `8` | `orthogonal`: corner radius, `0` or more. `0` for sharp corners. |
173
+ | `offset` | `number` | `20` | `orthogonal`: how far the line goes straight out of an element before turning, `0` or more. |
162
174
 
163
175
  The path builders `bezierPath`, `straightPath` and `orthogonalPath` are also
164
176
  exported if you want to draw lines between points yourself.
165
177
 
178
+ ### Errors
179
+
180
+ Options are checked when they are given, so a mistake fails at once with a
181
+ message that names the option:
182
+
183
+ - **`TypeError`:** a value of the wrong type, for example `strokeWidth: '3'`,
184
+ `label: 0`, or a target that is neither an element nor a selector.
185
+ - **`RangeError`:** a value out of range, for example `type: 'wavy'`,
186
+ `startSide: 'middle'` or `radius: -5`.
187
+ - **`ArclaceError`:** Arclace can't do what was asked: a selector matches
188
+ nothing or is invalid (with the browser's error as `cause`), an id is taken,
189
+ or the connection or the instance has been removed. It is exported, for
190
+ `instanceof` checks.
191
+
192
+ Every message starts with `arclace:`. When a call throws, nothing is added, so
193
+ the lines already drawn keep working. An option set to `undefined` uses the
194
+ default, and option names Arclace doesn't know are ignored.
195
+
166
196
  ## Styling
167
197
 
168
198
  Each connection is rendered as:
@@ -172,7 +202,7 @@ Each connection is rendered as:
172
202
  class="arc-connection arc-bezier"
173
203
  data-type="bezier"
174
204
  data-start-side="right"
175
- data-stop-side="left"
205
+ data-end-side="left"
176
206
  >
177
207
  <marker class="arc-marker">…</marker>
178
208
  <!-- arrow -->
@@ -181,7 +211,7 @@ Each connection is rendered as:
181
211
  <!-- label -->
182
212
  <circle class="arc-anchor arc-anchor-start" />
183
213
  <!-- anchors -->
184
- <circle class="arc-anchor arc-anchor-stop" />
214
+ <circle class="arc-anchor arc-anchor-end" />
185
215
  </g>
186
216
  ```
187
217
 
@@ -226,8 +256,25 @@ clickable, turn pointer events back on for the paths:
226
256
  }
227
257
  ```
228
258
 
259
+ A line can't take keyboard focus and is hidden from screen readers, so make a
260
+ click on it a shortcut for a control that is in your page anyway, such as a
261
+ button:
262
+
263
+ ```html
264
+ <div id="diagram">
265
+ <div class="box" id="a">A</div>
266
+ <div class="box" id="b">B</div>
267
+ <div class="box" id="c">C</div>
268
+ <button type="button" id="details">Show A to B</button>
269
+ </div>
270
+ ```
271
+
229
272
  ```ts
230
- connection.path.addEventListener('click', () => console.log(connection.id));
273
+ const showDetails = () => console.log(connection.id);
274
+
275
+ document.querySelector('#details')?.addEventListener('click', showDetails);
276
+ // The same action for pointer users who click the line
277
+ connection.path.addEventListener('click', showDetails);
231
278
  ```
232
279
 
233
280
  ## Keeping lines in sync
@@ -259,6 +306,49 @@ useEffect(() => {
259
306
  }, []);
260
307
  ```
261
308
 
309
+ ## Accessibility
310
+
311
+ The lines are decorative. The overlay has `aria-hidden="true"`, so screen
312
+ readers don't announce lines, arrows or labels, and a line can't take keyboard
313
+ focus. Whatever a line tells sighted users must also be in your page's own HTML.
314
+
315
+ The simplest way is to connect elements whose markup already says how they
316
+ relate. Lines between the items of an ordered list show a sequence that a screen
317
+ reader reads out as a list of steps:
318
+
319
+ ```html
320
+ <ol id="diagram">
321
+ <li class="box" id="a">Build</li>
322
+ <li class="box" id="b">Test</li>
323
+ <li class="box" id="c">Deploy</li>
324
+ </ol>
325
+ ```
326
+
327
+ ```ts
328
+ const arclace = new Arclace({ container: '#diagram' });
329
+
330
+ arclace.connect('#a', '#b', { arrow: 'end' });
331
+ arclace.connect('#b', '#c', { arrow: 'end' });
332
+ ```
333
+
334
+ Beyond that:
335
+
336
+ - **Describe other relationships in text,** for example in a table of what
337
+ connects to what, or in a sentence that `aria-describedby` on a focusable
338
+ element points at.
339
+ - **Repeat labels in the page.** A label is part of the overlay, so its text
340
+ isn't announced either.
341
+ - **Don't tell lines apart by color alone.** Use `dashed`, `arrow` or a label as
342
+ well, and give lines a contrast of at least 3:1 with the background so they
343
+ stay visible with low vision.
344
+ - **Motion:** with the stylesheet, `animated` lines stop moving when the user
345
+ asks for reduced motion (`prefers-reduced-motion`).
346
+ - **Clickable lines** need the same action on a control in the page; see
347
+ [Clickable lines](#clickable-lines).
348
+
349
+ Arclace doesn't add `aria-describedby` or any other attribute to your elements:
350
+ it only changes what it draws.
351
+
262
352
  ## Development
263
353
 
264
354
  ```shell
package/dist/arclace.d.ts CHANGED
@@ -52,9 +52,9 @@ type ArcConnectionOptionsType = {
52
52
  */
53
53
  startSide?: ArcSideOptionType;
54
54
  /**
55
- * The side of the stop element the line arrives at. Defaults to `'auto'`.
55
+ * The side of the end element the line arrives at. Defaults to `'auto'`.
56
56
  */
57
- stopSide?: ArcSideOptionType;
57
+ endSide?: ArcSideOptionType;
58
58
  /**
59
59
  * Where to draw arrow heads. Defaults to `'none'`.
60
60
  */
@@ -77,7 +77,7 @@ type ArcConnectionOptionsType = {
77
77
  */
78
78
  dashed?: boolean;
79
79
  /**
80
- * Animate the dashes from start to stop. Implies `dashed`. Requires the
80
+ * Animate the dashes from start to end. Implies `dashed`. Requires the
81
81
  * stylesheet. Defaults to `false`.
82
82
  */
83
83
  animated?: boolean;
@@ -127,7 +127,7 @@ type ArcConnectionOptionsType = {
127
127
  */
128
128
  type ArcConnectionDefinitionType = ArcConnectionOptionsType & {
129
129
  startElement: ArcElementTargetType;
130
- stopElement: ArcElementTargetType;
130
+ endElement: ArcElementTargetType;
131
131
  };
132
132
  /**
133
133
  * Options for a {@link Arclace} instance.
@@ -162,37 +162,28 @@ type ArcOptionsType = {
162
162
  */
163
163
  type ArcGeometryType = {
164
164
  start: ArcPointInterface;
165
- stop: ArcPointInterface;
165
+ end: ArcPointInterface;
166
166
  startSide: ArcSideType;
167
- stopSide: ArcSideType;
167
+ endSide: ArcSideType;
168
168
  labelPoint: ArcPointInterface;
169
169
  d: string;
170
170
  };
171
171
 
172
172
  /**
173
- * Connection options that have no default.
173
+ * Connection options with every default filled in. `label`, `color` and
174
+ * `className` have no default.
174
175
  */
175
- type ArcOptionalKeysType = 'id' | 'label' | 'color' | 'className';
176
- /**
177
- * Connection options with every default filled in.
178
- */
179
- type ArcResolvedConnectionOptionsType = Required<Omit<ArcConnectionOptionsType, ArcOptionalKeysType>> & Pick<ArcConnectionOptionsType, ArcOptionalKeysType> & {
176
+ type ArcResolvedConnectionOptionsType = Required<Omit<ArcConnectionOptionsType, 'id' | 'label' | 'color' | 'className'>> & Pick<ArcConnectionOptionsType, 'label' | 'color' | 'className'> & {
180
177
  id: string;
181
178
  };
182
179
  /**
183
- * Options every connection falls back to.
180
+ * Options every connection falls back to. Frozen: set your own defaults with
181
+ * the `defaults` option of {@link Arclace} instead.
184
182
  */
185
- declare const DEFAULT_CONNECTION_OPTIONS: Required<Omit<ArcConnectionOptionsType, ArcOptionalKeysType>>;
186
- type ArcConnectionParamsType = {
187
- id: string;
188
- startElement: Element;
189
- stopElement: Element;
190
- options: ArcConnectionOptionsType;
191
- defaults?: ArcConnectionOptionsType;
192
- owner: Arclace;
193
- };
183
+ declare const DEFAULT_CONNECTION_OPTIONS: Readonly<Required<Omit<ArcConnectionOptionsType, 'id' | 'label' | 'color' | 'className'>>>;
194
184
  /**
195
- * A line between two elements. Created with {@link Arclace.connect}.
185
+ * A line between two elements. Created with {@link Arclace.connect} or
186
+ * {@link Arclace.connectAll}, not with `new`.
196
187
  *
197
188
  * Each connection renders as:
198
189
  *
@@ -202,7 +193,7 @@ type ArcConnectionParamsType = {
202
193
  * <path class="arc-path" />
203
194
  * <text class="arc-label">…</text> <!-- when `label` is set -->
204
195
  * <circle class="arc-anchor arc-anchor-start" /> <!-- when `anchors` is set -->
205
- * <circle class="arc-anchor arc-anchor-stop" />
196
+ * <circle class="arc-anchor arc-anchor-end" />
206
197
  * </g>
207
198
  * ```
208
199
  *
@@ -213,7 +204,7 @@ declare class Connection {
213
204
  #private;
214
205
  readonly id: string;
215
206
  readonly startElement: Element;
216
- readonly stopElement: Element;
207
+ readonly endElement: Element;
217
208
  /**
218
209
  * The `<g>` element holding everything this connection draws.
219
210
  */
@@ -222,12 +213,12 @@ declare class Connection {
222
213
  * The `<path>` element of the line.
223
214
  */
224
215
  readonly path: SVGPathElement;
216
+ private constructor();
225
217
  /**
226
218
  * The geometry from the last update, or `null` when the connection is
227
219
  * hidden because one of its elements is not rendered.
228
220
  */
229
- geometry: ArcGeometryType | null;
230
- constructor(params: ArcConnectionParamsType);
221
+ get geometry(): Readonly<ArcGeometryType> | null;
231
222
  /**
232
223
  * The connection's options merged with the instance defaults.
233
224
  */
@@ -239,6 +230,9 @@ declare class Connection {
239
230
  * ```ts
240
231
  * connection.setOptions({ type: 'orthogonal', arrow: 'end' });
241
232
  * ```
233
+ * @throws {TypeError} When an option has the wrong type, or `id` is set.
234
+ * @throws {RangeError} When an option is out of range.
235
+ * @throws {ArclaceError} When the connection has been removed.
242
236
  */
243
237
  setOptions(options: Omit<ArcConnectionOptionsType, 'id'>): this;
244
238
  /**
@@ -276,6 +270,12 @@ declare class Arclace {
276
270
  * The SVG overlay all lines are drawn in.
277
271
  */
278
272
  readonly svg: SVGSVGElement;
273
+ /**
274
+ * @throws {TypeError} When an option has the wrong type.
275
+ * @throws {RangeError} When an option is out of range.
276
+ * @throws {ArclaceError} When there is no DOM, or the container can't be
277
+ * found.
278
+ */
279
279
  constructor(options?: ArcOptionsType);
280
280
  /**
281
281
  * All current connections, in the order they were made.
@@ -285,23 +285,32 @@ declare class Arclace {
285
285
  * Connects two elements and draws the line right away.
286
286
  *
287
287
  * @param startElement - The element (or selector) the line starts at.
288
- * @param stopElement - The element (or selector) the line stops at.
288
+ * @param endElement - The element (or selector) the line ends at.
289
289
  * @param options - Options for this connection, merged over the instance defaults.
290
- * @throws {Error} When an element can't be found or the id is taken.
290
+ * @throws {TypeError} When an element or an option has the wrong type.
291
+ * @throws {RangeError} When an option is out of range.
292
+ * @throws {ArclaceError} When an element can't be found, the id is taken
293
+ * or the instance has been destroyed. Nothing is added.
291
294
  * @example
292
295
  * ```ts
293
296
  * const connection = arclace.connect(a, b, { type: 'orthogonal', arrow: 'end' });
294
297
  * ```
295
298
  */
296
- connect(startElement: ArcElementTargetType, stopElement: ArcElementTargetType, options?: ArcConnectionOptionsType): Connection;
299
+ connect(startElement: ArcElementTargetType, endElement: ArcElementTargetType, options?: ArcConnectionOptionsType): Connection;
297
300
  /**
298
- * Connects many pairs of elements and draws them in one go.
301
+ * Connects many pairs of elements and draws them in one go. Every
302
+ * definition is checked first, so either all of them are added or none.
299
303
  *
304
+ * @throws {TypeError} When `definitions` isn't an array, or an element or
305
+ * an option has the wrong type.
306
+ * @throws {RangeError} When an option is out of range.
307
+ * @throws {ArclaceError} When an element can't be found, an id is taken or
308
+ * repeated, or the instance has been destroyed.
300
309
  * @example
301
310
  * ```ts
302
311
  * arclace.connectAll([
303
- * { startElement: '#a', stopElement: '#b' },
304
- * { startElement: '#a', stopElement: '#c', dashed: true }
312
+ * { startElement: '#a', endElement: '#b' },
313
+ * { startElement: '#a', endElement: '#c', dashed: true }
305
314
  * ]);
306
315
  * ```
307
316
  */
@@ -311,7 +320,11 @@ declare class Arclace {
311
320
  */
312
321
  get(id: string): Connection | undefined;
313
322
  /**
314
- * Returns every connection that starts or stops at an element.
323
+ * Returns every connection that starts or ends at an element. A selector
324
+ * that matches nothing returns an empty array.
325
+ *
326
+ * @throws {TypeError} When the target is neither an element nor a string.
327
+ * @throws {ArclaceError} When the selector is invalid.
315
328
  */
316
329
  find(target: ArcElementTargetType): Connection[];
317
330
  /**
@@ -319,7 +332,10 @@ declare class Arclace {
319
332
  *
320
333
  * @param target - A connection, a connection id, or an element (or
321
334
  * selector) whose connections should all be removed. Targets that match
322
- * nothing are ignored.
335
+ * nothing, and `null` or `undefined`, are ignored.
336
+ * @throws {TypeError} When the target is another kind of value.
337
+ * @throws {ArclaceError} When a string is neither an id nor a valid
338
+ * selector.
323
339
  * @example
324
340
  * ```ts
325
341
  * arclace.disconnect(connection);
@@ -353,8 +369,8 @@ declare class Arclace {
353
369
  *
354
370
  * const arclace = createConnections(
355
371
  * [
356
- * { startElement: '#a', stopElement: '#b' },
357
- * { startElement: '#b', stopElement: '#c', arrow: 'end' }
372
+ * { startElement: '#a', endElement: '#b' },
373
+ * { startElement: '#b', endElement: '#c', arrow: 'end' }
358
374
  * ],
359
375
  * { defaults: { type: 'orthogonal' } }
360
376
  * );
@@ -362,6 +378,29 @@ declare class Arclace {
362
378
  */
363
379
  declare const createConnections: (definitions: ArcConnectionDefinitionType[], options?: ArcOptionsType) => Arclace;
364
380
 
381
+ /**
382
+ * Thrown when Arclace can't do what was asked, for example when a selector
383
+ * matches nothing, an id is taken, or the instance has been destroyed.
384
+ *
385
+ * Arguments of the wrong type throw a `TypeError`, and values out of range a
386
+ * `RangeError`, instead. When another error is behind the failure, such as
387
+ * an invalid selector, it is the `cause`.
388
+ *
389
+ * @example
390
+ * ```ts
391
+ * try {
392
+ * arclace.connect('#a', '#b', { id: 'a-to-b' });
393
+ * arclace.connect('#b', '#c', { id: 'a-to-b' }); // the id is taken
394
+ * } catch (error) {
395
+ * if (error instanceof ArclaceError) console.warn(error.message);
396
+ * }
397
+ * ```
398
+ */
399
+ declare class ArclaceError extends Error {
400
+ name: string;
401
+ constructor(message: string, options?: ErrorOptions);
402
+ }
403
+
365
404
  type ArcPathResultType = {
366
405
  /**
367
406
  * SVG path data.
@@ -375,25 +414,31 @@ type ArcPathResultType = {
375
414
  /**
376
415
  * A straight line between two points.
377
416
  *
417
+ * @throws {TypeError} When a point doesn't have finite `x` and `y`.
378
418
  * @example
379
419
  * ```ts
380
420
  * straightPath({ x: 0, y: 0 }, { x: 100, y: 0 }).d; // 'M 0 0 L 100 0'
381
421
  * ```
382
422
  */
383
- declare const straightPath: (start: ArcPointInterface, stop: ArcPointInterface) => ArcPathResultType;
423
+ declare const straightPath: (start: ArcPointInterface, end: ArcPointInterface) => ArcPathResultType;
384
424
  /**
385
- * A cubic bezier curve that leaves `start` and arrives at `stop`
425
+ * A cubic bezier curve that leaves `start` and arrives at `end`
386
426
  * perpendicular to their sides.
387
427
  *
428
+ * @throws {TypeError} When a point or `curvature` isn't finite.
429
+ * @throws {RangeError} When a side isn't `top`, `right`, `bottom` or `left`.
388
430
  * @example
389
431
  * ```ts
390
432
  * bezierPath({ x: 0, y: 0 }, 'right', { x: 200, y: 100 }, 'left').d;
391
433
  * ```
392
434
  */
393
- declare const bezierPath: (start: ArcPointInterface, startSide: ArcSideType, stop: ArcPointInterface, stopSide: ArcSideType, curvature?: number) => ArcPathResultType;
435
+ declare const bezierPath: (start: ArcPointInterface, startSide: ArcSideType, end: ArcPointInterface, endSide: ArcSideType, curvature?: number) => ArcPathResultType;
394
436
  /**
395
437
  * An orthogonal line with rounded corners.
396
438
  *
439
+ * @throws {TypeError} When a point, `radius` or `offset` isn't finite.
440
+ * @throws {RangeError} When a side isn't `top`, `right`, `bottom` or `left`,
441
+ * or `radius` or `offset` is negative.
397
442
  * @example
398
443
  * ```ts
399
444
  * orthogonalPath({ x: 0, y: 0 }, 'right', { x: 200, y: 100 }, 'left', {
@@ -402,10 +447,10 @@ declare const bezierPath: (start: ArcPointInterface, startSide: ArcSideType, sto
402
447
  * }).d;
403
448
  * ```
404
449
  */
405
- declare const orthogonalPath: (start: ArcPointInterface, startSide: ArcSideType, stop: ArcPointInterface, stopSide: ArcSideType, { radius, offset }?: {
450
+ declare const orthogonalPath: (start: ArcPointInterface, startSide: ArcSideType, end: ArcPointInterface, endSide: ArcSideType, { radius, offset }?: {
406
451
  radius?: number;
407
452
  offset?: number;
408
453
  }) => ArcPathResultType;
409
454
 
410
- export { Arclace, Connection, DEFAULT_CONNECTION_OPTIONS, bezierPath, createConnections, orthogonalPath, straightPath };
411
- export type { ArcArrowType, ArcConnectionDefinitionType, ArcConnectionOptionsType, ArcConnectionParamsType, ArcElementTargetType, ArcGeometryType, ArcOptionalKeysType, ArcOptionsType, ArcPathResultType, ArcPathType, ArcPointInterface, ArcRectInterface, ArcResolvedConnectionOptionsType, ArcSideOptionType, ArcSideType };
455
+ export { Arclace, ArclaceError, Connection, DEFAULT_CONNECTION_OPTIONS, bezierPath, createConnections, orthogonalPath, straightPath };
456
+ export type { ArcArrowType, ArcConnectionDefinitionType, ArcConnectionOptionsType, ArcElementTargetType, ArcGeometryType, ArcOptionsType, ArcPathResultType, ArcPathType, ArcPointInterface, ArcRectInterface, ArcResolvedConnectionOptionsType, ArcSideOptionType, ArcSideType };