mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 10:56:15 -08:00
7 lines
3.9 KiB
JavaScript
7 lines
3.9 KiB
JavaScript
/*!
|
|
* artplayer-helper-iframe.js v1.0.0
|
|
* Github: https://github.com/zhw2590582/ArtPlayer
|
|
* (c) 2017-2022 Harvey Zack
|
|
* Released under the MIT License.
|
|
*/
|
|
!function(e,t,s,n,i){var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},o="function"==typeof r.parcelRequire4dc0&&r.parcelRequire4dc0,a=o.cache||{},c="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function d(t,s){if(!a[t]){if(!e[t]){var n="function"==typeof r.parcelRequire4dc0&&r.parcelRequire4dc0;if(!s&&n)return n(t,!0);if(o)return o(t,!0);if(c&&"string"==typeof t)return c(t);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}l.resolve=function(s){var n=e[t][1][s];return null!=n?n:s},l.cache={};var u=a[t]=new d.Module(t);e[t][0].call(u.exports,l,u,u.exports,this)}return a[t].exports;function l(e){var t=l.resolve(e);return!1===t?{}:d(t)}}d.isParcelRequire=!0,d.Module=function(e){this.id=e,this.bundle=d,this.exports={}},d.modules=e,d.cache=a,d.parent=o,d.register=function(t,s){e[t]=[function(e,t){t.exports=s},{}]},Object.defineProperty(d,"root",{get:function(){return r.parcelRequire4dc0}}),r.parcelRequire4dc0=d;for(var u=0;u<t.length;u++)d(t[u]);var l=d(s);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd&&define((function(){return l}))}({kXBUH:[function(e,t,s){e("@parcel/transformer-js/src/esmodule-helpers.js").defineInteropFlag(s);class n{static postMessage({type:e,data:t,id:s=0}){window.parent.postMessage({type:e,data:t,id:s},"*")}static async onMessage(e){const{type:t,data:s,id:i}=e.data;switch(t){case"commit":try{if(s.match(/\bresolve\((.*?)\)/)){const e=`return new Promise(function(resolve){\n${s}\n})`,t=await new Function(e)();n.postMessage({type:"response",data:t,id:i})}else{const e=new Function(s)();n.postMessage({type:"response",data:e,id:i})}}catch(e){n.postMessage({type:"error",data:e.message,id:i})}break;case"destroy":n.isDestroy||n.destroy()}}static inject(){n.isInject=!0,n.isDestroy=!1,n.postMessage({type:"inject"}),window.addEventListener("message",n.onMessage)}static destroy(){n.isInject=!1,n.isDestroy=!0,n.postMessage({type:"destroy"}),window.removeEventListener("message",n.onMessage)}constructor({iframe:e,url:t}){this.url=t,this.$iframe=e,this.promises={},this.isInject=!1,this.isDestroy=!1,this.messageCallback=()=>null,this.onMessage=this.onMessage.bind(this),window.addEventListener("message",this.onMessage),this.$iframe.src=this.url}onMessage(e){const{type:t,data:s,id:n}=e.data;switch(t){case"inject":this.isInject=!0;break;case"destroy":this.isInject=!1,this.isDestroy||this.destroy()}this.promises[n]&&("error"===t?this.promises[n].reject(new Error(s)):this.promises[n].resove(s),delete this.promises[n]),this.messageCallback&&this.messageCallback({type:t,data:s})}postMessage({type:e,data:t}){return new Promise(((s,n)=>{(function i(){if(this.isInject){const i=Date.now();this.promises[i]={resove:s,reject:n},this.$iframe.contentWindow.postMessage({type:e,data:t,id:i},"*")}else this.isDestroy||setTimeout(i.bind(this),200)}).call(this)}))}commit(e){const t=e.toString(),s=t.substring(t.indexOf("{")+1,t.lastIndexOf("}"));return this.postMessage({type:"commit",data:s})}message(e){this.messageCallback=e}destroy(){this.isDestroy=!0,window.removeEventListener("message",this.onMessage)}}s.default=n,"undefined"!=typeof window&&(window.ArtplayerHelperIframe=n)},{"@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],"9pCYc":[function(e,t,s){s.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},s.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},s.exportAll=function(e,t){return Object.keys(e).forEach((function(s){"default"===s||"__esModule"===s||t.hasOwnProperty(s)||Object.defineProperty(t,s,{enumerable:!0,get:function(){return e[s]}})})),t},s.export=function(e,t,s){Object.defineProperty(e,t,{enumerable:!0,get:s})}},{}]},["kXBUH"],"kXBUH"); |