You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
20 KiB
JavaScript
1 line
20 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mediaTag=t():e.mediaTag=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=68)}([function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(5),u=n(3),a=n(4),c=function(){function e(){r(this,e)}return i(e,null,[{key:"findRequiredModuleIdentifiers",value:function(t){return o.logics().filter(function(n){return n.apply(t)&&!e.forbiddenIdentifiers.includes(n.identifier)}).map(function(e){return e.identifier})}},{key:"findFilterIdentifiersToRegister",value:function(t){return o.logics().filter(function(n){return n.apply(t)&&!e.forbiddenIdentifiers.includes(n.identifier)}).filter(function(e){return"filter"===e.type}).map(function(e){return e.identifier})}},{key:"findPluginIdentifiersToRegister",value:function(t){return o.logics().filter(function(n){return n.apply(t)&&!e.forbiddenIdentifiers.includes(n.identifier)}).filter(function(e){return"plugin"===e.type}).map(function(e){return e.identifier})}},{key:"searchLogicCollision",value:function(e){var t=e.filter(function(e){return a.plugins().find(function(t){return e.identifier===t.identifier})});return t.length>1?{modules:t}:null}},{key:"findModuleChain",value:function(t){var n=e.findRequiredModuleIdentifiers(t),r=n.map(function(e){var t=u.getFilter(e)||a.getPlugin(e);if(t)return t;throw new Error("Module "+e+" not found")}),i=e.searchLogicCollision(r);if(i){var o=i.modules.map(function(e){return e.identifier});throw new Error("Has collision between ["+o+"]'s logics")}return r}},{key:"startup",value:function(t){if(o.hasLogics()===!1)return void console.warn("Guidelines havn't logics ... The orchestrator cannot do anything !");var n=t.getId();e.chains[n]=e.findModuleChain(t),e.history[n]={identifiers:[e.findRequiredModuleIdentifiers(t)],cycles:{}},e.chains[n].length>0&&e.run(t)}},{key:"coherence",value:function(t){var n=t.getId(),r=e.history[n].identifiers.length-1;if(Object.keys(e.history[n].cycles).some(function(t){return e.history[n].cycles[t]>e.allowedCycles}))throw console.log(e.history[n]),new Error("Maximum cycles exceed "+e.history[n].cycles);var i=e.history[n].identifiers[r-1].every(function(t){return e.history[n].identifiers[r].includes(t)})||e.history[n].identifiers[r-1][0]===e.history[n].identifiers[r][0],o=e.history[n].identifiers[r][0];i&&(console.info('Chain has not evolved since the last module execution, the module "%s" is skipped',o),e.chains[n].shift())}},{key:"run",value:function(t){var n=t.getId();e.chains[n][0]?e.chains[n][0].startup(t):console.warn("Attempts to run a empty chain ...","History : ",e.history[n])}},{key:"chain",value:function(t){e.update(t),e.coherence(t),e.run(t)}},{key:"update",value:function(t){var n=t.getId(),r=e.chains[n].shift();e.findModuleChain(t).filter(function(t){return!e.chains[n].includes(t)}).forEach(function(t){e.chains[n].unshift(t)});var i=e.history[n].cycles[r.identifier];e.history[n].cycles[r.identifier]="number"==typeof i?i+1:1;var o=e.chains[n].map(function(e){return e.identifier});e.history[n].identifiers.push(o)}}]),e}();c.chains={},c.history={},c.allowedCycles=1,c.forbiddenIdentifiers=[],e.exports=c},,,function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"identifiers",value:function(){return Object.keys(e.filtersMap)}},{key:"filters",value:function(){return Object.keys(e.filtersMap).map(function(t){return e.filtersMap[t]})}},{key:"isRegistered",value:function(t){return t.identifier in e.filtersMap}},{key:"register",value:function(t){t&&(e.isRegistered(t)&&console.warn('Filter "'+t.identifier+'" is already registered and will be overwritten'),e.filtersMap[t.identifier]=t)}},{key:"getFilter",value:function(t){return e.filters().find(function(e){return e.identifier===t})}},{key:"findType",value:function(t){var n=void 0;return e.filters().some(function(e){return!!e.typeCheck(t)&&(n=e.identifier,!0)}),n}}]),e}();o.filtersMap={},e.exports=o},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"identifiers",value:function(){return Object.keys(e.pluginsMap)}},{key:"plugins",value:function(){return Object.keys(e.pluginsMap).map(function(t){return e.pluginsMap[t]})}},{key:"isRegistered",value:function(t){return t.identifier in e.pluginsMap}},{key:"register",value:function(t){t&&(e.isRegistered(t)&&console.warn('Plugin "'+t.identifier+'" is already registered and will be overwritten'),e.pluginsMap[t.identifier]=t)}},{key:"getPlugin",value:function(t){return e.plugins().find(function(e){return e.identifier===t})}},{key:"findType",value:function(t){var n=void 0;return e.plugins().some(function(e){return!!e.typeCheck(t)&&(n=e.identifier,!0)}),n}}]),e}();o.pluginsMap={},e.exports=o},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"isRegistered",value:function(t){return e.logicsMap[t.identifier]}},{key:"registerLogic",value:function(t){e.isRegistered(t)?console.warn('The logic "{$logic.identifier}" is already registered'):e.logicsMap[t.identifier]=t}},{key:"registerLogics",value:function(t){var n=!0,r=!1,i=void 0;try{for(var o,u=Object.keys(t)[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var a=o.value;e.registerLogic(t[a])}}catch(e){r=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(r)throw i}}}},{key:"logics",value:function(){return Object.keys(e.logicsMap).map(function(t){return e.logicsMap[t]})}},{key:"hasLogics",value:function(){return Object.keys(e.logicsMap).length>0}}]),e}();o.logicsMap={},e.exports=o},function(e,t,n){"use strict";var r=n(11),i=n(27);r.registerPlugin(i);var o=n(29);r.registerPlugin(o);var u=n(25);r.registerPlugin(u);var a=n(26);r.registerPlugin(a);var c=n(28);r.registerPlugin(c);var s=n(15);r.registerFilter(s);var l=n(14);r.registerFilter(l);var f=n(13);r.registerFilter(f);n(16);e.exports=r},,,function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u={PluginExists:function(e){function t(e){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,'Plugin with same "'+e.identifier+'" identifier found.'))}return o(t,e),t}(Error),TypeNotFound:function(e){function t(){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Media Tag could not find the content type of an instance.}."))}return o(t,e),t}(Error),FilterExists:function(e){function t(e){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,'Filter with same "'+e.identifier+' identifier found."'))}return o(t,e),t}(Error),FetchFail:function(e){function t(e){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,'Could not fetch "'+e.url+'", received "'+e.status+": "+e.statusText+'".'))}return o(t,e),t}(Error),InvalidCryptoKey:function(e){function t(){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Invalid cryptographic key."))}return o(t,e),t}(Error),InvalidCryptoLib:function(e){function t(){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Invalid cryptographic algorithm name."))}return o(t,e),t}(Error),FailedCrypto:function(e){function t(e){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Failed to decrypt file"+(e&&e.message?" "+e.message:"")+"."))}return o(t,e),t}(Error)};e.exports=u},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(t){r(this,e),this.id=e.uid(),this.attributesObject=e.attributesObject(t),this.hookedFns={hasChildNodes:t.hasChildNodes.bind(t),removeChild:t.removeChild.bind(t),getLastChild:function(){return t.lastChild},appendChild:t.appendChild.bind(t)}}return i(e,[{key:"setProperties",value:function(e){for(var t in e){if(this[t])throw new Error("The property "+t+" already exists in this MediaObject !");this[t]=e[t]}}},{key:"getId",value:function(){return this.id}},{key:"getAttribute",value:function(e){return this.attributesObject[e]}},{key:"setAttribute",value:function(e,t){this.attributesObject[e]=t}},{key:"removeAttribute",value:function(e){delete this.attributesObject[e]}},{key:"getAllDataAttrKeys",value:function(){return Object.keys(this.attributesObject).filter(function(e){return e.startsWith("data-attr")})}},{key:"getExtension",value:function(){return this.extension}},{key:"getMimeType",value:function(){return this.mime}},{key:"hasAttribute",value:function(e){return e in this.attributesObject}},{key:"getType",value:function(){return this.type}},{key:"clearContents",value:function(){for(;this.hookedFns.hasChildNodes();)this.hookedFns.removeChild(this.hookedFns.getLastChild())}},{key:"replaceContents",value:function(e){var t=this;this.clearContents(),e.forEach(function(e){return t.hookedFns.appendChild(e)})}},{key:"utilsSetAllDataAttributes",value:function(e){var t=this;this.getAllDataAttrKeys().forEach(function(n){return e.setAttribute(n.substr(10),t.getAttribute(n))})}},{key:"utilsPassAllDataAttributes",value:function(e){var t=this;this.getAllDataAttrKeys().forEach(function(n){return e.setAttribute(n,t.getAttribute(n))})}}]),e}();o.uid=function(e){return function(){return e++}}(0),o.attributesObject=function(e){var t={};if(e.hasAttributes()){var n=!0,r=!1,i=void 0;try{for(var o,u=e.attributes[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var a=o.value;t[a.name]=a.value}}catch(e){r=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(r)throw i}}}return t.hasAttribute=function(e){return t[e]},t},e.exports=o},function(e,t,n){"use strict";function r(e){var t=e.mediaObject;return t?t:(t=new i(e),r.startup(t))}var i=n(10),o=n(12),u=n(3),a=n(4),c=n(0);r.startup=function(e){var t=o.parse(e);return e.setProperties(t),c.startup(e),e},r.registerFilter=u.register,r.registerPlugin=a.register,r.Orchestrator=c,r.MediaObject=i,r.Parser=o,e.exports=r},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){r(this,e)}return i(e,null,[{key:"extension",value:function(e){return e.getAttribute("data-type").split("/")[1]}},{key:"type",value:function(e){return e.getAttribute("data-type").split("/")[0]}},{key:"mime",value:function(e){return e.getAttribute("data-type")}},{key:"protocol",value:function(e){var t=e.getAttribute("src").split("://");return t.length>1?t[0]:window.location.protocol}},{key:"hostname",value:function(e){var t=e.getAttribute("src").split("://");return t.length>1?t[1].split("/")[0]:window.location.hostname}},{key:"source",value:function(e){return e.getAttribute("src")}},{key:"parse",value:function(t){return{protocol:e.protocol(t),hostname:e.hostname(t),src:e.source(t),type:e.type(t),extension:e.extension(t),mime:e.mime(t)}}}]),e}();e.exports=o},function(e,t,n){"use strict";var r=n(0),i={identifier:"clear-key",startup:function(e){var t=e.getAttribute("data-clear-key"),n=t.substring(0,32),i=t.substring(33,65);e.setAttribute("id",n),e.setAttribute("key",i),e.removeAttribute("data-clear-key"),r.chain(e)}};e.exports=i},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(9),u=n(0),a=function(){function e(){r(this,e)}return i(e,null,[{key:"slice",value:function(e){return Array.prototype.slice.call(e)}},{key:"getRandomKeyStr",value:function(){var t=e.Nacl,n=t.randomBytes(18);return t.util.encodeBase64(n)}},{key:"getKeyFromStr",value:function(t){var n=e.Nacl;return n.hash(n.util.decodeBase64(t)).subarray(32,64)}},{key:"encrypt",value:function(t,n){var r=t,i=e.Nacl.randomBytes(24),o=e.Nacl.secretbox(r,i,n);if(o)return new Uint8Array(e.slice(i).concat(e.slice(o)));throw new Error}},{key:"decrypt",value:function(t,n){if(t.length<24)throw new Error;var r=e.slice,i=e.Nacl,o=new Uint8Array(r(t).slice(0,24)),u=new Uint8Array(r(t).slice(24)),a=i.secretbox.open(u,o,n);if(a)return a;throw new Error("Decrypted file in undefined")}}]),e}();a.Nacl=window.nacl;var c=function(){function e(){r(this,e)}return i(e,null,[{key:"getArrayBuffer",value:function(e){return fetch(e).then(function(e){if(e.ok)return e.arrayBuffer();throw new o.FetchFails}).then(function(e){return e})}},{key:"createUrl",value:function(e){return window.URL.createObjectURL(e)}},{key:"getBlobUrl",value:function(e,t){return window.URL.createObjectURL(new Blob([e],{type:t}))}},{key:"getDataUrl",value:function(e,t){return"data:"+t+";base64,"+a.Nacl.util.encodeBase64(e)}}]),e}(),s={identifier:"crypto",startup:function(e){var t=e.getAttribute("src"),n=e.getAttribute("data-crypto-key"),r=a.getKeyFromStr(n),i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t=i.response;if(t){var n=new Uint8Array(t),o=a.decrypt(n,r),s=c.getDataUrl(o,e.getMimeType());e.setAttribute("src",s),e.removeAttribute("data-crypto-key"),u.chain(e)}},i.send(null)}};e.exports=s},function(e,t,n){"use strict";var r=n(0),i={identifier:"default",startup:function(e){r.chain(e)}};e.exports=i},function(e,t,n){"use strict";var r=n(5),i={FilterDefaultLogic:n(19),FilterCryptoLogic:n(18),FilterClearKeyLogic:n(17),PluginImageLogic:n(22),PluginAudioLogic:n(20),PluginVideoLogic:n(24),PluginPdfLogic:n(23),PluginDashLogic:n(21)};r.registerLogics(i),e.exports=r},function(e,t,n){"use strict";e.exports={identifier:"clear-key",type:"filter",apply:function(e){return e.hasAttribute("data-clear-key")}}},function(e,t,n){"use strict";e.exports={identifier:"crypto",type:"filter",apply:function(e){return e.hasAttribute("data-crypto-key")}}},function(e,t,n){"use strict";e.exports={identifier:"default",type:"filter",apply:function(e){return e.hasAttribute("src")&&e.hasAttribute("data-type")}}},function(e,t,n){"use strict";e.exports={identifier:"audio",type:"plugin",apply:function(e){var t=new RegExp("^mp3|ogg|webm|wav$"),n=new RegExp("^audio/(mp3|ogg|webm|wav)$");return e.hasAttribute("src")&&"audio"===e.getType()&&null!==t.exec(e.getExtension())&&null!==n.exec(e.getMimeType())}}},function(e,t,n){"use strict";e.exports={identifier:"dash",type:"plugin",apply:function(e){var t=new RegExp("^dash[+]xml$"),n=new RegExp("^application/dash[+]xml$");return e.hasAttribute("src")&&"application"===e.getType()&&null!==t.exec(e.getExtension())&&null!==n.exec(e.getMimeType())}}},function(e,t,n){"use strict";e.exports={identifier:"image",type:"plugin",apply:function(e){var t=new RegExp("^png|jpg|jpeg|gif$"),n=new RegExp("^image/(png|svg+xml|jpeg|gif)$");return e.hasAttribute("src")&&"image"===e.getType()&&null!==t.exec(e.getExtension())&&null!==n.exec(e.getMimeType())}}},function(e,t,n){"use strict";e.exports={identifier:"pdf",type:"plugin",apply:function(e){var t=new RegExp("^pdf$"),n=new RegExp("^application/pdf$");return e.hasAttribute("src")&&"application"===e.getType()&&null!==t.exec(e.getExtension())&&null!==n.exec(e.getMimeType())}}},function(e,t,n){"use strict";e.exports={identifier:"video",type:"plugin",apply:function(e){var t=new RegExp("^mp4|ogg|webm$"),n=new RegExp("^video/(mp4|ogg|webm)$");return e.hasAttribute("src")&&"video"===e.getType()&&null!==t.exec(e.getExtension())&&null!==n.exec(e.getMimeType())}}},function(e,t,n){"use strict";var r={identifier:"audio",startup:function(e){var t=document.createElement("audio");t.setAttribute("src",e.getAttribute("src")),e.utilsSetAllDataAttributes(t),e.replaceContents([t])}};e.exports=r},function(e,t,n){"use strict";var r={identifier:"dash",startup:function(e){var t=document.createElement("video"),n=new shaka.Player(t),r=e.getAttribute("id"),i=e.getAttribute("key");if(r&&i){var o='{"'+r+'": "'+i+'"}',u=JSON.parse(o);n.configure({drm:{clearKeys:u}})}e.utilsSetAllDataAttributes(t),e.replaceContents([t]),n.load(e.getAttribute("src")).then(function(){})}};e.exports=r},function(e,t,n){"use strict";var r={identifier:"image",startup:function(e){var t=document.createElement("img");t.setAttribute("src",e.getAttribute("src")),e.utilsSetAllDataAttributes(t),e.replaceContents([t])}};e.exports=r},function(e,t,n){"use strict";var r={identifier:"pdf",startup:function(e){var t=e.getAttribute("src"),n=document.createElement("canvas");e.utilsSetAllDataAttributes(n),e.replaceContents([n]),PDFJS.disableWorker=!0,PDFJS.getDocument(t).promise.then(function(e){function t(e){var t=1,r=e.getViewport(t),i=n.getContext("2d");n.height=r.height,n.width=r.width;var o={canvasContext:i,viewport:r};e.render(o).then(function(){})}function r(t){t||console.log("no event"),0===t.buttons?i===e.numPages?i=1:i++:4===t.buttons&&(1===i?i=e.numPages:i--)}var i=1;e.getPage(i).then(function(e){t(e)}),n.onclick=function(n){r(n),e.getPage(i).then(function(e){t(e)})}},function(e){console.error(e)})}};e.exports=r},function(e,t,n){"use strict";var r={identifier:"video",startup:function(e){var t=document.createElement("video");t.setAttribute("src",e.getAttribute("src")),e.utilsSetAllDataAttributes(t),e.replaceContents([t])}};e.exports=r},,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,function(e,t,n){e.exports=n(6)}])}); |