@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 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
- "use strict";var A=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of R(t))!T.call(e,o)&&o!==n&&A(e,o,{get:()=>t[o],enumerable:!(r=E(t,o))||r.enumerable});return e};var C=e=>N(A({},"__esModule",{value:!0}),e);var v={};m(v,{iconToPng:()=>d,toPng:()=>D,toPngDataURL:()=>O});module.exports=C(v);var w=require("@pixid/core"),I=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;I[e]=t>>>0}var M=e=>{let t=4294967295;for(let n=0;n<e.length;n++)t=I[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0},S=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},k=e=>{let t=Math.max(1,Math.ceil(e.length/65535)),n=new Uint8Array(2+e.length+t*5+4),r=0;n[r++]=120,n[r++]=1;for(let s=0;s<t;s++){let f=s*65535,i=e.subarray(f,Math.min(f+65535,e.length)),l=s===t-1;n[r++]=l?1:0,n[r++]=i.length&255,n[r++]=i.length>>>8,n[r++]=~i.length&255,n[r++]=~i.length>>>8&255,n.set(i,r),r+=i.length}let o=S(e);return n[r++]=o>>>24&255,n[r++]=o>>>16&255,n[r++]=o>>>8&255,n[r]=o&255,n},g={IHDR:"IHDR",PLTE:"PLTE",IDAT:"IDAT",IEND:"IEND"},x=(e,t)=>{let n=new Uint8Array(12+t.length),r=new DataView(n.buffer);r.setUint32(0,t.length);for(let o=0;o<4;o++)n[4+o]=e.charCodeAt(o);return n.set(t,8),r.setUint32(8+t.length,M(n.subarray(4,8+t.length))),n},H=[137,80,78,71,13,10,26,10],d=(e,t=4)=>{if(!Number.isInteger(t)||t<1)throw new RangeError(`invalid scale: ${t} (expected a positive integer)`);let n=e.size*t,r=Math.ceil(n/4),o=new Uint8Array((1+r)*n);for(let c=0;c<n;c++){let u=c*(1+r)+1,b=Math.floor(c/t)*e.size;for(let a=0;a<n;a++){let P=e.grid[b+Math.floor(a/t)],p=u+(a>>2);o[p]=o[p]|P<<(3-(a&3))*2}}let s=new Uint8Array(13),f=new DataView(s.buffer);f.setUint32(0,n),f.setUint32(4,n),s[8]=2,s[9]=3,s[10]=0,s[11]=0,s[12]=0;let i=new Uint8Array([...e.bgcolor,...e.color,...e.spotcolor]),l=[new Uint8Array(H),x(g.IHDR,s),x(g.PLTE,i),x(g.IDAT,k(o)),x(g.IEND,new Uint8Array(0))],U=new Uint8Array(l.reduce((c,u)=>c+u.length,0)),y=0;for(let c of l)U.set(c,y),y+=c.length;return U},D=(e={})=>d((0,w.createIcon)(e),e.scale??4),h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",L=e=>{let t="";for(let n=0;n<e.length;n+=3){let r=e[n],o=e[n+1],s=e[n+2];t+=h[r>>2],t+=h[(r&3)<<4|(o??0)>>4],t+=o===void 0?"=":h[(o&15)<<2|(s??0)>>6],t+=s===void 0?"=":h[s&63]}return t},O=(e={})=>`data:image/png;base64,${L(D(e))}`;0&&(module.exports={iconToPng,toPng,toPngDataURL});
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 { IconOptions, IconData } from '@pixid/core';
2
-
3
- interface PngOptions extends IconOptions {
4
- /** Pixels per cell. Defaults to 4. */
5
- scale?: number;
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 { IconOptions, IconData } from '@pixid/core';
2
-
3
- interface PngOptions extends IconOptions {
4
- /** Pixels per cell. Defaults to 4. */
5
- scale?: number;
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 d}from"@pixid/core";var p=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)n=n&1?3988292384^n>>>1:n>>>1;p[e]=n>>>0}var D=e=>{let n=4294967295;for(let t=0;t<e.length;t++)n=p[(n^e[t])&255]^n>>>8;return(n^4294967295)>>>0},b=e=>{let n=1,t=0;for(let r=0;r<e.length;r++)n=(n+e[r])%65521,t=(t+n)%65521;return(t<<16|n)>>>0},P=e=>{let n=Math.max(1,Math.ceil(e.length/65535)),t=new Uint8Array(2+e.length+n*5+4),r=0;t[r++]=120,t[r++]=1;for(let s=0;s<n;s++){let f=s*65535,i=e.subarray(f,Math.min(f+65535,e.length)),l=s===n-1;t[r++]=l?1:0,t[r++]=i.length&255,t[r++]=i.length>>>8,t[r++]=~i.length&255,t[r++]=~i.length>>>8&255,t.set(i,r),r+=i.length}let o=b(e);return t[r++]=o>>>24&255,t[r++]=o>>>16&255,t[r++]=o>>>8&255,t[r]=o&255,t},g={IHDR:"IHDR",PLTE:"PLTE",IDAT:"IDAT",IEND:"IEND"},x=(e,n)=>{let t=new Uint8Array(12+n.length),r=new DataView(t.buffer);r.setUint32(0,n.length);for(let o=0;o<4;o++)t[4+o]=e.charCodeAt(o);return t.set(n,8),r.setUint32(8+n.length,D(t.subarray(4,8+n.length))),t},E=[137,80,78,71,13,10,26,10],R=(e,n=4)=>{if(!Number.isInteger(n)||n<1)throw new RangeError(`invalid scale: ${n} (expected a positive integer)`);let t=e.size*n,r=Math.ceil(t/4),o=new Uint8Array((1+r)*t);for(let c=0;c<t;c++){let u=c*(1+r)+1,w=Math.floor(c/n)*e.size;for(let a=0;a<t;a++){let I=e.grid[w+Math.floor(a/n)],y=u+(a>>2);o[y]=o[y]|I<<(3-(a&3))*2}}let s=new Uint8Array(13),f=new DataView(s.buffer);f.setUint32(0,t),f.setUint32(4,t),s[8]=2,s[9]=3,s[10]=0,s[11]=0,s[12]=0;let i=new Uint8Array([...e.bgcolor,...e.color,...e.spotcolor]),l=[new Uint8Array(E),x(g.IHDR,s),x(g.PLTE,i),x(g.IDAT,P(o)),x(g.IEND,new Uint8Array(0))],A=new Uint8Array(l.reduce((c,u)=>c+u.length,0)),U=0;for(let c of l)A.set(c,U),U+=c.length;return A},T=(e={})=>R(d(e),e.scale??4),h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",m=e=>{let n="";for(let t=0;t<e.length;t+=3){let r=e[t],o=e[t+1],s=e[t+2];n+=h[r>>2],n+=h[(r&3)<<4|(o??0)>>4],n+=o===void 0?"=":h[(o&15)<<2|(s??0)>>6],n+=s===void 0?"=":h[s&63]}return n},C=(e={})=>`data:image/png;base64,${m(T(e))}`;export{R as iconToPng,T as toPng,C as toPngDataURL};
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.1.1",
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
- "types": "./dist/index.d.ts",
31
- "import": "./dist/index.js",
32
- "require": "./dist/index.cjs"
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.1.1"
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": "tsup"
58
+ "build": "tsdown"
53
59
  }
54
60
  }