Skip to content

Commit b5b92e6

Browse files
committedJan 12, 2025
Updates
1 parent d673b15 commit b5b92e6

12 files changed

+244
-34
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ lerna-debug.log*
1111
package-lock.json
1212
yarn.lock
1313
pnpm-lock.yaml
14+
bun.lockb
1415

1516
node_modules
1617
dist

‎demos/bun/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ bower_components
4646

4747
.lock-wscript
4848

49+
# Lock files
50+
package-lock.json
51+
bun.lockb
52+
*.lock
53+
4954
# Compiled binary addons (https://nodejs.org/api/addons.html)
5055

5156
build/Release

‎demos/bun/index.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import { bloImage } from "@blockchainhub/blo";
22

33
const SQUARE_WIDTH = 3;
44

5+
const paletteKeys = ["background", "primary", "accent"] as const;
6+
57
function renderImage([data, palette]: ReturnType<typeof bloImage>) {
68
let output = "";
79
const currentLine: string[] = [];
810

911
for (let i = 0; i < data.length; i++) {
1012
const color = hsl2rgb(
11-
palette[data[i]][0],
12-
palette[data[i]][1] / 100,
13-
palette[data[i]][2] / 100,
13+
palette[paletteKeys[data[i]]][0],
14+
palette[paletteKeys[data[i]]][1] / 100,
15+
palette[paletteKeys[data[i]]][2] / 100,
1416
);
1517

1618
const [r, g, b] = color.map((c) => Math.floor(c * 255));
@@ -28,7 +30,7 @@ function renderImage([data, palette]: ReturnType<typeof bloImage>) {
2830
return output;
2931
}
3032

31-
function renderIcon(address: `0x${string}`) {
33+
function renderIcon(address: string) {
3234
console.log(
3335
renderImage(bloImage(address)),
3436
`\n${address}`,

‎demos/node/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ web_modules/
107107
.cache
108108
.parcel-cache
109109

110+
# Lock files
111+
package-lock.json
112+
bun.lockb
113+
*.lock
114+
110115
# Next.js build output
111116

112117
.next

‎demos/node/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { bloImage } from "@blockchainhub/blo";
22

33
const SQUARE_WIDTH = 3;
4+
const paletteKeys = ["background", "primary", "accent"];
45

56
function renderImage([data, palette]) {
67
let output = "";
78
const currentLine = [];
89

910
for (let i = 0; i < data.length; i++) {
1011
const color = hsl2rgb(
11-
palette[data[i]][0],
12-
palette[data[i]][1] / 100,
13-
palette[data[i]][2] / 100,
12+
palette[paletteKeys[data[i]]][0],
13+
palette[paletteKeys[data[i]]][1] / 100,
14+
palette[paletteKeys[data[i]]][2] / 100,
1415
);
1516

1617
const [r, g, b] = color.map((c) => Math.floor(c * 255));

‎demos/react/.gitignore

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
15+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
16+
17+
# Runtime data
18+
19+
pids
20+
_.pid
21+
_.seed
22+
\*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
26+
lib-cov
27+
28+
# Coverage directory used by tools like istanbul
29+
30+
coverage
31+
\*.lcov
32+
33+
# nyc test coverage
34+
35+
.nyc_output
36+
37+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
38+
39+
.grunt
40+
41+
# Bower dependency directory (https://bower.io/)
42+
43+
bower_components
44+
45+
# node-waf configuration
46+
47+
.lock-wscript
48+
49+
# Compiled binary addons (https://nodejs.org/api/addons.html)
50+
51+
build/Release
52+
53+
# Dependency directories
54+
55+
node_modules/
56+
jspm_packages/
57+
58+
# Snowpack dependency directory (https://snowpack.dev/)
59+
60+
web_modules/
61+
62+
# TypeScript cache
63+
64+
\*.tsbuildinfo
65+
66+
# Optional npm cache directory
67+
68+
.npm
69+
70+
# Optional eslint cache
71+
72+
.eslintcache
73+
74+
# Optional stylelint cache
75+
76+
.stylelintcache
77+
78+
# Microbundle cache
79+
80+
.rpt2_cache/
81+
.rts2_cache_cjs/
82+
.rts2_cache_es/
83+
.rts2_cache_umd/
84+
85+
# Optional REPL history
86+
87+
.node_repl_history
88+
89+
# Output of 'npm pack'
90+
91+
\*.tgz
92+
93+
# Yarn Integrity file
94+
95+
.yarn-integrity
96+
97+
# dotenv environment variable files
98+
99+
.env
100+
.env.development.local
101+
.env.test.local
102+
.env.production.local
103+
.env.local
104+
105+
# parcel-bundler cache (https://parceljs.org/)
106+
107+
.cache
108+
.parcel-cache
109+
110+
# Lock files
111+
package-lock.json
112+
bun.lockb
113+
*.lock
114+
115+
# Next.js build output
116+
117+
.next
118+
out
119+
120+
# Nuxt.js build / generate output
121+
122+
.nuxt
123+
dist
124+
125+
# Gatsby files
126+
127+
.cache/
128+
129+
# Comment in the public line in if your project uses Gatsby and not Next.js
130+
131+
# https://nextjs.org/blog/next-9-1#public-directory-support
132+
133+
# public
134+
135+
# vuepress build output
136+
137+
.vuepress/dist
138+
139+
# vuepress v2.x temp and cache directory
140+
141+
.temp
142+
.cache
143+
144+
# Docusaurus cache and generated files
145+
146+
.docusaurus
147+
148+
# Serverless directories
149+
150+
.serverless/
151+
152+
# FuseBox cache
153+
154+
.fusebox/
155+
156+
# DynamoDB Local files
157+
158+
.dynamodb/
159+
160+
# TernJS port file
161+
162+
.tern-port
163+
164+
# Stores VSCode versions used for testing VSCode extensions
165+
166+
.vscode-test
167+
168+
# yarn v2
169+
170+
.yarn/cache
171+
.yarn/unplugged
172+
.yarn/build-state.yml
173+
.yarn/install-state.gz
174+
.pnp.\*
175+
176+
# IntelliJ based IDEs
177+
.idea

‎demos/react/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"jsx": "react-jsx"
4+
"jsx": "react-jsx",
5+
"types": ["react", "react-dom"]
56
},
67
"include": [".", ".."]
78
}

‎src/image.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Address, BloImage, BloImageData, Hsl, PaletteIndex } from "./types";
1+
import type { Address, BloImage, BloImageData, Hsl, Palette, PaletteIndex } from "./types";
22

33
import { seedRandom } from "./random";
44

@@ -28,12 +28,12 @@ export function randomImageData(random: () => number): BloImageData {
2828
return data;
2929
}
3030

31-
export function randomPalette(random: () => number): [Hsl, Hsl, Hsl] {
31+
export function randomPalette(random: () => number): Palette {
3232
// calls order is significant
33-
const c = randomColor(random);
34-
const b = randomColor(random);
35-
const s = randomColor(random);
36-
return [b, c, s];
33+
const primary = randomColor(random);
34+
const background = randomColor(random);
35+
const accent = randomColor(random);
36+
return { background, primary, accent };
3737
}
3838

3939
export function randomColor(rand: () => number): Hsl {

‎src/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ export type {
1212
PaletteIndex,
1313
} from "./types";
1414

15-
export function blo(address: Address, size: number = 64): string {
16-
return "data:image/svg+xml;base64," + btoa(bloSvg(address, size));
15+
export function blo(address: Address, uppercase: boolean = true, size: number = 64): string {
16+
return "data:image/svg+xml;base64," + btoa(bloSvg(address, uppercase, size));
1717
}
1818

19-
export function bloSvg(address: Address, size: number = 64): string {
20-
return svg(address, size);
19+
export function bloSvg(address: Address, uppercase: boolean = true, size: number = 64): string {
20+
const processedAddress = uppercase ? address.toUpperCase() : address;
21+
return svg(processedAddress, size);
2122
}
2223

23-
export function bloImage(address: Address): BloImage {
24-
return image(address);
24+
export function bloImage(address: Address, uppercase: boolean = true): BloImage {
25+
const processedAddress = uppercase ? address.toUpperCase() : address;
26+
return image(processedAddress);
2527
}

‎src/svg.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const SVG_START = `<svg `
1010

1111
export function svg(address: Address, size: number) {
1212
const random = seedRandom(address.toLowerCase());
13-
14-
const [b, c, s] = randomPalette(random);
13+
const { background: b, primary: c, accent: s } = randomPalette(random);
1514

1615
const paths = [
1716
`M0,0H8V8H0z`, // background

‎src/types.ts

+29-11
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ export type BloImage = [BloImageData, Palette];
66
export type BloImageData = Uint8Array;
77

88
// Colors used by a given icon.
9-
export type Palette = [
10-
Hsl, // background
11-
Hsl, // color
12-
Hsl, // spot
13-
];
14-
15-
// Points to one of the three Palette colors.
16-
export type PaletteIndex =
17-
| 0 // background
18-
| 1 // color
19-
| 2; // spot
9+
export type Palette = {
10+
background: Hsl;
11+
primary: Hsl;
12+
accent: Hsl;
13+
};
14+
15+
// Or using const for better type inference
16+
export const PaletteIndexes = {
17+
BACKGROUND: 0,
18+
PRIMARY: 1,
19+
ACCENT: 2,
20+
} as const;
21+
export type PaletteIndex = typeof PaletteIndexes[keyof typeof PaletteIndexes];
2022

2123
// A color in the HSL color space.
2224
// [0]: 0-360 (hue)
@@ -26,3 +28,19 @@ export type Hsl = Uint16Array;
2628

2729
// An Ethereum address.
2830
export type Address = string;
31+
32+
// Add size constraints
33+
export type ValidSize = number;
34+
// Or more strictly:
35+
// export type ValidSize = 16 | 32 | 64 | 128 | 256;
36+
37+
// Function signatures with improved type safety
38+
export type BloFunction = (address: Address, uppercase?: boolean, size?: ValidSize) => string;
39+
export type BloSvgFunction = (address: Address, uppercase?: boolean, size?: ValidSize) => string;
40+
export type BloImageFunction = (address: Address, uppercase?: boolean) => BloImage;
41+
42+
export type HslValues = {
43+
hue: number; // 0-360
44+
saturation: number; // 0-100
45+
lightness: number; // 0-100
46+
};

‎src/vite-env.d.ts

-1
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.