This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
epubreader/js/lib/typedarray.min.js
2020-04-21 22:37:42 +02:00

2 lines
8.8 KiB
JavaScript

var ArrayBuffer,ArrayBufferView,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,DataView;(function(){"use strict";function t(){if(document){document.createTextNode("").splitText(1)}throw new RangeError("INDEX_SIZE_ERR")}function n(e){if(Object.getOwnPropertyNames&&Object.defineProperty){var t=Object.getOwnPropertyNames(e),n;for(n=0;n<t.length;n+=1){Object.defineProperty(e,t[n],{value:e[t[n]],writable:false,enumerable:false,configurable:false})}}}function r(e){function t(t){Object.defineProperty(e,t,{get:function(){return e._getter(t)},set:function(n){e._setter(t,n)},enumerable:true,configurable:false})}if(!Object.defineProperty){return}var n;for(n=0;n<e.length;n+=1){t(n)}}function i(e,t){var n=32-t;return e<<n>>n}function s(e,t){var n=32-t;return e<<n>>>n}function o(e){return[e&255]}function u(e){return i(e[0],8)}function a(e){return[e&255]}function f(e){return s(e[0],8)}function l(e){return[e>>8&255,e&255]}function c(e){return i(e[0]<<8|e[1],16)}function h(e){return[e>>8&255,e&255]}function p(e){return s(e[0]<<8|e[1],16)}function d(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}function v(e){return i(e[0]<<24|e[1]<<16|e[2]<<8|e[3],32)}function m(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}function g(e){return s(e[0]<<24|e[1]<<16|e[2]<<8|e[3],32)}function y(e,t,n){var r=(1<<t-1)-1,i,s,o,u,a,f,l,c;if(isNaN(e)){s=(1<<r)-1;o=Math.pow(2,n-1);i=0}else if(e===Infinity||e===-Infinity){s=(1<<r)-1;o=0;i=e<0?1:0}else if(e===0){s=0;o=0;i=1/e===-Infinity?1:0}else{i=e<0;e=Math.abs(e);if(e>=Math.pow(2,1-r)){u=Math.min(Math.floor(Math.log(e)/Math.LN2),r);s=u+r;o=Math.round(e*Math.pow(2,n-u)-Math.pow(2,n))}else{s=0;o=Math.round(e/Math.pow(2,1-r-n))}}f=[];for(a=n;a;a-=1){f.push(o%2?1:0);o=Math.floor(o/2)}for(a=t;a;a-=1){f.push(s%2?1:0);s=Math.floor(s/2)}f.push(i?1:0);f.reverse();l=f.join("");c=[];while(l.length){c.push(parseInt(l.substring(0,8),2));l=l.substring(8)}return c}function b(e,t,n){var r=[],i,s,o,u,a,f,l,c;for(i=e.length;i;i-=1){o=e[i-1];for(s=8;s;s-=1){r.push(o%2?1:0);o=o>>1}}r.reverse();u=r.join("");a=(1<<t-1)-1;f=parseInt(u.substring(0,1),2)?-1:1;l=parseInt(u.substring(1,1+t),2);c=parseInt(u.substring(1+t),2);if(l===(1<<t)-1){return c!==0?NaN:f*Infinity}else if(l>0){return f*Math.pow(2,l-a)*(1+c/Math.pow(2,n))}else if(c!==0){return f*Math.pow(2,-(a-1))*(c/Math.pow(2,n))}else{return f<0?-0:0}}function w(e){return b(e,11,52)}function E(e){return y(e,11,52)}function S(e){return b(e,8,23)}function x(e){return y(e,8,23)}var e={ToInt32:function(e){return e>>0},ToUint32:function(e){return e>>>0}};if(Object.prototype.__defineGetter__&&!Object.defineProperty){Object.defineProperty=function(e,t,n){if(n.hasOwnProperty("get")){e.__defineGetter__(t,n.get)}if(n.hasOwnProperty("set")){e.__defineSetter__(t,n.set)}}}if(!ArrayBuffer){(function(){function i(i,s,o){var u;u=function(i,s,o){var a,f,l,c;if(!arguments.length||typeof arguments[0]==="number"){this.length=e.ToInt32(arguments[0]);if(o<0){throw new RangeError("ArrayBufferView size is not a small enough positive integer.")}this.byteLength=this.length*this.BYTES_PER_ELEMENT;this.buffer=new ArrayBuffer(this.byteLength);this.byteOffset=0}else if(typeof arguments[0]==="object"&&arguments[0].constructor===u){a=arguments[0];this.length=a.length;this.byteLength=this.length*this.BYTES_PER_ELEMENT;this.buffer=new ArrayBuffer(this.byteLength);this.byteOffset=0;for(l=0;l<this.length;l+=1){this._setter(l,a._getter(l))}}else if(typeof arguments[0]==="object"&&!(arguments[0]instanceof ArrayBuffer)){f=arguments[0];this.length=e.ToUint32(f.length);this.byteLength=this.length*this.BYTES_PER_ELEMENT;this.buffer=new ArrayBuffer(this.byteLength);this.byteOffset=0;for(l=0;l<this.length;l+=1){c=f[l];this._setter(l,Number(c))}}else if(typeof arguments[0]==="object"&&arguments[0]instanceof ArrayBuffer){this.buffer=i;this.byteOffset=e.ToUint32(s);if(this.byteOffset>this.buffer.byteLength){t()}if(this.byteOffset%this.BYTES_PER_ELEMENT){throw new RangeError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.")}if(arguments.length<3){this.byteLength=this.buffer.byteLength-this.byteOffset;if(this.byteLength%this.BYTES_PER_ELEMENT){t()}this.length=this.byteLength/this.BYTES_PER_ELEMENT}else{this.length=e.ToUint32(o);this.byteLength=this.length*this.BYTES_PER_ELEMENT}if(this.byteOffset+this.byteLength>this.buffer.byteLength){t()}}else{throw new TypeError("Unexpected argument type(s)")}this.constructor=u;n(this);r(this)};u.prototype=new ArrayBufferView;u.prototype.BYTES_PER_ELEMENT=i;u.prototype._pack=s;u.prototype._unpack=o;u.BYTES_PER_ELEMENT=i;u.prototype._getter=function(t){if(arguments.length<1){throw new SyntaxError("Not enough arguments")}t=e.ToUint32(t);if(t>=this.length){return}var n=[],r,i;for(r=0,i=this.byteOffset+t*this.BYTES_PER_ELEMENT;r<this.BYTES_PER_ELEMENT;r+=1,i+=1){n.push(this.buffer._bytes[i])}return this._unpack(n)};u.prototype.get=u.prototype._getter;u.prototype._setter=function(t,n){if(arguments.length<2){throw new SyntaxError("Not enough arguments")}t=e.ToUint32(t);if(t>=this.length){return}var r=this._pack(n),i,s;for(i=0,s=this.byteOffset+t*this.BYTES_PER_ELEMENT;i<this.BYTES_PER_ELEMENT;i+=1,s+=1){this.buffer._bytes[s]=r[i]}};u.prototype.set=function(n,r){if(arguments.length<1){throw new SyntaxError("Not enough arguments")}var i,s,o,u,a,f,l,c,h,p;if(typeof arguments[0]==="object"&&arguments[0].constructor===this.constructor){i=arguments[0];o=e.ToUint32(arguments[1]);if(o+i.length>this.length){t()}c=this.byteOffset+o*this.BYTES_PER_ELEMENT;h=i.length*this.BYTES_PER_ELEMENT;if(i.buffer===this.buffer){p=[];for(a=0,f=i.byteOffset;a<h;a+=1,f+=1){p[a]=i.buffer._bytes[f]}for(a=0,l=c;a<h;a+=1,l+=1){this.buffer._bytes[l]=p[a]}}else{for(a=0,f=i.byteOffset,l=c;a<h;a+=1,f+=1,l+=1){this.buffer._bytes[l]=i.buffer._bytes[f]}}}else if(typeof arguments[0]==="object"&&typeof arguments[0].length!=="undefined"){s=arguments[0];u=e.ToUint32(s.length);o=e.ToUint32(arguments[1]);if(o+u>this.length){t()}for(a=0;a<u;a+=1){f=s[a];this._setter(o+a,Number(f))}}else{throw new TypeError("Unexpected argument type(s)")}};u.prototype.subarray=function(t,n){function r(e,t,n){return e<t?t:e>n?n:e}t=e.ToInt32(t);n=e.ToInt32(n);if(arguments.length<1){t=0}if(arguments.length<2){n=this.length}if(t<0){t=this.length+t}if(n<0){n=this.length+n}t=r(t,0,this.length);n=r(n,0,this.length);var i=n-t;if(i<0){i=0}return new this.constructor(this.buffer,t*this.BYTES_PER_ELEMENT,i)};return u}ArrayBuffer=function(t){t=e.ToInt32(t);if(t<0){throw new RangeError("ArrayBuffer size is not a small enough positive integer.")}this.byteLength=t;this._bytes=[];this._bytes.length=t;var r;for(r=0;r<this.byteLength;r+=1){this._bytes[r]=0}n(this)};ArrayBufferView=function(){};Int8Array=Int8Array||i(1,o,u);Uint8Array=Uint8Array||i(1,a,f);Int16Array=Int16Array||i(2,l,c);Uint16Array=Uint16Array||i(2,h,p);Int32Array=Int32Array||i(4,d,v);Uint32Array=Uint32Array||i(4,m,g);Float32Array=Float32Array||i(4,x,S);Float64Array=Float64Array||i(8,E,w)})()}if(!DataView){(function(){function r(e,t){if(typeof e.get==="function"){return e.get(t)}else{return e[t]}}function s(n){return function(s,o){s=e.ToUint32(s);if(s+n.BYTES_PER_ELEMENT>this.byteLength){t()}s+=this.byteOffset;var u=new Uint8Array(this.buffer,s,n.BYTES_PER_ELEMENT),a=[],f;for(f=0;f<n.BYTES_PER_ELEMENT;f+=1){a.push(r(u,f))}if(Boolean(o)===Boolean(i)){a.reverse()}return r(new n((new Uint8Array(a)).buffer),0)}}function o(n){return function(s,o,u){s=e.ToUint32(s);if(s+n.BYTES_PER_ELEMENT>this.byteLength){t()}var a=new n([o]),f=new Uint8Array(a.buffer),l=[],c,h;for(c=0;c<n.BYTES_PER_ELEMENT;c+=1){l.push(r(f,c))}if(Boolean(u)===Boolean(i)){l.reverse()}h=new Uint8Array(this.buffer,s,n.BYTES_PER_ELEMENT);h.set(l)}}var i=function(){var e=new Uint16Array([4660]),t=new Uint8Array(e.buffer);return r(t,0)===18}();DataView=function(r,i,s){if(!(typeof r==="object"&&r instanceof ArrayBuffer)){throw new TypeError("TypeError")}this.buffer=r;this.byteOffset=e.ToUint32(i);if(this.byteOffset>this.buffer.byteLength){t()}if(arguments.length<3){this.byteLength=this.buffer.byteLength-this.byteOffset}else{this.byteLength=e.ToUint32(s)}if(this.byteOffset+this.byteLength>this.buffer.byteLength){t()}n(this)};if(ArrayBufferView){DataView.prototype=new ArrayBufferView}DataView.prototype.getUint8=s(Uint8Array);DataView.prototype.getInt8=s(Int8Array);DataView.prototype.getUint16=s(Uint16Array);DataView.prototype.getInt16=s(Int16Array);DataView.prototype.getUint32=s(Uint32Array);DataView.prototype.getInt32=s(Int32Array);DataView.prototype.getFloat32=s(Float32Array);DataView.prototype.getFloat64=s(Float64Array);DataView.prototype.setUint8=o(Uint8Array);DataView.prototype.setInt8=o(Int8Array);DataView.prototype.setUint16=o(Uint16Array);DataView.prototype.setInt16=o(Int16Array);DataView.prototype.setUint32=o(Uint32Array);DataView.prototype.setInt32=o(Int32Array);DataView.prototype.setFloat32=o(Float32Array);DataView.prototype.setFloat64=o(Float64Array)})()}})()