├── .appcast.xml
├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── docs
└── share-as-is-demo.gif
├── package-lock.json
├── package.json
├── share-as-is.sketchplugin
└── Contents
│ └── Sketch
│ ├── manifest.json
│ └── plugin.js
└── src
├── analytics.js
├── constants.js
├── manifest.json
├── plugin.js
├── rasterize.js
├── sound.js
└── utils.js
/.appcast.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 | -
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.{js,json,html,md}]
2 | charset = utf-8
3 | indent_style = space
4 | indent_size = 2
5 | insert_final_newline = true
6 | trim_trailing_whitespace = true
7 | end_of_line = lf
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # build artefacts
2 | share-as-is.sketchplugin.zip
3 |
4 | # npm
5 | node_modules
6 | .npm
7 | npm-debug.log
8 |
9 | # mac
10 | .DS_Store
11 |
12 | # IDE
13 | .idea
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Andrey Shakhmin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sketch Share As Is!
2 |
3 | This [SketchApp](https://sketchapp.com/) plugin allows to quickly copy selected or all artboards on the page to clipboard as a raster image the way artboards look in Sketch canvas and paste the resulting image whenever you want (Slack, Skype, 3rd party sharing services, etc). A perfect tool for sharing work in progress with your teammates!
4 |
5 | ## Installation
6 |
7 | 1. Download [share-as-is.sketchplugin.zip](https://github.com/turbobabr/sketch-share-as-is/releases/download/v1.0.1/share-as-is.sketchplugin.zip) archive with the plugin.
8 | 2. Un-zip downloaded archive and double-click `share-as-is.sketchplugin` file to install.
9 |
10 | ## Usage
11 |
12 | Select certain artboards you want to copy to the clipboard and hit `control-option-c` shortcut. To copy the entire page "as is", just deselect currently selected layers and use the same shortcut:
13 |
14 | 
15 |
16 | ## Version history
17 |
18 | **Share As Is! - 1.0.1: 3/16/2018**
19 | * Sketch 49 support
20 |
21 | **Share As Is! - 1.0.0: 8/11/2017**
22 | * First version
23 |
24 | ## Feedback
25 |
26 | If you discover any issue or have any suggestions, please [open an issue](https://github.com/turbobabr/sketch-share-as-is/issues) or find me on twitter [@turbobabr](http://twitter.com/turbobabr).
27 |
28 | ## License
29 |
30 | The MIT License (MIT)
31 |
32 | Copyright (c) 2017 Andrey Shakhmin
33 |
34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
35 |
36 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
37 |
38 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 |
--------------------------------------------------------------------------------
/docs/share-as-is-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/turbobabr/sketch-share-as-is/42b73e9e088556d3dc296fec99b808f06b20037e/docs/share-as-is-demo.gif
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sketch-share-as-is",
3 | "version": "1.0.1",
4 | "description": "Quickly copy to clipboard and share artboards the way they look in Sketch itself, with titles, borders and backgrounds.",
5 | "scripts": {
6 | "build": "skpm-build",
7 | "watch": "skpm-build --watch",
8 | "start": "skpm-build --watch --run",
9 | "postinstall": "npm run build && skpm-link"
10 | },
11 | "repository": {
12 | "type": "git",
13 | "url": "git+https://github.com/turbobabr/sketch-share-as-is.git"
14 | },
15 | "author": "Andrey Shakhmin",
16 | "license": "MIT",
17 | "bugs": {
18 | "url": "https://github.com/turbobabr/sketch-share-as-is/issues"
19 | },
20 | "homepage": "https://github.com/turbobabr/sketch-share-as-is#readme",
21 | "skpm": {
22 | "name": "Share As Is!",
23 | "manifest": "src/manifest.json",
24 | "main": "share-as-is.sketchplugin",
25 | "assets": [
26 | "assets/**/*"
27 | ]
28 | },
29 | "devDependencies": {
30 | "@skpm/builder": "^0.4.0"
31 | },
32 | "dependencies": {
33 | "lodash": "^4.17.4",
34 | "sketch-color": "^0.1.1",
35 | "sketch-constants": "^1.1.0",
36 | "tinycolor2": "^1.4.1"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/share-as-is.sketchplugin/Contents/Sketch/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "identifier": "com.turbobabr.sketch.share-as-is",
3 | "author": "Andrey Shakhmin",
4 | "compatibleVersion": 3,
5 | "bundleVersion": 1,
6 | "commands": [
7 | {
8 | "name": "Copy to Clipboard",
9 | "identifier": "copyToClipboard",
10 | "shortcut": "control option c",
11 | "script": "plugin.js"
12 | }
13 | ],
14 | "menu": {
15 | "title": "Share As Is!",
16 | "items": [
17 | "copyToClipboard"
18 | ]
19 | },
20 | "version": "1.0.1",
21 | "description": "Quickly copy to clipboard and share artboards the way they look in Sketch itself, with titles, borders and backgrounds.",
22 | "homepage": "https://github.com/turbobabr/sketch-share-as-is#readme",
23 | "name": "Share As Is!",
24 | "disableCocoaScriptPreprocessor": true,
25 | "appcast": "https://raw.githubusercontent.com/turbobabr/sketch-share-as-is/master/.appcast.xml"
26 | }
--------------------------------------------------------------------------------
/src/analytics.js:
--------------------------------------------------------------------------------
1 |
2 | import { UUIDKey } from './constants';
3 |
4 | export const logEvent = (event, props) => {
5 | let uuid = NSUserDefaults.standardUserDefaults().objectForKey(UUIDKey);
6 | if (!uuid) {
7 | uuid = NSUUID.UUID().UUIDString();
8 | NSUserDefaults.standardUserDefaults().setObject_forKey(uuid, UUIDKey);
9 | }
10 |
11 | const fProps = {
12 | token : "9ce1b980de746d30a6fb36830b4f4eee",
13 | sketchVersion : NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString"),
14 | uuid : uuid,
15 | pluginVersion : coscript.printController().pluginBundle().version()
16 | };
17 |
18 | if (props) {
19 | for (let key in props)
20 | fProps[key] = props[key];
21 | }
22 |
23 | const payload = {
24 | event : event,
25 | properties : fProps
26 | },
27 | json = NSJSONSerialization.dataWithJSONObject_options_error(payload, 0, nil),
28 | base64 = json.base64EncodedStringWithOptions(0),
29 | url = NSURL.URLWithString(NSString.stringWithFormat("https://api.mixpanel.com/track/?data=%@&ip=1", base64));
30 |
31 | if(url) {
32 | NSURLSession.sharedSession().dataTaskWithURL(url).resume();
33 | }
34 | };
35 |
36 |
--------------------------------------------------------------------------------
/src/constants.js:
--------------------------------------------------------------------------------
1 | export const Commands = {
2 | CopyToClipboard: 'copyToClipboard',
3 | Settings: 'settings'
4 | };
5 |
6 | export const UUIDKey = 'com.turbobabr.share-as-is.uuid';
--------------------------------------------------------------------------------
/src/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "identifier" : "com.turbobabr.sketch.share-as-is",
3 | "author" : "Andrey Shakhmin",
4 | "compatibleVersion": 3,
5 | "bundleVersion": 1,
6 | "commands": [
7 | {
8 | "name": "Copy to Clipboard",
9 | "identifier": "copyToClipboard",
10 | "shortcut": "control option c",
11 | "script": "./plugin.js"
12 | }
13 | ],
14 | "menu": {
15 | "title": "Share As Is!",
16 | "items": [
17 | "copyToClipboard"
18 | ]
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/plugin.js:
--------------------------------------------------------------------------------
1 |
2 | import Utils from './utils';
3 | import { Commands } from './constants';
4 | import { playSystemSound, SystemSounds } from './sound';
5 |
6 | import rasterize from './rasterize';
7 | import { logEvent } from './analytics';
8 |
9 | export default function (context) {
10 | switch(Utils.normalize(context.command.identifier())) {
11 | case Commands.CopyToClipboard:
12 | let image = rasterize(context.document,context.selection);
13 | if(image) {
14 | const pasteboard = NSPasteboard.generalPasteboard();
15 | pasteboard.clearContents();
16 | pasteboard.writeObjects(NSArray.arrayWithObject(image));
17 |
18 | playSystemSound(SystemSounds.Pop);
19 | context.document.showMessage('[share-as-is]: Resulting image has been copied to the clipboard.');
20 |
21 | logEvent('copyToClipboard',{
22 | isEntirePage: context.selection.count() < 1,
23 | copiedArtboards: context.selection.valueForKeyPath('@distinctUnionOfObjects.parentArtboard').count(),
24 | totalArtboards: context.document.currentPage().artboards().count()
25 | });
26 | }
27 |
28 | break;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/rasterize.js:
--------------------------------------------------------------------------------
1 |
2 | import _ from 'lodash';
3 | import colorToMSColor from 'sketch-color';
4 | import tinycolor from 'tinycolor2';
5 | import { TextBehaviour, ExportOptionsFormat } from 'sketch-constants';
6 | import Utils from './utils';
7 |
8 | const colorToNSColor = (color) => {
9 | const rgba = tinycolor(color).toRgb();
10 | return NSColor.colorWithRed_green_blue_alpha(rgba.r / 255.0, rgba.g / 255.0, rgba.b / 255.0, rgba.a);
11 | };
12 |
13 | const addArtboardBlock = (page,artboard,useCustomLabelsForSymbols = true) => {
14 | let shape = MSShapeGroup.shapeWithRect(artboard.rect());
15 | shape.style().addStylePartOfType(0).color = colorToMSColor('white');
16 |
17 | let shadow = shape.style().addStylePartOfType(2);
18 | shadow.offsetX = 0;
19 | shadow.offsetY = 1;
20 | shadow.color = colorToMSColor('rgba(0,0,0,0.3)');
21 | shadow.blurRadius = 3;
22 |
23 | page.insertLayer_atIndex(shape,1);
24 |
25 | // Add label
26 | let label = MSTextLayer.alloc().init();
27 | label.stringValue = artboard.name();
28 | label.textBehaviour = TextBehaviour.Fixed;
29 |
30 | let textStyle = label.style().textStyle();
31 |
32 | const lineHeight = 24;
33 |
34 | let paragraphStyle = NSMutableParagraphStyle.alloc().init();
35 | paragraphStyle.minimumLineHeight = lineHeight;
36 | paragraphStyle.maximumLineHeight = lineHeight;
37 | paragraphStyle.lineBreakMode = NSLineBreakByTruncatingMiddle;
38 |
39 | const labelColor = artboard.isKindOfClass(MSSymbolMaster) && useCustomLabelsForSymbols ? '#7B20A5' : '#5F5F5F';
40 | let attributes = {
41 | 'NSFont': NSFont.systemFontOfSize_weight(11,NSFontWeightLight),
42 | 'NSColor': colorToNSColor(labelColor),
43 | 'NSKern': 0.1,
44 | 'NSParagraphStyle': paragraphStyle
45 | };
46 |
47 | textStyle.attributes = attributes;
48 |
49 | const rect = artboard.rect();
50 |
51 | label.rect = CGRectMake(rect.origin.x+3,rect.origin.y-lineHeight+1,rect.size.width-3,lineHeight);
52 | page.insertLayer_atIndex(label,page.layers().count());
53 |
54 | return [shape,label];
55 | };
56 |
57 | const rasterize = (document,selection,options = {}) => {
58 | let documentData = document.documentData().copyWithOptions(1);
59 | let page = documentData.currentPage();
60 | if(page.layers().count() < 1) {
61 | return null;
62 | }
63 |
64 | let artboards = NSArray.arrayWithArray([]);
65 | let rect = null;
66 |
67 | let exportSelectedLayersOnly = false;
68 |
69 | if(selection.count() < 1) {
70 | const layers = page.layers();
71 | for(let i=0;i {
81 | const shadowArtboard = documentData.layerWithID(artboard.objectID());
82 | if(shadowArtboard) {
83 | shadowArtboards.push(shadowArtboard);
84 | }
85 | });
86 |
87 | artboards = NSArray.arrayWithArray(shadowArtboards);
88 | _.each(Utils.normalize(artboards),(artboard) => {
89 | artboard.includeBackgroundColorInExport = true;
90 | });
91 |
92 | let layers = artboards;
93 | for(let i=0;i board);
111 | let addedLayers = [];
112 | _.each(boards,(board) => {
113 | if(board.isKindOfClass(MSArtboardGroup)) {
114 | addedLayers = addedLayers.concat(addArtboardBlock(page,board));
115 | }
116 | });
117 |
118 | const request = MSExportRequest.alloc().init();
119 | request.rect = rect;
120 | request.scale = 1;
121 | request.shouldTrim = false;
122 | request.format = ExportOptionsFormat.PNG;
123 | request.immutableDocument = documentData.immutableModelObject();
124 | request.rootLayer = page.immutableModelObject();
125 | request.includeArtboardBackground = true;
126 |
127 | if(exportSelectedLayersOnly) {
128 | let includedLayerIDs = NSMutableSet.alloc().init();
129 | _.each(boards.concat(addedLayers).concat([shape]),(board) => {
130 | const objectIDs = request.objectIDsForSelfAncestorsAndChildrenOfAncestry(MSImmutableLayerAncestry.ancestryWithMSLayer(board));
131 | includedLayerIDs.unionSet(objectIDs);
132 | });
133 |
134 | request.includedLayerIDs = NSSet.setWithSet(includedLayerIDs);
135 | request.options = 1;
136 | }
137 |
138 | const exporter = MSExporter.exporterForRequest_colorSpace(request, NSColorSpace.sRGBColorSpace());
139 | return exporter.image();
140 | };
141 |
142 | export default rasterize;
143 |
--------------------------------------------------------------------------------
/src/sound.js:
--------------------------------------------------------------------------------
1 | export const SystemSounds = {
2 | Basso: "Basso",
3 | Blow: "Blow",
4 | Bottle: "Bottle",
5 | Frog: "Frog",
6 | Glass: "Glass",
7 | Hero: "Hero",
8 | Morse: "Morse",
9 | Ping: "Ping",
10 | Pop: "Pop",
11 | Purr: "Purr",
12 | Sosumi: "Sosumi",
13 | Submarine: "Submarine",
14 | Tink: "Tink"
15 | };
16 |
17 | export function playSystemSound(soundName) {
18 | const sound = NSSound.soundNamed(soundName);
19 | if(!sound) {
20 | return;
21 | }
22 |
23 | sound.play();
24 | }
25 |
--------------------------------------------------------------------------------
/src/utils.js:
--------------------------------------------------------------------------------
1 | import _ from 'lodash';
2 |
3 | const Utils = {};
4 |
5 | Utils.normalizeObject = (obj) => {
6 | if(!obj) {
7 | return null;
8 | }
9 |
10 | if(obj.isKindOfClass(NSString)) {
11 | return obj.UTF8String();
12 | } else if(obj.isKindOfClass(NSValue)) {
13 | return obj + 0;
14 | } else if(obj.isKindOfClass(NSDictionary)) {
15 | return _.fromPairs(_.map(obj,(value,key) => {
16 | return [key,Utils.normalizeObject(value)];
17 | }));
18 | } else if(obj.isKindOfClass(NSArray)) {
19 | return _.map(obj,(value) => {
20 | return Utils.normalizeObject(value);
21 | });
22 | }
23 |
24 | return obj;
25 | };
26 |
27 | Utils.normalize = (obj) => { // Alias for `normalizeObject`
28 | return Utils.normalizeObject(obj);
29 | };
30 |
31 | export default Utils;
--------------------------------------------------------------------------------