Paperjs Offset Core
A fork from the excellent work made in paperjs-offset (Thanks!). The difference is to be able to provide a PaperScope to the offsetting functionality in case you need to work with paper-core.js directly from paper/dist/paper-core. Current use case is when using paper-core.js and working with paperjs using javascript with a bundler included. Could perhaps also be useful when working with multiple paperjs scopes.
Other changes includes:
- Removed deprecated ExtendPaperJs functionality.
- Removed window global
Under development. Not tested for use in Node.js, only in browser.
Background from original paperjs-offset, 2016-2019
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.
Usage
Installation
npm install paperjs-offset-core
And then, in your project:
import paper from 'paper/dist/paper-core'
import { PaperOffset } from 'paperjs-offset'
let canvas = document.querySelector('canvas')
paper.setup(canvas)
paper.view.center = [0, 0]
const offsetOptions = {
scope: paper
}
let path = new paper.Path()
PaperOffset.offset(path, offset, offsetOptions)
PaperOffset.offsetStroke(path, offset, offsetOptions)
Sample references:
offset(path: paper.Path | paper.CompoundPath, offset: number, options?: OffsetOptions): paper.Path | paper.CompoundPath
offsetStroke(path: paper.Path | paper.CompoundPath, offset: number, options?: OffsetOptions): paper.Path | paper.CompoundPath
interface OffsetOptions {
join?: 'miter' | 'bevel' | 'round';
cap?: 'butt' | 'round';
limit?: number;
insert?: boolean;
scope: paper.PaperScope
}
Preview
You can use open demo folder for simple cases demonstration.
License
Distributed under the MIT license.