Sketch.app JSON 插件库
提供基于 JSON 格式的插件的功能, 而不是学习所有素描的私人 API 对象 .
这是在 Sketch 插件环境内使用; 要完全在节点生成草图文件, 您需要不同的库 .
有两个主要的API:
// Converts an object, eg from context.selection into a JSON string representation
toSJSON(sketchObject);
// Takes a Sketch JSON tree and turns it into a native object. May throw on invalid data
fromSJSON(json);
此外,如果您想从词典中创建层,您想要这样:
// Pass in a javascript object literal
const obj: SJTextLayer = {
"_class": "text",
"do_objectID": generateID(),
"frame": {
"_class": "rect",
"constrainProportions": false,
"height": 17,
"width": 117,
"x": 146,
"y": 253
},
"isVisible": true,
"name": "My hot hot ABCD",
...
};
fromSJSONObject(obj);
如果您想要验证您的版本 Sketch 兼容( v43+) :
import JSONPlugin from 'sketchapp-json-plugin';
if (JSONPlugin.appVersionSupported()) {
const layer = SJSON.fromSJSON(myJSON);
...
document.pages[0].addLayers([layer]);
} else {
// Use old code path
}