@substrate-system/blur-hash 0.0.26 → 0.0.29

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 CHANGED
@@ -5,18 +5,21 @@
5
5
  [![Common Changelog](https://nichoth.github.io/badge/common-changelog.svg)](https://common-changelog.org)
6
6
  [![semantic versioning](https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&style=flat-square)](https://semver.org/)
7
7
  [![install size](https://flat.badgen.net/packagephobia/install/@substrate-system/blur-hash?cache-control=no-cache)](https://packagephobia.com/result?p=@substrate-system/blur-hash)
8
- [![GZip size](https://flat.badgen.net/bundlephobia/minzip/@substrate-system/blur-hash?color=green)](https://bundlephobia.com/package/@substrate-system/blur-hash)
8
+ [![GZip size](https://flat.badgen.net/bundlephobia/minzip/@substrate-system/blur-hash)](https://bundlephobia.com/package/@substrate-system/blur-hash)
9
9
  [![license](https://img.shields.io/badge/license-Big_Time-blue?style=flat-square)](LICENSE)
10
10
 
11
11
 
12
12
  This is the ["blur-up" image loading technique](https://css-tricks.com/the-blur-up-technique-for-loading-background-images/),
13
- with the [blur-hash algorithm](https://blurha.sh/), as a [web component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components).
13
+ with the [blur-hash algorithm](https://blurha.sh/),
14
+ as a [web component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components).
14
15
 
15
16
  [See a live demonstration](https://substrate-system.github.io/blur-hash/)
16
17
 
17
18
  > [!TIP]
18
19
  > Throttle the internet speed with the dev tools.
19
20
 
21
+ <details><summary><h2>Contents</h2></summary>
22
+
20
23
  <!-- toc -->
21
24
 
22
25
  - [Install](#install)
@@ -39,6 +42,9 @@ with the [blur-hash algorithm](https://blurha.sh/), as a [web component](https:/
39
42
 
40
43
  <!-- tocstop -->
41
44
 
45
+ </details>
46
+
47
+
42
48
  ## Install
43
49
 
44
50
  ```sh
@@ -47,7 +53,8 @@ npm i -S @substrate-system/blur-hash
47
53
 
48
54
  ## Modules
49
55
 
50
- This exposes ESM and common JS via [package.json `exports` field](https://nodejs.org/api/packages.html#exports).
56
+ This exposes ESM and common JS via
57
+ [package.json `exports` field](https://nodejs.org/api/packages.html#exports).
51
58
 
52
59
  ### ESM
53
60
  ```js
@@ -85,9 +92,9 @@ Use the tag in HTML.
85
92
  time="0.6s"
86
93
  alt="cool cat"
87
94
  placeholder="LEHV6nWB2yk8pyo0adR*.7kCMdnj"
88
- src="..."
89
- width=100
90
- height=100
95
+ src="/example/cat.png"
96
+ width="100"
97
+ height="100"
91
98
  >
92
99
  </blur-hash>
93
100
  </div>
@@ -108,18 +115,18 @@ BlurHash.define()
108
115
  placeholder="LEHV6nWB2yk8pyo0adR*.7kCMdnj"
109
116
  width=100
110
117
  height=100
111
- src="..."
118
+ src="/example/cat.png"
112
119
  ></blur-hash>
113
120
  ```
114
121
 
115
122
  ### Server-side rendering
116
- Following convention, this module exposes an `html` function at `/ssr`. It
117
- returns a plain string of appropriate markup in Node.
123
+ Following convention, this module exposes `render` function at `/html`. It
124
+ returns a plain string of markup.
118
125
 
119
126
  ```js
120
- import { html } from '@substrate-system/blur-hash/ssr'
127
+ import { render } from '@substrate-system/blur-hash/html'
121
128
 
122
- const htmlString = html({
129
+ const htmlString = render({
123
130
  alt: 'hello',
124
131
  width: 30,
125
132
  height: 30,
@@ -17,14 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var ssr_exports = {};
21
- __export(ssr_exports, {
22
- html: () => html,
23
- outerHTML: () => outerHTML
20
+ var html_exports = {};
21
+ __export(html_exports, {
22
+ outerHTML: () => outerHTML,
23
+ render: () => render
24
24
  });
25
- module.exports = __toCommonJS(ssr_exports);
25
+ module.exports = __toCommonJS(html_exports);
26
26
  var import_util = require("@substrate-system/util");
27
- function html(attrs) {
27
+ function render(attrs) {
28
28
  const {
29
29
  width,
30
30
  height,
@@ -61,8 +61,8 @@ function html(attrs) {
61
61
  ${htmlString}
62
62
  </blur-hash>` : htmlString;
63
63
  }
64
- __name(html, "html");
64
+ __name(render, "render");
65
65
  const outerHTML = /* @__PURE__ */ __name((attrs) => {
66
- return `<blur-hash>${html(attrs)}</blur-hash>`;
66
+ return `<blur-hash>${render(attrs)}</blur-hash>`;
67
67
  }, "outerHTML");
68
- //# sourceMappingURL=ssr.cjs.map
68
+ //# sourceMappingURL=html.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/html.ts"],
4
+ "sourcesContent": ["import { attributes } from '@substrate-system/util'\nimport type { ImgAttrs } from './index.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 htmlString = `<canvas\n alt=\"${alt}\"\n width=${width}\n height=${height}\n class=\"blurry\"\n width=${width}\n height=${height}\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 = attributes(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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAKpB,SAAS,OAAQ,OAAgB;AACpC,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI;AAEJ,MAAI,CAAC,YAAa,OAAM,IAAI,MAAM,iBAAiB;AAEnD,QAAM,aAAa;AAAA,eACR,GAAG;AAAA,gBACF,KAAK;AAAA,iBACJ,MAAM;AAAA;AAAA,gBAEP,KAAK;AAAA,iBACJ,MAAM;AAAA;AAAA;AAAA;AAAA,eAIR,GAAG;AAAA,8BACY,qBAAqB,MAAM;AAAA,oBACrC,YAAY,OAAO;AAAA,mBACpB,WAAW,MAAM;AAAA,UAC1B,SAAS,WAAW,MAAM,MAAM,EAAE;AAAA,UAClC,QAAQ,UAAU,KAAK,MAAM,EAAE;AAAA,eAC1B,GAAG;AAAA;AAGd,QAAM,sBAAkB,wBAAW,KAAK;AAGxC,SAAO,OAAO,WAAW,cACrB,cAAc,eAAe;AAAA,cACvB,UAAU;AAAA,wBAEhB;AACR;AA3CgB;AA6CT,MAAM,YAAY,wBAAC,UAAmB;AACzC,SAAO,cAAc,OAAO,KAAK,CAAC;AACtC,GAFyB;",
6
+ "names": []
7
+ }
@@ -2,6 +2,6 @@ import type { ImgAttrs } from './index.js';
2
2
  export type SSRAttrs = ImgAttrs & {
3
3
  classes?: string;
4
4
  };
5
- export declare function html(attrs: SSRAttrs): string;
5
+ export declare function render(attrs: SSRAttrs): string;
6
6
  export declare const outerHTML: (attrs: SSRAttrs) => string;
7
- //# sourceMappingURL=ssr.d.ts.map
7
+ //# sourceMappingURL=html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG;IAAE,OAAO,CAAC,EAAC,MAAM,CAAA;CAAE,CAAA;AAErD,wBAAgB,MAAM,CAAE,KAAK,EAAC,QAAQ,UA2CrC;AAED,eAAO,MAAM,SAAS,UAAU,QAAQ,WAEvC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { attributes } from "@substrate-system/util";
4
- function html(attrs) {
4
+ function render(attrs) {
5
5
  const {
6
6
  width,
7
7
  height,
@@ -38,12 +38,12 @@ function html(attrs) {
38
38
  ${htmlString}
39
39
  </blur-hash>` : htmlString;
40
40
  }
41
- __name(html, "html");
41
+ __name(render, "render");
42
42
  const outerHTML = /* @__PURE__ */ __name((attrs) => {
43
- return `<blur-hash>${html(attrs)}</blur-hash>`;
43
+ return `<blur-hash>${render(attrs)}</blur-hash>`;
44
44
  }, "outerHTML");
45
45
  export {
46
- html,
47
- outerHTML
46
+ outerHTML,
47
+ render
48
48
  };
49
- //# sourceMappingURL=ssr.js.map
49
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/html.ts"],
4
+ "sourcesContent": ["import { attributes } from '@substrate-system/util'\nimport type { ImgAttrs } from './index.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 htmlString = `<canvas\n alt=\"${alt}\"\n width=${width}\n height=${height}\n class=\"blurry\"\n width=${width}\n height=${height}\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 = attributes(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"],
5
+ "mappings": ";;AAAA,SAAS,kBAAkB;AAKpB,SAAS,OAAQ,OAAgB;AACpC,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI;AAEJ,MAAI,CAAC,YAAa,OAAM,IAAI,MAAM,iBAAiB;AAEnD,QAAM,aAAa;AAAA,eACR,GAAG;AAAA,gBACF,KAAK;AAAA,iBACJ,MAAM;AAAA;AAAA,gBAEP,KAAK;AAAA,iBACJ,MAAM;AAAA;AAAA;AAAA;AAAA,eAIR,GAAG;AAAA,8BACY,qBAAqB,MAAM;AAAA,oBACrC,YAAY,OAAO;AAAA,mBACpB,WAAW,MAAM;AAAA,UAC1B,SAAS,WAAW,MAAM,MAAM,EAAE;AAAA,UAClC,QAAQ,UAAU,KAAK,MAAM,EAAE;AAAA,eAC1B,GAAG;AAAA;AAGd,QAAM,kBAAkB,WAAW,KAAK;AAGxC,SAAO,OAAO,WAAW,cACrB,cAAc,eAAe;AAAA,cACvB,UAAU;AAAA,wBAEhB;AACR;AA3CgB;AA6CT,MAAM,YAAY,wBAAC,UAAmB;AACzC,SAAO,cAAc,OAAO,KAAK,CAAC;AACtC,GAFyB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,21 @@
1
+ var g=Object.defineProperty;var n=(t,e)=>g(t,"name",{value:e,configurable:!0});var $=Object.defineProperty,_=n((t,e)=>$(t,"name",{value:e,configurable:!0}),"__name"),b=class{static{n(this,"Queue")}static{_(this,"Queue")}_inProgress=Promise.resolve();add(e){return this._inProgress=this._inProgress.then(()=>e()),this._inProgress}};var y=Object.defineProperty,v=n((t,e)=>y(t,"name",{value:e,configurable:!0}),"__name");function u(t){return Object.keys(t).reduce((e,r)=>{let s=t[r];return s?typeof s=="boolean"?s?(e+` ${r}`).trim():e:Array.isArray(s)?e+` ${r}="${s.join(" ")}"`:(e+` ${r}="${s}"`).trim():e},"")}n(u,"attributes");v(u,"attributes");var A=Object.defineProperty,o=n((t,e)=>A(t,"name",{value:e,configurable:!0}),"__name");function j(t){return t.map(e=>e.name+(e.value===""?"":`="${e.value}"`)).join(" ")}n(j,"attributesToString");o(j,"attributesToString");function P(t){return new Promise(e=>{t?setTimeout(e,t):setTimeout(e,0)})}n(P,"sleep");o(P,"sleep");function S(t){let e=new FormData(t),r={};return e.forEach((s,i)=>{if(Reflect.has(r,i)){let a=r[i];Array.isArray(a)?a.push(s):r[i]=[r[i],s]}else r[i]=s}),r}n(S,"parseForm");o(S,"parseForm");function x(t){return t.reduce((e,r)=>(e[r.name]=r.value||!0,e),{})}n(x,"attributesAsObject");o(x,"attributesAsObject");function w(t){return Object.keys(t).map(e=>e+(t[e]===!0?"":`="${t[e]}"`)).join(" ")}n(w,"objectToString");o(w,"objectToString");function O(t,e){for(let r in e){let s=e[r];s===!1?t.removeAttribute(r):t.setAttribute(r,s===!0?"":s)}}n(O,"setAttributes");o(O,"setAttributes");function T(t){let{width:e,height:r,alt:s,contentVisibility:i,placeholder:a,decoding:m,loading:p,srcset:c,sizes:f,src:d}=t;if(!a)throw new Error("not placeholder");let l=`<canvas
2
+ alt="${s}"
3
+ width=${e}
4
+ height=${r}
5
+ class="blurry"
6
+ width=${e}
7
+ height=${r}
8
+ ></canvas>
9
+
10
+ <img class="blurry"
11
+ alt="${s}"
12
+ content-visibility="${i||"auto"}"
13
+ decoding="${m||"async"}"
14
+ loading="${p||"lazy"}"
15
+ ${c?`srcset="${c}"`:""}
16
+ ${f?`sizes="${f}"`:""}
17
+ src="${d}"
18
+ />`,h=u(t);return typeof window>"u"?`<blur-hash ${h}>
19
+ ${l}
20
+ </blur-hash>`:l}n(T,"render");var G=n(t=>`<blur-hash>${T(t)}</blur-hash>`,"outerHTML");export{G as outerHTML,T as render};
21
+ //# sourceMappingURL=html.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../node_modules/@substrate-system/util/src/queue.ts", "../node_modules/@substrate-system/util/src/to-string.ts", "../node_modules/@substrate-system/util/src/index.ts", "../src/ssr.ts"],
4
- "sourcesContent": ["export class Queue<T> {\n _inProgress:Promise<T|void> = Promise.resolve()\n\n add (createP:()=>Promise<T>):Promise<T|void> {\n this._inProgress = this._inProgress.then(() => {\n return createP()\n })\n\n return this._inProgress\n }\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 attributes (\n attrs:Record<string, undefined|null|string|number|boolean|(string|number)[]>\n):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 * from './queue.js'\nexport * from './classes.js'\nexport * from './to-string.js'\n\n/**\n * Get attributes from an HTMLElement, and return them as a string.\n * like `key=val`.\n * @param {Attr[]} attrs An array of the attributes, where attributes are like\n * `{ name: 'aaa', value: 'bbb' }`\n * @returns {string} The attributes as a string like `key=val`\n */\nexport function attributesToString (attrs:Attr[]):string {\n return attrs.map(attr => attr.name + (attr.value === '' ?\n '' :\n `=\"${attr.value}\"`))\n .join(' ')\n}\n\n/**\n * Wait for `ms` milliseconds.\n *\n * @param {number} [ms]\n * @return {Promise<void>}\n */\nexport function sleep (ms?:number):Promise<void> {\n return new Promise(resolve => {\n if (!ms) {\n setTimeout(resolve, 0)\n } else {\n setTimeout(resolve, ms)\n }\n })\n}\n\n/**\n * Serialize a form and return a plain object.\n * If a form control with the same name appears more than once, the\n * property will be converted to an array.\n */\nexport function parseForm (form:HTMLFormElement):Record<string, unknown> {\n const formData = new FormData(form)\n const object:Record<string, unknown> = {}\n\n formData.forEach((value, key) => {\n if (Reflect.has(object, key)) {\n const entry = object[key]\n if (Array.isArray(entry)) {\n entry.push(value)\n } else {\n object[key] = [object[key], value]\n }\n } else {\n object[key] = value\n }\n })\n\n return object\n}\n\n/**\n * Return a new object of key value pairs given an array of attributes.\n *\n * @param attrs An array of attributes\n * @returns {Record<string, string|true>} An object of key value pairs, or\n * key -> true for boolean attributes\n */\nexport function attributesAsObject (attrs:Attr[]):Record<string, string|true> {\n return attrs.reduce((acc, attr) => {\n acc[attr.name] = attr.value || true\n return acc\n }, {})\n}\n\nexport function objectToString (obj:Record<string, string|true>):string {\n return Object.keys(obj).map(k => {\n return k + (obj[k] === true ? '' : `=\"${obj[k]}\"`)\n }).join(' ')\n}\n\nexport default {\n attributesToString,\n attributesAsObject,\n setAttributes\n}\n\nexport function setAttributes (el:HTMLElement, attrs:Record<string, string|boolean>) {\n for (const key in attrs) {\n const val = attrs[key]\n if (val === false) {\n el.removeAttribute(key)\n } else {\n el.setAttribute(key, (val === true ? '' : val))\n }\n }\n}\n", "import { attributes } from '@substrate-system/util'\nimport type { ImgAttrs } from './index.js'\n\nexport type SSRAttrs = ImgAttrs & { classes?:string }\n\nexport function html (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 htmlString = `<canvas\n alt=\"${alt}\"\n width=${width}\n height=${height}\n class=\"blurry\"\n width=${width}\n height=${height}\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 = attributes(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>${html(attrs)}</blur-hash>`\n}\n"],
5
- "mappings": "sKAAaA,EAAN,KAAe,OAAA,CAAAC,EAAA,cAAtB,MAAsB,CAAAA,EAAA,KAAA,OAAA,CAAA,CAClB,YAA8B,QAAQ,QAAQ,EAE9C,IAAKC,EAAwC,CACzC,YAAK,YAAc,KAAK,YAAY,KAAK,IAC9BA,EAAQ,CAClB,EAEM,KAAK,WAChB,CACJ,yFCHO,SAASC,EACZC,EACK,CACL,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,CAlBgBG,EAAAL,EAAA,cAAAK,EAAAL,EAAA,YAAA,yFCIT,SAASM,EAAoBC,EAAqB,CACrD,OAAOA,EAAM,IAAIC,GAAQA,EAAK,MAAQA,EAAK,QAAU,GACjD,GACA,KAAKA,EAAK,KAAK,IAAI,EAClB,KAAK,GAAG,CACjB,CALgBC,EAAAH,EAAA,sBAAAG,EAAAH,EAAA,oBAAA,EAaT,SAASI,EAAOC,EAA0B,CAC7C,OAAO,IAAI,QAAQC,GAAW,CACrBD,EAGD,WAAWC,EAASD,CAAE,EAFtB,WAAWC,EAAS,CAAC,CAI7B,CAAC,CACL,CARgBH,EAAAC,EAAA,SAAAD,EAAAC,EAAA,OAAA,EAeT,SAASG,EAAWC,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EACA,IAAAC,CACJ,EAAIV,EAEJ,GAAI,CAACK,EAAa,MAAM,IAAI,MAAM,iBAAiB,EAEnD,IAAMM,EAAa;AAAA,eACRR,CAAG;AAAA,gBACFF,CAAK;AAAA,iBACJC,CAAM;AAAA;AAAA,gBAEPD,CAAK;AAAA,iBACJC,CAAM;AAAA;AAAA;AAAA;AAAA,eAIRC,CAAG;AAAA,8BACYC,GAAqB,MAAM;AAAA,oBACrCE,GAAY,OAAO;AAAA,mBACpBC,GAAW,MAAM;AAAA,UAC1BC,EAAS,WAAWA,CAAM,IAAM,EAAE;AAAA,UAClCC,EAAQ,UAAUA,CAAK,IAAM,EAAE;AAAA,eAC1BC,CAAG;AAAA,QAGRE,EAAkBC,EAAWb,CAAK,EAGxC,OAAO,OAAO,OAAW,IACrB,cAAcY,CAAe;AAAA,cACvBD,CAAU;AAAA,sBAEhBA,CACR,CA3CgBG,EAAAf,EAAA,QA6CT,IAAMgB,EAAYD,EAACd,GACf,cAAcD,EAAKC,CAAK,CAAC,eADX",
6
- "names": ["Queue", "__name", "createP", "attributes", "attrs", "acc", "k", "value", "__name", "attributesToString", "attrs", "attr", "__name", "sleep", "ms", "resolve", "parseForm", "form", "formData", "object", "value", "key", "entry", "attributesAsObject", "acc", "objectToString", "obj", "k", "setAttributes", "el", "attrs", "key", "val", "__name", "html", "attrs", "width", "height", "alt", "contentVisibility", "placeholder", "decoding", "loading", "srcset", "sizes", "src", "htmlString", "attributeString", "attributes", "__name", "outerHTML"]
3
+ "sources": ["../node_modules/@substrate-system/util/src/queue.ts", "../node_modules/@substrate-system/util/src/to-string.ts", "../node_modules/@substrate-system/util/src/index.ts", "../src/html.ts"],
4
+ "sourcesContent": ["export class Queue<T> {\n _inProgress:Promise<T|void> = Promise.resolve()\n\n add (createP:()=>Promise<T>):Promise<T|void> {\n this._inProgress = this._inProgress.then(() => {\n return createP()\n })\n\n return this._inProgress\n }\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 attributes (\n attrs:Record<string, undefined|null|string|number|boolean|(string|number)[]>\n):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 * from './queue.js'\nexport * from './classes.js'\nexport * from './to-string.js'\n\n/**\n * Get attributes from an HTMLElement, and return them as a string.\n * like `key=val`.\n * @param {Attr[]} attrs An array of the attributes, where attributes are like\n * `{ name: 'aaa', value: 'bbb' }`\n * @returns {string} The attributes as a string like `key=val`\n */\nexport function attributesToString (attrs:Attr[]):string {\n return attrs.map(attr => attr.name + (attr.value === '' ?\n '' :\n `=\"${attr.value}\"`))\n .join(' ')\n}\n\n/**\n * Wait for `ms` milliseconds.\n *\n * @param {number} [ms]\n * @return {Promise<void>}\n */\nexport function sleep (ms?:number):Promise<void> {\n return new Promise(resolve => {\n if (!ms) {\n setTimeout(resolve, 0)\n } else {\n setTimeout(resolve, ms)\n }\n })\n}\n\n/**\n * Serialize a form and return a plain object.\n * If a form control with the same name appears more than once, the\n * property will be converted to an array.\n */\nexport function parseForm (form:HTMLFormElement):Record<string, unknown> {\n const formData = new FormData(form)\n const object:Record<string, unknown> = {}\n\n formData.forEach((value, key) => {\n if (Reflect.has(object, key)) {\n const entry = object[key]\n if (Array.isArray(entry)) {\n entry.push(value)\n } else {\n object[key] = [object[key], value]\n }\n } else {\n object[key] = value\n }\n })\n\n return object\n}\n\n/**\n * Return a new object of key value pairs given an array of attributes.\n *\n * @param attrs An array of attributes\n * @returns {Record<string, string|true>} An object of key value pairs, or\n * key -> true for boolean attributes\n */\nexport function attributesAsObject (attrs:Attr[]):Record<string, string|true> {\n return attrs.reduce((acc, attr) => {\n acc[attr.name] = attr.value || true\n return acc\n }, {})\n}\n\nexport function objectToString (obj:Record<string, string|true>):string {\n return Object.keys(obj).map(k => {\n return k + (obj[k] === true ? '' : `=\"${obj[k]}\"`)\n }).join(' ')\n}\n\nexport default {\n attributesToString,\n attributesAsObject,\n setAttributes\n}\n\nexport function setAttributes (el:HTMLElement, attrs:Record<string, string|boolean>) {\n for (const key in attrs) {\n const val = attrs[key]\n if (val === false) {\n el.removeAttribute(key)\n } else {\n el.setAttribute(key, (val === true ? '' : val))\n }\n }\n}\n", "import { attributes } from '@substrate-system/util'\nimport type { ImgAttrs } from './index.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 htmlString = `<canvas\n alt=\"${alt}\"\n width=${width}\n height=${height}\n class=\"blurry\"\n width=${width}\n height=${height}\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 = attributes(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"],
5
+ "mappings": "sKAAaA,EAAN,KAAe,OAAA,CAAAC,EAAA,cAAtB,MAAsB,CAAAA,EAAA,KAAA,OAAA,CAAA,CAClB,YAA8B,QAAQ,QAAQ,EAE9C,IAAKC,EAAwC,CACzC,YAAK,YAAc,KAAK,YAAY,KAAK,IAC9BA,EAAQ,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AUA,CAAK,IAAM,EAAE;AAAA,eAC1BC,CAAG;AAAA,QAGRE,EAAkBC,EAAWb,CAAK,EAGxC,OAAO,OAAO,OAAW,IACrB,cAAcY,CAAe;AAAA,cACvBD,CAAU;AAAA,sBAEhBA,CACR,CA3CgBG,EAAAf,EAAA,UA6CT,IAAMgB,EAAYD,EAACd,GACf,cAAcD,EAAOC,CAAK,CAAC,eADb",
6
+ "names": ["Queue", "__name", "createP", "attributes", "attrs", "acc", "k", "value", "__name", "attributesToString", "attrs", "attr", "__name", "sleep", "ms", "resolve", "parseForm", "form", "formData", "object", "value", "key", "entry", "attributesAsObject", "acc", "objectToString", "obj", "k", "setAttributes", "el", "attrs", "key", "val", "__name", "render", "attrs", "width", "height", "alt", "contentVisibility", "placeholder", "decoding", "loading", "srcset", "sizes", "src", "htmlString", "attributeString", "attributes", "__name", "outerHTML"]
7
7
  }
package/dist/index.cjs CHANGED
@@ -24,7 +24,7 @@ __export(index_exports, {
24
24
  module.exports = __toCommonJS(index_exports);
25
25
  var import_web_component = require("@substrate-system/web-component");
26
26
  var import_blurhash = require("blurhash");
27
- var import_ssr = require("./ssr.js");
27
+ var import_html = require("./html.js");
28
28
  class BlurHash extends import_web_component.WebComponent.create("blur-hash") {
29
29
  static {
30
30
  __name(this, "BlurHash");
@@ -98,7 +98,7 @@ class BlurHash extends import_web_component.WebComponent.create("blur-hash") {
98
98
  this.sharpen();
99
99
  }
100
100
  static html(attrs) {
101
- return (0, import_ssr.html)(attrs);
101
+ return (0, import_html.render)(attrs);
102
102
  }
103
103
  /**
104
104
  * Use the attributes to create HTML.
@@ -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 { html } from './ssr.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\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) : attrs.width) :\n parseInt(this.style.width))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height) : attrs.height) :\n parseInt(this.style.height))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n const pixels = decode(placeholder, width, height)\n const canvas = this.querySelector('canvas') as HTMLCanvasElement\n const ctx = canvas.getContext('2d')!\n const imageData = ctx.createImageData(width, height)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\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 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 const pixels = decode(placeholder, width, height)\n const canvas = this.querySelector('canvas') as HTMLCanvasElement\n const ctx = canvas.getContext('2d')!\n const imageData = ctx.createImageData(width, height)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n\n this.sharpen()\n }\n\n static html (attrs:ImgAttrs & { classes?:string }) {\n return html(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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA6B;AAC7B,sBAAuB;AACvB,iBAAqB;AAuBd,MAAM,iBAAiB,kCAAa,OAAO,WAAW,EAAE;AAAA,EAzB/D,OAyB+D;AAAA;AAAA;AAAA,EAC3D;AAAA,EAEA,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,SAA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a,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,EAAE,SAAS,QAAQ,OAAO,QAAQ,KAAK,KAAK,YAAY,CAAC;AAAA,EAClF;AACJ;",
4
+ "sourcesContent": ["import { WebComponent } from '@substrate-system/web-component'\nimport { decode } from 'blurhash'\nimport { render } from './html.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\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) : attrs.width) :\n parseInt(this.style.width))\n const height = (attrs.height ?\n (typeof attrs.height === 'string' ? parseInt(attrs.height) : attrs.height) :\n parseInt(this.style.height))\n\n this.innerHTML = BlurHash.html(Object.assign(attrs, { width, height }))\n\n const { placeholder, src: newSrc } = attrs\n\n const pixels = decode(placeholder, width, height)\n const canvas = this.querySelector('canvas') as HTMLCanvasElement\n const ctx = canvas.getContext('2d')!\n const imageData = ctx.createImageData(width, height)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\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 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 const pixels = decode(placeholder, width, height)\n const canvas = this.querySelector('canvas') as HTMLCanvasElement\n const ctx = canvas.getContext('2d')!\n const imageData = ctx.createImageData(width, height)\n imageData.data.set(pixels)\n ctx.putImageData(imageData, 0, 0)\n\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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA6B;AAC7B,sBAAuB;AACvB,kBAAuB;AAuBhB,MAAM,iBAAiB,kCAAa,OAAO,WAAW,EAAE;AAAA,EAzB/D,OAyB+D;AAAA;AAAA;AAAA,EAC3D;AAAA,EAEA,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,KAAK,IAAI,MAAM,QACjE,SAAS,KAAK,MAAM,KAAK;AAC7B,UAAM,SAAU,MAAM,SACjB,OAAO,MAAM,WAAW,WAAW,SAAS,MAAM,MAAM,IAAI,MAAM,SACnE,SAAS,KAAK,MAAM,MAAM;AAE9B,SAAK,YAAY,SAAS,KAAK,OAA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