@grida/hud 0.1.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/LICENSE +201 -0
- package/README.md +340 -0
- package/dist/index-CBqCh-ZM.d.mts +734 -0
- package/dist/index-DRBeSiI2.d.ts +734 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -0
- package/dist/index.mjs +2 -0
- package/dist/react.d.mts +73 -0
- package/dist/react.d.ts +73 -0
- package/dist/react.js +124 -0
- package/dist/react.mjs +117 -0
- package/dist/surface-CNlBaEXn.js +1890 -0
- package/dist/surface-hUEeEVdL.mjs +1808 -0
- package/package.json +68 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { A as HUDPolyline, C as marqueeToHUDDraw, D as HUDCanvasOptions, E as HUDCanvas, M as HUDRule, N as HUDScreenRect, O as HUDDraw, S as lassoToHUDDraw, T as snapGuideToHUDDraw, _ as Modifiers, a as RenderShape, b as SurfaceEvent, c as HUDStyle, d as Intent, f as IntentPhase, g as RotationCorner, h as ResizeDirection, i as OverlayElement, j as HUDRect, k as HUDLine, l as SelectionGroup, m as CursorIcon, n as MIN_CHROME_VISIBLE_SIZE, o as Surface, p as SurfaceGesture, r as MIN_HIT_SIZE, s as SurfaceOptions, t as HitShape, u as SelectionShape, v as NO_MODS, w as measurementToHUDDraw, x as SurfaceResponse, y as PointerButton } from "./index-CBqCh-ZM.mjs";
|
|
2
|
+
export { type CursorIcon, HUDCanvas, type HUDCanvasOptions, type HUDDraw, type HUDLine, type HUDPolyline, type HUDRect, type HUDRule, type HUDScreenRect, type HUDStyle, type HitShape, type Intent, type IntentPhase, MIN_CHROME_VISIBLE_SIZE, MIN_HIT_SIZE, type Modifiers, NO_MODS, type OverlayElement, type PointerButton, type RenderShape, type ResizeDirection, type RotationCorner, type SelectionGroup, type SelectionShape, Surface, type SurfaceEvent, type SurfaceGesture, type SurfaceOptions, type SurfaceResponse, lassoToHUDDraw, marqueeToHUDDraw, measurementToHUDDraw, snapGuideToHUDDraw };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { A as HUDPolyline, C as marqueeToHUDDraw, D as HUDCanvasOptions, E as HUDCanvas, M as HUDRule, N as HUDScreenRect, O as HUDDraw, S as lassoToHUDDraw, T as snapGuideToHUDDraw, _ as Modifiers, a as RenderShape, b as SurfaceEvent, c as HUDStyle, d as Intent, f as IntentPhase, g as RotationCorner, h as ResizeDirection, i as OverlayElement, j as HUDRect, k as HUDLine, l as SelectionGroup, m as CursorIcon, n as MIN_CHROME_VISIBLE_SIZE, o as Surface, p as SurfaceGesture, r as MIN_HIT_SIZE, s as SurfaceOptions, t as HitShape, u as SelectionShape, v as NO_MODS, w as measurementToHUDDraw, x as SurfaceResponse, y as PointerButton } from "./index-DRBeSiI2.js";
|
|
2
|
+
export { type CursorIcon, HUDCanvas, type HUDCanvasOptions, type HUDDraw, type HUDLine, type HUDPolyline, type HUDRect, type HUDRule, type HUDScreenRect, type HUDStyle, type HitShape, type Intent, type IntentPhase, MIN_CHROME_VISIBLE_SIZE, MIN_HIT_SIZE, type Modifiers, NO_MODS, type OverlayElement, type PointerButton, type RenderShape, type ResizeDirection, type RotationCorner, type SelectionGroup, type SelectionShape, Surface, type SurfaceEvent, type SurfaceGesture, type SurfaceOptions, type SurfaceResponse, lassoToHUDDraw, marqueeToHUDDraw, measurementToHUDDraw, snapGuideToHUDDraw };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_surface = require("./surface-CNlBaEXn.js");
|
|
3
|
+
exports.HUDCanvas = require_surface.HUDCanvas;
|
|
4
|
+
exports.MIN_CHROME_VISIBLE_SIZE = require_surface.MIN_CHROME_VISIBLE_SIZE;
|
|
5
|
+
exports.MIN_HIT_SIZE = require_surface.MIN_HIT_SIZE;
|
|
6
|
+
exports.NO_MODS = require_surface.NO_MODS;
|
|
7
|
+
exports.Surface = require_surface.Surface;
|
|
8
|
+
exports.lassoToHUDDraw = require_surface.lassoToHUDDraw;
|
|
9
|
+
exports.marqueeToHUDDraw = require_surface.marqueeToHUDDraw;
|
|
10
|
+
exports.measurementToHUDDraw = require_surface.measurementToHUDDraw;
|
|
11
|
+
exports.snapGuideToHUDDraw = require_surface.snapGuideToHUDDraw;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as lassoToHUDDraw, c as snapGuideToHUDDraw, i as NO_MODS, l as HUDCanvas, n as MIN_CHROME_VISIBLE_SIZE, o as marqueeToHUDDraw, r as MIN_HIT_SIZE, s as measurementToHUDDraw, t as Surface } from "./surface-hUEeEVdL.mjs";
|
|
2
|
+
export { HUDCanvas, MIN_CHROME_VISIBLE_SIZE, MIN_HIT_SIZE, NO_MODS, Surface, lassoToHUDDraw, marqueeToHUDDraw, measurementToHUDDraw, snapGuideToHUDDraw };
|
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { O as HUDDraw, o as Surface, s as SurfaceOptions } from "./index-CBqCh-ZM.mjs";
|
|
2
|
+
import { Measurement } from "@grida/cmath/_measurement";
|
|
3
|
+
import cmath from "@grida/cmath";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { SnapResult } from "@grida/cmath/_snap";
|
|
6
|
+
|
|
7
|
+
//#region react.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Instantiate a `Surface` against the given canvas element and return the
|
|
10
|
+
* imperative instance. The surface is created once and reused across renders;
|
|
11
|
+
* its providers are kept up to date via refs so the host can pass new
|
|
12
|
+
* closures freely.
|
|
13
|
+
*
|
|
14
|
+
* The hook does **not** wire pointer events — the host attaches listeners
|
|
15
|
+
* to whatever element it wants (usually the canvas's container) and calls
|
|
16
|
+
* `surface.dispatch(event)` directly. This keeps the hook framework-agnostic
|
|
17
|
+
* past React's lifecycle.
|
|
18
|
+
*/
|
|
19
|
+
declare function useHUDSurface(canvasRef: React.RefObject<HTMLCanvasElement | null>, options: SurfaceOptions): Surface | null;
|
|
20
|
+
interface HUDOverlayProps {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
transform: cmath.Transform;
|
|
24
|
+
draw: HUDDraw | undefined;
|
|
25
|
+
color?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generic HUD overlay component.
|
|
30
|
+
*
|
|
31
|
+
* Renders a `<canvas>` element driven by {@link HUDCanvas}. Pass a
|
|
32
|
+
* pre-built {@link HUDDraw} command list to control what is drawn.
|
|
33
|
+
*/
|
|
34
|
+
declare const HUDOverlay: React.FC<HUDOverlayProps>;
|
|
35
|
+
interface SnapGuideProps {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
transform: cmath.Transform;
|
|
39
|
+
snapping: SnapResult | undefined;
|
|
40
|
+
color?: string;
|
|
41
|
+
className?: string;
|
|
42
|
+
}
|
|
43
|
+
declare const SnapGuide: React.FC<SnapGuideProps>;
|
|
44
|
+
interface MeasurementGuideProps {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
transform: cmath.Transform;
|
|
48
|
+
measurement: Measurement | undefined;
|
|
49
|
+
color?: string;
|
|
50
|
+
className?: string;
|
|
51
|
+
}
|
|
52
|
+
declare const MeasurementGuide: React.FC<MeasurementGuideProps>;
|
|
53
|
+
interface MarqueeProps {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
transform: cmath.Transform;
|
|
57
|
+
a: cmath.Vector2 | undefined;
|
|
58
|
+
b: cmath.Vector2 | undefined;
|
|
59
|
+
color?: string;
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
declare const Marquee: React.FC<MarqueeProps>;
|
|
63
|
+
interface LassoProps {
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
transform: cmath.Transform;
|
|
67
|
+
points: cmath.Vector2[] | undefined;
|
|
68
|
+
color?: string;
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
declare const Lasso: React.FC<LassoProps>;
|
|
72
|
+
//#endregion
|
|
73
|
+
export { HUDOverlay, HUDOverlayProps, Lasso, LassoProps, Marquee, MarqueeProps, MeasurementGuide, MeasurementGuideProps, SnapGuide, SnapGuideProps, useHUDSurface };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { O as HUDDraw, o as Surface, s as SurfaceOptions } from "./index-DRBeSiI2.js";
|
|
2
|
+
import cmath from "@grida/cmath";
|
|
3
|
+
import { SnapResult } from "@grida/cmath/_snap";
|
|
4
|
+
import { Measurement } from "@grida/cmath/_measurement";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
|
|
7
|
+
//#region react.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Instantiate a `Surface` against the given canvas element and return the
|
|
10
|
+
* imperative instance. The surface is created once and reused across renders;
|
|
11
|
+
* its providers are kept up to date via refs so the host can pass new
|
|
12
|
+
* closures freely.
|
|
13
|
+
*
|
|
14
|
+
* The hook does **not** wire pointer events — the host attaches listeners
|
|
15
|
+
* to whatever element it wants (usually the canvas's container) and calls
|
|
16
|
+
* `surface.dispatch(event)` directly. This keeps the hook framework-agnostic
|
|
17
|
+
* past React's lifecycle.
|
|
18
|
+
*/
|
|
19
|
+
declare function useHUDSurface(canvasRef: React.RefObject<HTMLCanvasElement | null>, options: SurfaceOptions): Surface | null;
|
|
20
|
+
interface HUDOverlayProps {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
transform: cmath.Transform;
|
|
24
|
+
draw: HUDDraw | undefined;
|
|
25
|
+
color?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generic HUD overlay component.
|
|
30
|
+
*
|
|
31
|
+
* Renders a `<canvas>` element driven by {@link HUDCanvas}. Pass a
|
|
32
|
+
* pre-built {@link HUDDraw} command list to control what is drawn.
|
|
33
|
+
*/
|
|
34
|
+
declare const HUDOverlay: React.FC<HUDOverlayProps>;
|
|
35
|
+
interface SnapGuideProps {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
transform: cmath.Transform;
|
|
39
|
+
snapping: SnapResult | undefined;
|
|
40
|
+
color?: string;
|
|
41
|
+
className?: string;
|
|
42
|
+
}
|
|
43
|
+
declare const SnapGuide: React.FC<SnapGuideProps>;
|
|
44
|
+
interface MeasurementGuideProps {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
transform: cmath.Transform;
|
|
48
|
+
measurement: Measurement | undefined;
|
|
49
|
+
color?: string;
|
|
50
|
+
className?: string;
|
|
51
|
+
}
|
|
52
|
+
declare const MeasurementGuide: React.FC<MeasurementGuideProps>;
|
|
53
|
+
interface MarqueeProps {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
transform: cmath.Transform;
|
|
57
|
+
a: cmath.Vector2 | undefined;
|
|
58
|
+
b: cmath.Vector2 | undefined;
|
|
59
|
+
color?: string;
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
declare const Marquee: React.FC<MarqueeProps>;
|
|
63
|
+
interface LassoProps {
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
transform: cmath.Transform;
|
|
67
|
+
points: cmath.Vector2[] | undefined;
|
|
68
|
+
color?: string;
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
declare const Lasso: React.FC<LassoProps>;
|
|
72
|
+
//#endregion
|
|
73
|
+
export { HUDOverlay, HUDOverlayProps, Lasso, LassoProps, Marquee, MarqueeProps, MeasurementGuide, MeasurementGuideProps, SnapGuide, SnapGuideProps, useHUDSurface };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const require_surface = require("./surface-CNlBaEXn.js");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
react = require_surface.__toESM(react);
|
|
6
|
+
let _grida_cmath__snap = require("@grida/cmath/_snap");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
//#region react.tsx
|
|
9
|
+
/**
|
|
10
|
+
* Instantiate a `Surface` against the given canvas element and return the
|
|
11
|
+
* imperative instance. The surface is created once and reused across renders;
|
|
12
|
+
* its providers are kept up to date via refs so the host can pass new
|
|
13
|
+
* closures freely.
|
|
14
|
+
*
|
|
15
|
+
* The hook does **not** wire pointer events — the host attaches listeners
|
|
16
|
+
* to whatever element it wants (usually the canvas's container) and calls
|
|
17
|
+
* `surface.dispatch(event)` directly. This keeps the hook framework-agnostic
|
|
18
|
+
* past React's lifecycle.
|
|
19
|
+
*/
|
|
20
|
+
function useHUDSurface(canvasRef, options) {
|
|
21
|
+
const [surface, setSurface] = react.useState(null);
|
|
22
|
+
const pickRef = react.useRef(options.pick);
|
|
23
|
+
const shapeOfRef = react.useRef(options.shapeOf);
|
|
24
|
+
const onIntentRef = react.useRef(options.onIntent);
|
|
25
|
+
pickRef.current = options.pick;
|
|
26
|
+
shapeOfRef.current = options.shapeOf;
|
|
27
|
+
onIntentRef.current = options.onIntent;
|
|
28
|
+
react.useLayoutEffect(() => {
|
|
29
|
+
if (!canvasRef.current) return;
|
|
30
|
+
const s = new require_surface.Surface(canvasRef.current, {
|
|
31
|
+
pick: (p) => pickRef.current(p),
|
|
32
|
+
shapeOf: (id) => shapeOfRef.current(id),
|
|
33
|
+
onIntent: (i) => onIntentRef.current(i),
|
|
34
|
+
style: options.style,
|
|
35
|
+
readonly: options.readonly,
|
|
36
|
+
color: options.color
|
|
37
|
+
});
|
|
38
|
+
setSurface(s);
|
|
39
|
+
return () => {
|
|
40
|
+
s.dispose();
|
|
41
|
+
setSurface(null);
|
|
42
|
+
};
|
|
43
|
+
}, [canvasRef]);
|
|
44
|
+
react.useEffect(() => {
|
|
45
|
+
if (!surface) return;
|
|
46
|
+
if (options.style) surface.setStyle(options.style);
|
|
47
|
+
if (options.readonly !== void 0) surface.setReadonly(options.readonly);
|
|
48
|
+
}, [
|
|
49
|
+
surface,
|
|
50
|
+
options.style,
|
|
51
|
+
options.readonly
|
|
52
|
+
]);
|
|
53
|
+
return surface;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generic HUD overlay component.
|
|
57
|
+
*
|
|
58
|
+
* Renders a `<canvas>` element driven by {@link HUDCanvas}. Pass a
|
|
59
|
+
* pre-built {@link HUDDraw} command list to control what is drawn.
|
|
60
|
+
*/
|
|
61
|
+
const HUDOverlay = (props) => {
|
|
62
|
+
const canvasRef = react.useRef(null);
|
|
63
|
+
const rendererRef = react.useRef(null);
|
|
64
|
+
react.useLayoutEffect(() => {
|
|
65
|
+
if (!canvasRef.current) return;
|
|
66
|
+
if (!rendererRef.current) rendererRef.current = new require_surface.HUDCanvas(canvasRef.current, { color: props.color });
|
|
67
|
+
rendererRef.current.setColor(props.color);
|
|
68
|
+
rendererRef.current.setSize(props.width, props.height);
|
|
69
|
+
rendererRef.current.setTransform(props.transform);
|
|
70
|
+
rendererRef.current.draw(props.draw);
|
|
71
|
+
}, [
|
|
72
|
+
props.width,
|
|
73
|
+
props.height,
|
|
74
|
+
props.transform,
|
|
75
|
+
props.draw,
|
|
76
|
+
props.color
|
|
77
|
+
]);
|
|
78
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("canvas", {
|
|
79
|
+
ref: canvasRef,
|
|
80
|
+
style: {
|
|
81
|
+
width: props.width,
|
|
82
|
+
height: props.height,
|
|
83
|
+
pointerEvents: "none"
|
|
84
|
+
},
|
|
85
|
+
className: props.className
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const SnapGuide = (props) => {
|
|
89
|
+
const draw = react.useMemo(() => {
|
|
90
|
+
return require_surface.snapGuideToHUDDraw(props.snapping ? _grida_cmath__snap.guide.plot(props.snapping) : void 0);
|
|
91
|
+
}, [props.snapping]);
|
|
92
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HUDOverlay, {
|
|
93
|
+
...props,
|
|
94
|
+
draw
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const MeasurementGuide = (props) => {
|
|
98
|
+
const draw = react.useMemo(() => props.measurement ? require_surface.measurementToHUDDraw(props.measurement) : void 0, [props.measurement]);
|
|
99
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HUDOverlay, {
|
|
100
|
+
...props,
|
|
101
|
+
draw
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const Marquee = (props) => {
|
|
105
|
+
const draw = react.useMemo(() => props.a && props.b ? require_surface.marqueeToHUDDraw(props.a, props.b) : void 0, [props.a, props.b]);
|
|
106
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HUDOverlay, {
|
|
107
|
+
...props,
|
|
108
|
+
draw
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const Lasso = (props) => {
|
|
112
|
+
const draw = react.useMemo(() => props.points ? require_surface.lassoToHUDDraw(props.points) : void 0, [props.points]);
|
|
113
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HUDOverlay, {
|
|
114
|
+
...props,
|
|
115
|
+
draw
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
exports.HUDOverlay = HUDOverlay;
|
|
120
|
+
exports.Lasso = Lasso;
|
|
121
|
+
exports.Marquee = Marquee;
|
|
122
|
+
exports.MeasurementGuide = MeasurementGuide;
|
|
123
|
+
exports.SnapGuide = SnapGuide;
|
|
124
|
+
exports.useHUDSurface = useHUDSurface;
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { a as lassoToHUDDraw, c as snapGuideToHUDDraw, l as HUDCanvas, o as marqueeToHUDDraw, s as measurementToHUDDraw, t as Surface } from "./surface-hUEeEVdL.mjs";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { guide } from "@grida/cmath/_snap";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
//#region react.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Instantiate a `Surface` against the given canvas element and return the
|
|
9
|
+
* imperative instance. The surface is created once and reused across renders;
|
|
10
|
+
* its providers are kept up to date via refs so the host can pass new
|
|
11
|
+
* closures freely.
|
|
12
|
+
*
|
|
13
|
+
* The hook does **not** wire pointer events — the host attaches listeners
|
|
14
|
+
* to whatever element it wants (usually the canvas's container) and calls
|
|
15
|
+
* `surface.dispatch(event)` directly. This keeps the hook framework-agnostic
|
|
16
|
+
* past React's lifecycle.
|
|
17
|
+
*/
|
|
18
|
+
function useHUDSurface(canvasRef, options) {
|
|
19
|
+
const [surface, setSurface] = React.useState(null);
|
|
20
|
+
const pickRef = React.useRef(options.pick);
|
|
21
|
+
const shapeOfRef = React.useRef(options.shapeOf);
|
|
22
|
+
const onIntentRef = React.useRef(options.onIntent);
|
|
23
|
+
pickRef.current = options.pick;
|
|
24
|
+
shapeOfRef.current = options.shapeOf;
|
|
25
|
+
onIntentRef.current = options.onIntent;
|
|
26
|
+
React.useLayoutEffect(() => {
|
|
27
|
+
if (!canvasRef.current) return;
|
|
28
|
+
const s = new Surface(canvasRef.current, {
|
|
29
|
+
pick: (p) => pickRef.current(p),
|
|
30
|
+
shapeOf: (id) => shapeOfRef.current(id),
|
|
31
|
+
onIntent: (i) => onIntentRef.current(i),
|
|
32
|
+
style: options.style,
|
|
33
|
+
readonly: options.readonly,
|
|
34
|
+
color: options.color
|
|
35
|
+
});
|
|
36
|
+
setSurface(s);
|
|
37
|
+
return () => {
|
|
38
|
+
s.dispose();
|
|
39
|
+
setSurface(null);
|
|
40
|
+
};
|
|
41
|
+
}, [canvasRef]);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!surface) return;
|
|
44
|
+
if (options.style) surface.setStyle(options.style);
|
|
45
|
+
if (options.readonly !== void 0) surface.setReadonly(options.readonly);
|
|
46
|
+
}, [
|
|
47
|
+
surface,
|
|
48
|
+
options.style,
|
|
49
|
+
options.readonly
|
|
50
|
+
]);
|
|
51
|
+
return surface;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Generic HUD overlay component.
|
|
55
|
+
*
|
|
56
|
+
* Renders a `<canvas>` element driven by {@link HUDCanvas}. Pass a
|
|
57
|
+
* pre-built {@link HUDDraw} command list to control what is drawn.
|
|
58
|
+
*/
|
|
59
|
+
const HUDOverlay = (props) => {
|
|
60
|
+
const canvasRef = React.useRef(null);
|
|
61
|
+
const rendererRef = React.useRef(null);
|
|
62
|
+
React.useLayoutEffect(() => {
|
|
63
|
+
if (!canvasRef.current) return;
|
|
64
|
+
if (!rendererRef.current) rendererRef.current = new HUDCanvas(canvasRef.current, { color: props.color });
|
|
65
|
+
rendererRef.current.setColor(props.color);
|
|
66
|
+
rendererRef.current.setSize(props.width, props.height);
|
|
67
|
+
rendererRef.current.setTransform(props.transform);
|
|
68
|
+
rendererRef.current.draw(props.draw);
|
|
69
|
+
}, [
|
|
70
|
+
props.width,
|
|
71
|
+
props.height,
|
|
72
|
+
props.transform,
|
|
73
|
+
props.draw,
|
|
74
|
+
props.color
|
|
75
|
+
]);
|
|
76
|
+
return /* @__PURE__ */ jsx("canvas", {
|
|
77
|
+
ref: canvasRef,
|
|
78
|
+
style: {
|
|
79
|
+
width: props.width,
|
|
80
|
+
height: props.height,
|
|
81
|
+
pointerEvents: "none"
|
|
82
|
+
},
|
|
83
|
+
className: props.className
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const SnapGuide = (props) => {
|
|
87
|
+
const draw = React.useMemo(() => {
|
|
88
|
+
return snapGuideToHUDDraw(props.snapping ? guide.plot(props.snapping) : void 0);
|
|
89
|
+
}, [props.snapping]);
|
|
90
|
+
return /* @__PURE__ */ jsx(HUDOverlay, {
|
|
91
|
+
...props,
|
|
92
|
+
draw
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const MeasurementGuide = (props) => {
|
|
96
|
+
const draw = React.useMemo(() => props.measurement ? measurementToHUDDraw(props.measurement) : void 0, [props.measurement]);
|
|
97
|
+
return /* @__PURE__ */ jsx(HUDOverlay, {
|
|
98
|
+
...props,
|
|
99
|
+
draw
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const Marquee = (props) => {
|
|
103
|
+
const draw = React.useMemo(() => props.a && props.b ? marqueeToHUDDraw(props.a, props.b) : void 0, [props.a, props.b]);
|
|
104
|
+
return /* @__PURE__ */ jsx(HUDOverlay, {
|
|
105
|
+
...props,
|
|
106
|
+
draw
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const Lasso = (props) => {
|
|
110
|
+
const draw = React.useMemo(() => props.points ? lassoToHUDDraw(props.points) : void 0, [props.points]);
|
|
111
|
+
return /* @__PURE__ */ jsx(HUDOverlay, {
|
|
112
|
+
...props,
|
|
113
|
+
draw
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { HUDOverlay, Lasso, Marquee, MeasurementGuide, SnapGuide, useHUDSurface };
|