From 572b60ec6ed9fced0f5584c0433d04c446aeac8a Mon Sep 17 00:00:00 2001 From: ellunium Date: Sat, 6 Oct 2018 17:55:09 +0200 Subject: [PATCH 01/15] Update Sketch Measure.sketchplugin/Contents/Sketch/library/common.js Support for Sketch 52 and 52.1 --- .../Contents/Sketch/library/common.js | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 35f9113..747b34d 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -208,8 +208,8 @@ SM.extend({ return MSLayerGroup.new(); }, addShape: function(){ - var shape = MSRectangleShape.alloc().initWithFrame(NSMakeRect(0, 0, 100, 100)); - return MSShapeGroup.shapeWithPath(shape); + return MSShapeGroup.shapeWithRect(NSMakeRect(0, 0, 100, 100)); + }, addText: function(container){ var text = MSTextLayer.new(); @@ -441,9 +441,9 @@ SM.extend({ return style.contextSettings().opacity() }, getStyleName: function(layer){ - var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(), + var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(), layerStyle = layer.style(), - sharedObjectID = layerStyle.sharedObjectID(), + sharedObjectID = layerStyle.objectID(), style; styles = styles.objectsSortedByName(); @@ -655,11 +655,12 @@ SM.extend({ border.position = 1; } - const s = MSSharedStyle.alloc().initWithName_firstInstance(name, style); + const s = MSSharedStyle.alloc().initWithName_style(name, style); sharedStyles.addSharedObject(s); } - return (style.newInstance)? style.newInstance(): style; + var style = this.find({key: "(name != NULL) && (name == %@)", match: name}, sharedStyles); + return style; }, sharedTextStyle: function(name, color, alignment){ var sharedStyles = this.document.documentData().layerTextStyles(), @@ -679,12 +680,16 @@ SM.extend({ text.setTextAlignment(alignment); style = text.style(); - const s = MSSharedStyle.alloc().initWithName_firstInstance(name, style); + + const s = MSSharedStyle.alloc().initWithName_style(name, style); + sharedStyles.addSharedObject(s); this.removeLayer(text); } - return (style.newInstance)? style.newInstance(): style; + var style = this.find({key: "(name != NULL) && (name == %@)", match: name}, sharedStyles); + return style; + } }); @@ -704,10 +709,9 @@ SM.extend({ placement = options.placement, shapeTemp = this.addShape(); - if(styles){ - shapeTemp.setStyle(styles.layer); - } - else{ + if(styles){ + shapeTemp.setSharedStyle(styles.layer); + } else { shapeTemp.style().addStylePartOfType(0); } @@ -816,10 +820,9 @@ SM.extend({ textTemp = this.addText(); if(styles){ - shapeTemp.setStyle(styles.layer); - textTemp.setStyle(styles.text); - } - else{ + shapeTemp.setSharedStyle(styles.layer); + textTemp.setSharedStyle(styles.text); + } else { shape.style().addStylePartOfType(0); } @@ -903,13 +906,11 @@ SM.extend({ boxRect.setWidth(textRect.width + 8); boxRect.setHeight(textRect.height + 8); - arrow.setRotation(45); - arrow.flatten(); arrowRect.setWidth(8); arrowRect.setHeight(8); - arrowRect.setX(arrowX); arrowRect.setY(arrowY); + arrow.setRotation(45); return { element: box, @@ -1366,7 +1367,7 @@ SM.extend({ temp.setStringValue(text); temp.setTextBehaviour(1); temp.setTextBehaviour(0); - temp.setStyle(styles.text); + temp.setSharedStyle(styles.text); var tempRect = this.getRect(temp), ruler = this.setRuler({ @@ -1957,8 +1958,8 @@ SM.extend({ text.setStringValue(target.stringValue()); text.setTextBehaviour(1); text.setTextBehaviour(0); - note.setStyle(noteStyle.layer); - text.setStyle(noteStyle.text); + note.setSharedStyle(noteStyle.layer); + text.setSharedStyle(noteStyle.text); var noteRect = this.getRect(note), textRect = this.getRect(text), @@ -2353,6 +2354,7 @@ SM.extend({ isExportable: function(layer) { return this.is(layer, MSTextLayer) || this.is(layer, MSShapeGroup) || + this.is(layer, MSRectangleShape) || this.is(layer, MSBitmapLayer) || this.is(layer, MSSliceLayer) || this.is(layer, MSSymbolInstance) || From 7e29726916434fc86a2125909371895d07b4db3f Mon Sep 17 00:00:00 2001 From: ellunium Date: Sat, 6 Oct 2018 18:01:15 +0200 Subject: [PATCH 02/15] Updates Sketch v52 --- .../Contents/Sketch/manifest.json | 2 +- appcast.xml | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/manifest.json b/Sketch Measure.sketchplugin/Contents/Sketch/manifest.json index dd97dd6..35ef517 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/manifest.json +++ b/Sketch Measure.sketchplugin/Contents/Sketch/manifest.json @@ -177,7 +177,7 @@ "identifier": "com.utom.measure", "appcast": "https://raw.githubusercontent.com/utom/sketch-measure/master/appcast.xml", "homepage": "http://utom.design/measure/", - "version": "2.7.5", + "version": "2.7.6", "description" : "Make it a fun to create spec for developers and teammates", "authorEmail" : "utombox@gmail.com", "name" : "Sketch Measure" diff --git a/appcast.xml b/appcast.xml index f1b3a05..ddbca04 100644 --- a/appcast.xml +++ b/appcast.xml @@ -5,7 +5,19 @@ http://utom.design/measure/appcast.xml Make it a fun to create spec for developers and teammates en - + + Version 2.7.5 + + +
  • Support Sketch v52
  • + + ]]> +
    + +
    + + Version 2.7.5 ]]> - + Version 2.7.4 From beb5c8837f6604263185c90d96682f8d2824ed7f Mon Sep 17 00:00:00 2001 From: ellunium Date: Tue, 9 Oct 2018 00:09:40 +0200 Subject: [PATCH 03/15] fixed crash when marking overlays --- .../Contents/Sketch/library/common.js | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 747b34d..c9f5986 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -208,7 +208,7 @@ SM.extend({ return MSLayerGroup.new(); }, addShape: function(){ - return MSShapeGroup.shapeWithRect(NSMakeRect(0, 0, 100, 100)); + return MSShapeGroup.shapeWithRect(NSMakeRect(0, 0, 100, 100)); }, addText: function(container){ @@ -441,10 +441,10 @@ SM.extend({ return style.contextSettings().opacity() }, getStyleName: function(layer){ - var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(), - layerStyle = layer.style(), - sharedObjectID = layerStyle.objectID(), - style; + var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(), + layerStyle = layer.style(), + sharedObjectID = layerStyle.objectID(), + style; styles = styles.objectsSortedByName(); @@ -655,12 +655,12 @@ SM.extend({ border.position = 1; } - const s = MSSharedStyle.alloc().initWithName_style(name, style); + const s = MSSharedStyle.alloc().initWithName_style(name, style); sharedStyles.addSharedObject(s); } - var style = this.find({key: "(name != NULL) && (name == %@)", match: name}, sharedStyles); - return style; + var style = this.find({key: "(name != NULL) && (name == %@)", match: name}, sharedStyles); + return style; }, sharedTextStyle: function(name, color, alignment){ var sharedStyles = this.document.documentData().layerTextStyles(), @@ -681,14 +681,14 @@ SM.extend({ style = text.style(); - const s = MSSharedStyle.alloc().initWithName_style(name, style); + const s = MSSharedStyle.alloc().initWithName_style(name, style); sharedStyles.addSharedObject(s); this.removeLayer(text); } - var style = this.find({key: "(name != NULL) && (name == %@)", match: name}, sharedStyles); - return style; + var style = this.find({key: "(name != NULL) && (name == %@)", match: name}, sharedStyles); + return style; } }); @@ -709,8 +709,8 @@ SM.extend({ placement = options.placement, shapeTemp = this.addShape(); - if(styles){ - shapeTemp.setSharedStyle(styles.layer); + if(styles){ + shapeTemp.setSharedStyle(styles.layer); } else { shapeTemp.style().addStylePartOfType(0); } @@ -820,8 +820,8 @@ SM.extend({ textTemp = this.addText(); if(styles){ - shapeTemp.setSharedStyle(styles.layer); - textTemp.setSharedStyle(styles.text); + shapeTemp.setSharedStyle(styles.layer); + textTemp.setSharedStyle(styles.text); } else { shape.style().addStylePartOfType(0); } @@ -910,7 +910,7 @@ SM.extend({ arrowRect.setHeight(8); arrowRect.setX(arrowX); arrowRect.setY(arrowY); - arrow.setRotation(45); + arrow.setRotation(45); return { element: box, @@ -1516,6 +1516,7 @@ SM.extend({ SM.extend({ overlay: function(target){ + //Crashing on exception: -[MSImmutableSharedStyle hasMarkers]: unrecognized selector sent to instance 0x608002a4f510 var targetRect = this.getRect(target), name = "OVERLAY#" + target.objectID(), container = this.find({key: "(name != NULL) && (name == %@)", match: name}), @@ -1531,7 +1532,7 @@ SM.extend({ container.addLayers([overlay]); - overlay.setStyle(overlayStyle); + overlay.setSharedStyle(overlayStyle); overlay.setName("overlay"); overlayRect.setX(targetRect.x); overlayRect.setY(targetRect.y); @@ -1658,8 +1659,8 @@ SM.extend({ content.push("style-name: " + styleName); } break; - case "layer-name": - content.push("layer-name: " + target.name()); + case "layer-name": + content.push("layer-name: " + target.name()); break; default: render = false; @@ -2354,7 +2355,7 @@ SM.extend({ isExportable: function(layer) { return this.is(layer, MSTextLayer) || this.is(layer, MSShapeGroup) || - this.is(layer, MSRectangleShape) || + this.is(layer, MSRectangleShape) || this.is(layer, MSBitmapLayer) || this.is(layer, MSSliceLayer) || this.is(layer, MSSymbolInstance) || From 1f4c8d7f1e35378bcb953925ef03995eaf9aec1e Mon Sep 17 00:00:00 2001 From: ellunium Date: Tue, 9 Oct 2018 09:55:42 +0200 Subject: [PATCH 04/15] added support for oval, path, triangle, star and polygon shapes --- .../Contents/Sketch/library/common.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index c9f5986..2bd16df 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -675,7 +675,7 @@ SM.extend({ text.changeTextColorTo(color.NSColorWithColorSpace(nil)); - text.setFontSize(12); + text.setFontSize(8); text.setFontPostscriptName("HelveticaNeue"); text.setTextAlignment(alignment); @@ -1543,6 +1543,13 @@ SM.extend({ } }); +// SM.extend({ +// url: function(content){ +// var urlRegex = /[\w\.\-\+]+:)\/{2}(([\w\d\.]+):([\w\d\.]+))?@?(([a-zA-Z0-9\.\-_]+)(?::(\d{1,5}))?))?(\/(?:[a-zA-Z0-9\.\-\/\+\%]+)?)(?:\?([a-zA-Z0-9=%\-_\.\*&;]+))?(?:#([a-zA-Z0-9\-=,&%;\/\\"'\?]+)?)?/g; +// return content.replace(urlRegex, '$1'); +// } +// }); + // properties.js SM.extend({ fillTypeContent: function( fillJSON ){ @@ -2356,6 +2363,11 @@ SM.extend({ return this.is(layer, MSTextLayer) || this.is(layer, MSShapeGroup) || this.is(layer, MSRectangleShape) || + this.is(layer, MSOvalShape) || + this.is(layer, MSShapePathLayer) || + this.is(layer, MSTriangleShape) || + this.is(layer, MSStarShape) || + this.is(layer, MSPolygonShape) || this.is(layer, MSBitmapLayer) || this.is(layer, MSSliceLayer) || this.is(layer, MSSymbolInstance) || From 5b441f9364a1dc0dcfc6131f394ac75c56dd0783 Mon Sep 17 00:00:00 2001 From: ellunium Date: Tue, 9 Oct 2018 10:12:48 +0200 Subject: [PATCH 05/15] cleaning up text size test --- .../Contents/Sketch/library/common.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 2bd16df..34dd14e 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -675,7 +675,7 @@ SM.extend({ text.changeTextColorTo(color.NSColorWithColorSpace(nil)); - text.setFontSize(8); + text.setFontSize(12); text.setFontPostscriptName("HelveticaNeue"); text.setTextAlignment(alignment); @@ -2362,15 +2362,15 @@ SM.extend({ isExportable: function(layer) { return this.is(layer, MSTextLayer) || this.is(layer, MSShapeGroup) || + this.is(layer, MSSymbolInstance) || + this.is(layer, MSBitmapLayer) || + this.is(layer, MSSliceLayer) || this.is(layer, MSRectangleShape) || this.is(layer, MSOvalShape) || this.is(layer, MSShapePathLayer) || this.is(layer, MSTriangleShape) || this.is(layer, MSStarShape) || this.is(layer, MSPolygonShape) || - this.is(layer, MSBitmapLayer) || - this.is(layer, MSSliceLayer) || - this.is(layer, MSSymbolInstance) || this.isSliceGroup(layer) }, getStates: function(layer){ From b8f6a52fbdf7dae2d12eb8f5bce5d1b71d77eea6 Mon Sep 17 00:00:00 2001 From: ellunium Date: Tue, 9 Oct 2018 16:10:06 +0200 Subject: [PATCH 06/15] fixed radius support when exporting and marking --- .../Contents/Sketch/library/common.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 34dd14e..d943cef 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -357,7 +357,7 @@ SM.extend({ }; }, getRadius: function(layer){ - return ( layer.layers && this.is(layer.layers().firstObject(), MSRectangleShape) ) ? layer.layers().firstObject().fixedRadius(): 0; + return (layer.layers && this.is(layer.layers().firstObject(), MSRectangleShape)) ? layer.layers().firstObject().fixedRadius() : (this.is(layer, MSRectangleShape))? layer.fixedRadius() : 0; }, getBorders: function(style) { var bordersData = [], @@ -1626,7 +1626,7 @@ SM.extend({ content.push("opacity: " + Math.round( targetStyle.contextSettings().opacity() * 100) + "%"); break; case "radius": - if(self.is(target, MSShapeGroup) && self.is(target.layers().firstObject(), MSRectangleShape)){ + if((self.is(target, MSShapeGroup) && self.is(target.layers().firstObject(), MSRectangleShape)) || self.is(target, MSRectangleShape)){ content.push("radius: " + self.convertUnit( self.getRadius(target) ) ); } break; @@ -2362,15 +2362,15 @@ SM.extend({ isExportable: function(layer) { return this.is(layer, MSTextLayer) || this.is(layer, MSShapeGroup) || - this.is(layer, MSSymbolInstance) || - this.is(layer, MSBitmapLayer) || - this.is(layer, MSSliceLayer) || this.is(layer, MSRectangleShape) || this.is(layer, MSOvalShape) || this.is(layer, MSShapePathLayer) || this.is(layer, MSTriangleShape) || this.is(layer, MSStarShape) || this.is(layer, MSPolygonShape) || + this.is(layer, MSBitmapLayer) || + this.is(layer, MSSliceLayer) || + this.is(layer, MSSymbolInstance) || this.isSliceGroup(layer) }, getStates: function(layer){ From 1667bc023ce0057721bce0d5cb8d09411d224488 Mon Sep 17 00:00:00 2001 From: ellunium Date: Thu, 11 Oct 2018 07:47:10 +0200 Subject: [PATCH 07/15] expanded radius support to handle multiple radius values on mark and export --- .../Contents/Sketch/library/common.js | 74 ++++++++++++------- .../Contents/Sketch/library/template.html | 35 +++++++-- 2 files changed, 77 insertions(+), 32 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index d943cef..42d413b 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -357,7 +357,13 @@ SM.extend({ }; }, getRadius: function(layer){ - return (layer.layers && this.is(layer.layers().firstObject(), MSRectangleShape)) ? layer.layers().firstObject().fixedRadius() : (this.is(layer, MSRectangleShape))? layer.fixedRadius() : 0; + if(layer.layers && this.is(layer.layers().firstObject(), MSRectangleShape)){ + return (layer.layers().firstObject().cornerRadiusString().split(';').map(Number).length == 1) ? layer.layers().firstObject().fixedRadius() : layer.layers().firstObject().cornerRadiusString().split(';').map(Number); + } else if(this.is(layer, MSRectangleShape)) { + return (layer.cornerRadiusString().split(';').map(Number).length == 1) ? layer.fixedRadius() : layer.cornerRadiusString().split(';').map(Number); + } else { + return 0; + } }, getBorders: function(style) { var bordersData = [], @@ -469,26 +475,46 @@ SM.extend({ return Math.round( number / 2 ); }, convertUnit: function(length, isText, percentageType){ - if(percentageType && this.artboard){ - var artboardRect = this.getRect( this.artboard ); - if (percentageType == "width") { - return Math.round((length / artboardRect.width) * 1000) / 10 + "%"; - + if(length.length){ + var units = this.configs.unit.split("/"), + unit = units[0]; + + if( units.length > 1 && isText){ + unit = units[1]; } - else if(percentageType == "height"){ - return Math.round((length / artboardRect.height) * 1000) / 10 + "%"; - } - } - var length = Math.round( length / this.configs.scale * 10 ) / 10, - units = this.configs.unit.split("/"), - unit = units[0]; + var scale = this.configs.scale; + var tempLegth = []; - if( units.length > 1 && isText){ - unit = units[1]; - } + length.forEach(function(element) { + tempLegth.push(Math.round( element / scale * 10 ) / 10); + }); + + return tempLegth.join(unit + ' ') + unit; + + } else { - return length + unit; + if(percentageType && this.artboard){ + var artboardRect = this.getRect( this.artboard ); + if (percentageType == "width") { + return Math.round((length / artboardRect.width) * 1000) / 10 + "%"; + } + else if(percentageType == "height"){ + return Math.round((length / artboardRect.height) * 1000) / 10 + "%"; + } + } + + var length = Math.round( length / this.configs.scale * 10 ) / 10, + units = this.configs.unit.split("/"), + unit = units[0]; + + if( units.length > 1 && isText){ + unit = units[1]; + } + + return length + unit; + } + }, toHex:function(c) { var hex = Math.round(c).toString(16).toUpperCase(); @@ -1543,13 +1569,6 @@ SM.extend({ } }); -// SM.extend({ -// url: function(content){ -// var urlRegex = /[\w\.\-\+]+:)\/{2}(([\w\d\.]+):([\w\d\.]+))?@?(([a-zA-Z0-9\.\-_]+)(?::(\d{1,5}))?))?(\/(?:[a-zA-Z0-9\.\-\/\+\%]+)?)(?:\?([a-zA-Z0-9=%\-_\.\*&;]+))?(?:#([a-zA-Z0-9\-=,&%;\/\\"'\?]+)?)?/g; -// return content.replace(urlRegex, '$1'); -// } -// }); - // properties.js SM.extend({ fillTypeContent: function( fillJSON ){ @@ -3164,7 +3183,12 @@ SM.extend({ var c = layerCSSAttributes[i] if(! /\/\*/.exec(c) ) css.push(this.toJSString(c)); } - if(css.length > 0) layerData.css = css; + if(css.length > 0) { + layerData.css = css; + if(this.is(layer, MSRectangleShape) && !!layer.fixedRadius()){ + layerData.css.push('border-radius: ' + layer.cornerRadiusString().replace(/;/g,'px ') + 'px;'); + } + } this.getMask(group, layer, layerData, layerStates); this.getSlice(layer, layerData, symbolLayer); diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html b/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html index 72e68a5..7beff0c 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html @@ -232,13 +232,35 @@ return (Math.round( size / size2 * 1000 ) / 10) + "%"; }, unitSize: function(length, isText){ - var length = Math.round( length / this.configs.scale * 100 ) / 100, - units = this.configs.unit.split("/"), - unit = units[0]; - if( units.length > 1 && isText){ - unit = units[1]; + if(length.length){ + + var units = this.configs.unit.split("/"), + unit = units[0]; + + if( units.length > 1 && isText){ + unit = units[1]; + } + + var scale = this.configs.scale; + var tempLegth = []; + + length.forEach(function(element) { + tempLegth.push(Math.round( element / scale * 10 ) / 10); + }); + + return tempLegth.join(unit + ' ') + unit; + + } else { + + var length = Math.round( length / this.configs.scale * 10 ) / 10, + units = this.configs.unit.split("/"), + unit = units[0]; + if( units.length > 1 && isText){ + unit = units[1]; + } + return length + unit; } - return length + unit; + }, scaleSize: function (length){ return Math.round( length / this.configs.scale * 10 ) / 10; @@ -886,7 +908,6 @@ radius = (layerData.radius)? [ '
    ', '', - '', '
    ' ].join(''): '', styleName = (layerData.styleName)? [ From 2a45bebb154da88cda6c6767f91829403acdbda5 Mon Sep 17 00:00:00 2001 From: ellunium Date: Thu, 11 Oct 2018 16:41:33 +0200 Subject: [PATCH 08/15] changed radius validation to array, making it less prone to erros --- Sketch Measure.sketchplugin/Contents/Sketch/library/common.js | 2 +- .../Contents/Sketch/library/template.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 42d413b..f57c3f7 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -475,7 +475,7 @@ SM.extend({ return Math.round( number / 2 ); }, convertUnit: function(length, isText, percentageType){ - if(length.length){ + if(Array.isArray(length)){ var units = this.configs.unit.split("/"), unit = units[0]; diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html b/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html index 7beff0c..a2c746e 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/template.html @@ -232,7 +232,7 @@ return (Math.round( size / size2 * 1000 ) / 10) + "%"; }, unitSize: function(length, isText){ - if(length.length){ + if(Array.isArray(length)){ var units = this.configs.unit.split("/"), unit = units[0]; From 302b05bcce7a4f60f16aeca04d06c9895b0a998d Mon Sep 17 00:00:00 2001 From: ellunium Date: Thu, 11 Oct 2018 22:53:41 +0200 Subject: [PATCH 09/15] added support to show radius even on masked items --- .../Contents/Sketch/library/common.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index f57c3f7..2a17377 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -1539,10 +1539,8 @@ SM.extend({ } }); - SM.extend({ overlay: function(target){ - //Crashing on exception: -[MSImmutableSharedStyle hasMarkers]: unrecognized selector sent to instance 0x608002a4f510 var targetRect = this.getRect(target), name = "OVERLAY#" + target.objectID(), container = this.find({key: "(name != NULL) && (name == %@)", match: name}), @@ -3114,7 +3112,8 @@ SM.extend({ ( layerStates.isLocked && !this.is(layer, MSSliceLayer) ) || layerStates.isEmpty || layerStates.hasSlice || - layerStates.isMeasure + layerStates.isMeasure || + layer.isMasked() ){ return this; } @@ -3178,14 +3177,15 @@ SM.extend({ var layerCSSAttributes = layer.CSSAttributes(), css = []; - + for(var i = 0; i < layerCSSAttributes.count(); i++) { var c = layerCSSAttributes[i] if(! /\/\*/.exec(c) ) css.push(this.toJSString(c)); } + if(css.length > 0) { layerData.css = css; - if(this.is(layer, MSRectangleShape) && !!layer.fixedRadius()){ + if(this.is(layer, MSRectangleShape) && !!layer.cornerRadiusString() && layer.cornerRadiusString() != 0){ layerData.css.push('border-radius: ' + layer.cornerRadiusString().replace(/;/g,'px ') + 'px;'); } } From 96189fe6b312147e050727aa417e162bfeb7a815 Mon Sep 17 00:00:00 2001 From: ellunium Date: Fri, 12 Oct 2018 11:34:48 +0200 Subject: [PATCH 10/15] added backward compatibility for notes marked with older versions of the plugin --- Sketch Measure.sketchplugin/Contents/Sketch/library/common.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 2a17377..46b9917 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -3097,7 +3097,9 @@ SM.extend({ layerStates = this.getStates(layer); if(layer && this.is(layer, MSLayerGroup) && /NOTE\#/.exec(layer.name())){ - var textLayer = layer.children()[3]; + for (var i = 0; i < layer.children().count(); i++) { + if(this.is(layer.children()[i], MSTextLayer)) var textLayer = layer.children()[i]; + } data.notes.push({ rect: this.rectToJSON(textLayer.absoluteRect(), artboardRect), From 64abb7b71e8a145dab60bee4f695451f290fe3e4 Mon Sep 17 00:00:00 2001 From: ellunium Date: Fri, 12 Oct 2018 12:30:53 +0200 Subject: [PATCH 11/15] fixed bug where styles would not show when exporting --- .../Contents/Sketch/library/common.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 46b9917..b3ffb72 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -448,9 +448,9 @@ SM.extend({ }, getStyleName: function(layer){ var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(), - layerStyle = layer.style(), - sharedObjectID = layerStyle.objectID(), - style; + layerStyle = layer.style(), + sharedObjectID = layer.sharedStyleID(), + style; styles = styles.objectsSortedByName(); From 0286de9ed92bceab6f4b81ff9e9d9035ed02377a Mon Sep 17 00:00:00 2001 From: ellunium Date: Fri, 12 Oct 2018 14:58:21 +0200 Subject: [PATCH 12/15] fixed bug to show radius when rectangle fill is an image when exporting --- Sketch Measure.sketchplugin/Contents/Sketch/library/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index b3ffb72..3911128 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -3185,7 +3185,7 @@ SM.extend({ if(! /\/\*/.exec(c) ) css.push(this.toJSString(c)); } - if(css.length > 0) { + if(css.length > 0 || layer.CSSAttributes().length > 0) { layerData.css = css; if(this.is(layer, MSRectangleShape) && !!layer.cornerRadiusString() && layer.cornerRadiusString() != 0){ layerData.css.push('border-radius: ' + layer.cornerRadiusString().replace(/;/g,'px ') + 'px;'); From 65fe50b604ecc72309afb01c38674cc79fcfa8c4 Mon Sep 17 00:00:00 2001 From: ellunium Date: Fri, 12 Oct 2018 22:03:55 +0200 Subject: [PATCH 13/15] added fix to show Library and Local styles, also added a check for sharedStyleID --- .../Contents/Sketch/library/common.js | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index 3911128..fe3562e 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -447,19 +447,38 @@ SM.extend({ return style.contextSettings().opacity() }, getStyleName: function(layer){ - var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(), - layerStyle = layer.style(), - sharedObjectID = layer.sharedStyleID(), - style; - - styles = styles.objectsSortedByName(); + if(layer.sharedStyleID()){ + var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(), + layerStyle = layer.style(), + sharedObjectID = layer.sharedStyleID(), + style; + + styles = styles.objectsSortedByName(); + + if(styles.count() > 0){ + style = this.find({key: "(objectID != NULL) && (objectID == %@)", match: sharedObjectID}, styles); + } + + if(!style){ + var styles = (this.is(layer, MSTextLayer))? this.document.documentData().foreignTextStyles(): this.document.documentData().foreignLayerStyles(), + layerStyle = layer.style(), + sharedObjectID = layer.sharedStyleID(), + style; + + styles.forEach(libraryStyle => { + if(String(libraryStyle.localSharedStyle().objectID()) == String(sharedObjectID)){ + style = libraryStyle.localSharedStyle().name(); + } + }); + + if(!style) return ""; + return this.toJSString(style); + } + return this.toJSString(style.name()); - if(styles.count() > 0){ - style = this.find({key: "(objectID != NULL) && (objectID == %@)", match: sharedObjectID}, styles); + } else { + return ""; } - - if(!style) return ""; - return this.toJSString(style.name()); }, updateContext: function(){ this.context.document = NSDocumentController.sharedDocumentController().currentDocument(); From e77002b17552090f9f022a70d345134e2665108e Mon Sep 17 00:00:00 2001 From: ellunium Date: Fri, 12 Oct 2018 23:25:10 +0200 Subject: [PATCH 14/15] changed version to 2.7.6 for all languages --- .../Contents/Sketch/library/i18n/manifest-en.json | 2 +- .../Contents/Sketch/library/i18n/manifest-zh-Hans.json | 2 +- .../Contents/Sketch/library/i18n/manifest-zh-Hant.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-en.json b/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-en.json index dd97dd6..35ef517 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-en.json +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-en.json @@ -177,7 +177,7 @@ "identifier": "com.utom.measure", "appcast": "https://raw.githubusercontent.com/utom/sketch-measure/master/appcast.xml", "homepage": "http://utom.design/measure/", - "version": "2.7.5", + "version": "2.7.6", "description" : "Make it a fun to create spec for developers and teammates", "authorEmail" : "utombox@gmail.com", "name" : "Sketch Measure" diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hans.json b/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hans.json index 7d70b34..a063287 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hans.json +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hans.json @@ -180,7 +180,7 @@ "identifier": "com.utom.measure", "appcast": "https://raw.githubusercontent.com/utom/sketch-measure/master/appcast.xml", "homepage": "http://utom.design/measure/", - "version": "2.7.5", + "version": "2.7.6", "description" : "Make it a fun to create spec for developers and teammates", "authorEmail" : "utombox@gmail.com", "name" : "Sketch Measure" diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hant.json b/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hant.json index 9e041ae..9d3b94b 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hant.json +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/i18n/manifest-zh-Hant.json @@ -180,7 +180,7 @@ "identifier": "com.utom.measure", "appcast": "https://raw.githubusercontent.com/utom/sketch-measure/master/appcast.xml", "homepage": "http://utom.design/measure/", - "version": "2.7.5", + "version": "2.7.6", "description" : "Make it a fun to create spec for developers and teammates", "authorEmail" : "utombox@gmail.com", "name" : "Sketch Measure" From 3ea02ff87787ce53c48888b9d90279b6bb225666 Mon Sep 17 00:00:00 2001 From: ellunium Date: Sun, 14 Oct 2018 08:55:17 +0200 Subject: [PATCH 15/15] added a check in case CSSAtributes() gets fixed and they add back radius-border property --- Sketch Measure.sketchplugin/Contents/Sketch/library/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js index fe3562e..db5b0ec 100755 --- a/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js +++ b/Sketch Measure.sketchplugin/Contents/Sketch/library/common.js @@ -3206,7 +3206,7 @@ SM.extend({ if(css.length > 0 || layer.CSSAttributes().length > 0) { layerData.css = css; - if(this.is(layer, MSRectangleShape) && !!layer.cornerRadiusString() && layer.cornerRadiusString() != 0){ + if(this.is(layer, MSRectangleShape) && !!layer.cornerRadiusString() && layer.cornerRadiusString() != 0 && !/border-radius/.exec(layer.CSSAttributes())){ layerData.css.push('border-radius: ' + layer.cornerRadiusString().replace(/;/g,'px ') + 'px;'); } }