Skip to content

Commit

Permalink
add text-shadow box-shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
bugluo committed Nov 1, 2017
1 parent 664ce20 commit 3842b28
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/codeStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ function codeS(context) {
function exportText(selection) {
var layerStyle = selection.style();
var returnText = [];
var getShadow = getShadows(layerStyle);
if(getShadow.length > 0){
var shadowText = '';
for(var i = 0;i < getShadow.length; i++) {
if(shadowText != ''){
shadowText += ',\n';
}
if(getShadow[i].type != 'inner'){
shadowText += Math.round(getShadow[i].offsetX / Rate) + keyCode + ' ' + Math.round(getShadow[i].offsetY / Rate) + keyCode + ' ' + Math.round(getShadow[i].blurRadius / Rate) + keyCode + ' ' + getShadow[i].color;
}
}
returnText.push('text-shadow: ' + shadowText + ';');
}

if (layerStyle.contextSettings().opacity() != 1) {
returnText.push('opacity: ' + layerStyle.contextSettings().opacity().toFixed(2) + ';');
}
Expand Down Expand Up @@ -206,6 +220,7 @@ function codeS(context) {
}
var backgroundColor = getFills(layerStyle);
var getBorder = getBorders(layerStyle);
var getShadow = getShadows(layerStyle);
var borderless = 0;
var rateX = 1;
if (Rate > 1) {
Expand All @@ -220,6 +235,18 @@ function codeS(context) {
returnText.push('border: ' + Math.round(getBorder[0].thickness / rateX) + keyCode + ' solid ' + (getBorder[0].color) + ';');
}
}

if(getShadow.length > 0){
var shadowText = 'box-shadow: ';
for(var i = 0;i < getShadow.length; i++) {
if(i != 0){
shadowText += ',\n';
}
shadowText += Math.round(getShadow[i].offsetX / Rate) + keyCode + ' ' + Math.round(getShadow[i].offsetY / Rate) + keyCode + ' ' + Math.round(getShadow[i].blurRadius / Rate) + keyCode + ' ' + Math.round(getShadow[i].spread / Rate) + keyCode + ' ' + getShadow[i].color + (getShadow[i].type == 'inner' ? ' inset': '');
}
returnText.push(shadowText + ';');
}

var width = selection.rect().size.width / Rate;
var height = selection.rect().size.height / Rate;
returnText.push('width: ' + Math.round(width - borderless) + keyCode + ';');
Expand Down

0 comments on commit 3842b28

Please sign in to comment.