@harmonics/lattice-ui 0.5.0 → 0.6.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.
@@ -0,0 +1,59 @@
1
+ import type { BoardAction } from "../boardTypes";
2
+ import { type Part, type Piece } from "../hexes";
3
+ import { LatticeElement } from "./host";
4
+ export declare const BOARD_TAG = "lattice-board";
5
+ /** A piece as a page hands it over: an id of its own (one is made if not) and its parts. */
6
+ export interface BoardPiece {
7
+ id?: string;
8
+ parts: Part[];
9
+ }
10
+ export interface BoardChangeDetail {
11
+ /** The board's pieces now, fixed ones left out. */
12
+ pieces: Piece[];
13
+ action: BoardAction;
14
+ /** The piece acted on ("" when the board itself moved pieces back into view). */
15
+ id: string;
16
+ }
17
+ /** The board's own events, for `addEventListener`. */
18
+ export interface LatticeBoardEventMap extends HTMLElementEventMap {
19
+ change: CustomEvent<BoardChangeDetail>;
20
+ catch: CustomEvent<{
21
+ id: string;
22
+ }>;
23
+ }
24
+ export interface LatticeBoard {
25
+ addEventListener<K extends keyof LatticeBoardEventMap>(type: K, listener: (this: LatticeBoard, event: LatticeBoardEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
26
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
27
+ removeEventListener<K extends keyof LatticeBoardEventMap>(type: K, listener: (this: LatticeBoard, event: LatticeBoardEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
28
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
29
+ }
30
+ export declare class LatticeBoard extends LatticeElement {
31
+ static readonly observedAttributes: string[];
32
+ private readonly givenSignal;
33
+ private readonly fixedSignal;
34
+ private readonly traySignal;
35
+ private readonly scaleSignal;
36
+ private readonly labelSignal;
37
+ /** The board's pieces while it is drawn. */
38
+ private live;
39
+ private made;
40
+ private readonly madeId;
41
+ /** The pieces on the board, fixed ones left out. */
42
+ get pieces(): Piece[];
43
+ set pieces(pieces: unknown);
44
+ /** Pieces drawn flat and in the way, never handled. */
45
+ get fixed(): Piece[];
46
+ set fixed(pieces: unknown);
47
+ get tray(): boolean;
48
+ set tray(tray: boolean | string | null);
49
+ get scale(): number;
50
+ set scale(scale: number | string);
51
+ get label(): string;
52
+ set label(label: string);
53
+ attributeChangedCallback(name: string, _: string | null, value: string | null): void;
54
+ }
55
+ /**
56
+ * Register `<lattice-board>` once, or as `name` (a tag of your own, when another library holds
57
+ * this one); a second call, or a call on a server, does nothing.
58
+ */
59
+ export declare const defineLatticeBoard: (name?: string) => void;
@@ -28,5 +28,8 @@ export declare class LatticeFace extends LatticeElement {
28
28
  set decorative(decorative: boolean | string | null);
29
29
  attributeChangedCallback(name: string, _: string | null, value: string | null): void;
30
30
  }
31
- /** Register `<lattice-face>` once; a second call, or a call on a server, does nothing. */
32
- export declare const defineLatticeFace: () => void;
31
+ /**
32
+ * Register `<lattice-face>` once, or as `name` (a tag of your own, when another library holds this
33
+ * one); a second call, or a call on a server, does nothing.
34
+ */
35
+ export declare const defineLatticeFace: (name?: string) => void;
@@ -1 +1 @@
1
- export { type Area, apart, boxOf, type Corner, cornerAt, cornerOf, cornersOf, covered, fits, glued, type Hex, hexAt, MAGNET, type Magnet, magnetOf, moved, nearestFit, outlineOf, type Part, type Piece, pieceOf, pivotPoint, pulledOff, screenArea, seamsOf, sharedSides, snapDelta, snapFrames, stepFor, stepOnScreen, type Tri, touching, trisOf, turned, unitAt, } from "../hexes";
1
+ export { type Area, apart, boxOf, type Corner, cornerAt, cornerOf, cornersOf, covered, crossesCell, crossesLine, crossesRing, fits, glued, type Hex, hexAt, MAGNET, type Magnet, magnetOf, moved, nearestFit, outlineOf, type Part, type Piece, pieceOf, pivotPoint, pulledOff, screenArea, seamsOf, sharedSides, snapDelta, snapFrames, stepFor, stepOnScreen, type Tri, touching, trisOf, turned, unitAt, } from "../hexes";
@@ -5,8 +5,11 @@
5
5
  declare const HostElement: typeof HTMLElement;
6
6
  /** One stylesheet per kind of element, made the first time one is shown and shared after. */
7
7
  export declare function sheetOf(css: string): () => CSSStyleSheet;
8
- /** Register an element once, in a browser; a second call, or a call on a server, does nothing. */
9
- export declare function define(tag: string, element: CustomElementConstructor): void;
8
+ /**
9
+ * Register an element once, in a browser, as `name` (its own `tag` by default); a second call, or
10
+ * a call on a server, does nothing. A name another element already holds is left to it, and said.
11
+ */
12
+ export declare function define(tag: string, element: CustomElementConstructor, name?: string): void;
10
13
  /** A whole number from an attribute or a property, or `fallback` when it is not one. */
11
14
  export declare const numberOf: (value: unknown, fallback: number) => number;
12
15
  /** Whether a boolean attribute or property is on: present, and not "false". */
@@ -12,5 +12,8 @@ export declare class LatticeIcon extends LatticeElement {
12
12
  set label(label: string);
13
13
  attributeChangedCallback(name: string, _: string | null, value: string | null): void;
14
14
  }
15
- /** Register `<lattice-icon>` once; a second call, or a call on a server, does nothing. */
16
- export declare const defineLatticeIcon: () => void;
15
+ /**
16
+ * Register `<lattice-icon>` once, or as `name` (a tag of your own, when another library holds this
17
+ * one); a second call, or a call on a server, does nothing.
18
+ */
19
+ export declare const defineLatticeIcon: (name?: string) => void;
@@ -1,7 +1,7 @@
1
1
  import { defineLatticeFace, LatticeFace } from "./face";
2
2
  import { defineLatticeIcon, LatticeIcon } from "./icon";
3
3
  import { defineLatticeShape, LatticeShape } from "./shape";
4
- import { defineShearsPad, ShearsPadElement, type StrokeDetail } from "./shears";
4
+ import { defineShearsPad, ShearsPadElement, type ShearsPadEventMap, type StrokeDetail, type StrokeEndDetail } from "./shears";
5
5
  import { defineHexSky, HexSky } from "./sky";
6
6
  export { FACES } from "../faceLattice";
7
7
  export type { Part } from "../hexes";
@@ -11,7 +11,7 @@ export { SHAPE_TAG } from "./shape";
11
11
  export { SHAPE_NAMES, type ShapeName, TONES } from "./shapes";
12
12
  export { SHEARS_TAG, type StrokePoint } from "./shears";
13
13
  export { SKY_TAG } from "./sky";
14
- export { defineHexSky, defineLatticeFace, defineLatticeIcon, defineLatticeShape, defineShearsPad, HexSky, LatticeFace, LatticeIcon, LatticeShape, ShearsPadElement, type StrokeDetail, };
14
+ export { defineHexSky, defineLatticeFace, defineLatticeIcon, defineLatticeShape, defineShearsPad, HexSky, LatticeFace, LatticeIcon, LatticeShape, ShearsPadElement, type ShearsPadEventMap, type StrokeDetail, type StrokeEndDetail, };
15
15
  /** Register every element once; a second call, or a call on a server, does nothing. */
16
16
  export declare function defineLatticeElements(): void;
17
17
  declare global {
@@ -22,10 +22,4 @@ declare global {
22
22
  "shears-pad": ShearsPadElement;
23
23
  "lattice-icon": LatticeIcon;
24
24
  }
25
- interface HTMLElementEventMap {
26
- stroke: CustomEvent<StrokeDetail>;
27
- strokeend: CustomEvent<{
28
- points: StrokeDetail["points"];
29
- }>;
30
- }
31
25
  }
@@ -12,7 +12,8 @@ export declare class LatticeShape extends LatticeElement {
12
12
  private readonly labelSignal;
13
13
  get shape(): ShapeName;
14
14
  set shape(name: string);
15
- /** The parts drawn: those given, or the shape's. */
15
+ private made;
16
+ /** The parts drawn: those given, or the shape's; the same array until an input changes. */
16
17
  get parts(): Part[];
17
18
  set parts(parts: unknown);
18
19
  get tone(): number;
@@ -25,5 +26,8 @@ export declare class LatticeShape extends LatticeElement {
25
26
  set label(label: string);
26
27
  attributeChangedCallback(name: string, _: string | null, value: string | null): void;
27
28
  }
28
- /** Register `<lattice-shape>` once; a second call, or a call on a server, does nothing. */
29
- export declare const defineLatticeShape: () => void;
29
+ /**
30
+ * Register `<lattice-shape>` once, or as `name` (a tag of your own, when another library holds this
31
+ * one); a second call, or a call on a server, does nothing.
32
+ */
33
+ export declare const defineLatticeShape: (name?: string) => void;
@@ -6,9 +6,28 @@ export type StrokePoint = {
6
6
  y: number;
7
7
  };
8
8
  export interface StrokeDetail {
9
+ /** The stroke so far, a copy of its own. */
9
10
  points: StrokePoint[];
11
+ /** The newest point, the last of `points`. */
12
+ point: StrokePoint;
10
13
  fresh: boolean;
11
14
  }
15
+ export interface StrokeEndDetail {
16
+ points: StrokePoint[];
17
+ /** The stroke was cut short instead of lifted. */
18
+ cancelled: boolean;
19
+ }
20
+ /** The pad's own events, for `addEventListener`. */
21
+ export interface ShearsPadEventMap extends HTMLElementEventMap {
22
+ stroke: CustomEvent<StrokeDetail>;
23
+ strokeend: CustomEvent<StrokeEndDetail>;
24
+ }
25
+ export interface ShearsPadElement {
26
+ addEventListener<K extends keyof ShearsPadEventMap>(type: K, listener: (this: ShearsPadElement, event: ShearsPadEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
27
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
28
+ removeEventListener<K extends keyof ShearsPadEventMap>(type: K, listener: (this: ShearsPadElement, event: ShearsPadEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
29
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
30
+ }
12
31
  export declare class ShearsPadElement extends LatticeElement {
13
32
  static readonly observedAttributes: string[];
14
33
  private readonly disabledSignal;
@@ -16,5 +35,8 @@ export declare class ShearsPadElement extends LatticeElement {
16
35
  set disabled(disabled: boolean | string | null);
17
36
  attributeChangedCallback(_: string, __: string | null, value: string | null): void;
18
37
  }
19
- /** Register `<shears-pad>` once; a second call, or a call on a server, does nothing. */
20
- export declare const defineShearsPad: () => void;
38
+ /**
39
+ * Register `<shears-pad>` once, or as `name` (a tag of your own, when another library holds this
40
+ * one); a second call, or a call on a server, does nothing.
41
+ */
42
+ export declare const defineShearsPad: (name?: string) => void;
@@ -19,5 +19,8 @@ export declare class HexSky extends LatticeElement {
19
19
  set y(y: number | string);
20
20
  attributeChangedCallback(name: string, _: string | null, value: string | null): void;
21
21
  }
22
- /** Register `<hex-sky>` once; a second call, or a call on a server, does nothing. */
23
- export declare const defineHexSky: () => void;
22
+ /**
23
+ * Register `<hex-sky>` once, or as `name` (a tag of your own, when another library holds this
24
+ * one); a second call, or a call on a server, does nothing.
25
+ */
26
+ export declare const defineHexSky: (name?: string) => void;
@@ -1,4 +1,5 @@
1
- import type { HexSky, IconName, LatticeFace, LatticeIcon, LatticeShape, Part, ShapeName, ShearsPadElement, StrokeDetail, StrokePoint } from "./index";
1
+ import type { BoardChangeDetail, BoardPiece, LatticeBoard } from "./board-entry";
2
+ import type { HexSky, IconName, LatticeFace, LatticeIcon, LatticeShape, Part, ShapeName, ShearsPadElement, StrokeDetail, StrokeEndDetail } from "./index";
2
3
  declare module "solid-js" {
3
4
  namespace JSX {
4
5
  interface IntrinsicElements {
@@ -13,6 +14,7 @@ declare module "solid-js" {
13
14
  };
14
15
  "hex-sky": JSX.HTMLAttributes<HexSky> & {
15
16
  kind?: "sky" | "earth";
17
+ orient?: "pointy" | "flat";
16
18
  scale?: number | string;
17
19
  x?: number | string;
18
20
  y?: number | string;
@@ -32,15 +34,24 @@ declare module "solid-js" {
32
34
  name?: IconName;
33
35
  label?: string;
34
36
  };
37
+ "lattice-board": JSX.HTMLAttributes<LatticeBoard> & {
38
+ tray?: boolean;
39
+ scale?: number | string;
40
+ label?: string;
41
+ };
35
42
  }
36
43
  interface ExplicitProperties {
37
44
  parts: Part[] | string;
45
+ pieces: BoardPiece[] | string;
46
+ fixed: BoardPiece[];
38
47
  }
39
48
  interface CustomEvents {
40
- stroke: CustomEvent<StrokeDetail>;
41
- strokeend: CustomEvent<{
42
- points: StrokePoint[];
49
+ change: CustomEvent<BoardChangeDetail>;
50
+ catch: CustomEvent<{
51
+ id: string;
43
52
  }>;
53
+ stroke: CustomEvent<StrokeDetail>;
54
+ strokeend: CustomEvent<StrokeEndDetail>;
44
55
  }
45
56
  }
46
57
  }