@pixid/png 0.1.1 → 0.2.0
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 +21 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -10
- package/dist/index.d.ts +9 -10
- package/dist/index.js +1 -1
- package/package.json +14 -8
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @pixid/png
|
|
2
|
+
|
|
3
|
+
<img src="https://raw.githubusercontent.com/thilllon/pixid/main/assets/alice.png" width="64" height="64" alt="identicon for alice" />
|
|
4
|
+
|
|
5
|
+
Encodes deterministic blocky identicons as PNG bytes or `data:image/png` URLs
|
|
6
|
+
with a built-in encoder: no `Buffer`, no zlib, nothing outside `@pixid/core`,
|
|
7
|
+
so it runs in Node, browsers, and edge runtimes alike.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @pixid/png
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { writeFileSync } from 'node:fs';
|
|
15
|
+
import { toPng, toPngDataURL } from '@pixid/png';
|
|
16
|
+
|
|
17
|
+
writeFileSync('alice.png', toPng({ seed: 'alice', scale: 16 })); // the icon above: 128×128, 4313 bytes
|
|
18
|
+
const src = toPngDataURL({ seed: 'alice', scale: 16 }); // 'data:image/png;base64,...'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Full API: [`@pixid/png` in the pixid README](https://github.com/thilllon/pixid#pixidpng).
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@pixid/core");const t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let e=0;e<8;e++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}const n=e=>{let n=4294967295;for(let r=0;r<e.length;r++)n=t[(n^e[r])&255]^n>>>8;return(n^4294967295)>>>0},r=e=>{let t=1,n=0;for(let r=0;r<e.length;r++)t=(t+e[r])%65521,n=(n+t)%65521;return(n<<16|t)>>>0},i=e=>{let t=Math.max(1,Math.ceil(e.length/65535)),n=new Uint8Array(2+e.length+t*5+4),i=0;n[i++]=120,n[i++]=1;for(let r=0;r<t;r++){let a=r*65535,o=e.subarray(a,Math.min(a+65535,e.length)),s=r===t-1;n[i++]=+!!s,n[i++]=o.length&255,n[i++]=o.length>>>8,n[i++]=~o.length&255,n[i++]=~o.length>>>8&255,n.set(o,i),i+=o.length}let a=r(e);return n[i++]=a>>>24&255,n[i++]=a>>>16&255,n[i++]=a>>>8&255,n[i]=a&255,n},a={IHDR:`IHDR`,PLTE:`PLTE`,IDAT:`IDAT`,IEND:`IEND`},o=(e,t)=>{let r=new Uint8Array(12+t.length),i=new DataView(r.buffer);i.setUint32(0,t.length);for(let t=0;t<4;t++)r[4+t]=e.charCodeAt(t);return r.set(t,8),i.setUint32(8+t.length,n(r.subarray(4,8+t.length))),r},s=[137,80,78,71,13,10,26,10],c=(e,t=4)=>{if(!Number.isInteger(t)||t<1)throw RangeError(`invalid scale: ${t} (expected a positive integer)`);let n=e.size*t,r=Math.ceil(n/4),c=new Uint8Array((1+r)*n);for(let i=0;i<n;i++){let a=i*(1+r)+1,o=Math.floor(i/t)*e.size;for(let r=0;r<n;r++){let n=e.grid[o+Math.floor(r/t)],i=a+(r>>2);c[i]=c[i]|n<<(3-(r&3))*2}}let l=new Uint8Array(13),u=new DataView(l.buffer);u.setUint32(0,n),u.setUint32(4,n),l[8]=2,l[9]=3,l[10]=0,l[11]=0,l[12]=0;let d=new Uint8Array([...e.bgcolor,...e.color,...e.spotcolor]),f=[new Uint8Array(s),o(a.IHDR,l),o(a.PLTE,d),o(a.IDAT,i(c)),o(a.IEND,new Uint8Array)],p=new Uint8Array(f.reduce((e,t)=>e+t.length,0)),m=0;for(let e of f)p.set(e,m),m+=e.length;return p},l=(t={})=>c((0,e.createIcon)(t),t.scale??4),u=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,d=e=>{let t=``;for(let n=0;n<e.length;n+=3){let r=e[n],i=e[n+1],a=e[n+2];t+=u[r>>2],t+=u[(r&3)<<4|(i??0)>>4],t+=i===void 0?`=`:u[(i&15)<<2|(a??0)>>6],t+=a===void 0?`=`:u[a&63]}return t},f=(e={})=>`data:image/png;base64,${d(l(e))}`;exports.iconToPng=c,exports.toPng=l,exports.toPngDataURL=f;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface PngOptions extends IconOptions {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { IconData, IconOptions } from "@pixid/core";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export interface PngOptions extends IconOptions {
|
|
4
|
+
/** Pixels per cell. Defaults to 4. */
|
|
5
|
+
scale?: number;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Encodes precomputed icon data as a PNG file.
|
|
@@ -10,10 +10,9 @@ interface PngOptions extends IconOptions {
|
|
|
10
10
|
* Uses an indexed-color PNG (3-entry palette, 2 bits per pixel), so files
|
|
11
11
|
* stay small without a compression library.
|
|
12
12
|
*/
|
|
13
|
-
declare const iconToPng: (icon: IconData, scale?: number) => Uint8Array;
|
|
13
|
+
export declare const iconToPng: (icon: IconData, scale?: number) => Uint8Array;
|
|
14
14
|
/** Generates an icon and encodes it as a PNG file. */
|
|
15
|
-
declare const toPng: (options?: PngOptions) => Uint8Array;
|
|
15
|
+
export declare const toPng: (options?: PngOptions) => Uint8Array;
|
|
16
16
|
/** Generates an icon and encodes it as a `data:image/png;base64` URL. */
|
|
17
|
-
declare const toPngDataURL: (options?: PngOptions) => string;
|
|
18
|
-
|
|
19
|
-
export { type PngOptions, iconToPng, toPng, toPngDataURL };
|
|
17
|
+
export declare const toPngDataURL: (options?: PngOptions) => string;
|
|
18
|
+
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface PngOptions extends IconOptions {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { IconData, IconOptions } from "@pixid/core";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export interface PngOptions extends IconOptions {
|
|
4
|
+
/** Pixels per cell. Defaults to 4. */
|
|
5
|
+
scale?: number;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Encodes precomputed icon data as a PNG file.
|
|
@@ -10,10 +10,9 @@ interface PngOptions extends IconOptions {
|
|
|
10
10
|
* Uses an indexed-color PNG (3-entry palette, 2 bits per pixel), so files
|
|
11
11
|
* stay small without a compression library.
|
|
12
12
|
*/
|
|
13
|
-
declare const iconToPng: (icon: IconData, scale?: number) => Uint8Array;
|
|
13
|
+
export declare const iconToPng: (icon: IconData, scale?: number) => Uint8Array;
|
|
14
14
|
/** Generates an icon and encodes it as a PNG file. */
|
|
15
|
-
declare const toPng: (options?: PngOptions) => Uint8Array;
|
|
15
|
+
export declare const toPng: (options?: PngOptions) => Uint8Array;
|
|
16
16
|
/** Generates an icon and encodes it as a `data:image/png;base64` URL. */
|
|
17
|
-
declare const toPngDataURL: (options?: PngOptions) => string;
|
|
18
|
-
|
|
19
|
-
export { type PngOptions, iconToPng, toPng, toPngDataURL };
|
|
17
|
+
export declare const toPngDataURL: (options?: PngOptions) => string;
|
|
18
|
+
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createIcon as
|
|
1
|
+
import{createIcon as e}from"@pixid/core";const t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let e=0;e<8;e++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}const n=e=>{let n=4294967295;for(let r=0;r<e.length;r++)n=t[(n^e[r])&255]^n>>>8;return(n^4294967295)>>>0},r=e=>{let t=1,n=0;for(let r=0;r<e.length;r++)t=(t+e[r])%65521,n=(n+t)%65521;return(n<<16|t)>>>0},i=e=>{let t=Math.max(1,Math.ceil(e.length/65535)),n=new Uint8Array(2+e.length+t*5+4),i=0;n[i++]=120,n[i++]=1;for(let r=0;r<t;r++){let a=r*65535,o=e.subarray(a,Math.min(a+65535,e.length)),s=r===t-1;n[i++]=+!!s,n[i++]=o.length&255,n[i++]=o.length>>>8,n[i++]=~o.length&255,n[i++]=~o.length>>>8&255,n.set(o,i),i+=o.length}let a=r(e);return n[i++]=a>>>24&255,n[i++]=a>>>16&255,n[i++]=a>>>8&255,n[i]=a&255,n},a={IHDR:`IHDR`,PLTE:`PLTE`,IDAT:`IDAT`,IEND:`IEND`},o=(e,t)=>{let r=new Uint8Array(12+t.length),i=new DataView(r.buffer);i.setUint32(0,t.length);for(let t=0;t<4;t++)r[4+t]=e.charCodeAt(t);return r.set(t,8),i.setUint32(8+t.length,n(r.subarray(4,8+t.length))),r},s=[137,80,78,71,13,10,26,10],c=(e,t=4)=>{if(!Number.isInteger(t)||t<1)throw RangeError(`invalid scale: ${t} (expected a positive integer)`);let n=e.size*t,r=Math.ceil(n/4),c=new Uint8Array((1+r)*n);for(let i=0;i<n;i++){let a=i*(1+r)+1,o=Math.floor(i/t)*e.size;for(let r=0;r<n;r++){let n=e.grid[o+Math.floor(r/t)],i=a+(r>>2);c[i]=c[i]|n<<(3-(r&3))*2}}let l=new Uint8Array(13),u=new DataView(l.buffer);u.setUint32(0,n),u.setUint32(4,n),l[8]=2,l[9]=3,l[10]=0,l[11]=0,l[12]=0;let d=new Uint8Array([...e.bgcolor,...e.color,...e.spotcolor]),f=[new Uint8Array(s),o(a.IHDR,l),o(a.PLTE,d),o(a.IDAT,i(c)),o(a.IEND,new Uint8Array)],p=new Uint8Array(f.reduce((e,t)=>e+t.length,0)),m=0;for(let e of f)p.set(e,m),m+=e.length;return p},l=(t={})=>c(e(t),t.scale??4),u=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,d=e=>{let t=``;for(let n=0;n<e.length;n+=3){let r=e[n],i=e[n+1],a=e[n+2];t+=u[r>>2],t+=u[(r&3)<<4|(i??0)>>4],t+=i===void 0?`=`:u[(i&15)<<2|(a??0)>>6],t+=a===void 0?`=`:u[a&63]}return t},f=(e={})=>`data:image/png;base64,${d(l(e))}`;export{c as iconToPng,l as toPng,f as toPngDataURL};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixid/png",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Encodes pixid blocky identicons as PNG (Uint8Array or data URL) with a built-in zero-dependency encoder. Works in Node, browsers, and edge runtimes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"identicon",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "thilllon",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/thilllon/pixid.git",
|
|
16
|
+
"url": "git+https://github.com/thilllon/pixid.git",
|
|
17
17
|
"directory": "packages/png"
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/thilllon/pixid",
|
|
@@ -27,16 +27,22 @@
|
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/index.d.cts",
|
|
36
|
+
"default": "./dist/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
34
40
|
},
|
|
35
41
|
"files": [
|
|
36
42
|
"dist"
|
|
37
43
|
],
|
|
38
44
|
"dependencies": {
|
|
39
|
-
"@pixid/core": "^0.
|
|
45
|
+
"@pixid/core": "^0.2.0"
|
|
40
46
|
},
|
|
41
47
|
"devDependencies": {
|
|
42
48
|
"@types/pngjs": "^6.0.5",
|
|
@@ -49,6 +55,6 @@
|
|
|
49
55
|
"node": ">=18"
|
|
50
56
|
},
|
|
51
57
|
"scripts": {
|
|
52
|
-
"build": "
|
|
58
|
+
"build": "tsdown"
|
|
53
59
|
}
|
|
54
60
|
}
|