//#region src/characters/types.d.ts interface SakanaWidgetState { /** inertia */ i: number; /** stickiness */ s: number; /** decay */ d: number; /** angle */ r: number; /** height */ y: number; /** vertical speed */ t: number; /** horizontal speed */ w: number; } interface SakanaWidgetCharacter { image: string; initialState: SakanaWidgetState; } //#endregion //#region src/core.d.ts type SakanaWidgetVisibility = 'show' | 'hide'; interface SakanaWidgetOptions { /** * widget size, default to `200` */ size?: number; /** * auto fit size (120px minimum), default to `false` */ autoFit?: boolean; /** * default character, default to `chisato` */ character?: 'chisato' | 'takina' | string; /** * how the character image fits its square area, default to `cover` */ imageFit?: 'cover' | 'contain'; /** * controls bar, default to `true` */ controls?: boolean; /** * show spring rod, default to `true` */ rod?: boolean; /** * character draggable, default to `true` */ draggable?: boolean; /** * rod color and width, default to `#b4b4b4` & `10` */ stroke?: { color?: string; width?: number; }; /** * motion stop threshold, default to `0.1` */ threshold?: number; /** * rotate origin, default to `0` */ rotate?: number; /** * enable accessibility title feature, default to `false` */ title?: boolean; /** * enable persistent hide state via localStorage, default to `false` */ saveState?: boolean; /** * localStorage key for persist state, default to `sakana-widget-status` */ stateKey?: string; } interface SakanaWidgetControl { /** Unique identifier within this widget instance. */ id: string; /** Accessible label for the icon button; never displayed as button text. */ label: string; /** DOM icon. The widget clones it before inserting it. */ icon: Element; onClick: (widget: SakanaWidget, event: MouseEvent) => void; } /** * widget instance class */ declare class SakanaWidget { private _options; private _imageSize; private _limit; private _lastFrameTime; private _frameRequestId; private _running; private _mounted; private _dragging; private _stopDrag; private _magicForceTimeout; private _magicForceEnabled; private _saveState; private _stateKey; private _hidden; private _stateListeners; private _char; private _image; private _state; private _domWrapper; private _domApp; private _domRod; private _domMain; private _domImage; private _domCtrl; private _domCtrlPerson; private _domCtrlMagic; private _domCtrlClose; private _customControls; private _mountElement; private _resizeObserver; /** * @public * @static * get data of a registered character */ static getCharacter: (name: string) => SakanaWidgetCharacter | null; /** * @public * @static * get all registered character */ static getCharacters: () => Record; /** * @public * @static * registered a new character */ static registerCharacter: (name: string, character: SakanaWidgetCharacter) => void; constructor(options?: SakanaWidgetOptions); /** * @private * calculate limit and update from size */ private _updateLimit; /** * @private * refresh widget size */ private _updateSize; /** * @private * create widget dom elements */ private _updateDom; /** * @private * calculate center of the image */ private _calcCenterPoint; /** * @private * draw a frame */ private _draw; private _scheduleFrame; private _startAnimation; private _stopAnimation; /** * @private * run the widget in animation frame */ private _run; /** * @private * manually move the widget */ private _move; /** * @private * handle mouse down event */ private _onMouseDown; /** * @private * handle touch start event */ private _onTouchStart; /** * @private * do a force on widget (for auto mode) */ private _magicForce; /** * @public * switch the auto mode */ private _setAutoMode; triggerAutoMode: () => void; /** * @public * set current state of widget */ setState: (state: Partial) => this; /** * @public * set current character of widget */ setCharacter: (name: string) => this; /** * @public * set to next character of widget */ nextCharacter: () => this; /** * @public * add a custom control to this widget's control bar */ addControl: (control: SakanaWidgetControl) => this; /** * @public * remove a previously added custom control */ removeControl: (id: string) => this; /** * @private * control widget visibility and persist state */ private _saveHiddenState; private _getSavedHiddenState; private _setHidden; /** * @public * hide the widget (stops animation, persists state if saveState is enabled) */ hide: () => this; /** * @public * show the widget if previously hidden */ show: () => this; /** * @public * add a listener for widget visibility changes */ addStateListener: (listener: (state: SakanaWidgetVisibility) => void) => this; /** * @public * remove a previously added state listener */ removeStateListener: (listener: (state: SakanaWidgetVisibility) => void) => this; /** * @private * handle widget resize */ private _onResize; /** * @public * mount the widget */ mount: (el: HTMLElement | string) => this; /** * @public * unmount the widget */ unmount: () => this; } //#endregion export { type SakanaWidgetCharacter, type SakanaWidgetControl, type SakanaWidgetOptions, type SakanaWidgetState, type SakanaWidgetVisibility, SakanaWidget as default };