@flighthq/gizmo 0.4.1-edge.37.ff47e13
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.md +9 -0
- package/README.md +17 -0
- package/dist/contract.d.ts +3 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +3 -0
- package/dist/contract.js.map +1 -0
- package/dist/gizmoState.d.ts +17 -0
- package/dist/gizmoState.d.ts.map +1 -0
- package/dist/gizmoState.js +587 -0
- package/dist/gizmoState.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/node2dGizmoFeatures.d.ts +3 -0
- package/dist/node2dGizmoFeatures.d.ts.map +1 -0
- package/dist/node2dGizmoFeatures.js +22 -0
- package/dist/node2dGizmoFeatures.js.map +1 -0
- package/package.json +57 -0
- package/src/gizmoState.test.ts +872 -0
- package/src/gizmoTreeShaking.test.ts +35 -0
- package/src/node2dGizmoFeatures.test.ts +51 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
|
|
3
|
+
import { build } from 'esbuild';
|
|
4
|
+
|
|
5
|
+
describe('Gizmo feature tree shaking', () => {
|
|
6
|
+
it('does not pull the handle assembly or interaction runtime into a Node2D-feature-only bundle', async () => {
|
|
7
|
+
const result = await build({
|
|
8
|
+
bundle: true,
|
|
9
|
+
format: 'esm',
|
|
10
|
+
logLevel: 'silent',
|
|
11
|
+
minify: true,
|
|
12
|
+
packages: 'external',
|
|
13
|
+
stdin: {
|
|
14
|
+
contents: `export { createNode2DGizmoFeatures } from './contract.ts';`,
|
|
15
|
+
resolveDir: fileUrlDirectory(import.meta.url),
|
|
16
|
+
sourcefile: 'tree-shake-node2d-features.ts',
|
|
17
|
+
},
|
|
18
|
+
treeShaking: true,
|
|
19
|
+
write: false,
|
|
20
|
+
});
|
|
21
|
+
const output = result.outputFiles[0].text;
|
|
22
|
+
expect(output).toContain('createNode2DGizmoFeatures');
|
|
23
|
+
expect(output).not.toContain('GizmoTranslateXHandle');
|
|
24
|
+
expect(output).not.toContain('appendShapeCircle');
|
|
25
|
+
expect(output).not.toContain('@flighthq/interaction');
|
|
26
|
+
expect(output).not.toContain('@flighthq/selection');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function fileUrlDirectory(url: string): string {
|
|
31
|
+
const directory = new URL('.', url);
|
|
32
|
+
const pathname = decodeURIComponent(directory.pathname);
|
|
33
|
+
if (directory.hostname !== '') return `//${directory.hostname}${pathname}`;
|
|
34
|
+
return /^\/[A-Za-z]:\//.test(pathname) ? pathname.slice(1) : pathname;
|
|
35
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createCamera2D } from '@flighthq/camera/contract';
|
|
2
|
+
import { createRectangle, createVector2 } from '@flighthq/geometry/contract';
|
|
3
|
+
import { addNodeChild } from '@flighthq/node/contract';
|
|
4
|
+
import { createDisplayObject, createScene2D } from '@flighthq/scene2d/contract';
|
|
5
|
+
import {
|
|
6
|
+
appendShapeBeginFill,
|
|
7
|
+
appendShapeEndFill,
|
|
8
|
+
appendShapeRectangle,
|
|
9
|
+
createShape,
|
|
10
|
+
registerDefaultShapeBoundsCommands,
|
|
11
|
+
} from '@flighthq/shape/contract';
|
|
12
|
+
|
|
13
|
+
import { createNode2DGizmoFeatures } from './node2dGizmoFeatures';
|
|
14
|
+
|
|
15
|
+
describe('createNode2DGizmoFeatures', () => {
|
|
16
|
+
it('adapts Node2D world bounds, pivot origin, and composed rotation in degrees', () => {
|
|
17
|
+
registerDefaultShapeBoundsCommands();
|
|
18
|
+
const scene = createScene2D();
|
|
19
|
+
const parent = createDisplayObject({ rotation: 15, x: 10, y: 20 });
|
|
20
|
+
const node = createShape({ pivotX: 2, pivotY: 3, rotation: 30, x: 8, y: 9 });
|
|
21
|
+
appendShapeBeginFill(node, 0xffffff);
|
|
22
|
+
appendShapeRectangle(node, 0, 0, 10, 20);
|
|
23
|
+
appendShapeEndFill(node);
|
|
24
|
+
addNodeChild(scene.root, parent);
|
|
25
|
+
addNodeChild(parent, node);
|
|
26
|
+
const features = createNode2DGizmoFeatures();
|
|
27
|
+
const bounds = createRectangle();
|
|
28
|
+
const origin = createVector2();
|
|
29
|
+
|
|
30
|
+
expect(features.getWorldBoundsRectangle(bounds, node)).toBe(true);
|
|
31
|
+
features.getWorldOrigin(origin, node);
|
|
32
|
+
|
|
33
|
+
expect(bounds.width).toBeGreaterThan(0);
|
|
34
|
+
expect(bounds.height).toBeGreaterThan(0);
|
|
35
|
+
expect(origin.x).toBeCloseTo(10 + 8 * Math.cos(Math.PI / 12) - 9 * Math.sin(Math.PI / 12), 8);
|
|
36
|
+
expect(origin.y).toBeCloseTo(20 + 8 * Math.sin(Math.PI / 12) + 9 * Math.cos(Math.PI / 12), 8);
|
|
37
|
+
expect(features.getWorldRotation(node)).toBeCloseTo(45, 8);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('is independent of camera and overlay state', () => {
|
|
41
|
+
const features = createNode2DGizmoFeatures();
|
|
42
|
+
const camera = createCamera2D(320, 200, { zoom: 2 });
|
|
43
|
+
|
|
44
|
+
expect(features).toEqual({
|
|
45
|
+
getWorldBoundsRectangle: expect.any(Function),
|
|
46
|
+
getWorldOrigin: expect.any(Function),
|
|
47
|
+
getWorldRotation: expect.any(Function),
|
|
48
|
+
});
|
|
49
|
+
expect(camera.zoom).toBe(2);
|
|
50
|
+
});
|
|
51
|
+
});
|