forked from JeremyHeleine/Photo-Sphere-Viewer
-
-
Notifications
You must be signed in to change notification settings - Fork 629
/
model.ts
397 lines (376 loc) · 9.07 KB
/
model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
import { Object3D, Texture, WebGLRendererParameters } from 'three';
import { AdapterConstructor } from './adapters/AbstractAdapter';
import { ACTIONS } from './data/constants';
import { PluginConstructor } from './plugins/AbstractPlugin';
import { Viewer } from './Viewer';
import { AnimationOptions } from './utils';
/**
* A wrapper around a Promise with an initial value before resolution
*/
export type ResolvableBoolean = { initial: boolean; promise: Promise<boolean> };
/**
* Object defining a point
*/
export type Point = {
x: number;
y: number;
};
/**
* Object defining a size
*/
export type Size = {
width: number;
height: number;
};
/**
* Object defining a size in CSS
*/
export type CssSize = {
width: string;
height: string;
};
/**
* Object defining angular corrections to a sphere
*/
export type SphereCorrection = {
pan?: number;
tilt?: number;
roll?: number;
};
/**
* Object defining a spherical position (radians)
*/
export type Position = {
yaw: number;
pitch: number;
};
/**
* Object defining a spherical position (radians or degrees)
*/
export type SphericalPosition = {
yaw: number | string;
pitch: number | string;
};
/**
* Object defining a position on the panorama image (pixels)
*/
export type PanoramaPosition = {
textureX: number;
textureY: number;
textureFace?: string;
};
/**
* Object defining a spherical or panorama position
*/
export type ExtendedPosition = SphericalPosition | PanoramaPosition;
/**
* Object defining options for {@link Viewer.animate}
*/
export type AnimateOptions = Partial<ExtendedPosition> & {
/**
* Animation speed or duration in milliseconds
*/
speed: string | number;
/**
* New zoom level between 0 and 100
*/
zoom?: number;
/**
* Easing function used for the animation
* @default 'inOutSine'
*/
easing?: AnimationOptions<any>['easing'];
};
/**
* Crop information of an equirectangular panorama
*/
export type PanoData = {
isEquirectangular: true;
fullWidth: number;
fullHeight: number;
croppedWidth: number;
croppedHeight: number;
croppedX: number;
croppedY: number;
poseHeading?: number;
posePitch?: number;
poseRoll?: number;
};
/**
* Function to compute panorama data once the image is loaded
*/
export type PanoDataProvider = (image: HTMLImageElement, xmpData?: PanoData) => PanoData;
/**
* Object defining options for {@link Viewer.setPanorama}
*/
export type PanoramaOptions = {
/**
* new panorama position
*/
position?: ExtendedPosition;
/**
* new navbar caption
*/
caption?: string;
/**
* new panorama description
*/
description?: string;
/**
* new zoom level between 0 and 100
*/
zoom?: number;
/**
* enable transition (rotation + fading) between old and new panorama
* @default true
*/
transition?: boolean | 'fade-only';
/**
* speed or duration of the transition between old and new panorama
* @default 1500
*/
speed?: string | number;
/**
* show the loader while loading the new panorama
* @default true
*/
showLoader?: boolean;
/**
* new sphere correction to apply to the panorama
*/
sphereCorrection?: SphereCorrection;
/**
* new data used for this panorama
*/
panoData?: PanoData | PanoDataProvider;
};
/**
* Result of {@link AbstractAdapter.loadTexture}
*/
export type TextureData<TTexture = Texture | Texture[] | Record<string, Texture>, TPanorama = any, TData = any> = {
/**
* Actual texture or list of textures
*/
texture: TTexture;
/**
* Original panorama definition
*/
panorama: TPanorama;
/**
* Panorama metadata
*/
panoData?: TData;
/**
* Key used in the loader cache
*/
cacheKey?: string;
};
/**
* Data of {@link events.ClickEvent}
*/
export type ClickData = {
/**
* if it's a right click
*/
rightclick: boolean;
/**
* position in the browser window
*/
clientX: number;
/**
* position in the browser window
*/
clientY: number;
/**
* position in the viewer
*/
viewerX: number;
/**
* position in the viewer
*/
viewerY: number;
/**
* position in spherical coordinates
*/
yaw: number;
/**
* position in spherical coordinates
*/
pitch: number;
/**
* position on the texture, if applicable
*/
textureX?: number;
/**
* position on the texture, if applicable
*/
textureY?: number;
/**
* position on the texture, if applicable
*/
textureFace?: string;
/**
* Original element which received the click
*/
target: HTMLElement;
/**
* List of THREE scenes objects under the mouse
*/
objects: Object3D[];
/**
* clicked Marker
*/
marker?: any;
};
/**
* Custom Web Component interface for navbar buttons
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface NavbarButtonElement extends HTMLElement {
attachViewer?(viewer: Viewer): void;
}
/**
* Definition of a custom navbar button
*/
export type NavbarCustomButton = {
/**
* Unique identifier of the button, usefull when using the {@link Navbar.getButton} method
*/
id?: string;
/**
* Tooltip displayed when the mouse is over the button
*/
title?: string;
/**
* Content of the button. Preferably a square image or SVG icon
*/
content: string | NavbarButtonElement;
/**
* CSS class added to the button
*/
className?: string;
/**
* Function called when the button is clicked
*/
onClick?: (viewer: Viewer) => void;
/**
* initial state of the button
* @default false
*/
disabled?: boolean;
/**
* initial visibility of the button
* @default true
*/
visible?: boolean;
/**
* if the button can be moved to menu when the navbar is too small
* @default true
*/
collapsable?: boolean;
/**
* if the button is accessible with the keyboard
* @default true
*/
tabbable?: boolean;
};
/**
* Viewer configuration
* @link https://photo-sphere-viewer.js.org/guide/config.html
*/
export type ViewerConfig = {
container: HTMLElement | string;
panorama?: any;
/** @default equirectangular */
adapter?: AdapterConstructor | [AdapterConstructor, any];
plugins?: Array<PluginConstructor | [PluginConstructor, any]>;
/** @default null */
caption?: string;
/** @default null */
description?: string;
/** @default null */
downloadUrl?: string;
/** @default null */
downloadName?: string;
/** @default null */
loadingImg?: string;
/** @default 'Loading...' */
loadingTxt?: string;
/** @default `container` size */
size?: CssSize;
/** @default false */
fisheye?: boolean | number;
/** @default 30 */
minFov?: number;
/** @default 90 */
maxFov?: number;
/** @default 50 */
defaultZoomLvl?: number;
/** @default 0 */
defaultYaw?: number | string;
/** @default 0 */
defaultPitch?: number | string;
/** @default `0,0,0` */
sphereCorrection?: SphereCorrection;
/** @default 1 */
moveSpeed?: number;
/** @default 1 */
zoomSpeed?: number;
/** @default true */
moveInertia?: boolean;
/** @default true */
mousewheel?: boolean;
/** @default true */
mousemove?: boolean;
/** @default false */
mousewheelCtrlKey?: boolean;
/** @default false */
touchmoveTwoFingers?: boolean;
panoData?: PanoData | PanoDataProvider;
requestHeaders?: Record<string, string> | ((url: string) => Record<string, string>);
/** @default '{ alpha: true, antialias: true }' */
rendererParameters?: WebGLRendererParameters;
/** @default false */
withCredentials?: boolean;
/** @default 'zoom move download description caption fullscreen' */
navbar?: boolean | string | Array<string | NavbarCustomButton>;
lang?: Record<string, string>;
keyboard?: boolean | 'always' | 'fullscreen' | Record<string, ACTIONS | ((viewer: Viewer) => void)>;
keyboardActions?: Record<string, ACTIONS | ((viewer: Viewer) => void)>;
};
/**
* Viewer configuration after applying parsers
*/
export type ParsedViewerConfig = Omit<
ViewerConfig,
| 'adapter'
| 'plugins'
| 'defaultYaw'
| 'defaultPitch'
| 'fisheye'
| 'requestHeaders'
| 'navbar'
| 'keyboard'
> & {
adapter?: [AdapterConstructor, any];
plugins?: Array<[PluginConstructor, any]>;
defaultYaw?: number;
defaultPitch?: number;
fisheye?: number;
requestHeaders?: (url: string) => Record<string, string>;
navbar?: Array<string | NavbarCustomButton>;
keyboard?: false | 'always' | 'fullscreen';
};
/**
* Readonly viewer configuration
*/
export type ReadonlyViewerConfig =
| 'panorama'
| 'panoData'
| 'container'
| 'adapter'
| 'plugins';
/**
* Updatable viewer configuration
*/
export type UpdatableViewerConfig = Omit<ViewerConfig, ReadonlyViewerConfig>;