{"version":3,"file":"live-dvr-time-display.cjs","names":["videojs","version","VJSCurrentTimeDisplay","getComponent","CurrentTimeDisplay","ready","player","on","setTimeout","updateTextNode_","e","updateContent","time","scrubbing","getCache","currentTime","liveTracker","isLive","Date","now","Math","abs","liveCurrentTime","toTimeString","slice","formattedTime_","VERSION","registerComponent","videojs","version","VJSTimeTooltip","getComponent","TimeTooltip","updateTime","seekBarRect","seekBarPoint","time","cb","rafId_","cancelAnimationFrame","requestAnimationFrame","content","formatTime","player_","liveTracker","isLive","liveWindow","player","seekBarTime","Date","now","Math","abs","toTimeString","slice","update","VERSION","registerComponent"],"sources":["../package.json","../src/current-time-display.js","../src/time-tooltip.js"],"sourcesContent":["{\n  \"name\": \"@srgssr/live-dvr-time-display\",\n  \"version\": \"1.0.0\",\n  \"license\": \"MIT\",\n  \"author\": \"SRG SSR\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/SRGSSR/pillarbox-web-suite.git\"\n  },\n  \"publishConfig\": {\n    \"access\": \"public\"\n  },\n  \"homepage\": \"https://github.com/SRGSSR/pillarbox-web-suite/tree/main/packages/live-dvr-time-display#readme\",\n  \"type\": \"module\",\n  \"main\": \"dist/live-dvr-time-display.cjs\",\n  \"browser\": \"dist/live-dvr-time-display.umd.min.js\",\n  \"module\": \"dist/live-dvr-time-display.js\",\n  \"style\": \"./dist/live-dvr-time-display.min.css\",\n  \"exports\": {\n    \".\": {\n      \"import\": \"./dist/live-dvr-time-display.js\",\n      \"require\": \"./dist/live-dvr-time-display.cjs\"\n    },\n    \"./*\": \"./*\"\n  },\n  \"files\": [\n    \"dist/*\",\n    \"scss/*\"\n  ],\n  \"keywords\": [\n    \"video.js\",\n    \"player\"\n  ],\n  \"scripts\": {\n    \"clean\": \"rimraf dist\",\n    \"build\": \"npm-run-all clean build:*\",\n    \"build:css\": \"sass ./scss/live-dvr-time-display.scss:dist/live-dvr-time-display.min.css --style compressed --source-map --load-path node_modules\",\n    \"build:lib\": \"vite build --config vite.config.lib.js\",\n    \"build:umd\": \"vite build --config vite.config.umd.js\",\n    \"github:page\": \"vite build\",\n    \"release:ci\": \"semantic-release\",\n    \"start\": \" vite --port 4200 --open\",\n    \"test\": \"vitest run --silent --coverage --coverage.reporter text\"\n  },\n  \"peerDependencies\": {\n    \"video.js\": \"^8.0.0\"\n  },\n  \"devDependencies\": {\n    \"@srgssr/pillarbox-web\": \"^1.24.1\"\n  }\n}\n","import videojs from 'video.js';\nimport { version } from '../package.json';\n\n/**\n* @ignore\n* @type {typeof import('video.js/dist/types/control-bar/time-controls/current-time-display').default}\n*/\nconst VJSCurrentTimeDisplay = videojs.getComponent('CurrentTimeDisplay');\n\n/**\n * Displays the current time\n *\n * @extends VJSCurrentTimeDisplay\n */\nclass CurrentTimeDisplay extends VJSCurrentTimeDisplay {\n  ready() {\n    this.player().on('durationchange', () => {\n      setTimeout(() => {\n        this.updateTextNode_(0);\n      }, 1);\n    });\n    this.on(this.player(), 'seeking', (e) => {\n      this.updateContent(e);\n    });\n  }\n\n  /**\n   * @override\n   */\n  updateContent() {\n    let time = (this.player().scrubbing())\n      ? this.player().getCache().currentTime\n      : this.player().currentTime();\n\n    if (this.player().liveTracker && this.player().liveTracker.isLive()) {\n      time = new Date(\n        (Date.now() - Math.abs(\n          this.player().liveTracker.liveCurrentTime() -\n          this.player().currentTime()\n        ) * 1000)\n      ).toTimeString().slice(0, 5);\n\n      this.updateTextNode_(time);\n      // Avoid overriding updateTextNode_ to have the time formatted in hours e.g 00:00\n      this.formattedTime_ = time;\n\n      return;\n    }\n\n    this.updateTextNode_(time);\n  }\n\n  static get VERSION() {\n    return version;\n  }\n}\n\nvideojs.registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);\n\nexport default CurrentTimeDisplay;\n","import videojs from 'video.js';\nimport { version } from '../package.json';\n\n/**\n* @ignore\n* @type {typeof import('video.js/dist/types/control-bar/progress-control/time-tooltip').default}\n*/\nconst VJSTimeTooltip = videojs.getComponent('TimeTooltip');\n\n/**\n * Time tooltips display a time above the progress bar.\n *\n * @extends VJSTimeTooltip\n */\nclass TimeTooltip extends VJSTimeTooltip {\n  /**\n   * @override\n   */\n  updateTime(seekBarRect, seekBarPoint, time, cb) {\n    if (this.rafId_) {\n      this.cancelAnimationFrame(this.rafId_);\n    }\n\n    this.rafId_ = this.requestAnimationFrame(() => {\n      let content = videojs.time.formatTime(time);\n\n      if (this.player_.liveTracker && this.player_.liveTracker.isLive()) {\n        const liveWindow = this.player().liveTracker.liveWindow();\n        const seekBarTime = seekBarPoint ? liveWindow * seekBarPoint : 0;\n\n        content = new Date(\n          (Date.now() - Math.abs(\n            liveWindow - seekBarTime\n          ) * 1000)\n        ).toTimeString().slice(0, 8);\n      }\n\n      this.update(seekBarRect, seekBarPoint, content);\n\n      if (cb) {\n        cb();\n      }\n    });\n  }\n\n  static get VERSION() {\n    return version;\n  }\n}\n\nvideojs.registerComponent('TimeTooltip', TimeTooltip);\n\nexport default TimeTooltip;\n"],"mappings":"qiBCOME,EAAwBF,EAAAA,QAAQG,aAAa,oBAAoB,EAOjEC,EAAN,cAAiCF,CAAsB,CACrDG,OAAQ,CACN,KAAKC,OAAO,CAAC,CAACC,GAAG,qBAAwB,CACvCC,eAAiB,CACf,KAAKC,gBAAgB,CAAC,CACxB,EAAG,CAAC,CACN,CAAC,EACD,KAAKF,GAAG,KAAKD,OAAO,EAAG,UAAYI,GAAM,CACvC,KAAKC,cAAcD,CAAC,CACtB,CAAC,CACH,CAKAC,eAAgB,CACd,IAAIC,EAAQ,KAAKN,OAAO,CAAC,CAACO,UAAU,EAChC,KAAKP,OAAO,CAAC,CAACQ,SAAS,CAAC,CAACC,YACzB,KAAKT,OAAO,CAAC,CAACS,YAAY,EAE9B,GAAI,KAAKT,OAAO,CAAC,CAACU,aAAe,KAAKV,OAAO,CAAC,CAACU,YAAYC,OAAO,EAAG,CACnEL,EAAO,IAAIM,KACRA,KAAKC,IAAI,EAAIC,KAAKC,IACjB,KAAKf,OAAO,CAAC,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