@harmonics/lattice-ui 0.4.0 → 0.5.1

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,33 @@
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.5.1
7
+
8
+ - What 0.5.0 says, built. 0.5.0 shipped this README and CHANGELOG over a `dist` built before
9
+ them: its scripts have `orient` and nothing else of 0.5.0, and its `react.d.ts` imports a
10
+ `StrokeEndDetail` its types do not have. `npm publish` now builds and checks the package first.
11
+
12
+ ## 0.5.0
13
+
14
+ - `<shears-pad>` always ends a stroke. `strokeend` carries `cancelled`: true when the stroke was cut
15
+ short (the pointer cancelled or its capture lost, `disabled` set mid-stroke, the pad taken off
16
+ the page), where before no `strokeend` came at all. `pointercancel` is now `cancelled: true`.
17
+ `stroke` carries `point`, the newest point.
18
+ - **Types:** `stroke` and `strokeend` are typed on `ShearsPadElement` (`ShearsPadEventMap`, and
19
+ `StrokeEndDetail`) instead of on every element's `HTMLElementEventMap`. A listener added on a
20
+ plain `HTMLElement` reference now needs the pad's type, or a cast.
21
+ - `<lattice-face>` idles on animation frames and stops while off screen or in a hidden tab; it
22
+ follows `prefers-reduced-motion` as it changes, not only as it was when first drawn.
23
+ - An element moved on the page keeps its drawing and state; it lets go only once it stays off.
24
+ - `defineX(name)` registers an element under a tag of your own. A tag another element holds is
25
+ left to it with a console warning instead of in silence.
26
+ - `<lattice-shape>` warns once when `parts` is a string that is not JSON (the usual cause: React
27
+ set it before the elements were defined). `parts` read twice is the same array.
28
+ - `@harmonics/lattice-ui/hexes` exports `crossesCell`, `crossesLine` and `crossesRing`.
29
+ - `<hex-sky orient="flat">`: the lattice turned a quarter turn clockwise about its origin, for pages
30
+ whose pieces have flat-topped cells. `x`, `y` and `scale` mean what they did; the default,
31
+ `pointy`, draws exactly what 0.4.0 did.
32
+
6
33
  ## 0.4.0
7
34
 
8
35
  - The magnet in `@harmonics/lattice-ui/hexes`: `magnetOf(piece, dx, dy, held)` says where to draw a
package/README.md CHANGED
@@ -25,7 +25,15 @@ npm install @harmonics/lattice-ui
25
25
 
