Skip to content

Commit d0c0515

Browse files
committed
remove xml helpers from standard import
1 parent 1f5adc8 commit d0c0515

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ const options = {
8383
If you need to edit the output svg for your use case, blobs also allows for _editable_ output.
8484

8585
```typescript
86-
import * as blobs from "blobs";
87-
8886
const editableSvg = blobs.editable(options);
8987
```
9088

@@ -95,6 +93,17 @@ editableSvg.attributes.width = 1000;
9593
const svg = editableSvg.render();
9694
```
9795

96+
Utilities to create nodes in the editable output can be imported from `blobs/editable`.
97+
98+
```typescript
99+
import {xml} from "blobs/editable";
100+
101+
const xmlChild = xml("path");
102+
xmlChild.attributes.stroke = "red";
103+
// ...
104+
editableSvg.children.push(xmlChild);
105+
```
106+
98107
## License
99108

100109
[MIT](./LICENSE)
File renamed without changes.
File renamed without changes.

index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Point} from "./internal/math/geometry";
55
import {rad} from "./internal/math/unit";
66
import {smooth} from "./internal/svg/smooth";
77
import {renderEditable} from "./internal/svg/render";
8-
import {XmlElement} from "./internal/xml";
8+
import {XmlElement} from "./editable";
99

1010
export interface BlobOptions {
1111
// Bounding box dimensions.
@@ -37,12 +37,16 @@ export interface BlobOptions {
3737

3838
// Generates an svg document string containing a randomized rounded shape.
3939
const blobs = (opt: BlobOptions): string => {
40-
return editable(opt).render();
40+
return blobs.editable(opt).render();
4141
};
4242

4343
// Generates an editable data structure which can be rendered to an svg document
4444
// containing a randomized rounded shape.
45-
export const editable = (opt: BlobOptions): XmlElement => {
45+
blobs.editable = (opt: BlobOptions): XmlElement => {
46+
if (!opt) {
47+
throw new Error("no options specified");
48+
}
49+
4650
// Random number generator.
4751
const rgen = rand(opt.seed || String(Date.now()));
4852

@@ -94,4 +98,3 @@ export const editable = (opt: BlobOptions): XmlElement => {
9498
};
9599

96100
export default blobs;
97-
export {IXml, XmlElement} from "./internal/xml";

internal/svg/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {loopAccess} from "./util";
22
import {Point, interpolate} from "./point";
3-
import {xml, XmlElement} from "../xml";
3+
import {xml, XmlElement} from "../../editable";
44

55
export interface RenderOptions {
66
// Viewport size.

testing/blobs.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import blobs, {BlobOptions, editable} from "..";
1+
import blobs, {BlobOptions} from "..";
22

33
const genMinimalOptions = (): BlobOptions => ({
44
size: 1000 * Math.random(),
@@ -27,6 +27,10 @@ describe("blobs", () => {
2727
expect(a).toEqual(b);
2828
});
2929

30+
it("should require options be provided", () => {
31+
expect(() => (blobs as any)()).toThrow("options");
32+
});
33+
3034
it("should require a size be provided", () => {
3135
const options = genMinimalOptions();
3236

@@ -68,7 +72,7 @@ describe("editable", () => {
6872
it("should reflect changes when edited", () => {
6973
const options = genMinimalOptions();
7074

71-
const out = editable(options);
75+
const out = blobs.editable(options);
7276
const initial = out.render();
7377
out.attributes.id = "test";
7478
const modified = out.render();

0 commit comments

Comments
 (0)