@margoengine/viewcube 0.0.0-stage → 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.
@@ -0,0 +1,204 @@
1
+ // @margo/core-built 0.1.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ import { ViewCube as e } from "./index.js";
5
+ import { MargoError as t } from "@margoengine/math/errors";
6
+ //#region src/compass.ts
7
+ var n = class t extends e {
8
+ static localOf(e, t) {
9
+ return e.local(t);
10
+ }
11
+ static turn(e, n, r, i) {
12
+ let a = e;
13
+ a.spin = !0;
14
+ try {
15
+ t.prototype.orbit.call(e, n, r, 0, void 0, void 0, i);
16
+ } finally {
17
+ a.spin = !1;
18
+ }
19
+ }
20
+ }, r = /* @__PURE__ */ new WeakMap(), i = [
21
+ "north",
22
+ "east",
23
+ "south",
24
+ "west"
25
+ ], a = ".mvc-compass{position:absolute;left:-8px;right:-8px;top:calc(100% + 32px);height:36px;pointer-events:none}\n.mvc-compass-track{position:absolute;inset:0;border:1px solid var(--mvc-line);border-radius:50%;box-sizing:border-box}\n.mvc-compass button{position:absolute;transform:translate(-50%,-50%);width:22px;height:22px;border:1px solid var(--mvc-line);border-radius:50%;padding:0;pointer-events:auto;background:var(--mvc-background);color:var(--mvc-text);font:600 10px system-ui;cursor:pointer}\n.mvc-compass button:hover,.mvc-compass button:focus-visible{background:var(--mvc-hover);color:var(--mvc-hover-text)}\n.mvc:has(>.mvc-compass)>.mvc-projection{bottom:-110px}\n.mvc-menu{position:fixed;z-index:10000;min-width:180px;max-width:calc(100vw - 8px);padding:4px;border:1px solid var(--mvc-line);border-radius:5px;background:var(--mvc-background);color:var(--mvc-text);font:12px system-ui;box-sizing:border-box}\n.mvc-menu button{display:block;width:100%;padding:6px 10px;text-align:left;border:0;background:none;color:inherit;font:inherit;cursor:pointer}\n.mvc-menu button:hover,.mvc-menu button:focus-visible{background:var(--mvc-hover);color:var(--mvc-hover-text);outline:2px solid var(--mvc-focus);outline-offset:-2px}\n.mvc-menu button:disabled{opacity:.5;cursor:default}\n.mvc-menu [aria-checked=true]::before{content:'✓ ';}\n.mvc-menu[hidden],.mvc-compass[hidden]{display:none}", o = class e {
26
+ static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
27
+ return new e(t, n);
28
+ }
29
+ constructor(e, n = {}) {
30
+ if (this.cube = e, this.buttons = [], this.items = [], this.off = [], this.disposed = !1, this.heading = 0, this.dragged = !1, r.has(e)) throw new t("attached", "Cube already has a compass; dispose it before attaching another");
31
+ if (!e.element.parentElement || e.engine.disposed) throw new t("disposed", "Cube is disposed; create a new cube before attaching a compass");
32
+ let o = n.north ?? 0;
33
+ if (!Number.isFinite(o)) throw RangeError("Invalid north; use a finite angle in radians");
34
+ this.angle = o, this.name = e.name + ":compass";
35
+ let s = e.element.ownerDocument, c = (e, t, n = "") => {
36
+ let r = s.createElement(e);
37
+ return r.className = n, t.appendChild(r), r;
38
+ };
39
+ this.element = c("div", e.element, "mvc-compass"), this.element.setAttribute("role", "group"), this.element.setAttribute("aria-label", "Compass"), c("style", this.element).textContent = a, c("div", this.element, "mvc-compass-track").setAttribute("aria-hidden", "true"), i.forEach((t, r) => {
40
+ let i = c("button", this.element);
41
+ i.type = "button", i.textContent = n.labels?.[t] ?? t[0].toUpperCase(), i.setAttribute("aria-label", t[0].toUpperCase() + t.slice(1) + " view"), this.listen(i, "click", () => {
42
+ this.dragged ? this.dragged = !1 : e.view(this.direction(r));
43
+ }), this.buttons.push(i);
44
+ }), this.visible = n.visible ?? !0, this.margins = [
45
+ e.element.style.marginLeft,
46
+ e.element.style.marginRight,
47
+ e.element.style.marginBottom
48
+ ], e.element.style.marginLeft = `calc(${this.margins[0] || "0px"} + 16px)`, e.element.style.marginRight = `calc(${this.margins[1] || "0px"} + 16px)`, e.element.style.marginBottom = `calc(${this.margins[2] || "0px"} + 110px)`;
49
+ for (let e of [
50
+ "pointerdown",
51
+ "pointermove",
52
+ "pointerup",
53
+ "pointercancel"
54
+ ]) this.listen(this.element, e, (e) => this.pointer(e));
55
+ let l = e;
56
+ if (this.fitAction = n.fit ?? (typeof l.fit == "function" ? () => l.fit() : void 0), n.menu !== !1) {
57
+ this.menu = c("div", s.body, "mvc-menu"), this.menu.hidden = !0, this.menu.setAttribute("role", "menu"), this.menu.setAttribute("aria-label", "View cube actions");
58
+ let t = (e, t, n = "menuitem") => {
59
+ let r = c("button", this.menu);
60
+ r.type = "button", r.textContent = e, r.tabIndex = -1, r.setAttribute("role", n), this.listen(r, "click", () => {
61
+ this.closeMenu(), t();
62
+ }), this.items.push(r);
63
+ };
64
+ t("Home view", () => e.home()), t("Set current view as Home", () => e.setHome()), t("Fit to view", () => this.fitAction?.()), t("Perspective", () => e.setProjection("perspective"), "menuitemradio"), t("Orthographic", () => e.setProjection("orthographic"), "menuitemradio"), t("Show compass", () => {
65
+ this.visible = !this.visible;
66
+ }, "menuitemcheckbox"), this.listen(e.element, "contextmenu", (e) => {
67
+ let t = e;
68
+ t.preventDefault(), this.openMenu(t.clientX, t.clientY);
69
+ }), this.listen(e.element, "keydown", (t) => {
70
+ let n = t;
71
+ if (n.key === "ContextMenu" || n.shiftKey && n.key === "F10") {
72
+ n.preventDefault();
73
+ let t = e.element.getBoundingClientRect();
74
+ this.openMenu(t.left, t.bottom);
75
+ }
76
+ }), this.listen(this.menu, "keydown", (e) => this.menuKey(e)), this.listen(s, "pointerdown", (e) => {
77
+ this.menu.contains(e.target) || this.closeMenu(!1);
78
+ }), this.listen(s.defaultView, "resize", () => this.closeMenu(!1)), this.listen(s, "scroll", () => this.closeMenu(!1), !0);
79
+ }
80
+ this.previousDispose = e.dispose, this.disposeCube = () => {
81
+ this.dispose(), this.previousDispose.call(e);
82
+ }, e.dispose = this.disposeCube, r.set(e, this), e.engine.use(this.plugin = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
83
+ name: this.name,
84
+ setup() {},
85
+ registerPasses: (e) => {
86
+ e.add({
87
+ name: this.name,
88
+ order: 10001,
89
+ execute: () => this.sync()
90
+ });
91
+ },
92
+ dispose: () => this.dispose()
93
+ }), this.sync();
94
+ }
95
+ get north() {
96
+ return this.angle;
97
+ }
98
+ set north(e) {
99
+ if (!Number.isFinite(e)) throw RangeError("Invalid north; use a finite angle in radians");
100
+ this.angle = e, this.sync();
101
+ }
102
+ get visible() {
103
+ return !this.element.hidden;
104
+ }
105
+ set visible(e) {
106
+ this.element.hidden = !e;
107
+ }
108
+ direction(e) {
109
+ let t = this.angle + e * Math.PI / 2;
110
+ return [
111
+ Math.sin(t),
112
+ 0,
113
+ -Math.cos(t)
114
+ ];
115
+ }
116
+ sync() {
117
+ if (this.disposed) return;
118
+ let e = this.cube.camera, t = n.localOf(this.cube, e.position.map((t, n) => t - e.target[n]));
119
+ if (Math.hypot(t[0], t[2]) > 1e-9 * Math.hypot(...t)) this.heading = Math.atan2(t[0], t[2]);
120
+ else {
121
+ let r = n.localOf(this.cube, e.up), i = Math.sign(t[1]);
122
+ this.heading = Math.atan2(-i * r[0], -i * r[2]);
123
+ }
124
+ let r = (parseFloat(this.cube.element.style.width) + 16) / 2;
125
+ this.buttons.forEach((e, t) => {
126
+ let n = this.direction(t), i = (n[0] * Math.cos(this.heading) - n[2] * Math.sin(this.heading)) * r, a = (n[0] * Math.sin(this.heading) + n[2] * Math.cos(this.heading)) * 18;
127
+ e.style.left = `calc(50% + ${i}px)`, e.style.top = `${18 + a}px`;
128
+ });
129
+ }
130
+ openMenu(e, t) {
131
+ if (!this.menu || this.disposed) return;
132
+ if (![e, t].every(Number.isFinite)) throw RangeError("Invalid menu point; use finite viewport coordinates");
133
+ let n = this.menu.ownerDocument, r = n.defaultView;
134
+ this.restoreFocus = this.cube.element.contains(n.activeElement) ? n.activeElement : this.cube.element.querySelector("button[tabindex=\"0\"]") ?? this.buttons[0], this.items[2].disabled = !this.fitAction;
135
+ let i = this.cube.getProjection();
136
+ for (let e of [3, 4]) this.items[e].disabled = !i, this.items[e].setAttribute("aria-checked", String(i === (e === 3 ? "perspective" : "orthographic")));
137
+ this.items[5].setAttribute("aria-checked", String(this.visible));
138
+ let a = r.getComputedStyle(this.cube.element);
139
+ for (let e of [
140
+ "background",
141
+ "text",
142
+ "line",
143
+ "hover",
144
+ "hover-text",
145
+ "focus"
146
+ ]) this.menu.style.setProperty("--mvc-" + e, a.getPropertyValue("--mvc-" + e));
147
+ this.menu.hidden = !1;
148
+ let o = this.menu.getBoundingClientRect();
149
+ this.menu.style.left = Math.max(4, Math.min(e, r.innerWidth - o.width - 4)) + "px", this.menu.style.top = Math.max(4, Math.min(t, r.innerHeight - o.height - 4)) + "px", this.items[0].focus();
150
+ }
151
+ closeMenu(e = !0) {
152
+ this.menu && !this.menu.hidden && (this.menu.hidden = !0, e && this.restoreFocus?.focus());
153
+ }
154
+ menuKey(e) {
155
+ let t = this.items.filter((e) => !e.disabled), n = t.indexOf(this.menu.ownerDocument.activeElement);
156
+ if (e.key === "Escape" || e.key === "Tab") {
157
+ this.closeMenu(), e.key === "Escape" && e.preventDefault();
158
+ return;
159
+ }
160
+ let r;
161
+ if (e.key === "ArrowDown") r = (n + 1) % t.length;
162
+ else if (e.key === "ArrowUp") r = (n - 1 + t.length) % t.length;
163
+ else if (e.key === "Home") r = 0;
164
+ else if (e.key === "End") r = t.length - 1;
165
+ else return;
166
+ e.preventDefault(), t[r].focus();
167
+ }
168
+ listen(e, t, n, r = !1) {
169
+ e.addEventListener(t, n, r), this.off.push(() => e.removeEventListener(t, n, r));
170
+ }
171
+ pointer(e) {
172
+ if (e.type === "pointerdown") {
173
+ this.dragged = !1;
174
+ let t = e.target.closest("button");
175
+ if (e.button !== 0 || !t || !this.element.contains(t)) return;
176
+ let r = this.cube.camera, i = n.localOf(this.cube, r.position.map((e, t) => e - r.target[t]));
177
+ this.sync(), this.grab = {
178
+ id: e.pointerId,
179
+ x: e.clientX,
180
+ y: e.clientY,
181
+ theta: this.heading,
182
+ phi: Math.acos(Math.max(-1, Math.min(1, i[1] / Math.hypot(...i)))),
183
+ twist: this.cube.turns * Math.PI / 2,
184
+ button: t
185
+ }, e.isTrusted && t.setPointerCapture(e.pointerId);
186
+ return;
187
+ }
188
+ let t = this.grab;
189
+ t && e.pointerId === t.id && (e.type === "pointermove" ? !this.dragged && Math.hypot(e.clientX - t.x, e.clientY - t.y) < 3 || (this.dragged = !0, n.turn(this.cube, t.theta - (e.clientX - t.x) * 2 / (parseFloat(this.cube.element.style.width) + 16), t.phi, t.twist), e.preventDefault(), this.sync()) : (t.button.hasPointerCapture?.(t.id) && t.button.releasePointerCapture(t.id), this.grab = void 0));
190
+ }
191
+ dispose() {
192
+ if (this.disposed) return;
193
+ this.closeMenu(), this.disposed = !0, this.grab?.button.hasPointerCapture?.(this.grab.id) && this.grab.button.releasePointerCapture(this.grab.id), this.grab = void 0;
194
+ for (let e of this.off) e();
195
+ this.element.remove(), this.menu?.remove();
196
+ let e = this.cube;
197
+ [e.element.style.marginLeft, e.element.style.marginRight, e.element.style.marginBottom] = this.margins, e.dispose === this.disposeCube && (e.dispose = this.previousDispose), r.delete(e), !e.engine.disposed && this.plugin && e.engine.sceneOf(this.plugin)?.removePlugin(this.name);
198
+ }
199
+ [Symbol.dispose ?? Symbol()]() {
200
+ this.dispose();
201
+ }
202
+ };
203
+ //#endregion
204
+ export { o as ViewCompass };
package/dist/fit.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type { EngineKernel } from '@margoengine/core';
2
+ import { UpViewCube, type UpViewCubeOptions } from './up.js';
3
+ /** World AABB as minX, minY, minZ, maxX, maxY, maxZ, evaluated at each view request. */
4
+ export type ViewBounds = ArrayLike<number> | (() => ArrayLike<number>);
5
+ /** CameraProjection's public framing fields; no cameras runtime dependency is required. */
6
+ export interface ViewFitProjection {
7
+ mode: 'orthographic' | 'perspective';
8
+ up?: [number, number, number];
9
+ zoom: number;
10
+ height?: number;
11
+ left?: number;
12
+ right?: number;
13
+ top?: number;
14
+ bottom?: number;
15
+ near?: number;
16
+ far?: number;
17
+ applyLens?(aspect: number): number;
18
+ }
19
+ /** Framing, world frame and inherited widget options. */
20
+ export interface FitViewCubeOptions extends UpViewCubeOptions {
21
+ /** Bounds to frame. Default none; assign bounds before requesting a fitted view. */
22
+ bounds?: ViewBounds;
23
+ /** Multiplicative margin, at least 1. Default 1.1. */
24
+ padding?: number;
25
+ /** Viewport width / height. Default the chosen engine view's aspect. */
26
+ aspect?: number | (() => number);
27
+ /** A CameraProjection or equivalent; auto-detected when attached as the cameras plugin. */
28
+ projection?: ViewFitProjection;
29
+ }
30
+ /** Frames bounds throughout face, edge, corner, keyboard, home and roll transitions. */
31
+ export declare class FitViewCube extends UpViewCube {
32
+ /** Current world bounds or live bounds provider. Undefined disables automatic fitting. */
33
+ bounds?: ViewBounds;
34
+ /** Margin around the enclosing sphere. Default 1.1. */
35
+ padding: number;
36
+ private readonly aspectSource;
37
+ private readonly fitProjection?;
38
+ private framing?;
39
+ static attach(engine: EngineKernel, options?: FitViewCubeOptions): FitViewCube;
40
+ constructor(engine: EngineKernel, options?: FitViewCubeOptions);
41
+ /** Frames the current direction without changing its roll. Default duration is the widget duration. */
42
+ fit(duration?: number): void;
43
+ setProjection(mode: 'orthographic' | 'perspective'): void;
44
+ protected orbit(theta: number, phi: number, duration: number, to?: readonly number[], distance?: number, twist?: number): void;
45
+ update(delta: number): void;
46
+ private checkProjection;
47
+ private fitZoom;
48
+ }
package/dist/fit.js ADDED
@@ -0,0 +1,84 @@
1
+ // @margo/core-built 0.1.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ import { UpViewCube as e } from "./up.js";
5
+ //#region src/fit.ts
6
+ var t = class t extends e {
7
+ static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
8
+ return new t(e, n);
9
+ }
10
+ constructor(e, t = {}) {
11
+ super(e, {
12
+ ...t,
13
+ up: t.up ?? "y"
14
+ }), this.bounds = t.bounds, this.padding = t.padding ?? 1.1;
15
+ let n = t.aspect, r = t.view;
16
+ this.aspectSource = () => {
17
+ if (n !== void 0) return typeof n == "function" ? n() : n;
18
+ let [, , t, i] = r?.viewport ?? [
19
+ 0,
20
+ 0,
21
+ 1,
22
+ 1
23
+ ];
24
+ return t / i * (r?.pixels ? 1 : e.canvas.width / e.canvas.height);
25
+ }, this.fitProjection = t.projection ?? e.plugins?.get("cameras");
26
+ }
27
+ fit(e = this.duration) {
28
+ this.roll(0, e);
29
+ }
30
+ setProjection(e) {
31
+ super.setProjection(e), this.bounds && this.fit(0);
32
+ }
33
+ orbit(e, t, n, r, i, a = 0) {
34
+ if (!this.bounds) return super.orbit(e, t, n, r, i, a);
35
+ let o = Array.from(typeof this.bounds == "function" ? this.bounds() : this.bounds), s = this.aspectSource(), c = this.padding, l = this.camera;
36
+ if (o.length !== 6 || !o.every(Number.isFinite) || o.slice(0, 3).some((e, t) => e > o[t + 3]) || ![
37
+ s,
38
+ c,
39
+ n
40
+ ].every(Number.isFinite) || s <= 0 || c < 1 || n < 0) throw RangeError("Invalid view fit; use ordered finite bounds, aspect > 0, padding >= 1 and duration >= 0");
41
+ let u = o.slice(0, 3).map((e, t) => e / 2 + o[t + 3] / 2), d = Math.max(l.near * 2, Math.hypot(...o.slice(0, 3).map((e, t) => o[t + 3] / 2 - e / 2))) * c, f = Math.hypot(...u.map((e, t) => e - l.target[t])), p = l.position.map((e, t) => e - l.target[t]), m = Math.hypot(...p);
42
+ this.fitProjection?.applyLens?.(s);
43
+ let h = Math.atan(Math.tan(l.fov * Math.PI / 360) * Math.min(1, s)), g = this.fitProjection?.mode === "orthographic", _ = (e) => {
44
+ let t = this.fitProjection, n = Math.max(l.near + e, (t.near ?? l.near) + e), r = t.far === void 0 ? Infinity : t.far - e;
45
+ if (n > r) throw RangeError("View bounds exceed projection clip planes; widen projection.near/far");
46
+ return Math.max(n, Math.min(m, r));
47
+ }, v = g ? _(d) : d / Math.sin(h), y = g ? _(d + f) : Math.max(m, (d + f) / Math.sin(h));
48
+ if (!m || ![
49
+ d,
50
+ v,
51
+ y
52
+ ].every(Number.isFinite) || l.fov <= 0 || l.fov >= 180 || (g ? d + f >= l.far / 2 : Math.max(y, v) + d + f >= l.far)) throw RangeError("View bounds exceed the camera clip range; raise camera.far or supply smaller bounds");
53
+ g && this.checkProjection(this.fitProjection), this.framing = {
54
+ center: u,
55
+ radius: d,
56
+ aspect: s
57
+ }, l.position = p.map((e, t) => l.target[t] + e / m * y), super.orbit(e, t, n, u, v, a), this.fitZoom();
58
+ }
59
+ update(e) {
60
+ super.update(e), this.framing && (this.fitZoom(), this.animating || (this.framing = void 0));
61
+ }
62
+ checkProjection(e) {
63
+ let t = [
64
+ e.left,
65
+ e.right,
66
+ e.top,
67
+ e.bottom
68
+ ];
69
+ if (!Number.isFinite(e.zoom) || e.height !== void 0 && !(e.height > 0 && Number.isFinite(e.height)) || [e.near, e.far].some((e) => e !== void 0 && !Number.isFinite(e)) || e.near !== void 0 && e.far !== void 0 && e.near >= e.far || t.every((e) => e !== void 0) && (!t.every(Number.isFinite) || e.right <= e.left || e.top <= e.bottom)) throw RangeError("Invalid fit projection; use CameraProjection with positive height and ordered finite frustum bounds");
70
+ }
71
+ fitZoom() {
72
+ let e = this.framing, t = this.fitProjection, n = this.camera;
73
+ if (!e || t?.mode !== "orthographic") return;
74
+ let r = Math.hypot(...n.position.map((e, t) => e - n.target[t])), i = e.radius + Math.hypot(...e.center.map((e, t) => e - n.target[t])), a = (t.height ?? 2 * r * Math.tan(n.fov * Math.PI / 360)) / 2, o = [
75
+ t.left,
76
+ t.right,
77
+ t.top,
78
+ t.bottom
79
+ ].every((e) => e !== void 0), s = o ? (t.right - t.left) / 2 : a * e.aspect, c = o ? (t.top - t.bottom) / 2 : a, l = o ? (t.right + t.left) / 2 : 0, u = o ? (t.top + t.bottom) / 2 : 0;
80
+ t.zoom = Math.min(s / (i + Math.abs(l)), c / (i + Math.abs(u)));
81
+ }
82
+ };
83
+ //#endregion
84
+ export { t as FitViewCube };
@@ -0,0 +1,193 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { Camera, EngineKernel, RenderView } from '@margoengine/core';
3
+ /** One of the six cube faces. */
4
+ export type Face = 'top' | 'bottom' | 'front' | 'back' | 'left' | 'right';
5
+ /** A named view (`iso` is top-front-right), or a direction from the target toward the camera such as `[1, 1, 0]`. */
6
+ export type View = Face | 'iso' | readonly [number, number, number];
7
+ /** Camera projection the toggle switches between. */
8
+ export type Projection = 'orthographic' | 'perspective';
9
+ /** A camera placement for the home view: where the camera is and the target it looks at. */
10
+ export interface HomeView {
11
+ position: readonly number[];
12
+ target: readonly number[];
13
+ }
14
+ /** Options for {@link ViewCube}; every field has a default. */
15
+ export interface ViewCubeOptions {
16
+ /** Element the cube is placed in. Default: the canvas's parent. */
17
+ container?: HTMLElement;
18
+ /**
19
+ * The engine view this cube belongs to: it turns that view's camera and sits in the corner of its rectangle (the
20
+ * container must cover the canvas). Default the engine camera and the whole canvas.
21
+ */
22
+ view?: Pick<RenderView, 'camera' | 'viewport' | 'pixels'>;
23
+ /** Corner of the view the cube sits in. Default 'top-right'. */
24
+ corner?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
25
+ /** Cube edge in CSS pixels. Default 80. */
26
+ size?: number;
27
+ /** Seconds a click animates for. Default 0.4. */
28
+ duration?: number;
29
+ /** A `@margoengine/cameras` CameraProjection (anything with `mode`): shows a perspective/orthographic toggle.
30
+ * Default: the CameraProjection already attached to the engine, if any. */
31
+ projection?: {
32
+ mode: Projection;
33
+ };
34
+ /** Face names, for translation. */
35
+ labels?: Partial<Record<Face, string>>;
36
+ /** Clicking the view already shown turns to the opposite one (Blender, SolidWorks "Normal To" twice). Default false.
37
+ * A `@margoengine/controls` profile carries it: `ViewCube.attach(engine, {...BLENDER.viewCube})`. */
38
+ flip?: boolean;
39
+ /** Dragging the cube orbits the camera around its target; a press that moves under 3 pixels is still a click.
40
+ * Default true; also a public field. */
41
+ drag?: boolean;
42
+ /**
43
+ * The app's home view: shows a home button, and the button and the Home key animate there (position, target and
44
+ * distance). `true` takes the camera as it is when the cube attaches. Default none: Home goes to the isometric view.
45
+ */
46
+ home?: HomeView | boolean;
47
+ /** Shows two roll buttons that turn the view 90 degrees about the view axis, counter-clockwise and clockwise. Default false. */
48
+ roll?: boolean;
49
+ /**
50
+ * Colours: 'light', 'dark', 'high-contrast', 'auto' (follows the browser's dark scheme and more-contrast settings), or
51
+ * your own tokens over the light ones. Default none: the light colours, which your own CSS may change through the
52
+ * `--mvc-*` custom properties on `.mvc`.
53
+ */
54
+ theme?: ThemeName | 'auto' | Partial<ViewCubeTheme>;
55
+ }
56
+ /** The widget's colours, any CSS colour each. Each is a custom property on the root: `--mvc-background`, ... */
57
+ export interface ViewCubeTheme {
58
+ /** Face and button fill. */
59
+ background: string;
60
+ /** Face names and button glyphs. */
61
+ text: string;
62
+ /** Face edges and button borders. */
63
+ line: string;
64
+ /** Fill over a hovered or focused face, edge or corner. */
65
+ hover: string;
66
+ /** Face name on a hovered or focused face. */
67
+ hoverText: string;
68
+ /** Keyboard focus ring. */
69
+ focus: string;
70
+ }
71
+ /** A built-in {@link THEMES} entry. */
72
+ export type ThemeName = 'light' | 'dark' | 'high-contrast';
73
+ /**
74
+ * Built-in colours, checked by the package tests over a black and a white page behind the translucent fill: WCAG 2
75
+ * contrast of at least 4.5:1 (high contrast 7:1) for the text on the fill and on the hover fill, 3:1 for the edges on
76
+ * the fill and for the focus ring on the hover fill it is drawn on.
77
+ */
78
+ export declare const THEMES: Readonly<Record<ThemeName, Readonly<ViewCubeTheme>>>;
79
+ /**
80
+ * A CAD orientation cube in a corner of the view (Autodesk-style ViewCube). It turns with the camera; a click on a face,
81
+ * edge or corner animates the camera around its target to that view, keeping the distance. Keyboard: the six faces are
82
+ * buttons; arrow keys step the view 45°, Home goes to the home view (isometric without one). Works with the stage's CADCameraControls and
83
+ * `@margoengine/controls` OrbitControls (they read the camera each frame), and toggles a `@margoengine/cameras` projection.
84
+ */
85
+ export declare class ViewCube {
86
+ readonly engine: EngineKernel;
87
+ /** Converts a world direction to the widget frame. Optional entries may supply a different frame. */
88
+ protected local(direction: readonly number[]): readonly number[];
89
+ /** Converts a widget direction to world space. Inverse of {@link local}. */
90
+ protected world(direction: readonly number[]): readonly number[];
91
+ /** The widget root; style or move it as you like. */
92
+ readonly element: HTMLDivElement;
93
+ readonly camera: Camera;
94
+ duration: number;
95
+ /** See ViewCubeOptions.flip. */
96
+ flip: boolean;
97
+ /** See ViewCubeOptions.drag. */
98
+ drag: boolean;
99
+ readonly name: string;
100
+ /** The engine plugin it registered, to remove from the scene it went into. */
101
+ private plugin;
102
+ private readonly cube;
103
+ private readonly buttons;
104
+ private readonly toggle?;
105
+ private readonly projection?;
106
+ private readonly container;
107
+ private readonly position;
108
+ private animation?;
109
+ private homeView?;
110
+ private homeButton?;
111
+ /** Moves a top-corner cube down to make room for the button row above it. */
112
+ private readonly lift;
113
+ private last;
114
+ private disposed;
115
+ private upSet?;
116
+ private upPrev?;
117
+ /** Counter-clockwise roll of the image in radians, and the azimuth of the up the cube set on a pole. */
118
+ private twist;
119
+ private az;
120
+ /** The press being dragged: pointer, where it went down, the camera's angles then, radians per CSS pixel. */
121
+ private grab?;
122
+ private dragged;
123
+ /** True while a drag (the cube's or a compass's) sets the heading: on a pole it turns a projection-owned up too. */
124
+ private spin;
125
+ private readonly speed;
126
+ /** Creates the ViewCube on `engine` (preferred over the constructor). */
127
+ static attach(engine: EngineKernel, options?: ViewCubeOptions): ViewCube;
128
+ constructor(engine: EngineKernel, { container, corner, size, duration, projection, labels, flip, drag, home, roll, theme, view, }?: ViewCubeOptions);
129
+ /**
130
+ * Builds the widget's hot spots in `cube`, the element {@link draw} turns: each element with a `data-view` of three
131
+ * numbers is clicked and dragged like a face. The cube's six faces of nine cells here; AxisTriad builds balls.
132
+ */
133
+ protected build(cube: HTMLDivElement, names: Record<Face, string>, size: number): void;
134
+ /**
135
+ * Shows the camera's orientation: the rows of its view rotation (screen right, up and back in world space) and the
136
+ * same as a CSS matrix3d. Called by {@link sync} only when the orientation changed.
137
+ */
138
+ protected draw(_right: readonly number[], _up: readonly number[], back: readonly number[], matrix: string): void;
139
+ /** Animates to a view (`duration` 0 jumps). The target and distance stay; vertical views keep -Z (top) or +Z (bottom) up. */
140
+ view(view: View, duration?: number): void;
141
+ /** Sets the home view (default: the camera as it is now) and shows the home button. */
142
+ setHome(home?: HomeView): void;
143
+ /** A copy of the home view, or undefined before one is set. */
144
+ getHome(): HomeView | undefined;
145
+ /** Animates to the home view: its position, target and distance (`duration` 0 jumps). Without one, the isometric view. */
146
+ home(duration?: number): void;
147
+ /**
148
+ * Rolls the view about its axis by quarter turns, counter-clockwise on screen for positive `turns` (default 1), keeping
149
+ * the position and target. The cube keeps the roll while other controls orbit; a view change from the cube (a face,
150
+ * edge or corner, the arrow keys, Home) turns the view upright again.
151
+ */
152
+ roll(turns?: number, duration?: number): void;
153
+ /** Quarter turns the view is rolled counter-clockwise: 0 to 3 at rest, fractional while a roll animates. */
154
+ get turns(): number;
155
+ /**
156
+ * Sets the colours: a built-in theme, 'auto', or tokens (any left out keep the light ones, or what your CSS sets).
157
+ * Written as `--mvc-*` custom properties on {@link element}.
158
+ */
159
+ setTheme(theme: ThemeName | 'auto' | Partial<ViewCubeTheme>): void;
160
+ /** Current projection mode, or undefined without a projection. */
161
+ getProjection(): Projection | undefined;
162
+ setProjection(mode: Projection): void;
163
+ /** Advances the animation; the engine calls it before each frame. */
164
+ update(delta: number): void;
165
+ /** True while a view change is animating. */
166
+ get animating(): boolean;
167
+ /** Turns the cube to the camera; called after each frame's updates. */
168
+ sync(): void;
169
+ dispose(): void;
170
+ [Symbol.dispose]: () => void;
171
+ /** Moves the camera to azimuth theta and polar angle phi around the target; near the poles exactly onto them. */
172
+ private place;
173
+ /**
174
+ * Core rejects an up parallel to the view. On an exactly vertical view the cube sets camera.up to the screen up the
175
+ * view had on its way to the pole (azimuth theta), and puts the previous up back once the camera leaves the pole. An up
176
+ * it did not set that already works (a CameraProjection's vertical up) is left alone. A roll turns that up about the
177
+ * view axis, again every frame, so the roll holds while other controls orbit. An up set by someone else wins and ends
178
+ * the roll.
179
+ */
180
+ private pole;
181
+ /** Azimuth and polar angle of the camera; on the pole the azimuth of the up the cube set, else of camera.up (the screen up). */
182
+ private current;
183
+ /** Animates the azimuth and polar angle around the target; home also moves the target to `to` and the distance to `radius`. */
184
+ protected orbit(theta: number, phi: number, duration: number, to?: readonly number[], radius?: number, twist?: number): void;
185
+ private showProjection;
186
+ private readonly onClick;
187
+ /**
188
+ * Drag to orbit: turntable angles as OrbitControls moves them, so dragging right turns the cube's front to the right
189
+ * (the camera goes left) and dragging down tips the top toward the viewer, up to the poles.
190
+ */
191
+ private readonly onPointer;
192
+ private readonly onKey;
193
+ }