@viamrobotics/test-widgets 0.1.1 → 0.1.2

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.
Files changed (26) hide show
  1. package/dist/components/index.d.ts +0 -2
  2. package/dist/components/index.js +0 -2
  3. package/dist/components/widgets/do-command/do-command.svelte +14 -4
  4. package/dist/components/widgets/switch/position-view.svelte +6 -6
  5. package/dist/components/widgets/vision-service/context.svelte.js +6 -6
  6. package/package.json +1 -1
  7. package/dist/components/image-annotations/annotation-edit-utils.d.ts +0 -21
  8. package/dist/components/image-annotations/annotation-edit-utils.js +0 -183
  9. package/dist/components/image-annotations/bounding-box-labeler.svelte +0 -521
  10. package/dist/components/image-annotations/bounding-box-labeler.svelte.d.ts +0 -51
  11. package/dist/components/image-annotations/bounding-box-types.d.ts +0 -29
  12. package/dist/components/image-annotations/bounding-box-types.js +0 -17
  13. package/dist/components/image-annotations/bounding-box.svelte +0 -230
  14. package/dist/components/image-annotations/bounding-box.svelte.d.ts +0 -44
  15. package/dist/components/image-annotations/get-image-size.d.ts +0 -7
  16. package/dist/components/image-annotations/get-image-size.js +0 -29
  17. package/dist/components/image-annotations/labeler-constants.d.ts +0 -4
  18. package/dist/components/image-annotations/labeler-constants.js +0 -4
  19. package/dist/components/image-annotations/resize-corner.svelte +0 -47
  20. package/dist/components/image-annotations/resize-corner.svelte.d.ts +0 -9
  21. package/dist/components/image-annotations/resize-edge.svelte +0 -51
  22. package/dist/components/image-annotations/resize-edge.svelte.d.ts +0 -9
  23. package/dist/components/image-annotations/resize-handle-props.d.ts +0 -60
  24. package/dist/components/image-annotations/resize-handle-props.js +0 -66
  25. package/dist/components/image-annotations/resize-handles.svelte +0 -53
  26. package/dist/components/image-annotations/resize-handles.svelte.d.ts +0 -8
@@ -53,5 +53,3 @@ export { default as VisionServiceWidget } from './widgets/vision-service/vision-
53
53
  export { default as RefetchController } from './refetch-controller.svelte';
54
54
  export { NavigationMap, NavigationTab, type NavigationTabType, type Shapes, type CapsuleGeometry, type SphereGeometry, type BoxGeometry, type Geometry, type Obstacle, type Path, } from './navigation-map';
55
55
  export { MapLibre, MapLibreMarker, CenterControls, FollowControls, NavigationControls, SatelliteControls, DirectionalMarker, LngLatInput, MapProviders, type MapProvider, GeoPose, Waypoint, useMapLibre, useMapLibreEvent, useMapLibreThreeRaycast, useMapLibreThreeRenderer, lngLatToMercator, mercatorToCartesian, lngLatToCartesian, cartesianToMercator, cartesianToLngLat, } from './maplibre';
56
- export { default as BoundingBoxLabeler } from './image-annotations/bounding-box-labeler.svelte';
57
- export { ZOOM_MIN, ZOOM_MAX, INVERT_Y_FLOAT_DISTANCE, INVERT_X_FLOAT_DISTANCE, } from './image-annotations/labeler-constants';
@@ -52,5 +52,3 @@ export { default as VisionServiceWidget } from './widgets/vision-service/vision-
52
52
  export { default as RefetchController } from './refetch-controller.svelte';
53
53
  export { NavigationMap, NavigationTab, } from './navigation-map';
54
54
  export { MapLibre, MapLibreMarker, CenterControls, FollowControls, NavigationControls, SatelliteControls, DirectionalMarker, LngLatInput, MapProviders, GeoPose, Waypoint, useMapLibre, useMapLibreEvent, useMapLibreThreeRaycast, useMapLibreThreeRenderer, lngLatToMercator, mercatorToCartesian, lngLatToCartesian, cartesianToMercator, cartesianToLngLat, } from './maplibre';
55
- export { default as BoundingBoxLabeler } from './image-annotations/bounding-box-labeler.svelte';
56
- export { ZOOM_MIN, ZOOM_MAX, INVERT_Y_FLOAT_DISTANCE, INVERT_X_FLOAT_DISTANCE, } from './image-annotations/labeler-constants';
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { Button } from '@viamrobotics/prime-core'
2
+ import { Button, Progress } from '@viamrobotics/prime-core'
3
3
  import { JsonEditor } from '@viamrobotics/prime-editor'
4
4
  import { MLModelClient, ResourceName, Struct } from '@viamrobotics/sdk'
