Skip to content

Commit 73eec58

Browse files
committed
add v2 documentation
1 parent 8c19dc8 commit 73eec58

File tree

5 files changed

+150
-43
lines changed

5 files changed

+150
-43
lines changed

CHANGELOG.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
# 1.1.0
22

3-
- Add support for editable output
3+
- Add support for editable output
44

55
# 1.0.5
66

7-
- Fix assets in README on npmjs.com
7+
- Fix assets in README on npmjs.com
88

99
# 1.0.4
1010

11-
- Use snapshot tests to verify consistency
12-
- Ignore unnecessary files in npm tarball
13-
- Output sourcemap file
14-
- Add project logo
15-
- README content updates
11+
- Use snapshot tests to verify consistency
12+
- Ignore unnecessary files in npm tarball
13+
- Output sourcemap file
14+
- Add project logo
15+
- README content updates
1616

1717
# 1.0.3
1818

19-
- Add link to demo page in the README
19+
- Add link to demo page in the README
2020

2121
# 1.0.2
2222

23-
- Make transpiled output minified
24-
- Minor changes to the README
23+
- Make transpiled output minified
24+
- Minor changes to the README
2525

2626
# 1.0.1
2727

28-
- Remove accidental dependency
29-
- Minor changes to the README
28+
- Remove accidental dependency
29+
- Minor changes to the README
3030

3131
# 1.0.0
3232

33-
- Initial release
33+
- Initial release

README.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<!--
22
33
TODO rewrite v1 docs in separate doc
4-
TODO update docs for v2
54
65
-->
76

