nilssonH / sketch-color-parser

Parses all colors used in Sketch v43+ files.
https://nilshoenson.github.io/sketch-color-parser/
27 stars 1 forks source link

No Text Layer colors get parsed #1

Open nilssonH opened 7 years ago

nilssonH commented 7 years ago

Currently the only colors that get parsed are used on shapes. The current JSON output of Sketch archived the colors of a Text layer, so I still need to find a way to unarchive it.

rborn commented 7 years ago

@nilshoenson they are binary plist data encoded to base64 😉

nilssonH commented 7 years ago

@rborn Thanks, didn't know that! Will take a look at it.

rborn commented 7 years ago

@nilshoenson just a note, the base64 string has some escaped chars like \/, you will need to unescape them. I lost some time till I figured out this 😄

samasmith89 commented 7 years ago

@nilshoenson @rborn Did either of you successfully get the base64 plist converted into rgba or hex, using pure javascript? I'm trying to create a very similar Sketch Color Parser, but I really need to be able to access text colors in addition to shape colors.

Here is a snippet of my app, along with the console output. I'm logging 1) the raw encoded NSColor archive, 2) the decoded base64 string, and 3) the plist file that I parsed from the decoded string.

sketch_color_plugin

Yet, this plist file is thousands of key/string pairs that look like total gibberish (here's an excerpt of the plist output):

sketch_color_plugin_2

Have y'all had more success than I have in terms of converting an NSColor to a HEX color? Is there anything noticeably wrong with my code or my output?

samasmith89 commented 7 years ago

Also, I just noticed upon closer examination that the exact rgba color value of my text is nested inside of the decoded archive string (see highlighted section):

sketch_color_plugin_3

I suppose I could use regex to extract this string from the decoded archive, but that seems like a very buggy approach...