1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.wechatH5Video=n():t.wechatH5Video=n()}(window,function(){return function(t){var n={};function e(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:i})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(e.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(i,o,function(n){return t[n]}.bind(null,o));return i},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s="tjUo")}({"9tPo":function(t,n){t.exports=function(t){var n="undefined"!=typeof window&&window.location;if(!n)throw new Error("fixUrls requires window.location");if(!t||"string"!=typeof t)return t;var e=n.protocol+"//"+n.host,i=e+n.pathname.replace(/\/[^\/]*$/,"/");return t.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(t,n){var o,r=n.trim().replace(/^"(.*)"$/,function(t,n){return n}).replace(/^'(.*)'$/,function(t,n){return n});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(r)?t:(o=0===r.indexOf("//")?r:0===r.indexOf("/")?e+r:i+r.replace(/^\.\//,""),"url("+JSON.stringify(o)+")")})}},FdW2:function(t,n,e){(n=t.exports=e("I1BE")(!1)).push([t.i,"._1xwULLzOHv {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 999;\n /* display: none; */\n background-color: black;\n overflow: hidden;\n}\n\n.UXTJH12jSj {\n position: absolute;\n left: -100%;\n top: -100%;\n right: -100%;\n bottom: -100%;\n margin: auto;\n z-index: 1;\n overflow: hidden;\n background-color: black;\n transform-origin: 50% 50%;\n}\n\n.P9ADzOFtys {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: -1;\n /* object-fit: fill;\n object-position: 50% 50%; */\n}\n\n._3yeOA1YF-a {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n}\n\n.LavftRexGF {\n width: 100%;\n height: 100%;\n position: absolute;\n background: transparent no-repeat;\n background-size: cover;\n z-index: 99;\n}\n\n.HgFlCSREpq {\n position: absolute;\n left: -100%;\n top: -100%;\n right: -100%;\n bottom: -100%;\n z-index: 1000;\n margin: auto;\n max-width: 60px;\n max-height: 60px;\n opacity: .6;\n}\n\n.HgFlCSREpq svg{\n max-width: 60px;\n max-height: 60px;\n fill: #fff;\n}\n\n._1CKERg-CKj {\n display: none;\n color: #fff;\n position: absolute;\n top: 20px;\n right: 20px;\n z-index: 1000;\n}",""]),n.locals={container:"_1xwULLzOHv",wrapper:"UXTJH12jSj",video:"P9ADzOFtys",mask:"_3yeOA1YF-a",poster:"LavftRexGF",playBtn:"HgFlCSREpq",jumpBtn:"_1CKERg-CKj"}},I1BE:function(t,n){t.exports=function(t){var n=[];return n.toString=function(){return this.map(function(n){var e=function(t,n){var e=t[1]||"",i=t[3];if(!i)return e;if(n&&"function"==typeof btoa){var o=(s=i,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(s))))+" */"),r=i.sources.map(function(t){return"/*# sourceURL="+i.sourceRoot+t+" */"});return[e].concat(r).concat([o]).join("\n")}var s;return[e].join("\n")}(n,t);return n[2]?"@media "+n[2]+"{"+e+"}":e}).join("")},n.i=function(t,e){"string"==typeof t&&(t=[[null,t,""]]);for(var i={},o=0;o<this.length;o++){var r=this[o][0];"number"==typeof r&&(i[r]=!0)}for(o=0;o<t.length;o++){var s=t[o];"number"==typeof s[0]&&i[s[0]]||(e&&!s[2]?s[2]=e:e&&(s[2]="("+s[2]+") and ("+e+")"),n.push(s))}},n}},"aET+":function(t,n,e){var i,o,r={},s=(i=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===o&&(o=i.apply(this,arguments)),o}),a=function(t){var n={};return function(t,e){if("function"==typeof t)return t();if(void 0===n[t]){var i=function(t,n){return n?n.querySelector(t):document.querySelector(t)}.call(this,t,e);if(window.HTMLIFrameElement&&i instanceof window.HTMLIFrameElement)try{i=i.contentDocument.head}catch(t){i=null}n[t]=i}return n[t]}}(),c=null,u=0,p=[],l=e("9tPo");function d(t,n){for(var e=0;e<t.length;e++){var i=t[e],o=r[i.id];if(o){o.refs++;for(var s=0;s<o.parts.length;s++)o.parts[s](i.parts[s]);for(;s<i.parts.length;s++)o.parts.push(w(i.parts[s],n))}else{var a=[];for(s=0;s<i.parts.length;s++)a.push(w(i.parts[s],n));r[i.id]={id:i.id,refs:1,parts:a}}}}function h(t,n){for(var e=[],i={},o=0;o<t.length;o++){var r=t[o],s=n.base?r[0]+n.base:r[0],a={css:r[1],media:r[2],sourceMap:r[3]};i[s]?i[s].parts.push(a):e.push(i[s]={id:s,parts:[a]})}return e}function f(t,n){var e=a(t.insertInto);if(!e)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var i=p[p.length-1];if("top"===t.insertAt)i?i.nextSibling?e.insertBefore(n,i.nextSibling):e.appendChild(n):e.insertBefore(n,e.firstChild),p.push(n);else if("bottom"===t.insertAt)e.appendChild(n);else{if("object"!=typeof t.insertAt||!t.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var o=a(t.insertAt.before,e);e.insertBefore(n,o)}}function v(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t);var n=p.indexOf(t);n>=0&&p.splice(n,1)}function m(t){var n=document.createElement("style");if(void 0===t.attrs.type&&(t.attrs.type="text/css"),void 0===t.attrs.nonce){var i=function(){0;return e.nc}();i&&(t.attrs.nonce=i)}return y(n,t.attrs),f(t,n),n}function y(t,n){Object.keys(n).forEach(function(e){t.setAttribute(e,n[e])})}function w(t,n){var e,i,o,r;if(n.transform&&t.css){if(!(r="function"==typeof n.transform?n.transform(t.css):n.transform.default(t.css)))return function(){};t.css=r}if(n.singleton){var s=u++;e=c||(c=m(n)),i=x.bind(null,e,s,!1),o=x.bind(null,e,s,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(e=function(t){var n=document.createElement("link");return void 0===t.attrs.type&&(t.attrs.type="text/css"),t.attrs.rel="stylesheet",y(n,t.attrs),f(t,n),n}(n),i=function(t,n,e){var i=e.css,o=e.sourceMap,r=void 0===n.convertToAbsoluteUrls&&o;(n.convertToAbsoluteUrls||r)&&(i=l(i));o&&(i+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var s=new Blob([i],{type:"text/css"}),a=t.href;t.href=URL.createObjectURL(s),a&&URL.revokeObjectURL(a)}.bind(null,e,n),o=function(){v(e),e.href&&URL.revokeObjectURL(e.href)}):(e=m(n),i=function(t,n){var e=n.css,i=n.media;i&&t.setAttribute("media",i);if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}.bind(null,e),o=function(){v(e)});return i(t),function(n){if(n){if(n.css===t.css&&n.media===t.media&&n.sourceMap===t.sourceMap)return;i(t=n)}else o()}}t.exports=function(t,n){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(n=n||{}).attrs="object"==typeof n.attrs?n.attrs:{},n.singleton||"boolean"==typeof n.singleton||(n.singleton=s()),n.insertInto||(n.insertInto="head"),n.insertAt||(n.insertAt="bottom");var e=h(t,n);return d(e,n),function(t){for(var i=[],o=0;o<e.length;o++){var s=e[o];(a=r[s.id]).refs--,i.push(a)}t&&d(h(t,n),n);for(o=0;o<i.length;o++){var a;if(0===(a=i[o]).refs){for(var c=0;c<a.parts.length;c++)a.parts[c]();delete r[a.id]}}}};var b,g=(b=[],function(t,n){return b[t]=n,b.filter(Boolean).join("\n")});function x(t,n,e,i){var o=e?"":i.css;if(t.styleSheet)t.styleSheet.cssText=g(n,o);else{var r=document.createTextNode(o),s=t.childNodes;s[n]&&t.removeChild(s[n]),s.length?t.insertBefore(r,s[n]):t.appendChild(r)}}},p2bk:function(t,n,e){var i=e("FdW2");"string"==typeof i&&(i=[[t.i,i,""]]);var o={hmr:!0,transform:void 0,insertInto:void 0};e("aET+")(i,o);i.locals&&(t.exports=i.locals)},tjUo:function(t,n,e){"use strict";e.r(n),e.d(n,"default",function(){return r});var i=e("p2bk"),o=e.n(i),r=function(){function t(t,n){if(!t)throw new Error("缺少媒体路径参数source");if(!n.context)throw new Error("缺少容器参数context");this.options=Object.assign({context:null,preload:!0,mask:!0,poster:null,playBtn:!0,jumpBtn:!1,autoClose:!1,canvas:!1,fill:!0,orientation:"portrait",isRotate:!0,onPlay:function(){},onPause:function(){},onEnd:function(){}},n),this.source=t,this.context=c(this.options.context)?document.getElementById(this.options.context):this.options.context,this.orientation=null,this.container=null,this.video=null,this.mask=null,this.poster=null,this.playBtn=null,this.jumpBtn=null,this.canvas=null,this.canvasCtx=null,this.timer=null,this.initContainer(),this.initWrapper(),this.options.preload&&this.init()}var n=t.prototype;return n.init=function(){this.context.appendChild(this.container),this.video=this.getVideo(),this.options.canvas&&this._videoToCavas(),this.options.fill?this._fillResize():this._handleResize()},n.initContainer=function(){this.container=document.createElement("div"),this.container.classList.add(o.a.container)},n.initWrapper=function(){this.wrapper=document.createElement("div"),this.wrapper.classList.add(o.a.wrapper),this.wrapper.innerHTML="\n <video\n autoPlay\n muted\n class="+o.a.video+'\n style="'+(this.options.fill?"object-fit: fill;object-position: 50% 50%;":"")+'"\n width="100%"\n preload="true"\n x-webkit-airplay="allow",\n webkit-playsinline="true",\n playsinline="true",\n x5-video-player-type="h5",\n x5-video-player-fullscreen="true",\n x5-video-orientation="'+this.options.orientation+'"\n >\n '+(this.source instanceof Object?'<source src="'+this.source.url+'" type="video/'+this.source.type+'"></source>':'<source src="'+this.source+'"></source>')+"\n </video>\n ",this.container.appendChild(this.wrapper),this.options.mask&&this._initMask(),this.options.poster&&this._initPoster(),this.options.playBtn&&this._initPlayBtn(),this.options.jumpBtn&&this._initeJumpBtn()},n._initMask=function(){this.mask=document.createElement("div"),this.mask.classList.add(o.a.mask),this.container.appendChild(this.mask)},n._initPoster=function(){this.poster=document.createElement("div"),this.poster.classList.add(o.a.poster),this.poster.style.backgroundImage="url('"+this.options.poster+"')",this.container.appendChild(this.poster)},n._initPlayBtn=function(){this.playBtn=document.createElement("div"),this.playBtn.classList.add(o.a.playBtn),this.playBtn.innerHTML='\n <svg viewBox="0 0 64 64">\n <path d="M26,45.5L44,32L26,18.6v27V45.5L26,45.5z M32,2C15.4,2,2,15.5,2,32c0,16.6,13.4,30,30,30c16.6,0,30-13.4,30-30 C62,15.4,48.5,2,32,2L32,2z M32,56c-9.7,0-18.5-5.9-22.2-14.8C6.1,32.2,8.1,21.9,15,15c6.9-6.9,17.2-8.9,26.2-5.2 C50.1,13.5,56,22.3,56,32C56,45.3,45.2,56,32,56L32,56z" />\n </svg>\n ',this.container.appendChild(this.playBtn)},n._initeJumpBtn=function(){this.jumpBtn=document.createElement("div"),this.jumpBtn.classList.add(o.a.jumpBtn),this.jumpBtn.innerHTML="跳过视频>>",this.container.appendChild(this.jumpBtn)},n.getVideo=function(){return this.wrapper.querySelector("."+o.a.video)},n.load=function(){return this.context.contains(this.container)||this.init(),this._addEvent(),this.video.load(),this},n.play=function(){this.video.play(),this.options.onPlay();var t=this;t.video.isPlayed=!1,t.video.addEventListener("timeupdate",function(){!t.video.isPlayed&&this.currentTime>.1&&(t.video.isPlayed=!0,t.options.canvas&&t._drawCavas(),t._hiddenPoster(),t._hiddenPlayBtn(),t._showJumpBtn())})},n.pause=function(){this.video.pause(),this._showPlayBtn(),this._hideJumpBtn(),this.options.onPause(),this.options.canvas&&l(this.timer)},n._hiddenPoster=function(){this.poster&&(this.poster.style.display="none")},n._showPoster=function(){this.poster&&(this.poster.style.display="block")},n._hiddenPlayBtn=function(){this.playBtn&&(this.playBtn.style.display="none")},n._showPlayBtn=function(){this.playBtn&&(this.playBtn.style.display="block")},n._showJumpBtn=function(){this.jumpBtn&&(this.jumpBtn.style.display="block")},n._hideJumpBtn=function(){this.jumpBtn&&(this.jumpBtn.style.display="none")},n._remove=function(){this.context.removeChild(this.container)},n._reload=function(){this.video.currentTime=0,this.pause(),this._showPoster()},n._addEvent=function(){var t=this;this.options.playBtn&&this.playBtn.addEventListener("click",function(){t.play()},!1),this.options.mask&&this.mask.addEventListener("click",function(){t.options.onEnd(),t._remove()},!1),this.options.jumpBtn&&this.jumpBtn.addEventListener("click",function(){t.options.onEnd(),t.options.autoClose?t._remove():t._reload(),t.options.canvas&&l(t.timer)},!1),this.video.addEventListener("ended",function(){t.options.onEnd(),t._showPlayBtn(),t.options.autoClose?t._remove():t._reload(),t.options.canvas&&l(t.timer)},!1),window.onresize=function(){setTimeout(function(){s(t.wrapper,{width:window.innerWidth+"px",height:window.innerHeight+"px"}),t.options.canvas&&s(t.canvas,{width:window.innerWidth+"px",height:window.innerHeight+"px"})},200)}},n._containerRect=function(){return this.container.getBoundingClientRect()},n._handleResize=function(){var t=window.innerWidth,n=window.innerHeight-16*t/9;n=Math.round(n),this.video.style.marginTop=n/2+"px"},n._fillResize=function(){var t=this,n=function(){var n=t._containerRect().width,e=t._containerRect().height;a()===t.options.orientation?(s(t.wrapper,{width:n+"px",height:e+"px",transform:""}),t.options.canvas&&s(t.canvas,{width:n+"px",height:e+"px",transform:""})):(s(t.wrapper,{width:e+"px",height:n+"px",transform:"rotate(-90deg)"}),t.options.canvas&&s(t.canvas,{width:e+"px",height:n+"px"}))};this.options.isRotate?(n(),window.addEventListener(u,function t(){window.removeEventListener(u,t),setTimeout(function(){n(),window.addEventListener(u,t,!1)},400)},!1)):s(this.wrapper,{width:this._containerRect().width+"px",height:this._containerRect().height+"px"})},n._videoToCavas=function(){this.video&&(this.canvas=document.createElement("canvas"),this.canvas.width=this._containerRect().width,this.canvas.height=this._containerRect().height,this.canvasCtx=this.canvas.getContext("2d"),this.video.parentNode.replaceChild(this.canvas,this.video))},n._drawCavas=function(){var t=this;this.canvasCtx.drawImage(this.video,0,0,this.canvas.width,this.canvas.height),this.timer=p(function(){t._drawCavas()})},t}(),s=function(t,n){for(var e in n)t.style[e]=n[e]},a=function(){return document.documentElement.clientWidth>document.documentElement.clientHeight?"landscape":"portrait"},c=function(t){return"string"==typeof t&&t.constructor===String},u="onorientationchange"in window?"orientationchange":"resize",p=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,l=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame}}).default}); |