@viamrobotics/test-widgets 0.1.8 → 0.1.9

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.
@@ -1,8 +1,5 @@
1
1
  <script lang="ts">
2
2
  import { useThrelte } from '@threlte/core'
3
- import { useInteractivity } from '@threlte/extras'
4
- import { onMount } from 'svelte'
5
- import { Vector2 } from 'three'
6
3
  import { Container, Text } from 'threlte-uikit'
7
4
 
8
5
  import { lightTextColors } from './color'
@@ -17,19 +14,6 @@
17
14
 
18
15
  const { detection, factor = 0 }: Props = $props()
19
16
 
20
- const normalizedDeviceCoordsToPixel = (
21
- ndcCoords: Vector2,
22
- canvasWidth: number,
23
- canvasHeight: number
24
- ) => {
25
- const screenX = (ndcCoords.x + 1) / 2
26
- const screenY = (ndcCoords.y + 1) / 2
27
- const pixelX = Math.round(screenX * canvasWidth)
28
- const pixelY = Math.round((1 - screenY) * canvasHeight)
29
- return new Vector2(pixelX, pixelY)
30
- }
31
-
32
- const { pointer } = useInteractivity()
33
17
  const context = useDetections()
34
18
 
35
19
  const factoredxMin = $derived(Number(detection.xMin) * factor)
@@ -37,46 +21,32 @@
37
21
  const factoredyMin = $derived(Number(detection.yMin) * factor)
38
22
  const factoredyMax = $derived(Number(detection.yMax) * factor)
39
23
 
40
- /**
41
- * Check preexisting mouse coords for hover state
42
- */
43
- $effect.pre(() => {
44
- const pixelCoords = normalizedDeviceCoordsToPixel($pointer, $size.width, $size.height)
45
-
46
- if (
47
- factoredxMin < pixelCoords.x &&
48
- factoredxMax > pixelCoords.x &&
49
- factoredyMin < pixelCoords.y &&
50
- factoredyMax > pixelCoords.y
51
- ) {
52
- context.hovered.add(detection.id)
53
- } else {
54
- context.hovered.delete(detection.id)
55
- }
56
- })
57
-
58
- const hovering = $derived(context.hovered.has(detection.id))
24
+ let hovering = $state(false)
59
25
 
60
26
  // These are ballparking, but seem good enough for nearly all cases
61
27
  const isDetectionNearTop = $derived(factoredyMin < 30)
62
28
  const isDetectionNearRight = $derived(factoredxMin > $size.width * 0.66)
63
-
64
- onMount(() => {
65
- return () => {
66
- context.hovered.delete(detection.id)
67
- }
68
- })
69
29
  </script>
70
30
 
71
31
  <Container
72
32
  positionType="absolute"
73
33
  positionLeft={factoredxMin}
74
34
  positionTop={factoredyMin}
75
- borderColor={hovering ? detection.color : '#aaa'}
35
+ borderColor="#aaa"
36
+ hover={{
37
+ borderColor: detection.color,
38
+ }}
76
39
  borderWidth={2}
77
40
  width={factoredxMax - factoredxMin}
78
41
  height={factoredyMax - factoredyMin}
79
- onpointerleave={() => context.hovered.delete(detection.id)}
42
+ onpointerenter={() => {
43
+ context.hovered.add(detection.id)
44
+ hovering = true
45
+ }}
46
+ onpointerleave={() => {
47
+ context.hovered.delete(detection.id)
48
+ hovering = false
49
+ }}
80
50
  >
81
51
  {#if hovering}
82
52
  <Text
@@ -16,7 +16,7 @@
16
16
  interface Props {
17
17
  data?: {
18
18
  detections: Detection[]
19
- image: ({ image: Uint8Array } & Exclude<cameraApi.Image, 'image'>) | undefined
19
+ image: ({ image: Uint8Array } & Omit<cameraApi.Image, 'image'>) | undefined
20
20
  classifications: Classification[]
21
21
  }
22
22
  detectionsSupported: boolean
@@ -62,7 +62,9 @@
62
62
  provideFontFamilies({
63
63
  publicSans: {
64
64
  // This must remain `/static/*` while the frontend directory still exist
65
+ light: '/static/fonts/public-sans.json',
65
66
  medium: '/static/fonts/public-sans.json',
67
+ 'extra-light': '/static/fonts/public-sans.json',
66
68
  },
67
69
  })
68
70
 
@@ -108,7 +110,7 @@
108
110
  </div>
109
111
  {:else}
110
112
  <div
111
- class="relative max-h-full min-h-0 max-w-full"
113
+ class="border-light relative max-h-full min-h-0 max-w-full border"
112
114
  style:width={`${size.width.toString()}px`}
113
115
  style:height={`${size.height.toString()}px`}
114
116
  >
@@ -117,11 +119,13 @@
117
119
  >
118
120
  {fps.current.toFixed(1)}fps
119
121
  </div>
122
+ <img
123
+ class="absolute top-0 left-0"
124
+ alt=""
125
+ {src}
126
+ />
120
127
  <Canvas>
121
- <Scene
122
- {src}
123
- factor={size.factor}
124
- />
128
+ <Scene factor={size.factor} />
125
129
  </Canvas>
126
130
  </div>
127
131
  <div
@@ -4,7 +4,7 @@ interface Props {
4
4
  detections: Detection[];
5
5
  image: ({
6
6
  image: Uint8Array;
7
- } & Exclude<cameraApi.Image, 'image'>) | undefined;
7
+ } & Omit<cameraApi.Image, 'image'>) | undefined;
8
8
  classifications: Classification[];
9
9
  };
10
10
  detectionsSupported: boolean;
@@ -1,17 +1,16 @@
1
1
  <script lang="ts">
2
2
  import { T } from '@threlte/core'
3
3
  import { interactivity } from '@threlte/extras'
4
- import { Fullscreen, Image } from 'threlte-uikit'
4
+ import { Fullscreen } from 'threlte-uikit'
5
5
 
6
6
  import { useDetections } from './context.svelte'
7
7
  import Detection from './detection.svelte'
8
8
 
9
9
  interface Props {
10
- src: string
11
10
  factor?: number
12
11
  }
13
12
 
14
- const { src, factor = 0 }: Props = $props()
13
+ const { factor = 0 }: Props = $props()
15
14
 
16
15
  const context = useDetections()
17
16
 
@@ -22,24 +21,7 @@
22
21
  makeDefault
23
22
  position={[0, 0, 1]}
24
23
  >
25
- <Fullscreen
26
- positionType="relative"
27
- width="100%"
28
- height="100%"
29
- >
30
- <Image
31
- positionType="absolute"
32
- width="100%"
33
- height="100%"
34
- {src}
35
- />
36
- </Fullscreen>
37
-
38
- <Fullscreen
39
- positionType="relative"
40
- width="100%"
41
- height="100%"
42
- >
24
+ <Fullscreen>
43
25
  {#each context.current as detection (detection.id)}
44
26
  <Detection
45
27
  {detection}
@@ -1,5 +1,4 @@
1
1
  interface Props {
2
- src: string;
3
2
  factor?: number;
4
3
  }
5
4
  declare const Scene: import("svelte").Component<Props, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/test-widgets",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "files": [