@viamrobotics/motion-tools 1.13.1 → 1.15.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/dist/FrameConfigUpdater.svelte.d.ts +2 -2
- package/dist/HoverUpdater.svelte.d.ts +1 -1
- package/dist/attribute.js +11 -3
- package/dist/buffer.d.ts +56 -7
- package/dist/buffer.js +70 -12
- package/dist/color.d.ts +1 -1
- package/dist/color.js +2 -2
- package/dist/components/App.svelte +25 -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 +9 -7
- package/dist/components/Entities/Frame.svelte +48 -48
- package/dist/components/Entities/Frame.svelte.d.ts +3 -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 +45 -173
- package/dist/components/Entities/Geometry.svelte.d.ts +5 -14
- package/dist/components/Entities/Line.svelte +69 -19
- 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 +133 -0
- package/dist/components/Entities/Mesh.svelte.d.ts +4 -0
- 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 +7 -3
- 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/AddRelationship.svelte +4 -2
- package/dist/components/overlay/Details.svelte +21 -19
- package/dist/components/overlay/FloatingPanel.svelte +40 -3
- 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/AddFrames.svelte +4 -2
- package/dist/components/overlay/left-pane/Drawer.svelte +3 -2
- package/dist/components/overlay/left-pane/Tree.svelte +6 -12
- package/dist/components/overlay/left-pane/TreeContainer.svelte +33 -50
- package/dist/components/overlay/left-pane/TreeContainer.svelte.d.ts +1 -1
- package/dist/components/overlay/left-pane/buildTree.js +15 -0
- 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 +3 -20
- package/dist/ecs/traits.js +34 -7
- package/dist/ecs/useQuery.svelte.js +1 -1
- package/dist/frame.js +1 -1
- package/dist/hooks/use3DModels.svelte.js +4 -6
- 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 +18 -19
- package/dist/hooks/useGeometries.svelte.js +66 -43
- 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 +108 -63
- package/dist/hooks/usePointclouds.svelte.js +53 -33
- 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 +31 -31
- package/dist/metadata.d.ts +22 -0
- package/dist/metadata.js +66 -0
- package/dist/plugins/bvh.svelte.js +2 -2
- package/dist/snapshot.d.ts +22 -2
- package/dist/snapshot.js +67 -25
- 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 +3 -2
- package/dist/three/OBBHelper.js +17 -5
- package/dist/three/OrientationVector.js +1 -1
- package/dist/transform.js +1 -1
- package/package.json +3 -2
- package/dist/WorldObject.svelte.d.ts +0 -27
- package/dist/WorldObject.svelte.js +0 -127
- 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,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BoxGeometry, BufferGeometry, EdgesGeometry, Matrix3, Matrix4, Mesh, Object3D, Quaternion, Vector3, } from 'three';
|
|
2
|
+
import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
|
|
3
|
+
import { LineSegments2 } from 'three/examples/jsm/lines/LineSegments2.js';
|
|
4
|
+
import { LineSegmentsGeometry } from 'three/examples/jsm/lines/LineSegmentsGeometry.js';
|
|
2
5
|
const center = new Vector3();
|
|
3
6
|
const half = new Vector3();
|
|
4
7
|
const size = new Vector3();
|
|
@@ -6,13 +9,22 @@ const quaternion = new Quaternion();
|
|
|
6
9
|
const scale = new Vector3();
|
|
7
10
|
const absScale = new Vector3();
|
|
8
11
|
const worldCenter = new Vector3();
|
|
9
|
-
export class OBBHelper extends
|
|
10
|
-
constructor(color = 0x000000, linewidth =
|
|
11
|
-
const
|
|
12
|
-
const
|
|
12
|
+
export class OBBHelper extends LineSegments2 {
|
|
13
|
+
constructor(color = 0x000000, linewidth = 2) {
|
|
14
|
+
const edges = new EdgesGeometry(new BoxGeometry());
|
|
15
|
+
const geometry = new LineSegmentsGeometry();
|
|
16
|
+
geometry.setPositions(edges.getAttribute('position').array);
|
|
17
|
+
const material = new LineMaterial({
|
|
18
|
+
color,
|
|
19
|
+
linewidth,
|
|
20
|
+
depthTest: false,
|
|
21
|
+
depthWrite: false,
|
|
22
|
+
transparent: true,
|
|
23
|
+
});
|
|
13
24
|
super(geometry, material);
|
|
14
25
|
this.matrixAutoUpdate = false;
|
|
15
26
|
this.frustumCulled = false;
|
|
27
|
+
this.renderOrder = 999;
|
|
16
28
|
}
|
|
17
29
|
setFromOBB(obb) {
|
|
18
30
|
// position/rotation
|
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.0",
|
|
4
4
|
"description": "Motion visualization with Viam",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -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",
|
|
@@ -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,27 +0,0 @@
|
|
|
1
|
-
import type { PlainMessage, Struct } from '@viamrobotics/sdk';
|
|
2
|
-
import { BatchedMesh, Color, Vector3 } from 'three';
|
|
3
|
-
import type { GLTF } from 'three/examples/jsm/Addons.js';
|
|
4
|
-
import type { OBB } from 'three/addons/math/OBB.js';
|
|
5
|
-
declare enum SupportedShapes {
|
|
6
|
-
points = "points",
|
|
7
|
-
line = "line",
|
|
8
|
-
arrow = "arrow"
|
|
9
|
-
}
|
|
10
|
-
type Metadata = {
|
|
11
|
-
colors?: Float32Array<ArrayBufferLike>;
|
|
12
|
-
color?: Color;
|
|
13
|
-
opacity?: number;
|
|
14
|
-
gltf?: GLTF;
|
|
15
|
-
points?: Vector3[];
|
|
16
|
-
pointSize?: number;
|
|
17
|
-
lineWidth?: number;
|
|
18
|
-
lineDotColor?: Color;
|
|
19
|
-
batched?: {
|
|
20
|
-
id: number;
|
|
21
|
-
object: BatchedMesh;
|
|
22
|
-
};
|
|
23
|
-
shape?: SupportedShapes;
|
|
24
|
-
getBoundingBoxAt?: (box: OBB) => void;
|
|
25
|
-
};
|
|
26
|
-
export declare const parseMetadata: (fields?: PlainMessage<Struct>["fields"]) => Metadata;
|
|
27
|
-
export {};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { BatchedMesh, Color, Vector3 } from 'three';
|
|
2
|
-
import { isColorRepresentation, isRGB, parseColor, parseOpacity, parseRGB } from './color';
|
|
3
|
-
var SupportedShapes;
|
|
4
|
-
(function (SupportedShapes) {
|
|
5
|
-
SupportedShapes["points"] = "points";
|
|
6
|
-
SupportedShapes["line"] = "line";
|
|
7
|
-
SupportedShapes["arrow"] = "arrow";
|
|
8
|
-
})(SupportedShapes || (SupportedShapes = {}));
|
|
9
|
-
const METADATA_KEYS = [
|
|
10
|
-
'colors',
|
|
11
|
-
'color',
|
|
12
|
-
'opacity',
|
|
13
|
-
'gltf',
|
|
14
|
-
'points',
|
|
15
|
-
'pointSize',
|
|
16
|
-
'lineWidth',
|
|
17
|
-
'lineDotColor',
|
|
18
|
-
'batched',
|
|
19
|
-
'shape',
|
|
20
|
-
];
|
|
21
|
-
const isMetadataKey = (key) => {
|
|
22
|
-
return METADATA_KEYS.includes(key);
|
|
23
|
-
};
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
const unwrapValue = (value) => {
|
|
26
|
-
if (!value?.kind)
|
|
27
|
-
return value;
|
|
28
|
-
switch (value.kind.case) {
|
|
29
|
-
case 'numberValue':
|
|
30
|
-
case 'stringValue':
|
|
31
|
-
case 'boolValue': {
|
|
32
|
-
return value.kind.value;
|
|
33
|
-
}
|
|
34
|
-
case 'structValue': {
|
|
35
|
-
const result = {};
|
|
36
|
-
for (const [key, val] of Object.entries(value.kind.value.fields || {})) {
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
-
result[key] = unwrapValue(val);
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
case 'listValue': {
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
return value.kind.value.values?.map((value) => unwrapValue(value)) || [];
|
|
45
|
-
}
|
|
46
|
-
case 'nullValue': {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
default: {
|
|
50
|
-
return value.kind.value;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
export const parseMetadata = (fields = {}) => {
|
|
55
|
-
const json = {};
|
|
56
|
-
for (const [k, v] of Object.entries(fields)) {
|
|
57
|
-
if (!isMetadataKey(k))
|
|
58
|
-
continue;
|
|
59
|
-
const unwrappedValue = unwrapValue(v);
|
|
60
|
-
switch (k) {
|
|
61
|
-
case 'color':
|
|
62
|
-
case 'lineDotColor': {
|
|
63
|
-
json[k] = readColor(unwrappedValue);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case 'colors': {
|
|
67
|
-
let colorBytes;
|
|
68
|
-
// Handle base64-encoded string (from protobuf Struct)
|
|
69
|
-
if (typeof unwrappedValue === 'string') {
|
|
70
|
-
const binary = atob(unwrappedValue);
|
|
71
|
-
colorBytes = new Uint8Array(binary.length);
|
|
72
|
-
for (let i = 0; i < binary.length; i++) {
|
|
73
|
-
colorBytes[i] = binary.charCodeAt(i);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else if (Array.isArray(unwrappedValue)) {
|
|
77
|
-
colorBytes = unwrappedValue;
|
|
78
|
-
}
|
|
79
|
-
if (colorBytes && colorBytes.length >= 3) {
|
|
80
|
-
const r = (colorBytes[0] ?? 0) / 255;
|
|
81
|
-
const g = (colorBytes[1] ?? 0) / 255;
|
|
82
|
-
const b = (colorBytes[2] ?? 0) / 255;
|
|
83
|
-
const a = colorBytes.length >= 4 ? (colorBytes[3] ?? 255) / 255 : 1;
|
|
84
|
-
json.color = new Color(r, g, b);
|
|
85
|
-
json.opacity = a;
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case 'opacity': {
|
|
90
|
-
json[k] = parseOpacity(unwrappedValue);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
case 'gltf': {
|
|
94
|
-
json[k] = unwrappedValue;
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
case 'points': {
|
|
98
|
-
json[k] = unwrappedValue;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
case 'pointSize': {
|
|
102
|
-
json[k] = unwrappedValue;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case 'lineWidth': {
|
|
106
|
-
json[k] = unwrappedValue;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case 'batched': {
|
|
110
|
-
json[k] = unwrappedValue;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
case 'shape': {
|
|
114
|
-
json[k] = unwrappedValue;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return json;
|
|
120
|
-
};
|
|
121
|
-
const readColor = (color) => {
|
|
122
|
-
if (isColorRepresentation(color))
|
|
123
|
-
return parseColor(color);
|
|
124
|
-
if (isRGB(color))
|
|
125
|
-
return parseRGB(color);
|
|
126
|
-
return new Color('black');
|
|
127
|
-
};
|
|
@@ -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
|
-
};
|