Giter Site home page Giter Site logo

ingrammicro / puzzle-tokens Goto Github PK

View Code? Open in Web Editor NEW
92.0 13.0 17.0 55.47 MB

Batch create, manage and update Sketch styles and symbols using SCSS/LESS

License: GNU General Public License v3.0

JavaScript 81.32% CSS 0.72% Shell 0.28% Less 8.68% SCSS 8.96% Sass 0.03%
sketch-plugin less design-systems design-tokens sass css

puzzle-tokens's Introduction

Puzzle Tokens

Puzzle Tokens is a Sketch plugin to specify and apply design tokens (in LESS or SCSS format) to Sketch layers (with shared styles) with auto styles preview generation.

Check this article to get a detailed overview with examples and join Discussions for live talk

Installation

  1. Download zip file
  2. Unarchive and install
  3. Download and install Node.js
  4. Instal less or sass using the following Terminal commands:
sudo -s
npm i less -g
npm i sass -g
  1. Now you're good to go!

Usage

  1. Download Example 1.
  2. Open Library.sketch file in Sketch.app
  3. Run Plugins > Puzzle Tokens > Apply Design Tokens menu command
  4. Specify LESS file according to screenshot

  1. Repeat the same operation, but select "tokens-blue.less" file. See how styles and widgets look now.

Features

The following CSS styles are supporting.

// Text Layers

.TextStyle {
    // Sketch only styles
    pt-paragraph-spacing:  23.33;
    pt-text:               "New text content";
    -pt-text-size-behaviour: fixed-size;    // or "auto-height" or  "auto-width"           

    // CSS native styles
    font-size:             12px;   
    font-family:           "Open Sans";     // or "Open Sans","Times New Roman"
    font-weight:           bold;            // or extra-light, light, regular, medium, semibold, bold OR fa-solid (special trick to define FontAwesome solid icon)
    font-style:            italic;          // or normal
    line-height:           1.0;             // or 1.2 or 1.5 or any other mulitplier for font-size OR 10px
    color:                 #FFFFFF;         // HEX value OR any other CSS-compatible color values, such as red or black OR color variable name in double quotes
    opacity:               63%;             // supported "63%" or "0.42"
    text-transform:        uppercase;       // "uppercase", "lowercase", "none"
    text-decoration:       underline;       // "underline", "line-through"
    text-align:            left;            // "left", center", "right", "justify"
    vertical-align:        top;             // "top", "middle", "bottom"
    letter-spacing:        10px;            // <value>px OR "normal"
}

// Shape layers

