This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let sketch = require('sketch') | |
| let doc = sketch.getSelectedDocument() | |
| let libraries = sketch.getLibraries() | |
| let textStyles = doc.sharedTextStyles | |
| //var importedStyles = [] | |
| //var textStyleRefs = libraries.getImportableTextStyleReferencesForDocument(doc) | |
| //textStyleRefs.forEach( ref => importedStyles.push(ref.import())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Frame extends Component { | |
| componentDidMount() { | |
| this.iframeHead = this.node.contentDocument.head | |
| this.iframeRoot = this.node.contentDocument.body | |
| this.forceUpdate() | |
| } | |
| render() { | |
| const { children, head, ...rest } = this.props | |
| return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @desc Creates a list of domains with custom TLDs using a pattern string with fixed length with option for keywords | |
| // @param {String} pattern | |
| // @param {Array|String} tlds | |
| // @returns {Array} domainList | |
| // | |
| // | |
| // Pattern string is defined by: | |
| // - keywords lowercase | |
| // - any letter uppercase A | |
| // - consonants uppercase C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mouseInCanvasViewForDocument(document) { | |
| var mouseInWindow = document.documentWindow().convertScreenToBase(NSEvent.mouseLocation()); | |
| return document.contentDrawView().convertPoint_fromView(mouseInWindow,null); | |
| } | |
| function CGPointToObject(point) { | |
| return { | |
| x: point.x.doubleValue(), | |
| y: point.y.doubleValue() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let selection = doc.selectedLayers | |
| selection.forEach(layer => { | |
| var sel = layer.sketchObject | |
| if (sel.resizeToFitChildrenWithOption) { | |
| sel.resizeToFitChildrenWithOption(0); | |
| } else { | |
| sel.fixGeometryWithOptions(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let sketch = require('sketch') | |
| let doc = sketch.getSelectedDocument() | |
| let selectedArtboard = doc.selectedLayers.layers[0] | |
| var request = NSMutableURLRequest.alloc().init(); | |
| request.setHTTPMethod_("GET"); | |
| request.setURL(NSURL.URLWithString('https://upload.wikimedia.org/wikipedia/commons/5/59/Sketch_Logo.svg')); | |
| var responseData = NSURLConnection.sendSynchronousRequest_returningResponse_error(request,nil,nil); | |
| var stringResponse = NSString.alloc().initWithData_encoding(responseData,NSUTF8StringEncoding]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Sketch = require('sketch') | |
| framework("CoreText"); | |
| let myTextLayer = Sketch.getSelectedDocument().selectedLayers.layers[0] | |
| let textLayer = myTextLayer.sketchObject | |
| if (textLayer.isEditingText() == 0) { | |
| console.log("select some text") | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let sketch = require('sketch') | |
| let doc = sketch.getSelectedDocument() | |
| let selectedLayersObject = doc.selectedLayers | |
| let selectedLayersArray = selectedLayersObject.layers | |
| let interalLayersArray = selectedLayersArray.map(layer => layer.sketchObject) | |
| // convert your JS layers to internal Sketch Objects | |
| let msLayerArray = MSLayerArray.arrayWithLayers(interalLayersArray) | |
| // MSSymbolCreator actually needs this MSLayerArray object, not just a NSArray of MSLayers for some reason |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sketch = require('sketch') | |
| export default () => { | |
| const doc = sketch.getSelectedDocument() | |
| const selectedArtboard = doc.selectedLayers.layers[0] | |
| function selectChildren(layer) { | |
| layer.selected = true | |
| if (layer.layers) { | |
| layer.layers.forEach(selectChildren) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| selection.sketchObject.resizeToFitContentsIfNeededNoCache() //重置 symbol 尺寸 | |
| layer.select_byExpandingSelection(true,false) // 设置图层为选中状态 |