-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpath2d.patch.js
More file actions
35 lines (29 loc) · 740 Bytes
/
path2d.patch.js
File metadata and controls
35 lines (29 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {path} from "d3-path";
import {names} from './path-operation-names.js';
if (typeof Path2D !== 'undefined' && typeof window !== 'undefined') {
patchPath2D(window, Path2D);
}
export function patchPath2D(scope, Path2D) {
if (Path2D.prototype.toSvgString) {
// no need to patch
return;
}
/**
* Use d3-path to mock a svg path string builder.
*/
class Path2DDelegate extends Path2D {
_path
constructor(p) {
super(p);
this._path = path()
}
}
scope.Path2D = Path2DDelegate;
names.forEach(name => {
const pOrigin = Path2D.prototype[name];
Path2DDelegate.prototype[name] = function () {
pOrigin.apply(this, arguments)
this._path[name](...arguments);
}
})
}