.ShapeStyle {
    // SKETCH only properties
    border-position:       center;    // center OR inside OR outside
    border-line-end:            butt;      // butt / round / projecting
    border-line-join:           miter;     // miter / round / bevel
    border-start-arrowhead:     openarrow; // none / openarrow / filledarrow / opencircle / filledcircle / opensquare / filledsquare
    border-end-arrowhead:       openarrow; // none / openarrow / filledarrow / opencircle / filledcircle / opensquare / filledsquare            
    -pt-border-update:          true;  // Use it if you want to replace an existing border, instead of adding a new one.
    -pt-fill-update:            true;  // Use it if you want to replace an existing fill, instead of adding a new one.

    /// CSS native properties
    background-color:      #B0AFB1;
    background-color:      linear-gradient(45deg, #000000,#B0AFB4);
    background-color:      linear-gradient(134deg, #004B3A 0%, #2D8B61 51%, #9BD77E 100%);
    background-color:      "mycolors/color01"; // assign color variable
    opacity:               63%;       // "63%" or "0.42"
    border-color:          #000000;
    border-color:          linear-gradient(45deg, #000000,#B0AFB4);
    border-color:          linear-gradient(134deg, #004B3A 0%, #2D8B61 51%, #9BD77E 100%);
    border-color:          "mycolors/color01"; // assign color variable
    border-width:          2px;
    border-style:          dotted;    // dotted OR dashed

    box-shadow:            none; // Clear any existing shadows from the layer style.
    box-shadow:            0 10px 20px 2 #FF00FF;
    box-shadow:            inset 0 10px 20px 2 rgba(0,0,0,0.1);
    box-shadow:            0 10px 20px 2 rgba(0,0,0,0.1), inset 0 10px 20px 2 rgba(0,0,0,0.1);
    -pt-shadow-update:          true;  // Use it if you want to replace any previous shadows, instead of adding a new one.

    mix-blend-mode:         normal; // normal / darken / multiply / color-burn / lighten / screen / color-dodge / overlay / difference 
                                    // exclusion / hue / saturation / color / luminosity
     
    // !!ATTENTION!!
    // Shared styles don't include radius property,
    // still you can set the radius-border for a style.
    // Border radius will be reapplied to layers
    // through style assigned to it. You can also
    // apply it to the layers or symbols directly.

    border-radius:         5px;
    border-radius:         5px 5px 0 0;
}

// Text & Shape Layer Common Properties
.Style{
    // Sketch only styles
    -pt-layer-type:          text; // "layer" or "text" // Usefull to help PT to understnand the type of the layer
    -pt-pin-left:            true; // "true" or "false
    -pt-pin-right:           true; // "true" or "false          
    -pt-pin-top:             true; // "true" or "false
    -pt-pin-bottom:          true; // "true" or "false
    -pt-fix-size-height:     true; // "true" or "false
    -pt-fix-size-width:      true; // "true" or "false
    -pt-skip-missed:         true: // "true" or "false // Usefull to skip style if no layer
                                                       // found without an error
    -pt-resize-symbol:      true:  //  resize layer owner (symbol master) to a layer size

    // The following properties are not a part of shared styles.
    // Bu you can set these properties for a shared style.
    // These properties will be reapplied to layers
    // through style assigned to it. You can also
    // apply it to the layers or symbols directly.

    width:                  100px;
    height:                 100px;

    margin-top:             10px;
    margin-left:            20px;
    margin-right:           20px;
    margin-bottom:          10px;
    
    // By default, margin is set relative to the layer's containing artboard or page.
    // (Specifically, the layer is moved so that it is positioned inside the artboard/
    // page at the specified margin. In the example above, the top-left corner of the
    // layer is set to x:10 and y:20 of the containing artboard.)
    //
    // If you prefer to set the margin  relative to another layer (for example, to set 
    // the text layer of a button within the boundaries of the button's background
    // layer style), use the "-pt-margin-relative-to" property shown below.
    
    -pt-margin-relative-to: "layer name"; // set margin values relative to the specified
                                          // layer. The specified layer must be a sibling
                                          // (at the same level in a group, artboard, or
                                          // symbol) of the layer to which you are
                                          // applying the margin styles. If not specified,
                                          // margin will be set relative to the artboard
                                          // or page
    -pt-margin-resize:      true;         // if true, resize the "margin-relative-to"
                                          // layer to "fit" the size of the current layer,
                                          // plus the specified margin. This will make
                                          // the "margin-relative-to" layer surround
                                          // the current layer at exactly the requested
                                          // margin.


    -pt-valign:                     middle; // middle / top / bottom : align vertically inside a parent
}

// Group & SymbolMaster Properties
#Group{
    -pt-smartlayout:         LeftToRight; // LeftToRight OR HorizontallyCenter OR RightToLeft OR TopToBottom 
                                          // OR VerticallyCenter OR BottomToTop OR None
}

// Group, SymbolMaster and Artboard Properties
#Symbol{
    -pt-fit-content:        true;        // Resize to fit content
}

// SymbolMaster properties
#Symbol{
    -pt-resize-instances:   true;        // Resize all instances of a symbol; the same as
                                         // clicking Sketch's "Shrink instance to fit
                                         // content" button in the Overrides section of
                                         // the instance. (This reapplies SmartLayout,
                                         // useful when you change the size of a symbol.)
}

// Symbol Instance Properties
#Card .IconButton {                      // Path to a symbol-instance layer

    // You can change the symbol source for a symbol override (for example, to switch
    // the icon displayed in a symbol instance). Usage is:
    // -pt-override-symbol: ('AffectedLayerName', '#Path #To #New #Symbol');
    //
    // In the example shown here, the Card symbol has a symbol instance in a layer named
    // IconButton. If that IconButton instance has a symbol override in layer RightIcon,
    // you can set the icon to a new icon by sharing its Puzzle Tokens path like so:
    
    -pt-override-symbol:    ('RightIcon ', '#Icons #Arrows #RightArrow');
    
    // Set the path to 'none' to disable the symbol override and show nothing at all.
}

