@harmonics/lattice-ui 0.0.0-stage → 0.4.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 ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ `@harmonics/lattice-ui` follows semantic versioning; while it is `0.x`, a minor version may change
4
+ an element's inputs, events or tokens, and says so here.
5
+
6
+ ## 0.4.0
7
+
8
+ - The magnet in `@harmonics/lattice-ui/hexes`: `magnetOf(piece, dx, dy, held)` says where to draw a
9
+ carried piece and which slot it would land in. Near a slot it leans in, nearer the slot catches
10
+ and holds it, and it stays held until tugged past a release distance (`MAGNET` has the four
11
+ distances). `snapFrames(from)` is the click into the slot: Web Animations keyframes that pass it
12
+ once and settle; `stepOnScreen(step)` is a step's move on the screen. Additive: nothing in 0.3.0 changes.
13
+
14
+ ## 0.3.0
15
+
16
+ - Glue in `@harmonics/lattice-ui/hexes`: `glued` (a piece joined to every piece it shares a side
17
+ with, each part keeping its tone), `sharedSides` (the sides that would glue), `seamsOf` (where a
18
+ piece is glued), `apart` (back into its units), `pulledOff` (one part off, the rest as one piece
19
+ or several); with `turned` and `pivotPoint` (a sixth of a turn about the piece's pivot) and
20
+ `unitAt` (a new cell or triangle under a point). Additive: nothing in 0.2.0 changes.
21
+
22
+ ## 0.2.0
23
+
24
+ - `@harmonics/lattice-ui/hexes`: the lattice's geometry, for pages that place their own pieces on
25
+ the sky. Cells, corners and triangles (`boxOf`, `cornerOf`, `cornersOf`, `hexAt`, `cornerAt`,
26
+ `trisOf`), pieces (`pieceOf`, `covered`, `outlineOf`, `touching`), moving and snapping (`moved`,
27
+ `snapDelta`, `stepFor`) and finding room (`fits`, `nearestFit`, `screenArea`). Pure functions, no
28
+ DOM. Additive: nothing in 0.1.0 changes.
29
+
30
+ ## 0.1.0
31
+
32
+ - `<lattice-face>`: the tree's face, by mood or by expression, idling, with a laugh of relief on
33
+ `pulse`.
34
+ - `<lattice-shape>`: nine ready-made shapes of lattice cells and triangles, or any `parts`, in eight
35
+ woods.
36
+ - `<hex-sky>`: the sky and the earth lattices, at any scale and origin.
37
+ - `<shears-pad>`: the cut gesture, as `stroke` and `strokeend` events.
38
+ - `<lattice-icon>`: the shears and done marks.
39
+ - Types for React 19 (`/react`) and Solid (`/solid`); `HTMLElementTagNameMap` for every tag.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Blankenship
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,239 @@
1
- # Temporary Holding Version
1
+ # @harmonics/lattice-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Harmonics tree's look as Custom Elements: a face drawn in the lattice's own triangles, the
4
+ hexagon sky, raised shapes of cells and triangles, a shears cut gesture, and two marks. They work
5
+ on any page and in any framework (React, Vue, Svelte, Solid, plain HTML) with no build step. Each
6
+ draws in its own shadow root and carries the tree's colours with it, so it needs nothing else from
7
+ the page. You bring the state; the elements draw it.
8
+
9
+ ```sh
10
+ npm install @harmonics/lattice-ui
11
+ ```
12
+
13
+ ## In five minutes
14
+
15
+ ```html
16
+ <script type="module">
17
+ import "@harmonics/lattice-ui/define"; // registers every element
18
+ </script>
19
+
20
+ <lattice-face mood="distressed"></lattice-face>
21
+ <lattice-shape shape="flower" tone="4"></lattice-shape>
22
+ <hex-sky style="height: 200px"></hex-sky>
23
+ <button><lattice-icon name="shears"></lattice-icon> Prune</button>
24
+ ```
25
+
26
+ `@harmonics/lattice-ui` itself defines nothing when imported: call `defineLatticeElements()` (or
27
+ one element's `defineLatticeFace()`, …) in a browser. Both are safe to import in a server render;
28
+ there they do nothing. Every input is both an attribute and a property.
29
+
30
+ ## Elements
31
+
32
+ ### `<lattice-face>`
33
+
34
+ A pale hexagon plate raised off the page with a face on it, in 1,536 of the lattice's triangles.
35
+ It idles (blinks, bobs), laughs with relief when `pulse` goes up, and sinks the old face as a new
36
+ one comes. Under `prefers-reduced-motion`, or `still`, it holds still and only changes.
37
+
38
+ | Input | Type | Default | |
39
+ |---|---|---|---|
40
+ | `mood` | `happy` `content` `asleep` `sad` `distressed` `puzzled` `relieved` (`MOODS`) | `happy` | The tree's moods, each wearing a face |
41
+ | `expression` | a name from `FACES` (`Happy`, `Laughing`, `Sad`, `Surprised`, `Angry`, `Worried`, `Sleepy`, `Wink`, `Smitten`) | | Wins over `mood` |
42
+ | `pulse` | number | `0` | Raise it by one for a laugh of relief |
43
+ | `still` | boolean | `false` | No idle, no laugh, no fade |
44
+ | `size` | number (pixels) | `96` | Its width; the height follows |
45
+ | `label` | string | "A happy face" | What a screen reader says |
46
+ | `decorative` | boolean | `false` | Hidden from screen readers |
47
+
48
+ ```js
49
+ const face = document.querySelector("lattice-face");
50
+ face.pulse += 1;
51
+ ```
52
+
53
+ ### `<lattice-shape>`
54
+
55
+ A shape made of the sky lattice's own cells and triangles, raised off the page, each part in one
56
+ of the tree's woods.
57
+
58
+ | Input | Type | Default | |
59
+ |---|---|---|---|
60
+ | `shape` | `cell` `pair` `line` `flower` `triangle` `diamond` `trapezoid` `big-triangle` `hexagon` (`SHAPE_NAMES`) | `cell` | |
61
+ | `parts` | `Part[]`, or the same as JSON | | Any shape on the lattice; wins over `shape` |
62
+ | `tone` | 0–7 | `0` | 0–4 the tree's woods, 5 good fruit, 6 bitter, 7 untasted |
63
+ | `lift` | number | `8` | How high it stands, in lattice units |
64
+ | `scale` | number | `1` | 1 is the tree's own size: a cell 76 pixels across |
65
+ | `label` | string | | Without one it is hidden from screen readers |
66
+
67
+ A part is a cell `{ kind: "cell", at: { q, r } }` on the axial hex grid, or a triangle
68
+ `{ kind: "tri", at: { i, j, k } }` (corner `i, j` of the triangle grid, `k` 0 pointing right, 1
69
+ left), each with an optional `tone`.
70
+
71
+ ```js
72
+ shape.parts = [
73
+ { kind: "cell", at: { q: 0, r: 0 }, tone: 1 },
74
+ { kind: "tri", at: { i: 0, j: 3, k: 0 }, tone: 5 },
75
+ ];
76
+ ```
77
+
78
+ ### `<hex-sky>`
79
+
80
+ The tree's sky, its hexagon lattice drawn faint over it, filling the element. Size it as any block.
81
+ Decorative.
82
+
83
+ | Input | Type | Default | |
84
+ |---|---|---|---|
85
+ | `kind` | `sky` `earth` | `sky` | Earth: cells broken into triangles, on the earth's colour |
86
+ | `scale` | number | `1` | The lattice's size |
87
+ | `x`, `y` | number (pixels) | `0` | Where the lattice's origin sits from the element's top-left, so a sky showing part of a larger one keeps its cells in place |
88
+
89
+ ### `<shears-pad>`
90
+
91
+ The cut gesture. A drag across it draws the blade's fading trail and reports the stroke; what it
92
+ cuts is yours to decide. Put it over what can be cut and size it as any block.
93
+
94
+ | Event | `detail` | |
95
+ |---|---|---|
96
+ | `stroke` | `{ points, fresh }` | At every move; `fresh` on a stroke's first point |
97
+ | `strokeend` | `{ points }` | When the pointer lifts |
98
+
99
+ Points are in the element's own pixels from its top-left. `disabled` stops it taking strokes. A
100
+ cut by pointer has no keyboard of its own: give the same action a button.
101
+
102
+ ```js
103
+ pad.addEventListener("stroke", (e) => cutAlong(e.detail.points));
104
+ ```
105
+
106
+ ### `<lattice-icon>`
107
+
108
+ `name="shears"` or `name="done"`, in the text's colour, a step square
109
+ (`--lattice-icon-size` to change it). Hidden from screen readers unless it has a `label`.
110
+
111
+ ## Styling
112
+
113
+ Every element carries the tree's colour tokens, light and dark (it follows
114
+ `prefers-color-scheme`). Set any of them on the element itself to change it:
115
+
116
+ ```css
117
+ lattice-face, lattice-shape {
118
+ --color-tree-ink: #222;
119
+ --color-tree-raised: #fffdf6;
120
+ }
121
+ ```
122
+
123
+ Set them on the elements, not on `body`: an element's own tokens sit nearer than an ancestor's.
124
+ The ones the elements use:
125
+
126
+ | Token | Used for |
127
+ |---|---|
128
+ | `--color-tree-sky` | the sky, and what woods and plates are mixed with |
129
+ | `--color-tree-earth` | the earth sky |
130
+ | `--color-tree-ink` | the face's features |
131
+ | `--color-tree-raised` | the face's plate, a glint, untasted fruit |
132
+ | `--color-tree-wood-0` … `--color-tree-wood-4` | the five woods; `wood-0` is also the plate's edge |
133
+ | `--color-tree-olive` | fruit |
134
+ | `--color-tree-alert` | blush, the tongue, the blade's trail |
135
+ | `--color-tree-lattice-sky`, `--color-tree-lattice-earth` | the lattice lines |
136
+ | `--tree-rule-width`, `--tree-rule-thick-width` | edges, seams, the blade |
137
+ | `--space-tree-2`, `--space-tree-4` | how far a face sinks; an icon's size |
138
+
139
+ Each element also exposes its drawing as a part: `::part(face)`, `::part(shape)`, `::part(sky)`,
140
+ `::part(trail)`, `::part(icon)`. A mark's own paths are parts too, for a hover that recolours
141
+ them: `lattice-icon::part(done-cell)`, `::part(done-check)`, `::part(shears-blade)`,
142
+ `::part(shears-handle)`.
143
+
144
+ ## Frameworks
145
+
146
+ - **React 19**: use the tags directly; add `import type {} from "@harmonics/lattice-ui/react"`
147
+ for their props. React 19 sets inputs as properties, so `parts={[…]}` works, and listens with
148
+ `onstroke` / `onstrokeend`.
149
+ - **Solid**: `import type {} from "@harmonics/lattice-ui/solid"`; set objects with `prop:parts`;
150
+ listen with `on:stroke`.
151
+ - **Vue**: tell the compiler the tags are custom elements
152
+ (`compilerOptions.isCustomElement: (tag) => /^(lattice|hex|shears)-/.test(tag)`); bind objects
153
+ with `.prop` (`:parts.prop="parts"`); listen with `@stroke`.
154
+ - **Svelte, Angular, plain HTML**: as any custom element.
155
+
156
+ TypeScript knows the tags from `HTMLElementTagNameMap` once the package is imported.
157
+
158
+ ## Geometry
159
+
160
+ `@harmonics/lattice-ui/hexes` is the lattice's own geometry, for a page that places pieces on the
161
+ sky itself (a board, a puzzle, an editor). Pure functions, no DOM, safe in a server render.
162
+
163
+ ```js
164
+ import { pieceOf, moved, snapDelta, fits, nearestFit, screenArea } from "@harmonics/lattice-ui/hexes";
165
+
166
+ const piece = pieceOf("a", [{ kind: "cell", at: { q: 2, r: 1 }, tone: 1 }]);
167
+ const carried = moved(piece, snapDelta(piece, dx, dy)); // follow a pointer, snapped to whole cells
168
+ const placed = fits(carried, others, screenArea(width, height))
169
+ ? carried
170
+ : nearestFit(carried, others, screenArea(width, height));
171
+ ```
172
+
173
+ The sky is pointy-top hexagons 44 on a side: a cell is 76.21 across, rows are 66 apart, and each
174
+ row starts half a cell further right. A cell is `{ q, r }` (axial); its box's top-left is
175
+ `boxOf(hex)`. Split into triangles, the sky is also a grid of corners `{ i, j }` (`cornerOf`), each
176
+ the top-left of two triangles `{ i, j, k }`: `k` 0 points right, 1 left. A piece is
177
+ `{ id, parts, pivot }`; make one with `pieceOf`. A piece with a cell moves a whole cell at a time.
178
+
179
+ To lay a `<lattice-shape>` exactly on a `<hex-sky>` of the same `scale` (`s`), give the shape the
180
+ piece's parts and place it at `s × (minX − 2, minY − lift − 2)`, the top-left of every corner it
181
+ covers (`covered`, `cornersOf`, `cornerOf`), less the shape's padding and lift.
182
+
183
+ ### Glue
184
+
185
+ Pieces that share a side (not only a corner) can be glued into one; each part keeps its `tone`, so
186
+ a glued piece still shows its woods, and it moves and turns as one. The functions that split a
187
+ piece take `id`, your own generator of new piece ids.
188
+
189
+ ```js
190
+ import { apart, glued, pulledOff, seamsOf, sharedSides, turned, unitAt } from "@harmonics/lattice-ui/hexes";
191
+
192
+ const sides = others.flatMap((o) => sharedSides(piece, o)); // where G would glue: draw them lit
193
+ const { piece: one, absorbed } = glued(piece, others); // G: drop the absorbed ids from your list
194
+ const seams = seamsOf(one); // the sides between its parts, to draw as hairlines
195
+ const units = apart(one, newId); // Shift+G: every part a piece of its own
196
+ const [part, ...rest] = pulledOff(one, index, newId); // one part off; the rest stay joined
197
+ const turnedOnce = turned(one, 1); // a sixth clockwise about its pivot (pivotPoint(one) on screen)
198
+ const fresh = unitAt("tri", x, y, tone, newId()); // a new cell or triangle under a point
199
+ ```
200
+
201
+ Sides and seams come as pairs of screen points, in the sky's own pixels. Glued pieces are drawn
202
+ with `<lattice-shape>` like any other: give it the piece's parts.
203
+
204
+ ### Magnet
205
+
206
+ A carried piece is pulled into the sky's lattice. Near a slot it leans in. Nearer, the slot
207
+ catches it and it is drawn there exactly. It stays held until it is tugged past a release
208
+ distance, which is further out than the catch, so it never flickers at the edge. `MAGNET` holds
209
+ the four distances, as parts of the piece's unit: `reach`, `capture`, `release` and `lean`.
210
+
211
+ ```js
212
+ import { magnetOf, moved, snapFrames, stepOnScreen } from "@harmonics/lattice-ui/hexes";
213
+
214
+ let held; // the slot it is held in, handed back on every move
215
+ onPointerMove((dx, dy) => {
216
+ const m = magnetOf(piece, dx, dy, held);
217
+ held = m.held;
218
+ draw(piece, m.x, m.y); // where it is drawn, as a move from where it was lifted
219
+ glow(m.step, m.pull); // the slot it would land in, and how hard it pulls (0 to 1)
220
+ });
221
+ onPointerUp((dx, dy) => {
222
+ const m = magnetOf(piece, dx, dy, held);
223
+ const slot = stepOnScreen(m.step); // the slot's move on the screen
224
+ piece = moved(piece, m.step);
225
+ // The click: from where it was let go, past the slot once, to rest in it.
226
+ element.animate(snapFrames({ x: m.x - slot.x, y: m.y - slot.y }), { duration: 260 });
227
+ });
228
+ ```
229
+
230
+ Under reduced motion, draw the piece in its slot and leave out the animation.
231
+
232
+ ## Server rendering
233
+
234
+ Importing either entry on a server does nothing and throws nothing. Render the tags as markup;
235
+ they draw when the page defines them in the browser.
236
+
237
+ ## Licence
238
+
239
+ MIT. The package bundles [Solid](https://www.solidjs.com) (MIT).
package/dist/define.js ADDED
@@ -0,0 +1,4 @@
1
+ import { t as e } from "./elements-BJBhL4LI.js";
2
+ //#region src/elements/define.ts
3
+ e();
4
+ //#endregion