26
26
  `@harmonics/lattice-ui` itself defines nothing when imported: call `defineLatticeElements()` (or
27
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.
28
+ there they do nothing. Every input is both an attribute and a property; a property set does not
29
+ change the attribute, so style by class rather than by `[mood=…]`. A value an input does not know
30
+ falls back to its default.
31
+
32
+ A tag another library already holds is left to it, with a warning. Give the element a tag of your
33
+ own instead: `defineHexSky("my-sky")`, and the same for every `defineX`.
34
+
35
+ An element moved on the page (a list reordered) keeps what it was doing; one taken off the page
36
+ lets go a moment later.
29
37
 
30
38
  ## Elements
31
39
 
@@ -33,7 +41,8 @@ there they do nothing. Every input is both an attribute and a property.
33
41
 
34
42
  A pale hexagon plate raised off the page with a face on it, in 1,536 of the lattice's triangles.
35
43
  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.
44
+ one comes. Under `prefers-reduced-motion` (followed as it changes), or `still`, it holds still and
45
+ only changes. Off screen, or in a hidden tab, it does not idle.
37
46
 
38
47
  | Input | Type | Default | |
39
48
  |---|---|---|---|
@@ -83,6 +92,7 @@ Decorative.
83
92
  | Input | Type | Default | |
84
93
  |---|---|---|---|
85
94
  | `kind` | `sky` `earth` | `sky` | Earth: cells broken into triangles, on the earth's colour |
95
+ | `orient` | `pointy` `flat` | `pointy` | Flat: the lattice turned a quarter turn clockwise about its origin, so its cells have flat tops and bottoms |
86
96
  | `scale` | number | `1` | The lattice's size |
87
97
  | `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
98
 
@@ -93,16 +103,20 @@ cuts is yours to decide. Put it over what can be cut and size it as any block.
93
103
 
94
104
  | Event | `detail` | |
95
105
  |---|---|---|
96
- | `stroke` | `{ points, fresh }` | At every move; `fresh` on a stroke's first point |
97
- | `strokeend` | `{ points }` | When the pointer lifts |
106
+ | `stroke` | `{ points, point, fresh }` | At every move; `point` is the newest, `fresh` on a stroke's first |
107
+ | `strokeend` | `{ points, cancelled }` | Once per stroke: lifted, or `cancelled` when cut short (the pointer cancelled or lost, `disabled` set, the pad taken off the page) |
98
108
 
99
109
  Points are in the element's own pixels from its top-left. `disabled` stops it taking strokes. A
100
110
  cut by pointer has no keyboard of its own: give the same action a button.
101
111
 
102
112
  ```js
103
113
  pad.addEventListener("stroke", (e) => cutAlong(e.detail.points));
114
+ pad.addEventListener("strokeend", (e) => (e.detail.cancelled ? undo() : commit()));
104
115
  ```
105
116
 
117
+ `ShearsPadEventMap` types these on the pad's own `addEventListener`. To find what a stroke cut,
118
+ see [Cutting](#cutting).
119
+
106
120
  ### `<lattice-icon>`
107
121
 
108
122
  `name="shears"` or `name="done"`, in the text's colour, a step square
@@ -145,7 +159,9 @@ them: `lattice-icon::part(done-cell)`, `::part(done-check)`, `::part(shears-blad
145
159
 
146
160
  - **React 19**: use the tags directly; add `import type {} from "@harmonics/lattice-ui/react"`
147
161
  for their props. React 19 sets inputs as properties, so `parts={[…]}` works, and listens with
148
- `onstroke` / `onstrokeend`.
162
+ `onstroke` / `onstrokeend`. Define the elements before React first renders them: until then
163
+ React cannot see the property and sets `parts` as the attribute `"[object Object]"`, which draws
164
+ nothing (the shape warns once in the console when that happens).
149
165
  - **Solid**: `import type {} from "@harmonics/lattice-ui/solid"`; set objects with `prop:parts`;
150
166
  listen with `on:stroke`.
151
167
  - **Vue**: tell the compiler the tags are custom elements
@@ -229,6 +245,25 @@ onPointerUp((dx, dy) => {
229
245
 
230
246
  Under reduced motion, draw the piece in its slot and leave out the animation.
231
247
 
248
+ ### Cutting
249
+
250
+ What a `<shears-pad>` stroke went through. A stroke goes through an outline when it goes in at one
251
+ side and out at another; one that only grazes a corner, or stops inside, does not.
252
+
253
+ ```js
254
+ import { crossesCell, crossesLine, crossesRing } from "@harmonics/lattice-ui/hexes";
255
+
256
+ pad.addEventListener("stroke", (e) => {
257
+ const stroke = e.detail.points; // in the sky's pixels when the pad covers the sky at scale 1
258
+ const isCut = (part) => part.kind === "cell" && crossesCell(stroke, part.at);
259
+ const cut = pieces.filter((p) => p.parts.some(isCut));
260
+ const severed = crossesLine(stroke, branch); // through a line of points
261
+ const through = crossesRing(stroke, outline); // through any closed outline
262
+ });
263
+ ```
264
+
265
+ `crossesCell(stroke, hex, lift)` takes the cell as drawn `lift` above its place.
266
+
232
267
  ## Server rendering
233
268
 
234
269
  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-BJBhL4LI.js";
1
+ import { t as e } from "./elements-Ka2LbDpP.js";
2
2
  //#region src/elements/define.ts
3
3
  e();
4
4
  //#endregion