#Image{
    // Required Properties
    image:                 ~"images/new-logo.jpg";  // OR transparent
    // Optional Properties
    border-color:          white;
    border-width:          3px;
    box-shadow:            0 10px 20px 2 #FF00FF;
    width:                 100px;  // OR 50 %
    height:                100px;  // OR 50 %
    top:                   11px;
    bottom:                22px;
    left:                  2px;
    right:                 33px;
}

You can look into more examples to get familiar with the plugin.

Supported Targets

You can update the following Sketch objects.

// Update shared style
.MyStyles .Group .Style1{
    color: #FFFFFF;
}

// Update symbol child style properties
#MySymbols #Buttons #Submit{
    .Text{
        color: #FFFFFF;
    }
}

// Update artboard child style properties
#MyArtboard #Group1{
    .Rectangle{
        color: #FFFFFF;
    }
}

// Assign shared style to artboard/symbol child
#MySymbols #Buttons #Submit{
    .Text{
        sktext-style: "MyStyle/Group/Style1";
    }
    .Back{
        sklayer-style: "MyStyle/Group/Back";
    }
}

// Update color variables  !!!!!!!! DONT USE GRADIENTS FOR COLOR VARIABLES. SKETCH WILL CRASH !!!!! 
.--COLORS-{
    .primary{
        color:                                      black;
    }
    .secondary{
        color:                                      grey;
    }
}

Special Tricks for Selector Names

  • To start a style or symbol name from a number just add --PT- prefix. So, "--PT-1 Style" will be transformed to "1 Style".
  • To start a style or symbol name from a dot just use -DOT- special keyword. So, "-DOT-Style" will be transformed to ".Style"
  • To use a space inside a style or symbol name you can uses a space (but formally it will not be a CSS compartible notation) or replace space by __ .So "My__First__Style" wil be transformed to "My First Style

Required Style Properties

To apply text style you need to defined at least one of the following properites:

  • color
  • font-family
  • font-size
  • font-weight
  • text-transform
  • text-align
  • vertical-align
  • pt-paragraph-spacing

For layer style:

  • background-color
  • border-color
  • box-shadow
  • border-radius
  • opacity

To create _image:

  • image

To assign shared style to layer:

  • sklayer-style
  • sktext-style

Sketch versions supported

Some styles, such as text font/transformation/etc require Sketch 53 or later. You're safe using the latest stable Sketch version to get the plugin working.

Demos

https://www.dropbox.com/s/f25cfsm26vgeu62/Recording1.mov?dl=0

Command line API

#!/bin/bash
context="{\"file\":\"${HOME}/GitHub/puzzle-tokens/Styles/material-palettes/palettes.sketch\""
# The following line is optional
context="${context},\"saveAs\":\"${HOME}/GitHub/puzzle-tokens/Styles/material-palettes/palettes_new.sketch\""
context="${context},\"styles\":\"${HOME}/GitHub/puzzle-tokens/Styles/material-palettes/scss/palettes.scss\""
context="${context},\"commands\":\"apply,save,close\"}"
echo $context
/Applications/Sketch.app/Contents/Resources/sketchtool/bin/sketchtool --without-activating=YES --new-instance=No run ~/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins/PuzzleTokens.sketchplugin "cmdRun" --context=$context

Compact variant:

