Skip to content

Commit c02571f

Browse files
committed
expose XmlElement interface in v1 + rename canvas api in v2
1 parent 4bcfdb3 commit c02571f

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

README.legacy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ editableSvg.attributes.width = 1000;
7676
const svg = editableSvg.render();
7777
```
7878

79-
Utilities to create nodes in the editable output can be imported from `blobs/editable`.
79+
New elements can be added anywhere in the hierarchy.
8080

8181
```typescript
8282
const xmlChild = blobs.xml("path");

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<a href="https://github.com/g-harel/blobs/README.legacy.md"><b>Legacy documentation</b></a>
2+
<a href="https://github.com/g-harel/blobs/blob/master/README.legacy.md"><b>Legacy documentation</b></a>
33
</p>
44

55
<br>
@@ -61,7 +61,7 @@ container.innerHTML = svgString;
6161
## Canvas
6262

6363
```js
64-
const path = blobs2.canvas(
64+
const path = blobs2.canvasPath(
6565
{
6666
seed: Date.now(),
6767
extraPoints: 16,
@@ -100,7 +100,7 @@ export interface SvgOptions {
100100
stroke?: string; // Default: "none".
101101
strokeWidth?: number; // Default: 0.
102102
}
103-
export const canvas: (blobOptions: BlobOptions, canvasOptions?: CanvasOptions) => Path2D;
103+
export const canvasPath: (blobOptions: BlobOptions, canvasOptions?: CanvasOptions) => Path2D;
104104
export const svg: (blobOptions: BlobOptions, svgOptions?: SvgOptions) => string;
105105
export const svgPath: (blobOptions: BlobOptions) => string;
106106
```

internal/animate/testing/script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const testGen = () => {
180180
for (let j = 0; j < cellSideCount; j++) {
181181
ctx.strokeRect(i * cellSize, j * cellSize, cellSize, cellSize);
182182
ctx.fill(
183-
blobs2.canvas(
183+
blobs2.canvasPath(
184184
{
185185
extraPoints: j,
186186
randomness: i,

public/blobs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const raw = (blobOptions: BlobOptions): Point[] => {
6363
});
6464
};
6565

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

public/legacy.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {rand} from "../internal/rand";
2-
import {renderEditable, XmlElement} from "../internal/render/svg";
2+
import {renderEditable, XmlElement as InternalXmlElement} from "../internal/render/svg";
33
import {genBlob} from "../internal/gen";
44
import {mapPoints} from "../internal/util";
55

@@ -100,7 +100,14 @@ blobs.editable = (options: BlobOptions): XmlElement => {
100100
});
101101
};
102102

103+
export interface XmlElement {
104+
tag: string;
105+
attributes: Record<string, string | number>;
106+
children: XmlElement[];
107+
render(): string;
108+
}
109+
103110
// Shortcut to create an XmlElement without "new";
104-
blobs.xml = (tag: string) => new XmlElement(tag);
111+
blobs.xml = (tag: string): XmlElement => new InternalXmlElement(tag);
105112

106113
export default blobs;

0 commit comments

Comments
 (0)