next-blurhash-previews 0.0.3-beta43 → 0.0.3-beta46
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.
package/bin/remark-plugin.js
CHANGED
@@ -10,7 +10,7 @@ export const blurhashPlugin = publicPath => () => {
|
|
10
10
|
let outstanding = 0;
|
11
11
|
|
12
12
|
visitParents(tree, "image", async (node, ancestors) => {
|
13
|
-
let { url: imagePath, alt } = node;
|
13
|
+
let { url: imagePath, alt = "" } = node;
|
14
14
|
|
15
15
|
const originalImg = imagePath;
|
16
16
|
if (!/http/.test(imagePath)) {
|
@@ -28,6 +28,8 @@ export const blurhashPlugin = publicPath => () => {
|
|
28
28
|
|
29
29
|
const blurHash = await getBlurhash(imagePath);
|
30
30
|
|
31
|
+
const { w, h } = blurHash;
|
32
|
+
|
31
33
|
console.log(
|
32
34
|
colors.green(`Finished processing ${imagePath}\n\t`, blurHash)
|
33
35
|
);
|
@@ -37,7 +39,7 @@ export const blurhashPlugin = publicPath => () => {
|
|
37
39
|
|
38
40
|
const newNode = `
|
39
41
|
<blurhash-image url="${originalImg}" preview='${JSON.stringify(blurHash)}'>
|
40
|
-
<img alt="${alt
|
42
|
+
<img alt="${alt}" width="${w}" height="${h}" src="${originalImg}" slot="image" />
|
41
43
|
<canvas width="${blurHash.w}" height="${blurHash.h}" slot="preview"></canvas>
|
42
44
|
</blurhash-image>`.trim();
|
43
45
|
|
@@ -10,7 +10,7 @@ class ImageWithPreview extends HTMLElement {
|
|
10
10
|
|
11
11
|
static observedAttributes = ["preview"];
|
12
12
|
|
13
|
-
#
|
13
|
+
#connected = false;
|
14
14
|
get #imgEl(): any {
|
15
15
|
return this.querySelector("img");
|
16
16
|
}
|
@@ -21,8 +21,6 @@ class ImageWithPreview extends HTMLElement {
|
|
21
21
|
constructor() {
|
22
22
|
super();
|
23
23
|
|
24
|
-
console.log("CREATED", x++);
|
25
|
-
|
26
24
|
this.sd = this.attachShadow({ mode: "open" });
|
27
25
|
this.sd.innerHTML = `<slot name="preview"></slot>`;
|
28
26
|
}
|
@@ -43,6 +41,7 @@ class ImageWithPreview extends HTMLElement {
|
|
43
41
|
};
|
44
42
|
|
45
43
|
connectedCallback() {
|
44
|
+
this.#connected = true;
|
46
45
|
if (!this.#checkReady()) {
|
47
46
|
this.mo = new MutationObserver(this.#checkReady);
|
48
47
|
this.mo.observe(this, {
|
@@ -54,7 +53,7 @@ class ImageWithPreview extends HTMLElement {
|
|
54
53
|
}
|
55
54
|
|
56
55
|
#imgLoad = () => {
|
57
|
-
|
56
|
+
this.sd.innerHTML = `<slot name="image"></slot>`;
|
58
57
|
};
|
59
58
|
|
60
59
|
attributeChangedCallback(name) {
|
@@ -64,12 +63,10 @@ class ImageWithPreview extends HTMLElement {
|
|
64
63
|
}
|
65
64
|
|
66
65
|
#updatePreview() {
|
67
|
-
|
68
|
-
if (this.#previewSet) {
|
66
|
+
if (!this.#connected || !this.getAttribute("preview")) {
|
69
67
|
return;
|
70
68
|
}
|
71
|
-
|
72
|
-
console.log(this.#previewSet, this.getAttribute("url"));
|
69
|
+
|
73
70
|
const previewObj = JSON.parse(this.getAttribute("preview")!);
|
74
71
|
updateBlurHashPreview(this.#canvasEl, previewObj);
|
75
72
|
}
|
package/imagePreviewBootstrap.js
CHANGED
@@ -2,12 +2,11 @@ import { createElement } from "react";
|
|
2
2
|
|
3
3
|
export const imagePreviewBootstrap = createElement("script", {
|
4
4
|
dangerouslySetInnerHTML: { __html: `(() => { "use strict";
|
5
|
-
let x = 1;
|
6
5
|
class ImageWithPreview extends HTMLElement {
|
7
6
|
sd;
|
8
7
|
mo;
|
9
8
|
static observedAttributes = ["preview"];
|
10
|
-
#
|
9
|
+
#connected = false;
|
11
10
|
get #imgEl() {
|
12
11
|
return this.querySelector("img");
|
13
12
|
}
|
@@ -16,7 +15,6 @@ class ImageWithPreview extends HTMLElement {
|
|
16
15
|
}
|
17
16
|
constructor() {
|
18
17
|
super();
|
19
|
-
console.log("CREATED", x++);
|
20
18
|
this.sd = this.attachShadow({
|
21
19
|
mode: "open"
|
22
20
|
});
|
@@ -35,6 +33,7 @@ class ImageWithPreview extends HTMLElement {
|
|
35
33
|
}
|
36
34
|
};
|
37
35
|
connectedCallback() {
|
36
|
+
this.#connected = true;
|
38
37
|
if (!this.#checkReady()) {
|
39
38
|
this.mo = new MutationObserver(this.#checkReady);
|
40
39
|
this.mo.observe(this, {
|
@@ -45,6 +44,7 @@ class ImageWithPreview extends HTMLElement {
|
|
45
44
|
}
|
46
45
|
}
|
47
46
|
#imgLoad = () => {
|
47
|
+
this.sd.innerHTML = \`<slot name="image"></slot>\`;
|
48
48
|
};
|
49
49
|
attributeChangedCallback(name) {
|
50
50
|
if (this.#canvasEl && name === "preview") {
|
@@ -52,12 +52,9 @@ class ImageWithPreview extends HTMLElement {
|
|
52
52
|
}
|
53
53
|
}
|
54
54
|
#updatePreview() {
|
55
|
-
|
56
|
-
if (this.#previewSet) {
|
55
|
+
if (!this.#connected || !this.getAttribute("preview")) {
|
57
56
|
return;
|
58
57
|
}
|
59
|
-
this.#previewSet = true;
|
60
|
-
console.log(this.#previewSet, this.getAttribute("url"));
|
61
58
|
const previewObj = JSON.parse(this.getAttribute("preview"));
|
62
59
|
updateBlurHashPreview(this.#canvasEl, previewObj);
|
63
60
|
}
|