/Applications/Sketch.app/Contents/Resources/sketchtool/bin/sketchtool --without-activating=YES --new-instance=No run ~/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins/PuzzleTokens.sketchplugin "cmdRun" --context="{\"file\":\"${HOME}/GitHub/puzzle-tokens/Styles/material-palettes/palettes.sketch\",\"styles\":\"${HOME}/GitHub/puzzle-tokens/Styles/material-palettes/scss/palettes.scss\",\"commands\":\"apply,save,close\"}"

puzzle-tokens's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puzzle-tokens's Issues

Getting errors trying to run LESS styles.

Started
Read LESS: running...
/usr/local/lib/node_modules/less
internal/modules/cjs/loader.js:797
    throw err;
    ^

Error: Cannot find module '/usr/local/lib/node_modules/less'
Require stack:
- /private/var/folders/k8/vy_1t24s075cnqhjpy2f6qx80000gn/T/nsconvert_less.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at transformLESStoJSON (/private/var/folders/k8/vy_1t24s075cnqhjpy2f6qx80000gn/T/nsconvert_less.js:96:16)
    at Object.<anonymous> (/private/var/folders/k8/vy_1t24s075cnqhjpy2f6qx80000gn/T/nsconvert_less.js:27:1)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/private/var/folders/k8/vy_1t24s075cnqhjpy2f6qx80000gn/T/nsconvert_less.js'
  ]
}

Less is installed:

which less
/usr/bin/less

Any suggestions? Thanks!

TypeError, plugin not working through the CLI anymore

PROCESS /Users/vincentk/Versions/ConnectApp/connect_app_atomic_library-vm.sketch
APPLY STYLES...
TypeError: undefined is not an object (evaluating 'this.pathToSource.substring')
at run (/Users/vincentk/Library/Application Support/com.bohemiancoding.sketch3/Plugins/PuzzleTokens.sketchplugin/Contents/Sketch/cmdline-functions.js:2007:52)
at runFromCmd (/Users/vincentk/Library/Application Support/com.bohemiancoding.sketch3/Plugins/PuzzleTokens.sketchplugin/Contents/Sketch/cmdline-functions.js:1979:33)
at applyStyles (/Users/vincentk/Library/Application Support/com.bohemiancoding.sketch3/Plugins/PuzzleTokens.sketchplugin/Contents/Sketch/cmdline-functions.js:4058:22)
at /Users/vincentk/Library/Application Support/com.bohemiancoding.sketch3/Plugins/PuzzleTokens.sketchplugin/Contents/Sketch/cmdline-functions.js:4131:36
at value (/Applications/Sketch.app/Contents/Resources/SketchAPI_dom.js:1:32133)
at cmdRun (/Users/vincentk/Library/Application Support/com.bohemiancoding.sketch3/Plugins/PuzzleTokens.sketchplugin/Contents/Sketch/cmdline-functions.js:4119:18){"file":"/Users/vincentk/Versions/ConnectApp/connect_app_atomic_library-vm.sketch","saveAs":"/Users/vincentk/Versions/ConnectApp/connect_app_atomic_library-sunrise.sketch","styles":"/Users/vincentk/Documents/design-assets/Sunrise/Css/Sunrise.less","commands":"apply,save,close"}

[FR] Create opacity styles without color or other attributes.

It is beneficial to create styles that only contain opacity settings without any other attributes. This would allow us to apply them to groups and other containers as a whole.

I attempted this, but the plugin doesn't seem to create the styles correctly. I tried both decimal and percentage values.

.Opacities .0 {
  opacity: 0;
}
.Opacities .25 {
  opacity: 0.25;
}
.Opacities .50 {
  opacity: 0.5;
}
.Opacities .75 {
  opacity: 0.75;
}
.Opacities .100 {
  opacity: 1;
}

Sketch 66.1 "Error: An Obj-C exception occurred."

I have tried importing demo .less files from the repository, and creating some of my own but I was stuck with the error that opened in plugin window.

"Error: An Obj-C exception occurred."

I am using macOS Mojave and the latest sketch 66.1