@@ -46,23 +45,22 @@ _Options are **not** [sanitized](https://en.wikipedia.org/wiki/HTML_sanitization
4645

4746
#### Required
4847

49-
Name | Type | Description
50-
-------------- | ---------- | ---------------------------------------------
51-
`size` | `number` | Bounding box dimensions (in pixels)
52-
`complexity` | `number` | Blob complexity (number of points)
53-
`contrast` | `number` | Blob contrast (randomness of point position)
54-
48+
| Name | Type | Description |
49+
| ------------ | -------- | -------------------------------------------- |
50+
| `size` | `number` | Bounding box dimensions (in pixels) |
51+
| `complexity` | `number` | Blob complexity (number of points) |
52+
| `contrast` | `number` | Blob contrast (randomness of point position) |
5553

5654
#### Optional
5755

58-
Name | Type | Default | Description
59-
-------------- | ---------- | ---------- | -------------------------------------
60-
`color` | `string?` | `"none"` | Fill color
61-
`stroke` | `object?` | `...` | Stroke options
62-
`stroke.color` | `string` | `"none"` | Stroke color
63-
`stroke.width` | `number` | `0` | Stroke width (in pixels)
64-
`seed` | `string?` | _`random`_ | Value to seed random number generator
65-
`guides` | `boolean?` | `false` | Render points, handles and stroke
56+
| Name | Type | Default | Description |
57+
| -------------- | ---------- | ---------- | ------------------------------------- |
58+
| `color` | `string?` | `"none"` | Fill color |
59+
| `stroke` | `object?` | `...` | Stroke options |
60+
| `stroke.color` | `string` | `"none"` | Stroke color |
61+
| `stroke.width` | `number` | `0` | Stroke width (in pixels) |
62+
| `seed` | `string?` | _`random`_ | Value to seed random number generator |
63+
| `guides` | `boolean?` | `false` | Render points, handles and stroke |
6664

6765
_Either `stroke` or `color` must be defined._
6866

@@ -72,16 +70,16 @@ _Guides will use stroke color and width if defined. Otherwise, they default to `
7270

7371
```typescript
7472
const options = {
75-
size: 600,
76-
complexity: 0.2,
77-
contrast: 0.4,
78-
color: "#ec576b",
79-
stroke: {
80-
width: 0,
81-
color: "black",
82-
},
83-
guides: false,
84-
seed: "1234",
73+
size: 600,
74+
complexity: 0.2,
75+
contrast: 0.4,
76+
color: "#ec576b",
77+
stroke: {
78+
width: 0,
79+
color: "black",
80+
},
81+
guides: false,
82+
seed: "1234",
8583
};
8684
```
8785

README.v2.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<a href="https://blobs.dev">
2+
<img align="left" width="360" height="300" src="./assets/logo-color.svg?sanitize=true">
3+
</a>
4+
5+
<br>
6+
<br>
7+
8+
[![](https://img.shields.io/npm/v/blobs.svg)](https://www.npmjs.com/package/blobs)
9+
10+
```ts
11+
// $ npm install blobs
12+
import * as blobs2 from "blobs/v2";
13+
```
14+
15+
```html
16+
<script src="https://unpkg.com/blobs/v2"></script>
17+
```
18+
19+
<br>
20+
<br>
21+
<br>
22+
<br>
23+
24+
## SVG Path
25+
26+
```js
27+
const svgPath = blobs2.svg({
28+
seed: Date.now(),
29+
extraPoints: 8,
30+
randomness: 4,
31+
size: 256,
32+
});
33+
doSomething(svgPath);
34+
```
35+
36+
## SVG
37+
38+
```js
39+
const svgString = blobs2.svg(
40+
{
41+
seed: Date.now(),
42+
extraPoints: 8,
43+
randomness: 4,
44+
size: 256,
45+
},
46+
{
47+
fill: "white", // 🚨 NOT SANITIZED
48+
stroke: "black", // 🚨 NOT SANITIZED
49+
strokeWidth: 4,
50+
},
51+
);
52+
container.innerHTML = svgString;
53+
```
54+
55+
## Canvas
56+
57+
```js
58+
const path = blobs2.canvas(
59+
{
60+
seed: Date.now(),
61+
extraPoints: 16,
62+
randomness: 2,
63+
size: 128,
64+
},
65+
{
66+
offsetX: 16,
67+
offsetY: 32,
68+
},
69+
);
70+
ctx.stroke(path);
71+
```
72+
73+
## Complete API
74+
75+
```ts
76+
export interface BlobOptions {
77+
// A given seed will always produce the same blob.
78+
// Use `Date.now()` for pseudorandom behavior.
79+
seed: string | number;
80+
// Actual number of points will be `3 + extraPoints`.
81+
extraPoints: number;
82+
// Increases the amount of variation in point position.
83+
randomness: number;
84+
// Size of bounding box.
85+
size: number;
86+
}
87+
export interface CanvasOptions {
88+
// Coordinates of top-left corner of blob.
89+
offsetX?: number;
90+
offsetY?: number;
91+
}
92+
export interface SvgOptions {
93+
fill?: string; // Default: "#ec576b".
94+
stroke?: string; // Default: "none".
95+
strokeWidth?: number; // Default: 0.
96+
}
97+
export const canvas: (blobOptions: BlobOptions, canvasOptions?: CanvasOptions) => Path2D;
98+
export const svg: (blobOptions: BlobOptions, svgOptions?: SvgOptions) => string;
99+
export const svgPath: (blobOptions: BlobOptions) => string;
100+
```
101+
102+
## License
103+
104+
[MIT](./LICENSE)
105+
106+
<p align="center">
107+
<br><br>
108+
<img width="100" src="./assets/logo-grey.svg?sanitize=true" />
109+
</p>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"postpublish": "npm run clean",
1212
"build": "npm run clean && rollup -c rollup.config.js",
1313
"clean": "trash '**/*.js' '**/*.js.map' '**/*.d.ts' '!**/node_modules/**/*' '!rollup.config.js'",
14-
"fmt": "prettier --list-different --write --ignore-path .gitignore '**/*.{js,ts}'",
14+
"fmt": "prettier --list-different --write --ignore-path .gitignore '**/*.{js,ts,md}'",
1515
"anim": "parcel internal/animate/testing/index.html --open",
1616
"test": "jest"
1717
},

public/blobs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const typeCheck = (name: string, val: any, expected: string[]) => {
3030
}
3131
};
3232

33-
export const raw = (blobOptions: BlobOptions): Point[] => {
33+
const raw = (blobOptions: BlobOptions): Point[] => {
3434
const rgen = rand(String(blobOptions.seed));
3535

3636
typeCheck("seed", blobOptions.seed, ["string", "number"]);
@@ -63,7 +63,7 @@ export const raw = (blobOptions: BlobOptions): Point[] => {
6363
});
6464
};
6565

66-
export const canvas = (blobOptions: BlobOptions, canvasOptions: CanvasOptions): Path2D => {
66+
export const canvas = (blobOptions: BlobOptions, canvasOptions: CanvasOptions = {}): Path2D => {
6767
return renderPath2D(
6868
mapPoints(raw(blobOptions), ({curr}) => {
6969
curr.x += canvasOptions.offsetX || 0;
@@ -73,12 +73,12 @@ export const canvas = (blobOptions: BlobOptions, canvasOptions: CanvasOptions):
7373
);
7474
};
7575

76-
export const svg = (blobOptions: BlobOptions, svgOptions: SvgOptions): string => {
76+
export const svg = (blobOptions: BlobOptions, svgOptions: SvgOptions = {}): string => {
7777
const path = svgPath(blobOptions);
7878
const size = Math.floor(blobOptions.size);
7979
const fill = svgOptions.fill === undefined ? "#ec576b" : svgOptions.fill;
8080
const stroke = svgOptions.stroke === undefined ? "none" : svgOptions.stroke;
81-
const strokeWidth = svgOptions.strokeWidth === undefined ? 1 : svgOptions.strokeWidth;
81+
const strokeWidth = svgOptions.strokeWidth === undefined ? 0 : svgOptions.strokeWidth;
8282
return `
8383
<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}" xmlns="http://www.w3.org/2000/svg">
8484
<path stroke="${stroke}" stroke-width="${strokeWidth}" fill="${fill}" d="${path}"/>

0 commit comments

Comments
 (0)