@cosmicds/vue-toolkit 0.3.1 → 0.4.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/README.md +20 -1
- package/dist/index.common.js +741 -628
- package/dist/index.umd.js +741 -628
- package/dist/index.umd.min.js +4 -4
- package/dist/src/background.d.ts +4 -0
- package/dist/src/components/CreditLogos.vue.d.ts +14 -9
- package/dist/src/components/FundingAcknowledgement.vue.d.ts +1 -1
- package/dist/src/components/Gallery.vue.d.ts +2 -2
- package/dist/src/components/GeolocationButton.vue.d.ts +0 -16
- package/dist/src/components/IconButton.vue.d.ts +10 -12
- package/dist/src/components/LocationSelector.vue.d.ts +4 -4
- package/dist/src/components/WwtHud.vue.d.ts +3 -3
- package/dist/src/composables.d.ts +15 -7
- package/dist/src/geolocation.d.ts +6 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/keyboard.d.ts +35 -2
- package/dist/src/mapbox.d.ts +55 -3
- package/dist/src/stories/CreditLogos.stories.d.ts +6 -0
- package/dist/src/stories/FundingAcknowledgement.stories.d.ts +6 -0
- package/dist/src/stories/Gallery.stories.d.ts +6 -0
- package/dist/src/stories/IconButton.stories.d.ts +6 -0
- package/dist/src/stories/LocationSelector.stories.d.ts +6 -0
- package/dist/src/stories/WwtHud.stories.d.ts +6 -0
- package/dist/src/types.d.ts +123 -4
- package/dist/src/utils.d.ts +24 -2
- package/dist/src/wwt-utils.d.ts +6 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -3
- package/src/background.ts +4 -0
- package/src/composables.ts +14 -1
- package/src/geolocation.ts +12 -0
- package/src/index.ts +2 -1
- package/src/keyboard.ts +36 -2
- package/src/mapbox.ts +74 -8
- package/src/types.ts +127 -5
- package/src/utils.ts +24 -4
- package/src/wwt-utils.ts +6 -0
package/src/types.ts
CHANGED
|
@@ -2,148 +2,270 @@ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
|
|
2
2
|
import { CircleMarkerOptions, TileLayerOptions } from "leaflet";
|
|
3
3
|
import { engineStore } from "@wwtelescope/engine-pinia";
|
|
4
4
|
|
|
5
|
+
/** The type of the WWT engine Pinia store */
|
|
5
6
|
export type WWTEngineStore = ReturnType<typeof engineStore>;
|
|
6
7
|
|
|
7
8
|
/* Funding acknowledgement */
|
|
8
9
|
|
|
10
|
+
/** Interface describing props for the funding acknowledgement component */
|
|
9
11
|
export interface FundingAcknowledgementProps {
|
|
12
|
+
/** The color of the acknowledgement text */
|
|
10
13
|
color?: string;
|
|
14
|
+
|
|
15
|
+
/** The background color of the acknowledgement */
|
|
11
16
|
backgroundColor?: string;
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
/* Credit logos */
|
|
15
20
|
|
|
21
|
+
/** Interface describing a logo */
|
|
22
|
+
export interface CreditLogo {
|
|
23
|
+
/** The URL for the logo image */
|
|
24
|
+
src: string;
|
|
25
|
+
/** The URL to open when the logo is clicked */
|
|
26
|
+
href: string;
|
|
27
|
+
/** Alt text to use for the logo. If none is given, the logo will have no alt text */
|
|
28
|
+
alt?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A union type enumerating the default credit logos */
|
|
32
|
+
export type DefaultCreditLogo = "cosmicds" | "wwt" | "sciact" | "nasa";
|
|
33
|
+
|
|
34
|
+
/** Interface describing props for the credit logos component */
|
|
16
35
|
export interface CreditLogosProps {
|
|
17
|
-
|
|
36
|
+
/** What size to use for the logos. Should be a valid CSS size. */
|
|
18
37
|
logoSize?: string;
|
|
38
|
+
/** Any extra logos that we want to use */
|
|
39
|
+
extraLogos?: CreditLogo[];
|
|
40
|
+
/** Which default logos to use. If not specified, use them all */
|
|
41
|
+
defaultLogos: DefaultCreditLogo[];
|
|
19
42
|
}
|
|
20
43
|
|
|
21
44
|
/* Gallery */
|
|
22
45
|
|
|
46
|
+
/** Interface describing props for the gallery component */
|
|
23
47
|
export interface GalleryProps {
|
|
48
|
+
/** The URL of a WTML file describing the desired gallery contents. Required */
|
|
24
49
|
wtmlUrl: string;
|
|
50
|
+
/** The number of columns of the gallery.
|
|
51
|
+
* Accepts a number or a valid CSS value to be used in `repeat` for `grid-template-columns`
|
|
52
|
+
* Defaults to 'auto-fit'
|
|
53
|
+
*/
|
|
25
54
|
columns?: number | string;
|
|
55
|
+
/** The width of the gallery. Should be a valid CSS value for `width`. Defaults to 300px */
|
|
26
56
|
width?: string;
|
|
57
|
+
/** Maximum height of the gallery. Should be a valid CSS value for `max-height`. Defaults to 500px */
|
|
27
58
|
maxHeight?: string;
|
|
59
|
+
/** The title of the gallery. Default is 'Gallery' */
|
|
28
60
|
title?: string;
|
|
61
|
+
/** The accent color to use for selected images in the gallery. Should be a valid CSS color. Default is 'dodgerblue' */
|
|
29
62
|
selectedColor?: string;
|
|
63
|
+
/** Whether a user can select only one image at a time. Default true */
|
|
30
64
|
singleSelect?: boolean;
|
|
65
|
+
/** Whether only the last selected image is highlighted. Default false */
|
|
31
66
|
highlightLastOnly?: boolean;
|
|
67
|
+
/** The index of the preview image in the WTML file. Defaults to 0. */
|
|
32
68
|
previewIndex?: number;
|
|
69
|
+
/** The text to show when the gallery is closed. Default is 'Image Gallery' */
|
|
33
70
|
closedText?: string;
|
|
34
71
|
}
|
|
35
72
|
|
|
36
73
|
/* Geolocation button */
|
|
37
74
|
|
|
75
|
+
/** A union type consisting of the density options for the geolocation button */
|
|
38
76
|
export type GeolocationButtonDensity = null | "default" | "comfortable" | "compact";
|
|
39
77
|
|
|
78
|
+
/** Interface describing props for the geolocation button */
|
|
40
79
|
export interface GeolocationButtonProps {
|
|
80
|
+
/** The color of the geolocation button. Defaults to "white" */
|
|
41
81
|
color?: string;
|
|
42
|
-
|
|
82
|
+
/** The size of the button */
|
|
43
83
|
size?: string;
|
|
84
|
+
/** The density of the button. This adjusts the vertical height of the button. Defaults to "comfortable" */
|
|
44
85
|
density?: GeolocationButtonDensity;
|
|
86
|
+
/** The elevation of the button. Defaults to "2" */
|
|
45
87
|
elevation?: string;
|
|
88
|
+
/** Whether to hide the button. Defaults to false */
|
|
46
89
|
hideButton?: boolean;
|
|
90
|
+
/** Whether to show the button's text label. Defaults to false */
|
|
47
91
|
showTextLabel?: boolean;
|
|
92
|
+
/** Whether to show the button's geolocation coordinates. Defaults to false */
|
|
48
93
|
showCoords?: boolean;
|
|
94
|
+
/** Whether to show text indicating when location fetching is in progress. Defaults to false */
|
|
49
95
|
showTextProgress?: boolean;
|
|
96
|
+
/** Whether to show circle indicator when fetching is in progress. Defaults to true */
|
|
50
97
|
showProgressCircle?: boolean;
|
|
98
|
+
/** Whether to include text on the button. Defaults to false */
|
|
51
99
|
useTextButton?: boolean;
|
|
100
|
+
/** The size of the in-progress circle. Defaults to 12 */
|
|
52
101
|
progressCircleSize?: number;
|
|
102
|
+
/** The button's label. Defaults to "My Location" */
|
|
53
103
|
label?: string;
|
|
104
|
+
/** The ID to use to create the button ID */
|
|
54
105
|
id?: string;
|
|
106
|
+
/** The icon to use when the geolocation has been obtained */
|
|
55
107
|
trueIcon?: string;
|
|
108
|
+
/** The icon to use when there is no value for the geolocation */
|
|
56
109
|
falseIcon?: string;
|
|
57
|
-
|
|
110
|
+
/** Whether to show the location and permission status. Useful for debugging, defaults to false */
|
|
58
111
|
showPermissions?: boolean;
|
|
59
112
|
}
|
|
60
113
|
|
|
61
114
|
/* Icon button */
|
|
62
|
-
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A type describing the props of a FontAwesome icon
|
|
118
|
+
* We need to do this because FontAwesome doesn't export the prop types
|
|
119
|
+
*/
|
|
63
120
|
export type FontAwesomeIconProps = InstanceType<typeof FontAwesomeIcon>["$props"];
|
|
121
|
+
/** A type describing the size options for a FontAwesome icon */
|
|
64
122
|
export type SizeType = Extract<FontAwesomeIconProps, 'size'>;
|
|
65
123
|
|
|
124
|
+
/** An interface describing props for the icon button */
|
|
66
125
|
export interface IconButtonProps {
|
|
126
|
+
/** Whether or not the icon button is active. Only makes sense in cases where one wants the button to have an on/off state */
|
|
67
127
|
modelValue?: boolean;
|
|
128
|
+
/** The name of the FontAwesome icon to use. It's assumed that only one of this and `mdIcon` will be used */
|
|
68
129
|
faIcon?: string;
|
|
130
|
+
/** The name of the MID icon to use. It's assumed that only one of this and `faIcon` will be used */
|
|
69
131
|
mdIcon?: string;
|
|
132
|
+
/** The primary color of the button. Sets the icon and border colors. Default is white */
|
|
70
133
|
color?: string;
|
|
134
|
+
/** The color of the button when focused. Default is white */
|
|
71
135
|
focusColor?: string;
|
|
136
|
+
/** The color of the button when active. Default is white */
|
|
137
|
+
activeColor?: string;
|
|
138
|
+
/** The background color of the button. Default is #040404 */
|
|
72
139
|
backgroundColor?: string;
|
|
73
|
-
|
|
140
|
+
/** Whether the button has a border. Default is true */
|
|
74
141
|
border?: boolean;
|
|
142
|
+
/** The time duration, in ms, to recognize a press event as a long press. Default is 500 */
|
|
75
143
|
longPressTimeMs?: number;
|
|
144
|
+
/** The tooltip text for the button. If not specified, tooltip will not be shown */
|
|
76
145
|
tooltipText?: string;
|
|
146
|
+
/** The location of the tooltip. Default is start */
|
|
77
147
|
tooltipLocation?: string;
|
|
148
|
+
/** Whether to show the tooltip when the button is clicked. Default is false */
|
|
78
149
|
tooltipOnClick?: boolean;
|
|
150
|
+
/** Whether to show the tooltip when the button is focused. Default is false */
|
|
79
151
|
tooltipOnFocus?: boolean;
|
|
152
|
+
/** Whether to show the tooltip when the button is hovered. Default is true */
|
|
80
153
|
tooltipOnHover?: boolean;
|
|
154
|
+
/** The distance away from the button that the tooltip appears. Default is 0 */
|
|
81
155
|
tooltipOffset?: string | number;
|
|
156
|
+
/** Whether to show the tooltip when appropriate. Default is true */
|
|
82
157
|
showTooltip?: boolean;
|
|
158
|
+
/** The size of the FontAwesome icon */
|
|
83
159
|
faSize?: SizeType;
|
|
160
|
+
/** The size of the MDI icon. Should be a valid CSS size */
|
|
84
161
|
mdSize?: string;
|
|
85
162
|
}
|
|
86
163
|
|
|
87
164
|
|
|
88
165
|
/* Location selector */
|
|
89
166
|
|
|
167
|
+
/** An interface describing a latitude/longitude location */
|
|
90
168
|
export interface LocationDeg {
|
|
169
|
+
/** The longitude of the location, in degrees */
|
|
91
170
|
longitudeDeg: number;
|
|
171
|
+
/** The latitude of the location, in degrees */
|
|
92
172
|
latitudeDeg: number;
|
|
93
173
|
}
|
|
94
174
|
|
|
175
|
+
/** An interface describing options for the Leaflet map in the location selector */
|
|
95
176
|
export interface LeafletMapOptions extends TileLayerOptions {
|
|
177
|
+
/** The template URL to use for the base map layer */
|
|
96
178
|
templateUrl: string;
|
|
179
|
+
/** The initial location to center the map on */
|
|
97
180
|
initialLocation?: LocationDeg;
|
|
181
|
+
/** The initial zoom level of the map */
|
|
98
182
|
initialZoom?: number;
|
|
99
183
|
}
|
|
100
184
|
|
|
185
|
+
/** An interface describing a GeoJSON item, to be used as a prop for the location selector */
|
|
101
186
|
export interface GeoJSONProp {
|
|
187
|
+
/** The URL of a remote GeoJSON resource. This and `geojson` and not intended to be used together */
|
|
102
188
|
url?: string;
|
|
189
|
+
/** A GeoJSON object to add to the location selector */
|
|
103
190
|
geojson?: GeoJSON.FeatureCollection | GeoJSON.Feature | GeoJSON.GeometryCollection;
|
|
191
|
+
/** The style options for any circle markers related to this item. Required */
|
|
104
192
|
style: CircleMarkerOptions;
|
|
105
193
|
}
|
|
106
194
|
|
|
195
|
+
/** Interface describing a place on the location selector */
|
|
107
196
|
export interface PlaceDeg extends LocationDeg {
|
|
197
|
+
/** The color to use for the circle showing the place */
|
|
108
198
|
color?: string;
|
|
199
|
+
/** The fill color to use for the circle showing the place */
|
|
109
200
|
fillColor?: string;
|
|
201
|
+
/** The fill opacity to use for the circle showing the place */
|
|
110
202
|
fillOpacity?: number;
|
|
203
|
+
/** The radius to use for the circle showing the place */
|
|
111
204
|
radius?: number;
|
|
205
|
+
/** The name of the place */
|
|
112
206
|
name?: string;
|
|
113
207
|
}
|
|
114
208
|
|
|
209
|
+
/** Interface describing props for the location selector */
|
|
115
210
|
export interface LocationSelectorProps {
|
|
211
|
+
/** The color to use for the activator button */
|
|
116
212
|
activatorColor?: string;
|
|
213
|
+
/** Whether to attempt to detect the user's location when the component is mounted. Default is true */
|
|
117
214
|
detectLocation?: boolean;
|
|
215
|
+
/** The currently selected location. Default is the coordinates for Harvard College Observatory */
|
|
118
216
|
modelValue?: LocationDeg;
|
|
217
|
+
/** Map options for the Leaflet map. If not specified, sensible defaults are used */
|
|
119
218
|
mapOptions?: LeafletMapOptions;
|
|
219
|
+
/** The initial place to be selected on the map */
|
|
120
220
|
initialPlace?: PlaceDeg;
|
|
221
|
+
/** The list of places to show on the map */
|
|
121
222
|
places?: PlaceDeg[];
|
|
223
|
+
/** Options for place circles */
|
|
122
224
|
placeCircleOptions?: CircleMarkerOptions;
|
|
225
|
+
/** Whether places can be selected on the map. Default is true */
|
|
123
226
|
placeSelectable?: boolean;
|
|
227
|
+
/** Whether a location can be selected on the map. Default is true */
|
|
124
228
|
selectable?: boolean;
|
|
229
|
+
/** Options for the circle showing the selected place */
|
|
125
230
|
selectedCircleOptions?: CircleMarkerOptions;
|
|
231
|
+
/** Which event to use to select a location. Default is "click" */
|
|
126
232
|
selectionEvent?: "click" | "dblclick";
|
|
233
|
+
/** Whether to use world radii for circle sizes (as opposed to screen radii). Default is true */
|
|
127
234
|
worldRadii?: boolean;
|
|
235
|
+
/** GeoJSON items to display on the map. The list is empty by default */
|
|
128
236
|
geoJsonFiles?: GeoJSONProp[];
|
|
237
|
+
/** Layers to show on the map. The list is empty by default */
|
|
129
238
|
layers?: L.Layer[];
|
|
130
239
|
}
|
|
131
240
|
|
|
132
241
|
/* WWT HUD */
|
|
133
242
|
|
|
243
|
+
/** Interface describing the location of the WWT HUD */
|
|
134
244
|
export interface HUDLocation {
|
|
245
|
+
/** Distance from the top. Should be a valid CSS value */
|
|
135
246
|
top?: string | number,
|
|
247
|
+
/** Distance from the left. Should be a valid CSS value */
|
|
136
248
|
left?: string | number,
|
|
249
|
+
/** Distance from the bottom. Should be a valid CSS value */
|
|
137
250
|
bottom?: string | number,
|
|
251
|
+
/** Distance from the right. Should be a valid CSS value */
|
|
138
252
|
right?: string | number,
|
|
139
253
|
}
|
|
140
254
|
|
|
255
|
+
/** Interface describing props for the WWT HUD */
|
|
141
256
|
export interface WwtHUDProps {
|
|
257
|
+
/** Location of the HUD in the browser window. Default is `{ top: "50%", left: "50%" }` */
|
|
142
258
|
location?: HUDLocation;
|
|
259
|
+
/** Define an offset for the HUD. Default is `{ x: 0.5, y: 0.5 }` */
|
|
143
260
|
offsetCenter?: { x: number; y: number };
|
|
261
|
+
/** Other variables to include in the HUD display. Default is `{}` */
|
|
144
262
|
otherVariables?: Object; // eslint-disable-line @typescript-eslint/ban-types
|
|
263
|
+
/** The font size of the HUD text. Should be a valid CSS value for `font-size` */
|
|
145
264
|
fontSize?: string;
|
|
265
|
+
/** Background color for the HUD. Should be a valid CSS color. Default is `rgba(0, 0, 0, 0.5)` */
|
|
146
266
|
backgroundColor?: string | null;
|
|
267
|
+
/** Text shadow for the HUD text. Should be a valid CSS value for `text-shadow`. Default is `"0 0 5px black"` */
|
|
147
268
|
textShadow?: string | null;
|
|
269
|
+
/** The WWT engine store to use for the HUD. Required */
|
|
148
270
|
store: ReturnType<typeof engineStore>;
|
|
149
271
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
|
+
/** Degrees -> radians conversion factor */
|
|
1
2
|
export const D2R = Math.PI / 180;
|
|
3
|
+
/** Radians -> degrees conversion factor */
|
|
2
4
|
export const R2D = 180 / Math.PI;
|
|
3
5
|
|
|
6
|
+
/** The base URL for the CosmicDS API server */
|
|
4
7
|
export const API_BASE_URL = "https://api.cosmicds.cfa.harvard.edu";
|
|
5
|
-
export const MINIDS_BASE_URL = `${API_BASE_URL}/minids`;
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Determine whether the user's device supports touch events.
|
|
11
|
+
*
|
|
12
|
+
* @returns Whether touch events are supported
|
|
13
|
+
*/
|
|
14
|
+
export function supportsTouchscreen(): boolean {
|
|
8
15
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
16
|
// @ts-ignore
|
|
10
17
|
return ('ontouchstart' in window) || ('ontouchstart' in document.documentElement) || !!window.navigator.msPointerEnabled;
|
|
11
18
|
}
|
|
12
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Determine whether a given user agent string describes a mobile device.
|
|
22
|
+
* This is done via a regex match against common user agent string pieces.
|
|
23
|
+
*
|
|
24
|
+
* @returns Whether the user agent string describes a mobile device
|
|
25
|
+
*/
|
|
13
26
|
export function isMobile(userAgent: string): boolean {
|
|
14
27
|
return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent));
|
|
15
28
|
}
|
|
16
29
|
|
|
30
|
+
/** Blur the current active element, if there is one */
|
|
17
31
|
export function blurActiveElement() {
|
|
18
32
|
const active = document.activeElement;
|
|
19
33
|
if (active instanceof HTMLElement) {
|
|
@@ -21,7 +35,14 @@ export function blurActiveElement() {
|
|
|
21
35
|
}
|
|
22
36
|
}
|
|
23
37
|
|
|
24
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Filter an array in place (as opposed to .filter, which creates a new array).
|
|
40
|
+
* Modified from https://stackoverflow.com/a/37319954
|
|
41
|
+
*
|
|
42
|
+
* @param array - The array to filter
|
|
43
|
+
* @param condition - The filtering condition. Elements for which this returns true are retained
|
|
44
|
+
* @template T
|
|
45
|
+
*/
|
|
25
46
|
export function filterInPlace<T>(array: T[], condition: (t: T) => boolean) {
|
|
26
47
|
let i = 0;
|
|
27
48
|
let j = 0;
|
|
@@ -34,5 +55,4 @@ export function filterInPlace<T>(array: T[], condition: (t: T) => boolean) {
|
|
|
34
55
|
}
|
|
35
56
|
|
|
36
57
|
array.length = j;
|
|
37
|
-
return array;
|
|
38
58
|
}
|
package/src/wwt-utils.ts
CHANGED
|
@@ -11,6 +11,12 @@ function doMove(store: WWTEngineStore, x: number, y: number) {
|
|
|
11
11
|
store.move({ x, y });
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* A composable that sets up WWT keyboard controls.
|
|
16
|
+
* @param store The WWT engine's Pinia store
|
|
17
|
+
* @param element The element on which to attach the keyboard listeners. Uses the browser window if none is given
|
|
18
|
+
* @returns The `KeyboardControlSettings` instance that was used to create the listeners
|
|
19
|
+
*/
|
|
14
20
|
export function useWWTKeyboardControls(store: WWTEngineStore, element?: Window | HTMLElement): KeyboardControlSettings {
|
|
15
21
|
const root = element || window;
|
|
16
22
|
const kcs = new KeyboardControlSettings({});
|