5
5
  import { createResourceClient, createResourceMutation } from '@viamrobotics/svelte-sdk'
@@ -31,7 +31,7 @@
31
31
 
32
32
  const doCommandMutation = $derived(createResourceMutation(client, 'doCommand'))
33
33
 
34
- let lastErr = $state<Error>()
34
+ let lastErr = $state<Error | null>()
35
35
 
36
36
  const uid = $props.id()
37
37
 
@@ -41,10 +41,12 @@
41
41
 
42
42
  const execute = async () => {
43
43
  try {
44
+ lastErr = null
45
+ output = ''
44
46
  const parsedInput = Struct.fromJsonString(input.current ?? '{}')
45
47
  const data = await doCommandMutation.mutateAsync([parsedInput])
46
48
  output = JSON.stringify(data, null, 2)
47
- lastErr = undefined
49
+ lastErr = null
48
50
  } catch (error) {
49
51
  lastErr = error as Error
50
52
  }
@@ -72,7 +74,15 @@
72
74
  >
73
75
 
74
76
  <div class="flex w-[45%] flex-col gap-2 border-l py-2">
75
- <span class="text-gray-9 px-4 text-sm font-medium">Output</span>
77
+ <div class="flex flex-row items-center">
78
+ <span class="text-gray-9 px-4 text-sm font-medium">Output</span>
79
+ {#if doCommandMutation.isPending}
80
+ <Progress
81
+ size="medium"
82
+ variant="dark"
83
+ />
84
+ {/if}
85
+ </div>
76
86
  {#if !lastErr}
77
87
  <JsonEditor
78
88
  label="output"
@@ -27,17 +27,17 @@
27
27
  refetchInterval: 500,
28
28
  })
29
29
 
30
- // TODO: switch to using optimistic update mutation client from svelte SDK when available APP-15498
31
- let currentPosition = $derived(positionQuery.data ?? 0)
32
-
33
30
  const numPositionsQuery = createResourceQuery(client, 'getNumberOfPositions', {
34
31
  refetchInterval: 500,
35
32
  })
36
33
 
37
- const setPositionMutation = createResourceMutation(client, 'setPosition')
34
+ const setPositionMutation = createResourceMutation(
35
+ client,
36
+ 'setPosition',
37
+ () => positionQuery.queryKey
38
+ )
38
39
 
39
40
  const onSelect = async (position: number) => {
40
- currentPosition = position
41
41
  await setPositionMutation.mutateAsync([position])
42
42
  await positionQuery.refetch()
43
43
  }
@@ -51,7 +51,7 @@
51
51
  <Position
52
52
  numPositions={numPositionsQuery.data[0]}
53
53
  labels={numPositionsQuery.data[1]}
54
- {currentPosition}
54
+ currentPosition={positionQuery.data}
55
55
  {onSelect}
56
56
  lastError={setPositionMutation.error}
57
57
  />
@@ -6,12 +6,12 @@ import { labelToColor } from "./color.js";
6
6
  * Adds ids to detections.
7
7
  */
8
8
  export const addIdsToDetections = (detections) => {
9
- for (const detection of detections) {
10
- detection.id = MathUtils.generateUUID();
11
- detection.confidence = Math.round(detection.confidence * 100);
12
- detection.color = labelToColor(detection.className);
13
- }
14
- return detections;
9
+ return detections.map((detection) => ({
10
+ ...detection,
11
+ id: MathUtils.generateUUID(),
12
+ confidence: Math.round(detection.confidence * 100),
13
+ color: labelToColor(detection.className),
14
+ }));
15
15
  };
16
16
  export const DETECTIONS_CONTEXT_KEY = Symbol('detections-context');
17
17
  const categorize = (list) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/test-widgets",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,21 +0,0 @@
1
- import type { Size } from './get-image-size';
2
- import { type BoundingBox, type BoundingCoords, type Coordinates, ResizeHandleLocation } from './bounding-box-types';
3
- export declare const getBoundingRect: (original: BoundingBox, dragDistance: Coordinates | undefined, containerWidth: number, containerHeight: number, corner?: ResizeHandleLocation) => BoundingCoords;
4
- export declare const shouldDisplayBoxFill: (annotationID: string, inEditMode: boolean, focusedID: string | undefined, editTargetID: string | undefined, hoveredAnnotations: Record<string, boolean>) => boolean;
5
- export declare const createNormalizedTempBox: (label: string, size: Size, firstPoint: Coordinates, finalPoint: Coordinates) => {
6
- xMinNormalized: number;
7
- xMaxNormalized: number;
8
- yMinNormalized: number;
9
- yMaxNormalized: number;
10
- label: string;
11
- id: string;
12
- } | undefined;
13
- export declare const getModifyKeyForOS: () => "metaKey" | "ctrlKey";
14
- export declare const calculatePastedBox: (mousePosition: Coordinates, copyTarget: BoundingBox, containerWidth: number, containerHeight: number) => {
15
- id: string;
16
- label: string;
17
- xMinNormalized: number;
18
- xMaxNormalized: number;
19
- yMinNormalized: number;
20
- yMaxNormalized: number;
21
- };
@@ -1,183 +0,0 @@
1
- import { BoxModifier, ResizeHandleLocation, } from './bounding-box-types';
2
- export const getBoundingRect = (original, dragDistance, containerWidth, containerHeight, corner) => {
3
- let transformation = BoxModifier.Scaled;
4
- if (dragDistance) {
5
- transformation = corner ? BoxModifier.Resized : BoxModifier.Translated;
6
- }
7
- // scale annotation size to container
8
- const scaledCopy = { ...original };
9
- scaledCopy.xMinNormalized *= containerWidth;
10
- scaledCopy.xMaxNormalized *= containerWidth;
11
- scaledCopy.yMinNormalized *= containerHeight;
12
- scaledCopy.yMaxNormalized *= containerHeight;
13
- if (transformation === BoxModifier.Scaled || !dragDistance) {
14
- return scaledCopy;
15
- }
16
- // apply transformation
17
- const unboundedRect = transformation === BoxModifier.Resized && corner
18
- ? getResizedRect(scaledCopy, dragDistance, corner)
19
- : getTranslatedRect(scaledCopy, dragDistance, containerWidth, containerHeight);
20
- // ensure transformation does not exceed boundaries of container
21
- return {
22
- xMinNormalized: Math.max(unboundedRect.xMinNormalized, 0),
23
- xMaxNormalized: Math.min(unboundedRect.xMaxNormalized, containerWidth),
24
- yMinNormalized: Math.max(unboundedRect.yMinNormalized, 0),
25
- yMaxNormalized: Math.min(unboundedRect.yMaxNormalized, containerHeight),
26
- };
27
- };
28
- const getTranslatedRect = (original, dragDistance, containerWidth, containerHeight) => {
29
- const modifiedRect = {
30
- xMinNormalized: original.xMinNormalized + dragDistance.x,
31
- xMaxNormalized: original.xMaxNormalized + dragDistance.x,
32
- yMinNormalized: original.yMinNormalized + dragDistance.y,
33
- yMaxNormalized: original.yMaxNormalized + dragDistance.y,
34
- };
35
- // maintains box size if user attempts to drag a box beyond the bounds of the image
36
- if (modifiedRect.xMinNormalized <= 0) {
37
- modifiedRect.xMaxNormalized -= modifiedRect.xMinNormalized;
38
- modifiedRect.xMinNormalized = 0;
39
- }
40
- if (modifiedRect.yMinNormalized <= 0) {
41
- modifiedRect.yMaxNormalized -= modifiedRect.yMinNormalized;
42
- modifiedRect.yMinNormalized = 0;
43
- }
44
- if (modifiedRect.xMaxNormalized >= containerWidth) {
45
- modifiedRect.xMinNormalized =
46
- containerWidth - (modifiedRect.xMaxNormalized - modifiedRect.xMinNormalized);
47
- modifiedRect.xMaxNormalized = containerWidth;
48
- }
49
- if (modifiedRect.yMaxNormalized >= containerHeight) {
50
- modifiedRect.yMinNormalized =
51
- containerHeight - (modifiedRect.yMaxNormalized - modifiedRect.yMinNormalized);
52
- modifiedRect.yMaxNormalized = containerHeight;
53
- }
54
- return modifiedRect;
55
- };
56
- const getResizedRect = (original, dragDistance, corner) => {
57
- let variableX = undefined;
58
- let variableY = undefined;
59
- switch (corner) {
60
- case ResizeHandleLocation.T: {
61
- variableY = 'yMinNormalized';
62
- break;
63
- }
64
- case ResizeHandleLocation.R: {
65
- variableX = 'xMaxNormalized';
66
- break;
67
- }
68
- case ResizeHandleLocation.B: {
69
- variableY = 'yMaxNormalized';
70
- break;
71
- }
72
- case ResizeHandleLocation.L: {
73
- variableX = 'xMinNormalized';
74
- break;
75
- }
76
- case ResizeHandleLocation.TL: {
77
- variableX = 'xMinNormalized';
78
- variableY = 'yMinNormalized';
79
- break;
80
- }
81
- case ResizeHandleLocation.TR: {
82
- variableX = 'xMaxNormalized';
83
- variableY = 'yMinNormalized';
84
- break;
85
- }
86
- case ResizeHandleLocation.BL: {
87
- variableX = 'xMinNormalized';
88
- variableY = 'yMaxNormalized';
89
- break;
90
- }
91
- case ResizeHandleLocation.BR: {
92
- variableX = 'xMaxNormalized';
93
- variableY = 'yMaxNormalized';
94
- break;
95
- }
96
- }
97
- const modifiedRect = {
98
- ...original,
99
- };
100
- if (variableX) {
101
- modifiedRect[variableX] = original[variableX] + dragDistance.x;
102
- }
103
- if (variableY) {
104
- modifiedRect[variableY] = original[variableY] + dragDistance.y;
105
- }
106
- if (modifiedRect.xMinNormalized > modifiedRect.xMaxNormalized) {
107
- const temp = modifiedRect.xMaxNormalized;
108
- modifiedRect.xMaxNormalized = modifiedRect.xMinNormalized;
109
- modifiedRect.xMinNormalized = temp;
110
- }
111
- if (modifiedRect.yMinNormalized > modifiedRect.yMaxNormalized) {
112
- const temp = modifiedRect.yMaxNormalized;
113
- modifiedRect.yMaxNormalized = modifiedRect.yMinNormalized;
114
- modifiedRect.yMinNormalized = temp;
115
- }
116
- return modifiedRect;
117
- };
118
- export const shouldDisplayBoxFill = (annotationID, inEditMode, focusedID, editTargetID, hoveredAnnotations) => {
119
- return (editTargetID === annotationID ||
120
- ((focusedID ? focusedID === annotationID : Boolean(hoveredAnnotations[annotationID])) &&
121
- !inEditMode));
122
- };
123
- export const createNormalizedTempBox = (label, size, firstPoint, finalPoint) => {
124
- // coordinates start in center, must translate all coordinates by one quadrant (i.e. half the height and width of container)
125
- const xMinNormalized = Math.min(firstPoint.x, finalPoint.x) / size.width;
126
- const xMaxNormalized = Math.max(firstPoint.x, finalPoint.x) / size.width;
127
- const yMinNormalized = Math.min(firstPoint.y, finalPoint.y) / size.height;
128
- const yMaxNormalized = Math.max(firstPoint.y, finalPoint.y) / size.height;
129
- return xMaxNormalized - xMinNormalized > 0.01 && yMaxNormalized - yMinNormalized > 0.01
130
- ? {
131
- // if normalized values exceed bounds of image, lock to edge by setting to min/max value (0 and 1 respectively)
132
- xMinNormalized: Math.max(0, xMinNormalized),
133
- xMaxNormalized: Math.min(1, xMaxNormalized),
134
- yMinNormalized: Math.max(0, yMinNormalized),
135
- yMaxNormalized: Math.min(1, yMaxNormalized),
136
- label,
137
- id: '__NEW_TEMP_BBOX_ID__',
138
- }
139
- : undefined;
140
- };
141
- export const getModifyKeyForOS = () => {
142
- const isMac = navigator.userAgent.includes('Mac');
143
- return isMac ? 'metaKey' : 'ctrlKey';
144
- };
145
- export const calculatePastedBox = (mousePosition, copyTarget, containerWidth, containerHeight) => {
146
- const boxWidth = copyTarget.xMaxNormalized - copyTarget.xMinNormalized;
147
- const boxHeight = copyTarget.yMaxNormalized - copyTarget.yMinNormalized;
148
- // creates box centered on current mouse position
149
- const tempBox = {
150
- xMin: mousePosition.x / containerWidth - boxWidth / 2,
151
- xMax: mousePosition.x / containerWidth + boxWidth / 2,
152
- yMin: mousePosition.y / containerHeight - boxHeight / 2,
153
- yMax: mousePosition.y / containerHeight + boxHeight / 2,
154
- };
155
- /**
156
- * if side exceeds boundary of image, set exceeding side equal to boundary
157
- * then translate parallel side by the same distance
158
- */
159
- if (tempBox.xMin < 0) {
160
- tempBox.xMax -= tempBox.xMin;
161
- tempBox.xMin = 0;
162
- }
163
- if (tempBox.yMin < 0) {
164
- tempBox.yMax -= tempBox.yMin;
165
- tempBox.yMin = 0;
166
- }
167
- if (tempBox.xMax > 1) {
168
- tempBox.xMin -= tempBox.xMax - 1;
169
- tempBox.xMax = 1;
170
- }
171
- if (tempBox.yMax > 1) {
172
- tempBox.yMin -= tempBox.yMax - 1;
173
- tempBox.yMax = 1;
174
- }
175
- return {
176
- id: '',
177
- label: copyTarget.label,
178
- xMinNormalized: tempBox.xMin,
179
- xMaxNormalized: tempBox.xMax,
180
- yMinNormalized: tempBox.yMin,
181
- yMaxNormalized: tempBox.yMax,
182
- };
183
- };