The dicussion to implement a offset function in paper.js started years ago, yet the author have not decided to put a offset feature into the library. So I implement an extension of my own.
As far as I know, the author has promised recently to implement a native offset functionality in near feature, the library will be closed once the native implement is published.
This library implement both path offset and stroke offset, you may offset a path or expand a stroke like what you did in Adobe illustrator. Offset complicate path may cause unwanted self intersections, this library already take care some cases but bugs still exists. Please let me notice the false conditions in the issue pannel so I can correct it.
For node development, use
npm install paperjs-offset
And then, in you project:
// call offsetPaperOffset // call offset strokePaperOffset
You may still use the old way to extend paperjs module, which is deprecated and will be removed in future version.
// extend paper.Path, paper.CompoundPath with offset, offsetStroke methodExtendPaperJspaper; // Warning: The library no longer include extended definitions for paper.Path & paper.CompoundPath, you may need your own declarations to use extension in typescript.path as any.offset10;
Or for web development, include the paperjs-offset.js or paperjs-offset.min.js in demo folder.
The library now exposes a global variable PaperOffset, again, the extension of paper.Path and paper.CompoundPath with offset/offsetStroke functions is still available, but no longer recommended.
let path = /* params */ PaperOffsetPaperOffset // deprecatedpath// deprecatedpath
offsetpath: paper.Path | paper.CompoundPath, offset: number, options?: OffsetOptions: paper.Path | paper.CompoundPath offsetStrokepath: paper.Path | paper.CompoundPath, offset: number, options?: OffsetOptions: paper.Path | paper.CompoundPath
There are some cases that the library may return weird result or failed silently, please let me noticed in the project issues. And in some cases the library will yeild an ok result than a perfect one. Currently the library should give good results for closed shapes, but may fail in some open curve cases, I'm still working on it.
You can use open demo folder for simple cases demonstration.
Distributed under the MIT license. See LICENSE for detail.