From 4b34c9e2f1adb059db5edbaabb9417e62eca74e9 Mon Sep 17 00:00:00 2001 From: mathieudutour Date: Wed, 5 Sep 2018 14:52:11 -0400 Subject: [PATCH] fix for Sketch 52 --- src/my-command.js | 14 +++++++++----- src/roughjs.js | 14 ++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/my-command.js b/src/my-command.js index 80f6941..51fb365 100644 --- a/src/my-command.js +++ b/src/my-command.js @@ -13,7 +13,7 @@ function getOptionsFromLayer(layer) { let options = {} const fill = (layer.style.fills || []).filter( - f => f.sketchObject.isEnabled() && f.fill === 'Color' + f => f.sketchObject.isEnabled() && f.fill === sketch.Style.FillType.Color )[0] if (fill) { @@ -21,7 +21,7 @@ function getOptionsFromLayer(layer) { } const border = (layer.style.borders || []).filter( - f => f.sketchObject.isEnabled() && f.fillType === 'Color' + f => f.sketchObject.isEnabled() && f.fillType === sketch.Style.FillType.Color )[0] if (border) { @@ -44,11 +44,15 @@ export default function(context) { } selection.forEach(layer => { - if (layer.type !== 'Shape') { + if (!layer.sketchObject.pathInFrameWithTransforms) { return } - const rc = new RoughSketch(layer.parent) + // override the wrapper to have a proper object + layer = sketch.Shape.fromNative(layer.sketchObject) + + const rc = new RoughSketch(layer.parent.type === 'Page' ? layer : layer.parent) + const newLayer = rc.path( getPathFromLayer(layer), getOptionsFromLayer(layer) @@ -62,8 +66,8 @@ export default function(context) { // hide previous layer layer.hidden = true layer.selected = false - // select new one + // select new one newLayer.selected = true }) } diff --git a/src/roughjs.js b/src/roughjs.js index 1d4aa5a..be94d75 100644 --- a/src/roughjs.js +++ b/src/roughjs.js @@ -1,9 +1,11 @@ import { RoughGenerator } from 'roughjs/src/generator' // we hook into the internals to write the wrapper ourselves import sketch from 'sketch' +const shapeFromPath = MSShapeGroup.shapeWithBezierPath || MSShapeGroup.layerWithPath + export class RoughSketch { constructor(layer, config) { - this.layer = sketch.fromNative(layer); + this.layer = layer; this._init(config); } @@ -79,7 +81,7 @@ export class RoughSketch { switch (drawing.type) { case 'path': { let closed = MOPointer.alloc().init() - path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath( + path = sketch.Shape.fromNative(shapeFromPath( MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed( this._opsToPath(drawing), closed @@ -95,7 +97,7 @@ export class RoughSketch { } case 'fillPath': { let closed = MOPointer.alloc().init() - path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath( + path = sketch.Shape.fromNative(shapeFromPath( MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed( this._opsToPath(drawing), closed @@ -113,7 +115,7 @@ export class RoughSketch { } case 'path2Dfill': { let closed = MOPointer.alloc().init() - path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath( + path = sketch.Shape.fromNative(shapeFromPath( MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed( drawing.path, closed @@ -136,7 +138,7 @@ export class RoughSketch { }) let closed = MOPointer.alloc().init() - const mask = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath( + const mask = sketch.Shape.fromNative(shapeFromPath( MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed( drawing.path, closed @@ -176,7 +178,7 @@ export class RoughSketch { fweight = o.strokeWidth / 2; } let closed = MOPointer.alloc().init() - let path = sketch.Shape.fromNative(MSShapeGroup.shapeWithBezierPath( + let path = sketch.Shape.fromNative(shapeFromPath( MSPath.pathWithBezierPath(SVGPathInterpreter.bezierPathFromCommands_isPathClosed( this._opsToPath(drawing), closed