videojs-sprite-thumbnails
Version:
Plugin to display thumbnails from a sprite image when hovering over the progress bar.
3 lines (2 loc) • 3.69 kB
JavaScript
/*! @name videojs-sprite-thumbnails @version 0.6.0 @license MIT */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js"),require("global/window")):"function"==typeof define&&define.amd?define(["video.js","global/window"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).videojsSpriteThumbnails=t(e.videojs,e.window)}(this,(function(e,t){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=o(e),r=o(t);function i(e,t,o){return e(o={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&o.path)}},o.exports),o.exports}var u=i((function(e){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e},e.exports.default=e.exports,e.exports.__esModule=!0})),a=i((function(e){function t(o,n){return e.exports=t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},e.exports.default=e.exports,e.exports.__esModule=!0,t(o,n)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0})),s=i((function(e){e.exports=function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,a(e,t)},e.exports.default=e.exports,e.exports.__esModule=!0})),l=n.default.getPlugin("plugin"),p={url:"",width:0,height:0,interval:1,responsive:600,downlink:2},d=function(e){function t(t,o){var i;i=e.call(this,t)||this;var a=u(i),s=a.log;return a.options=n.default.mergeOptions(p,o),a.setState({ready:!1}),a.on("statechanged",(function(){s.debug("will"+(a.state.ready?"":" not")+" show thumbnails")})),a.player.ready((function(){!function(e,t,o){var i=o.url,u=o.height,a=o.width,s=!1,l={},p=n.default.dom||n.default,d=e.controlBar,c=d&&d.progressControl,f=c&&c.seekBar,h=f&&f.mouseTimeDisplay&&f.mouseTimeDisplay.timeTooltip,g=function(e){var t=h.el().style;Object.keys(e).forEach((function(o){var n=e[o];""!==n?t.setProperty(o,n):t.removeProperty(o)}))},x=function(){g({width:"",height:"","background-image":"","background-repeat":"","background-position":"","background-size":"",top:"",color:"","text-shadow":"",border:"",margin:""})},m=function(t){var n=l[i],r=n.naturalWidth,s=n.naturalHeight,c=f.el();if(n.complete&&r&&s){var h=p.getPointerPosition(c,t).x*e.duration();h/=o.interval;var m=o.responsive,b=e.currentWidth(),v=m&&b<m?b/m:1,w=r/a,y=a*v,k=u*v,_=Math.floor(h%w)*-y,j=Math.floor(h/w)*-k,P=r*v+"px "+s*v+"px",T=p.findPosition(d.el()).top,M=p.findPosition(c).top,O=-k-Math.max(0,M-T);g({width:y+"px",height:k+"px","background-image":"url("+i+")","background-repeat":"no-repeat","background-position":_+"px "+j+"px","background-size":P,top:O+"px",color:"#fff","text-shadow":"1px 1px #000",border:"1px solid #000",margin:"0 1px"})}else x()},b=function(e){var n=["mousemove","touchmove"],p=r.default,d=p.navigator,f=t.log,g=o.downlink,b=d.connection||d.mozConnection||d.webkitConnection,v=!b||b.downlink>=g,w=h&&(a&&u||e),y=l[i],k=function(e){t.setState({ready:e})};if(h&&x(),w&&(i&&v||y)){var _="loading "+i;y?_="re"+_:(l[i]=new p.Image,l[i].src=i,e&&(s=!0,_="pre"+_)),f.debug(_),c.on(n,m),k(!0)}else e||(c.off(n,m),k(),["url","width","height"].forEach((function(e){o[e]||f("no thumbnails "+e+" given")})),v||f.warn("connection.downlink < "+g))};b(!0),e.on("loadstart",(function(){s?s=!1:(e.currentSources().forEach((function(e){var t=e.spriteThumbnails;t&&(o=n.default.mergeOptions(o,t),i=o.url,u=o.height,a=o.width)})),b())})),e.addClass("vjs-sprite-thumbnails")}(a.player,a,a.options)})),i}return s(t,e),t}(l);return d.defaultState={},d.VERSION="0.6.0",n.default.registerPlugin("spriteThumbnails",d),d}));