@esotericsoftware/spine-player
Version:
The official Spine Runtimes for the web.
161 lines (160 loc) • 5.62 kB
TypeScript
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated September 24, 2021. Replaces all prior versions.
*
* Copyright (c) 2013-2021, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
import { Animation, AnimationState, Color, Downloader, Skeleton, StringMap, TimeKeeper, TrackEntry } from "@esotericsoftware/spine-core";
import { AssetManager, LoadingScreen, ManagedWebGLRenderingContext, SceneRenderer } from "@esotericsoftware/spine-webgl";
export interface SpinePlayerConfig {
jsonUrl: string;
jsonField: string;
binaryUrl: string;
atlasUrl: string;
rawDataURIs: StringMap<string>;
animation: string;
animations: string[];
defaultMix: number;
skin: string;
skins: string[];
premultipliedAlpha: boolean;
showControls: boolean;
showLoading: boolean;
debug: {
bones: boolean;
regions: boolean;
meshes: boolean;
bounds: boolean;
paths: boolean;
clipping: boolean;
points: boolean;
hulls: boolean;
};
viewport: {
x: number;
y: number;
width: number;
height: number;
padLeft: string | number;
padRight: string | number;
padTop: string | number;
padBottom: string | number;
debugRender: boolean;
transitionTime: number;
animations: StringMap<Viewport>;
};
alpha: boolean;
backgroundColor: string;
fullScreenBackgroundColor: string;
backgroundImage: {
url: string;
x: number;
y: number;
width: number;
height: number;
};
mipmaps: true;
controlBones: string[];
success: (player: SpinePlayer) => void;
error: (player: SpinePlayer, msg: string) => void;
frame: (player: SpinePlayer, delta: number) => void;
update: (player: SpinePlayer, delta: number) => void;
draw: (player: SpinePlayer, delta: number) => void;
loading: (player: SpinePlayer, delta: number) => void;
downloader: Downloader;
}
export interface Viewport {
x: number;
y: number;
width: number;
height: number;
padLeft: string | number;
padRight: string | number;
padTop: string | number;
padBottom: string | number;
}
export declare class SpinePlayer {
private config;
parent: HTMLElement;
dom: HTMLElement;
canvas: HTMLCanvasElement;
context: ManagedWebGLRenderingContext;
sceneRenderer: SceneRenderer;
loadingScreen: LoadingScreen;
assetManager: AssetManager;
bg: Color;
bgFullscreen: Color;
private playerControls;
private timelineSlider;
private playButton;
private skinButton;
private animationButton;
private playTime;
private selectedBones;
private cancelId;
popup: Popup;
error: boolean;
skeleton: Skeleton;
animationState: AnimationState;
paused: boolean;
speed: number;
time: TimeKeeper;
private stopRequestAnimationFrame;
private viewport;
private currentViewport;
private previousViewport;
private viewportTransitionStart;
constructor(parent: HTMLElement | string, config: SpinePlayerConfig);
private validateConfig;
private initialize;
private loadSkeleton;
private setupInput;
play(): void;
pause(): void;
setAnimation(animation: string | Animation, loop?: boolean): TrackEntry;
addAnimation(animation: string | Animation, loop?: boolean, delay?: number): TrackEntry;
setViewport(animation: string | Animation): Animation;
private percentageToWorldUnit;
private calculateAnimationViewport;
private drawFrame;
stopRendering(): void;
private hidePopup;
private showSpeedDialog;
private showAnimationsDialog;
private showSkinsDialog;
private showSettingsDialog;
private showError;
}
declare class Popup {
private id;
private button;
private player;
dom: HTMLElement;
private className;
constructor(id: string, button: HTMLElement, player: SpinePlayer, parent: HTMLElement, htmlContent: string);
hide(id: string): boolean;
show(): void;
}
export {};