Skip to content

Commit

Permalink
Support Sketch v52
Browse files Browse the repository at this point in the history
  • Loading branch information
utom committed Oct 17, 2018
1 parent cbde414 commit 2bd89e4
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 171 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework module SMFramework {
umbrella header "SMFramework.h"

export *
module * { export * }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>17D102</string>
<string>18A391</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8A218a</string>
<string>10A255</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>16A300</string>
<string>18A384</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<string>macosx10.14</string>
<key>DTXcode</key>
<string>0800</string>
<string>1000</string>
<key>DTXcodeBuild</key>
<string>8A218a</string>
<string>10A255</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 UTOMBOX. All rights reserved.</string>
</dict>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>17D102</string>
<string>18A391</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8A218a</string>
<string>10A255</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>16A300</string>
<string>18A384</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<string>macosx10.14</string>
<key>DTXcode</key>
<string>0800</string>
<string>1000</string>
<key>DTXcodeBuild</key>
<string>8A218a</string>
<string>10A255</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 UTOMBOX. All rights reserved.</string>
</dict>
Expand Down
Binary file not shown.
91 changes: 36 additions & 55 deletions Sketch Measure.sketchplugin/Contents/Sketch/library/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,38 +447,19 @@ SM.extend({
return style.contextSettings().opacity()
},
getStyleName: function(layer){
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());
var styles = (this.is(layer, MSTextLayer))? this.document.documentData().layerTextStyles(): this.document.documentData().layerStyles(),
layerStyle = layer.style(),
sharedObjectID = layerStyle.objectID(),
style;

} else {
return "";
styles = styles.objectsSortedByName();

if(styles.count() > 0){
style = this.find({key: "(objectID != NULL) && (objectID == %@)", match: sharedObjectID}, styles);
}

if(!style) return "";
return this.toJSString(style.name());
},
updateContext: function(){
this.context.document = NSDocumentController.sharedDocumentController().currentDocument();
Expand All @@ -494,10 +475,10 @@ SM.extend({
return Math.round( number / 2 );
},
convertUnit: function(length, isText, percentageType){
if(Array.isArray(length)){
if(length.length){
var units = this.configs.unit.split("/"),
unit = units[0];

if( units.length > 1 && isText){
unit = units[1];
}
Expand All @@ -508,8 +489,8 @@ SM.extend({
length.forEach(function(element) {
tempLegth.push(Math.round( element / scale * 10 ) / 10);
});
return tempLegth.join(unit + ' ') + unit;

return tempLegth.join(unit + ' ') + unit;

} else {

Expand All @@ -522,18 +503,18 @@ SM.extend({
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();
Expand Down Expand Up @@ -902,8 +883,8 @@ SM.extend({
// rect function
var x = targetRect.x + this.mathHalf(targetRect.width) - this.mathHalf(textRect.width),
y = targetRect.y + this.mathHalf(targetRect.height) - this.mathHalf(textRect.height),
arrowX = x - 4 + this.mathHalf(textRect.width + 8) - 4,
arrowY = y - 4 + this.mathHalf(textRect.height + 8) - 4;
arrowX = x - 3 + this.mathHalf(textRect.width + 6) - 3,
arrowY = y - 3 + this.mathHalf(textRect.height + 6) - 3;

if(!this.is(target, MSPage) && !this.is(target, MSArtboardGroup)){
switch(placement){
Expand Down Expand Up @@ -951,11 +932,11 @@ SM.extend({
boxRect.setWidth(textRect.width + 8);
boxRect.setHeight(textRect.height + 8);

arrowRect.setWidth(8);
arrowRect.setHeight(8);
arrowRect.setWidth(6);
arrowRect.setHeight(6);
arrowRect.setX(arrowX);
arrowRect.setY(arrowY);
arrow.setRotation(45);
arrow.setRotation(45);

return {
element: box,
Expand Down Expand Up @@ -1558,8 +1539,10 @@ 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}),
Expand Down Expand Up @@ -2948,8 +2931,9 @@ SM.extend({
exporting = true;
var artboard = self.selectionArtboards[artboardIndex],
page = artboard.parentGroup(),
layer = artboard.children()[layerIndex];
log( page.name() + ' - ' + artboard.name() + ' - ' + layer.name());
layer = artboard.children()[layerIndex],
message = page.name() + ' - ' + artboard.name() + ' - ' + layer.name();
// log( page.name() + ' - ' + artboard.name() + ' - ' + layer.name());
try {
self.getLayer(
artboard, // Sketch artboard element
Expand All @@ -2961,7 +2945,8 @@ SM.extend({
exporting = false;
} catch (e) {
self.wantsStop = true;
processing.evaluateWebScript("$('#processing-text').html('<strong>Error:</strong> <small>" + self.toHTMLEncode(e.message) + "</small>');");
log(e)
processing.evaluateWebScript("$('#processing-text').html('<small>" + self.toHTMLEncode(message) + "</small>');");
}

if( layerIndex >= artboard.children().length ){
Expand Down Expand Up @@ -3116,9 +3101,7 @@ SM.extend({
layerStates = this.getStates(layer);

if(layer && this.is(layer, MSLayerGroup) && /NOTE\#/.exec(layer.name())){
for (var i = 0; i < layer.children().count(); i++) {
if(this.is(layer.children()[i], MSTextLayer)) var textLayer = layer.children()[i];
}
var textLayer = layer.children()[2];

data.notes.push({
rect: this.rectToJSON(textLayer.absoluteRect(), artboardRect),
Expand All @@ -3133,8 +3116,7 @@ SM.extend({
( layerStates.isLocked && !this.is(layer, MSSliceLayer) ) ||
layerStates.isEmpty ||
layerStates.hasSlice ||
layerStates.isMeasure ||
layer.isMasked()
layerStates.isMeasure
){
return this;
}
Expand Down Expand Up @@ -3198,15 +3180,14 @@ 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 || layer.CSSAttributes().length > 0) {
if(css.length > 0) {
layerData.css = css;
if(this.is(layer, MSRectangleShape) && !!layer.cornerRadiusString() && layer.cornerRadiusString() != 0 && !/border-radius/.exec(layer.CSSAttributes())){
if(this.is(layer, MSRectangleShape) && !!layer.fixedRadius()){
layerData.css.push('border-radius: ' + layer.cornerRadiusString().replace(/;/g,'px ') + 'px;');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.6",
"version": "2.7.7",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "[email protected]",
"name" : "Sketch Measure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.6",
"version": "2.7.7",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "[email protected]",
"name" : "Sketch Measure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.6",
"version": "2.7.7",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "[email protected]",
"name" : "Sketch Measure"
Expand Down
35 changes: 7 additions & 28 deletions Sketch Measure.sketchplugin/Contents/Sketch/library/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,35 +232,13 @@
return (Math.round( size / size2 * 1000 ) / 10) + "%";
},
unitSize: function(length, isText){
if(Array.isArray(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;
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];
}

return length + unit;
},
scaleSize: function (length){
return Math.round( length / this.configs.scale * 10 ) / 10;
Expand Down Expand Up @@ -908,6 +886,7 @@
radius = (layerData.radius)? [
'<div class="item" data-label="' +_('Radius') + ':">',
'<label><input id="radius" type="text" value="' + this.unitSize(layerData.radius) + '" readonly="readonly"></label>',
'<label></label>',
'</div>'
].join(''): '',
styleName = (layerData.styleName)? [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function linkHelp(){
}

function linkZhCNHelp(){
openURL('http://sketch.im/plugins/1');
openURL('http://sketch.cm/plugins/1');
}

function linkFeedback(){
Expand Down
2 changes: 1 addition & 1 deletion Sketch Measure.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.6",
"version": "2.7.7",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "[email protected]",
"name" : "Sketch Measure"
Expand Down
Loading

0 comments on commit 2bd89e4

Please sign in to comment.