next-blurhash-previews 0.0.3-beta61 → 0.0.3-beta62
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.
@@ -72,11 +72,7 @@ if (!customElements.get("blurhash-image")) {
|
|
72
72
|
customElements.define("blurhash-image", ImageWithPreview);
|
73
73
|
}
|
74
74
|
|
75
|
-
|
76
|
-
[document.querySelector("#next-blurhash-worker-script")!.textContent!],
|
77
|
-
{ type: "text/javascript" }
|
78
|
-
);
|
79
|
-
const worker = new Worker(window.URL.createObjectURL(workerBlob));
|
75
|
+
var worker;
|
80
76
|
|
81
77
|
function updateBlurHashPreview(canvasEl: HTMLCanvasElement, preview: blurhash) {
|
82
78
|
const { w: width, h: height, blurhash } = preview;
|
@@ -84,6 +80,13 @@ function updateBlurHashPreview(canvasEl: HTMLCanvasElement, preview: blurhash) {
|
|
84
80
|
canvasEl.height = height;
|
85
81
|
|
86
82
|
if (true) {
|
83
|
+
if (!worker) {
|
84
|
+
const workerBlob = new Blob(
|
85
|
+
[document.querySelector("#next-blurhash-worker-script")!.textContent!],
|
86
|
+
{ type: "text/javascript" }
|
87
|
+
);
|
88
|
+
worker = new Worker(window.URL.createObjectURL(workerBlob));
|
89
|
+
}
|
87
90
|
const offscreen = (canvasEl as any).transferControlToOffscreen();
|
88
91
|
worker.postMessage({ canvas: offscreen, width, height, blurhash }, [
|
89
92
|
offscreen,
|
package/imagePreviewBootstrap.js
CHANGED
@@ -65,10 +65,7 @@ class ImageWithPreview extends HTMLElement {
|
|
65
65
|
if (!customElements.get("blurhash-image")) {
|
66
66
|
customElements.define("blurhash-image", ImageWithPreview);
|
67
67
|
}
|
68
|
-
|
69
|
-
type: "text/javascript"
|
70
|
-
});
|
71
|
-
const worker = new Worker(window.URL.createObjectURL(workerBlob));
|
68
|
+
var worker;
|
72
69
|
function updateBlurHashPreview(canvasEl, preview) {
|
73
70
|
const {
|
74
71
|
w: width,
|
@@ -78,6 +75,12 @@ function updateBlurHashPreview(canvasEl, preview) {
|
|
78
75
|
canvasEl.width = width;
|
79
76
|
canvasEl.height = height;
|
80
77
|
{
|
78
|
+
if (!worker) {
|
79
|
+
const workerBlob = new Blob([document.querySelector("#next-blurhash-worker-script").textContent], {
|
80
|
+
type: "text/javascript"
|
81
|
+
});
|
82
|
+
worker = new Worker(window.URL.createObjectURL(workerBlob));
|
83
|
+
}
|
81
84
|
const offscreen = canvasEl.transferControlToOffscreen();
|
82
85
|
worker.postMessage({
|
83
86
|
canvas: offscreen,
|