@phun-ky/arclace 0.0.0-stage → 0.3.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 +86 -0
- package/LICENSE +21 -0
- package/README.md +336 -2
- package/dist/arclace.d.ts +456 -0
- package/dist/arclace.js +839 -0
- package/dist/arclace.js.map +1 -0
- package/dist/arclace.umd.cjs +2 -0
- package/dist/arclace.umd.cjs.map +1 -0
- package/dist/style.css +52 -0
- package/package.json +119 -4
- package/src/Arclace.ts +578 -0
- package/src/Connection.ts +455 -0
- package/src/errors.ts +25 -0
- package/src/index.ts +30 -0
- package/src/style.css +52 -0
- package/src/types.ts +200 -0
- package/src/utils/geometry.ts +61 -0
- package/src/utils/id.ts +14 -0
- package/src/utils/measure.ts +64 -0
- package/src/utils/paths.ts +345 -0
- package/src/utils/resolve-element.ts +46 -0
- package/src/utils/sides.ts +108 -0
- package/src/utils/svg.ts +34 -0
- package/src/utils/validate.ts +253 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.3.0](https://github.com/phun-ky/arclace/compare/0.2.0...0.3.0) (2026-11-04)
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* Update code that uses the following:
|
|
8
|
+
|
|
9
|
+
- stop is now end: stopElement is endElement, stopSide is endSide,
|
|
10
|
+
geometry.stop and geometry.stopSide are geometry.end and
|
|
11
|
+
geometry.endSide, .arc-anchor-stop is .arc-anchor-end, and
|
|
12
|
+
data-stop-side is data-end-side
|
|
13
|
+
- options are checked before anything is added. Wrong types throw a
|
|
14
|
+
TypeError (strokeWidth: '3', label: 0, dashed: 'no', an empty or
|
|
15
|
+
non-string id) and values out of range a RangeError (type: 'wavy',
|
|
16
|
+
arrow: 'yes', an unknown side, a negative strokeWidth, spacing,
|
|
17
|
+
radius or offset). defaults can't set an id, and autoUpdate must be
|
|
18
|
+
true, false or 'frame'
|
|
19
|
+
- failures throw ArclaceError, exported, instead of Error. An invalid
|
|
20
|
+
selector throws an ArclaceError with the SyntaxError as its cause
|
|
21
|
+
- find() returns [] for a selector that matches nothing, instead of
|
|
22
|
+
throwing
|
|
23
|
+
- disconnect() throws a TypeError for a target that is not a
|
|
24
|
+
connection, a string, an element, null or undefined
|
|
25
|
+
- setOptions() throws after the connection was removed or its
|
|
26
|
+
instance destroyed, and when given an id
|
|
27
|
+
- DEFAULT_CONNECTION_OPTIONS is frozen, and geometry is a read-only
|
|
28
|
+
frozen object
|
|
29
|
+
- the Connection constructor is private in the types; connections
|
|
30
|
+
come from connect() and connectAll(). ArcConnectionParamsType and
|
|
31
|
+
ArcOptionalKeysType are no longer exported
|
|
32
|
+
- the path builders check their points (finite x and y) and sides
|
|
33
|
+
|
|
34
|
+
### Documentation
|
|
35
|
+
|
|
36
|
+
* ✏️ assurance case and VEX statements ([73b4fe6](https://github.com/phun-ky/arclace/commit/73b4fe6bd0e1e553de71c8817d9720b1b27cc360)), references [#19](https://github.com/phun-ky/arclace/issues/19)
|
|
37
|
+
* ✏️ 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)
|
|
38
|
+
* ✏️ 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)
|
|
39
|
+
* ✏️ 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)
|
|
40
|
+
|
|
41
|
+
### Refactoring
|
|
42
|
+
|
|
43
|
+
* 💡 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)
|
|
44
|
+
|
|
45
|
+
## [0.2.0](https://github.com/phun-ky/arclace/compare/0.1.0...0.2.0) (2026-11-04)
|
|
46
|
+
|
|
47
|
+
### ⚠ BREAKING CHANGES
|
|
48
|
+
|
|
49
|
+
* 💡 rename the package to Arclace
|
|
50
|
+
|
|
51
|
+
### Tasks
|
|
52
|
+
|
|
53
|
+
* 🤖 sign off every commit with a prepare-commit-msg hook ([940e06b](https://github.com/phun-ky/arclace/commit/940e06b72871db570ccb516f76d81bcb5ea3e53b)), references [#18](https://github.com/phun-ky/arclace/issues/18)
|
|
54
|
+
* 🤖 skip the first release under a new package name ([738c8b6](https://github.com/phun-ky/arclace/commit/738c8b6534c860d53361811781268ae0bf08c7dd)), references [#58](https://github.com/phun-ky/arclace/issues/58)
|
|
55
|
+
|
|
56
|
+
### Documentation
|
|
57
|
+
|
|
58
|
+
* ✏️ add a VitePress docs site with the API reference ([3125b4c](https://github.com/phun-ky/arclace/commit/3125b4c17ac477aa9b331dac6513a2ce69a93d2e)), references [#15](https://github.com/phun-ky/arclace/issues/15)
|
|
59
|
+
* ✏️ explain the name Arclace ([180ca0d](https://github.com/phun-ky/arclace/commit/180ca0d781d85e1ff7b96cb41d1b5cc6cc07f495)), references [#58](https://github.com/phun-ky/arclace/issues/58)
|
|
60
|
+
* ✏️ rewrite the security policy and add security insights ([2942a2c](https://github.com/phun-ky/arclace/commit/2942a2cb86c595810ae5c5493e664ad13b5bebf2)), references [#17](https://github.com/phun-ky/arclace/issues/17)
|
|
61
|
+
* ✏️ show the markup the playground example runs on ([a5251de](https://github.com/phun-ky/arclace/commit/a5251de0298dc051cc2eb451e3e30b70c3644f92)), references [#16](https://github.com/phun-ky/arclace/issues/16)
|
|
62
|
+
* ✏️ tell where connect-the-things comes from ([9df2bdf](https://github.com/phun-ky/arclace/commit/9df2bdff7e9dcf50e223fb60e64eb0301406acf7)), references [#56](https://github.com/phun-ky/arclace/issues/56)
|
|
63
|
+
|
|
64
|
+
### Refactoring
|
|
65
|
+
|
|
66
|
+
* 💡 rename the package to Arclace ([5758e91](https://github.com/phun-ky/arclace/commit/5758e91483c20a13b2010e0afab0635e04ee8cd0))
|
|
67
|
+
|
|
68
|
+
## 0.1.0 (2026-11-03)
|
|
69
|
+
|
|
70
|
+
### Tasks
|
|
71
|
+
|
|
72
|
+
* 🤖 fix the labeler rules, issue template labels and triage ([b45a57a](https://github.com/phun-ky/connect-the-things/commit/b45a57a93b5885da18e76911f6c8f21816c34a03)), references [#10](https://github.com/phun-ky/connect-the-things/issues/10)
|
|
73
|
+
* 🤖 group Dependabot updates and add GitHub Actions ([ad5216e](https://github.com/phun-ky/connect-the-things/commit/ad5216e8f88c8d9357b94e6401b873e1350bb805)), references [#9](https://github.com/phun-ky/connect-the-things/issues/9)
|
|
74
|
+
* 🤖 ignore the .claude directory ([27ed8ce](https://github.com/phun-ky/connect-the-things/commit/27ed8ce590218370d09f1d4534f082320eac518c)), references [#49](https://github.com/phun-ky/connect-the-things/issues/49)
|
|
75
|
+
* 🤖 lint and API docs tooling ([2dd8e60](https://github.com/phun-ky/connect-the-things/commit/2dd8e60a1c1e019e5786bbfb2a1cc2c5091b16cc)), references [#3](https://github.com/phun-ky/connect-the-things/issues/3)
|
|
76
|
+
* 🤖 move to ESLint 10 and lint every file type ([1b1d7ac](https://github.com/phun-ky/connect-the-things/commit/1b1d7acd6197723c78070ab9ca0bdd81c95b1be4)), references [#6](https://github.com/phun-ky/connect-the-things/issues/6)
|
|
77
|
+
* 🤖 refresh development dependencies and override katex ([e157c35](https://github.com/phun-ky/connect-the-things/commit/e157c359b453a0d6bba14763c2a1d34553eb4877)), references [#11](https://github.com/phun-ky/connect-the-things/issues/11)
|
|
78
|
+
* 🤖 upgrade release-it to 21 and the changelog plugin to 12 ([4c4704e](https://github.com/phun-ky/connect-the-things/commit/4c4704ece6498cc88a7a387b56611531589d27df)), references [#44](https://github.com/phun-ky/connect-the-things/issues/44) [#12](https://github.com/phun-ky/connect-the-things/issues/12)
|
|
79
|
+
|
|
80
|
+
### Feature
|
|
81
|
+
|
|
82
|
+
* 🎸 draw SVG lines between DOM elements ([62ee4e3](https://github.com/phun-ky/connect-the-things/commit/62ee4e359bfec916643a9f5da506979562651f33)), references [#3](https://github.com/phun-ky/connect-the-things/issues/3)
|
|
83
|
+
|
|
84
|
+
### Bug
|
|
85
|
+
|
|
86
|
+
* 🐛 ship ES modules with types that resolve everywhere ([390da51](https://github.com/phun-ky/connect-the-things/commit/390da51be2a84fb5a02bae9ed1f6957680ebdb8d)), references [#4](https://github.com/phun-ky/connect-the-things/issues/4)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-2026 Alexander Vassbotn Røyne-Helgesen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,337 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @phun-ky/arclace
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.bestpractices.dev/projects/16333)
|
|
4
|
+
[](https://scorecard.dev/viewer/?uri=github.com/phun-ky/arclace)
|
|
5
|
+
|
|
6
|
+
> Draw SVG lines between DOM elements.
|
|
7
|
+
|
|
8
|
+
Point it at two elements and it draws a line between them: a curve, a straight
|
|
9
|
+
line or an orthogonal "circuit board" line, with optional arrows, labels and
|
|
10
|
+
anchors. The lines follow the elements when they move, resize, scroll or get
|
|
11
|
+
zoomed.
|
|
12
|
+
|
|
13
|
+
It's framework agnostic and has zero dependencies. You keep your own HTML for
|
|
14
|
+
the boxes; Arclace only draws the lines.
|
|
15
|
+
|
|
16
|
+
- **Three line types**: `bezier`, `straight` and `orthogonal` (with rounded
|
|
17
|
+
corners)
|
|
18
|
+
- **Automatic sides**: lines leave and enter on the sides that face each other,
|
|
19
|
+
or on sides you pick
|
|
20
|
+
- **Spreading**: several lines on the same side of an element are spread out and
|
|
21
|
+
ordered so they don't cross
|
|
22
|
+
- **Arrows, labels, anchors, dashed and animated lines**
|
|
23
|
+
- **Keeps itself in sync** with resizes, scrolling and DOM/style changes, or on
|
|
24
|
+
every frame if you want
|
|
25
|
+
- **Works in scrolled and CSS-transformed containers**, so it fits pan/zoom
|
|
26
|
+
canvases
|
|
27
|
+
- **Styled with CSS**: everything uses `currentColor` and plain class names
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
npm i @phun-ky/arclace
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
ES modules; `require()` needs Node 22.12 or later. A UMD build is available for
|
|
36
|
+
script tags (see [Without a bundler](#without-a-bundler)).
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<div id="diagram">
|
|
42
|
+
<div class="box" id="a">A</div>
|
|
43
|
+
<div class="box" id="b">B</div>
|
|
44
|
+
<div class="box" id="c">C</div>
|
|
45
|
+
</div>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { Arclace } from '@phun-ky/arclace';
|
|
50
|
+
// Optional: label halo, hollow anchors and the dash animation
|
|
51
|
+
import '@phun-ky/arclace/style.css';
|
|
52
|
+
|
|
53
|
+
const arclace = new Arclace({ container: '#diagram' });
|
|
54
|
+
|
|
55
|
+
arclace.connect('#a', '#b', { arrow: 'end', label: 'depends on' });
|
|
56
|
+
arclace.connect('#a', '#c', { type: 'orthogonal', dashed: true });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or create everything at once:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { createConnections } from '@phun-ky/arclace';
|
|
63
|
+
|
|
64
|
+
const arclace = createConnections(
|
|
65
|
+
[
|
|
66
|
+
{ startElement: '#a', endElement: '#b' },
|
|
67
|
+
{ startElement: '#b', endElement: '#c', label: 'then' }
|
|
68
|
+
],
|
|
69
|
+
{ container: '#diagram', defaults: { type: 'orthogonal', arrow: 'end' } }
|
|
70
|
+
);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Without a bundler
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<link
|
|
77
|
+
rel="stylesheet"
|
|
78
|
+
href="https://unpkg.com/@phun-ky/arclace/dist/style.css"
|
|
79
|
+
/>
|
|
80
|
+
<script src="https://unpkg.com/@phun-ky/arclace"></script>
|
|
81
|
+
<script>
|
|
82
|
+
const arclace = new Arclace.Arclace();
|
|
83
|
+
|
|
84
|
+
arclace.connect('#a', '#b');
|
|
85
|
+
</script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## How it works
|
|
89
|
+
|
|
90
|
+
Each instance adds one `<svg class="arc-svg">` to its container, absolutely
|
|
91
|
+
positioned over the container's content, and draws every line into it. The
|
|
92
|
+
overlay doesn't block clicks (`pointer-events: none`).
|
|
93
|
+
|
|
94
|
+
- Put all the elements you connect inside the container. If the container is
|
|
95
|
+
`position: static` it is changed to `position: relative` so the overlay
|
|
96
|
+
scrolls and clips with it (and changed back on `destroy()`). The default
|
|
97
|
+
container is `document.body`.
|
|
98
|
+
- Positions are measured relative to the overlay itself, so lines stay correct
|
|
99
|
+
in scrolled containers and when the container is scaled with CSS transforms
|
|
100
|
+
(for example by a pan/zoom library).
|
|
101
|
+
- The overlay is the container's first child, so it is painted below positioned
|
|
102
|
+
elements that come after it. Set `z-index` on `.arc-svg` to change that.
|
|
103
|
+
|
|
104
|
+
## API
|
|
105
|
+
|
|
106
|
+
### `new Arclace(options?)`
|
|
107
|
+
|
|
108
|
+
| Option | Type | Default | Description |
|
|
109
|
+
| ------------ | ----------------------------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
+
| `container` | `Element \| string` | `document.body` | The element the overlay is added to. |
|
|
111
|
+
| `autoUpdate` | `boolean \| 'frame'` | `true` | `true` redraws on window resize, scroll, element resize and DOM/style changes in the container. `'frame'` redraws every animation frame. `false` only redraws when you call `update()`. |
|
|
112
|
+
| `defaults` | [Connection options](#connection-options) | `{}` | Defaults for every connection made by this instance. |
|
|
113
|
+
| `className` | `string` | | Extra classes for the overlay. |
|
|
114
|
+
|
|
115
|
+
| Member | Description |
|
|
116
|
+
| ------------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
117
|
+
| `connect(start, end, options?)` | Connects two elements (or selectors) and draws the line. Returns a `Connection`. |
|
|
118
|
+
| `connectAll(definitions)` | Connects many `{ startElement, endElement, ...options }` pairs in one go: all of them or, if one fails, none. |
|
|
119
|
+
| `get(id)` | The connection with that id. |
|
|
120
|
+
| `find(element)` | Every connection that starts or ends at an element. `[]` when a selector matches nothing. |
|
|
121
|
+
| `disconnect(target)` | Removes a connection, a connection by id, or every connection of an element. |
|
|
122
|
+
| `clear()` | Removes every connection. |
|
|
123
|
+
| `update()` | Remeasures and redraws everything. |
|
|
124
|
+
| `destroy()` | Removes everything and stops listening for changes. |
|
|
125
|
+
| `connections` | All connections, in the order they were made. |
|
|
126
|
+
| `container`, `svg` | The container and the overlay. |
|
|
127
|
+
|
|
128
|
+
### `Connection`
|
|
129
|
+
|
|
130
|
+
| Member | Description |
|
|
131
|
+
| ---------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
132
|
+
| `setOptions(options)` | Changes options and redraws. |
|
|
133
|
+
| `remove()` | Removes the connection. |
|
|
134
|
+
| `update()` | Redraws (all connections of the instance, since spreading depends on the others). |
|
|
135
|
+
| `options` | The options in effect, with defaults filled in. |
|
|
136
|
+
| `geometry` | `{ start, end, startSide, endSide, labelPoint, d }` from the last draw, or `null` when hidden. |
|
|
137
|
+
| `id`, `startElement`, `endElement` | |
|
|
138
|
+
| `element`, `path` | The connection's `<g>` and `<path>`, for styling or event listeners. |
|
|
139
|
+
|
|
140
|
+
A connection is hidden while one of its elements is detached or `display: none`,
|
|
141
|
+
and shown again when it comes back.
|
|
142
|
+
|
|
143
|
+
### Connection options
|
|
144
|
+
|
|
145
|
+
| Option | Type | Default | Description |
|
|
146
|
+
| ------------- | -------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------- |
|
|
147
|
+
| `id` | `string` | generated | Unique id, for `get()` and `disconnect()`. |
|
|
148
|
+
| `type` | `'bezier' \| 'straight' \| 'orthogonal'` | `'bezier'` | How the line is drawn. |
|
|
149
|
+
| `startSide` | `'auto' \| 'top' \| 'right' \| 'bottom' \| 'left'` | `'auto'` | Side of the start element. `auto` picks the side facing the other element. |
|
|
150
|
+
| `endSide` | same as `startSide` | `'auto'` | Side of the end element. |
|
|
151
|
+
| `arrow` | `'none' \| 'start' \| 'end' \| 'both'` | `'none'` | Arrow heads. |
|
|
152
|
+
| `label` | `string` | | Text in the middle of the line. |
|
|
153
|
+
| `color` | `string` | | Line color. Without it, lines use `--arc-color` or the container's text color. |
|
|
154
|
+
| `strokeWidth` | `number` | `2` | Line width in pixels, `0` or more. Arrows and anchors scale with it. |
|
|
155
|
+
| `dashed` | `boolean` | `false` | Dashed line. |
|
|
156
|
+
| `animated` | `boolean` | `false` | Dashes flowing from start to end. Needs `style.css`. |
|
|
157
|
+
| `anchors` | `boolean` | `false` | Dots where the line meets the elements. |
|
|
158
|
+
| `className` | `string` | | Extra classes for the connection's `<g>`. |
|
|
159
|
+
| `gap` | `number` | `0` | Space between the element edge and the line end. Negative moves the end into the element. |
|
|
160
|
+
| `spread` | `boolean` | `true` | Spread lines that share a side of an element. |
|
|
161
|
+
| `spacing` | `number` | `16` | Distance between spread lines, `0` or more. Shrinks to fit the side. |
|
|
162
|
+
| `curvature` | `number` | `1` | `bezier`: how far the curve bulges out. Negative bulges the other way. |
|
|
163
|
+
| `radius` | `number` | `8` | `orthogonal`: corner radius, `0` or more. `0` for sharp corners. |
|
|
164
|
+
| `offset` | `number` | `20` | `orthogonal`: how far the line goes straight out of an element before turning, `0` or more. |
|
|
165
|
+
|
|
166
|
+
The path builders `bezierPath`, `straightPath` and `orthogonalPath` are also
|
|
167
|
+
exported if you want to draw lines between points yourself.
|
|
168
|
+
|
|
169
|
+
### Errors
|
|
170
|
+
|
|
171
|
+
Options are checked when they are given, so a mistake fails at once with a
|
|
172
|
+
message that names the option:
|
|
173
|
+
|
|
174
|
+
- **`TypeError`:** a value of the wrong type, for example `strokeWidth: '3'`,
|
|
175
|
+
`label: 0`, or a target that is neither an element nor a selector.
|
|
176
|
+
- **`RangeError`:** a value out of range, for example `type: 'wavy'`,
|
|
177
|
+
`startSide: 'middle'` or `radius: -5`.
|
|
178
|
+
- **`ArclaceError`:** Arclace can't do what was asked: a selector matches
|
|
179
|
+
nothing or is invalid (with the browser's error as `cause`), an id is taken,
|
|
180
|
+
or the connection or the instance has been removed. It is exported, for
|
|
181
|
+
`instanceof` checks.
|
|
182
|
+
|
|
183
|
+
Every message starts with `arclace:`. When a call throws, nothing is added, so
|
|
184
|
+
the lines already drawn keep working. An option set to `undefined` uses the
|
|
185
|
+
default, and option names Arclace doesn't know are ignored.
|
|
186
|
+
|
|
187
|
+
## Styling
|
|
188
|
+
|
|
189
|
+
Each connection is rendered as:
|
|
190
|
+
|
|
191
|
+
```html
|
|
192
|
+
<g
|
|
193
|
+
class="arc-connection arc-bezier"
|
|
194
|
+
data-type="bezier"
|
|
195
|
+
data-start-side="right"
|
|
196
|
+
data-end-side="left"
|
|
197
|
+
>
|
|
198
|
+
<marker class="arc-marker">…</marker>
|
|
199
|
+
<!-- arrow -->
|
|
200
|
+
<path class="arc-path" />
|
|
201
|
+
<text class="arc-label">…</text>
|
|
202
|
+
<!-- label -->
|
|
203
|
+
<circle class="arc-anchor arc-anchor-start" />
|
|
204
|
+
<!-- anchors -->
|
|
205
|
+
<circle class="arc-anchor arc-anchor-end" />
|
|
206
|
+
</g>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Lines, arrows and anchors use `currentColor`, so `color` on `.arc-connection`
|
|
210
|
+
colors all of them:
|
|
211
|
+
|
|
212
|
+
```css
|
|
213
|
+
.arc-connection {
|
|
214
|
+
color: #6e625e;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.arc-connection.important {
|
|
218
|
+
color: #0054f0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.arc-path {
|
|
222
|
+
stroke-width: 3;
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`style.css` is optional. It adds a halo behind labels, hollow anchors and the
|
|
227
|
+
`animated` dash animation (turned off with `prefers-reduced-motion`), and these
|
|
228
|
+
custom properties:
|
|
229
|
+
|
|
230
|
+
| Property | Default |
|
|
231
|
+
| ------------------- | -------------- |
|
|
232
|
+
| `--arc-color` | `currentColor` |
|
|
233
|
+
| `--arc-label-color` | `currentColor` |
|
|
234
|
+
| `--arc-label-halo` | `#fff` |
|
|
235
|
+
| `--arc-label-size` | `12px` |
|
|
236
|
+
| `--arc-anchor-fill` | `#fff` |
|
|
237
|
+
|
|
238
|
+
### Clickable lines
|
|
239
|
+
|
|
240
|
+
The overlay ignores the pointer so it never blocks your page. To make lines
|
|
241
|
+
clickable, turn pointer events back on for the paths:
|
|
242
|
+
|
|
243
|
+
```css
|
|
244
|
+
.arc-path {
|
|
245
|
+
pointer-events: visibleStroke;
|
|
246
|
+
cursor: pointer;
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
connection.path.addEventListener('click', () => console.log(connection.id));
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Keeping lines in sync
|
|
255
|
+
|
|
256
|
+
With the default `autoUpdate: true`, lines are redrawn (at most once per frame)
|
|
257
|
+
when:
|
|
258
|
+
|
|
259
|
+
- the window resizes or anything scrolls
|
|
260
|
+
- the container or a connected element changes size
|
|
261
|
+
- elements are added or removed in the container, or their `style`, `class` or
|
|
262
|
+
`hidden` attributes change. Dragging by setting `style.left`/`top` or
|
|
263
|
+
`style.transform` just works.
|
|
264
|
+
|
|
265
|
+
For movement it can't observe, like CSS transitions and animations, either call
|
|
266
|
+
`arclace.update()` yourself or use `autoUpdate: 'frame'`.
|
|
267
|
+
|
|
268
|
+
## With frameworks
|
|
269
|
+
|
|
270
|
+
Create the instance after the elements are mounted and destroy it on unmount. In
|
|
271
|
+
React:
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
const arclace = new Arclace({ container: containerRef.current });
|
|
276
|
+
|
|
277
|
+
arclace.connect(aRef.current, bRef.current, { arrow: 'end' });
|
|
278
|
+
|
|
279
|
+
return () => arclace.destroy();
|
|
280
|
+
}, []);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Development
|
|
284
|
+
|
|
285
|
+
```shell
|
|
286
|
+
npm i
|
|
287
|
+
npm run dev # demo at http://localhost:5173
|
|
288
|
+
npm test
|
|
289
|
+
npm run test:ci # with coverage thresholds
|
|
290
|
+
npm run lint
|
|
291
|
+
npm run build # dist/
|
|
292
|
+
npm run check:pack # pack, install and run every example in Chrome
|
|
293
|
+
npm run docs:gen # API docs in docs/api/
|
|
294
|
+
npm run docs:dev # docs site at http://localhost:5173/arclace/
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Background
|
|
298
|
+
|
|
299
|
+
Arclace comes from [SPECCER](https://speccer.dev). While building SPECCER, I
|
|
300
|
+
spent most of the time on my own SVG feature for drawing the lines between its
|
|
301
|
+
pins and the elements they point at, with bezier curves shaped into curly
|
|
302
|
+
brackets.
|
|
303
|
+
|
|
304
|
+
I then found I could reuse that code to give a better overview of design tokens
|
|
305
|
+
and how they relate to one another. The first public proof of concept is
|
|
306
|
+
[on CodePen](https://codepen.io/editor/phun-ky/pen/01783ae7-e010-76d8-9429-43a7be9da34f).
|
|
307
|
+
After years of other work taking priority, I split the line drawing out into
|
|
308
|
+
this package, so it can connect anything on a page.
|
|
309
|
+
|
|
310
|
+
## Why Arclace?
|
|
311
|
+
|
|
312
|
+
Arclace combines **arc** and **lace**: the curve of a line, and the act of
|
|
313
|
+
threading separate things together.
|
|
314
|
+
|
|
315
|
+
**Arc** reflects the library's visual character and its origins in
|
|
316
|
+
[SPECCER](https://speccer.dev). There, curved SVG lines formed curly brackets
|
|
317
|
+
between annotation pins and the HTML elements they described. The same drawing
|
|
318
|
+
code later found another use: showing how design tokens relate to each other.
|
|
319
|
+
|
|
320
|
+
**Lace** captures the broader purpose: joining elements with visible threads,
|
|
321
|
+
the way a lace runs through eyelets. Move, resize, scroll or zoom an element,
|
|
322
|
+
and the lace follows. Whether a connection curves, runs straight or turns a
|
|
323
|
+
corner, it makes a relationship visible.
|
|
324
|
+
|
|
325
|
+
Together, the words tie the library's drawing roots to its wider role in
|
|
326
|
+
diagrams, node editors, flowcharts and annotated interfaces. And it reads
|
|
327
|
+
naturally in code:
|
|
328
|
+
|
|
329
|
+
```js
|
|
330
|
+
new Arclace({ container: '#diagram' });
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Pronounced "ARK-lays".
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
|
|
337
|
+
[MIT](LICENSE) © 2021-2026 Alexander Vassbotn Røyne-Helgesen
|