pdftex.js
Version:
pdftex in pure js
3 lines (2 loc) • 1.89 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.pdftex=n()}(this,function(){"use strict";function e(e,n){return null!=i&&i.terminate(),null==o?i=new r:(i=o,o=null),i.on("finish",function(){null==o&&(o=new r)}),i._compile(e,n),i}var n=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},t=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),r=function(){function r(){n(this,r),this._ready=!1,this.worker=new Worker(e._dir+"pdftex-worker.js"),this.ready=!1;var t=this;this._eventListener=[],this.worker.addEventListener("message",function(e){var n=e.data;"err"===n.type||"log"===n.type?t._fire(n.type,n.value):"finish"===n.type?t._fire("finish",n.value):"ready"===n.type?(t._ready=!0,t._fire("ready")):console.warn("Unexpected Worker response..",n)})}return t(r,[{key:"_compile",value:function(e,n){var t=this;this.source=e,this._options=n||{},n.debug&&(this.on("err",function(e){console.error(e)}),this.on("log",function(e){console.log(e)})),this.whenReady(function(){t.worker.postMessage({type:"start",source:e})})}},{key:"_fire",value:function(e,n){this._eventListener.forEach(function(t){t[0]===e&&t[1](n)})}},{key:"on",value:function(e,n){this._eventListener.push([e,n])}},{key:"terminate",value:function(){this.worker.terminate()}},{key:"whenReady",value:function(e){this._ready?e():this.on("ready",e)}}]),r}(),i=null,o=null;return e.preload=function(){null==o&&(o=new r)},e._dir="./",e.setPdftexDir=function(n){if("string"!=typeof n)throw new Error("Expect path to be a String!");"/"!==n[n.length-1]&&(n+="/"),e._dir=n},e});
//# sourceMappingURL=pdftex.js.map