next-blurhash-previews 0.0.3-beta33 → 0.0.3-beta34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,7 +74,9 @@ function updateBlurHashPreview(canvasEl: HTMLCanvasElement, preview: blurhash) {
74
74
  const worker = new Worker("/canvas-worker.js");
75
75
 
76
76
  const offscreen = (canvasEl as any).transferControlToOffscreen();
77
- worker.postMessage({ canvas: offscreen, width, height, blurhash });
77
+ worker.postMessage({ canvas: offscreen, width, height, blurhash }, [
78
+ offscreen,
79
+ ]);
78
80
  canvasEl.width = width;
79
81
  canvasEl.height = height;
80
82
 
@@ -1,5 +1,5 @@
1
1
  import { createElement } from "react";
2
2
 
3
3
  export const imagePreviewBootstrap = createElement("script", {
4
- dangerouslySetInnerHTML: { __html: `(() => { "use strict";const T=["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","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],d=t=>{let e=0;for(let s=0;s<t.length;s++){const n=t[s],i=T.indexOf(n);e=e*83+i}return e},b=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},p=t=>{let e=Math.max(0,Math.min(1,t));return e<=.0031308?Math.round(e*12.92*255+.5):Math.round((1.055*Math.pow(e,.4166666666666667)-.055)*255+.5)},k=t=>t<0?-1:1,v=(t,e)=>k(t)*Math.pow(Math.abs(t),e);class B extends Error{constructor(e){super(e),this.name="ValidationError",this.message=e}}const E=t=>{if(!t||t.length<6)throw new B("The blurhash string must be at least 6 characters");const e=d(t[0]),s=Math.floor(e/9)+1,n=e%9+1;if(t.length!==4+2*n*s)throw new B(\`blurhash length mismatch: length is \${t.length} but it should be \${4+2*n*s}\`)},A=t=>{const e=t>>16,s=t>>8&255,n=t&255;return[b(e),b(s),b(n)]},G=(t,e)=>{const s=Math.floor(t/361),n=Math.floor(t/19)%19,i=t%19;return[v((s-9)/9,2)*e,v((n-9)/9,2)*e,v((i-9)/9,2)*e]},I=(t,e,s,n)=>{E(t),n=n|1;const i=d(t[0]),c=Math.floor(i/9)+1,l=i%9+1,g=(d(t[1])+1)/166,a=new Array(l*c);for(let o=0;o<a.length;o++)if(o===0){const r=d(t.substring(2,6));a[o]=A(r)}else{const r=d(t.substring(4+o*2,6+o*2));a[o]=G(r,g*n)}const h=e*4,u=new Uint8ClampedArray(h*s);for(let o=0;o<s;o++)for(let r=0;r<e;r++){let C=0,q=0,y=0;for(let m=0;m<c;m++)for(let f=0;f<l;f++){const w=Math.cos(Math.PI*r*f/e)*Math.cos(Math.PI*o*m/s);let M=a[f+m*l];C+=M[0]*w,q+=M[1]*w,y+=M[2]*w}let L=p(C),P=p(q),R=p(y);u[4*r+0+o*h]=L,u[4*r+1+o*h]=P,u[4*r+2+o*h]=R,u[4*r+3+o*h]=255}return u};class O extends HTMLElement{sd;mo;static observedAttributes=["preview"];get#t(){return this.querySelector("img")}get#e(){return this.querySelector("canvas")}constructor(){super(),this.sd=this.attachShadow({mode:"open"}),this.sd.innerHTML='<slot name="preview"></slot>'}#s=()=>{if(this.#t&&this.#e)return this.mo?.disconnect(),this.#t.complete?this.#n():(this.#o(),this.#t.addEventListener("load",this.#n)),!0};connectedCallback(){this.#s()||(this.mo=new MutationObserver(this.#s),this.mo.observe(this,{subtree:!0,childList:!0,attributes:!1}))}#n=()=>{this.sd.innerHTML='<slot name="image"></slot>'};attributeChangedCallback(e){this.#e&&e==="preview"&&this.#o()}#o(){const e=JSON.parse(this.getAttribute("preview"));D(this.#e,e)}}customElements.get("blurhash-image")||customElements.define("blurhash-image",O);function D(t,e){const{w:s,h:n,blurhash:i}=e,c=new Worker("/canvas-worker.js"),l=t.transferControlToOffscreen();c.postMessage({canvas:l,width:s,height:n,blurhash:i}),t.width=s,t.height=n;const x=I(i,s,n),g=t.getContext("2d"),a=g.createImageData(s,n);a.data.set(x),g.putImageData(a,0,0)} })();` },
4
+ dangerouslySetInnerHTML: { __html: `(() => { "use strict";const T=["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","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],d=t=>{let e=0;for(let s=0;s<t.length;s++){const n=t[s],i=T.indexOf(n);e=e*83+i}return e},b=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},p=t=>{let e=Math.max(0,Math.min(1,t));return e<=.0031308?Math.round(e*12.92*255+.5):Math.round((1.055*Math.pow(e,.4166666666666667)-.055)*255+.5)},k=t=>t<0?-1:1,v=(t,e)=>k(t)*Math.pow(Math.abs(t),e);class B extends Error{constructor(e){super(e),this.name="ValidationError",this.message=e}}const E=t=>{if(!t||t.length<6)throw new B("The blurhash string must be at least 6 characters");const e=d(t[0]),s=Math.floor(e/9)+1,n=e%9+1;if(t.length!==4+2*n*s)throw new B(\`blurhash length mismatch: length is \${t.length} but it should be \${4+2*n*s}\`)},A=t=>{const e=t>>16,s=t>>8&255,n=t&255;return[b(e),b(s),b(n)]},G=(t,e)=>{const s=Math.floor(t/361),n=Math.floor(t/19)%19,i=t%19;return[v((s-9)/9,2)*e,v((n-9)/9,2)*e,v((i-9)/9,2)*e]},I=(t,e,s,n)=>{E(t),n=n|1;const i=d(t[0]),l=Math.floor(i/9)+1,c=i%9+1,g=(d(t[1])+1)/166,a=new Array(c*l);for(let o=0;o<a.length;o++)if(o===0){const r=d(t.substring(2,6));a[o]=A(r)}else{const r=d(t.substring(4+o*2,6+o*2));a[o]=G(r,g*n)}const h=e*4,u=new Uint8ClampedArray(h*s);for(let o=0;o<s;o++)for(let r=0;r<e;r++){let C=0,q=0,y=0;for(let m=0;m<l;m++)for(let f=0;f<c;f++){const w=Math.cos(Math.PI*r*f/e)*Math.cos(Math.PI*o*m/s);let M=a[f+m*c];C+=M[0]*w,q+=M[1]*w,y+=M[2]*w}let L=p(C),P=p(q),R=p(y);u[4*r+0+o*h]=L,u[4*r+1+o*h]=P,u[4*r+2+o*h]=R,u[4*r+3+o*h]=255}return u};class O extends HTMLElement{sd;mo;static observedAttributes=["preview"];get#t(){return this.querySelector("img")}get#e(){return this.querySelector("canvas")}constructor(){super(),this.sd=this.attachShadow({mode:"open"}),this.sd.innerHTML='<slot name="preview"></slot>'}#s=()=>{if(this.#t&&this.#e)return this.mo?.disconnect(),this.#t.complete?this.#n():(this.#o(),this.#t.addEventListener("load",this.#n)),!0};connectedCallback(){this.#s()||(this.mo=new MutationObserver(this.#s),this.mo.observe(this,{subtree:!0,childList:!0,attributes:!1}))}#n=()=>{this.sd.innerHTML='<slot name="image"></slot>'};attributeChangedCallback(e){this.#e&&e==="preview"&&this.#o()}#o(){const e=JSON.parse(this.getAttribute("preview"));D(this.#e,e)}}customElements.get("blurhash-image")||customElements.define("blurhash-image",O);function D(t,e){const{w:s,h:n,blurhash:i}=e,l=new Worker("/canvas-worker.js"),c=t.transferControlToOffscreen();l.postMessage({canvas:c,width:s,height:n,blurhash:i},[c]),t.width=s,t.height=n;const x=I(i,s,n),g=t.getContext("2d"),a=g.createImageData(s,n);a.data.set(x),g.putImageData(a,0,0)} })();` },
5
5
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-blurhash-previews",
3
- "version": "0.0.3-beta33",
3
+ "version": "0.0.3-beta34",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",