(I'll try to upload a screenshot later, firewall restrictions atm.)

Spaces in style name

from
https://spectrum.chat/puzzle-tokens/general/documentation-of-required-attributes~7ffa350a-c423-43ee-a88a-0774d801d78a?m=MTU3NDMwNzgxODI1OA==

josh-tt
@josh1111
6:43am
I just did a test with a new file.
Create a layer in sketch called colors / black(add extra space with cursor here)
Create a style from it
Create a document in puzzle tokens with .colors .black
A new style with be created and you end up with two. So, you have to write .black__ in the scss file and look out for any extra spaces people may have used when creating styles.
Spaces at the end of a style are hard to visually identify, so I missed that one several times. If you try to find the style later, it seems that sketch corrects the space (at least in the latest version), so it looks normal in the components panel which makes it even harder to find, but in the code where sketch stores the style it must still have the space.
Edited

7:07am
Attaching an example example to test, one sec: https://drive.google.com/file/d/17_y3mg_fGzwv_KKaMdaJAMJKl7EdGscC/view?usp=sharing

7:17am
Perhaps, some sort of simple hack debugger that finds styles that are exactly the same, looking (with the exception of spaces) gives you a hint that says - "these two styles were found identically named, but have different spacings, which sketch will interpret to be a new style" would be really helpful to catch on import.
Actually, an alphabetical 2-column inventory would be really useful to debug/check things in general so you can see the old style vs new style. Spaces could be highlighted.

Output in the CLI

Hi,

Did you find out what is causing this output when running PT through SketchTools?

image

It's not a big problem, but it makes it unclear where in the process my script is :)

[FR] Text Decorations

Would love to have the possibility to add Text Decorations to a style like:
text-decoration:underline;

[FR] Multiple Box-Shadow Properties

Trying to get multiple shadows properties to work but it doesn't seem to work.

For example:
background: rgba(255,255,255,0.00);
box-shadow: 0 7px 40px 0 rgba(0,0,0,0.13), 0 2px 8px 0 rgba(0,0,0,0.24);
border-radius: 4px;

Is this currently supported in the plugin?
57F06D2D-FE96-48E7-ABDE-F4F8B43B38BD

CLI not consequent to using the Plugin from sketch

I've made a shell script that loads a sketch fle, runs puzzle tokens from SketchTool and saves the file with another name.
Since last week when run the script, all my fles have the same .less file applied to them. instead of using different ones like before.

When I run PT from sketch everything works fine. What could be wrong?

Special character in classname

Probably a bit an edge case, but maybe easy to fix?

I want to use the character ฮฉ in the class/layer style name.
This because it is later in the alphabet, and thus later in the list.

I always get the error

Failed to parse SASS with error message:

Cannot read property 'props' of null

I guess it is not an allowed classname in css. would it be possible to fix it e.g. with the --PT- prefix?

If not also fine, then I know I need to go for another solution.

image

Plugin not working on cloud documents

ENOENT: no such file or directory, open '/Users/my-user-name/Library/Application%20Support/com.bohemiancoding.sketch3/CloudDocuments/813d2e60-b534-4276-8d04-20a31f48bb7f/puzle-tokens-text-and-layer-styles-vars.scss'

I am not 100% what goes wrong here? But it seems the in-between JSON/CSS file is not saved correctly.

A workaround, for now, is to make it a local document and then save it to the cloud manually. But ideally would like to see this fixed.

Thanks for the great plugin ๐Ÿ‘ let me know if you need additional details.

[FR] Separate Style Overview pages further by 'which library' the style comes from

Separate the pages further by 'which library' the style comes from, so that people using multiple libraries for different elements have them organized that way. Colors, Icons, Typo etc. and also can catch inconsistencies where styles are used from other libraries.

https://spectrum.chat/puzzle-tokens/general/guys-im-working-on-new-puzzle-tokens-feature-styles-overview-generator~adc65cb7-a14f-40ef-8615-fa8e052ca9a4?m=MTU3Mzg4MTY4MDkyNw==

[FR] Letter Spacing

Would love to see the letterspacing CSS property adopted. Let me know if there is any information I can provide to help with this. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.