Skip to content

Commit

Permalink
Close #466 : Add typings
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Feb 6, 2021
1 parent 0b0ed2a commit 584ce62
Show file tree
Hide file tree
Showing 34 changed files with 1,231 additions and 23 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A JavaScript library to display Photo Sphere panoramas",
"homepage": "https://photo-sphere-viewer.js.org",
"main": "dist/photo-sphere-viewer.js",
"types": "src/types/index.d.ts",
"files": [
"src/",
"dist/"
Expand Down
4 changes: 2 additions & 2 deletions src/components/Loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SYSTEM } from '../data/system';
import { getStyle } from '../utils';
import { bound, getStyle } from '../utils';
import { AbstractComponent } from './AbstractComponent';

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ export class Loader extends AbstractComponent {
context.arc(
this.canvas.width / 2, this.canvas.height / 2,
this.canvas.width / 2 - this.prop.tickness / 2,
-Math.PI / 2, value / 100 * 2 * Math.PI - Math.PI / 2
-Math.PI / 2, bound(value, 0, 100) / 100 * 2 * Math.PI - Math.PI / 2
);
context.stroke();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class Panel extends AbstractComponent {

/**
* @summary Shows the panel
* @param {Object} config
* @param {string|Object} config
* @param {string} [config.id]
* @param {string} config.content
* @param {boolean} [config.noMargin=false]
Expand Down
4 changes: 2 additions & 2 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ export const EVENTS = {
/**
* @event hide-notification
* @memberof PSV
* @summary Trigered when the notification is hidden
* @summary Triggered when the notification is hidden
*/
HIDE_NOTIFICATION : 'hide-notification',
/**
* @event hide-overlay
* @memberof PSV
* @summary Trigered when the overlay is hidden
* @summary Triggered when the overlay is hidden
* @param {string} [id]
*/
HIDE_OVERLAY : 'hide-overlay',
Expand Down
28 changes: 14 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ export {
* @property {string} back
*/

/**
* @typedef {Object} PSV.PanoData
* @summary Crop information of the panorama
* @property {number} fullWidth
* @property {number} fullHeight
* @property {number} croppedWidth
* @property {number} croppedHeight
* @property {number} croppedX
* @property {number} croppedY
* @property {number} poseHeading
* @property {number} posePitch
* @property {number} poseRoll
*/

/**
* @callback PanoDataProvider
* @summary Function to compute panorama data once the image is loaded
Expand All @@ -116,20 +130,6 @@ export {
* @property {PSV.PanoData} [panoData]
*/

/**
* @typedef {Object} PSV.PanoData
* @summary Crop information of the panorama
* @property {number} fullWidth
* @property {number} fullHeight
* @property {number} croppedWidth
* @property {number} croppedHeight
* @property {number} croppedX
* @property {number} croppedY
* @property {number} poseHeading
* @property {number} posePitch
* @property {number} poseRoll
*/

/**
* @typedef {Object} PSV.ClickData
* @summary Data of the `click` event
Expand Down
3 changes: 2 additions & 1 deletion src/services/TextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class TextureLoader extends AbstractService {

/**
* @summary Cancels current HTTP requests
* @package
*/
abortLoading() {
[...this.requests].forEach(r => r.abort());
Expand Down Expand Up @@ -375,7 +376,7 @@ export class TextureLoader extends AbstractService {

/**
* @summary Preload a panorama file without displaying it
* @param {string} panorama
* @param {string|string[]|PSV.Cubemap} panorama
* @returns {Promise}
*/
preloadPanorama(panorama) {
Expand Down
35 changes: 35 additions & 0 deletions src/types/Animation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export type AnimationOptions = {
properties: { [K: string]: { start: number, end: number } };
duration: number;
delay?: number;
easing?: string | ((progress: number) => number);
onTick: (properties: { [K: string]: number }, progress: number) => void;
};

/**
* @summary Interpolation helper for animations
* @description
* Implements the Promise API with an additional "cancel" and "finally" methods.
* The promise is resolved when the animation is complete and rejected if the animation is cancelled.
*/
export class Animation implements Promise<void> {

constructor(options: AnimationOptions);

// @ts-ignore
then(onFulfilled?: (() => void | Animation | PromiseLike<void>) | undefined | null, onRejected?: (() => void | Animation | PromiseLike<void>) | undefined | null): Animation;

// @ts-ignore
catch(onRejected?: (() => void | Animation | PromiseLike<void>) | undefined | null): Animation;

// @ts-ignore
finally(onFinally?: (() => void | Animation | PromiseLike<void>) | undefined | null): Animation;

cancel();

/**
* @summary Returns a resolved animation promise
*/
static resolve(): Animation;

}
6 changes: 6 additions & 0 deletions src/types/PSVError.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @summary Custom error used in the lib
*/
export class PSVError extends Error {
name: 'PSVError';
}
Loading

0 comments on commit 584ce62

Please sign in to comment.