@substrate-system/blur-hash 0.0.39 → 0.0.42
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/README.md +64 -12
- package/dist/bin/index.d.ts +7 -0
- package/dist/bin/index.d.ts.map +1 -0
- package/dist/bin/index.js +15 -10
- package/dist/bin/photon.d.ts +19 -0
- package/dist/bin/photon.d.ts.map +1 -0
- package/dist/bin/photon.js +46 -0
- package/dist/index.cjs +14 -6
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +14 -6
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +12 -12
- package/dist/index.min.js.map +3 -3
- package/dist/meta.json +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +19 -7
package/README.md
CHANGED
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
This is the
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
This is the
|
|
13
|
+
["blur-up" image loading technique](https://css-tricks.com/the-blur-up-technique-for-loading-background-images/),
|
|
14
|
+
with the
|
|
15
|
+
[blur-hash algorithm](https://blurha.sh/),
|
|
16
|
+
as a
|
|
17
|
+
[web component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components).
|
|
15
18
|
|
|
16
19
|
[See a live demonstration](https://substrate-system.github.io/blur-hash/)
|
|
17
20
|
|
|
@@ -37,7 +40,9 @@ as a [web component](https://developer.mozilla.org/en-US/docs/Web/API/Web_compon
|
|
|
37
40
|
* [Import CSS](#import-css)
|
|
38
41
|
* [variables](#variables)
|
|
39
42
|
- [Create the blur-hash string](#create-the-blur-hash-string)
|
|
43
|
+
* [1. Install the peer dependency](#1-install-the-peer-dependency)
|
|
40
44
|
* [JS API](#js-api)
|
|
45
|
+
* [From raw bytes (Cloudflare Workers)](#from-raw-bytes-cloudflare-workers)
|
|
41
46
|
* [CLI](#cli)
|
|
42
47
|
|
|
43
48
|
<!-- tocstop -->
|
|
@@ -101,6 +106,7 @@ Use the tag in HTML.
|
|
|
101
106
|
```
|
|
102
107
|
|
|
103
108
|
## Use
|
|
109
|
+
|
|
104
110
|
Call the static method `.define` in JS, then use the tag in HTML.
|
|
105
111
|
|
|
106
112
|
```js
|
|
@@ -120,8 +126,9 @@ BlurHash.define()
|
|
|
120
126
|
```
|
|
121
127
|
|
|
122
128
|
### Server-side rendering
|
|
123
|
-
|
|
124
|
-
returns a plain string
|
|
129
|
+
|
|
130
|
+
This module exposes a `render` function at `/html`. It returns a plain string
|
|
131
|
+
of HTML.
|
|
125
132
|
|
|
126
133
|
```js
|
|
127
134
|
import { render } from '@substrate-system/blur-hash/html'
|
|
@@ -130,7 +137,7 @@ const htmlString = render({
|
|
|
130
137
|
alt: 'hello',
|
|
131
138
|
width: 30,
|
|
132
139
|
height: 30,
|
|
133
|
-
placeholder: '
|
|
140
|
+
placeholder: 'UQGudvt700t3~XbIE1xt9Hazs:of.8s:V[Rj',
|
|
134
141
|
src: 'abc.jpg'
|
|
135
142
|
})
|
|
136
143
|
```
|
|
@@ -162,18 +169,19 @@ type Attrs = {
|
|
|
162
169
|
#### other attributes
|
|
163
170
|
|
|
164
171
|
#### time
|
|
172
|
+
|
|
165
173
|
The time for css transitions and animation. This is set as a CSS variable.
|
|
166
174
|
|
|
167
175
|
#### width & height
|
|
176
|
+
|
|
168
177
|
The dimensions for the image
|
|
169
178
|
|
|
170
179
|
----------------------------------------------
|
|
171
180
|
|
|
172
181
|
### `.reset`
|
|
173
182
|
|
|
174
|
-
Change the image, and do the blur-up thing again.
|
|
175
|
-
|
|
176
|
-
Takes a new `src` string, new placeholder string, and all other attributes.
|
|
183
|
+
Change the image, and do the blur-up thing again. Takes a new `src` string,
|
|
184
|
+
new placeholder string, and all other attributes.
|
|
177
185
|
|
|
178
186
|
If `width` and `height` are not passed in, it will keep the existing width
|
|
179
187
|
and height.
|
|
@@ -237,20 +245,60 @@ __CSS variables__
|
|
|
237
245
|
* `--blur-hash-opactiy` -- the opacity to use for the placeholder image,
|
|
238
246
|
default is `0.4`
|
|
239
247
|
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
|
|
240
252
|
## Create the blur-hash string
|
|
241
253
|
|
|
242
254
|
Use Node to create the `placeholder` attribute, the string consumed
|
|
243
255
|
by blur-hash.
|
|
244
256
|
|
|
257
|
+
### 1. Install the peer dependency
|
|
258
|
+
|
|
259
|
+
The hash generator uses [`@cf-wasm/photon`][photon], a WASM build of the
|
|
260
|
+
Photon image library, to decode and resize images. It is an *optional* peer
|
|
261
|
+
dependency, so it is not installed automatically. Add it to your project to
|
|
262
|
+
use the `./hash` or `./photon` entrypoints:
|
|
263
|
+
|
|
264
|
+
```sh
|
|
265
|
+
npm i @cf-wasm/photon
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Browser-only consumers of the `<blur-hash>` component do not need it.
|
|
269
|
+
|
|
270
|
+
[photon]: https://github.com/fineshopdesign/cf-wasm/tree/main/packages/photon
|
|
271
|
+
|
|
245
272
|
### JS API
|
|
246
273
|
|
|
274
|
+
Read an image file from disk (Node only) and get back the blurhash plus the
|
|
275
|
+
original image's dimensions:
|
|
276
|
+
|
|
247
277
|
```js
|
|
248
|
-
import {
|
|
278
|
+
import { createBlurhash } from '@substrate-system/blur-hash/hash'
|
|
249
279
|
|
|
250
|
-
const hash = await
|
|
251
|
-
// => '
|
|
280
|
+
const { hash, width, height } = await createBlurhash('./example/100.jpg')
|
|
281
|
+
// hash => 'UQGudvt700t3~XbIE1xt9Hazs:of.8s:V[Rj'
|
|
282
|
+
// width => 750
|
|
283
|
+
// height => 600
|
|
252
284
|
```
|
|
253
285
|
|
|
286
|
+
|
|
287
|
+
### From raw bytes (Cloudflare Workers)
|
|
288
|
+
|
|
289
|
+
If you already have the image bytes in memory -- for example inside a
|
|
290
|
+
Cloudflare Worker -- use the `./photon` entrypoint, which takes a `Uint8Array`
|
|
291
|
+
and runs in `workerd`:
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
import { encodeImage } from '@substrate-system/blur-hash/photon'
|
|
295
|
+
|
|
296
|
+
const { hash, width, height } = await encodeImage(bytes)
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Both entrypoints run under plain Node and Cloudflare Workers -- the correct
|
|
300
|
+
`@cf-wasm/photon` build resolves automatically per runtime.
|
|
301
|
+
|
|
254
302
|
### CLI
|
|
255
303
|
|
|
256
304
|
This package includes a CLI tool to create the placeholder string. After
|
|
@@ -269,3 +317,7 @@ On mac os,
|
|
|
269
317
|
```sh
|
|
270
318
|
npx blur ./my-file.jpg | pbcopy
|
|
271
319
|
```
|
|
320
|
+
|
|
321
|
+
```
|
|
322
|
+
/ed3d-plan-and-execute:execute-implementation-plan /Users/nick/code/blur-hash/docs/implementation-plans/2026-07-04-photon-blurhash-generation/ /Users/nick/code/blur-hash/
|
|
323
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../bin/index.ts"],"names":[],"mappings":";AAaA,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAE9D;;GAEG;AACH,wBAAsB,cAAc,CAChC,QAAQ,EAAC,MAAM,GACjB,OAAO,CAAC,cAAc,CAAC,CAGxB"}
|
package/dist/bin/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
4
|
import yargs from "yargs";
|
|
4
|
-
import sharp from "sharp";
|
|
5
5
|
import { hideBin } from "yargs/helpers";
|
|
6
|
-
import {
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
7
|
import { resolve } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import { encodeImage } from "./photon.js";
|
|
10
|
+
async function createBlurhash(filepath) {
|
|
11
|
+
const bytes = await readFile(filepath);
|
|
12
|
+
return encodeImage(new Uint8Array(bytes));
|
|
13
|
+
}
|
|
14
|
+
__name(createBlurhash, "createBlurhash");
|
|
13
15
|
const pathToThisFile = resolve(fileURLToPath(import.meta.url));
|
|
14
16
|
const pathPassedToNode = resolve(process.argv[1]);
|
|
15
17
|
const isThisFileBeingRunViaCLI = pathToThisFile.includes(pathPassedToNode);
|
|
@@ -18,7 +20,10 @@ if (isThisFileBeingRunViaCLI) {
|
|
|
18
20
|
"`npx blur my-fiile.jpg`",
|
|
19
21
|
"Create a small placeholder string from a local file"
|
|
20
22
|
).usage("Usage: blur <filename>").argv;
|
|
21
|
-
const filename = args._[0];
|
|
22
|
-
const
|
|
23
|
-
process.stdout.write(hash + "\n");
|
|
23
|
+
const filename = String(args._[0]);
|
|
24
|
+
const result = await createBlurhash(filename);
|
|
25
|
+
process.stdout.write(result.hash + "\n");
|
|
24
26
|
}
|
|
27
|
+
export {
|
|
28
|
+
createBlurhash
|
|
29
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The result of blurhash encoding: the hash string and original image
|
|
3
|
+
* dimensions.
|
|
4
|
+
*/
|
|
5
|
+
export type BlurhashResult = {
|
|
6
|
+
hash: string;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Decode raw image bytes and produce a blurhash string plus the original
|
|
12
|
+
* image's dimensions. Runtime-agnostic: the plain `@cf-wasm/photon` specifier
|
|
13
|
+
* resolves to the `node` build under Node and the `workerd` build under
|
|
14
|
+
* wrangler, so this runs unchanged in both.
|
|
15
|
+
*
|
|
16
|
+
* Throws if the bytes cannot be decoded as an image.
|
|
17
|
+
*/
|
|
18
|
+
export declare function encodeImage(bytes: Uint8Array): Promise<BlurhashResult>;
|
|
19
|
+
//# sourceMappingURL=photon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"photon.d.ts","sourceRoot":"","sources":["../../bin/photon.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAC,MAAM,CAAC;IACZ,KAAK,EAAC,MAAM,CAAC;IACb,MAAM,EAAC,MAAM,CAAC;CACjB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC7B,KAAK,EAAC,UAAU,GAClB,OAAO,CAAC,cAAc,CAAC,CA4CxB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { encode } from "blurhash";
|
|
4
|
+
import {
|
|
5
|
+
PhotonImage,
|
|
6
|
+
SamplingFilter,
|
|
7
|
+
resize
|
|
8
|
+
} from "@cf-wasm/photon";
|
|
9
|
+
const BLURHASH_SIZE = 32;
|
|
10
|
+
const COMPONENTS = 4;
|
|
11
|
+
async function encodeImage(bytes) {
|
|
12
|
+
let original = null;
|
|
13
|
+
let resized = null;
|
|
14
|
+
try {
|
|
15
|
+
original = PhotonImage.new_from_byteslice(bytes);
|
|
16
|
+
const width = original.get_width();
|
|
17
|
+
const height = original.get_height();
|
|
18
|
+
resized = resize(
|
|
19
|
+
original,
|
|
20
|
+
BLURHASH_SIZE,
|
|
21
|
+
BLURHASH_SIZE,
|
|
22
|
+
SamplingFilter.Nearest
|
|
23
|
+
);
|
|
24
|
+
const raw = resized.get_raw_pixels();
|
|
25
|
+
const pixels = new Uint8ClampedArray(
|
|
26
|
+
raw.buffer,
|
|
27
|
+
raw.byteOffset,
|
|
28
|
+
raw.byteLength
|
|
29
|
+
);
|
|
30
|
+
const hash = encode(
|
|
31
|
+
pixels,
|
|
32
|
+
BLURHASH_SIZE,
|
|
33
|
+
BLURHASH_SIZE,
|
|
34
|
+
COMPONENTS,
|
|
35
|
+
COMPONENTS
|
|
36
|
+
);
|
|
37
|
+
return { hash, width, height };
|
|
38
|
+
} finally {
|
|
39
|
+
resized?.free();
|
|
40
|
+
original?.free();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
__name(encodeImage, "encodeImage");
|
|
44
|
+
export {
|
|
45
|
+
encodeImage
|
|
46
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -94,14 +94,14 @@ class BlurHash extends import_web_component.WebComponent.create("blur-hash") {
|
|
|
94
94
|
}
|
|
95
95
|
sharpen() {
|
|
96
96
|
const img = this.qs("img");
|
|
97
|
-
|
|
97
|
+
const toSharp = /* @__PURE__ */ __name(() => {
|
|
98
98
|
img.classList.remove("blurry");
|
|
99
99
|
img.classList.add("sharp");
|
|
100
|
+
}, "toSharp");
|
|
101
|
+
if (img.complete && img.naturalWidth > 0) {
|
|
102
|
+
requestAnimationFrame(() => requestAnimationFrame(toSharp));
|
|
100
103
|
} else {
|
|
101
|
-
img.addEventListener("load",
|
|
102
|
-
img.classList.remove("blurry");
|
|
103
|
-
img.classList.add("sharp");
|
|
104
|
-
});
|
|
104
|
+
img.addEventListener("load", toSharp);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
connectedCallback() {
|
|
@@ -137,7 +137,15 @@ class BlurHash extends import_web_component.WebComponent.create("blur-hash") {
|
|
|
137
137
|
if (!width || !height) throw new Error("not width or not height");
|
|
138
138
|
if (!src) throw new Error("Not src");
|
|
139
139
|
if (!alt) throw new Error("Not alt");
|
|
140
|
-
return BlurHash.html({
|
|
140
|
+
return BlurHash.html({
|
|
141
|
+
classes,
|
|
142
|
+
srcset,
|
|
143
|
+
width,
|
|
144
|
+
height,
|
|
145
|
+
src,
|
|
146
|
+
alt,
|
|
147
|
+
placeholder
|
|
148
|
+
});
|
|
141
149
|
}
|
|
142
150
|
}
|
|
143
151
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { WebComponent } from '@substrate-system/web-component'\nimport { decode } from 'blurhash'\nimport { render } from './html.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\n// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'blur-hash': BlurHash\n }\n}\n\nexport type ImgAttrs = {\n alt:string;\n width:string|number;\n height:string|number;\n placeholder:string;\n src:string;\n srcset?:string|null;\n sizes?:string|null;\n time?:number;\n contentVisibility?:'visible'|'auto'|'hidden'|null;\n decoding?:'sync'|'async'|'auto'|null;\n loading?:'lazy'|'eager'|'auto'|null;\n}\n\nexport class BlurHash extends WebComponent.create('blur-hash') {\n time:number\n rafId:number|null = null\n\n constructor () {\n super()\n const w = this.getAttribute('width')\n const h = this.getAttribute('height')\n const time = this.getAttribute('time')\n this.time = time ? parseInt(time) : 800\n\n this.style.width = '' + w\n this.style.height = '' + h\n\n document.body.style.setProperty('--blur-hash-time',\n time ? '.' + (parseInt(time) / 1000 + 's') : '0.8s')\n }\n\n /**\n * Change the image, and do the blur-up thing again.\n * Will use the existing width & height if they are not passed in.\n */\n reset (attrs:(Omit<Omit<ImgAttrs, 'width'>, 'height'> & {\n width?:string|number;\n height?:string|number;\n })):void {\n if (attrs.width) this.style.width = '' + attrs.width\n if (attrs.height) this.style.height = '' + attrs.height\n\n const width = (attrs.width ?\n (typeof attrs.width === 'string' ? parseInt(attrs.width, 10) : attrs.width) :\n parseInt(this.style.width, 10))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height, 10) : attrs.height) :\n parseInt(this.style.height, 10))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n this.scheduleDecode(placeholder, width, height)\n\n this.setAttribute('src', newSrc)\n this.setAttribute('placeholder', placeholder)\n\n const img = this.querySelector('img')!\n if (attrs.srcset) img.setAttribute('srcset', attrs.srcset)\n if (attrs.sizes) img.setAttribute('sizes', attrs.sizes)\n\n this.sharpen()\n }\n\n /**\n * Decode the placeholder and paint it to the canvas on the next frame.\n * Cancels any pending frame first, so a rapid re-call (e.g. a second\n * `reset`) never leaves a stale decode running. Bails if the element has\n * detached before the frame fires.\n */\n scheduleDecode (placeholder:string, width:number, height:number):void {\n if (this.rafId !== null) cancelAnimationFrame(this.rafId)\n\n const { width: dw, height: dh } = decodeDimensions(width, height)\n\n this.rafId = requestAnimationFrame(() => {\n this.rafId = null\n if (!this.isConnected) return\n const canvas = this.querySelector<HTMLCanvasElement>('canvas')\n if (!canvas) return\n const ctx = canvas.getContext('2d')\n if (!ctx) return\n const pixels = decode(placeholder, dw, dh)\n const imageData = ctx.createImageData(dw, dh)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n })\n }\n\n disconnectedCallback ():void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId)\n this.rafId = null\n }\n }\n\n sharpen () {\n const img = this.qs('img')!\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA6B;AAC7B,sBAAuB;AACvB,kBAAuB;AACvB,+BAAiC;AAuB1B,MAAM,iBAAiB,kCAAa,OAAO,WAAW,EAAE;AAAA,EA1B/D,OA0B+D;AAAA;AAAA;AAAA,EAC3D;AAAA,EACA,QAAoB;AAAA,EAEpB,cAAe;AACX,UAAM;AACN,UAAM,IAAI,KAAK,aAAa,OAAO;AACnC,UAAM,IAAI,KAAK,aAAa,QAAQ;AACpC,UAAM,OAAO,KAAK,aAAa,MAAM;AACrC,SAAK,OAAO,OAAO,SAAS,IAAI,IAAI;AAEpC,SAAK,MAAM,QAAQ,KAAK;AACxB,SAAK,MAAM,SAAS,KAAK;AAEzB,aAAS,KAAK,MAAM;AAAA,MAAY;AAAA,MAC5B,OAAO,OAAO,SAAS,IAAI,IAAI,MAAO,OAAO;AAAA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IAAK;AACV,YAAM,aAAS,wBAAO,aAAa,IAAI,EAAE;AACzC,YAAM,YAAY,IAAI,gBAAgB,IAAI,EAAE;AAC5C,gBAAU,KAAK,IAAI,MAAM;AACzB,UAAI,aAAa,WAAW,GAAG,CAAC;AAAA,IACpC,CAAC;AAAA,EACL;AAAA,EAEA,uBAA6B;AACzB,QAAI,KAAK,UAAU,MAAM;AACrB,2BAAqB,KAAK,KAAK;AAC/B,WAAK,QAAQ;AAAA,IACjB;AAAA,EACJ;AAAA,EAEA,UAAW;AACP,UAAM,MAAM,KAAK,GAAG,KAAK;AACzB,
|
|
4
|
+
"sourcesContent": ["import { WebComponent } from '@substrate-system/web-component'\nimport { decode } from 'blurhash'\nimport { render } from './html.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\n// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'blur-hash': BlurHash\n }\n}\n\nexport type ImgAttrs = {\n alt:string;\n width:string|number;\n height:string|number;\n placeholder:string;\n src:string;\n srcset?:string|null;\n sizes?:string|null;\n time?:number;\n contentVisibility?:'visible'|'auto'|'hidden'|null;\n decoding?:'sync'|'async'|'auto'|null;\n loading?:'lazy'|'eager'|'auto'|null;\n}\n\nexport class BlurHash extends WebComponent.create('blur-hash') {\n time:number\n rafId:number|null = null\n\n constructor () {\n super()\n const w = this.getAttribute('width')\n const h = this.getAttribute('height')\n const time = this.getAttribute('time')\n this.time = time ? parseInt(time) : 800\n\n this.style.width = '' + w\n this.style.height = '' + h\n\n document.body.style.setProperty('--blur-hash-time',\n time ? '.' + (parseInt(time) / 1000 + 's') : '0.8s')\n }\n\n /**\n * Change the image, and do the blur-up thing again.\n * Will use the existing width & height if they are not passed in.\n */\n reset (attrs:(Omit<Omit<ImgAttrs, 'width'>, 'height'> & {\n width?:string|number;\n height?:string|number;\n })):void {\n if (attrs.width) this.style.width = '' + attrs.width\n if (attrs.height) this.style.height = '' + attrs.height\n\n const width = (attrs.width ?\n (typeof attrs.width === 'string' ? parseInt(attrs.width, 10) : attrs.width) :\n parseInt(this.style.width, 10))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height, 10) : attrs.height) :\n parseInt(this.style.height, 10))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n this.scheduleDecode(placeholder, width, height)\n\n this.setAttribute('src', newSrc)\n this.setAttribute('placeholder', placeholder)\n\n const img = this.querySelector('img')!\n if (attrs.srcset) img.setAttribute('srcset', attrs.srcset)\n if (attrs.sizes) img.setAttribute('sizes', attrs.sizes)\n\n this.sharpen()\n }\n\n /**\n * Decode the placeholder and paint it to the canvas on the next frame.\n * Cancels any pending frame first, so a rapid re-call (e.g. a second\n * `reset`) never leaves a stale decode running. Bails if the element has\n * detached before the frame fires.\n */\n scheduleDecode (placeholder:string, width:number, height:number):void {\n if (this.rafId !== null) cancelAnimationFrame(this.rafId)\n\n const { width: dw, height: dh } = decodeDimensions(width, height)\n\n this.rafId = requestAnimationFrame(() => {\n this.rafId = null\n if (!this.isConnected) return\n const canvas = this.querySelector<HTMLCanvasElement>('canvas')\n if (!canvas) return\n const ctx = canvas.getContext('2d')\n if (!ctx) return\n const pixels = decode(placeholder, dw, dh)\n const imageData = ctx.createImageData(dw, dh)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n })\n }\n\n disconnectedCallback ():void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId)\n this.rafId = null\n }\n }\n\n sharpen () {\n const img = this.qs('img')!\n const toSharp = () => {\n img.classList.remove('blurry')\n img.classList.add('sharp')\n }\n\n if (img.complete && img.naturalWidth > 0) {\n // The image is already decoded, so the class swap would run in\n // this same task -- before the browser ever paints the .blurry\n // (opacity:0) frame, and a CSS transition needs that start frame\n // to have painted or it does not run. Defer behind a double rAF\n // so one .blurry frame is rendered first; then the opacity fade\n // runs. A single rAF is not enough: it fires before the current\n // frame paints.\n requestAnimationFrame(() => requestAnimationFrame(toSharp))\n } else {\n // Still loading: the swap is deferred to `load`, which fires in a\n // later task after the .blurry frame has already painted.\n img.addEventListener('load', toSharp)\n }\n }\n\n connectedCallback () {\n const width = parseInt(this.getAttribute('width') ?? '')\n const height = parseInt(this.getAttribute('height') ?? '')\n const placeholder = this.getAttribute('placeholder')\n if (!placeholder) throw new Error('Missing placeholder')\n if (!width) throw new Error('Missing width')\n if (!height) throw new Error('Missing height')\n\n // don't render again if we dont have to\n if (!this.innerHTML) {\n this.innerHTML = this.render()\n }\n\n this.scheduleDecode(placeholder, width, height)\n this.sharpen()\n }\n\n static html (attrs:ImgAttrs & { classes?:string }) {\n return render(attrs)\n }\n\n /**\n * Use the attributes to create HTML.\n */\n render ():string {\n const srcset = this.getAttribute('srcset')\n const width = this.getAttribute('width')\n const height = this.getAttribute('height')\n const time = this.getAttribute('time')\n const classes = this.classList.toString()\n const placeholder = this.getAttribute('placeholder')\n this.time = time ? parseInt(time) : 800\n const src = this.getAttribute('src')\n const alt = this.getAttribute('alt')\n if (!placeholder) throw new Error('not placeholder')\n if (!width || !height) throw new Error('not width or not height')\n if (!src) throw new Error('Not src')\n if (!alt) throw new Error('Not alt')\n\n return BlurHash.html({\n classes,\n srcset,\n width,\n height,\n src,\n alt,\n placeholder\n })\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA6B;AAC7B,sBAAuB;AACvB,kBAAuB;AACvB,+BAAiC;AAuB1B,MAAM,iBAAiB,kCAAa,OAAO,WAAW,EAAE;AAAA,EA1B/D,OA0B+D;AAAA;AAAA;AAAA,EAC3D;AAAA,EACA,QAAoB;AAAA,EAEpB,cAAe;AACX,UAAM;AACN,UAAM,IAAI,KAAK,aAAa,OAAO;AACnC,UAAM,IAAI,KAAK,aAAa,QAAQ;AACpC,UAAM,OAAO,KAAK,aAAa,MAAM;AACrC,SAAK,OAAO,OAAO,SAAS,IAAI,IAAI;AAEpC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AAQ;AAAA,EACjB;AAAA,EAEA,OAAO,KAAM,OAAsC;AAC/C,eAAO,oBAAO,KAAK;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAiB;AACb,UAAM,SAAS,KAAK,aAAa,QAAQ;AACzC,UAAM,QAAQ,KAAK,aAAa,OAAO;AACvC,UAAM,SAAS,KAAK,aAAa,QAAQ;AACzC,UAAM,OAAO,KAAK,aAAa,MAAM;AACrC,UAAM,UAAU,KAAK,UAAU,SAAS;AACxC,UAAM,cAAc,KAAK,aAAa,aAAa;AACnD,SAAK,OAAO,OAAO,SAAS,IAAI,IAAI;AACpC,UAAM,MAAM,KAAK,aAAa,KAAK;AACnC,UAAM,MAAM,KAAK,aAAa,KAAK;AACnC,QAAI,CAAC,YAAa,OAAM,IAAI,MAAM,iBAAiB;AACnD,QAAI,CAAC,SAAS,CAAC,OAAQ,OAAM,IAAI,MAAM,yBAAyB;AAChE,QAAI,CAAC,IAAK,OAAM,IAAI,MAAM,SAAS;AACnC,QAAI,CAAC,IAAK,OAAM,IAAI,MAAM,SAAS;AAEnC,WAAO,SAAS,KAAK;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -72,14 +72,14 @@ class BlurHash extends WebComponent.create("blur-hash") {
|
|
|
72
72
|
}
|
|
73
73
|
sharpen() {
|
|
74
74
|
const img = this.qs("img");
|
|
75
|
-
|
|
75
|
+
const toSharp = /* @__PURE__ */ __name(() => {
|
|
76
76
|
img.classList.remove("blurry");
|
|
77
77
|
img.classList.add("sharp");
|
|
78
|
+
}, "toSharp");
|
|
79
|
+
if (img.complete && img.naturalWidth > 0) {
|
|
80
|
+
requestAnimationFrame(() => requestAnimationFrame(toSharp));
|
|
78
81
|
} else {
|
|
79
|
-
img.addEventListener("load",
|
|
80
|
-
img.classList.remove("blurry");
|
|
81
|
-
img.classList.add("sharp");
|
|
82
|
-
});
|
|
82
|
+
img.addEventListener("load", toSharp);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
connectedCallback() {
|
|
@@ -115,7 +115,15 @@ class BlurHash extends WebComponent.create("blur-hash") {
|
|
|
115
115
|
if (!width || !height) throw new Error("not width or not height");
|
|
116
116
|
if (!src) throw new Error("Not src");
|
|
117
117
|
if (!alt) throw new Error("Not alt");
|
|
118
|
-
return BlurHash.html({
|
|
118
|
+
return BlurHash.html({
|
|
119
|
+
classes,
|
|
120
|
+
srcset,
|
|
121
|
+
width,
|
|
122
|
+
height,
|
|
123
|
+
src,
|
|
124
|
+
alt,
|
|
125
|
+
placeholder
|
|
126
|
+
});
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
export {
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { WebComponent } from '@substrate-system/web-component'\nimport { decode } from 'blurhash'\nimport { render } from './html.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\n// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'blur-hash': BlurHash\n }\n}\n\nexport type ImgAttrs = {\n alt:string;\n width:string|number;\n height:string|number;\n placeholder:string;\n src:string;\n srcset?:string|null;\n sizes?:string|null;\n time?:number;\n contentVisibility?:'visible'|'auto'|'hidden'|null;\n decoding?:'sync'|'async'|'auto'|null;\n loading?:'lazy'|'eager'|'auto'|null;\n}\n\nexport class BlurHash extends WebComponent.create('blur-hash') {\n time:number\n rafId:number|null = null\n\n constructor () {\n super()\n const w = this.getAttribute('width')\n const h = this.getAttribute('height')\n const time = this.getAttribute('time')\n this.time = time ? parseInt(time) : 800\n\n this.style.width = '' + w\n this.style.height = '' + h\n\n document.body.style.setProperty('--blur-hash-time',\n time ? '.' + (parseInt(time) / 1000 + 's') : '0.8s')\n }\n\n /**\n * Change the image, and do the blur-up thing again.\n * Will use the existing width & height if they are not passed in.\n */\n reset (attrs:(Omit<Omit<ImgAttrs, 'width'>, 'height'> & {\n width?:string|number;\n height?:string|number;\n })):void {\n if (attrs.width) this.style.width = '' + attrs.width\n if (attrs.height) this.style.height = '' + attrs.height\n\n const width = (attrs.width ?\n (typeof attrs.width === 'string' ? parseInt(attrs.width, 10) : attrs.width) :\n parseInt(this.style.width, 10))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height, 10) : attrs.height) :\n parseInt(this.style.height, 10))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n this.scheduleDecode(placeholder, width, height)\n\n this.setAttribute('src', newSrc)\n this.setAttribute('placeholder', placeholder)\n\n const img = this.querySelector('img')!\n if (attrs.srcset) img.setAttribute('srcset', attrs.srcset)\n if (attrs.sizes) img.setAttribute('sizes', attrs.sizes)\n\n this.sharpen()\n }\n\n /**\n * Decode the placeholder and paint it to the canvas on the next frame.\n * Cancels any pending frame first, so a rapid re-call (e.g. a second\n * `reset`) never leaves a stale decode running. Bails if the element has\n * detached before the frame fires.\n */\n scheduleDecode (placeholder:string, width:number, height:number):void {\n if (this.rafId !== null) cancelAnimationFrame(this.rafId)\n\n const { width: dw, height: dh } = decodeDimensions(width, height)\n\n this.rafId = requestAnimationFrame(() => {\n this.rafId = null\n if (!this.isConnected) return\n const canvas = this.querySelector<HTMLCanvasElement>('canvas')\n if (!canvas) return\n const ctx = canvas.getContext('2d')\n if (!ctx) return\n const pixels = decode(placeholder, dw, dh)\n const imageData = ctx.createImageData(dw, dh)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n })\n }\n\n disconnectedCallback ():void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId)\n this.rafId = null\n }\n }\n\n sharpen () {\n const img = this.qs('img')!\n
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K,cAAc,KAAK;AACpC,QAAI,MAAM,OAAQ,KAAI,aAAa,UAAU,MAAM,MAAM;AACzD,QAAI,MAAM,MAAO,KAAI,aAAa,SAAS,MAAM,KAAK;AAEtD,SAAK,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,eAAgB,aAAoB,OAAc,QAAoB;AAClE,QAAI,KAAK,UAAU,KAAM,sBAAqB,KAAK,KAAK;AAExD,UAAM,EAAE,OAAO,IAAI,QAAQ,GAAG,IAAI,iBAAiB,OAAO,MAAM;AAEhE,SAAK,QAAQ,sBAAsB,MAAM;AACrC,WAAK,QAAQ;AACb,UAAI,CAAC,KAAK,YAAa;AACvB,YAAM,SAAS,KAAK,cAAiC,QAAQ;AAC7D,UAAI,CAAC,OAAQ;AACb,YAAM,MAAM,OAAO,WAAW,IAAI;AAClC,UAAI,CAAC,IAAK;AACV,YAAM,SAAS,OAAO,aAAa,IAAI,EAAE;AACzC,YAAM,YAAY,IAAI,gBAAgB,IAAI,EAAE;AAC5C,gBAAU,KAAK,IAAI,MAAM;AACzB,UAAI,aAAa,WAAW,GAAG,CAAC;AAAA,IACpC,CAAC;AAAA,EACL;AAAA,EAEA,uBAA6B;AACzB,QAAI,KAAK,UAAU,MAAM;AACrB,2BAAqB,KAAK,KAAK;AAC/B,WAAK,QAAQ;AAAA,IACjB;AAAA,EACJ;AAAA,EAEA,UAAW;AACP,UAAM,MAAM,KAAK,GAAG,KAAK;AACzB,
|
|
4
|
+
"sourcesContent": ["import { WebComponent } from '@substrate-system/web-component'\nimport { decode } from 'blurhash'\nimport { render } from './html.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\n// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'blur-hash': BlurHash\n }\n}\n\nexport type ImgAttrs = {\n alt:string;\n width:string|number;\n height:string|number;\n placeholder:string;\n src:string;\n srcset?:string|null;\n sizes?:string|null;\n time?:number;\n contentVisibility?:'visible'|'auto'|'hidden'|null;\n decoding?:'sync'|'async'|'auto'|null;\n loading?:'lazy'|'eager'|'auto'|null;\n}\n\nexport class BlurHash extends WebComponent.create('blur-hash') {\n time:number\n rafId:number|null = null\n\n constructor () {\n super()\n const w = this.getAttribute('width')\n const h = this.getAttribute('height')\n const time = this.getAttribute('time')\n this.time = time ? parseInt(time) : 800\n\n this.style.width = '' + w\n this.style.height = '' + h\n\n document.body.style.setProperty('--blur-hash-time',\n time ? '.' + (parseInt(time) / 1000 + 's') : '0.8s')\n }\n\n /**\n * Change the image, and do the blur-up thing again.\n * Will use the existing width & height if they are not passed in.\n */\n reset (attrs:(Omit<Omit<ImgAttrs, 'width'>, 'height'> & {\n width?:string|number;\n height?:string|number;\n })):void {\n if (attrs.width) this.style.width = '' + attrs.width\n if (attrs.height) this.style.height = '' + attrs.height\n\n const width = (attrs.width ?\n (typeof attrs.width === 'string' ? parseInt(attrs.width, 10) : attrs.width) :\n parseInt(this.style.width, 10))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height, 10) : attrs.height) :\n parseInt(this.style.height, 10))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n this.scheduleDecode(placeholder, width, height)\n\n this.setAttribute('src', newSrc)\n this.setAttribute('placeholder', placeholder)\n\n const img = this.querySelector('img')!\n if (attrs.srcset) img.setAttribute('srcset', attrs.srcset)\n if (attrs.sizes) img.setAttribute('sizes', attrs.sizes)\n\n this.sharpen()\n }\n\n /**\n * Decode the placeholder and paint it to the canvas on the next frame.\n * Cancels any pending frame first, so a rapid re-call (e.g. a second\n * `reset`) never leaves a stale decode running. Bails if the element has\n * detached before the frame fires.\n */\n scheduleDecode (placeholder:string, width:number, height:number):void {\n if (this.rafId !== null) cancelAnimationFrame(this.rafId)\n\n const { width: dw, height: dh } = decodeDimensions(width, height)\n\n this.rafId = requestAnimationFrame(() => {\n this.rafId = null\n if (!this.isConnected) return\n const canvas = this.querySelector<HTMLCanvasElement>('canvas')\n if (!canvas) return\n const ctx = canvas.getContext('2d')\n if (!ctx) return\n const pixels = decode(placeholder, dw, dh)\n const imageData = ctx.createImageData(dw, dh)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n })\n }\n\n disconnectedCallback ():void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId)\n this.rafId = null\n }\n }\n\n sharpen () {\n const img = this.qs('img')!\n const toSharp = () => {\n img.classList.remove('blurry')\n img.classList.add('sharp')\n }\n\n if (img.complete && img.naturalWidth > 0) {\n // The image is already decoded, so the class swap would run in\n // this same task -- before the browser ever paints the .blurry\n // (opacity:0) frame, and a CSS transition needs that start frame\n // to have painted or it does not run. Defer behind a double rAF\n // so one .blurry frame is rendered first; then the opacity fade\n // runs. A single rAF is not enough: it fires before the current\n // frame paints.\n requestAnimationFrame(() => requestAnimationFrame(toSharp))\n } else {\n // Still loading: the swap is deferred to `load`, which fires in a\n // later task after the .blurry frame has already painted.\n img.addEventListener('load', toSharp)\n }\n }\n\n connectedCallback () {\n const width = parseInt(this.getAttribute('width') ?? '')\n const height = parseInt(this.getAttribute('height') ?? '')\n const placeholder = this.getAttribute('placeholder')\n if (!placeholder) throw new Error('Missing placeholder')\n if (!width) throw new Error('Missing width')\n if (!height) throw new Error('Missing height')\n\n // don't render again if we dont have to\n if (!this.innerHTML) {\n this.innerHTML = this.render()\n }\n\n this.scheduleDecode(placeholder, width, height)\n this.sharpen()\n }\n\n static html (attrs:ImgAttrs & { classes?:string }) {\n return render(attrs)\n }\n\n /**\n * Use the attributes to create HTML.\n */\n render ():string {\n const srcset = this.getAttribute('srcset')\n const width = this.getAttribute('width')\n const height = this.getAttribute('height')\n const time = this.getAttribute('time')\n const classes = this.classList.toString()\n const placeholder = this.getAttribute('placeholder')\n this.time = time ? parseInt(time) : 800\n const src = this.getAttribute('src')\n const alt = this.getAttribute('alt')\n if (!placeholder) throw new Error('not placeholder')\n if (!width || !height) throw new Error('not width or not height')\n if (!src) throw new Error('Not src')\n if (!alt) throw new Error('Not alt')\n\n return BlurHash.html({\n classes,\n srcset,\n width,\n height,\n src,\n alt,\n placeholder\n })\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,wBAAwB;AAuB1B,MAAM,iBAAiB,aAAa,OAAO,WAAW,EAAE;AAAA,EA1B/D,OA0B+D;AAAA;AAAA;AAAA,EAC3D;AAAA,EACA,QAAoB;AAAA,EAEpB,cAAe;AACX,UAAM;AACN,UAAM,IAAI,KAAK,aAAa,OAAO;AACnC,UAAM,IAAI,KAAK,aAAa,QAAQ;AACpC,UAAM,OAAO,KAAK,aAAa,MAAM;AACrC,SAAK,OAAO,OAAO,SAAS,IAAI,IAAI;AAEpC,SAAK,MAAM,QAAQ,KAAK;AACxB,SAAK,MAAM,SAAS,KAAK;AAEzB,aAAS,KAAK,MAAM;AAAA,MAAY;AAAA,MAC5B,OAAO,OAAO,SAAS,IAAI,IAAI,MAAO,OAAO;AAAA,IAAM;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAO,OAGE;AACL,QAAI,MAAM,MAAO,MAAK,MAAM,QAAQ,KAAK,MAAM;AAC/C,QAAI,MAAM,OAAQ,MAAK,MAAM,SAAS,KAAK,MAAM;AAEjD,UAAM,QAAS,MAAM,QAChB,OAAO,MAAM,UAAU,WAAW,SAAS,MAAM,OAAO,EAAE,IAAI,MAAM,QACrE,SAAS,KAAK,MAAM,OAAO,EAAE;AACjC,UAAM,SAAU,MAAM,SACjB,OAAO,MAAM,WAAW,WAAW,SAAS,MAAM,QAAQ,EAAE,IAAI,MAAM,SACvE,SAAS,KAAK,MAAM,QAAQ,EAAE;AAElC,SAAK,YAAY,SAAS,KAAK,OAAO,OAAO,OAAO,EAAE,OAAO,OAAO,CAAC,CAAC;AAEtE,UAAM,EAAE,aAAa,KAAK,OAAO,IAAI;A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A;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.min.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
alt="${
|
|
3
|
-
width=${
|
|
4
|
-
height=${
|
|
1
|
+
var V=Object.defineProperty;var i=(e,t)=>V(e,"name",{value:t,configurable:!0});var W=Object.defineProperty,K=i((e,t)=>W(e,"name",{value:t,configurable:!0}),"__name");function y(e){return Object.keys(e).reduce((t,r)=>{let n=e[r];return n?typeof n=="boolean"?n?(t+` ${r}`).trim():t:Array.isArray(n)?t+` ${r}="${n.join(" ")}"`:(t+` ${r}="${n}"`).trim():t},"")}i(y,"toAttributes");K(y,"toAttributes");var k=Object.defineProperty,$=i((e,t)=>k(e,"name",{value:t,configurable:!0}),"__name");function O(e){return document.createElement(e).constructor!==window.HTMLElement}i(O,"isRegistered");$(O,"isRegistered");function U(e,t){window&&"customElements"in window&&(O(e)||window.customElements.define(e,t))}i(U,"define");$(U,"define");var ot=document.querySelector.bind(document),at=document.querySelectorAll.bind(document);function S(e,t){return e.matches||(e=e.parentElement),e.matches(t)?e:e.closest(t)}i(S,"match");$(S,"match");var J=Object.defineProperty,f=i((e,t)=>J(e,"name",{value:t,configurable:!0}),"__name"),v=class e extends window.HTMLElement{static{i(this,"WebComponent")}static{f(this,"WebComponent")}static TAG="";TAG="";static reflectedBooleanAttributes=[];static reflectedStringAttributes=[];static get observedAttributes(){return[...new Set([...this.reflectedBooleanAttributes,...this.reflectedStringAttributes])]}static match(t){return S(t,this.TAG)}static create(t){let r=class extends e{static{i(this,"CreatedClass")}static{f(this,"CreatedClass")}static TAG=t;TAG=t;render(){throw new Error("`render` should be implemented by children")}};return r.define=function(){return e.define.call(this)},r.event=function(n){return e.event.call(this,n)},r}static define(){D(this.TAG,this)}attributeChangedCallback(t,r,n){let s=this[H(t)];s&&s.call(this,r,n)}connectedCallback(){this.render()}qs(t){return this.querySelector(t)}qsa(t){return this.querySelectorAll(t)}static event(t){return q(this.TAG,t)}emit(t,r={}){if(t==="*")throw new Error('Do not emit the literal "*"');let{bubbles:n=!0,cancelable:s=!0,detail:a}=r,o=`${this.TAG}:${t}`,h=new CustomEvent(o,{bubbles:n,cancelable:s,detail:a});return this.dispatchEvent(h)}dispatch(t,r={}){let n=new CustomEvent(t,{bubbles:r.bubbles===void 0?!0:r.bubbles,cancelable:r.cancelable===void 0?!0:r.cancelable,detail:r.detail});return this.dispatchEvent(n)}on(t,r,n){let s=e.event.call(this,t);this.addEventListener(s,r,n)}off(t,r,n){let s=e.event.call(this,t);this.removeEventListener(s,r,n)}};function q(e,t){return`${e}:${t}`}i(q,"eventName");f(q,"eventName");var P=Object.create(null);function H(e){return P[e]||(P[e]=`handleChange_${e}`)}i(H,"handlerKey");f(H,"handlerKey");function j(e){return document.createElement(e).constructor!==window.HTMLElement}i(j,"isRegistered");f(j,"isRegistered");function D(e,t){if(typeof window>"u"||!("customElements"in window)||j(e))return;let r=t,n=r.reflectedBooleanAttributes??[],s=r.reflectedStringAttributes??[],a=t.prototype;for(let o of n)o in HTMLElement.prototype||Object.getOwnPropertyDescriptor(a,o)||Object.defineProperty(a,o,{get(){return this.hasAttribute(o)},set(h){this.toggleAttribute(o,!!h)},configurable:!0,enumerable:!0});for(let o of s){if(n.includes(o)){console.warn(`[web-component] "${o}" appears in both reflectedBooleanAttributes and reflectedStringAttributes on <${e}>. Boolean wins.`);continue}o in HTMLElement.prototype||Object.getOwnPropertyDescriptor(a,o)||Object.defineProperty(a,o,{get(){return this.getAttribute(o)},set(h){h==null?this.removeAttribute(o):this.setAttribute(o,String(h))},configurable:!0,enumerable:!0})}window.customElements.define(e,t)}i(D,"define");f(D,"define");var Q=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],p=i(e=>{let t=0;for(let r=0;r<e.length;r++){let n=e[r],s=Q.indexOf(n);t=t*83+s}return t},"x");var T=i(e=>{let t=e/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},"f"),C=i(e=>{let t=Math.max(0,Math.min(1,e));return t<=.0031308?Math.trunc(t*12.92*255+.5):Math.trunc((1.055*Math.pow(t,.4166666666666667)-.055)*255+.5)},"h"),X=i(e=>e<0?-1:1,"F"),L=i((e,t)=>X(e)*Math.pow(Math.abs(e),t),"M"),z=class extends Error{static{i(this,"d")}constructor(e){super(e),this.name="ValidationError",this.message=e}},Y=i(e=>{if(!e||e.length<6)throw new z("The blurhash string must be at least 6 characters");let t=p(e[0]),r=Math.floor(t/9)+1,n=t%9+1;if(e.length!==4+2*n*r)throw new z(`blurhash length mismatch: length is ${e.length} but it should be ${4+2*n*r}`)},"C");var Z=i(e=>{let t=e>>16,r=e>>8&255,n=e&255;return[T(t),T(r),T(n)]},"z"),tt=i((e,t)=>{let r=Math.floor(e/361),n=Math.floor(e/19)%19,s=e%19;return[L((r-9)/9,2)*t,L((n-9)/9,2)*t,L((s-9)/9,2)*t]},"L"),et=i((e,t,r,n)=>{Y(e),n=n|1;let s=p(e[0]),a=Math.floor(s/9)+1,o=s%9+1,h=(p(e[1])+1)/166,u=new Array(o*a);for(let l=0;l<u.length;l++)if(l===0){let c=p(e.substring(2,6));u[l]=Z(c)}else{let c=p(e.substring(4+l*2,6+l*2));u[l]=tt(c,h*n)}let d=t*4,m=new Uint8ClampedArray(d*r);for(let l=0;l<r;l++)for(let c=0;c<t;c++){let g=0,b=0,w=0;for(let A=0;A<a;A++)for(let M=0;M<o;M++){let x=Math.cos(Math.PI*c*M/t)*Math.cos(Math.PI*l*A/r),I=u[M+A*o];g+=I[0]*x,b+=I[1]*x,w+=I[2]*x}let N=C(g),_=C(b),F=C(w);m[4*c+0+l*d]=N,m[4*c+1+l*d]=_,m[4*c+2+l*d]=F,m[4*c+3+l*d]=255}return m},"U"),B=et;function E(e,t,r=32){let n=Math.max(e,t);if(n<=r)return{width:e,height:t};let s=r/n;return{width:Math.max(1,Math.round(e*s)),height:Math.max(1,Math.round(t*s))}}i(E,"decodeDimensions");function G(e){let{width:t,height:r,alt:n,contentVisibility:s,placeholder:a,decoding:o,loading:h,srcset:u,sizes:d,src:m}=e;if(!a)throw new Error("not placeholder");let l=typeof t=="string"?parseInt(t,10):t,c=typeof r=="string"?parseInt(r,10):r,g=E(l,c),b=`<canvas
|
|
2
|
+
alt="${n}"
|
|
3
|
+
width=${g.width}
|
|
4
|
+
height=${g.height}
|
|
5
5
|
class="blurry"
|
|
6
6
|
></canvas>
|
|
7
7
|
|
|
8
8
|
<img class="blurry"
|
|
9
|
-
alt="${
|
|
10
|
-
content-visibility="${
|
|
9
|
+
alt="${n}"
|
|
10
|
+
content-visibility="${s||"auto"}"
|
|
11
11
|
decoding="${o||"async"}"
|
|
12
|
-
loading="${
|
|
13
|
-
${
|
|
14
|
-
${
|
|
15
|
-
src="${
|
|
16
|
-
/>`,w=
|
|
12
|
+
loading="${h||"lazy"}"
|
|
13
|
+
${u?`srcset="${u}"`:""}
|
|
14
|
+
${d?`sizes="${d}"`:""}
|
|
15
|
+
src="${m}"
|
|
16
|
+
/>`,w=y(e);return typeof window>"u"?`<blur-hash ${w}>
|
|
17
17
|
${b}
|
|
18
|
-
</blur-hash>`:b}
|
|
18
|
+
</blur-hash>`:b}i(G,"render");var R=class e extends v.create("blur-hash"){static{i(this,"BlurHash")}time;rafId=null;constructor(){super();let t=this.getAttribute("width"),r=this.getAttribute("height"),n=this.getAttribute("time");this.time=n?parseInt(n):800,this.style.width=""+t,this.style.height=""+r,document.body.style.setProperty("--blur-hash-time",n?"."+(parseInt(n)/1e3+"s"):"0.8s")}reset(t){t.width&&(this.style.width=""+t.width),t.height&&(this.style.height=""+t.height);let r=t.width?typeof t.width=="string"?parseInt(t.width,10):t.width:parseInt(this.style.width,10),n=t.height?typeof t.height=="string"?parseInt(t.height,10):t.height:parseInt(this.style.height,10);this.innerHTML=e.html(Object.assign(t,{width:r,height:n}));let{placeholder:s,src:a}=t;this.scheduleDecode(s,r,n),this.setAttribute("src",a),this.setAttribute("placeholder",s);let o=this.querySelector("img");t.srcset&&o.setAttribute("srcset",t.srcset),t.sizes&&o.setAttribute("sizes",t.sizes),this.sharpen()}scheduleDecode(t,r,n){this.rafId!==null&&cancelAnimationFrame(this.rafId);let{width:s,height:a}=E(r,n);this.rafId=requestAnimationFrame(()=>{if(this.rafId=null,!this.isConnected)return;let o=this.querySelector("canvas");if(!o)return;let h=o.getContext("2d");if(!h)return;let u=B(t,s,a),d=h.createImageData(s,a);d.data.set(u),h.putImageData(d,0,0)})}disconnectedCallback(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}sharpen(){let t=this.qs("img"),r=i(()=>{t.classList.remove("blurry"),t.classList.add("sharp")},"toSharp");t.complete&&t.naturalWidth>0?requestAnimationFrame(()=>requestAnimationFrame(r)):t.addEventListener("load",r)}connectedCallback(){let t=parseInt(this.getAttribute("width")??""),r=parseInt(this.getAttribute("height")??""),n=this.getAttribute("placeholder");if(!n)throw new Error("Missing placeholder");if(!t)throw new Error("Missing width");if(!r)throw new Error("Missing height");this.innerHTML||(this.innerHTML=this.render()),this.scheduleDecode(n,t,r),this.sharpen()}static html(t){return G(t)}render(){let t=this.getAttribute("srcset"),r=this.getAttribute("width"),n=this.getAttribute("height"),s=this.getAttribute("time"),a=this.classList.toString(),o=this.getAttribute("placeholder");this.time=s?parseInt(s):800;let h=this.getAttribute("src"),u=this.getAttribute("alt");if(!o)throw new Error("not placeholder");if(!r||!n)throw new Error("not width or not height");if(!h)throw new Error("Not src");if(!u)throw new Error("Not alt");return e.html({classes:a,srcset:t,width:r,height:n,src:h,alt:u,placeholder:o})}};export{R as BlurHash};
|
|
19
19
|
//# sourceMappingURL=index.min.js.map
|
package/dist/index.min.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../node_modules/@substrate-system/web-component/src/attributes.ts", "../node_modules/@substrate-system/web-component/src/util.ts", "../node_modules/@substrate-system/web-component/src/index.ts", "../node_modules/blurhash/src/base83.ts", "../node_modules/blurhash/src/utils.ts", "../node_modules/blurhash/src/error.ts", "../node_modules/blurhash/src/decode.ts", "../node_modules/blurhash/src/encode.ts", "../src/decode-dimensions.ts", "../src/html.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export type Attrs = Record<string, undefined|null|string|number|boolean|(string|number)[]>\n\n/**\n * Transform an object into an HTML attributes string. The object should be\n * like `{ attributeName: value }`.\n *\n * @param attrs An object for the attributes.\n * @returns {string} A string suitable for use as HTML attributes.\n */\nexport function toAttributes (attrs:Attrs):string {\n return Object.keys(attrs).reduce((acc, k) => {\n const value = attrs[k]\n if (!value) return acc\n\n if (typeof value === 'boolean') {\n if (value) return (acc + ` ${k}`).trim()\n return acc\n }\n\n if (Array.isArray(value)) {\n return (acc + ` ${k}=\"${value.join(' ')}\"`)\n }\n\n return (acc + ` ${k}=\"${value}\"`).trim()\n }, '')\n}\n", "export { toAttributes } from './attributes.js'\n\n/**\n * Check if the given tag name has been registered.\n *\n * @see {@link https://stackoverflow.com/a/28210364 stackoverflow}\n * @param {string} elName The custom element tag name.\n * @returns {boolean} True if the given name has been registered already.\n */\nexport function isRegistered (elName:string):boolean {\n return document.createElement(elName).constructor !== window.HTMLElement\n}\n\nexport function define (name:string, element:CustomElementConstructor) {\n if (!window) return\n if (!('customElements' in window)) return\n\n if (!isRegistered(name)) {\n window.customElements.define(name, element)\n }\n}\n\nexport const qs = document.querySelector.bind(document)\nexport const qsa = document.querySelectorAll.bind(document)\n\n/**\n * Get the closes parent element matching the given selector.\n * @param el Element to start from\n * @param s Selector for an element\n * @returns {HTMLElement|null} The closes parent element that matches.\n */\nexport function match (el:HTMLElement, s:string):HTMLElement|null {\n if (!el.matches) el = el.parentElement!\n return el.matches(s) ? el : el.closest(s)\n}\n", "import { match as _match } from './util.js'\n\ninterface WildcardListenerEntry {\n listener:EventListenerOrEventListenerObject\n options?:boolean|AddEventListenerOptions\n}\n\nexport abstract class WebComponent extends window.HTMLElement {\n static TAG:string = ''\n TAG:string = ''\n\n /**\n * Declare boolean attributes that should be reflected as properties.\n * The base class auto-generates getters/setters and includes these in\n * `observedAttributes`. Framework property assignment (e.g. Preact's\n * `el.disabled = true`) will then correctly set the attribute.\n */\n static reflectedBooleanAttributes:string[] = []\n\n /**\n * Declare string attributes that should be reflected as properties.\n * Getter returns `string|null` (null when attribute is absent).\n * Setting `null` or `undefined` removes the attribute.\n */\n static reflectedStringAttributes:string[] = []\n\n /**\n * Auto-derived from `reflectedBooleanAttributes` and\n * `reflectedStringAttributes`. Override with `super.observedAttributes`\n * to add non-reflected observed attributes:\n *\n * ```ts\n * static get observedAttributes () {\n * return [...super.observedAttributes, 'aria-label']\n * }\n * ```\n */\n static get observedAttributes ():string[] {\n return [...new Set([\n ...this.reflectedBooleanAttributes,\n ...this.reflectedStringAttributes,\n ])]\n }\n\n static match (el:HTMLElement):HTMLElement|null {\n return _match(el, this.TAG)\n }\n\n /**\n * Store global wildcard listeners (listen to all events)\n * Triggered by ALL events dispatched through this element\n * @private\n */\n private _globalWildcardListeners:Set<WildcardListenerEntry> = new Set()\n\n /**\n * Store namespaced wildcard listeners (listen to 'component-name:*')\n * Triggered by events from emit() that match this component's namespace\n * @private\n */\n private _namespacedWildcardListeners:Set<WildcardListenerEntry> = new Set()\n\n static create (elementName:string):typeof WebComponent & {\n new (...args:any[]):WebComponent;\n TAG:string;\n define: typeof WebComponent.define;\n event: typeof WebComponent.event;\n } {\n const CreatedClass = class extends WebComponent {\n static TAG = elementName\n TAG = elementName\n render () {\n throw new Error('`render` should be implemented by children')\n }\n }\n\n // Copy static methods with proper binding\n CreatedClass.define = function () {\n return WebComponent.define.call(this)\n }\n CreatedClass.event = function (evType:string) {\n return WebComponent.event.call(this, evType)\n }\n\n return CreatedClass\n }\n\n static define<T extends {\n new (...args:any[]):WebComponent;\n TAG:string;\n }>(this:T) {\n define(this.TAG, this)\n }\n\n /**\n * Runs when the value of an attribute is changed.\n *\n * Depends on `static observedAttributes`.\n *\n * Should name methods like `handleChange_disabled`.\n *\n * @param {string} name The attribute name\n * @param {string} oldValue The old attribute value\n * @param {string} newValue The new attribute value\n */\n async attributeChangedCallback (\n name:string,\n oldValue:string,\n newValue:string\n ):Promise<void> {\n const handler = this[`handleChange_${name}`]\n if (handler) {\n await handler.call(this, oldValue, newValue)\n }\n }\n\n /**\n * Enhanced addEventListener that supports wildcards:\n * - Component.event('*') - Listen to all namespaced events for this\n * component (e.g., 'my-component:*')\n * - '*' - Listen to ALL events (namespaced and non-namespaced, including\n * normal DOM events)\n *\n * @param type - Event type, Component.event('*') for namespaced wildcard,\n * or '*' for global wildcard\n * @param listener - Event listener function or object\n * @param options - Event listener options\n */\n addEventListener (\n type:string,\n listener:EventListenerOrEventListenerObject,\n options?:boolean|AddEventListenerOptions\n ): void {\n if (type === WebComponent.event.call(this, '*')) {\n // Handle namespaced wildcard listener (component-name:*)\n this._namespacedWildcardListeners.add({ listener, options })\n } else if (type === '*') {\n // Handle global wildcard listener (all events)\n if (listener) {\n this._globalWildcardListeners.add({ listener, options })\n }\n } else {\n // Normal event listener - delegate to native implementation\n super.addEventListener(type, listener, options)\n }\n }\n\n /**\n * Notify namespaced wildcard listeners of an event\n * Only fires for events that match this component's namespace\n *\n * @param event - The event to dispatch to namespaced wildcard listeners\n * @private\n */\n private _notifyNamespacedWildcardListeners (event: Event): void {\n if (this._namespacedWildcardListeners.size === 0) {\n return\n }\n\n const componentName = this.TAG\n\n // Only trigger for events in this component's namespace\n if (!componentName || !event.type.startsWith(`${componentName}:`)) {\n return\n }\n\n // Call each namespaced wildcard listener\n this._namespacedWildcardListeners.forEach(({ listener }) => {\n try {\n if (typeof listener === 'function') {\n listener.call(this, event)\n } else if (listener && typeof listener.handleEvent === 'function') {\n listener.handleEvent(event)\n }\n } catch (error) {\n // Log errors but don't let one listener break others\n console.error(\n 'Error in namespaced wildcard event listener:',\n error\n )\n }\n })\n }\n\n /**\n * Notify global wildcard listeners of an event\n * Fires for ALL events dispatched through this element\n *\n * @param event - The event to dispatch to global wildcard listeners\n * @private\n */\n private _notifyGlobalWildcardListeners (event: Event): void {\n if (this._globalWildcardListeners.size === 0) {\n return\n }\n\n // Call each global wildcard listener\n this._globalWildcardListeners.forEach(({ listener }) => {\n try {\n if (typeof listener === 'function') {\n listener.call(this, event)\n } else if (listener && typeof listener.handleEvent === 'function') {\n listener.handleEvent(event)\n }\n } catch (error) {\n // Log errors but don't let one listener break others\n console.error('Error in global wildcard event listener:', error)\n }\n })\n }\n\n connectedCallback () {\n this.render()\n }\n\n abstract render ():any\n\n qs<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):HTMLElementTagNameMap[K]|null;\n\n qs<E extends Element = Element>(selector:string):E|null;\n qs (selector:string):Element|null {\n return this.querySelector(selector)\n }\n\n qsa<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):HTMLElementTagNameMap[K]|null;\n\n qsa<E extends Element = Element>(selector:string):E|null;\n qsa (selector:string):NodeListOf<Element> {\n return this.querySelectorAll(selector)\n }\n\n /**\n * Take a non-namepsaced event name, return namespace event name.\n *\n * @param {string} evType The non-namespace event name\n * @returns {string} Namespaced event name, eg, `my-component:click`\n */\n static event (evType:string):string {\n return eventName(this.TAG, evType)\n }\n\n /**\n * Emit a namespaced event.\n *\n * @param type (non-namespaced) event type string\n * @param opts `bubbles`, `detail`, and `cancelable`. Default is\n * `{ bubbles: true, cancelable: true }`\n * @returns {boolean}\n */\n emit<T = any> (type:string, opts:Partial<{\n bubbles:boolean,\n cancelable:boolean,\n detail:CustomEvent<T>['detail']\n }> = {}):boolean {\n if (type === '*') throw new Error('Do not emit the literal \"*\"')\n\n const { bubbles = true, cancelable = true, detail } = opts\n const namespacedType = `${this.TAG}:${type}`\n\n const event = new CustomEvent(namespacedType, {\n bubbles,\n cancelable,\n detail\n })\n\n // This will trigger both specific listeners and global wildcard\n // listeners (**)\n const result = this.dispatchEvent(event)\n\n // Notify namespaced wildcard listeners (*)\n this._notifyNamespacedWildcardListeners(event)\n\n return result\n }\n\n /**\n * Override dispatchEvent to notify global wildcard listeners\n * This ensures that '**' listeners catch ALL events\n *\n * @param event - The event to dispatch\n * @returns true if the event was not cancelled\n */\n dispatchEvent (event: Event): boolean {\n const result = super.dispatchEvent(event)\n\n // Notify global wildcard listeners for ALL events\n this._notifyGlobalWildcardListeners(event)\n\n return result\n }\n\n /**\n * Create and emit an event, no namespacing.\n */\n dispatch<T> (type:string, opts:Partial<{\n bubbles:boolean,\n cancelable:boolean,\n detail:CustomEvent<T>['detail']\n }> = {}):boolean {\n const event = new CustomEvent(type, {\n bubbles: (opts.bubbles === undefined) ? true : opts.bubbles,\n cancelable: (opts.cancelable === undefined) ? true : opts.cancelable,\n detail: opts.detail\n })\n\n return this.dispatchEvent(event)\n }\n\n /**\n * Listen for namespaced events.\n */\n on<T extends Event = Event> (\n evName:string,\n handler:(ev:T)=>any,\n options?:boolean|AddEventListenerOptions\n ):void;\n\n on (\n evName:string,\n handler:EventListenerObject,\n options?:boolean|AddEventListenerOptions\n ):void;\n\n on (\n evName:string,\n handler:((ev:Event)=>any)|EventListenerObject,\n options?:boolean|AddEventListenerOptions\n ):void {\n const fullEvName = WebComponent.event.call(this, evName)\n this.addEventListener(fullEvName, handler as EventListenerOrEventListenerObject, options)\n }\n\n /**\n * Remove a namespaced event listener.\n */\n off<T extends Event = Event> (\n evName:string,\n handler:(ev:T)=>any,\n options?:boolean|EventListenerOptions\n ):void;\n\n off (\n evName:string,\n handler:EventListenerObject,\n options?:boolean|EventListenerOptions\n ):void;\n\n off (\n evName:string,\n handler:((ev:Event)=>any)|EventListenerObject,\n options?:boolean|EventListenerOptions\n ):void {\n const fullEvName = WebComponent.event.call(this, evName)\n this.removeEventListener(fullEvName, handler as EventListenerOrEventListenerObject, options)\n }\n\n /**\n * Enhanced removeEventListener that supports wildcards:\n * - Component.event('*') - Remove namespaced wildcard listener\n * - '*' - Remove global wildcard listener\n *\n * @param type - Event type, Component.event('*') for namespaced, or '*'\n * for global\n * @param listener - Event listener function or object to remove\n * @param options - Event listener options\n */\n removeEventListener (\n type:string,\n listener:EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions\n ): void {\n if (type === WebComponent.event.call(this, '*')) {\n // Remove namespaced wildcard listener\n if (listener && this._namespacedWildcardListeners) {\n for (const entry of this._namespacedWildcardListeners) {\n if (entry.listener === listener) {\n this._namespacedWildcardListeners.delete(entry)\n break\n }\n }\n }\n } else if (type === '*') {\n // Remove global wildcard listener\n if (listener && this._globalWildcardListeners) {\n for (const entry of this._globalWildcardListeners) {\n if (entry.listener === listener) {\n this._globalWildcardListeners.delete(entry)\n break\n }\n }\n }\n } else {\n // Normal event listener - delegate to native implementation\n super.removeEventListener(type, listener, options)\n }\n }\n}\n\nfunction eventName (namespace:string, evType:string) {\n return `${namespace}:${evType}`\n}\n\n/**\n * Check if the given tag name has been registered.\n *\n * @see {@link https://stackoverflow.com/a/28210364 stackoverflow}\n * @param {string} elName The custom element tag name.\n * @returns {boolean} True if the given name has been registered already.\n */\nexport function isRegistered (elName:string):boolean {\n return document.createElement(elName).constructor !== window.HTMLElement\n}\n\nexport function define (name:string, element:CustomElementConstructor) {\n if (typeof window === 'undefined') return\n if (!('customElements' in window)) return\n if (isRegistered(name)) return\n\n const ctor = element as unknown as typeof WebComponent\n const boolAttrs:string[] = ctor.reflectedBooleanAttributes ?? []\n const strAttrs:string[] = ctor.reflectedStringAttributes ?? []\n const proto = (element as any).prototype\n\n for (const attr of boolAttrs) {\n // Skip built-in IDL attributes on HTMLElement and ancestors\n // (covers Element.prototype, Node.prototype, etc.)\n if (attr in HTMLElement.prototype) continue\n // Skip if the subclass already defines an own-property accessor\n if (Object.getOwnPropertyDescriptor(proto, attr)) continue\n Object.defineProperty(proto, attr, {\n get (this:HTMLElement):boolean {\n return this.hasAttribute(attr)\n },\n set (this:HTMLElement, v:unknown) {\n this.toggleAttribute(attr, Boolean(v))\n },\n configurable: true,\n enumerable: true,\n })\n }\n\n for (const attr of strAttrs) {\n if (boolAttrs.includes(attr)) {\n console.warn(\n `[web-component] \"${attr}\" appears in both ` +\n 'reflectedBooleanAttributes and reflectedStringAttributes ' +\n `on <${name}>. Boolean wins.`\n )\n continue\n }\n if (attr in HTMLElement.prototype) continue\n if (Object.getOwnPropertyDescriptor(proto, attr)) continue\n Object.defineProperty(proto, attr, {\n get (this:HTMLElement):string|null {\n return this.getAttribute(attr)\n },\n set (this:HTMLElement, v:unknown) {\n // null and undefined both remove the attribute\n if (v == null) {\n this.removeAttribute(attr)\n } else {\n this.setAttribute(attr, String(v))\n }\n },\n configurable: true,\n enumerable: true,\n })\n }\n\n window.customElements.define(name, element)\n}\n", "const digitCharacters = [\n \"0\",\n \"1\",\n \"2\",\n \"3\",\n \"4\",\n \"5\",\n \"6\",\n \"7\",\n \"8\",\n \"9\",\n \"A\",\n \"B\",\n \"C\",\n \"D\",\n \"E\",\n \"F\",\n \"G\",\n \"H\",\n \"I\",\n \"J\",\n \"K\",\n \"L\",\n \"M\",\n \"N\",\n \"O\",\n \"P\",\n \"Q\",\n \"R\",\n \"S\",\n \"T\",\n \"U\",\n \"V\",\n \"W\",\n \"X\",\n \"Y\",\n \"Z\",\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n \"i\",\n \"j\",\n \"k\",\n \"l\",\n \"m\",\n \"n\",\n \"o\",\n \"p\",\n \"q\",\n \"r\",\n \"s\",\n \"t\",\n \"u\",\n \"v\",\n \"w\",\n \"x\",\n \"y\",\n \"z\",\n \"#\",\n \"$\",\n \"%\",\n \"*\",\n \"+\",\n \",\",\n \"-\",\n \".\",\n \":\",\n \";\",\n \"=\",\n \"?\",\n \"@\",\n \"[\",\n \"]\",\n \"^\",\n \"_\",\n \"{\",\n \"|\",\n \"}\",\n \"~\",\n];\n\nexport const decode83 = (str: String) => {\n let value = 0;\n for (let i = 0; i < str.length; i++) {\n const c = str[i];\n const digit = digitCharacters.indexOf(c);\n value = value * 83 + digit;\n }\n return value;\n};\n\nexport const encode83 = (n: number, length: number): string => {\n var result = \"\";\n for (let i = 1; i <= length; i++) {\n let digit = (Math.floor(n) / Math.pow(83, length - i)) % 83;\n result += digitCharacters[Math.floor(digit)];\n }\n return result;\n};\n", "export const sRGBToLinear = (value: number) => {\n let v = value / 255;\n if (v <= 0.04045) {\n return v / 12.92;\n } else {\n return Math.pow((v + 0.055) / 1.055, 2.4);\n }\n};\n\nexport const linearTosRGB = (value: number) => {\n let v = Math.max(0, Math.min(1, value));\n if (v <= 0.0031308) {\n return Math.trunc(v * 12.92 * 255 + 0.5);\n } else {\n return Math.trunc((1.055 * Math.pow(v, 1 / 2.4) - 0.055) * 255 + 0.5);\n }\n};\n\nexport const sign = (n: number) => (n < 0 ? -1 : 1);\n\nexport const signPow = (val: number, exp: number) =>\n sign(val) * Math.pow(Math.abs(val), exp);\n", "export class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n this.message = message;\n }\n}\n", "import { decode83 } from \"./base83\";\nimport { sRGBToLinear, signPow, linearTosRGB } from \"./utils\";\nimport { ValidationError } from \"./error\";\n\n/**\n * Returns an error message if invalid or undefined if valid\n * @param blurhash\n */\nconst validateBlurhash = (blurhash: string) => {\n if (!blurhash || blurhash.length < 6) {\n throw new ValidationError(\n \"The blurhash string must be at least 6 characters\"\n );\n }\n\n const sizeFlag = decode83(blurhash[0]);\n const numY = Math.floor(sizeFlag / 9) + 1;\n const numX = (sizeFlag % 9) + 1;\n\n if (blurhash.length !== 4 + 2 * numX * numY) {\n throw new ValidationError(\n `blurhash length mismatch: length is ${\n blurhash.length\n } but it should be ${4 + 2 * numX * numY}`\n );\n }\n};\n\nexport const isBlurhashValid = (\n blurhash: string\n): { result: boolean; errorReason?: string } => {\n try {\n validateBlurhash(blurhash);\n } catch (error) {\n return { result: false, errorReason: error.message };\n }\n\n return { result: true };\n};\n\nconst decodeDC = (value: number) => {\n const intR = value >> 16;\n const intG = (value >> 8) & 255;\n const intB = value & 255;\n return [sRGBToLinear(intR), sRGBToLinear(intG), sRGBToLinear(intB)];\n};\n\nconst decodeAC = (value: number, maximumValue: number) => {\n const quantR = Math.floor(value / (19 * 19));\n const quantG = Math.floor(value / 19) % 19;\n const quantB = value % 19;\n\n const rgb = [\n signPow((quantR - 9) / 9, 2.0) * maximumValue,\n signPow((quantG - 9) / 9, 2.0) * maximumValue,\n signPow((quantB - 9) / 9, 2.0) * maximumValue,\n ];\n\n return rgb;\n};\n\nconst decode = (\n blurhash: string,\n width: number,\n height: number,\n punch?: number\n) => {\n validateBlurhash(blurhash);\n\n punch = punch | 1;\n\n const sizeFlag = decode83(blurhash[0]);\n const numY = Math.floor(sizeFlag / 9) + 1;\n const numX = (sizeFlag % 9) + 1;\n\n const quantisedMaximumValue = decode83(blurhash[1]);\n const maximumValue = (quantisedMaximumValue + 1) / 166;\n\n const colors = new Array(numX * numY);\n\n for (let i = 0; i < colors.length; i++) {\n if (i === 0) {\n const value = decode83(blurhash.substring(2, 6));\n colors[i] = decodeDC(value);\n } else {\n const value = decode83(blurhash.substring(4 + i * 2, 6 + i * 2));\n colors[i] = decodeAC(value, maximumValue * punch);\n }\n }\n\n const bytesPerRow = width * 4;\n const pixels = new Uint8ClampedArray(bytesPerRow * height);\n\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n let r = 0;\n let g = 0;\n let b = 0;\n\n for (let j = 0; j < numY; j++) {\n for (let i = 0; i < numX; i++) {\n const basis =\n Math.cos((Math.PI * x * i) / width) *\n Math.cos((Math.PI * y * j) / height);\n let color = colors[i + j * numX];\n r += color[0] * basis;\n g += color[1] * basis;\n b += color[2] * basis;\n }\n }\n\n let intR = linearTosRGB(r);\n let intG = linearTosRGB(g);\n let intB = linearTosRGB(b);\n\n pixels[4 * x + 0 + y * bytesPerRow] = intR;\n pixels[4 * x + 1 + y * bytesPerRow] = intG;\n pixels[4 * x + 2 + y * bytesPerRow] = intB;\n pixels[4 * x + 3 + y * bytesPerRow] = 255; // alpha\n }\n }\n return pixels;\n};\n\nexport default decode;\n", "import { encode83 } from \"./base83\";\nimport { sRGBToLinear, signPow, linearTosRGB } from \"./utils\";\nimport { ValidationError } from \"./error\";\n\ntype NumberTriplet = [number, number, number];\n\nconst bytesPerPixel = 4;\n\nconst multiplyBasisFunction = (\n pixels: Uint8ClampedArray,\n width: number,\n height: number,\n basisFunction: (i: number, j: number) => number\n): NumberTriplet => {\n let r = 0;\n let g = 0;\n let b = 0;\n const bytesPerRow = width * bytesPerPixel;\n\n for (let x = 0; x < width; x++) {\n const bytesPerPixelX = bytesPerPixel * x;\n\n for (let y = 0; y < height; y++) {\n const basePixelIndex = bytesPerPixelX + y * bytesPerRow;\n const basis = basisFunction(x, y);\n r +=\n basis * sRGBToLinear(pixels[basePixelIndex]);\n g +=\n basis * sRGBToLinear(pixels[basePixelIndex + 1]);\n b +=\n basis * sRGBToLinear(pixels[basePixelIndex + 2]);\n }\n }\n\n let scale = 1 / (width * height);\n\n return [r * scale, g * scale, b * scale];\n};\n\nconst encodeDC = (value: NumberTriplet): number => {\n const roundedR = linearTosRGB(value[0]);\n const roundedG = linearTosRGB(value[1]);\n const roundedB = linearTosRGB(value[2]);\n return (roundedR << 16) + (roundedG << 8) + roundedB;\n};\n\nconst encodeAC = (value: NumberTriplet, maximumValue: number): number => {\n let quantR = Math.floor(\n Math.max(\n 0,\n Math.min(18, Math.floor(signPow(value[0] / maximumValue, 0.5) * 9 + 9.5))\n )\n );\n let quantG = Math.floor(\n Math.max(\n 0,\n Math.min(18, Math.floor(signPow(value[1] / maximumValue, 0.5) * 9 + 9.5))\n )\n );\n let quantB = Math.floor(\n Math.max(\n 0,\n Math.min(18, Math.floor(signPow(value[2] / maximumValue, 0.5) * 9 + 9.5))\n )\n );\n\n return quantR * 19 * 19 + quantG * 19 + quantB;\n};\n\nconst encode = (\n pixels: Uint8ClampedArray,\n width: number,\n height: number,\n componentX: number,\n componentY: number\n): string => {\n if (componentX < 1 || componentX > 9 || componentY < 1 || componentY > 9) {\n throw new ValidationError(\"BlurHash must have between 1 and 9 components\");\n }\n if (width * height * 4 !== pixels.length) {\n throw new ValidationError(\"Width and height must match the pixels array\");\n }\n\n let factors: Array<[number, number, number]> = [];\n for (let y = 0; y < componentY; y++) {\n for (let x = 0; x < componentX; x++) {\n const normalisation = x == 0 && y == 0 ? 1 : 2;\n const factor = multiplyBasisFunction(\n pixels,\n width,\n height,\n (i: number, j: number) =>\n normalisation *\n Math.cos((Math.PI * x * i) / width) *\n Math.cos((Math.PI * y * j) / height)\n );\n factors.push(factor);\n }\n }\n\n const dc = factors[0];\n const ac = factors.slice(1);\n\n let hash = \"\";\n\n let sizeFlag = componentX - 1 + (componentY - 1) * 9;\n hash += encode83(sizeFlag, 1);\n\n let maximumValue: number;\n if (ac.length > 0) {\n let actualMaximumValue = Math.max(...ac.map((val) => Math.max(...val)));\n let quantisedMaximumValue = Math.floor(\n Math.max(0, Math.min(82, Math.floor(actualMaximumValue * 166 - 0.5)))\n );\n maximumValue = (quantisedMaximumValue + 1) / 166;\n hash += encode83(quantisedMaximumValue, 1);\n } else {\n maximumValue = 1;\n hash += encode83(0, 1);\n }\n\n hash += encode83(encodeDC(dc), 4);\n\n ac.forEach((factor) => {\n hash += encode83(encodeAC(factor, maximumValue), 2);\n });\n\n return hash;\n};\n\nexport default encode;\n", "/**\n * Compute the resolution to decode a BlurHash placeholder at.\n *\n * A placeholder is a low-frequency blur, and decode cost is\n * O(width * height * componentsX * componentsY). Decoding above a small\n * size wastes work with no visible benefit, because the canvas is stretched\n * to fill its host via CSS (`blur-hash canvas { width:100%; height:100% }`).\n *\n * This caps the long edge to `cap` pixels, preserves the aspect ratio, floors\n * each edge at 1px, and never upscales a source that is already small.\n *\n * @param width The layout/source width in pixels.\n * @param height The layout/source height in pixels.\n * @param cap Maximum pixels on the long edge. Default 32.\n * @returns The decode dimensions to pass to `decode` and `createImageData`.\n */\nexport function decodeDimensions (\n width:number,\n height:number,\n cap:number = 32\n):{ width:number; height:number } {\n const longEdge = Math.max(width, height)\n\n // Never upscale: a source at or below the cap decodes as-is.\n if (longEdge <= cap) {\n return { width, height }\n }\n\n const scale = cap / longEdge\n return {\n width: Math.max(1, Math.round(width * scale)),\n height: Math.max(1, Math.round(height * scale))\n }\n}\n", "import { toAttributes } from '@substrate-system/web-component/attributes'\nimport type { ImgAttrs } from './index.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\nexport type SSRAttrs = ImgAttrs & { classes?:string }\n\nexport function render (attrs:SSRAttrs) {\n const {\n width,\n height,\n alt,\n contentVisibility,\n placeholder,\n decoding,\n loading,\n srcset,\n sizes,\n src\n } = attrs\n\n if (!placeholder) throw new Error('not placeholder')\n\n const decodeWidth = typeof width === 'string' ? parseInt(width, 10) : width\n const decodeHeight = typeof height === 'string' ?\n parseInt(height, 10) :\n height\n const decodeSize = decodeDimensions(decodeWidth, decodeHeight)\n\n const htmlString = `<canvas\n alt=\"${alt}\"\n width=${decodeSize.width}\n height=${decodeSize.height}\n class=\"blurry\"\n ></canvas>\n\n <img class=\"blurry\"\n alt=\"${alt}\"\n content-visibility=\"${contentVisibility || 'auto'}\"\n decoding=\"${decoding || 'async'}\"\n loading=\"${loading || 'lazy'}\"\n ${srcset ? `srcset=\"${srcset}\"` : ''}\n ${sizes ? `sizes=\"${sizes}\"` : ''}\n src=\"${src}\"\n />`\n\n const attributeString = toAttributes(attrs)\n\n // running in node?\n return typeof window === 'undefined' ?\n `<blur-hash ${attributeString}>\n ${htmlString}\n </blur-hash>` :\n htmlString\n}\n\nexport const outerHTML = (attrs:SSRAttrs) => {\n return `<blur-hash>${render(attrs)}</blur-hash>`\n}\n", "import { WebComponent } from '@substrate-system/web-component'\nimport { decode } from 'blurhash'\nimport { render } from './html.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\n// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'blur-hash': BlurHash\n }\n}\n\nexport type ImgAttrs = {\n alt:string;\n width:string|number;\n height:string|number;\n placeholder:string;\n src:string;\n srcset?:string|null;\n sizes?:string|null;\n time?:number;\n contentVisibility?:'visible'|'auto'|'hidden'|null;\n decoding?:'sync'|'async'|'auto'|null;\n loading?:'lazy'|'eager'|'auto'|null;\n}\n\nexport class BlurHash extends WebComponent.create('blur-hash') {\n time:number\n rafId:number|null = null\n\n constructor () {\n super()\n const w = this.getAttribute('width')\n const h = this.getAttribute('height')\n const time = this.getAttribute('time')\n this.time = time ? parseInt(time) : 800\n\n this.style.width = '' + w\n this.style.height = '' + h\n\n document.body.style.setProperty('--blur-hash-time',\n time ? '.' + (parseInt(time) / 1000 + 's') : '0.8s')\n }\n\n /**\n * Change the image, and do the blur-up thing again.\n * Will use the existing width & height if they are not passed in.\n */\n reset (attrs:(Omit<Omit<ImgAttrs, 'width'>, 'height'> & {\n width?:string|number;\n height?:string|number;\n })):void {\n if (attrs.width) this.style.width = '' + attrs.width\n if (attrs.height) this.style.height = '' + attrs.height\n\n const width = (attrs.width ?\n (typeof attrs.width === 'string' ? parseInt(attrs.width, 10) : attrs.width) :\n parseInt(this.style.width, 10))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height, 10) : attrs.height) :\n parseInt(this.style.height, 10))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n this.scheduleDecode(placeholder, width, height)\n\n this.setAttribute('src', newSrc)\n this.setAttribute('placeholder', placeholder)\n\n const img = this.querySelector('img')!\n if (attrs.srcset) img.setAttribute('srcset', attrs.srcset)\n if (attrs.sizes) img.setAttribute('sizes', attrs.sizes)\n\n this.sharpen()\n }\n\n /**\n * Decode the placeholder and paint it to the canvas on the next frame.\n * Cancels any pending frame first, so a rapid re-call (e.g. a second\n * `reset`) never leaves a stale decode running. Bails if the element has\n * detached before the frame fires.\n */\n scheduleDecode (placeholder:string, width:number, height:number):void {\n if (this.rafId !== null) cancelAnimationFrame(this.rafId)\n\n const { width: dw, height: dh } = decodeDimensions(width, height)\n\n this.rafId = requestAnimationFrame(() => {\n this.rafId = null\n if (!this.isConnected) return\n const canvas = this.querySelector<HTMLCanvasElement>('canvas')\n if (!canvas) return\n const ctx = canvas.getContext('2d')\n if (!ctx) return\n const pixels = decode(placeholder, dw, dh)\n const imageData = ctx.createImageData(dw, dh)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n })\n }\n\n disconnectedCallback ():void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId)\n this.rafId = null\n }\n }\n\n sharpen () {\n const img = this.qs('img')!\n if (img.complete && img.naturalWidth > 0) {\n img.classList.remove('blurry')\n img.classList.add('sharp')\n } else {\n img.addEventListener('load', () => {\n img.classList.remove('blurry')\n img.classList.add('sharp')\n })\n }\n }\n\n connectedCallback () {\n const width = parseInt(this.getAttribute('width') ?? '')\n const height = parseInt(this.getAttribute('height') ?? '')\n const placeholder = this.getAttribute('placeholder')\n if (!placeholder) throw new Error('Missing placeholder')\n if (!width) throw new Error('Missing width')\n if (!height) throw new Error('Missing height')\n\n // don't render again if we dont have to\n if (!this.innerHTML) {\n this.innerHTML = this.render()\n }\n\n this.scheduleDecode(placeholder, width, height)\n this.sharpen()\n }\n\n static html (attrs:ImgAttrs & { classes?:string }) {\n return render(attrs)\n }\n\n /**\n * Use the attributes to create HTML.\n */\n render ():string {\n const srcset = this.getAttribute('srcset')\n const width = this.getAttribute('width')\n const height = this.getAttribute('height')\n const time = this.getAttribute('time')\n const classes = this.classList.toString()\n const placeholder = this.getAttribute('placeholder')\n this.time = time ? parseInt(time) : 800\n const src = this.getAttribute('src')\n const alt = this.getAttribute('alt')\n if (!placeholder) throw new Error('not placeholder')\n if (!width || !height) throw new Error('not width or not height')\n if (!src) throw new Error('Not src')\n if (!alt) throw new Error('Not alt')\n\n return BlurHash.html({ classes, srcset, width, height, src, alt, placeholder })\n }\n}\n"],
|
|
5
|
-
"mappings": "sKASO,SAASA,EAAcC,EAAoB,CAC9C,OAAO,OAAO,KAAKA,CAAK,EAAE,OAAO,CAACC,EAAKC,IAAM,CACzC,IAAMC,EAAQH,EAAME,CAAC,EACrB,OAAKC,EAED,OAAOA,GAAU,UACbA,GAAeF,EAAM,IAAIC,CAAC,IAAI,KAAK,EAChCD,EAGP,MAAM,QAAQE,CAAK,EACXF,EAAM,IAAIC,CAAC,KAAKC,EAAM,KAAK,GAAG,CAAC,KAGnCF,EAAM,IAAIC,CAAC,KAAKC,CAAK,KAAK,KAAK,EAXpBF,CAYvB,EAAG,EAAE,CACT,CAhBgBG,EAAAL,EAAA,gBAAAK,EAAAL,EAAA,cAAA,yFCAT,SAASM,EAAcC,EAAuB,CACjD,OAAO,SAAS,cAAcA,CAAM,EAAE,cAAgB,OAAO,WACjE,CAFgBC,EAAAF,EAAA,gBAAAE,EAAAF,EAAA,cAAA,EAIT,SAASG,EAAQC,EAAaC,EAAkC,CAC9D,QACC,mBAAoB,SAErBL,EAAaI,CAAI,GAClB,OAAO,eAAe,OAAOA,EAAMC,CAAO,EAElD,CAPgBH,EAAAC,EAAA,UAAAD,EAAAC,EAAA,QAAA,EAST,IAAMG,GAAK,SAAS,cAAc,KAAK,QAAQ,EACzCC,GAAM,SAAS,iBAAiB,KAAK,QAAQ,EAQnD,SAASC,EAAOC,EAAgBC,EAA2B,CAC9D,OAAKD,EAAG,UAASA,EAAKA,EAAG,eAClBA,EAAG,QAAQC,CAAC,EAAID,EAAKA,EAAG,QAAQC,CAAC,CAC5C,CAHgBR,EAAAM,EAAA,SAAAN,EAAAM,EAAA,OAAA,yFCxBMG,EAAf,MAAeC,UAAqB,OAAO,WAAY,OA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,UAAY,KAAK,OAAO,GAGjC,KAAK,eAAeC,EAAaF,EAAOC,CAAM,EAC9C,KAAK,QAAQ,CACjB,CAEA,OAAO,KAAMF,EAAsC,CAC/C,OAAOc,EAAOd,CAAK,CACvB,CAKA,QAAiB,CACb,IAAMe,EAAS,KAAK,aAAa,QAAQ,EACnCd,EAAQ,KAAK,aAAa,OAAO,EACjCC,EAAS,KAAK,aAAa,QAAQ,EACnCH,EAAO,KAAK,aAAa,MAAM,EAC/BiB,EAAU,KAAK,UAAU,SAAS,EAClCb,EAAc,KAAK,aAAa,aAAa,EACnD,KAAK,KAAOJ,EAAO,SAASA,CAAI,EAAI,IACpC,IAAMkB,EAAM,KAAK,aAAa,KAAK,EAC7BC,EAAM,KAAK,aAAa,KAAK,EACnC,GAAI,CAACf,EAAa,MAAM,IAAI,MAAM,iBAAiB,EACnD,GAAI,CAACF,GAAS,CAACC,EAAQ,MAAM,IAAI,MAAM,yBAAyB,EAChE,GAAI,CAACe,EAAK,MAAM,IAAI,MAAM,SAAS,EACnC,GAAI,CAACC,EAAK,MAAM,IAAI,MAAM,SAAS,EAEnC,OAAOxB,EAAS,KAAK,CAAE,QAAAsB,EAAS,OAAAD,EAAQ,MAAAd,EAAO,OAAAC,EAAQ,IAAAe,EAAK,IAAAC,EAAK,YAAAf,CAAY,CAAC,CAClF,CACJ",
|
|
6
|
-
"names": ["toAttributes", "attrs", "acc", "k", "value", "__name", "isRegistered", "elName", "__name", "define", "name", "element", "qs", "qsa", "match", "el", "s", "WebComponent", "_WebComponent", "__name", "el", "match", "elementName", "CreatedClass", "evType", "define", "name", "oldValue", "newValue", "handler", "
|
|
4
|
+
"sourcesContent": ["export type Attrs = Record<string, undefined|null|string|number|boolean|(string|number)[]>\n\n/**\n * Transform an object into an HTML attributes string. The object should be\n * like `{ attributeName: value }`.\n *\n * @param attrs An object for the attributes.\n * @returns {string} A string suitable for use as HTML attributes.\n */\nexport function toAttributes (attrs:Attrs):string {\n return Object.keys(attrs).reduce((acc, k) => {\n const value = attrs[k]\n if (!value) return acc\n\n if (typeof value === 'boolean') {\n if (value) return (acc + ` ${k}`).trim()\n return acc\n }\n\n if (Array.isArray(value)) {\n return (acc + ` ${k}=\"${value.join(' ')}\"`)\n }\n\n return (acc + ` ${k}=\"${value}\"`).trim()\n }, '')\n}\n", "export { toAttributes } from './attributes.js'\n\n/**\n * Check if the given tag name has been registered.\n *\n * @see {@link https://stackoverflow.com/a/28210364 stackoverflow}\n * @param {string} elName The custom element tag name.\n * @returns {boolean} True if the given name has been registered already.\n */\nexport function isRegistered (elName:string):boolean {\n return document.createElement(elName).constructor !== window.HTMLElement\n}\n\nexport function define (name:string, element:CustomElementConstructor) {\n if (!window) return\n if (!('customElements' in window)) return\n\n if (!isRegistered(name)) {\n window.customElements.define(name, element)\n }\n}\n\nexport const qs = document.querySelector.bind(document)\nexport const qsa = document.querySelectorAll.bind(document)\n\n/**\n * Get the closes parent element matching the given selector.\n * @param el Element to start from\n * @param s Selector for an element\n * @returns {HTMLElement|null} The closes parent element that matches.\n */\nexport function match (el:HTMLElement, s:string):HTMLElement|null {\n if (!el.matches) el = el.parentElement!\n return el.matches(s) ? el : el.closest(s)\n}\n", "import { match as _match } from './util.js'\n\nexport abstract class WebComponent extends window.HTMLElement {\n static TAG:string = ''\n TAG:string = ''\n\n /**\n * Declare boolean attributes that should be reflected as properties.\n * The base class auto-generates getters/setters and includes these in\n * `observedAttributes`. Framework property assignment (e.g. Preact's\n * `el.disabled = true`) will then correctly set the attribute.\n */\n static reflectedBooleanAttributes:string[] = []\n\n /**\n * Declare string attributes that should be reflected as properties.\n * Getter returns `string|null` (null when attribute is absent).\n * Setting `null` or `undefined` removes the attribute.\n */\n static reflectedStringAttributes:string[] = []\n\n /**\n * Auto-derived from `reflectedBooleanAttributes` and\n * `reflectedStringAttributes`. Override with `super.observedAttributes`\n * to add non-reflected observed attributes:\n *\n * ```ts\n * static get observedAttributes () {\n * return [...super.observedAttributes, 'aria-label']\n * }\n * ```\n */\n static get observedAttributes ():string[] {\n return [...new Set([\n ...this.reflectedBooleanAttributes,\n ...this.reflectedStringAttributes,\n ])]\n }\n\n static match (el:HTMLElement):HTMLElement|null {\n return _match(el, this.TAG)\n }\n\n static create (elementName:string):typeof WebComponent & {\n new (...args:any[]):WebComponent;\n TAG:string;\n define: typeof WebComponent.define;\n event: typeof WebComponent.event;\n } {\n const CreatedClass = class extends WebComponent {\n static TAG = elementName\n TAG = elementName\n render () {\n throw new Error('`render` should be implemented by children')\n }\n }\n\n // Copy static methods with proper binding\n CreatedClass.define = function () {\n return WebComponent.define.call(this)\n }\n CreatedClass.event = function (evType:string) {\n return WebComponent.event.call(this, evType)\n }\n\n return CreatedClass\n }\n\n static define<T extends {\n new (...args:any[]):WebComponent;\n TAG:string;\n }>(this:T) {\n define(this.TAG, this)\n }\n\n /**\n * Runs when the value of an attribute is changed.\n *\n * Depends on `static observedAttributes`.\n *\n * Should name methods like `handleChange_disabled`.\n *\n * @param {string} name The attribute name\n * @param {string} oldValue The old attribute value\n * @param {string} newValue The new attribute value\n */\n attributeChangedCallback (\n name:string,\n oldValue:string,\n newValue:string\n ):void {\n const handler = this[handlerKey(name)]\n if (handler) {\n handler.call(this, oldValue, newValue)\n }\n }\n\n connectedCallback () {\n this.render()\n }\n\n abstract render ():any\n\n qs<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):HTMLElementTagNameMap[K]|null;\n\n qs<E extends Element = Element>(selector:string):E|null;\n qs (selector:string):Element|null {\n return this.querySelector(selector)\n }\n\n qsa<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):HTMLElementTagNameMap[K]|null;\n\n qsa<E extends Element = Element>(selector:string):E|null;\n qsa (selector:string):NodeListOf<Element> {\n return this.querySelectorAll(selector)\n }\n\n /**\n * Take a non-namepsaced event name, return namespace event name.\n *\n * @param {string} evType The non-namespace event name\n * @returns {string} Namespaced event name, eg, `my-component:click`\n */\n static event (evType:string):string {\n return eventName(this.TAG, evType)\n }\n\n /**\n * Emit a namespaced event.\n *\n * @param type (non-namespaced) event type string\n * @param opts `bubbles`, `detail`, and `cancelable`. Default is\n * `{ bubbles: true, cancelable: true }`\n * @returns {boolean}\n */\n emit<T = any> (type:string, opts:Partial<{\n bubbles:boolean,\n cancelable:boolean,\n detail:CustomEvent<T>['detail']\n }> = {}):boolean {\n if (type === '*') throw new Error('Do not emit the literal \"*\"')\n\n const { bubbles = true, cancelable = true, detail } = opts\n const namespacedType = `${this.TAG}:${type}`\n\n const event = new CustomEvent(namespacedType, {\n bubbles,\n cancelable,\n detail\n })\n\n return this.dispatchEvent(event)\n }\n\n /**\n * Create and emit an event, no namespacing.\n */\n dispatch<T> (type:string, opts:Partial<{\n bubbles:boolean,\n cancelable:boolean,\n detail:CustomEvent<T>['detail']\n }> = {}):boolean {\n const event = new CustomEvent(type, {\n bubbles: (opts.bubbles === undefined) ? true : opts.bubbles,\n cancelable: (opts.cancelable === undefined) ? true : opts.cancelable,\n detail: opts.detail\n })\n\n return this.dispatchEvent(event)\n }\n\n /**\n * Listen for namespaced events.\n */\n on<T extends Event = Event> (\n evName:string,\n handler:(ev:T)=>any,\n options?:boolean|AddEventListenerOptions\n ):void;\n\n on (\n evName:string,\n handler:EventListenerObject,\n options?:boolean|AddEventListenerOptions\n ):void;\n\n on (\n evName:string,\n handler:((ev:Event)=>any)|EventListenerObject,\n options?:boolean|AddEventListenerOptions\n ):void {\n const fullEvName = WebComponent.event.call(this, evName)\n this.addEventListener(fullEvName, handler as EventListenerOrEventListenerObject, options)\n }\n\n /**\n * Remove a namespaced event listener.\n */\n off<T extends Event = Event> (\n evName:string,\n handler:(ev:T)=>any,\n options?:boolean|EventListenerOptions\n ):void;\n\n off (\n evName:string,\n handler:EventListenerObject,\n options?:boolean|EventListenerOptions\n ):void;\n\n off (\n evName:string,\n handler:((ev:Event)=>any)|EventListenerObject,\n options?:boolean|EventListenerOptions\n ):void {\n const fullEvName = WebComponent.event.call(this, evName)\n this.removeEventListener(fullEvName, handler as EventListenerOrEventListenerObject, options)\n }\n}\n\nfunction eventName (namespace:string, evType:string) {\n return `${namespace}:${evType}`\n}\n\n/**\n * Cache of attribute name -> handler method name (`handleChange_<attr>`).\n * Building the lookup string once per attribute avoids re-allocating it on\n * every `attributeChangedCallback`.\n */\nconst handlerKeys:Record<string, string> = Object.create(null)\nfunction handlerKey (name:string):string {\n return handlerKeys[name] || (handlerKeys[name] = `handleChange_${name}`)\n}\n\n/**\n * Check if the given tag name has been registered.\n *\n * @see {@link https://stackoverflow.com/a/28210364 stackoverflow}\n * @param {string} elName The custom element tag name.\n * @returns {boolean} True if the given name has been registered already.\n */\nexport function isRegistered (elName:string):boolean {\n return document.createElement(elName).constructor !== window.HTMLElement\n}\n\nexport function define (name:string, element:CustomElementConstructor) {\n if (typeof window === 'undefined') return\n if (!('customElements' in window)) return\n if (isRegistered(name)) return\n\n const ctor = element as unknown as typeof WebComponent\n const boolAttrs:string[] = ctor.reflectedBooleanAttributes ?? []\n const strAttrs:string[] = ctor.reflectedStringAttributes ?? []\n const proto = (element as any).prototype\n\n for (const attr of boolAttrs) {\n // Skip built-in IDL attributes on HTMLElement and ancestors\n // (covers Element.prototype, Node.prototype, etc.)\n if (attr in HTMLElement.prototype) continue\n // Skip if the subclass already defines an own-property accessor\n if (Object.getOwnPropertyDescriptor(proto, attr)) continue\n Object.defineProperty(proto, attr, {\n get (this:HTMLElement):boolean {\n return this.hasAttribute(attr)\n },\n set (this:HTMLElement, v:unknown) {\n this.toggleAttribute(attr, Boolean(v))\n },\n configurable: true,\n enumerable: true,\n })\n }\n\n for (const attr of strAttrs) {\n if (boolAttrs.includes(attr)) {\n console.warn(\n `[web-component] \"${attr}\" appears in both ` +\n 'reflectedBooleanAttributes and reflectedStringAttributes ' +\n `on <${name}>. Boolean wins.`\n )\n continue\n }\n if (attr in HTMLElement.prototype) continue\n if (Object.getOwnPropertyDescriptor(proto, attr)) continue\n Object.defineProperty(proto, attr, {\n get (this:HTMLElement):string|null {\n return this.getAttribute(attr)\n },\n set (this:HTMLElement, v:unknown) {\n // null and undefined both remove the attribute\n if (v == null) {\n this.removeAttribute(attr)\n } else {\n this.setAttribute(attr, String(v))\n }\n },\n configurable: true,\n enumerable: true,\n })\n }\n\n window.customElements.define(name, element)\n}\n", "const digitCharacters = [\n \"0\",\n \"1\",\n \"2\",\n \"3\",\n \"4\",\n \"5\",\n \"6\",\n \"7\",\n \"8\",\n \"9\",\n \"A\",\n \"B\",\n \"C\",\n \"D\",\n \"E\",\n \"F\",\n \"G\",\n \"H\",\n \"I\",\n \"J\",\n \"K\",\n \"L\",\n \"M\",\n \"N\",\n \"O\",\n \"P\",\n \"Q\",\n \"R\",\n \"S\",\n \"T\",\n \"U\",\n \"V\",\n \"W\",\n \"X\",\n \"Y\",\n \"Z\",\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n \"i\",\n \"j\",\n \"k\",\n \"l\",\n \"m\",\n \"n\",\n \"o\",\n \"p\",\n \"q\",\n \"r\",\n \"s\",\n \"t\",\n \"u\",\n \"v\",\n \"w\",\n \"x\",\n \"y\",\n \"z\",\n \"#\",\n \"$\",\n \"%\",\n \"*\",\n \"+\",\n \",\",\n \"-\",\n \".\",\n \":\",\n \";\",\n \"=\",\n \"?\",\n \"@\",\n \"[\",\n \"]\",\n \"^\",\n \"_\",\n \"{\",\n \"|\",\n \"}\",\n \"~\",\n];\n\nexport const decode83 = (str: String) => {\n let value = 0;\n for (let i = 0; i < str.length; i++) {\n const c = str[i];\n const digit = digitCharacters.indexOf(c);\n value = value * 83 + digit;\n }\n return value;\n};\n\nexport const encode83 = (n: number, length: number): string => {\n var result = \"\";\n for (let i = 1; i <= length; i++) {\n let digit = (Math.floor(n) / Math.pow(83, length - i)) % 83;\n result += digitCharacters[Math.floor(digit)];\n }\n return result;\n};\n", "export const sRGBToLinear = (value: number) => {\n let v = value / 255;\n if (v <= 0.04045) {\n return v / 12.92;\n } else {\n return Math.pow((v + 0.055) / 1.055, 2.4);\n }\n};\n\nexport const linearTosRGB = (value: number) => {\n let v = Math.max(0, Math.min(1, value));\n if (v <= 0.0031308) {\n return Math.trunc(v * 12.92 * 255 + 0.5);\n } else {\n return Math.trunc((1.055 * Math.pow(v, 1 / 2.4) - 0.055) * 255 + 0.5);\n }\n};\n\nexport const sign = (n: number) => (n < 0 ? -1 : 1);\n\nexport const signPow = (val: number, exp: number) =>\n sign(val) * Math.pow(Math.abs(val), exp);\n", "export class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n this.message = message;\n }\n}\n", "import { decode83 } from \"./base83\";\nimport { sRGBToLinear, signPow, linearTosRGB } from \"./utils\";\nimport { ValidationError } from \"./error\";\n\n/**\n * Returns an error message if invalid or undefined if valid\n * @param blurhash\n */\nconst validateBlurhash = (blurhash: string) => {\n if (!blurhash || blurhash.length < 6) {\n throw new ValidationError(\n \"The blurhash string must be at least 6 characters\"\n );\n }\n\n const sizeFlag = decode83(blurhash[0]);\n const numY = Math.floor(sizeFlag / 9) + 1;\n const numX = (sizeFlag % 9) + 1;\n\n if (blurhash.length !== 4 + 2 * numX * numY) {\n throw new ValidationError(\n `blurhash length mismatch: length is ${\n blurhash.length\n } but it should be ${4 + 2 * numX * numY}`\n );\n }\n};\n\nexport const isBlurhashValid = (\n blurhash: string\n): { result: boolean; errorReason?: string } => {\n try {\n validateBlurhash(blurhash);\n } catch (error) {\n return { result: false, errorReason: error.message };\n }\n\n return { result: true };\n};\n\nconst decodeDC = (value: number) => {\n const intR = value >> 16;\n const intG = (value >> 8) & 255;\n const intB = value & 255;\n return [sRGBToLinear(intR), sRGBToLinear(intG), sRGBToLinear(intB)];\n};\n\nconst decodeAC = (value: number, maximumValue: number) => {\n const quantR = Math.floor(value / (19 * 19));\n const quantG = Math.floor(value / 19) % 19;\n const quantB = value % 19;\n\n const rgb = [\n signPow((quantR - 9) / 9, 2.0) * maximumValue,\n signPow((quantG - 9) / 9, 2.0) * maximumValue,\n signPow((quantB - 9) / 9, 2.0) * maximumValue,\n ];\n\n return rgb;\n};\n\nconst decode = (\n blurhash: string,\n width: number,\n height: number,\n punch?: number\n) => {\n validateBlurhash(blurhash);\n\n punch = punch | 1;\n\n const sizeFlag = decode83(blurhash[0]);\n const numY = Math.floor(sizeFlag / 9) + 1;\n const numX = (sizeFlag % 9) + 1;\n\n const quantisedMaximumValue = decode83(blurhash[1]);\n const maximumValue = (quantisedMaximumValue + 1) / 166;\n\n const colors = new Array(numX * numY);\n\n for (let i = 0; i < colors.length; i++) {\n if (i === 0) {\n const value = decode83(blurhash.substring(2, 6));\n colors[i] = decodeDC(value);\n } else {\n const value = decode83(blurhash.substring(4 + i * 2, 6 + i * 2));\n colors[i] = decodeAC(value, maximumValue * punch);\n }\n }\n\n const bytesPerRow = width * 4;\n const pixels = new Uint8ClampedArray(bytesPerRow * height);\n\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width; x++) {\n let r = 0;\n let g = 0;\n let b = 0;\n\n for (let j = 0; j < numY; j++) {\n for (let i = 0; i < numX; i++) {\n const basis =\n Math.cos((Math.PI * x * i) / width) *\n Math.cos((Math.PI * y * j) / height);\n let color = colors[i + j * numX];\n r += color[0] * basis;\n g += color[1] * basis;\n b += color[2] * basis;\n }\n }\n\n let intR = linearTosRGB(r);\n let intG = linearTosRGB(g);\n let intB = linearTosRGB(b);\n\n pixels[4 * x + 0 + y * bytesPerRow] = intR;\n pixels[4 * x + 1 + y * bytesPerRow] = intG;\n pixels[4 * x + 2 + y * bytesPerRow] = intB;\n pixels[4 * x + 3 + y * bytesPerRow] = 255; // alpha\n }\n }\n return pixels;\n};\n\nexport default decode;\n", "import { encode83 } from \"./base83\";\nimport { sRGBToLinear, signPow, linearTosRGB } from \"./utils\";\nimport { ValidationError } from \"./error\";\n\ntype NumberTriplet = [number, number, number];\n\nconst bytesPerPixel = 4;\n\nconst multiplyBasisFunction = (\n pixels: Uint8ClampedArray,\n width: number,\n height: number,\n basisFunction: (i: number, j: number) => number\n): NumberTriplet => {\n let r = 0;\n let g = 0;\n let b = 0;\n const bytesPerRow = width * bytesPerPixel;\n\n for (let x = 0; x < width; x++) {\n const bytesPerPixelX = bytesPerPixel * x;\n\n for (let y = 0; y < height; y++) {\n const basePixelIndex = bytesPerPixelX + y * bytesPerRow;\n const basis = basisFunction(x, y);\n r +=\n basis * sRGBToLinear(pixels[basePixelIndex]);\n g +=\n basis * sRGBToLinear(pixels[basePixelIndex + 1]);\n b +=\n basis * sRGBToLinear(pixels[basePixelIndex + 2]);\n }\n }\n\n let scale = 1 / (width * height);\n\n return [r * scale, g * scale, b * scale];\n};\n\nconst encodeDC = (value: NumberTriplet): number => {\n const roundedR = linearTosRGB(value[0]);\n const roundedG = linearTosRGB(value[1]);\n const roundedB = linearTosRGB(value[2]);\n return (roundedR << 16) + (roundedG << 8) + roundedB;\n};\n\nconst encodeAC = (value: NumberTriplet, maximumValue: number): number => {\n let quantR = Math.floor(\n Math.max(\n 0,\n Math.min(18, Math.floor(signPow(value[0] / maximumValue, 0.5) * 9 + 9.5))\n )\n );\n let quantG = Math.floor(\n Math.max(\n 0,\n Math.min(18, Math.floor(signPow(value[1] / maximumValue, 0.5) * 9 + 9.5))\n )\n );\n let quantB = Math.floor(\n Math.max(\n 0,\n Math.min(18, Math.floor(signPow(value[2] / maximumValue, 0.5) * 9 + 9.5))\n )\n );\n\n return quantR * 19 * 19 + quantG * 19 + quantB;\n};\n\nconst encode = (\n pixels: Uint8ClampedArray,\n width: number,\n height: number,\n componentX: number,\n componentY: number\n): string => {\n if (componentX < 1 || componentX > 9 || componentY < 1 || componentY > 9) {\n throw new ValidationError(\"BlurHash must have between 1 and 9 components\");\n }\n if (width * height * 4 !== pixels.length) {\n throw new ValidationError(\"Width and height must match the pixels array\");\n }\n\n let factors: Array<[number, number, number]> = [];\n for (let y = 0; y < componentY; y++) {\n for (let x = 0; x < componentX; x++) {\n const normalisation = x == 0 && y == 0 ? 1 : 2;\n const factor = multiplyBasisFunction(\n pixels,\n width,\n height,\n (i: number, j: number) =>\n normalisation *\n Math.cos((Math.PI * x * i) / width) *\n Math.cos((Math.PI * y * j) / height)\n );\n factors.push(factor);\n }\n }\n\n const dc = factors[0];\n const ac = factors.slice(1);\n\n let hash = \"\";\n\n let sizeFlag = componentX - 1 + (componentY - 1) * 9;\n hash += encode83(sizeFlag, 1);\n\n let maximumValue: number;\n if (ac.length > 0) {\n let actualMaximumValue = Math.max(...ac.map((val) => Math.max(...val)));\n let quantisedMaximumValue = Math.floor(\n Math.max(0, Math.min(82, Math.floor(actualMaximumValue * 166 - 0.5)))\n );\n maximumValue = (quantisedMaximumValue + 1) / 166;\n hash += encode83(quantisedMaximumValue, 1);\n } else {\n maximumValue = 1;\n hash += encode83(0, 1);\n }\n\n hash += encode83(encodeDC(dc), 4);\n\n ac.forEach((factor) => {\n hash += encode83(encodeAC(factor, maximumValue), 2);\n });\n\n return hash;\n};\n\nexport default encode;\n", "/**\n * Compute the resolution to decode a BlurHash placeholder at.\n *\n * A placeholder is a low-frequency blur, and decode cost is\n * O(width * height * componentsX * componentsY). Decoding above a small\n * size wastes work with no visible benefit, because the canvas is stretched\n * to fill its host via CSS (`blur-hash canvas { width:100%; height:100% }`).\n *\n * This caps the long edge to `cap` pixels, preserves the aspect ratio, floors\n * each edge at 1px, and never upscales a source that is already small.\n *\n * @param width The layout/source width in pixels.\n * @param height The layout/source height in pixels.\n * @param cap Maximum pixels on the long edge. Default 32.\n * @returns The decode dimensions to pass to `decode` and `createImageData`.\n */\nexport function decodeDimensions (\n width:number,\n height:number,\n cap:number = 32\n):{ width:number; height:number } {\n const longEdge = Math.max(width, height)\n\n // Never upscale: a source at or below the cap decodes as-is.\n if (longEdge <= cap) {\n return { width, height }\n }\n\n const scale = cap / longEdge\n return {\n width: Math.max(1, Math.round(width * scale)),\n height: Math.max(1, Math.round(height * scale))\n }\n}\n", "import { toAttributes } from '@substrate-system/web-component/attributes'\nimport type { ImgAttrs } from './index.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\nexport type SSRAttrs = ImgAttrs & { classes?:string }\n\nexport function render (attrs:SSRAttrs) {\n const {\n width,\n height,\n alt,\n contentVisibility,\n placeholder,\n decoding,\n loading,\n srcset,\n sizes,\n src\n } = attrs\n\n if (!placeholder) throw new Error('not placeholder')\n\n const decodeWidth = typeof width === 'string' ? parseInt(width, 10) : width\n const decodeHeight = typeof height === 'string' ?\n parseInt(height, 10) :\n height\n const decodeSize = decodeDimensions(decodeWidth, decodeHeight)\n\n const htmlString = `<canvas\n alt=\"${alt}\"\n width=${decodeSize.width}\n height=${decodeSize.height}\n class=\"blurry\"\n ></canvas>\n\n <img class=\"blurry\"\n alt=\"${alt}\"\n content-visibility=\"${contentVisibility || 'auto'}\"\n decoding=\"${decoding || 'async'}\"\n loading=\"${loading || 'lazy'}\"\n ${srcset ? `srcset=\"${srcset}\"` : ''}\n ${sizes ? `sizes=\"${sizes}\"` : ''}\n src=\"${src}\"\n />`\n\n const attributeString = toAttributes(attrs)\n\n // running in node?\n return typeof window === 'undefined' ?\n `<blur-hash ${attributeString}>\n ${htmlString}\n </blur-hash>` :\n htmlString\n}\n\nexport const outerHTML = (attrs:SSRAttrs) => {\n return `<blur-hash>${render(attrs)}</blur-hash>`\n}\n", "import { WebComponent } from '@substrate-system/web-component'\nimport { decode } from 'blurhash'\nimport { render } from './html.js'\nimport { decodeDimensions } from './decode-dimensions.js'\n\n// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'blur-hash': BlurHash\n }\n}\n\nexport type ImgAttrs = {\n alt:string;\n width:string|number;\n height:string|number;\n placeholder:string;\n src:string;\n srcset?:string|null;\n sizes?:string|null;\n time?:number;\n contentVisibility?:'visible'|'auto'|'hidden'|null;\n decoding?:'sync'|'async'|'auto'|null;\n loading?:'lazy'|'eager'|'auto'|null;\n}\n\nexport class BlurHash extends WebComponent.create('blur-hash') {\n time:number\n rafId:number|null = null\n\n constructor () {\n super()\n const w = this.getAttribute('width')\n const h = this.getAttribute('height')\n const time = this.getAttribute('time')\n this.time = time ? parseInt(time) : 800\n\n this.style.width = '' + w\n this.style.height = '' + h\n\n document.body.style.setProperty('--blur-hash-time',\n time ? '.' + (parseInt(time) / 1000 + 's') : '0.8s')\n }\n\n /**\n * Change the image, and do the blur-up thing again.\n * Will use the existing width & height if they are not passed in.\n */\n reset (attrs:(Omit<Omit<ImgAttrs, 'width'>, 'height'> & {\n width?:string|number;\n height?:string|number;\n })):void {\n if (attrs.width) this.style.width = '' + attrs.width\n if (attrs.height) this.style.height = '' + attrs.height\n\n const width = (attrs.width ?\n (typeof attrs.width === 'string' ? parseInt(attrs.width, 10) : attrs.width) :\n parseInt(this.style.width, 10))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height, 10) : attrs.height) :\n parseInt(this.style.height, 10))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n this.scheduleDecode(placeholder, width, height)\n\n this.setAttribute('src', newSrc)\n this.setAttribute('placeholder', placeholder)\n\n const img = this.querySelector('img')!\n if (attrs.srcset) img.setAttribute('srcset', attrs.srcset)\n if (attrs.sizes) img.setAttribute('sizes', attrs.sizes)\n\n this.sharpen()\n }\n\n /**\n * Decode the placeholder and paint it to the canvas on the next frame.\n * Cancels any pending frame first, so a rapid re-call (e.g. a second\n * `reset`) never leaves a stale decode running. Bails if the element has\n * detached before the frame fires.\n */\n scheduleDecode (placeholder:string, width:number, height:number):void {\n if (this.rafId !== null) cancelAnimationFrame(this.rafId)\n\n const { width: dw, height: dh } = decodeDimensions(width, height)\n\n this.rafId = requestAnimationFrame(() => {\n this.rafId = null\n if (!this.isConnected) return\n const canvas = this.querySelector<HTMLCanvasElement>('canvas')\n if (!canvas) return\n const ctx = canvas.getContext('2d')\n if (!ctx) return\n const pixels = decode(placeholder, dw, dh)\n const imageData = ctx.createImageData(dw, dh)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n })\n }\n\n disconnectedCallback ():void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId)\n this.rafId = null\n }\n }\n\n sharpen () {\n const img = this.qs('img')!\n const toSharp = () => {\n img.classList.remove('blurry')\n img.classList.add('sharp')\n }\n\n if (img.complete && img.naturalWidth > 0) {\n // The image is already decoded, so the class swap would run in\n // this same task -- before the browser ever paints the .blurry\n // (opacity:0) frame, and a CSS transition needs that start frame\n // to have painted or it does not run. Defer behind a double rAF\n // so one .blurry frame is rendered first; then the opacity fade\n // runs. A single rAF is not enough: it fires before the current\n // frame paints.\n requestAnimationFrame(() => requestAnimationFrame(toSharp))\n } else {\n // Still loading: the swap is deferred to `load`, which fires in a\n // later task after the .blurry frame has already painted.\n img.addEventListener('load', toSharp)\n }\n }\n\n connectedCallback () {\n const width = parseInt(this.getAttribute('width') ?? '')\n const height = parseInt(this.getAttribute('height') ?? '')\n const placeholder = this.getAttribute('placeholder')\n if (!placeholder) throw new Error('Missing placeholder')\n if (!width) throw new Error('Missing width')\n if (!height) throw new Error('Missing height')\n\n // don't render again if we dont have to\n if (!this.innerHTML) {\n this.innerHTML = this.render()\n }\n\n this.scheduleDecode(placeholder, width, height)\n this.sharpen()\n }\n\n static html (attrs:ImgAttrs & { classes?:string }) {\n return render(attrs)\n }\n\n /**\n * Use the attributes to create HTML.\n */\n render ():string {\n const srcset = this.getAttribute('srcset')\n const width = this.getAttribute('width')\n const height = this.getAttribute('height')\n const time = this.getAttribute('time')\n const classes = this.classList.toString()\n const placeholder = this.getAttribute('placeholder')\n this.time = time ? parseInt(time) : 800\n const src = this.getAttribute('src')\n const alt = this.getAttribute('alt')\n if (!placeholder) throw new Error('not placeholder')\n if (!width || !height) throw new Error('not width or not height')\n if (!src) throw new Error('Not src')\n if (!alt) throw new Error('Not alt')\n\n return BlurHash.html({\n classes,\n srcset,\n width,\n height,\n src,\n alt,\n placeholder\n })\n }\n}\n"],
|
|
5
|
+
"mappings": "sKASO,SAASA,EAAcC,EAAoB,CAC9C,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AM,KAAK,aAAa,KAAK,EAC7BC,EAAM,KAAK,aAAa,KAAK,EACnC,GAAI,CAAChB,EAAa,MAAM,IAAI,MAAM,iBAAiB,EACnD,GAAI,CAACF,GAAS,CAACC,EAAQ,MAAM,IAAI,MAAM,yBAAyB,EAChE,GAAI,CAACgB,EAAK,MAAM,IAAI,MAAM,SAAS,EACnC,GAAI,CAACC,EAAK,MAAM,IAAI,MAAM,SAAS,EAEnC,OAAOzB,EAAS,KAAK,CACjB,QAAAuB,EACA,OAAAD,EACA,MAAAf,EACA,OAAAC,EACA,IAAAgB,EACA,IAAAC,EACA,YAAAhB,CACJ,CAAC,CACL,CACJ",
|
|
6
|
+
"names": ["toAttributes", "attrs", "acc", "k", "value", "__name", "isRegistered", "elName", "__name", "define", "name", "element", "qs", "qsa", "match", "el", "s", "WebComponent", "_WebComponent", "__name", "el", "match", "elementName", "CreatedClass", "evType", "define", "name", "oldValue", "newValue", "handler", "handlerKey", "selector", "eventName", "type", "opts", "bubbles", "cancelable", "detail", "namespacedType", "event", "evName", "options", "fullEvName", "namespace", "handlerKeys", "isRegistered", "elName", "element", "ctor", "boolAttrs", "strAttrs", "proto", "attr", "v", "q", "x", "__name", "t", "e", "l", "f", "__name", "t", "e", "h", "F", "M", "d", "C", "x", "z", "__name", "t", "e", "f", "L", "l", "M", "U", "C", "x", "m", "b", "i", "o", "a", "c", "s", "y", "B", "R", "w", "P", "G", "T", "V", "h", "I", "E", "j", "decodeDimensions", "width", "height", "cap", "longEdge", "scale", "__name", "render", "attrs", "width", "height", "alt", "contentVisibility", "placeholder", "decoding", "loading", "srcset", "sizes", "src", "decodeWidth", "decodeHeight", "decodeSize", "decodeDimensions", "htmlString", "attributeString", "toAttributes", "__name", "BlurHash", "_BlurHash", "WebComponent", "__name", "w", "h", "time", "attrs", "width", "height", "placeholder", "newSrc", "img", "dw", "dh", "decodeDimensions", "canvas", "ctx", "pixels", "j", "imageData", "toSharp", "render", "srcset", "classes", "src", "alt"]
|
|
7
7
|
}
|
package/dist/meta.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"format": "esm"
|
|
12
12
|
},
|
|
13
13
|
"src/index.ts": {
|
|
14
|
-
"bytes":
|
|
14
|
+
"bytes": 6307,
|
|
15
15
|
"imports": [],
|
|
16
16
|
"format": "esm"
|
|
17
17
|
}
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"imports": [],
|
|
72
72
|
"exports": [],
|
|
73
73
|
"inputs": {},
|
|
74
|
-
"bytes":
|
|
74
|
+
"bytes": 9679
|
|
75
75
|
},
|
|
76
76
|
"dist/index.js": {
|
|
77
77
|
"imports": [
|
|
@@ -102,10 +102,10 @@
|
|
|
102
102
|
"entryPoint": "src/index.ts",
|
|
103
103
|
"inputs": {
|
|
104
104
|
"src/index.ts": {
|
|
105
|
-
"bytesInOutput":
|
|
105
|
+
"bytesInOutput": 4546
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
|
-
"bytes":
|
|
108
|
+
"bytes": 4732
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAM9D,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,WAAW,EAAE,QAAQ,CAAA;KACxB;CACJ;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,GAAG,EAAC,MAAM,CAAC;IACX,KAAK,EAAC,MAAM,GAAC,MAAM,CAAC;IACpB,MAAM,EAAC,MAAM,GAAC,MAAM,CAAC;IACrB,WAAW,EAAC,MAAM,CAAC;IACnB,GAAG,EAAC,MAAM,CAAC;IACX,MAAM,CAAC,EAAC,MAAM,GAAC,IAAI,CAAC;IACpB,KAAK,CAAC,EAAC,MAAM,GAAC,IAAI,CAAC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AAM,GAAC,IAAI,CAAC;IACpB,KAAK,CAAC,EAAC,MAAM,GAAC,IAAI,CAAC;IACnB,IAAI,CAAC,EAAC,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAC,SAAS,GAAC,MAAM,GAAC,QAAQ,GAAC,IAAI,CAAC;IAClD,QAAQ,CAAC,EAAC,MAAM,GAAC,OAAO,GAAC,MAAM,GAAC,IAAI,CAAC;IACrC,OAAO,CAAC,EAAC,MAAM,GAAC,OAAO,GAAC,MAAM,GAAC,IAAI,CAAC;CACvC,CAAA;;;;;;;AAED,qBAAa,QAAS,SAAQ,aAAgC;IAC1D,IAAI,EAAC,MAAM,CAAA;IACX,KAAK,EAAC,MAAM,GAAC,IAAI,CAAO;;IAgBxB;;;OAGG;IACH,KAAK,CAAE,KAAK,EAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,GAAG;QACpD,KAAK,CAAC,EAAC,MAAM,GAAC,MAAM,CAAC;QACrB,MAAM,CAAC,EAAC,MAAM,GAAC,MAAM,CAAC;KACzB,CAAC,GAAE,IAAI;IA2BR;;;;;OAKG;IACH,cAAc,CAAE,WAAW,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,MAAM,EAAC,MAAM,GAAE,IAAI;IAmBrE,oBAAoB,IAAI,IAAI;IAO5B,OAAO;IAuBP,iBAAiB;IAiBjB,MAAM,CAAC,IAAI,CAAE,KAAK,EAAC,QAAQ,GAAG;QAAE,OAAO,CAAC,EAAC,MAAM,CAAA;KAAE;IAIjD;;OAEG;IACH,MAAM,IAAI,MAAM;CAyBnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@substrate-system/blur-hash",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A blurry placeholder image web component",
|
|
6
6
|
"browserslist": ">= 0.25%",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"require": "./dist/render.cjs"
|
|
24
24
|
},
|
|
25
25
|
"./hash": "./dist/bin/index.js",
|
|
26
|
+
"./photon": "./dist/bin/photon.js",
|
|
26
27
|
"./*": {
|
|
27
28
|
"import": [
|
|
28
29
|
"./dist/*.js",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"build-tests": "esbuild test/index.ts --target=es2020 --bundle --keep-names > test/test-bundle.js",
|
|
40
41
|
"test": "npm run build && npm run build-tests && npm run test-gui && npm run test-bin && npm run test-api && npm run test-ssr",
|
|
41
42
|
"test-bin": "npm run build-bin && esbuild ./test/bin.ts > ./test/bin.js && node ./test/bin.js | tap-spec",
|
|
42
|
-
"test-api": "esbuild ./test/api.ts --format=esm --platform=node > test/api.js && esbuild
|
|
43
|
+
"test-api": "esbuild ./test/api.ts --format=esm --platform=node > test/api.js && esbuild bin/*.ts --platform=node --format=esm --keep-names --outdir=bin && node ./test/api.js | tap-spec",
|
|
43
44
|
"test-ssr": "esbuild ./test/ssr.ts --bundle --platform=node | node --input-type=module | tap-spec",
|
|
44
45
|
"test-gui": "esbuild ./test/index.ts --bundle | tapout | tap-spec",
|
|
45
46
|
"build-css": "lightningcss --browserslist src/index.css -o dist/style.css",
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
"build-example": "mkdir -p ./public && rm -rf ./public/* && vite --base=\"/blur-hash\" build",
|
|
51
52
|
"build-docs": "typedoc --tsconfig tsconfig.build.json ./src/index.ts",
|
|
52
53
|
"build": "mkdir -p ./dist && rm -rf ./dist/* && npm run build-cjs && npm run build-esm && npm run build-esm:min && npm run build-bin && npm run build-css && npm run build-css:min",
|
|
53
|
-
"build-bin": "mkdir -p dist/bin && esbuild --platform=node
|
|
54
|
+
"build-bin": "mkdir -p dist/bin && esbuild bin/*.ts --platform=node --format=esm --keep-names --outdir=dist/bin",
|
|
54
55
|
"start": "vite",
|
|
55
56
|
"toc": "markdown-toc --maxdepth 3 -i README.md",
|
|
56
57
|
"preversion": "npm run lint",
|
|
@@ -59,25 +60,28 @@
|
|
|
59
60
|
"prepublishOnly": "npm run build"
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
|
-
"@substrate-system/web-component": "^0.0.
|
|
63
|
+
"@substrate-system/web-component": "^0.0.56",
|
|
63
64
|
"blurhash": "^2.0.5",
|
|
64
65
|
"image-size": "^2.0.2",
|
|
65
66
|
"inkjet": "^3.0.0",
|
|
66
|
-
"sharp": "^0.34.5",
|
|
67
67
|
"yargs": "^18.0.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
+
"@cf-wasm/photon": "^0.3.5",
|
|
70
71
|
"@substrate-system/dom": "^0.1.13",
|
|
71
72
|
"@substrate-system/tapout": "^0.0.38",
|
|
72
73
|
"@substrate-system/tapzero": "^0.10.16",
|
|
73
|
-
"@types/
|
|
74
|
+
"@types/node": "^25.0.0",
|
|
74
75
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
75
76
|
"@typescript-eslint/parser": "^8.0.0",
|
|
76
77
|
"auto-changelog": "^2.4.0",
|
|
77
78
|
"browserslist": "^4.24.0",
|
|
78
|
-
"esbuild": "^0.
|
|
79
|
+
"esbuild": "^0.28.0",
|
|
79
80
|
"eslint": "^8.57.0",
|
|
80
81
|
"eslint-config-standard": "^17.1.0",
|
|
82
|
+
"eslint-plugin-import": "^2.32.0",
|
|
83
|
+
"eslint-plugin-n": "^18.2.1",
|
|
84
|
+
"eslint-plugin-promise": "^7.3.0",
|
|
81
85
|
"lightningcss": "^1.32.0",
|
|
82
86
|
"lightningcss-cli": "^1.32.0",
|
|
83
87
|
"markdown-toc": "^1.2.0",
|
|
@@ -87,6 +91,14 @@
|
|
|
87
91
|
"typescript": "^6.0.2",
|
|
88
92
|
"vite": "^8.0.5"
|
|
89
93
|
},
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"@cf-wasm/photon": "^0.3.5"
|
|
96
|
+
},
|
|
97
|
+
"peerDependenciesMeta": {
|
|
98
|
+
"@cf-wasm/photon": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
90
102
|
"author": "nichoth <nichoth@nichoth.com> (https://nichoth.com)",
|
|
91
103
|
"license": "SEE LICENSE IN LICENSE",
|
|
92
104
|
"types": "./dist/index.d.ts",
|