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 Aug 25, 2021
1 parent 4cd59e1 commit bc8481b
Show file tree
Hide file tree
Showing 44 changed files with 1,939 additions and 7 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"description": "A JavaScript library to display Photo Sphere panoramas",
"homepage": "https://photo-sphere-viewer.js.org",
"main": "dist/photo-sphere-viewer.js",
"types": "types/index.d.ts",
"files": [
"src/",
"dist/"
"dist/",
"types/"
],
"authors": [
{
Expand All @@ -32,7 +34,7 @@
},
"dependencies": {
"three": "^0.131.2",
"uevent": "~2.0.0"
"uevent": "~2.0.1"
},
"devDependencies": {
"@babel/core": "^7.7.4",
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/AbstractAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class AbstractAdapter {
}

/**
* @summary Destroys the service
* @summary Destroys the adapter
*/
destroy() {
delete this.psv;
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ export {
*/

/**
* @typedef {PSV.AnimateOptions} PSV.PanoramaOptions
* @typedef {PSV.ExtendedPosition} PSV.PanoramaOptions
* @summary Object defining panorama and animation options
* @property {boolean|number} [transition=1500] - duration of the transition between all and new panorama
* @property {boolean} [showLoader=true] - show the loader
* @property {number} [zoom] - new zoom level between 0 and 100
* @property {PSV.SphereCorrection} [sphereCorrection] - new sphere correction to apply to the panorama
* @property {PSV.PanoData | PSV.PanoDataProvider} [panoData] - new panorama data used for this panorama
*/
Expand Down
2 changes: 1 addition & 1 deletion src/utils/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function getAngle(position1, position2) {
}

/**
* Returns the distance between two points on a sphere of radius one
* @summary Returns the distance between two points on a sphere of radius one
* @memberOf PSV.utils
* @param {number[]} p1
* @param {number[]} p2
Expand Down
2 changes: 1 addition & 1 deletion src/utils/misc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @summary Transforms a string to dash-case{@link https://github.com/shahata/dasherize}
* @summary Transforms a string to dash-case {@link https://github.com/shahata/dasherize}
* @memberOf PSV.utils
* @param {string} str
* @returns {string}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/psv.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CSS_POSITIONS = {
* @memberOf PSV.utils
* @description The implementation is as close as possible to the "background-position" specification
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/background-position}
* @param {string|object} value
* @param {string|PSV.Point} value
* @returns {PSV.Point}
*/
export function parsePosition(value) {
Expand Down
15 changes: 15 additions & 0 deletions types-test/CustomPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AbstractPlugin, Viewer } from '../types/photo-sphere-viewer';

export class CustomPlugin extends AbstractPlugin {

static id = 'custom';

constructor(psv: Viewer) {
super(psv);
}

doSomething() {

}

}
62 changes: 62 additions & 0 deletions types-test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { CONSTANTS, Viewer } from 'photo-sphere-viewer';
import MarkersPlugin, { MarkersPluginOptions } from 'photo-sphere-viewer/dist/plugins/markers';
import { CustomPlugin } from './CustomPlugin';

const viewer = new Viewer({
container: 'container',
plugins: [
[MarkersPlugin, {
clickEventOnMarker: true,
} as MarkersPluginOptions],
CustomPlugin,
],
});

viewer.setPanorama('test.jpg', {
transition: false,
})
.then(() => {

});

viewer.animate({
longitude: 0,
latitude: 0,
speed: '2rpm',
})
.then(() => {

});

viewer.zoom(50);

viewer.setOption('useXmpData', true);

viewer.setOptions({
useXmpData: false,
});

viewer.navbar.setCaption('Test');

viewer.panel.show({
content: 'Content',
clickHandler: (e: MouseEvent) => null,
});

viewer.once('ready', e => {

});

viewer.on('position-updated', (e, position) => {
const longitude: number = position.longitude;
});

viewer.on(CONSTANTS.CHANGE_EVENTS.GET_ANIMATE_POSITION, (e, position) => {
return {longitude: position.longitude + 0.1, latitude: position.latitude + 0.1};
});

const customPlugin: MarkersPlugin = viewer.getPlugin(CustomPlugin);
customPlugin.doSomething();

const customPluginAgain = viewer.getPlugin<CustomPlugin>('custom');
customPluginAgain.doSomething();
11 changes: 11 additions & 0 deletions types-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": "./",
"typeRoots": [
"../types"
],
"paths": {
"*": ["../types/*"]
}
}
}
35 changes: 35 additions & 0 deletions types/photo-sphere-viewer/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 types/photo-sphere-viewer/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 bc8481b

Please sign in to comment.