next-blurhash-previews 0.0.3-beta66 → 0.0.3-beta67
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,18 +72,21 @@ if (!customElements.get("blurhash-image")) {
|
|
72
72
|
customElements.define("blurhash-image", ImageWithPreview);
|
73
73
|
}
|
74
74
|
|
75
|
+
var worker;
|
76
|
+
|
75
77
|
function updateBlurHashPreview(canvasEl: HTMLCanvasElement, preview: blurhash) {
|
76
78
|
const { w: width, h: height, blurhash } = preview;
|
77
79
|
canvasEl.width = width;
|
78
80
|
canvasEl.height = height;
|
79
81
|
|
80
82
|
if (true) {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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,6 +65,7 @@ class ImageWithPreview extends HTMLElement {
|
|
65
65
|
if (!customElements.get("blurhash-image")) {
|
66
66
|
customElements.define("blurhash-image", ImageWithPreview);
|
67
67
|
}
|
68
|
+
var worker;
|
68
69
|
function updateBlurHashPreview(canvasEl, preview) {
|
69
70
|
const {
|
70
71
|
w: width,
|
@@ -74,10 +75,12 @@ function updateBlurHashPreview(canvasEl, preview) {
|
|
74
75
|
canvasEl.width = width;
|
75
76
|
canvasEl.height = height;
|
76
77
|
{
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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,
|