The Javascript Clipper library performs clipping and offsetting for both lines and polygons. All four boolean clipping operations are supported - intersection, union, difference and exclusive-or. Polygons can be of any shape including self-intersecting polygons.
Javascript Clipper is a port of Angus Johnson's Clipper library: https://sourceforge.net/projects/polyclipping
LIVE DEMO: http://jsclipper.sourceforge.net/6.4.2.2/main_demo.html
LIVE DEMO...