@viamrobotics/motion-tools 1.14.0 → 1.15.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/dist/FrameConfigUpdater.svelte.d.ts +2 -2
- package/dist/HoverUpdater.svelte.d.ts +1 -1
- package/dist/attribute.js +1 -1
- package/dist/buf/common/v1/common_pb.d.ts +45 -0
- package/dist/buf/common/v1/common_pb.js +65 -0
- package/dist/color.d.ts +1 -1
- package/dist/color.js +2 -2
- package/dist/components/App.svelte +27 -21
- package/dist/components/App.svelte.d.ts +1 -1
- package/dist/components/BatchedArrows.svelte +5 -3
- package/dist/components/Camera.svelte +1 -0
- package/dist/components/CameraControls.svelte +5 -3
- package/dist/components/Entities/Arrows/ArrowGroups.svelte +6 -3
- package/dist/components/Entities/Arrows/Arrows.svelte +6 -3
- package/dist/components/Entities/Entities.svelte +7 -5
- package/dist/components/Entities/Frame.svelte +8 -5
- package/dist/components/Entities/Frame.svelte.d.ts +2 -2
- package/dist/components/Entities/GLTF.svelte +8 -5
- package/dist/components/Entities/GLTF.svelte.d.ts +2 -2
- package/dist/components/Entities/Geometry.svelte +13 -6
- package/dist/components/Entities/Line.svelte +8 -5
- package/dist/components/Entities/Line.svelte.d.ts +1 -1
- package/dist/components/Entities/LineDots.svelte +1 -1
- package/dist/components/Entities/LineGeometry.svelte +1 -1
- package/dist/components/Entities/Mesh.svelte +8 -5
- package/dist/components/Entities/Points.svelte +9 -6
- package/dist/components/Entities/Points.svelte.d.ts +2 -2
- package/dist/components/Entities/Pose.svelte +4 -3
- package/dist/components/Entities/hooks/useEntityEvents.svelte.d.ts +1 -1
- package/dist/components/Entities/hooks/useEntityEvents.svelte.js +2 -2
- package/dist/components/FileDrop/FileDrop.svelte +10 -6
- package/dist/components/FileDrop/file-dropper.d.ts +1 -1
- package/dist/components/FileDrop/pcd-dropper.js +1 -1
- package/dist/components/FileDrop/ply-dropper.js +1 -1
- package/dist/components/FileDrop/snapshot-dropper.js +1 -1
- package/dist/components/Focus.svelte +4 -2
- package/dist/components/KeyboardControls.svelte +4 -2
- package/dist/components/Lasso/Debug.svelte +5 -2
- package/dist/components/Lasso/Lasso.svelte +9 -6
- package/dist/components/Lasso/Tool.svelte +10 -7
- package/dist/components/MeasureTool/MeasurePoint.svelte +2 -1
- package/dist/components/MeasureTool/MeasurePoint.svelte.d.ts +1 -1
- package/dist/components/MeasureTool/MeasureTool.svelte +7 -5
- package/dist/components/PCD.svelte +4 -3
- package/dist/components/PointerMissBox.svelte +3 -2
- package/dist/components/Scene.svelte +12 -9
- package/dist/components/SceneProviders.svelte +20 -18
- package/dist/components/Selected.svelte +6 -20
- package/dist/components/Snapshot.svelte +8 -5
- package/dist/components/StaticGeometries.svelte +10 -7
- package/dist/components/hover/HoveredEntities.svelte +2 -1
- package/dist/components/hover/HoveredEntity.svelte +2 -1
- package/dist/components/hover/HoveredEntityTooltip.svelte +1 -0
- package/dist/components/hover/LinkedHoveredEntity.svelte +7 -5
- package/dist/components/overlay/AddFrames.svelte +64 -0
- package/dist/components/overlay/AddFrames.svelte.d.ts +3 -0
- package/dist/components/overlay/AddRelationship.svelte +4 -2
- package/dist/components/overlay/Details.svelte +23 -21
- package/dist/components/overlay/FloatingPanel.svelte +47 -5
- package/dist/components/overlay/FloatingPanel.svelte.d.ts +1 -0
- package/dist/components/overlay/LiveUpdatesBanner.svelte +1 -0
- package/dist/components/overlay/Logs.svelte +4 -2
- package/dist/components/overlay/Popover.svelte +3 -2
- package/dist/components/overlay/RefreshRate.svelte +4 -2
- package/dist/components/overlay/dashboard/Button.svelte +2 -1
- package/dist/components/overlay/dashboard/Button.svelte.d.ts +1 -1
- package/dist/components/overlay/dashboard/Dashboard.svelte +3 -1
- package/dist/components/overlay/left-pane/Drawer.svelte +3 -2
- package/dist/components/overlay/left-pane/Tree.svelte +27 -38
- package/dist/components/overlay/left-pane/TreeContainer.svelte +17 -47
- package/dist/components/overlay/left-pane/TreeContainer.svelte.d.ts +1 -1
- package/dist/components/overlay/settings/Settings.svelte +37 -10
- package/dist/components/overlay/settings/Tabs.svelte +2 -1
- package/dist/components/overlay/widgets/ArmPositions.svelte +3 -2
- package/dist/components/overlay/widgets/Camera.svelte +6 -5
- package/dist/components/weblab/WeblabActive.svelte +2 -1
- package/dist/components/xr/ArmTeleop.svelte +7 -6
- package/dist/components/xr/BentPlaneGeometry.svelte +3 -2
- package/dist/components/xr/CameraFeed.svelte +2 -0
- package/dist/components/xr/Controllers.svelte +5 -3
- package/dist/components/xr/Draggable.svelte +4 -3
- package/dist/components/xr/HandCollider.svelte +2 -1
- package/dist/components/xr/JointLimitsWidget.svelte +1 -0
- package/dist/components/xr/OriginMarker.svelte +2 -1
- package/dist/components/xr/PointDistance.svelte +3 -2
- package/dist/components/xr/XR.svelte +8 -6
- package/dist/components/xr/XRConfigPanel.svelte +4 -3
- package/dist/components/xr/XRControllerSettings.svelte +2 -1
- package/dist/components/xr/XRToast.svelte +4 -3
- package/dist/ecs/traits.d.ts +1 -1
- package/dist/ecs/traits.js +1 -1
- package/dist/ecs/useQuery.svelte.js +1 -1
- package/dist/frame.js +1 -1
- package/dist/hooks/use3DModels.svelte.js +3 -3
- package/dist/hooks/useConfigFrames.svelte.js +3 -3
- package/dist/hooks/useDrawAPI.svelte.js +9 -9
- package/dist/hooks/useFramelessComponents.svelte.js +1 -1
- package/dist/hooks/useFrames.svelte.js +7 -7
- package/dist/hooks/useGeometries.svelte.js +8 -8
- package/dist/hooks/useMouseRaycaster.svelte.d.ts +1 -1
- package/dist/hooks/useMouseRaycaster.svelte.js +1 -1
- package/dist/hooks/usePartConfig.svelte.d.ts +1 -1
- package/dist/hooks/usePartConfig.svelte.js +3 -3
- package/dist/hooks/usePointcloudObjects.svelte.js +6 -6
- package/dist/hooks/usePointclouds.svelte.js +5 -5
- package/dist/hooks/usePose.svelte.js +7 -7
- package/dist/hooks/useSelection.svelte.d.ts +1 -1
- package/dist/hooks/useWeblabs.svelte.d.ts +1 -0
- package/dist/hooks/useWeblabs.svelte.js +15 -3
- package/dist/hooks/useWorldState.svelte.js +8 -8
- package/dist/plugins/bvh.svelte.js +2 -2
- package/dist/snapshot.d.ts +2 -2
- package/dist/snapshot.js +4 -4
- package/dist/three/BatchedArrow.d.ts +1 -1
- package/dist/three/BatchedArrow.js +1 -1
- package/dist/three/InstancedArrows/InstancedArrows.d.ts +1 -1
- package/dist/three/InstancedArrows/InstancedArrows.js +3 -3
- package/dist/three/InstancedArrows/box.js +1 -1
- package/dist/three/InstancedArrows/geometry.js +1 -1
- package/dist/three/InstancedArrows/raycast.d.ts +1 -1
- package/dist/three/InstancedArrows/raycast.js +1 -1
- package/dist/three/OBBHelper.d.ts +2 -3
- package/dist/three/OBBHelper.js +64 -43
- package/dist/three/OrientationVector.js +1 -1
- package/dist/transform.js +1 -1
- package/package.json +7 -6
- package/dist/components/overlay/left-pane/AddFrames.svelte +0 -30
- package/dist/components/overlay/left-pane/AddFrames.svelte.d.ts +0 -18
- package/dist/hooks/__tests__/fixtures/ResizableTestWrapper.svelte +0 -41
- package/dist/hooks/__tests__/fixtures/ResizableTestWrapper.svelte.d.ts +0 -6
- package/dist/hooks/useResizable.svelte.d.ts +0 -12
- package/dist/hooks/useResizable.svelte.js +0 -46
package/dist/three/OBBHelper.js
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Box3, BoxGeometry, BufferGeometry, EdgesGeometry, Matrix4, Mesh, Object3D, Quaternion, Vector3, } from 'three';
|
|
2
2
|
import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
|
|
3
3
|
import { LineSegments2 } from 'three/examples/jsm/lines/LineSegments2.js';
|
|
4
4
|
import { LineSegmentsGeometry } from 'three/examples/jsm/lines/LineSegmentsGeometry.js';
|
|
5
|
+
const box = new Box3();
|
|
6
|
+
const childBox = new Box3();
|
|
7
|
+
const inverseRootMatrixWorld = new Matrix4();
|
|
8
|
+
const rootMatrixWorld = new Matrix4();
|
|
9
|
+
const relativeMatrix = new Matrix4();
|
|
10
|
+
const scaleMatrix = new Matrix4();
|
|
5
11
|
const center = new Vector3();
|
|
6
|
-
const half = new Vector3();
|
|
7
12
|
const size = new Vector3();
|
|
13
|
+
const basis = new Matrix4();
|
|
8
14
|
const quaternion = new Quaternion();
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
const corners = [
|
|
16
|
+
new Vector3(),
|
|
17
|
+
new Vector3(),
|
|
18
|
+
new Vector3(),
|
|
19
|
+
new Vector3(),
|
|
20
|
+
new Vector3(),
|
|
21
|
+
new Vector3(),
|
|
22
|
+
new Vector3(),
|
|
23
|
+
new Vector3(),
|
|
24
|
+
];
|
|
25
|
+
const expandBoxByTransformedBox = (box, childBox, matrix) => {
|
|
26
|
+
const min = childBox.min;
|
|
27
|
+
const max = childBox.max;
|
|
28
|
+
corners[0].set(min.x, min.y, min.z).applyMatrix4(matrix);
|
|
29
|
+
corners[1].set(min.x, min.y, max.z).applyMatrix4(matrix);
|
|
30
|
+
corners[2].set(min.x, max.y, min.z).applyMatrix4(matrix);
|
|
31
|
+
corners[3].set(min.x, max.y, max.z).applyMatrix4(matrix);
|
|
32
|
+
corners[4].set(max.x, min.y, min.z).applyMatrix4(matrix);
|
|
33
|
+
corners[5].set(max.x, min.y, max.z).applyMatrix4(matrix);
|
|
34
|
+
corners[6].set(max.x, max.y, min.z).applyMatrix4(matrix);
|
|
35
|
+
corners[7].set(max.x, max.y, max.z).applyMatrix4(matrix);
|
|
36
|
+
for (const corner of corners) {
|
|
37
|
+
box.expandByPoint(corner);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
12
40
|
export class OBBHelper extends LineSegments2 {
|
|
13
41
|
constructor(color = 0x000000, linewidth = 2) {
|
|
14
42
|
const edges = new EdgesGeometry(new BoxGeometry());
|
|
@@ -27,52 +55,45 @@ export class OBBHelper extends LineSegments2 {
|
|
|
27
55
|
this.renderOrder = 999;
|
|
28
56
|
}
|
|
29
57
|
setFromOBB(obb) {
|
|
30
|
-
|
|
31
|
-
const basis = new Matrix4().setFromMatrix3(obb.rotation);
|
|
58
|
+
basis.setFromMatrix3(obb.rotation);
|
|
32
59
|
quaternion.setFromRotationMatrix(basis);
|
|
33
|
-
// scale = full size
|
|
34
60
|
size.copy(obb.halfSize).multiplyScalar(2);
|
|
35
|
-
// compose
|
|
36
61
|
this.matrix.compose(obb.center, quaternion, size);
|
|
37
|
-
this.matrixWorld.copy(this.matrix);
|
|
62
|
+
this.matrixWorld.copy(this.matrix);
|
|
38
63
|
return this;
|
|
39
64
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
setFromObject(root) {
|
|
66
|
+
root.updateWorldMatrix(true, true);
|
|
67
|
+
rootMatrixWorld.copy(root.matrixWorld);
|
|
68
|
+
inverseRootMatrixWorld.copy(rootMatrixWorld).invert();
|
|
69
|
+
box.makeEmpty();
|
|
70
|
+
root.traverse((child) => {
|
|
71
|
+
const mesh = child;
|
|
72
|
+
const geometry = mesh.geometry;
|
|
73
|
+
if (!geometry)
|
|
74
|
+
return;
|
|
75
|
+
if (!geometry.boundingBox) {
|
|
76
|
+
geometry.computeBoundingBox();
|
|
77
|
+
}
|
|
78
|
+
if (!geometry.boundingBox)
|
|
79
|
+
return;
|
|
80
|
+
// Transform this mesh's local bounding box into root-local space
|
|
81
|
+
relativeMatrix.multiplyMatrices(inverseRootMatrixWorld, mesh.matrixWorld);
|
|
82
|
+
childBox.copy(geometry.boundingBox);
|
|
83
|
+
expandBoxByTransformedBox(box, childBox, relativeMatrix);
|
|
84
|
+
});
|
|
85
|
+
if (box.isEmpty()) {
|
|
56
86
|
console.warn('[OBBHelper] No geometry found on object to compute OBB.');
|
|
57
87
|
return this;
|
|
58
88
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
object.getWorldQuaternion(quaternion);
|
|
68
|
-
object.getWorldScale(scale);
|
|
69
|
-
// non-uniform scale supported (no shear): enlarge halfSize by |scale|
|
|
70
|
-
half.copy(size).multiply(absScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z)));
|
|
71
|
-
worldCenter.copy(center);
|
|
72
|
-
object.localToWorld(worldCenter);
|
|
73
|
-
// compose transform (unit box -> oriented box)
|
|
74
|
-
const fullSize = half.multiplyScalar(2);
|
|
75
|
-
this.matrix.compose(worldCenter, quaternion, fullSize);
|
|
89
|
+
box.getCenter(center);
|
|
90
|
+
box.getSize(size);
|
|
91
|
+
// Place the helper at the center of the bounding box, in root-local space
|
|
92
|
+
this.matrix.makeTranslation(center.x, center.y, center.z);
|
|
93
|
+
// Then inherit the root's full world transform
|
|
94
|
+
this.matrix.premultiply(rootMatrixWorld);
|
|
95
|
+
// Scale the unit box to the OBB extents in root-local axes
|
|
96
|
+
this.matrix.multiply(scaleMatrix.makeScale(size.x, size.y, size.z));
|
|
76
97
|
this.matrixWorld.copy(this.matrix);
|
|
77
98
|
return this;
|
|
78
99
|
}
|
package/dist/transform.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OrientationVector } from './three/OrientationVector';
|
|
2
1
|
import { Euler, MathUtils, Matrix4, Quaternion, Vector3 } from 'three';
|
|
2
|
+
import { OrientationVector } from './three/OrientationVector';
|
|
3
3
|
const quaternion = new Quaternion();
|
|
4
4
|
const euler = new Euler();
|
|
5
5
|
const ov = new OrientationVector();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viamrobotics/motion-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.1",
|
|
4
4
|
"description": "Motion visualization with Viam",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"@skeletonlabs/skeleton": "3.2.0",
|
|
18
18
|
"@skeletonlabs/skeleton-svelte": "1.5.1",
|
|
19
19
|
"@sveltejs/adapter-static": "3.0.9",
|
|
20
|
-
"@sveltejs/kit": "2.
|
|
21
|
-
"@sveltejs/package": "2.5.
|
|
20
|
+
"@sveltejs/kit": "2.55.0",
|
|
21
|
+
"@sveltejs/package": "2.5.7",
|
|
22
22
|
"@sveltejs/vite-plugin-svelte": "6.1.4",
|
|
23
23
|
"@tailwindcss/forms": "0.5.10",
|
|
24
24
|
"@tailwindcss/vite": "4.1.13",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"esbuild": "^0.27.3",
|
|
52
52
|
"eslint": "10.0.2",
|
|
53
53
|
"eslint-config-prettier": "10.1.8",
|
|
54
|
+
"eslint-plugin-perfectionist": "^5.6.0",
|
|
54
55
|
"eslint-plugin-svelte": "3.15.0",
|
|
55
56
|
"eslint-plugin-unicorn": "^63.0.0",
|
|
56
57
|
"globals": "16.3.0",
|
|
@@ -62,8 +63,8 @@
|
|
|
62
63
|
"prettier-plugin-tailwindcss": "0.6.14",
|
|
63
64
|
"publint": "0.3.12",
|
|
64
65
|
"runed": "0.31.1",
|
|
65
|
-
"svelte": "5.
|
|
66
|
-
"svelte-check": "4.
|
|
66
|
+
"svelte": "5.53.13",
|
|
67
|
+
"svelte-check": "4.4.5",
|
|
67
68
|
"svelte-virtuallists": "1.4.2",
|
|
68
69
|
"tailwindcss": "4.1.13",
|
|
69
70
|
"three": "0.182.0",
|
|
@@ -149,7 +150,7 @@
|
|
|
149
150
|
"preview": "vite preview",
|
|
150
151
|
"check": "svelte-kit sync && pnpm build:workers && svelte-check --tsconfig ./tsconfig.json && pnpm vet",
|
|
151
152
|
"check:watch": "svelte-kit sync && pnpm build:workers && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
152
|
-
"format": "prettier --write .",
|
|
153
|
+
"format": "prettier --write . && eslint . --fix",
|
|
153
154
|
"lint:draw": "golangci-lint run ./draw/...",
|
|
154
155
|
"lint:client": "golangci-lint run ./client/...",
|
|
155
156
|
"lint:prettier": "prettier --check .",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { IconButton } from '@viamrobotics/prime-core'
|
|
3
|
-
import Drawer from './Drawer.svelte'
|
|
4
|
-
import { usePartConfig } from '../../../hooks/usePartConfig.svelte'
|
|
5
|
-
import { useFramelessComponents } from '../../../hooks/useFramelessComponents.svelte'
|
|
6
|
-
|
|
7
|
-
const framelessComponents = useFramelessComponents()
|
|
8
|
-
const partConfig = usePartConfig()
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<Drawer name="Add frames">
|
|
12
|
-
<div class="flex max-h-64 flex-col gap-2 overflow-auto p-3">
|
|
13
|
-
{#if framelessComponents.current.length > 0}
|
|
14
|
-
<ul class="space-y-1">
|
|
15
|
-
{#each framelessComponents.current as component (component)}
|
|
16
|
-
<li class="flex items-center gap-2 text-xs text-gray-700">
|
|
17
|
-
{component}
|
|
18
|
-
<IconButton
|
|
19
|
-
label="Add frame"
|
|
20
|
-
icon="plus"
|
|
21
|
-
onclick={() => partConfig.createFrame(component)}
|
|
22
|
-
/>
|
|
23
|
-
</li>
|
|
24
|
-
{/each}
|
|
25
|
-
</ul>
|
|
26
|
-
{:else}
|
|
27
|
-
No components without frames
|
|
28
|
-
{/if}
|
|
29
|
-
</div>
|
|
30
|
-
</Drawer>
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
-
$$bindings?: Bindings;
|
|
4
|
-
} & Exports;
|
|
5
|
-
(internal: unknown, props: {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const AddFrames: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
-
[evt: string]: CustomEvent<any>;
|
|
16
|
-
}, {}, {}, string>;
|
|
17
|
-
type AddFrames = InstanceType<typeof AddFrames>;
|
|
18
|
-
export default AddFrames;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { useResizable } from '../../useResizable.svelte'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
name: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
let { name }: Props = $props()
|
|
9
|
-
|
|
10
|
-
const resizable = useResizable(() => name)
|
|
11
|
-
|
|
12
|
-
let container = $state<HTMLDivElement>()
|
|
13
|
-
|
|
14
|
-
$effect(() => {
|
|
15
|
-
if (container) {
|
|
16
|
-
resizable.observe(container)
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
<div data-testid="status">
|
|
22
|
-
{#if resizable.isLoaded}
|
|
23
|
-
loaded
|
|
24
|
-
{:else}
|
|
25
|
-
loading
|
|
26
|
-
{/if}
|
|
27
|
-
</div>
|
|
28
|
-
|
|
29
|
-
<div data-testid="dimensions">
|
|
30
|
-
{resizable.current.width}x{resizable.current.height}
|
|
31
|
-
</div>
|
|
32
|
-
|
|
33
|
-
<div
|
|
34
|
-
bind:this={container}
|
|
35
|
-
data-testid="container"
|
|
36
|
-
class="resize"
|
|
37
|
-
style:width={`${resizable.current.width}px`}
|
|
38
|
-
style:height={`${resizable.current.height}px`}
|
|
39
|
-
>
|
|
40
|
-
Resizable container
|
|
41
|
-
</div>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
interface Dimensions {
|
|
2
|
-
width: number;
|
|
3
|
-
height: number;
|
|
4
|
-
}
|
|
5
|
-
interface Context {
|
|
6
|
-
readonly current: Dimensions;
|
|
7
|
-
readonly isLoaded: boolean;
|
|
8
|
-
observe: (target: HTMLElement) => void;
|
|
9
|
-
}
|
|
10
|
-
export declare const MIN_DIMENSIONS: Dimensions;
|
|
11
|
-
export declare const useResizable: (name: () => string, defaultDimensions?: () => Dimensions) => Context;
|
|
12
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { get, set } from 'idb-keyval';
|
|
2
|
-
export const MIN_DIMENSIONS = { width: 240, height: 320 };
|
|
3
|
-
export const useResizable = (name, defaultDimensions) => {
|
|
4
|
-
const key = $derived(`${name()}-resizable`);
|
|
5
|
-
let dimensions = $derived(defaultDimensions?.() ?? MIN_DIMENSIONS);
|
|
6
|
-
let loaded = $state(false);
|
|
7
|
-
let observer;
|
|
8
|
-
$effect(() => {
|
|
9
|
-
get(key).then((saved) => {
|
|
10
|
-
if (saved) {
|
|
11
|
-
dimensions = saved;
|
|
12
|
-
}
|
|
13
|
-
loaded = true;
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
const observe = (target) => {
|
|
17
|
-
// Disconnect previous observer if any
|
|
18
|
-
observer?.disconnect();
|
|
19
|
-
observer = new ResizeObserver((entries) => {
|
|
20
|
-
const entry = entries[0];
|
|
21
|
-
if (!entry)
|
|
22
|
-
return;
|
|
23
|
-
const next = {
|
|
24
|
-
width: Math.max(entry.contentRect.width, MIN_DIMENSIONS.width),
|
|
25
|
-
height: Math.max(entry.contentRect.height, MIN_DIMENSIONS.height),
|
|
26
|
-
};
|
|
27
|
-
set(key, next);
|
|
28
|
-
});
|
|
29
|
-
observer.observe(target);
|
|
30
|
-
};
|
|
31
|
-
const disconnect = () => {
|
|
32
|
-
observer?.disconnect();
|
|
33
|
-
};
|
|
34
|
-
$effect(() => {
|
|
35
|
-
return disconnect;
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
get current() {
|
|
39
|
-
return dimensions;
|
|
40
|
-
},
|
|
41
|
-
get isLoaded() {
|
|
42
|
-
return loaded;
|
|
43
|
-
},
|
|
44
|
-
observe,
|
|
45
|
-
};
|
|
46
|
-
};
|