Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
* Added dispose instance method
* Updated the reverse method to not return an absolute array
* Version bump
  • Loading branch information
thednp committed Oct 19, 2024
1 parent 1820546 commit b130acc
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 40 deletions.
2 changes: 1 addition & 1 deletion dist/svg-path-commander.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/svg-path-commander.cjs.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/svg-path-commander.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,13 @@ declare class SVGPathCommander {
* @return the path string
*/
toString(): string;
/**
* Remove the instance.
*
* @public
* @return void
*/
dispose(): void;
}

declare namespace arcTools {
Expand Down
2 changes: 1 addition & 1 deletion dist/svg-path-commander.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/svg-path-commander.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion dist/svg-path-commander.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,6 @@ class A {
* @public
*/
reverse(t) {
this.toAbsolute();
const { segments: s } = this, r = Yt(s), n = r.length > 1 ? r : !1, i = n ? n.map((l, c) => t ? c ? ft(l) : l.slice(0) : ft(l)) : s.slice(0);
let o = [];
return n ? o = i.flat(1) : o = t ? s : ft(s), this.segments = o.slice(0), this;
Expand Down Expand Up @@ -1747,6 +1746,15 @@ class A {
toString() {
return kt(this.segments, this.round);
}
/**
* Remove the instance.
*
* @public
* @return void
*/
dispose() {
Object.keys(this).forEach((t) => delete this[t]);
}
}
d(A, "CSSMatrix", T), d(A, "pathToAbsolute", ht), d(A, "pathToRelative", Kt), d(A, "pathToCurve", yt), d(A, "pathToString", kt), d(A, "arcTools", Be), d(A, "bezierTools", {
Cvalues: Ae,
Expand Down
2 changes: 1 addition & 1 deletion dist/svg-path-commander.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/svg-path-commander.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/svg-path-commander.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "svg-path-commander",
"author": "thednp",
"license": "MIT",
"version": "2.1.3",
"version": "2.1.4",
"description": "Modern TypeScript tools for SVG",
"source": "./src/index.ts",
"main": "./dist/svg-path-commander.js",
Expand Down
54 changes: 27 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ class SVGPathCommander {
* @public
*/
reverse(onlySubpath?: boolean) {
this.toAbsolute();

const { segments } = this;
const split = splitPath(segments);
const subPath = split.length > 1 ? split : false;
Expand Down Expand Up @@ -449,6 +447,16 @@ class SVGPathCommander {
toString() {
return pathToString(this.segments, this.round);
}

/**
* Remove the instance.
*
* @public
* @return void
*/
dispose() {
Object.keys(this).forEach(key => delete this[key as keyof typeof this]);
}
}

export default SVGPathCommander;
16 changes: 14 additions & 2 deletions test/class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ a1.63 1.63 0 0 0 -0.906 0.274a1.63 1.63 0 0 0 -0.601 0.73a1.63 1.63 0 0 0 -0.094
expect(path.getAttribute('d')).to.equal(rect.toString())
});

it('Test dispose', async () => {
const path = new SVGPathCommander(`M 2 0 a2 2 0 00-2 2`);
expect(path.segments.length).to.equal(2);
expect(path.origin).to.deep.equal([0, 0, 0]);
expect(path.round).to.equal(4);

path.dispose();
expect(path.segments).to.be.undefined;
expect(path.origin).to.be.undefined;
expect(path.round).to.be.undefined;
});

it('Test overloaded moveTo', async () => {
const container = getMarkup();
wrapper.append(container);
Expand Down Expand Up @@ -300,7 +312,7 @@ a1.63 1.63 0 0 0 -0.906 0.274a1.63 1.63 0 0 0 -0.601 0.73a1.63 1.63 0 0 0 -0.094
const rect1 = new SVGPathCommander('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2z').reverse(true);

path.setAttribute('d', rect1.toString());
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2V14A2 2 0 0 0 2 16H14A2 2 0 0 0 16 14V2A2 2 0 0 0 14 0H2Z')
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2z')
});

it('Test reverse composite', async () => {
Expand All @@ -322,7 +334,7 @@ a1.63 1.63 0 0 0 -0.906 0.274a1.63 1.63 0 0 0 -0.601 0.73a1.63 1.63 0 0 0 -0.094

const rect = new SVGPathCommander('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2zM4 4h8l-4 8z').reverse(true);
path.setAttribute('d', rect.toString());
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2V14A2 2 0 0 0 2 16H14A2 2 0 0 0 16 14V2A2 2 0 0 0 14 0H2ZM8 12L12 4H4Z')
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2zM8 12L12 4H4Z')
});

it('Test flipX', () => {
Expand Down

0 comments on commit b130acc

Please sign in to comment.