Comparing version 1.1.5 to 2.0.0
@@ -1,4 +0,2 @@ | ||
export { default as decode, isBlurhashValid } from "./decode"; | ||
export { default as encode } from "./encode"; | ||
export * from "./error"; | ||
var q=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],x=t=>{let e=0;for(let r=0;r<t.length;r++){let n=t[r],l=q.indexOf(n);e=e*83+l}return e},p=(t,e)=>{var r="";for(let n=1;n<=e;n++){let l=Math.floor(t)/Math.pow(83,e-n)%83;r+=q[Math.floor(l)]}return r};var f=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},h=t=>{let e=Math.max(0,Math.min(1,t));return e<=.0031308?Math.trunc(e*12.92*255+.5):Math.trunc((1.055*Math.pow(e,.4166666666666667)-.055)*255+.5)},F=t=>t<0?-1:1,M=(t,e)=>F(t)*Math.pow(Math.abs(t),e);var d=class extends Error{constructor(e){super(e),this.name="ValidationError",this.message=e}};var C=t=>{if(!t||t.length<6)throw new d("The blurhash string must be at least 6 characters");let e=x(t[0]),r=Math.floor(e/9)+1,n=e%9+1;if(t.length!==4+2*n*r)throw new d(`blurhash length mismatch: length is ${t.length} but it should be ${4+2*n*r}`)},N=t=>{try{C(t)}catch(e){return{result:!1,errorReason:e.message}}return{result:!0}},z=t=>{let e=t>>16,r=t>>8&255,n=t&255;return[f(e),f(r),f(n)]},L=(t,e)=>{let r=Math.floor(t/361),n=Math.floor(t/19)%19,l=t%19;return[M((r-9)/9,2)*e,M((n-9)/9,2)*e,M((l-9)/9,2)*e]},U=(t,e,r,n)=>{C(t),n=n|1;let l=x(t[0]),m=Math.floor(l/9)+1,b=l%9+1,i=(x(t[1])+1)/166,u=new Array(b*m);for(let o=0;o<u.length;o++)if(o===0){let a=x(t.substring(2,6));u[o]=z(a)}else{let a=x(t.substring(4+o*2,6+o*2));u[o]=L(a,i*n)}let c=e*4,s=new Uint8ClampedArray(c*r);for(let o=0;o<r;o++)for(let a=0;a<e;a++){let y=0,B=0,R=0;for(let w=0;w<m;w++)for(let P=0;P<b;P++){let G=Math.cos(Math.PI*a*P/e)*Math.cos(Math.PI*o*w/r),T=u[P+w*b];y+=T[0]*G,B+=T[1]*G,R+=T[2]*G}let V=h(y),I=h(B),E=h(R);s[4*a+0+o*c]=V,s[4*a+1+o*c]=I,s[4*a+2+o*c]=E,s[4*a+3+o*c]=255}return s},j=U;var A=4,D=(t,e,r,n)=>{let l=0,m=0,b=0,g=e*A;for(let u=0;u<e;u++){let c=A*u;for(let s=0;s<r;s++){let o=c+s*g,a=n(u,s);l+=a*f(t[o]),m+=a*f(t[o+1]),b+=a*f(t[o+2])}}let i=1/(e*r);return[l*i,m*i,b*i]},$=t=>{let e=h(t[0]),r=h(t[1]),n=h(t[2]);return(e<<16)+(r<<8)+n},H=(t,e)=>{let r=Math.floor(Math.max(0,Math.min(18,Math.floor(M(t[0]/e,.5)*9+9.5)))),n=Math.floor(Math.max(0,Math.min(18,Math.floor(M(t[1]/e,.5)*9+9.5)))),l=Math.floor(Math.max(0,Math.min(18,Math.floor(M(t[2]/e,.5)*9+9.5))));return r*19*19+n*19+l},O=(t,e,r,n,l)=>{if(n<1||n>9||l<1||l>9)throw new d("BlurHash must have between 1 and 9 components");if(e*r*4!==t.length)throw new d("Width and height must match the pixels array");let m=[];for(let s=0;s<l;s++)for(let o=0;o<n;o++){let a=o==0&&s==0?1:2,y=D(t,e,r,(B,R)=>a*Math.cos(Math.PI*o*B/e)*Math.cos(Math.PI*s*R/r));m.push(y)}let b=m[0],g=m.slice(1),i="",u=n-1+(l-1)*9;i+=p(u,1);let c;if(g.length>0){let s=Math.max(...g.map(a=>Math.max(...a))),o=Math.floor(Math.max(0,Math.min(82,Math.floor(s*166-.5))));c=(o+1)/166,i+=p(o,1)}else c=1,i+=p(0,1);return i+=p($(b),4),g.forEach(s=>{i+=p(H(s,c),2)}),i},S=O;export{d as ValidationError,j as decode,S as encode,N as isBlurhashValid}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,13 @@ | ||
export { default as decode, isBlurhashValid } from "./decode"; | ||
export { default as encode } from "./encode"; | ||
export * from "./error"; | ||
declare const isBlurhashValid: (blurhash: string) => { | ||
result: boolean; | ||
errorReason?: string; | ||
}; | ||
declare const decode: (blurhash: string, width: number, height: number, punch?: number) => Uint8ClampedArray; | ||
declare const encode: (pixels: Uint8ClampedArray, width: number, height: number, componentX: number, componentY: number) => string; | ||
declare class ValidationError extends Error { | ||
constructor(message: string); | ||
} | ||
export { ValidationError, decode, encode, isBlurhashValid }; |
@@ -1,12 +0,2 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var decode_1 = require("./decode"); | ||
exports.decode = decode_1.default; | ||
exports.isBlurhashValid = decode_1.isBlurhashValid; | ||
var encode_1 = require("./encode"); | ||
exports.encode = encode_1.default; | ||
__export(require("./error")); | ||
var q=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var r in e)q(t,r,{get:e[r],enumerable:!0})},H=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of j(e))!D.call(t,s)&&s!==r&&q(t,s,{get:()=>e[s],enumerable:!(n=U(e,s))||n.enumerable});return t};var O=t=>H(q({},"__esModule",{value:!0}),t);var _={};$(_,{ValidationError:()=>b,decode:()=>I,encode:()=>F,isBlurhashValid:()=>V});module.exports=O(_);var C=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],x=t=>{let e=0;for(let r=0;r<t.length;r++){let n=t[r],s=C.indexOf(n);e=e*83+s}return e},p=(t,e)=>{var r="";for(let n=1;n<=e;n++){let s=Math.floor(t)/Math.pow(83,e-n)%83;r+=C[Math.floor(s)]}return r};var h=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},M=t=>{let e=Math.max(0,Math.min(1,t));return e<=.0031308?Math.trunc(e*12.92*255+.5):Math.trunc((1.055*Math.pow(e,.4166666666666667)-.055)*255+.5)},S=t=>t<0?-1:1,d=(t,e)=>S(t)*Math.pow(Math.abs(t),e);var b=class extends Error{constructor(e){super(e),this.name="ValidationError",this.message=e}};var A=t=>{if(!t||t.length<6)throw new b("The blurhash string must be at least 6 characters");let e=x(t[0]),r=Math.floor(e/9)+1,n=e%9+1;if(t.length!==4+2*n*r)throw new b(`blurhash length mismatch: length is ${t.length} but it should be ${4+2*n*r}`)},V=t=>{try{A(t)}catch(e){return{result:!1,errorReason:e.message}}return{result:!0}},W=t=>{let e=t>>16,r=t>>8&255,n=t&255;return[h(e),h(r),h(n)]},k=(t,e)=>{let r=Math.floor(t/361),n=Math.floor(t/19)%19,s=t%19;return[d((r-9)/9,2)*e,d((n-9)/9,2)*e,d((s-9)/9,2)*e]},J=(t,e,r,n)=>{A(t),n=n|1;let s=x(t[0]),m=Math.floor(s/9)+1,f=s%9+1,i=(x(t[1])+1)/166,u=new Array(f*m);for(let o=0;o<u.length;o++)if(o===0){let l=x(t.substring(2,6));u[o]=W(l)}else{let l=x(t.substring(4+o*2,6+o*2));u[o]=k(l,i*n)}let c=e*4,a=new Uint8ClampedArray(c*r);for(let o=0;o<r;o++)for(let l=0;l<e;l++){let y=0,B=0,R=0;for(let w=0;w<m;w++)for(let P=0;P<f;P++){let G=Math.cos(Math.PI*l*P/e)*Math.cos(Math.PI*o*w/r),T=u[P+w*f];y+=T[0]*G,B+=T[1]*G,R+=T[2]*G}let N=M(y),z=M(B),L=M(R);a[4*l+0+o*c]=N,a[4*l+1+o*c]=z,a[4*l+2+o*c]=L,a[4*l+3+o*c]=255}return a},I=J;var E=4,K=(t,e,r,n)=>{let s=0,m=0,f=0,g=e*E;for(let u=0;u<e;u++){let c=E*u;for(let a=0;a<r;a++){let o=c+a*g,l=n(u,a);s+=l*h(t[o]),m+=l*h(t[o+1]),f+=l*h(t[o+2])}}let i=1/(e*r);return[s*i,m*i,f*i]},Q=t=>{let e=M(t[0]),r=M(t[1]),n=M(t[2]);return(e<<16)+(r<<8)+n},X=(t,e)=>{let r=Math.floor(Math.max(0,Math.min(18,Math.floor(d(t[0]/e,.5)*9+9.5)))),n=Math.floor(Math.max(0,Math.min(18,Math.floor(d(t[1]/e,.5)*9+9.5)))),s=Math.floor(Math.max(0,Math.min(18,Math.floor(d(t[2]/e,.5)*9+9.5))));return r*19*19+n*19+s},Z=(t,e,r,n,s)=>{if(n<1||n>9||s<1||s>9)throw new b("BlurHash must have between 1 and 9 components");if(e*r*4!==t.length)throw new b("Width and height must match the pixels array");let m=[];for(let a=0;a<s;a++)for(let o=0;o<n;o++){let l=o==0&&a==0?1:2,y=K(t,e,r,(B,R)=>l*Math.cos(Math.PI*o*B/e)*Math.cos(Math.PI*a*R/r));m.push(y)}let f=m[0],g=m.slice(1),i="",u=n-1+(s-1)*9;i+=p(u,1);let c;if(g.length>0){let a=Math.max(...g.map(l=>Math.max(...l))),o=Math.floor(Math.max(0,Math.min(82,Math.floor(a*166-.5))));c=(o+1)/166,i+=p(o,1)}else c=1,i+=p(0,1);return i+=p(Q(f),4),g.forEach(a=>{i+=p(X(a,c),2)}),i},F=Z;0&&(module.exports={ValidationError,decode,encode,isBlurhashValid}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "blurhash", | ||
"version": "1.1.5", | ||
"version": "2.0.0", | ||
"description": "Encoder and decoder for the Wolt BlurHash algorithm.", | ||
@@ -8,2 +8,9 @@ "main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/esm/index.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"sideEffects": false, | ||
@@ -14,12 +21,13 @@ "repository": { | ||
}, | ||
"homepage": "http://blurhash.com", | ||
"homepage": "https://blurha.sh", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepublishOnly": "npm run build", | ||
"build": "npm run ts && npm run ts:esm", | ||
"build": "tsup", | ||
"demo": "webpack-dev-server --mode development", | ||
"prettier": "prettier src/**/*.ts", | ||
"prettier-fix": "npm run prettier -- --write", | ||
"ts": "tsc", | ||
"ts:watch": "npm run ts -- --noEmit --watch", | ||
"ts:esm": "tsc --outDir dist/esm --target es2020 --declaration false --module es2015" | ||
"start": "tsup --watch" | ||
}, | ||
@@ -35,9 +43,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"prettier": "1.18.2", | ||
"ts-loader": "6.0.4", | ||
"typescript": "3.5.3", | ||
"webpack": "4.41.2", | ||
"webpack-cli": "3.3.10", | ||
"webpack-dev-server": "3.9.0" | ||
"prettier": "2.7.1", | ||
"ts-loader": "9.3.1", | ||
"tsup": "^6.1.3", | ||
"typescript": "4.7.4", | ||
"webpack": "5.73.0", | ||
"webpack-cli": "4.10.0", | ||
"webpack-dev-server": "4.9.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40277
7
7
36
2