next-blurhash-previews 0.0.3-beta53 → 0.0.3-beta54
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,5 @@
|
|
1
|
-
//import { decode } from "blurhash/dist/esm";
|
2
|
-
|
3
1
|
type blurhash = { w: number; h: number; blurhash: string };
|
4
2
|
|
5
|
-
//declare function __blurhashDecode(blurhash: string, width: number, height: any);
|
6
|
-
//(window as any).__blurhashDecode = decode;
|
7
|
-
|
8
3
|
class ImageWithPreview extends HTMLElement {
|
9
4
|
sd: ShadowRoot;
|
10
5
|
mo?: MutationObserver;
|
@@ -37,7 +32,7 @@ class ImageWithPreview extends HTMLElement {
|
|
37
32
|
this.#imgEl.addEventListener("load", this.#imgLoad);
|
38
33
|
}
|
39
34
|
|
40
|
-
return
|
35
|
+
return 1;
|
41
36
|
}
|
42
37
|
};
|
43
38
|
|
@@ -54,9 +49,7 @@ class ImageWithPreview extends HTMLElement {
|
|
54
49
|
}
|
55
50
|
|
56
51
|
#imgLoad = () => {
|
57
|
-
|
58
|
-
this.sd.innerHTML = `<slot name="image"></slot>`;
|
59
|
-
}, 19000);
|
52
|
+
this.sd.innerHTML = `<slot name="image"></slot>`;
|
60
53
|
};
|
61
54
|
|
62
55
|
attributeChangedCallback(name) {
|
@@ -96,12 +89,4 @@ function updateBlurHashPreview(canvasEl: HTMLCanvasElement, preview: blurhash) {
|
|
96
89
|
offscreen,
|
97
90
|
]);
|
98
91
|
}
|
99
|
-
|
100
|
-
return;
|
101
|
-
// @ts-ignore
|
102
|
-
const pixels = decode(blurhash, width, height);
|
103
|
-
const ctx = canvasEl.getContext("2d")!;
|
104
|
-
const imageData = ctx.createImageData(width, height);
|
105
|
-
imageData.data.set(pixels);
|
106
|
-
ctx.putImageData(imageData, 0, 0);
|
107
92
|
}
|
package/imagePreviewBootstrap.js
CHANGED
@@ -4,7 +4,7 @@ export const imagePreviewBootstrap = createElement(
|
|
4
4
|
Fragment,
|
5
5
|
{},
|
6
6
|
createElement("script", {
|
7
|
-
dangerouslySetInnerHTML: { __html: `(() => { "use strict";class a extends HTMLElement{sd;mo;static observedAttributes=["preview"];#s=!1;get#e(){return this.querySelector("img")}get#t(){return this.querySelector("canvas")}constructor(){super(),this.sd=this.attachShadow({mode:"open"}),this.sd.innerHTML='<slot name="preview"></slot>'}#i=()=>{if(this.#e&&this.#t)return this.mo?.disconnect(),this.#e.complete?this.#r():(this.#h(),this.#e.addEventListener("load",this.#r))
|
7
|
+
dangerouslySetInnerHTML: { __html: `(() => { "use strict";class a extends HTMLElement{sd;mo;static observedAttributes=["preview"];#s=!1;get#e(){return this.querySelector("img")}get#t(){return this.querySelector("canvas")}constructor(){super(),this.sd=this.attachShadow({mode:"open"}),this.sd.innerHTML='<slot name="preview"></slot>'}#i=()=>{if(this.#e&&this.#t)return this.mo?.disconnect(),this.#e.complete?this.#r():(this.#h(),this.#e.addEventListener("load",this.#r)),1};connectedCallback(){this.#s=!0,this.#i()||(this.mo=new MutationObserver(this.#i),this.mo.observe(this,{subtree:!0,childList:!0,attributes:!1}))}#r=()=>{this.sd.innerHTML='<slot name="image"></slot>'};attributeChangedCallback(e){this.#t&&e==="preview"&&this.#h()}#h(){if(!this.#s||!this.getAttribute("preview"))return;const e=JSON.parse(this.getAttribute("preview"));c(this.#t,e)}}customElements.get("blurhash-image")||customElements.define("blurhash-image",a);function c(t,e){const{w:s,h:i,blurhash:h}=e;t.width=s,t.height=i;{const n=new Blob([document.querySelector("#next-blurhash-worker-script").textContent],{type:"text/javascript"}),o=new Worker(window.URL.createObjectURL(n)),r=t.transferControlToOffscreen();o.postMessage({canvas:r,width:s,height:i,blurhash:h},[r])}} })();` },
|
8
8
|
}),
|
9
9
|
createElement("script", {
|
10
10
|
id: "next-blurhash-worker-script",
|