next-blurhash-previews 0.0.3-beta48 → 0.0.3-beta49

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.
@@ -1,9 +1,7 @@
1
- import { decode } from "../node_modules/blurhash/dist/esm/index";
1
+ import { decode } from "blurhash/dist/esm";
2
2
 
3
3
  type blurhash = { w: number; h: number; blurhash: string };
4
4
 
5
- let x = 1;
6
-
7
5
  class ImageWithPreview extends HTMLElement {
8
6
  sd: ShadowRoot;
9
7
  mo?: MutationObserver;
@@ -55,7 +53,7 @@ class ImageWithPreview extends HTMLElement {
55
53
  #imgLoad = () => {
56
54
  setTimeout(() => {
57
55
  this.sd.innerHTML = `<slot name="image"></slot>`;
58
- }, 19000);
56
+ }, 10000);
59
57
  };
60
58
 
61
59
  attributeChangedCallback(name) {
@@ -1,85 +1,5 @@
1
1
  import { createElement } from "react";
2
2
 
3
3
  export const imagePreviewBootstrap = createElement("script", {
4
- dangerouslySetInnerHTML: { __html: `(() => { "use strict";
5
- class ImageWithPreview extends HTMLElement {
6
- sd;
7
- mo;
8
- static observedAttributes = ["preview"];
9
- #connected = false;
10
- get #imgEl() {
11
- return this.querySelector("img");
12
- }
13
- get #canvasEl() {
14
- return this.querySelector("canvas");
15
- }
16
- constructor() {
17
- super();
18
- this.sd = this.attachShadow({
19
- mode: "open"
20
- });
21
- this.sd.innerHTML = \`<slot name="preview"></slot>\`;
22
- }
23
- #checkReady = () => {
24
- if (this.#imgEl && this.#canvasEl) {
25
- this.mo?.disconnect();
26
- if (this.#imgEl.complete) {
27
- this.#imgLoad();
28
- } else {
29
- this.#updatePreview();
30
- this.#imgEl.addEventListener("load", this.#imgLoad);
31
- }
32
- return true;
33
- }
34
- };
35
- connectedCallback() {
36
- this.#connected = true;
37
- if (!this.#checkReady()) {
38
- this.mo = new MutationObserver(this.#checkReady);
39
- this.mo.observe(this, {
40
- subtree: true,
41
- childList: true,
42
- attributes: false
43
- });
44
- }
45
- }
46
- #imgLoad = () => {
47
- setTimeout(() => {
48
- this.sd.innerHTML = \`<slot name="image"></slot>\`;
49
- }, 19e3);
50
- };
51
- attributeChangedCallback(name) {
52
- if (this.#canvasEl && name === "preview") {
53
- this.#updatePreview();
54
- }
55
- }
56
- #updatePreview() {
57
- if (!this.#connected || !this.getAttribute("preview")) {
58
- return;
59
- }
60
- const previewObj = JSON.parse(this.getAttribute("preview"));
61
- updateBlurHashPreview(this.#canvasEl, previewObj);
62
- }
63
- }
64
- if (!customElements.get("blurhash-image")) {
65
- customElements.define("blurhash-image", ImageWithPreview);
66
- }
67
- function updateBlurHashPreview(canvasEl, preview) {
68
- const {
69
- w: width,
70
- h: height,
71
- blurhash
72
- } = preview;
73
- canvasEl.width = width;
74
- canvasEl.height = height;
75
- const worker = new Worker("/canvas-worker.js");
76
- const offscreen = canvasEl.transferControlToOffscreen();
77
- worker.postMessage({
78
- canvas: offscreen,
79
- width,
80
- height,
81
- blurhash
82
- }, [offscreen]);
83
- return;
84
- } })();` },
4
+ dangerouslySetInnerHTML: { __html: `(() => { "use strict";class o 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)),!0};connectedCallback(){this.#s=!0,this.#i()||(this.mo=new MutationObserver(this.#i),this.mo.observe(this,{subtree:!0,childList:!0,attributes:!1}))}#r=()=>{setTimeout(()=>{this.sd.innerHTML='<slot name="image"></slot>'},1e4)};attributeChangedCallback(e){this.#t&&e==="preview"&&this.#h()}#h(){if(!this.#s||!this.getAttribute("preview"))return;const e=JSON.parse(this.getAttribute("preview"));a(this.#t,e)}}customElements.get("blurhash-image")||customElements.define("blurhash-image",o);function a(t,e){const{w:s,h:i,blurhash:h}=e;t.width=s,t.height=i;const n=new Worker("/canvas-worker.js"),r=t.transferControlToOffscreen();n.postMessage({canvas:r,width:s,height:i,blurhash:h},[r])} })();` },
85
5
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-blurhash-previews",
3
- "version": "0.0.3-beta48",
3
+ "version": "0.0.3-beta49",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -0,0 +1,40 @@
1
+ import { defineConfig } from "vite";
2
+ // @ts-ignore
3
+ import path from "path";
4
+ import react from "@vitejs/plugin-react";
5
+ import writeBootstrapPlugin from "./util/setBootstrap";
6
+
7
+ export default defineConfig({
8
+ build: {
9
+ target: "es2022",
10
+ outDir: "./build",
11
+
12
+ // lib: {
13
+ // entry: "components/imageWithPreview.tsx",
14
+ // formats: ["cjs"],
15
+ // fileName: (a, b, c) => {
16
+ // console.log("mm", a, b, c);
17
+ // return "imageWithPreview.js";
18
+ // },
19
+ // name: "imageWithPreview",
20
+ // },
21
+ minify: false,
22
+ rollupOptions: {
23
+ input: {
24
+ imageWithPreview: path.resolve(
25
+ // @ts-ignore
26
+ __dirname,
27
+ "components/imageWithPreview.tsx"
28
+ ),
29
+ },
30
+ output: {
31
+ dir: "./build/",
32
+
33
+ //file: "imageWithPreview.js",
34
+ // file: (a, b, c) => { console.log(a, b, c); return "imageWithPreview.js"; }
35
+ },
36
+ external: ["react", "react-dom", "next", "next/script"],
37
+ },
38
+ },
39
+ plugins: [react(), writeBootstrapPlugin()],
40
+ });
package/vite.config.ts CHANGED
@@ -12,7 +12,7 @@ export default defineConfig({
12
12
  fileName: () => "imageWithPreview.js",
13
13
  name: "imageWithPreview",
14
14
  },
15
- minify: false,
15
+ //minify: false,
16
16
  rollupOptions: {
17
17
  external: ["react", "react-dom", "next", "next/script"],
18
18
  },