Skip to content

Commit

Permalink
feat: add base lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokrip committed Feb 8, 2025
1 parent 54909c2 commit a84d4b2
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/core/Echo.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
import { Effect } from "../types/enum/effect";

class Echo implements IEcho {
private defaultOptions: EchoDefaultOptions
private echoEffects: IEchoEffect;
private echoAudio: IEchoAudio;
private echoVibration: IEchoVibration;

constructor(defaultOptions = {}) {
this.defaultOptions = {
visualEffect: "wave",
visualEffect: Effect.WAVE,
sound: null,
delay: 0,
vibration: false,
duration: 500,
color: "#3498db",
size: 100,
...defaultOptions,
}

this.echoEffects = new EchoEffects();
this.echoAudio = new EchoAudio();
this.echoVibration = new EchoVibration();
}

public trigger(element: HTMLElement, options: TriggerOptions): void {
const config = {...this.defaultOptions, ...options};

setTimeout(() => {
if(config.visualEffect)
this.echoEffects._createVisualEffect(element, config)
if(config.sound) {
this.echoAudio._playSound(config.sound);
}
if(config.vibration) {
this.echoVibration._triggerVibration();
}

}, config.delay)
}
}

export default Echo;
5 changes: 5 additions & 0 deletions lib/core/EchoAudio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class EchoAudio implements IEchoAudio {
_playSound(soundUrl: string): void {

}
}
3 changes: 3 additions & 0 deletions lib/core/EchoError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class EchoError {

}
3 changes: 3 additions & 0 deletions lib/core/EchoVibration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class EchoVibration implements IEchoVibration{
_triggerVibration() {}
}
7 changes: 7 additions & 0 deletions lib/types/core/EchoAudio.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface IEchoAudio {
/**
* Проигрывает звук
* @param {string} soundUrl
*/
_playSound(soundUrl: string): void;
}
Empty file added lib/types/core/EchoError.d.ts
Empty file.
6 changes: 6 additions & 0 deletions lib/types/core/EchoVibration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface IEchoVibration {
/**
* Включает вибрацию на мобильных устройствах
*/
_triggerVibration(): void;
}
4 changes: 4 additions & 0 deletions lib/types/echo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ interface EchoDefaultOptions {
*/
delay: number;
/**
* Включение вибрации на мобильных
*/
vibration: boolean;
/**
* Длительность эффекта в мс
*/
duration: number;
Expand Down
5 changes: 5 additions & 0 deletions lib/types/enum/effect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum Effect {
WAVE = "wave",
PULSE = "pulse",
FLASH = "flash"
}

0 comments on commit a84d4b2

Please sign in to comment.