@margoengine/viewcube 0.0.0-stage → 1.0.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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Scott Campbell
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Margo Engine
2
+ Copyright 2026 Scott Campbell
3
+
4
+ This product includes Margo Engine (https://margoengine.com) by Scott Campbell.
package/README.md CHANGED
@@ -1,3 +1,131 @@
1
- # Temporary Holding Version
1
+ # @margoengine/viewcube
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Import `margoengine/viewcube` from the `margoengine` package, or `@margoengine/viewcube` from this package alone; the two are the same module. Neither is on npm yet: the [Install](../../README.md#install) section lists the two routes that work today (run in a clone, or install local tarballs).
4
+
5
+ A CAD orientation cube for Margo Engine: a small cube in a corner of the view that turns with the camera. Click a face,
6
+ edge or corner and the camera animates around its target to that view (Top, Front, Right, ..., the twelve edge views
7
+ and the eight isometric corners), keeping the distance. With `@margoengine/cameras` it also toggles perspective and
8
+ orthographic projection.
9
+
10
+ ```ts
11
+ import {Engine} from 'margoengine/core';
12
+ import {CameraProjection} from 'margoengine/cameras';
13
+ import {OrbitControls} from 'margoengine/controls';
14
+ import {ViewCube} from 'margoengine/viewcube';
15
+ const canvas = document.querySelector('canvas')!;
16
+
17
+ const engine = await Engine.create(canvas); // the canvas needs a parent element; the cube is placed in it
18
+ const projection = CameraProjection.attach(engine, {mode: 'perspective'});
19
+ OrbitControls.attach(engine); // or the stage's CADCameraControls
20
+ const cube = ViewCube.attach(engine, {projection}); // omit projection to hide the toggle
21
+
22
+ cube.view('top'); // 'top' | 'bottom' | 'front' | 'back' | 'left' | 'right' | 'iso'
23
+ cube.view([1, 1, 0]); // any direction from the target toward the camera
24
+ cube.view('front', 0); // jump without animating
25
+ cube.setProjection('orthographic');
26
+ cube.setTheme('dark'); // 'light' | 'dark' | 'high-contrast' | 'auto' | your own tokens
27
+ cube.drag = false; // dragging the cube orbits the camera unless turned off
28
+ cube.setHome({position: [6, 4, 8], target: [0, 1, 0]}); // your own home view; shows the home button
29
+ cube.home(); // the home button and the Home key do the same
30
+ cube.roll(1); // a quarter turn counter-clockwise about the view axis (-1 clockwise)
31
+ cube.dispose(); // engine.dispose() also disposes it
32
+ ```
33
+
34
+ For less than a cube, `margoengine/viewcube/axes` (`@margoengine/viewcube/axes`) has an axis triad: X, Y and Z
35
+ balls on sticks and a smaller ball at each negative end, turning with the camera.
36
+
37
+ ```ts
38
+ import {Engine} from 'margoengine/core';
39
+ import {AxisTriad} from 'margoengine/viewcube/axes';
40
+ const canvas = document.querySelector('canvas')!;
41
+
42
+ const engine = await Engine.create(canvas);
43
+ const triad = AxisTriad.attach(engine, {corner: 'bottom-left', home: true}); // every ViewCube option works
44
+ triad.view('right'); // a ViewCube in every other way
45
+ ```
46
+
47
+ Options: `container` (default: the canvas's parent; made `position: relative` if it is static), `corner`
48
+ (`'top-right'` default, `'top-left'`, `'bottom-right'`, `'bottom-left'`), `size` (cube edge in CSS pixels, 80),
49
+ `duration` (seconds, 0.4), `projection` (a CameraProjection, or anything with `mode`), `labels` (face names, for
50
+ translation), `flip` (false; also a public field: clicking the view already shown turns to the opposite one, as
51
+ Blender's navigation gizmo and SolidWorks' "Normal To" pressed twice do; Autodesk's ViewCube keeps the view),
52
+ `drag` (true; also a public field: dragging the cube orbits the camera), `home` (none; a `{position, target}`, or
53
+ `true` for the camera as it is when the cube attaches: shows the home button), `roll` (false; shows the two roll
54
+ buttons), `theme` (none: the light colours; see Themes).
55
+ `@margoengine/controls` navigation profiles carry it: `ViewCube.attach(engine, {...BLENDER.viewCube})`. The toggle
56
+ also follows projection changes made elsewhere (Blender's numpad 5 through a profile) on the next frame.
57
+ `cube.element` is the widget root for your own styling.
58
+
59
+ - **Orientation.** World Y is up, front is +Z, right is +X (glTF and Blender exports). Top shows X right and -Z up,
60
+ bottom X right and +Z up, from whichever side the camera comes, because the animation interpolates azimuth and
61
+ elevation the way OrbitControls moves. Top and bottom are exactly vertical: on the pole the cube sets `camera.up` to
62
+ the screen up of the way it came (arrow keys turn it there) and puts the previous up back as soon as the camera
63
+ leaves the pole, or on `dispose` (then 1e-6 rad off the pole, same image). An up it did not set is left alone, such as
64
+ a CameraProjection's vertical `up`, until a drag on the cube or its compass turns the heading on the pole: then the
65
+ cube turns the projection's `up` with it, so the image spins, and the projection keeps that up. OrbitControls and CADCameraControls leave an exact pole at azimuth 0, so after a
66
+ top view reached from the side they start from the front.
67
+ - **Drag to orbit.** Press on the cube and drag: the camera orbits its target at the same distance, with the
68
+ azimuth and elevation OrbitControls uses, so the cube's surface follows the pointer (half the cube's width is one
69
+ radian). Dragging right turns the front to the right; dragging down tips the top toward you and stops on the pole
70
+ in a standard top view. A press that moves under 3 pixels is still a click on the face, edge or corner, and the
71
+ click that ends a drag does nothing. The cube keeps the pointer while dragging, a drag cancels a view animation,
72
+ and only the primary button drags (`touch-action: none` on the widget, so a touch drag does not scroll the page).
73
+ - **Home view.** `home` or `cube.setHome(view)` sets the app's own home: a camera position and the target it looks
74
+ at (`cube.setHome()` takes the camera as it is now). A round home button appears above the cube's top-left corner;
75
+ it and the Home key animate the camera there, moving the target and the distance too, and land on them exactly.
76
+ A vertical home is exactly vertical with the standard top or bottom orientation. `cube.getHome()` returns a copy;
77
+ without a home, Home goes to the isometric view and there is no button. A press on the button never starts a drag.
78
+ - **Roll.** `roll: true` shows two round buttons above the cube's top-right corner that turn the view a quarter turn
79
+ about its axis, counter-clockwise and clockwise; `cube.roll(turns)` does the same for any number of quarter turns
80
+ and `cube.turns` reads the roll (0 to 3 at rest). The camera position and target stay; the cube rolls
81
+ `camera.up` about the view axis again every frame, so the roll holds while OrbitControls or another control
82
+ orbits, on the poles too, and a drag on a rolled cube still follows the pointer on screen. A view change from the
83
+ cube (a face, edge or corner, the arrow keys, Home) turns the view upright again; an up set by someone else wins
84
+ and ends the roll; `dispose` gives the app's up back. The buttons and the home button share a row above the cube,
85
+ so a cube in a top corner sits 38 px from the edge instead of 12 px.
86
+ - **Themes.** The colours are six tokens, each a CSS custom property on the widget root: `--mvc-background` (face
87
+ and button fill), `--mvc-text`, `--mvc-line` (edges and borders), `--mvc-hover` (fill of a hovered or focused face,
88
+ edge, corner or button), `--mvc-hover-text` and `--mvc-focus` (keyboard focus ring). `THEMES` exports the built-in
89
+ `light`, `dark` and `high-contrast` sets; `theme` or `cube.setTheme(...)` takes one of their names, `'auto'`
90
+ (dark when the browser prefers a dark scheme, high contrast when it prefers more contrast, else light) or your own
91
+ tokens, for example `cube.setTheme({background: '#1b1f27', text: '#f2f4f7'})`; tokens you leave out keep the
92
+ stylesheet's. Without a theme the cube sets no inline colours, so your own CSS can set the properties on `.mvc`.
93
+ The package tests check every built-in pair against WCAG 2 contrast over both a black and a white page behind the
94
+ translucent fill: text and hovered text at least 4.5:1 (high contrast 7:1), edges and the focus ring at least 3:1.
95
+ The light theme's edges and focus ring are darker than before themes (`#6b7280`, `#0b3d91`) for that reason.
96
+ - **Axis triad.** `AxisTriad` (entry `viewcube/axes`) is a `ViewCube` subclass that builds balls in place of the
97
+ faces: +X, +Y and +Z are buttons labelled X, Y and Z ("Right view (X)", "Top view (Y)", "Front view (Z)"), the
98
+ negative ends smaller rings. Each ball sits where its axis points on screen, nearer balls drawn in front, so the
99
+ view is read the way a CAD axis gizmo reads. Clicking a ball animates to that axis view, dragging orbits (two
100
+ radians per triad width), and the home view, roll buttons, projection toggle, themes, flip and keyboard behave as
101
+ on the cube. Default `size` is 64. The axis colours are `--mvc-x`, `--mvc-y` and `--mvc-z` (default `#c62828`,
102
+ `#2e7d32`, `#1565c0`, white letters at 4.5:1 or more). The cube's `build` and `draw` are the protected hooks it
103
+ overrides.
104
+ - **Engine views.** `ViewCube.attach(engine, {view: {camera, viewport}})` turns that view's camera and sits in the chosen corner of its rectangle (the cube's container must cover the canvas). One cube per view.
105
+ - **Controls.** The cube writes `camera.position` (and `camera.up` on the poles); OrbitControls, MapControls and the stage's CADCameraControls read
106
+ the camera each frame, so they keep working. Any other camera change during an animation (a drag, a wheel) cancels it.
107
+ A running `fitToBoundingBox` animation is cancelled when a view starts.
108
+ - **Accessibility.** The root is a labelled group. The six faces are buttons named "Front view", "Top view", ...; only
109
+ faces turned toward the viewer are in the tab order (screen readers reach all six). Arrow keys step the view 45°
110
+ around and over the target, Home goes to the home view (the isometric view without one), Enter or Space activates the focused face. Edge and
111
+ corner hot spots are pointer targets with tooltips. The projection toggle is a button with `aria-pressed`; the home button is named "Home view", the roll buttons "Roll the view counter-clockwise" and "... clockwise".
112
+ - **Rendering.** Plain DOM and CSS 3D transforms: no GPU work, no extra pass, crisp text at any DPR, works on WebGPU
113
+ and WebGL2. The cube turns in a frame-graph step after every control has moved the camera, so it never lags a frame,
114
+ and touches the DOM only when the orientation changed.
115
+
116
+ Why a separate package and not `@margoengine/controls`: the cube is a DOM widget that drives any camera controller
117
+ (including the stage's CADCameraControls, which does not use controls) and optionally `@margoengine/cameras`; keeping it
118
+ out leaves controls' bundle and dependencies unchanged.
119
+
120
+ Limits: roll is in quarter turns from the cube's buttons and `roll` (any whole or fractional count, landing on a
121
+ whole quarter turn), the home view keeps the camera's field of view and
122
+ projection (only position and target), and a custom theme's contrast is yours to check (only the built-in ones are
123
+ tested).
124
+
125
+ Size: 5,130 B min + gzip (the test enforces under 5,150 B); `viewcube/axes` adds 1,127 B on top (under 1,200 B). Apache-2.0. Peer: `@margoengine/core` (^0.1.0 || ^1.0.0).
126
+
127
+ Unit tests: `npm test --workspace @margoengine/viewcube`. Browser check with real clicks: `node packages/viewcube/test/browser-check.mjs`.
128
+
129
+ ## Core compatibility at engine boundaries
130
+
131
+ Each engine-bound entry (`.`, `/axes`, `/up`, `/fit`, `/compass`) carries the core version its build was made for, stamped into its plugins, `attach` methods and `engineRuntime` calls, and checks the engine's core when it attaches or its plugin is set up, before it reads or changes the engine. A mismatched core version, or a second core module in the page (two installs, or one bundled twice), throws MargoError `'version'` naming both cores and the package, with the help link https://margoengine.com/errors#version. The cure is one core: dedupe or rebuild the packages against the same core build (`npm ls @margoengine/core` lists the copies); do not catch the error and go on. The check keeps no global state, and importing an entry registers nothing and attaches nothing. Details: [One core per engine](../core/README.md#one-core-per-engine-version-checks-extension) in the core README.
package/dist/axes.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { EngineKernel } from '@margoengine/core';
2
+ import { type Face, ViewCube, type ViewCubeOptions } from './index.js';
3
+ /** Options for {@link AxisTriad}: the ViewCube's, with `size` (the triad's width in CSS pixels) defaulting to 64. */
4
+ export type AxisTriadOptions = ViewCubeOptions;
5
+ /**
6
+ * A compact axis gizmo (X, Y and Z balls on sticks, and a smaller ball at each negative end) for apps that want less
7
+ * than a cube. It is a {@link ViewCube} in every other way: a click on a ball animates to that axis view, dragging
8
+ * orbits, and the home view, roll buttons, projection toggle, themes and keyboard work the same. The axis colours are
9
+ * the custom properties `--mvc-x`, `--mvc-y` and `--mvc-z` (default red, green and blue).
10
+ */
11
+ export declare class AxisTriad extends ViewCube {
12
+ /** Balls and sticks with their signed axis (1 is +X, -3 is -Z); set while the base constructor builds the widget. */
13
+ private axes;
14
+ private radius;
15
+ /** Creates the AxisTriad on `engine` (preferred over the constructor). */
16
+ static attach(engine: EngineKernel, options?: AxisTriadOptions): AxisTriad;
17
+ constructor(engine: EngineKernel, options?: AxisTriadOptions);
18
+ /** Builds the balls and sticks in place of the cube's faces. */
19
+ protected build(cube: HTMLDivElement, names: Record<Face, string>, size: number): void;
20
+ /** Places each ball where its axis points on screen, nearer balls in front. */
21
+ protected draw(right: readonly number[], up: readonly number[], back: readonly number[]): void;
22
+ }
package/dist/axes.js ADDED
@@ -0,0 +1,72 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ import { ViewCube as e } from "./index.js";
5
+ //#region src/axes.ts
6
+ var t = [
7
+ [
8
+ 0,
9
+ "right",
10
+ "left",
11
+ "X"
12
+ ],
13
+ [
14
+ 1,
15
+ "top",
16
+ "bottom",
17
+ "Y"
18
+ ],
19
+ [
20
+ 2,
21
+ "front",
22
+ "back",
23
+ "Z"
24
+ ]
25
+ ], n = 18, r = 12, i = ".mvc-ball{position:absolute;left:0;top:0;box-sizing:border-box;margin:0;padding:0;border:2px solid var(--c);border-radius:50%;background:var(--c);color:#fff;font:700 10px/14px system-ui,sans-serif;text-align:center;pointer-events:auto;cursor:pointer;outline:none}\n.mvc-ball[aria-hidden]{background:var(--mvc-background)}\n.mvc-ball:hover,.mvc-ball:focus-visible{box-shadow:0 0 0 2px var(--mvc-focus)}\n.mvc-stick{position:absolute;left:0;top:0;height:2px;background:var(--c);transform-origin:0 50%;pointer-events:none}", a = class a extends e {
26
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
27
+ return new a(e, t);
28
+ }
29
+ constructor(e, t = {}) {
30
+ super(e, {
31
+ size: 64,
32
+ ...t
33
+ });
34
+ }
35
+ build(e, a, o) {
36
+ let s = e.ownerDocument, c = (t, n, r) => {
37
+ let i = s.createElement(t);
38
+ return i.className = n, i.style.setProperty("--c", r), e.appendChild(i), i;
39
+ };
40
+ e.appendChild(s.createElement("style")).textContent = i, this.axes = [], this.radius = o / 2 - n / 2;
41
+ for (let [e, i, o, s] of t) {
42
+ let t = `var(--mvc-${s.toLowerCase()},${[
43
+ "#c62828",
44
+ "#2e7d32",
45
+ "#1565c0"
46
+ ][e]})`;
47
+ for (let l of [1, -1]) {
48
+ let u = [
49
+ 0,
50
+ 0,
51
+ 0
52
+ ];
53
+ u[e] = l;
54
+ let d = l > 0 ? i : o, f = c("div", "mvc-stick", t), p = c(l > 0 ? "button" : "div", "mvc-ball", t);
55
+ l < 0 && (f.style.opacity = ".5"), p.dataset.view = u.join(), p.title = a[d], p.style.width = p.style.height = (l > 0 ? n : r) + "px", l > 0 ? (p.type = "button", p.textContent = s, p.setAttribute("aria-label", `${a[d]} view (${s})`)) : p.setAttribute("aria-hidden", "true"), this.axes.push([
56
+ p,
57
+ f,
58
+ l * (e + 1)
59
+ ]);
60
+ }
61
+ }
62
+ }
63
+ draw(e, t, i) {
64
+ let a = this.radius, o = a + n / 2;
65
+ for (let [s, c, l] of this.axes) {
66
+ let u = Math.abs(l) - 1, d = Math.sign(l), f = d * e[u] * a, p = -d * t[u] * a, m = d * i[u], h = d > 0 ? n : r;
67
+ s.style.transform = `translate(${+(o + f - h / 2).toFixed(3)}px,${+(o + p - h / 2).toFixed(3)}px)`, s.style.zIndex = String(Math.round(m * 100) + 200), c.style.width = +Math.hypot(f, p).toFixed(3) + "px", c.style.transform = `translate(${o}px,${o - 1}px) rotate(${+Math.atan2(p, f).toFixed(6)}rad)`, c.style.zIndex = String(Math.round(m * 50) + 200);
68
+ }
69
+ }
70
+ };
71
+ //#endregion
72
+ export { a as AxisTriad };
@@ -0,0 +1,62 @@
1
+ import { ViewCube } from './index.js';
2
+ /** Cardinal direction in the cube's horizontal plane. */
3
+ export type Cardinal = 'north' | 'east' | 'south' | 'west';
4
+ /** Optional compass and menu configuration. */
5
+ export interface ViewCompassOptions {
6
+ /** North heading in radians, clockwise from widget -front toward right. Default 0. */
7
+ north?: number;
8
+ /** Display the ring initially. Default true. */
9
+ visible?: boolean;
10
+ /** Add right-click and Shift+F10/ContextMenu access. Default true. */
11
+ menu?: boolean;
12
+ /** Fit action. Default calls cube.fit() when available; otherwise the menu item is disabled. */
13
+ fit?: () => void;
14
+ /** Short cardinal labels. Default N, E, S, W. Accessible names remain full direction names. */
15
+ labels?: Partial<Record<Cardinal, string>>;
16
+ }
17
+ /** A DOM compass ring and accessible context menu for any ViewCube, including /up and /fit. */
18
+ export declare class ViewCompass {
19
+ readonly cube: ViewCube;
20
+ /** Ring root; hidden by the visible property. */
21
+ readonly element: HTMLDivElement;
22
+ /** Context menu root, or undefined with menu:false. */
23
+ readonly menu?: HTMLDivElement;
24
+ private readonly buttons;
25
+ /** The engine plugin it registered, to remove from the scene it went into. */
26
+ private plugin;
27
+ private readonly items;
28
+ private readonly name;
29
+ private readonly previousDispose;
30
+ private readonly disposeCube;
31
+ private readonly margins;
32
+ private readonly off;
33
+ private readonly fitAction?;
34
+ private restoreFocus?;
35
+ private disposed;
36
+ private heading;
37
+ private angle;
38
+ private grab?;
39
+ private dragged;
40
+ /** Attaches one compass to an existing cube; disposing either cleans up the compass. */
41
+ static attach(cube: ViewCube, options?: ViewCompassOptions): ViewCompass;
42
+ constructor(cube: ViewCube, options?: ViewCompassOptions);
43
+ /** North heading in radians. Updating it changes both labels and click directions. */
44
+ get north(): number;
45
+ set north(angle: number);
46
+ /** Whether the compass ring is shown. Default true. */
47
+ get visible(): boolean;
48
+ set visible(value: boolean);
49
+ private direction;
50
+ /** Updates the ring heading after the cube's camera sync; the engine calls it each frame. */
51
+ sync(): void;
52
+ /** Opens the context menu at viewport CSS coordinates, clamped to the viewport. */
53
+ openMenu(x: number, y: number): void;
54
+ /** Hides the menu and, by default, restores the previously focused widget control. */
55
+ closeMenu(restore?: boolean): void;
56
+ private menuKey;
57
+ private listen;
58
+ private pointer;
59
+ /** Removes the ring, menu, listeners and plugin; leaves the cube usable. Idempotent. */
60
+ dispose(): void;
61
+ [Symbol.dispose]: () => void;
62
+ }