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,EAC7B,OAAO,KAAK,WAAa,KAAK,UAAY,EAAO,CAClD,CAED,YAAI,GACF,OAAO,KAAK,SACb,CAED,UAAI,GACF,OAAO,KAAK,OACb,CAEM,GAAI,EAAsB,GAC/B,KAAK,SAAS,GAAG,EAAW,EAC7B,CAEM,IAAK,EAAsB,GAChC,KAAK,SAAS,IAAI,EAAW,EAC9B,E","file":"/npm/tiny-timer@1.6.0/dist/tiny-timer.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/tiny-timer@1.6.0/dist/tiny-timer.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import mitt, { EventType, Handler } from 'mitt'\n\ntype Status = 'running' | 'paused' | 'stopped'\n\nclass Timer {\n  private _interval: number\n  private _stopwatch: boolean\n  private _duration: number = 0\n  private _endTime: number = 0\n  private _pauseTime: number = 0\n  private _status: Status = 'stopped'\n  private _timeoutID?: NodeJS.Timeout\n  private _emitter = mitt()\n\n  constructor ({ interval = 1000, stopwatch = false } = {}) {\n    this._interval = interval\n    this._stopwatch = stopwatch\n  }\n\n  public start (duration: number, interval?: number) {\n    if (this.status !== 'stopped') return\n    if (duration == null) {\n      throw new TypeError('Must provide duration parameter')\n    }\n    this._duration = duration\n    this._endTime = Date.now() + duration\n    this._changeStatus('running')\n    this._emitter.emit('tick', this._stopwatch ? 0 : this._duration)\n    this._timeoutID = setInterval(this.tick, interval || this._interval)\n  }\n\n  public stop () {\n    if (this._timeoutID) clearInterval(this._timeoutID)\n    this._changeStatus('stopped')\n  }\n\n  public pause () {\n    if (this.status !== 'running') return\n    this._pauseTime = Date.now()\n    this._changeStatus('paused')\n  }\n\n  public resume () {\n    if (this.status !== 'paused') return\n    this._endTime += Date.now() - this._pauseTime\n    this._pauseTime = 0\n    this._changeStatus('running')\n  }\n\n  private _changeStatus (status: Status) {\n    this._status = status\n    this._emitter.emit('statusChanged', this.status)\n  }\n\n  private tick = () => {\n    if (this.status === 'paused') return\n    if (Date.now() >= this._endTime) {\n      this.stop()\n      this._emitter.emit('tick', this._stopwatch ? this._duration : 0)\n      this._emitter.emit('done')\n    } else {\n      this._emitter.emit('tick', this.time)\n    }\n  }\n\n  get time () {\n    if (this.status === 'stopped') return 0\n    const time = this.status === 'paused' ? this._pauseTime : Date.now()\n    const left = this._endTime - time\n    return this._stopwatch ? this._duration - left : left\n  }\n\n  get duration () {\n    return this._duration\n  }\n\n  get status () {\n    return this._status\n  }\n\n  public on (eventName: EventType, handler: Handler<any>) {\n    this._emitter.on(eventName, handler)\n  }\n\n  public off (eventName: EventType, handler: Handler<any>) {\n    this._emitter.off(eventName, handler)\n  }\n}\n\nexport default Timer\n"]}