@harmonics/lattice-ui 0.1.0 → 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 CHANGED
@@ -3,6 +3,30 @@
3
3
  `@harmonics/lattice-ui` follows semantic versioning; while it is `0.x`, a minor version may change
4
4
  an element's inputs, events or tokens, and says so here.
5
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
+
6
30
  ## 0.1.0
7
31
 
8
32
  - `<lattice-face>`: the tree's face, by mood or by expression, idling, with a laugh of relief on
package/README.md CHANGED
@@ -155,6 +155,80 @@ them: `lattice-icon::part(done-cell)`, `::part(done-check)`, `::part(shears-blad
155
155
 
156
156
  TypeScript knows the tags from `HTMLElementTagNameMap` once the package is imported.
157
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
+
158
232
  ## Server rendering
159
233
 
160
234
  Importing either entry on a server does nothing and throws nothing. Render the tags as markup;
package/dist/define.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./elements-DMimFemm.js";
1
+ import { t as e } from "./elements-BJBhL4LI.js";
2
2
  //#region src/elements/define.ts
3
3
  e();
4
4
  //#endregion