@grida/hud 0.1.0 → 0.2.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/README.md +657 -28
- package/dist/core/index.d.mts +181 -0
- package/dist/core/index.d.ts +181 -0
- package/dist/core/index.js +301 -0
- package/dist/core/index.mjs +291 -0
- package/dist/cursor-CxS8EMvm.d.mts +64 -0
- package/dist/cursor-CxS8EMvm.d.ts +64 -0
- package/dist/cursor-DW-uAPVE.mjs +57 -0
- package/dist/cursor-FGiJBdU-.js +80 -0
- package/dist/cursors/index.d.mts +98 -0
- package/dist/cursors/index.d.ts +98 -0
- package/dist/cursors/index.js +188 -0
- package/dist/cursors/index.mjs +185 -0
- package/dist/index-BrfEdWbQ.d.ts +3140 -0
- package/dist/index-Cmbe2X5b.d.mts +3140 -0
- package/dist/index.d.mts +107 -2
- package/dist/index.d.ts +107 -2
- package/dist/index.js +66 -1
- package/dist/index.mjs +3 -2
- package/dist/overlay-CVV4s3IL.d.ts +241 -0
- package/dist/overlay-dsG32baA.d.mts +241 -0
- package/dist/primitives/bedrock.d.mts +47 -0
- package/dist/primitives/bedrock.d.ts +47 -0
- package/dist/primitives/bedrock.js +71 -0
- package/dist/primitives/bedrock.mjs +65 -0
- package/dist/react.d.mts +3 -2
- package/dist/react.d.ts +2 -1
- package/dist/react.js +8 -3
- package/dist/react.mjs +8 -3
- package/dist/surface-BHQVvRFC.js +7356 -0
- package/dist/surface-NHSzUR8r.mjs +6902 -0
- package/dist/types-3wwFisZs.d.mts +296 -0
- package/dist/types-3wwFisZs.d.ts +296 -0
- package/package.json +18 -2
- package/dist/index-CBqCh-ZM.d.mts +0 -734
- package/dist/index-DRBeSiI2.d.ts +0 -734
- package/dist/surface-CNlBaEXn.js +0 -1890
- package/dist/surface-hUEeEVdL.mjs +0 -1808
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import cmath from "@grida/cmath";
|
|
2
|
+
|
|
3
|
+
//#region primitives/types.d.ts
|
|
4
|
+
type HUDSemanticGroup = string;
|
|
5
|
+
interface HUDSemantic {
|
|
6
|
+
/** Semantic owner of this primitive, used for group-level visibility policy. */
|
|
7
|
+
group?: HUDSemanticGroup;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Solid color paint — the existing flat-fill behavior, lifted into the
|
|
11
|
+
* `HUDPaint` discriminated union.
|
|
12
|
+
*
|
|
13
|
+
* @unstable
|
|
14
|
+
*/
|
|
15
|
+
interface HUDPaintSolid {
|
|
16
|
+
kind: "solid";
|
|
17
|
+
/** CSS color string. */
|
|
18
|
+
color: string;
|
|
19
|
+
/** Paint opacity, 0–1 (default: 1). */
|
|
20
|
+
opacity?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Diagonal-stripes paint — HUD's canonical "highlighted region, not
|
|
24
|
+
* committed selection" chrome. Defaults match the editor's vector-edit
|
|
25
|
+
* hover language (45° / 8px / 1.5px in device pixels).
|
|
26
|
+
*
|
|
27
|
+
* HUD rasterizes the tile per frame at the current DPR × zoom bucket and
|
|
28
|
+
* caches the result — hosts never own the bitmap.
|
|
29
|
+
*
|
|
30
|
+
* @unstable
|
|
31
|
+
*/
|
|
32
|
+
interface HUDPaintStripes {
|
|
33
|
+
kind: "stripes";
|
|
34
|
+
/** CSS color string for the stripe. */
|
|
35
|
+
color: string;
|
|
36
|
+
/** Paint opacity, 0–1 (default: 1). */
|
|
37
|
+
opacity?: number;
|
|
38
|
+
/** Stripe angle in degrees (default: 45). */
|
|
39
|
+
angle?: number;
|
|
40
|
+
/** Distance between stripe centers in CSS (logical) px (default: 8).
|
|
41
|
+
* The paint resolver scales by `devicePixelRatio` at runtime. */
|
|
42
|
+
spacing?: number;
|
|
43
|
+
/** Stripe thickness in CSS (logical) px (default: 1.5).
|
|
44
|
+
* The paint resolver scales by `devicePixelRatio` at runtime. */
|
|
45
|
+
thickness?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The closed taxonomy of paint kinds HUD ships. See module banner above
|
|
49
|
+
* for the promotion contract.
|
|
50
|
+
*
|
|
51
|
+
* @unstable
|
|
52
|
+
*/
|
|
53
|
+
type HUDPaint = HUDPaintSolid | HUDPaintStripes;
|
|
54
|
+
/**
|
|
55
|
+
* A line segment in document space, extending `cmath.ui.Line` with
|
|
56
|
+
* an optional `dashed` style.
|
|
57
|
+
*/
|
|
58
|
+
interface HUDLine extends cmath.ui.Line, HUDSemantic {
|
|
59
|
+
dashed?: boolean;
|
|
60
|
+
/** Stroke width in screen-space CSS px. Defaults to the canvas default. */
|
|
61
|
+
strokeWidth?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Override the canvas color for this line's stroke and label pill. Falls
|
|
64
|
+
* back to the canvas's current color when absent.
|
|
65
|
+
*/
|
|
66
|
+
color?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Paint applied to the stroke. When set, takes precedence over `color`
|
|
69
|
+
* for the stroke; the label pill stays on `color` (labels are theming
|
|
70
|
+
* surface, not paintable design-language surface).
|
|
71
|
+
*
|
|
72
|
+
* @unstable
|
|
73
|
+
*/
|
|
74
|
+
strokePaint?: HUDPaint;
|
|
75
|
+
/**
|
|
76
|
+
* Label rotation in radians (CCW) around the label pill's screen-space
|
|
77
|
+
* center. Defaults to `0`. Used to make the size meter pill rotate with
|
|
78
|
+
* a `SelectionShape.transformed` parent. Only affects the pill +
|
|
79
|
+
* text; the underlying line stroke is unaffected.
|
|
80
|
+
*/
|
|
81
|
+
labelAngle?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A full-viewport axis-aligned line (infinite extent) at a given offset.
|
|
85
|
+
*
|
|
86
|
+
* `axis` indicates which axis the `offset` lives on:
|
|
87
|
+
* - `"x"` → vertical line at x=offset
|
|
88
|
+
* - `"y"` → horizontal line at y=offset
|
|
89
|
+
*
|
|
90
|
+
* Offset is in document space; the renderer projects it to screen.
|
|
91
|
+
*/
|
|
92
|
+
interface HUDRule extends HUDSemantic {
|
|
93
|
+
axis: "x" | "y";
|
|
94
|
+
offset: number;
|
|
95
|
+
/**
|
|
96
|
+
* Override the canvas color for this rule's stroke. Falls back to
|
|
97
|
+
* the canvas's current color when absent.
|
|
98
|
+
*/
|
|
99
|
+
color?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Paint applied to the stroke. When set, takes precedence over `color`.
|
|
102
|
+
*
|
|
103
|
+
* @unstable
|
|
104
|
+
*/
|
|
105
|
+
strokePaint?: HUDPaint;
|
|
106
|
+
/**
|
|
107
|
+
* Stroke width in screen-space CSS px. Defaults to the canvas default
|
|
108
|
+
* (`DEFAULT_LINE_WIDTH`, 0.5). Hosts emitting per-rule visual state
|
|
109
|
+
* (hovered, selected) can vary this to match a corresponding
|
|
110
|
+
* `RulerMark.strokeWidth`, so the strip tick and the guide line read
|
|
111
|
+
* as one continuous stroke. Mirrors {@link HUDLine.strokeWidth}.
|
|
112
|
+
*/
|
|
113
|
+
strokeWidth?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A single document-space point rendered as a small crosshair "X" on
|
|
117
|
+
* the canvas. The size of the crosshair is fixed in CSS pixels; the
|
|
118
|
+
* anchor (x, y) is in document space.
|
|
119
|
+
*
|
|
120
|
+
* Stroke uses the canvas color by default. Per-point override is opt-in.
|
|
121
|
+
*/
|
|
122
|
+
interface HUDPoint extends HUDSemantic {
|
|
123
|
+
x: number;
|
|
124
|
+
y: number;
|
|
125
|
+
/**
|
|
126
|
+
* Override the canvas color for this point's crosshair stroke.
|
|
127
|
+
* Falls back to the canvas's current color when absent.
|
|
128
|
+
*/
|
|
129
|
+
color?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Paint applied to the crosshair stroke. When set, takes precedence
|
|
132
|
+
* over `color`.
|
|
133
|
+
*
|
|
134
|
+
* @unstable
|
|
135
|
+
*/
|
|
136
|
+
strokePaint?: HUDPaint;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A rectangle in document space.
|
|
140
|
+
*
|
|
141
|
+
* Stroke uses the canvas color by default. Fill is opt-in.
|
|
142
|
+
*/
|
|
143
|
+
interface HUDRect extends HUDSemantic {
|
|
144
|
+
x: number;
|
|
145
|
+
y: number;
|
|
146
|
+
width: number;
|
|
147
|
+
height: number;
|
|
148
|
+
/** Whether to stroke the outline (default: true). */
|
|
149
|
+
stroke?: boolean;
|
|
150
|
+
/** Whether to fill the interior (default: false). */
|
|
151
|
+
fill?: boolean;
|
|
152
|
+
/** Opacity of the fill color, 0–1 (default: 1). Ignored when `fill` is falsy. */
|
|
153
|
+
fillOpacity?: number;
|
|
154
|
+
/** Draw the outline with a dash pattern. */
|
|
155
|
+
dashed?: boolean;
|
|
156
|
+
/** Stroke width in screen-space CSS px. Defaults to the canvas default. */
|
|
157
|
+
strokeWidth?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Override the canvas color for this rect's stroke and fill. Falls back
|
|
160
|
+
* to the canvas's current color when absent.
|
|
161
|
+
*/
|
|
162
|
+
color?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Paint applied to the fill. When set, takes precedence over `color` +
|
|
165
|
+
* `fillOpacity` for the fill (`fillOpacity` is folded into `HUDPaint.opacity`
|
|
166
|
+
* by the host when migrating).
|
|
167
|
+
*
|
|
168
|
+
* @unstable
|
|
169
|
+
*/
|
|
170
|
+
fillPaint?: HUDPaint;
|
|
171
|
+
/**
|
|
172
|
+
* Paint applied to the stroke. When set, takes precedence over `color`
|
|
173
|
+
* for the stroke.
|
|
174
|
+
*
|
|
175
|
+
* @unstable
|
|
176
|
+
*/
|
|
177
|
+
strokePaint?: HUDPaint;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A polyline (or closed polygon) in document space.
|
|
181
|
+
*
|
|
182
|
+
* Stroke uses the canvas color by default. Fill is opt-in.
|
|
183
|
+
*/
|
|
184
|
+
interface HUDPolyline extends HUDSemantic {
|
|
185
|
+
points: cmath.Vector2[];
|
|
186
|
+
/** Whether to stroke the path (default: true). */
|
|
187
|
+
stroke?: boolean;
|
|
188
|
+
/** Whether to fill the interior (default: false). */
|
|
189
|
+
fill?: boolean;
|
|
190
|
+
/** Opacity of the fill color, 0–1 (default: 1). Ignored when `fill` is falsy. */
|
|
191
|
+
fillOpacity?: number;
|
|
192
|
+
/** Stroke opacity, 0–1 (default: 1). Used for hovered-but-not-selected
|
|
193
|
+
* affordances (e.g. segment hover at 50% opacity). */
|
|
194
|
+
strokeOpacity?: number;
|
|
195
|
+
/** Stroke width in screen-space CSS px. Falls back to the canvas default
|
|
196
|
+
* (1px / zoom) when absent. Required for the path-edit chrome's
|
|
197
|
+
* state-driven segment outline (idle 1px, hovered/selected 3px). */
|
|
198
|
+
strokeWidth?: number;
|
|
199
|
+
/** Draw the stroke with a dash pattern. */
|
|
200
|
+
dashed?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Override the canvas color for this polyline's stroke and fill. Falls
|
|
203
|
+
* back to the canvas's current color when absent.
|
|
204
|
+
*/
|
|
205
|
+
color?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Paint applied to the fill. When set, takes precedence over `color` +
|
|
208
|
+
* `fillOpacity` for the fill.
|
|
209
|
+
*
|
|
210
|
+
* @unstable
|
|
211
|
+
*/
|
|
212
|
+
fillPaint?: HUDPaint;
|
|
213
|
+
/**
|
|
214
|
+
* Paint applied to the stroke. When set, takes precedence over `color`
|
|
215
|
+
* + `strokeOpacity` for the stroke.
|
|
216
|
+
*
|
|
217
|
+
* @unstable
|
|
218
|
+
*/
|
|
219
|
+
strokePaint?: HUDPaint;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* A rectangle whose **size is fixed in screen-space** but whose **anchor lives
|
|
223
|
+
* in document space**. Used for handles and other chrome that must not scale
|
|
224
|
+
* with viewport zoom.
|
|
225
|
+
*
|
|
226
|
+
* The anchor `(x, y)` is the document-space point that maps to one corner (or
|
|
227
|
+
* center) of the resulting screen-space rect — controlled by `anchor`.
|
|
228
|
+
*
|
|
229
|
+
* Default anchor is `"center"` (the doc-space point becomes the rect's center).
|
|
230
|
+
*/
|
|
231
|
+
interface HUDScreenRect extends HUDSemantic {
|
|
232
|
+
/** Document-space anchor point. */
|
|
233
|
+
x: number;
|
|
234
|
+
y: number;
|
|
235
|
+
/** Screen-space size in CSS px. */
|
|
236
|
+
width: number;
|
|
237
|
+
height: number;
|
|
238
|
+
/** Which point of the rect sits at (x, y). Default: "center". */
|
|
239
|
+
anchor?: "center" | "tl" | "tr" | "bl" | "br";
|
|
240
|
+
fill?: boolean;
|
|
241
|
+
stroke?: boolean;
|
|
242
|
+
/** Override the canvas color for fill. */
|
|
243
|
+
fillColor?: string;
|
|
244
|
+
/** Override the canvas color for stroke. */
|
|
245
|
+
strokeColor?: string;
|
|
246
|
+
/**
|
|
247
|
+
* Paint applied to the fill. When set, takes precedence over `fillColor`.
|
|
248
|
+
*
|
|
249
|
+
* @unstable
|
|
250
|
+
*/
|
|
251
|
+
fillPaint?: HUDPaint;
|
|
252
|
+
/**
|
|
253
|
+
* Paint applied to the stroke. When set, takes precedence over `strokeColor`.
|
|
254
|
+
*
|
|
255
|
+
* @unstable
|
|
256
|
+
*/
|
|
257
|
+
strokePaint?: HUDPaint;
|
|
258
|
+
/**
|
|
259
|
+
* Rotation in radians (CCW) around the rect's screen-space center.
|
|
260
|
+
* Defaults to `0`. Used to make handle knobs / size badges rotate
|
|
261
|
+
* together with a `SelectionShape.transformed` parent. Hit-testing is
|
|
262
|
+
* unaffected — render and hit live on independent shapes per the
|
|
263
|
+
* package's render/hit-test split (see README).
|
|
264
|
+
*/
|
|
265
|
+
angle?: number;
|
|
266
|
+
/**
|
|
267
|
+
* Rendered shape. `"rect"` (default) draws an axis-aligned (or rotated)
|
|
268
|
+
* rectangle of `width × height`. `"circle"` draws an ellipse inscribed
|
|
269
|
+
* in that same box — so the hit AABB stays a square at `MIN_HIT_SIZE`
|
|
270
|
+
* for Fitts' reach while the visible knob is round. Width = height is
|
|
271
|
+
* expected for circular knobs; non-square sizes degrade gracefully to
|
|
272
|
+
* an ellipse. Anchor / angle / fill / stroke / colors all apply
|
|
273
|
+
* identically; only the path drawn changes.
|
|
274
|
+
*/
|
|
275
|
+
shape?: "rect" | "circle";
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* A complete set of draw commands for one frame.
|
|
279
|
+
*
|
|
280
|
+
* The HUD clears the canvas and draws everything in this struct each frame.
|
|
281
|
+
* Callers build a `HUDDraw` from their domain data (snap result, measurement,
|
|
282
|
+
* guide state, etc.) and hand it to `HUDCanvas.draw()`.
|
|
283
|
+
*/
|
|
284
|
+
interface HUDDraw {
|
|
285
|
+
lines?: HUDLine[];
|
|
286
|
+
rules?: HUDRule[];
|
|
287
|
+
points?: HUDPoint[];
|
|
288
|
+
rects?: HUDRect[];
|
|
289
|
+
polylines?: HUDPolyline[];
|
|
290
|
+
/** Screen-space-sized rects anchored to document-space points (handles). */
|
|
291
|
+
screenRects?: HUDScreenRect[];
|
|
292
|
+
topRects?: HUDRect[];
|
|
293
|
+
topPolylines?: HUDPolyline[];
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
export { HUDPaintStripes as a, HUDRect as c, HUDSemantic as d, HUDSemanticGroup as f, HUDPaintSolid as i, HUDRule as l, HUDLine as n, HUDPoint as o, HUDPaint as r, HUDPolyline as s, HUDDraw as t, HUDScreenRect as u };
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import cmath from "@grida/cmath";
|
|
2
|
+
|
|
3
|
+
//#region primitives/types.d.ts
|
|
4
|
+
type HUDSemanticGroup = string;
|
|
5
|
+
interface HUDSemantic {
|
|
6
|
+
/** Semantic owner of this primitive, used for group-level visibility policy. */
|
|
7
|
+
group?: HUDSemanticGroup;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Solid color paint — the existing flat-fill behavior, lifted into the
|
|
11
|
+
* `HUDPaint` discriminated union.
|
|
12
|
+
*
|
|
13
|
+
* @unstable
|
|
14
|
+
*/
|
|
15
|
+
interface HUDPaintSolid {
|
|
16
|
+
kind: "solid";
|
|
17
|
+
/** CSS color string. */
|
|
18
|
+
color: string;
|
|
19
|
+
/** Paint opacity, 0–1 (default: 1). */
|
|
20
|
+
opacity?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Diagonal-stripes paint — HUD's canonical "highlighted region, not
|
|
24
|
+
* committed selection" chrome. Defaults match the editor's vector-edit
|
|
25
|
+
* hover language (45° / 8px / 1.5px in device pixels).
|
|
26
|
+
*
|
|
27
|
+
* HUD rasterizes the tile per frame at the current DPR × zoom bucket and
|
|
28
|
+
* caches the result — hosts never own the bitmap.
|
|
29
|
+
*
|
|
30
|
+
* @unstable
|
|
31
|
+
*/
|
|
32
|
+
interface HUDPaintStripes {
|
|
33
|
+
kind: "stripes";
|
|
34
|
+
/** CSS color string for the stripe. */
|
|
35
|
+
color: string;
|
|
36
|
+
/** Paint opacity, 0–1 (default: 1). */
|
|
37
|
+
opacity?: number;
|
|
38
|
+
/** Stripe angle in degrees (default: 45). */
|
|
39
|
+
angle?: number;
|
|
40
|
+
/** Distance between stripe centers in CSS (logical) px (default: 8).
|
|
41
|
+
* The paint resolver scales by `devicePixelRatio` at runtime. */
|
|
42
|
+
spacing?: number;
|
|
43
|
+
/** Stripe thickness in CSS (logical) px (default: 1.5).
|
|
44
|
+
* The paint resolver scales by `devicePixelRatio` at runtime. */
|
|
45
|
+
thickness?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The closed taxonomy of paint kinds HUD ships. See module banner above
|
|
49
|
+
* for the promotion contract.
|
|
50
|
+
*
|
|
51
|
+
* @unstable
|
|
52
|
+
*/
|
|
53
|
+
type HUDPaint = HUDPaintSolid | HUDPaintStripes;
|
|
54
|
+
/**
|
|
55
|
+
* A line segment in document space, extending `cmath.ui.Line` with
|
|
56
|
+
* an optional `dashed` style.
|
|
57
|
+
*/
|
|
58
|
+
interface HUDLine extends cmath.ui.Line, HUDSemantic {
|
|
59
|
+
dashed?: boolean;
|
|
60
|
+
/** Stroke width in screen-space CSS px. Defaults to the canvas default. */
|
|
61
|
+
strokeWidth?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Override the canvas color for this line's stroke and label pill. Falls
|
|
64
|
+
* back to the canvas's current color when absent.
|
|
65
|
+
*/
|
|
66
|
+
color?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Paint applied to the stroke. When set, takes precedence over `color`
|
|
69
|
+
* for the stroke; the label pill stays on `color` (labels are theming
|
|
70
|
+
* surface, not paintable design-language surface).
|
|
71
|
+
*
|
|
72
|
+
* @unstable
|
|
73
|
+
*/
|
|
74
|
+
strokePaint?: HUDPaint;
|
|
75
|
+
/**
|
|
76
|
+
* Label rotation in radians (CCW) around the label pill's screen-space
|
|
77
|
+
* center. Defaults to `0`. Used to make the size meter pill rotate with
|
|
78
|
+
* a `SelectionShape.transformed` parent. Only affects the pill +
|
|
79
|
+
* text; the underlying line stroke is unaffected.
|
|
80
|
+
*/
|
|
81
|
+
labelAngle?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A full-viewport axis-aligned line (infinite extent) at a given offset.
|
|
85
|
+
*
|
|
86
|
+
* `axis` indicates which axis the `offset` lives on:
|
|
87
|
+
* - `"x"` → vertical line at x=offset
|
|
88
|
+
* - `"y"` → horizontal line at y=offset
|
|
89
|
+
*
|
|
90
|
+
* Offset is in document space; the renderer projects it to screen.
|
|
91
|
+
*/
|
|
92
|
+
interface HUDRule extends HUDSemantic {
|
|
93
|
+
axis: "x" | "y";
|
|
94
|
+
offset: number;
|
|
95
|
+
/**
|
|
96
|
+
* Override the canvas color for this rule's stroke. Falls back to
|
|
97
|
+
* the canvas's current color when absent.
|
|
98
|
+
*/
|
|
99
|
+
color?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Paint applied to the stroke. When set, takes precedence over `color`.
|
|
102
|
+
*
|
|
103
|
+
* @unstable
|
|
104
|
+
*/
|
|
105
|
+
strokePaint?: HUDPaint;
|
|
106
|
+
/**
|
|
107
|
+
* Stroke width in screen-space CSS px. Defaults to the canvas default
|
|
108
|
+
* (`DEFAULT_LINE_WIDTH`, 0.5). Hosts emitting per-rule visual state
|
|
109
|
+
* (hovered, selected) can vary this to match a corresponding
|
|
110
|
+
* `RulerMark.strokeWidth`, so the strip tick and the guide line read
|
|
111
|
+
* as one continuous stroke. Mirrors {@link HUDLine.strokeWidth}.
|
|
112
|
+
*/
|
|
113
|
+
strokeWidth?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A single document-space point rendered as a small crosshair "X" on
|
|
117
|
+
* the canvas. The size of the crosshair is fixed in CSS pixels; the
|
|
118
|
+
* anchor (x, y) is in document space.
|
|
119
|
+
*
|
|
120
|
+
* Stroke uses the canvas color by default. Per-point override is opt-in.
|
|
121
|
+
*/
|
|
122
|
+
interface HUDPoint extends HUDSemantic {
|
|
123
|
+
x: number;
|
|
124
|
+
y: number;
|
|
125
|
+
/**
|
|
126
|
+
* Override the canvas color for this point's crosshair stroke.
|
|
127
|
+
* Falls back to the canvas's current color when absent.
|
|
128
|
+
*/
|
|
129
|
+
color?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Paint applied to the crosshair stroke. When set, takes precedence
|
|
132
|
+
* over `color`.
|
|
133
|
+
*
|
|
134
|
+
* @unstable
|
|
135
|
+
*/
|
|
136
|
+
strokePaint?: HUDPaint;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A rectangle in document space.
|
|
140
|
+
*
|
|
141
|
+
* Stroke uses the canvas color by default. Fill is opt-in.
|
|
142
|
+
*/
|
|
143
|
+
interface HUDRect extends HUDSemantic {
|
|
144
|
+
x: number;
|
|
145
|
+
y: number;
|
|
146
|
+
width: number;
|
|
147
|
+
height: number;
|
|
148
|
+
/** Whether to stroke the outline (default: true). */
|
|
149
|
+
stroke?: boolean;
|
|
150
|
+
/** Whether to fill the interior (default: false). */
|
|
151
|
+
fill?: boolean;
|
|
152
|
+
/** Opacity of the fill color, 0–1 (default: 1). Ignored when `fill` is falsy. */
|
|
153
|
+
fillOpacity?: number;
|
|
154
|
+
/** Draw the outline with a dash pattern. */
|
|
155
|
+
dashed?: boolean;
|
|
156
|
+
/** Stroke width in screen-space CSS px. Defaults to the canvas default. */
|
|
157
|
+
strokeWidth?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Override the canvas color for this rect's stroke and fill. Falls back
|
|
160
|
+
* to the canvas's current color when absent.
|
|
161
|
+
*/
|
|
162
|
+
color?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Paint applied to the fill. When set, takes precedence over `color` +
|
|
165
|
+
* `fillOpacity` for the fill (`fillOpacity` is folded into `HUDPaint.opacity`
|
|
166
|
+
* by the host when migrating).
|
|
167
|
+
*
|
|
168
|
+
* @unstable
|
|
169
|
+
*/
|
|
170
|
+
fillPaint?: HUDPaint;
|
|
171
|
+
/**
|
|
172
|
+
* Paint applied to the stroke. When set, takes precedence over `color`
|
|
173
|
+
* for the stroke.
|
|
174
|
+
*
|
|
175
|
+
* @unstable
|
|
176
|
+
*/
|
|
177
|
+
strokePaint?: HUDPaint;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A polyline (or closed polygon) in document space.
|
|
181
|
+
*
|
|
182
|
+
* Stroke uses the canvas color by default. Fill is opt-in.
|
|
183
|
+
*/
|
|
184
|
+
interface HUDPolyline extends HUDSemantic {
|
|
185
|
+
points: cmath.Vector2[];
|
|
186
|
+
/** Whether to stroke the path (default: true). */
|
|
187
|
+
stroke?: boolean;
|
|
188
|
+
/** Whether to fill the interior (default: false). */
|
|
189
|
+
fill?: boolean;
|
|
190
|
+
/** Opacity of the fill color, 0–1 (default: 1). Ignored when `fill` is falsy. */
|
|
191
|
+
fillOpacity?: number;
|
|
192
|
+
/** Stroke opacity, 0–1 (default: 1). Used for hovered-but-not-selected
|
|
193
|
+
* affordances (e.g. segment hover at 50% opacity). */
|
|
194
|
+
strokeOpacity?: number;
|
|
195
|
+
/** Stroke width in screen-space CSS px. Falls back to the canvas default
|
|
196
|
+
* (1px / zoom) when absent. Required for the path-edit chrome's
|
|
197
|
+
* state-driven segment outline (idle 1px, hovered/selected 3px). */
|
|
198
|
+
strokeWidth?: number;
|
|
199
|
+
/** Draw the stroke with a dash pattern. */
|
|
200
|
+
dashed?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Override the canvas color for this polyline's stroke and fill. Falls
|
|
203
|
+
* back to the canvas's current color when absent.
|
|
204
|
+
*/
|
|
205
|
+
color?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Paint applied to the fill. When set, takes precedence over `color` +
|
|
208
|
+
* `fillOpacity` for the fill.
|
|
209
|
+
*
|
|
210
|
+
* @unstable
|
|
211
|
+
*/
|
|
212
|
+
fillPaint?: HUDPaint;
|
|
213
|
+
/**
|
|
214
|
+
* Paint applied to the stroke. When set, takes precedence over `color`
|
|
215
|
+
* + `strokeOpacity` for the stroke.
|
|
216
|
+
*
|
|
217
|
+
* @unstable
|
|
218
|
+
*/
|
|
219
|
+
strokePaint?: HUDPaint;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* A rectangle whose **size is fixed in screen-space** but whose **anchor lives
|
|
223
|
+
* in document space**. Used for handles and other chrome that must not scale
|
|
224
|
+
* with viewport zoom.
|
|
225
|
+
*
|
|
226
|
+
* The anchor `(x, y)` is the document-space point that maps to one corner (or
|
|
227
|
+
* center) of the resulting screen-space rect — controlled by `anchor`.
|
|
228
|
+
*
|
|
229
|
+
* Default anchor is `"center"` (the doc-space point becomes the rect's center).
|
|
230
|
+
*/
|
|
231
|
+
interface HUDScreenRect extends HUDSemantic {
|
|
232
|
+
/** Document-space anchor point. */
|
|
233
|
+
x: number;
|
|
234
|
+
y: number;
|
|
235
|
+
/** Screen-space size in CSS px. */
|
|
236
|
+
width: number;
|
|
237
|
+
height: number;
|
|
238
|
+
/** Which point of the rect sits at (x, y). Default: "center". */
|
|
239
|
+
anchor?: "center" | "tl" | "tr" | "bl" | "br";
|
|
240
|
+
fill?: boolean;
|
|
241
|
+
stroke?: boolean;
|
|
242
|
+
/** Override the canvas color for fill. */
|
|
243
|
+
fillColor?: string;
|
|
244
|
+
/** Override the canvas color for stroke. */
|
|
245
|
+
strokeColor?: string;
|
|
246
|
+
/**
|
|
247
|
+
* Paint applied to the fill. When set, takes precedence over `fillColor`.
|
|
248
|
+
*
|
|
249
|
+
* @unstable
|
|
250
|
+
*/
|
|
251
|
+
fillPaint?: HUDPaint;
|
|
252
|
+
/**
|
|
253
|
+
* Paint applied to the stroke. When set, takes precedence over `strokeColor`.
|
|
254
|
+
*
|
|
255
|
+
* @unstable
|
|
256
|
+
*/
|
|
257
|
+
strokePaint?: HUDPaint;
|
|
258
|
+
/**
|
|
259
|
+
* Rotation in radians (CCW) around the rect's screen-space center.
|
|
260
|
+
* Defaults to `0`. Used to make handle knobs / size badges rotate
|
|
261
|
+
* together with a `SelectionShape.transformed` parent. Hit-testing is
|
|
262
|
+
* unaffected — render and hit live on independent shapes per the
|
|
263
|
+
* package's render/hit-test split (see README).
|
|
264
|
+
*/
|
|
265
|
+
angle?: number;
|
|
266
|
+
/**
|
|
267
|
+
* Rendered shape. `"rect"` (default) draws an axis-aligned (or rotated)
|
|
268
|
+
* rectangle of `width × height`. `"circle"` draws an ellipse inscribed
|
|
269
|
+
* in that same box — so the hit AABB stays a square at `MIN_HIT_SIZE`
|
|
270
|
+
* for Fitts' reach while the visible knob is round. Width = height is
|
|
271
|
+
* expected for circular knobs; non-square sizes degrade gracefully to
|
|
272
|
+
* an ellipse. Anchor / angle / fill / stroke / colors all apply
|
|
273
|
+
* identically; only the path drawn changes.
|
|
274
|
+
*/
|
|
275
|
+
shape?: "rect" | "circle";
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* A complete set of draw commands for one frame.
|
|
279
|
+
*
|
|
280
|
+
* The HUD clears the canvas and draws everything in this struct each frame.
|
|
281
|
+
* Callers build a `HUDDraw` from their domain data (snap result, measurement,
|
|
282
|
+
* guide state, etc.) and hand it to `HUDCanvas.draw()`.
|
|
283
|
+
*/
|
|
284
|
+
interface HUDDraw {
|
|
285
|
+
lines?: HUDLine[];
|
|
286
|
+
rules?: HUDRule[];
|
|
287
|
+
points?: HUDPoint[];
|
|
288
|
+
rects?: HUDRect[];
|
|
289
|
+
polylines?: HUDPolyline[];
|
|
290
|
+
/** Screen-space-sized rects anchored to document-space points (handles). */
|
|
291
|
+
screenRects?: HUDScreenRect[];
|
|
292
|
+
topRects?: HUDRect[];
|
|
293
|
+
topPolylines?: HUDPolyline[];
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
export { HUDPaintStripes as a, HUDRect as c, HUDSemantic as d, HUDSemanticGroup as f, HUDPaintSolid as i, HUDRule as l, HUDLine as n, HUDPoint as o, HUDPaint as r, HUDPolyline as s, HUDDraw as t, HUDScreenRect as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grida/hud",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"private": false,
|
|
4
5
|
"description": "Canvas-based heads-up display for the Grida editor viewport",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"canvas",
|
|
@@ -32,13 +33,28 @@
|
|
|
32
33
|
"types": "./dist/react.d.ts",
|
|
33
34
|
"import": "./dist/react.mjs",
|
|
34
35
|
"require": "./dist/react.js"
|
|
36
|
+
},
|
|
37
|
+
"./cursors": {
|
|
38
|
+
"types": "./dist/cursors/index.d.ts",
|
|
39
|
+
"import": "./dist/cursors/index.mjs",
|
|
40
|
+
"require": "./dist/cursors/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./core": {
|
|
43
|
+
"types": "./dist/core/index.d.ts",
|
|
44
|
+
"import": "./dist/core/index.mjs",
|
|
45
|
+
"require": "./dist/core/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./primitives": {
|
|
48
|
+
"types": "./dist/primitives/bedrock.d.ts",
|
|
49
|
+
"import": "./dist/primitives/bedrock.mjs",
|
|
50
|
+
"require": "./dist/primitives/bedrock.js"
|
|
35
51
|
}
|
|
36
52
|
},
|
|
37
53
|
"publishConfig": {
|
|
38
54
|
"access": "public"
|
|
39
55
|
},
|
|
40
56
|
"dependencies": {
|
|
41
|
-
"@grida/cmath": "0.
|
|
57
|
+
"@grida/cmath": "0.2.3"
|
|
42
58
|
},
|
|
43
59
|
"devDependencies": {
|
|
44
60
|
"@types/node": "^24",
|