├── .commitlintrc.json
├── .eslintrc.json
├── .github
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .prettierrc.js
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── NOTICE
├── README.md
├── __examples__
├── building-from-scratch
│ ├── .gitignore
│ ├── Swatch.js
│ ├── index.js
│ ├── package-lock.json
│ └── package.json
├── generating-sketch-from-style-dictionary
│ ├── .gitignore
│ ├── README.md
│ ├── components
│ │ └── typography.json
│ ├── config.js
│ ├── package-lock.json
│ ├── package.json
│ ├── properties
│ │ ├── color
│ │ │ ├── background.json
│ │ │ ├── brand.json
│ │ │ ├── core.json
│ │ │ └── font.json
│ │ └── size
│ │ │ ├── font.json
│ │ │ └── spacing.json
│ └── sketch
│ │ ├── ColorPage.js
│ │ ├── Swatch.js
│ │ ├── colorGroup.js
│ │ └── index.js
├── getting-styles-from-sketch
│ ├── .gitignore
│ ├── README.md
│ ├── index.js
│ ├── myFile.sketch
│ ├── package-lock.json
│ └── package.json
└── symbols
│ ├── .gitignore
│ ├── index.js
│ ├── package-lock.json
│ └── package.json
├── __tests__
├── __helpers.js
├── __sketch-files
│ ├── test-sketch
│ │ ├── document.json
│ │ ├── meta.json
│ │ ├── pages
│ │ │ ├── 5D6ECF45-F123-477C-B078-12A12853F430.json
│ │ │ └── CAA5BE6B-E854-4A3B-8261-D5522AFF8943.json
│ │ ├── previews
│ │ │ └── preview.png
│ │ └── user.json
│ └── test.sketch
├── building.test.js
├── editing.test.js
├── examples.test.js
└── utils
│ └── resizingConstraints.test.js
├── docs
├── .nojekyll
├── README.md
├── _sidebar.md
├── api.md
├── assets
│ └── theme.css
├── index.html
├── models.md
└── utils.md
├── index.d.ts
├── index.js
├── jsdoc.json
├── models
├── Artboard
│ ├── Artboard.js
│ ├── Artboard.test.js
│ ├── __Artboard.json
│ ├── index.d.ts
│ └── index.js
├── AttributedString
│ ├── AttributedString.js
│ ├── AttributedString.test.js
│ ├── index.d.ts
│ └── index.js
├── Bitmap
│ ├── Bitmap.js
│ ├── Bitmap.test.js
│ ├── index.d.ts
│ └── index.js
├── Blur
│ ├── Blur.js
│ ├── Blur.test.js
│ ├── index.d.ts
│ └── index.js
├── Border
│ ├── Border.js
│ ├── Border.test.js
│ ├── index.d.ts
│ └── index.js
├── BorderOptions
│ ├── BorderOptions.js
│ ├── BorderOptions.test.js
│ ├── index.d.ts
│ └── index.js
├── Color
│ ├── Color.js
│ ├── Color.test.js
│ ├── index.d.ts
│ └── index.js
├── CurvePoint
│ ├── CurvePoint.js
│ ├── CurvePoint.test.js
│ ├── index.d.ts
│ └── index.js
├── Document
│ ├── Document.js
│ ├── Document.test.js
│ ├── index.d.ts
│ └── index.js
├── ExportFormat
│ ├── ExportFormat.js
│ ├── ExportFormat.test.js
│ ├── __ExportFormat.json
│ ├── index.d.ts
│ └── index.js
├── ExportOptions
│ ├── ExportOptions.js
│ ├── ExportOptions.test.js
│ ├── __ExportOptions.json
│ ├── index.d.ts
│ └── index.js
├── Fill
│ ├── Fill.js
│ ├── Fill.test.js
│ ├── index.d.ts
│ └── index.js
├── Gradient
│ ├── Gradient.js
│ ├── Gradient.test.js
│ ├── index.d.ts
│ └── index.js
├── GraphicsContextSettings
│ ├── GraphicsContextSettings.js
│ ├── GraphicsContextSettings.test.js
│ ├── __GraphicsContextSettings.json
│ ├── index.d.ts
│ └── index.js
├── Group
│ ├── Group.js
│ ├── Group.test.js
│ ├── index.d.ts
│ └── index.js
├── InnerShadow
│ ├── InnerShadow.js
│ ├── InnerShadow.test.js
│ ├── __InnerShadow.json
│ ├── index.d.ts
│ └── index.js
├── Layer
│ ├── Layer.js
│ ├── Layer.test.js
│ ├── index.d.ts
│ └── index.js
├── Meta
│ ├── Meta.js
│ ├── Meta.test.js
│ ├── index.d.ts
│ └── index.js
├── Oval
│ ├── Oval.js
│ ├── Oval.test.js
│ ├── index.d.ts
│ └── index.js
├── Page
│ ├── Page.js
│ ├── Page.test.js
│ ├── index.d.ts
│ └── index.js
├── ParagraphStyle
│ ├── ParagraphStyle.js
│ ├── index.d.ts
│ └── index.js
├── Rect
│ ├── Rect.js
│ ├── Rect.test.js
│ ├── index.d.ts
│ └── index.js
├── Rectangle
│ ├── Rectangle.js
│ ├── Rectangle.test.js
│ ├── index.d.ts
│ └── index.js
├── RulerData
│ ├── RulerData.js
│ ├── RulerData.test.js
│ ├── index.d.ts
│ └── index.js
├── Shadow
│ ├── Shadow.js
│ ├── Shadow.test.js
│ ├── index.d.ts
│ └── index.js
├── ShapeGroup
│ ├── ShapeGroup.js
│ ├── ShapeGroup.test.js
│ ├── index.d.ts
│ └── index.js
├── ShapePath
│ ├── ShapePath.js
│ ├── ShapePath.test.js
│ ├── index.d.ts
│ └── index.js
├── SharedStyle
│ ├── SharedStyle.js
│ ├── SharedStyle.test.js
│ ├── index.d.ts
│ └── index.js
├── Sketch
│ ├── Sketch.js
│ ├── Sketch.test.js
│ ├── index.d.ts
│ └── index.js
├── Slice
│ ├── Slice.js
│ ├── index.d.ts
│ └── index.js
├── Star
│ ├── Star.js
│ ├── index.d.ts
│ └── index.js
├── StringAttribute
│ ├── StringAttribute.js
│ ├── StringAttribute.test.js
│ ├── index.d.ts
│ └── index.js
├── Style
│ ├── Style.js
│ ├── Style.test.js
│ ├── index.d.ts
│ └── index.js
├── Swatch
│ ├── Swatch.js
│ ├── Swatch.test.js
│ ├── index.d.ts
│ └── index.js
├── SymbolInstance
│ ├── SymbolInstance.js
│ ├── SymbolInstance.test.js
│ ├── __SymbolInstance.json
│ ├── index.d.ts
│ └── index.js
├── SymbolMaster
│ ├── SymbolMaster.js
│ ├── SymbolMaster.test.js
│ ├── __SymbolMaster.json
│ ├── index.d.ts
│ └── index.js
├── Text
│ ├── Text.js
│ ├── Text.test.js
│ ├── index.d.ts
│ └── index.js
├── TextStyle
│ ├── TextStyle.js
│ ├── TextStyle.test.js
│ ├── index.d.ts
│ └── index.js
├── User
│ ├── User.js
│ ├── User.test.js
│ ├── index.d.ts
│ └── index.js
├── index.d.ts
└── index.js
├── package-lock.json
├── package.json
├── scripts
├── generateDocs.js
└── handlebars
│ ├── body.hbs
│ ├── header.hbs
│ ├── main.hbs
│ └── sig-name.hbs
├── tsconfig.json
└── utils
├── index.d.ts
├── index.js
├── layerToClass.js
├── maps.js
├── paths.js
├── resizingConstraints.js
└── stackLayers.js
/.commitlintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["@commitlint/config-conventional"],
3 | "rules": {
4 | "scope-case": [0, "always", [
5 | "sentence-case",
6 | "start-case",
7 | "lower-case"
8 | ]],
9 | "subject-case": [0, "always", [
10 | "sentence-case",
11 | "start-case",
12 | "lower-case"
13 | ]]
14 | }
15 | }
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true
4 | },
5 | "globals": {
6 | "Buffer": true,
7 | "escape": true
8 | },
9 | "extends": ["airbnb-base", "prettier"],
10 | "plugins": ["prettier"],
11 | "rules": {
12 | "no-console": 0,
13 | "no-underscore-dangle": "off",
14 | "global-require": "off",
15 | "no-param-reassign": "off"
16 | },
17 | "overrides": [
18 | {
19 | "files": ["**/*.test.js"],
20 | "env": {
21 | "jest": true
22 | },
23 | "globals": {
24 | "expect": true,
25 | "beforeAll": true,
26 | "afterAll": true
27 | },
28 | "rules": {
29 | "global-require": "off",
30 | "no-unused-vars": "off",
31 | "import/no-unresolved": "off"
32 | }
33 | },{
34 | "files": ["scripts/*.js"],
35 | "rules": {
36 | "global-require": "off",
37 | "no-unused-vars": "off",
38 | "import/no-unresolved": "off",
39 | "import/no-extraneous-dependencies": "off"
40 | }
41 | }
42 | ]
43 | }
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | *Issue #, if available:*
2 |
3 | *Description of changes:*
4 |
5 |
6 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | __tests__/__output
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | trailingComma: 'es5',
3 | singleQuote: true,
4 | printWidth: 120,
5 | };
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "10"
4 | - "12"
5 | - "14"
6 |
7 | branches:
8 | only:
9 | - master
10 |
11 | jobs:
12 | include:
13 | - stage: test
14 | script: npm run test
15 | - stage: npm release
16 | node_js: "12"
17 | script: echo "Deploying to npm ..."
18 | deploy:
19 | provider: script
20 | skip_cleanup: true
21 | script:
22 | - npx semantic-release
23 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Code of Conduct
2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4 | opensource-codeofconduct@amazon.com with any additional questions or comments.
5 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Sketch Constructor
2 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
--------------------------------------------------------------------------------
/__examples__/building-from-scratch/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | dist/
--------------------------------------------------------------------------------
/__examples__/building-from-scratch/Swatch.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const { Group, Text, Rectangle } = require('sketch-constructor');
15 |
16 | class Swatch extends Group {
17 | constructor(args) {
18 | super({ frame: args.frame });
19 | const swatchColor = new Rectangle({
20 | width: 200,
21 | height: 100,
22 | x: 0,
23 | y: 0,
24 | name: args.value,
25 | style: {
26 | fills: [
27 | {
28 | color: args.value,
29 | },
30 | ],
31 | },
32 | });
33 |
34 | const swatchLabel = new Text({
35 | string: args.label,
36 | name: args.label,
37 | fontSize: 24,
38 | color: '#ccc',
39 | frame: {
40 | width: 200,
41 | height: 50,
42 | x: 0,
43 | y: 120,
44 | },
45 | });
46 |
47 | Object.assign(this, {
48 | layers: [swatchColor, swatchLabel],
49 | name: args.label,
50 | });
51 | }
52 | }
53 |
54 | module.exports = Swatch;
55 |
--------------------------------------------------------------------------------
/__examples__/building-from-scratch/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const fs = require('fs-extra');
15 | const { Sketch, Page, Artboard, SharedStyle } = require('sketch-constructor');
16 | const Swatch = require('./Swatch'); // custom component
17 |
18 | // Output directory
19 | fs.ensureDirSync('./dist');
20 |
21 | const colors = [
22 | {
23 | label: 'Red',
24 | value: '#E53935',
25 | },
26 | {
27 | label: 'Blue',
28 | value: '#1E88E5',
29 | },
30 | {
31 | label: 'Green',
32 | value: '#43A047',
33 | },
34 | {
35 | label: 'Orange',
36 | value: '#ff9900',
37 | },
38 | {
39 | label: 'Purple',
40 | value: '#9c27b0',
41 | },
42 | ];
43 |
44 | const sketch = new Sketch();
45 |
46 | const page = new Page({
47 | name: 'my page',
48 | });
49 |
50 | const artboard = new Artboard({
51 | name: 'my artboard',
52 | frame: {
53 | width: colors.length * 220 + 20,
54 | height: 190,
55 | },
56 | });
57 |
58 | // Iterate over the colors and put our custom Swatch component
59 | // on the artboard and add a layer style.
60 | colors.forEach((color, i) => {
61 | const swatch = new Swatch({
62 | ...color,
63 | frame: {
64 | x: i * 220 + 20,
65 | y: 20,
66 | width: 200,
67 | height: 170,
68 | },
69 | });
70 | const layerStyle = SharedStyle.LayerStyle({
71 | name: color.label,
72 | fills: [
73 | {
74 | color: color.value,
75 | },
76 | ],
77 | });
78 | sketch.addLayerStyle(layerStyle);
79 | artboard.addLayer(swatch);
80 | });
81 |
82 | // Add the pages and artboards to the sketch object
83 | page.addArtboard(artboard);
84 | sketch.addPage(page);
85 | // sketch.addArtboard( page.getID(), artboard );
86 |
87 | // Build the sketch file
88 | sketch.build('./dist/output.sketch').then(() => {
89 | console.log('Built!');
90 | });
91 |
--------------------------------------------------------------------------------
/__examples__/building-from-scratch/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "building-from-scratch",
3 | "version": "0.1.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "npm run build",
8 | "build": "node index.js",
9 | "start": "npm run build && open dist/output.sketch"
10 | },
11 | "author": "",
12 | "license": "Apache-2.0",
13 | "dependencies": {
14 | "fs-extra": "^8.1.0",
15 | "sketch-constructor": "^1.16.0"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | dist/
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/README.md:
--------------------------------------------------------------------------------
1 | # Generating a Sketch file from a Style Dictionary
2 |
3 | This example shows how you can generate a Sketch file from a [Style Dictionary](https://amzn.github.io/style-dictionary). Similar to the [building from scratch](../building-from-scratch) example, this one generates a Sketch file programmatically.
4 |
5 | ## Things to look at
6 |
7 | ### config.js
8 | This is the Style Dictionary configuration file. This is using the node module configuration file so we can easily add custom actions. Take a look at the `action` part of the config, here is where it is calling the function that actually creates the Sketch file.
9 |
10 | ### sketch/index.js
11 | This file exports a function that is called in the custom action defined in `config.js`. Here we create a new Sketch instance and then add Pages to it and add shared styles.
12 |
13 | ### sketch/Swatch.js
14 | This is a custom Sketch component that is created by extending the Group class and creating a Rectangle and 2 Text layers underneath.
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/components/typography.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": {
3 | "typography": {
4 | "h1": {
5 | "font-size": { "value": "{size.font.xxl.value}" },
6 | "font-weight": { "value": 300 },
7 | "color": { "value": "{color.font.base.value}" },
8 | "margin-bottom": { "value": "{size.spacing.xxl.value}" },
9 | "line-height": { "value": 1 }
10 | },
11 | "h2": {
12 | "font-size": { "value": "{size.font.xl.value}" },
13 | "font-weight": { "value": 400 },
14 | "color": { "value": "{color.font.secondary.value}" },
15 | "margin-bottom": { "value": "{size.spacing.xl.value}" },
16 | "line-height": { "value": 1 }
17 | },
18 | "h3": {
19 | "font-size": { "value": "{size.font.large.value}" },
20 | "font-weight": { "value": 600 },
21 | "color": { "value": "{color.font.tertiary.value}" },
22 | "margin-bottom": { "value": "{size.spacing.large.value}" },
23 | "line-height": { "value": 1 }
24 | }
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/config.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const fs = require('fs-extra');
15 |
16 | fs.ensureDirSync('./dist');
17 |
18 | module.exports = {
19 | source: ['properties/**/*.json', 'components/**/*.json'],
20 | action: {
21 | buildSketch: {
22 | do: require('./sketch'),
23 | undo: () => console.log('no undo')
24 | }
25 | },
26 | platforms: {
27 | sketch: {
28 | transforms: ['attribute/cti','name/cti/snake'],
29 | actions: ['buildSketch']
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generating-sketch-from-style-dictionary",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "config.js",
6 | "scripts": {
7 | "test": "npm run build",
8 | "build": "style-dictionary build --config ./config.js",
9 | "start": "npm run build && open dist/style-dictionary.sketch"
10 | },
11 | "author": "",
12 | "license": "Apache-2.0",
13 | "dependencies": {
14 | "fs-extra": "^8.1.0",
15 | "sketch-constructor": "^1.16.0",
16 | "style-dictionary": "^2.8.3"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/properties/color/background.json:
--------------------------------------------------------------------------------
1 | {
2 | "color": {
3 | "background": {
4 | "base": { "value":"{color.core.white.value}" },
5 | "alt": { "value":"{color.core.grey.10.value}" },
6 | "disabled": { "value":"{color.core.grey.10.value}" },
7 | "inverse": { "value":"{color.core.grey.120.value}" },
8 | "success": { "value":"{color.core.green.100.value}" },
9 | "error": { "value":"{color.core.red.100.value}" },
10 | "warning": { "value":"{color.core.orange.100.value}" },
11 | "info": { "value":"{color.core.blue.100.value}" },
12 | "link": { "value":"{color.core.blue.100.value}" },
13 | "low-priority": { "value":"{color.core.grey.60.value}" }
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/properties/color/brand.json:
--------------------------------------------------------------------------------
1 | {
2 | "color": {
3 | "brand": {
4 | "primary": {
5 | "lighter": { "value": "{color.core.teal.60.value}" },
6 | "light": { "value": "{color.core.teal.80.value}" },
7 | "base": { "value": "{color.core.teal.100.value}" },
8 | "dark": { "value": "{color.core.teal.120.value}" },
9 | "darker": { "value": "{color.core.teal.140.value}" }
10 | },
11 | "secondary": {
12 | "lighter": { "value": "{color.core.purple.60.value}" },
13 | "light": { "value": "{color.core.purple.80.value}" },
14 | "base": { "value": "{color.core.purple.100.value}" },
15 | "dark": { "value": "{color.core.purple.120.value}" },
16 | "darker": { "value": "{color.core.purple.140.value}" }
17 | }
18 | }
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/properties/color/core.json:
--------------------------------------------------------------------------------
1 | {
2 | "color": {
3 | "core": {
4 | "red": {
5 | "20" : { "value": "#FEEDEC" },
6 | "60" : { "value": "#F99B93" },
7 | "80" : { "value": "#F77F76" },
8 | "100" : { "value": "#E66157" },
9 | "120" : { "value": "#D64136" },
10 | "140" : { "value": "#C0291E" }
11 | },
12 | "purple": {
13 | "20" : { "value": "#E3DAF2" },
14 | "60" : { "value": "#C8B8E6" },
15 | "80" : { "value": "#8F6CCC" },
16 | "100" : { "value": "#6A5096" },
17 | "120" : { "value": "#553C80" },
18 | "140" : { "value": "#493171" }
19 | },
20 | "blue": {
21 | "20" : { "value": "#E3F0FA" },
22 | "60" : { "value": "#97C6EA" },
23 | "80" : { "value": "#67ACE0" },
24 | "100" : { "value": "#4197D9" },
25 | "120" : { "value": "#2F86C9" },
26 | "140" : { "value": "#1C75BA" }
27 | },
28 | "teal": {
29 | "20" : { "value": "#D9F8F5" },
30 | "60" : { "value": "#98EBE8" },
31 | "80" : { "value": "#40C7C2" },
32 | "100" : { "value": "#0FB7B0" },
33 | "120" : { "value": "#06A39C" },
34 | "140" : { "value": "#019790" }
35 | },
36 | "green": {
37 | "20" : { "value": "#E8F5E8" },
38 | "60" : { "value": "#AAD9A9" },
39 | "80" : { "value": "#83C882" },
40 | "100" : { "value": "#64BA63" },
41 | "120" : { "value": "#41AF40" },
42 | "140" : { "value": "#359A34" }
43 | },
44 | "yellow": {
45 | "20" : { "value": "#FFF9E7" },
46 | "60" : { "value": "#FFEAA7" },
47 | "80" : { "value": "#FFE07E" },
48 | "100" : { "value": "#FFD85E" },
49 | "120" : { "value": "#FBC61E" },
50 | "140" : { "value": "#FABB00" }
51 | },
52 | "orange": {
53 | "20" : { "value": "#FEEFE2" },
54 | "60" : { "value": "#FCC594" },
55 | "80" : { "value": "#FBAA63" },
56 | "100" : { "value": "#FA953C" },
57 | "120" : { "value": "#E3781B" },
58 | "140" : { "value": "#E67009" }
59 | },
60 | "grey": {
61 | "10" : { "value": "#F2F2F7" },
62 | "20" : { "value": "#DADAE6" },
63 | "40" : { "value": "#C2C2CC" },
64 | "60" : { "value": "#81818E" },
65 | "80" : { "value": "#48485E" },
66 | "100" : { "value": "#2E2E46" },
67 | "120" : { "value": "#252535" },
68 | "140" : { "value": "#191926" }
69 | },
70 |
71 | "white": { "value": "#ffffff" }
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/properties/color/font.json:
--------------------------------------------------------------------------------
1 | {
2 | "color": {
3 | "font": {
4 | "base": { "value": "{color.core.grey.120.value}" },
5 | "secondary": { "value": "{color.core.grey.80.value}" },
6 | "tertiary": { "value": "{color.core.grey.60.value}" },
7 | "quaternary": { "value": "{color.core.grey.40.value}" },
8 | "link": { "value": "{color.brand.primary.base.value}" },
9 | "active": { "value": "{color.brand.secondary.base.value}" },
10 | "hover": { "value": "{color.font.active.value}" },
11 | "error": { "value": "{color.core.red.100.value}" },
12 | "danger": { "value": "{color.core.red.100.value}" },
13 | "warning": { "value": "{color.core.orange.100.value}" },
14 | "success": { "value": "{color.core.green.100.value}" },
15 | "disabled": { "value": "{color.font.secondary.value}" }
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/properties/size/font.json:
--------------------------------------------------------------------------------
1 | {
2 | "size": {
3 | "font": {
4 | "tiny": { "value": 12 },
5 | "small": { "value": 14 },
6 | "base": { "value": 16 },
7 | "large": { "value": 24 },
8 | "xl": { "value": 32 },
9 | "xxl": { "value": 48 }
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/properties/size/spacing.json:
--------------------------------------------------------------------------------
1 | {
2 | "size": {
3 | "spacing": {
4 | "tiny": { "value": 4 },
5 | "small": { "value": 8 },
6 | "base": { "value": 12 },
7 | "large": { "value": 18 },
8 | "xl": { "value": 24 },
9 | "xxl": { "value": 36 }
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/sketch/ColorPage.js:
--------------------------------------------------------------------------------
1 | const { Page, Artboard } = require('sketch-constructor');
2 | const colorGroup = require('./colorGroup');
3 |
4 | class ColorPage extends Page {
5 | constructor(dictionary) {
6 | super({
7 | name: 'Colors',
8 | });
9 |
10 | this.layers = Object.keys(dictionary.properties.color).map((category, i) => {
11 | const layer = colorGroup(dictionary.properties.color[category], category);
12 | return new Artboard({
13 | name: category,
14 | layers: [layer],
15 | frame: {
16 | width: 1000,
17 | x: 1100 * i,
18 | height: layer.frame.height,
19 | },
20 | });
21 | });
22 | }
23 | }
24 |
25 | module.exports = ColorPage;
26 |
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/sketch/Swatch.js:
--------------------------------------------------------------------------------
1 | const { Group, Text, Rectangle } = require('sketch-constructor');
2 |
3 | class Swatch extends Group {
4 | constructor(args) {
5 | super({ frame: args.frame });
6 | const swatchColor = new Rectangle({
7 | width: 200,
8 | height: args.frame.height,
9 | x: 0,
10 | y: 0,
11 | name: args.value,
12 | style: {
13 | fills: [{
14 | color: args.value
15 | }]
16 | }
17 | });
18 |
19 | const swatchLabel = new Text({
20 | string: args.name,
21 | name: args.name,
22 | fontSize: 24,
23 | color: "#000",
24 | frame: {
25 | width: args.frame.width - 220,
26 | height: args.frame.height / 2,
27 | x: 220,
28 | y: 0,
29 | }
30 | });
31 |
32 |
33 | const swatchValue = new Text({
34 | string: args.value,
35 | name: args.value,
36 | fontSize: 16,
37 | color: "#ccc",
38 | frame: {
39 | width: args.frame.width - 220,
40 | height: args.frame.height / 2,
41 | x: 220,
42 | y: args.frame.height / 2,
43 | }
44 | });
45 |
46 | Object.assign(this, {
47 | layers: [
48 | swatchColor,
49 | swatchLabel,
50 | swatchValue
51 | ],
52 | name: args.name
53 | });
54 | }
55 | }
56 |
57 | module.exports = Swatch;
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/sketch/colorGroup.js:
--------------------------------------------------------------------------------
1 | const { Group, stackLayers } = require('sketch-constructor');
2 | const Swatch = require('./Swatch');
3 |
4 | function colorGroup(obj, name, level = 0) {
5 | if (Object.prototype.hasOwnProperty.call(obj, 'value')) {
6 | return new Swatch({
7 | ...obj,
8 | frame: {
9 | width: 1000,
10 | height: 100,
11 | },
12 | });
13 | }
14 |
15 | const layers = stackLayers(
16 | Object.keys(obj).reduce((ret, key) => {
17 | return ret.concat(colorGroup(obj[key], key, level + 1));
18 | }, []),
19 | 20
20 | );
21 | const lastLayer = layers[layers.length - 1];
22 |
23 | return new Group({
24 | name,
25 | frame: {
26 | width: 1000,
27 | height: lastLayer.frame.height + lastLayer.frame.y,
28 | },
29 | layers: layers.reverse(),
30 | });
31 | }
32 |
33 | module.exports = colorGroup;
34 |
--------------------------------------------------------------------------------
/__examples__/generating-sketch-from-style-dictionary/sketch/index.js:
--------------------------------------------------------------------------------
1 | const { Sketch } = require('sketch-constructor');
2 | const ColorPage = require('./ColorPage');
3 |
4 | module.exports = function BuildSketchWithStyles(dictionary) {
5 | // Create a new sketch instance
6 | const sketch = new Sketch();
7 |
8 | // Add shared styles for all background colors
9 | dictionary.allProperties
10 | .filter(prop => {
11 | return prop.attributes.category === 'color' && prop.attributes.type === 'background';
12 | })
13 | .forEach(prop => {
14 | sketch.addLayerStyle({
15 | name: prop.path.join(' / '),
16 | fills: [
17 | {
18 | color: prop.value,
19 | },
20 | ],
21 | });
22 | });
23 |
24 | // Add typography styles
25 | Object.keys(dictionary.properties.component.typography).forEach(key => {
26 | const font = dictionary.properties.component.typography[key];
27 | sketch.addTextStyle({
28 | name: key,
29 | textStyle: {
30 | fontSize: font['font-size'].value,
31 | color: font.color.value,
32 | },
33 | });
34 | });
35 |
36 | // Add a custom color page
37 | sketch.addPage(new ColorPage(dictionary));
38 |
39 | // Build the sketch file
40 | sketch.build('./dist/style-dictionary.sketch');
41 | };
42 |
--------------------------------------------------------------------------------
/__examples__/getting-styles-from-sketch/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | dist/
--------------------------------------------------------------------------------
/__examples__/getting-styles-from-sketch/README.md:
--------------------------------------------------------------------------------
1 | # Getting styles from a sketch document
2 |
3 | In this example we take an existing sketch file, myFile.sketch, and inspect it in node so that we can use it to output things like a CSS file for instance.
4 |
5 | ### What to look at
6 |
7 | index.js
8 |
9 | This file is doing all the work. It starts by importing the required node modules and then calling `Sketch.fromFile()` with the path of a sketch file. This method returns a promise which returns a `Sketch` instance. This Sketch class creates all necessary sub-classes so you can manipulate or get information from any part of the sketch document using the.Model classes.
10 |
11 | In this example we are looking at the shared text styles in the sketch document and writing those out to a CSS file. When you run `npm start` it will generate 'dist/styles.css' based on the text styles in the sketch document. You should be able to open that css file and see:
12 |
13 | ```css
14 | .H1 {
15 | color: rgb(134, 140, 145);
16 | font-size: 48px;
17 | font-family: 'Helvetica-Light';
18 | }
19 | .H2 {
20 | color: rgb(48, 57, 66);
21 | font-size: 36px;
22 | font-family: 'Helvetica';
23 | }
24 | ```
25 |
26 | Now if you open 'myFile.sketch' and add another shared text style, save the sketch file, run `npm start` again you should see the css file has been updated!
--------------------------------------------------------------------------------
/__examples__/getting-styles-from-sketch/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const fs = require('fs-extra');
15 | const { Sketch } = require('sketch-constructor');
16 |
17 | const sketchFile = './myFile.sketch';
18 | const cssFile = './dist/styles.css';
19 | fs.ensureDirSync('./dist');
20 |
21 | console.log(`Reading sketch file: ${sketchFile}`);
22 | Sketch.fromFile(sketchFile).then(sketch => {
23 | // Loop over the shared text styles in the document
24 | // Map them to a css declaration string
25 | // Join them into a single string with line breaks
26 | const css = sketch
27 | .getTextStyles()
28 | .map(sharedStyle => {
29 | const { textStyle } = sharedStyle.value;
30 | console.log(`Writing css declaration for: ${sharedStyle.name}`);
31 | return `.${sharedStyle.name} {
32 | color: ${textStyle.getColor().toRgbString()};
33 | font-size: ${textStyle.getFontSize()}px;
34 | font-family: '${textStyle.getFontName()}';
35 | }`;
36 | })
37 | .join('\n');
38 |
39 | // Write our css to a file
40 | console.log(`Writing css file: ${cssFile}`);
41 | fs.writeFileSync(cssFile, css);
42 | });
43 |
--------------------------------------------------------------------------------
/__examples__/getting-styles-from-sketch/myFile.sketch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amzn/sketch-constructor/297eb3306c6594f7cbf6ef40884ad3ea2a40735a/__examples__/getting-styles-from-sketch/myFile.sketch
--------------------------------------------------------------------------------
/__examples__/getting-styles-from-sketch/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "getting-styles-from-sketch",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "npm start",
8 | "start": "node index.js"
9 | },
10 | "author": "",
11 | "license": "Apache-2.0",
12 | "dependencies": {
13 | "fs-extra": "^8.1.0",
14 | "sketch-constructor": "^1.16.0"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/__examples__/symbols/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | node_modules
--------------------------------------------------------------------------------
/__examples__/symbols/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const fs = require('fs-extra');
15 | const { Sketch, Page, Text, SymbolMaster, Artboard } = require('../../index');
16 |
17 | // Output directory
18 | fs.ensureDirSync('./dist');
19 |
20 | const sketch = new Sketch();
21 |
22 | const page = new Page({
23 | name: 'my page',
24 | });
25 |
26 | const artboard = new Artboard({
27 | name: 'my artboard',
28 | frame: {
29 | width: 500,
30 | height: 500,
31 | x: 0,
32 | y: 0,
33 | },
34 | });
35 |
36 | const symbol = new SymbolMaster({
37 | name: 'symbol',
38 | frame: {
39 | width: 100,
40 | height: 100,
41 | x: 600,
42 | y: 0,
43 | },
44 | });
45 |
46 | const t = new Text({
47 | string: 'Hello',
48 | name: 'Hello',
49 | fontSize: 24,
50 | color: '#ccc',
51 | frame: {
52 | width: 100,
53 | height: 100,
54 | x: 0,
55 | y: 0,
56 | },
57 | });
58 | symbol.addLayer(t, true);
59 |
60 | const symbolInstance = symbol.createInstance({
61 | name: 'test',
62 | frame: {
63 | width: 100,
64 | height: 100,
65 | x: 0,
66 | y: 0,
67 | },
68 | });
69 |
70 | artboard.addLayer(symbolInstance);
71 |
72 | // Add the pages and artboards to the sketch object
73 | page.addArtboard(symbol);
74 | page.addArtboard(artboard);
75 | sketch.addPage(page);
76 |
77 | // Build the sketch file
78 | sketch.build('./dist/output.sketch').then(() => {
79 | console.log('Built!');
80 | });
81 |
--------------------------------------------------------------------------------
/__examples__/symbols/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "symbols",
3 | "version": "0.1.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "npm run build",
8 | "build": "node index.js",
9 | "start": "npm run build && cp dist/output.sketch dist/output.zip && open dist/output.zip && open dist/output.sketch"
10 | },
11 | "author": "",
12 | "license": "Apache-2.0",
13 | "dependencies": {
14 | "fs-extra": "^8.1.0",
15 | "sketch-constructor": "^1.16.0"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/__tests__/__helpers.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const fs = require('fs-extra');
15 |
16 | module.exports = {
17 | clearOutput: function() {
18 | fs.emptyDirSync('__tests__/__output');
19 | },
20 |
21 | fileToJSON: function(path) {
22 | return fs.readJsonSync(path);
23 | },
24 |
25 | fileExists: function(filePath) {
26 | try {
27 | return fs.statSync(filePath).isFile();
28 | } catch (err) {
29 | return false;
30 | }
31 | },
32 |
33 | pathDoesNotExist: function(path) {
34 | try {
35 | return !fs.existsSync(path);
36 | } catch (err) {
37 | return false;
38 | }
39 | },
40 |
41 | dirDoesNotExist: function(dirPath) {
42 | return this.pathDoesNotExist(dirPath);
43 | },
44 |
45 | fileDoesNotExist: function(filePath) {
46 | return this.pathDoesNotExist(filePath);
47 | }
48 | };
--------------------------------------------------------------------------------
/__tests__/__sketch-files/test-sketch/document.json:
--------------------------------------------------------------------------------
1 | {"_class":"document","do_objectID":"753833BB-B1FE-408B-93D7-07E9A185F1E2","assets":{"_class":"assetCollection","colors":[],"gradients":[],"imageCollection":{"_class":"imageCollection","images":{}},"images":[]},"colorSpace":0,"currentPageIndex":0,"foreignLayerStyles":[],"foreignSymbols":[],"foreignTextStyles":[],"layerStyles":{"_class":"sharedStyleContainer","objects":[]},"layerSymbols":{"_class":"symbolContainer","objects":[]},"layerTextStyles":{"_class":"sharedTextStyleContainer","objects":[{"_class":"sharedStyle","do_objectID":"4B68C2FE-F7E0-4EF6-BC87-8FED3008E9EB","name":"Test Style","value":{"_class":"style","endMarkerType":0,"miterLimit":10,"sharedObjectID":"4B68C2FE-F7E0-4EF6-BC87-8FED3008E9EB","startMarkerType":0,"textStyle":{"_class":"textStyle","encodedAttributes":{"MSAttributedStringFontAttribute":{"_class":"fontDescriptor","attributes":{"name":"AmazonEmber-Regular","size":70}},"MSAttributedStringColorAttribute":{"_class":"color","alpha":1,"blue":0.203921568627451,"green":0.1764705882352941,"red":0.1490196078431373},"textStyleVerticalAlignmentKey":0,"paragraphStyle":{"_class":"paragraphStyle","alignment":0}},"verticalAlignment":0},"windingRule":1}}]},"pages":[{"_class":"MSJSONFileReference","_ref_class":"MSImmutablePage","_ref":"pages\/CAA5BE6B-E854-4A3B-8261-D5522AFF8943"},{"_class":"MSJSONFileReference","_ref_class":"MSImmutablePage","_ref":"pages\/5D6ECF45-F123-477C-B078-12A12853F430"}]}
--------------------------------------------------------------------------------
/__tests__/__sketch-files/test-sketch/meta.json:
--------------------------------------------------------------------------------
1 | {"commit":"a9a8e0cffcaebe58914746cb1ab8f707ba873565","pagesAndArtboards":{"CAA5BE6B-E854-4A3B-8261-D5522AFF8943":{"name":"Page 1","artboards":{"5863D14C-8C6E-4C73-801F-A5BF691CF415":{"name":"Artboard"}}},"5D6ECF45-F123-477C-B078-12A12853F430":{"name":"Symbols","artboards":{"23A9809C-79C5-490C-9EE5-B78767E82314":{"name":"symbol1"}}}},"version":105,"fonts":["AmazonEmber-Regular"],"compatibilityVersion":99,"app":"com.bohemiancoding.sketch3","autosaved":0,"variant":"NONAPPSTORE","created":{"commit":"a9a8e0cffcaebe58914746cb1ab8f707ba873565","appVersion":"51.3","build":57544,"app":"com.bohemiancoding.sketch3","compatibilityVersion":99,"version":105,"variant":"NONAPPSTORE"},"saveHistory":["NONAPPSTORE.57544"],"appVersion":"51.3","build":57544}
--------------------------------------------------------------------------------
/__tests__/__sketch-files/test-sketch/previews/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amzn/sketch-constructor/297eb3306c6594f7cbf6ef40884ad3ea2a40735a/__tests__/__sketch-files/test-sketch/previews/preview.png
--------------------------------------------------------------------------------
/__tests__/__sketch-files/test-sketch/user.json:
--------------------------------------------------------------------------------
1 | {"document":{"pageListHeight":110},"CAA5BE6B-E854-4A3B-8261-D5522AFF8943":{"scrollOrigin":"{108, 108}","zoomValue":1},"5D6ECF45-F123-477C-B078-12A12853F430":{"scrollOrigin":"{243, 423}"}}
--------------------------------------------------------------------------------
/__tests__/__sketch-files/test.sketch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amzn/sketch-constructor/297eb3306c6594f7cbf6ef40884ad3ea2a40735a/__tests__/__sketch-files/test.sketch
--------------------------------------------------------------------------------
/__tests__/building.test.js:
--------------------------------------------------------------------------------
1 | const { Sketch, Text, Page, Artboard } = require('../index');
2 | const { fileExists, clearOutput } = require('./__helpers');
3 |
4 | describe('Building from scratch', () => {
5 | // beforeEach(() => {
6 | // clearOutput();
7 | // });
8 |
9 | it('should write a valid file', async () => {
10 | await (async () => {
11 | const sketch = new Sketch();
12 | const page = new Page({
13 | name: 'My Page',
14 | });
15 | const artboard = new Artboard({
16 | frame: {
17 | width: 1024,
18 | height: 768,
19 | },
20 | name: 'My Artboard',
21 | });
22 | const text = new Text({
23 | name: 'My Text',
24 | string: 'Test',
25 | fontSize: 24,
26 | });
27 | artboard.addLayer(text);
28 | sketch.addPage(page);
29 | sketch.addArtboard(page.getID(), artboard);
30 | // const path = `${process.cwd()}/__tests__/__output/output2.sketch`;
31 | // const outputPath = await sketch.build(path);
32 | // expect(fileExists(outputPath)).toBeTruthy();
33 |
34 | const { meta } = sketch;
35 | expect(Object.keys(meta.pagesAndArtboards || {}).length).toEqual(1);
36 | const metaPage = Object.values(meta.pagesAndArtboards)[0];
37 | expect(metaPage.name).toEqual('My Page');
38 | expect(Object.keys(metaPage.artboards).length).toEqual(1);
39 | const metaArtboard = Object.values(metaPage.artboards)[0];
40 | expect(metaArtboard.name).toEqual('My Artboard');
41 | })();
42 | });
43 | });
44 |
--------------------------------------------------------------------------------
/__tests__/editing.test.js:
--------------------------------------------------------------------------------
1 | const { Sketch, Artboard, Group } = require('../index');
2 | const { fileExists, clearOutput } = require('./__helpers');
3 |
4 | describe('Editing', () => {
5 | // beforeEach(() => {
6 | // clearOutput();
7 | // });
8 |
9 | it('should build', () => {
10 | return Sketch.fromFile(`${process.cwd()}/__tests__/__sketch-files/test.sketch`).then((sketch) => {
11 | const artboard = sketch.getPages((page) => page.name === 'Page 1')[0].getArtboards()[0];
12 | artboard.addLayer(
13 | new Group({
14 | name: 'Testing',
15 | })
16 | );
17 | // sketch.build(`${process.cwd()}/__tests__/__output/foo.sketch`)
18 | });
19 | });
20 | });
21 |
--------------------------------------------------------------------------------
/__tests__/examples.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const path = require('path');
15 | const fs = require('fs');
16 | const childProcess = require('child_process');
17 | const { clearOutput } = require('./__helpers');
18 |
19 | describe('Examples', () => {
20 | // beforeEach(() => {
21 | // clearOutput();
22 | // });
23 |
24 | fs.readdirSync(path.join(process.cwd(), '__examples__')).forEach((dir) => {
25 | it(dir, () => {
26 | childProcess.execSync(`cd __examples__/${dir} && npm i && npm test`);
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/__tests__/utils/resizingConstraints.test.js:
--------------------------------------------------------------------------------
1 | const { calculateResizingConstraint } = require('../../utils/resizingConstraints.js');
2 | const { resizingConstraintsMap } = require('../../utils/maps.js');
3 |
4 | describe('Test sizing constraints', () => {
5 | test('reduce series of numbers to their bitwise AND value', () => {
6 | const { top, left, height } = resizingConstraintsMap;
7 | const input = [left, height];
8 | // eslint-disable-next-line no-bitwise
9 | const output = top & left & height;
10 |
11 | expect(calculateResizingConstraint(top, ...input)).toEqual(output);
12 | });
13 |
14 | test('given undefined values will return `none` (63)', () => {
15 | const { top, wat, none } = resizingConstraintsMap;
16 | const output = none;
17 |
18 | expect(calculateResizingConstraint(top, wat)).toEqual(output);
19 | });
20 |
21 | describe('when given invalid combinations', () => {
22 | test('will throw when top, bottom & height are specified', () => {
23 | const { top, bottom, height } = resizingConstraintsMap;
24 | const input = [bottom, height];
25 |
26 | expect(() => calculateResizingConstraint(top, ...input)).toThrow();
27 | });
28 |
29 | test('will throw when left, right & width are specified', () => {
30 | const { left, right, width } = resizingConstraintsMap;
31 | const input = [right, width];
32 |
33 | expect(() => calculateResizingConstraint(left, ...input)).toThrow();
34 | });
35 | });
36 | });
37 |
--------------------------------------------------------------------------------
/docs/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amzn/sketch-constructor/297eb3306c6594f7cbf6ef40884ad3ea2a40735a/docs/.nojekyll
--------------------------------------------------------------------------------
/docs/_sidebar.md:
--------------------------------------------------------------------------------
1 | - [Overview](README.md)
2 | - [Models](models.md)
3 | - [Utils](utils.md)
--------------------------------------------------------------------------------
/docs/api.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amzn/sketch-constructor/297eb3306c6594f7cbf6ef40884ad3ea2a40735a/docs/api.md
--------------------------------------------------------------------------------
/docs/assets/theme.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --base-font-family: 'Open Sans', 'Helvetica Neue', Helvetica, sans-serif;
3 | --theme-color: #00B3AC;
4 | --link-color: var(--theme-color);
5 | --code-inline-color: inherit;
6 | }
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | sketch-constructor - Read/write/manipulate Sketch files in Node without Sketch plugins!
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/docs/utils.md:
--------------------------------------------------------------------------------
1 | ## textAlignmentMap
2 |
3 |
4 | Maps text alignment integer enums to human-readable strings
5 |
6 | **Example**
7 | ```js
8 | textAlignmentMap.left // => 0
9 | ```
10 |
11 | * * *
12 |
13 | ## textBehaviourMap
14 |
15 |
16 | Maps text text behaviour integer enums to human-readable strings
17 |
18 | **Example**
19 | ```js
20 | textBehaviourMap.auto // => 0
21 | ```
22 |
23 | * * *
24 |
25 | ## textTransformMap
26 |
27 |
28 | Maps text transform integer enums to human-readable strings
29 |
30 | **Example**
31 | ```js
32 | textTransformMap.uppercase // => 1
33 | ```
34 |
35 | * * *
36 |
37 | ## verticalAlignmentMap
38 |
39 |
40 | Maps vertical alignment int enums to human-readable strings
41 |
42 | **Example**
43 | ```js
44 | verticalAlignmentMap.top // => 0
45 | ```
46 |
47 | * * *
48 |
49 | ## blendModeMap
50 |
51 |
52 | Maps blend modes int enums to human-readable strings
53 |
54 | **Example**
55 | ```js
56 | blendModeMap.multiply // => 2
57 | ```
58 |
59 | * * *
60 |
61 | ## resizingConstraintsMap
62 |
63 |
64 | Maps resizing contrains int enums to human-readable strings
65 |
66 | **Example**
67 | ```js
68 | resizingConstraintsMap.top // => 31
69 | ```
70 |
71 | * * *
72 |
73 | ## STORAGE_DIR
74 |
75 |
76 | Path to the temporary sketch constructor folder
77 |
78 |
79 | * * *
80 |
81 | ## STORAGE_IMG_DIR
82 |
83 |
84 | Path to the temporary local image folder
85 |
86 |
87 | * * *
88 |
89 | ## STORAGE_PREVIEW_DIR
90 |
91 |
92 | Path to directory with preview file
93 |
94 |
95 | * * *
96 |
97 | ## STORAGE_PREVIEW_FILE
98 |
99 |
100 | Path to preview file
101 |
102 |
103 | * * *
104 |
105 | ## layerToClass
106 | > layerToClass(layer) ⇒ Layer
107 |
108 |
109 | layerToClass
110 |
111 | Takes a raw JSON layer and returns a new class instance.
112 |
113 | **Returns**: Layer
- - An instance of a subclass of a Layer, such as Artboard, Group, or Text
114 |
115 | | Param | Type | Description |
116 | | --- | --- | --- |
117 | | layer | Object
| The raw JSON of a layer as an object |
118 |
119 |
120 | * * *
121 |
122 | ## stackLayers
123 | > stackLayers(layers, gutter) ⇒ Array.<Layer>
124 |
125 |
126 | stackLayers
127 | Positions an array of layers so they flow vertically like they would on the web.
128 |
129 | **Returns**: Array.<Layer>
- - An array of Layers
130 |
131 | | Param | Type | Default | Description |
132 | | --- | --- | --- | --- |
133 | | layers | Array.<Layer>
| | An array of Layers |
134 | | gutter | int
| 0
| Optional gutter between layers |
135 |
136 |
137 | * * *
138 |
139 |
--------------------------------------------------------------------------------
/index.d.ts:
--------------------------------------------------------------------------------
1 | export * from './models';
2 | export * from './utils';
3 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = { ...require('./models'), ...require('./utils') };
2 |
--------------------------------------------------------------------------------
/jsdoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "tags": {
3 | "allowUnknownTags": true,
4 | "dictionaries": ["jsdoc"]
5 | },
6 | "source": {
7 | "include": ["models", "utils", "package.json", "README.md"],
8 | "includePattern": ".js$",
9 | "excludePattern": "(node_modules/|docs)"
10 | },
11 | "plugins": [
12 | "plugins/markdown"
13 | ],
14 | "templates": {
15 | "cleverLinks": false,
16 | "monospaceLinks": true,
17 | "useLongnameInNav": false
18 | },
19 | "opts": {
20 | "destination": "./docs/",
21 | "encoding": "utf8",
22 | "private": true,
23 | "recurse": true,
24 | "template": "node_modules/minami"
25 | }
26 | }
--------------------------------------------------------------------------------
/models/Artboard/Artboard.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Artboard = require('./index');
15 | const json = require('./__Artboard.json');
16 |
17 | describe('Artboard', () => {
18 | it('should work from raw JSON', () => {
19 | const artboard = new Artboard(null, json);
20 | expect(JSON.stringify(json, null, 2)).toEqual(JSON.stringify(artboard, null, 2));
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Artboard/__Artboard.json:
--------------------------------------------------------------------------------
1 | {
2 | "_class": "artboard",
3 | "do_objectID": "90CA1336-C5FC-4729-B576-711952931AD3",
4 | "booleanOperation": -1,
5 | "exportOptions": {
6 | "_class": "exportOptions",
7 | "exportFormats": [
8 | {
9 | "_class": "exportFormat",
10 | "absoluteSize": 0,
11 | "fileFormat": "png",
12 | "name": "",
13 | "namingScheme": 0,
14 | "scale": 1,
15 | "visibleScaleType": 0
16 | }
17 | ],
18 | "includedLayerIds": [],
19 | "layerOptions": 0,
20 | "shouldTrim": false
21 | },
22 | "frame": {
23 | "_class": "rect",
24 | "constrainProportions": false,
25 | "height": 261,
26 | "width": 346,
27 | "x": 232,
28 | "y": 279
29 | },
30 | "isFixedToViewport": false,
31 | "isFlippedHorizontal": false,
32 | "isFlippedVertical": false,
33 | "isLocked": false,
34 | "isVisible": true,
35 | "layerListExpandedType": 0,
36 | "name": "Artboard",
37 | "nameIsFixed": false,
38 | "resizingConstraint": 63,
39 | "resizingType": 0,
40 | "rotation": 0,
41 | "shouldBreakMaskChain": true,
42 | "clippingMaskMode": 0,
43 | "hasClippingMask": false,
44 | "style": {
45 | "_class": "style",
46 | "endMarkerType": 0,
47 | "miterLimit": 10,
48 | "startMarkerType": 0,
49 | "windingRule": 1
50 | },
51 | "hasClickThrough": false,
52 | "layers": [],
53 | "backgroundColor": {
54 | "_class": "color",
55 | "alpha": 1,
56 | "blue": 1,
57 | "green": 1,
58 | "red": 1
59 | },
60 | "hasBackgroundColor": true,
61 | "horizontalRulerData": {
62 | "_class": "rulerData",
63 | "base": 0,
64 | "guides": []
65 | },
66 | "includeBackgroundColorInExport": true,
67 | "includeInCloudUpload": true,
68 | "isFlowHome": false,
69 | "resizesContent": true,
70 | "verticalRulerData": {
71 | "_class": "rulerData",
72 | "base": 0,
73 | "guides": []
74 | }
75 | }
--------------------------------------------------------------------------------
/models/Artboard/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 | import Group from '../Group';
3 | import RulerData from '../RulerData';
4 |
5 | declare class Artboard extends Group {
6 | _class: 'artboard';
7 | backgroundColor: Color;
8 | hasBackgroundColor: boolean;
9 | horizontalRulerData: RulerData;
10 | verticalRulerData: RulerData;
11 | includeBackgroundColorInExport: boolean;
12 | includeInCloudUpload: boolean;
13 | isFlowHome: boolean;
14 | resizesContent: boolean;
15 |
16 | constructor(args?: any, json?: any);
17 | }
18 |
19 | export = Artboard;
20 |
--------------------------------------------------------------------------------
/models/Artboard/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Artboard');
15 |
--------------------------------------------------------------------------------
/models/AttributedString/AttributedString.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const StringAttribute = require('../StringAttribute');
15 |
16 | /**
17 | * An AttributedString is a string of text that has certain parts of it with different styles.
18 | */
19 | class AttributedString {
20 | /**
21 | * @property {String} string
22 | * @property {StringAttribute[]} attributes
23 | */
24 | static get Model() {
25 | return {
26 | _class: 'attributedString',
27 | string: '',
28 | attributes: [],
29 | };
30 | }
31 |
32 | /**
33 | *
34 | * @param {Object} args
35 | * @param {String} args.string
36 | * @param {StringAttribute[]} [args.attributes] If you don't pass any attributes, this will pass args to a new StringAttribute that will cover the full lenght of the string
37 | * @param {AttributedString.Model} json
38 | */
39 | constructor(args = {}, json) {
40 | if (json) {
41 | Object.assign(this, json);
42 | } else {
43 | Object.assign(this, {
44 | _class: 'attributedString',
45 | string: args.string || '',
46 | attributes: args.attributes || [new StringAttribute({ ...args, location: 0, length: args.string.length })],
47 | });
48 | }
49 | }
50 | }
51 |
52 | module.exports = AttributedString;
53 |
--------------------------------------------------------------------------------
/models/AttributedString/AttributedString.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const AttributedString = require('./AttributedString');
15 |
16 | const json = {};
17 |
18 | describe('AttributedString', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/AttributedString/index.d.ts:
--------------------------------------------------------------------------------
1 | import StringAttribute from '../StringAttribute';
2 |
3 | declare class AttributedString {
4 | _class: 'attributedString';
5 | string: string;
6 | attributes: StringAttribute[];
7 |
8 | constructor(args?: any, json?: any);
9 | }
10 |
11 | export = AttributedString;
12 |
--------------------------------------------------------------------------------
/models/AttributedString/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./AttributedString');
15 |
--------------------------------------------------------------------------------
/models/Bitmap/Bitmap.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const fs = require('fs-extra');
16 | const crypto = require('crypto');
17 | const Layer = require('../Layer');
18 | const Rect = require('../Rect');
19 | const Style = require('../Style');
20 | const { STORAGE_DIR, STORAGE_IMG_DIR } = require('../../utils/paths');
21 |
22 | /**
23 | * A bitmap layer is used for images
24 | * Currently supported file types: PNG
25 | * @extends Layer
26 | *
27 | */
28 | class Bitmap extends Layer {
29 | /**
30 | * @mixes Layer.Model
31 | * @property {boolean} fillReplacesImage
32 | * @property {boolean} hasClippingMask
33 | * @property {integer} intendedDPI
34 | * @property {integer} layerListExpandedType
35 | * @property {integer} resizingType
36 | * @property {float} rotation
37 | * @property {boolean} shouldBreakMaskChain
38 | * @property {Object} image
39 | */
40 | static get Model() {
41 | return {
42 | ...Layer.Model,
43 | _class: 'bitmap',
44 | fillReplacesImage: false,
45 | hasClippingMask: false,
46 | intendedDPI: 72,
47 | layerListExpandedType: 0,
48 | resizingType: 0,
49 | rotation: 0,
50 | shouldBreakMaskChain: false,
51 | image: {
52 | _class: 'MSJSONFileReference',
53 | _ref_class: 'MSImageData',
54 | _ref: '',
55 | },
56 | };
57 | }
58 |
59 | /**
60 | *
61 | * @param {Object} args
62 | * @param {String} args.filePath Local path of the image in PNG format
63 | * @param {Object} args.frame Sent to {@link Rect}
64 | * @param {Object} args.style Sent to {@link Style}
65 | * @param {Bitmap.Model} json
66 | */
67 | constructor(args = {}, json) {
68 | super(args, json);
69 | if (!json) {
70 | const id = args.id || uuid().toUpperCase();
71 | Object.assign(this, Bitmap.Model, {
72 | do_objectID: id,
73 | name: args.name || id,
74 | frame: new Rect(args.frame),
75 | style: new Style(args.style),
76 | layers: args.layers || [],
77 | });
78 | const fileHash = crypto.createHash('sha1').update(args.filePath).digest('hex');
79 | this.image._ref = `images/${fileHash}.png`;
80 | fs.ensureDirSync(STORAGE_IMG_DIR);
81 | fs.copyFileSync(args.filePath, `${STORAGE_DIR}/${this.image._ref}`);
82 | }
83 |
84 | return this;
85 | }
86 | }
87 |
88 | module.exports = Bitmap;
89 |
--------------------------------------------------------------------------------
/models/Bitmap/Bitmap.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Fill = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Fill', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 |
23 | it('should work from user generated', () => {
24 | expect(true).toBeTruthy();
25 | });
26 | });
27 |
--------------------------------------------------------------------------------
/models/Bitmap/index.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | import Layer = require('../Layer');
15 |
16 | declare class Bitmap extends Layer {
17 | _class: 'bitmap';
18 | clippingMask: Record;
19 | clippingMaskMode?: number;
20 | fillReplacesImage?: boolean;
21 | flow?: Record;
22 | hasClippingMask?: boolean;
23 | image?: Record;
24 | imageHash?: Record;
25 | /**
26 | * The scale the image was imported with into Sketch. This can be derived on import from the DPI of the image or the suffixes (@2x) of the filename. On legacy documents defaults to 0, which is meant to be the default image DPI of 72.
27 | */
28 | intendedDPI?: number;
29 | originalObjectID?: Record;
30 | sharedStyleID?: Record;
31 | userInfo?: Record
32 | }
33 |
34 | export = Bitmap;
35 |
--------------------------------------------------------------------------------
/models/Bitmap/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Bitmap');
15 |
--------------------------------------------------------------------------------
/models/Blur/Blur.js:
--------------------------------------------------------------------------------
1 | class Blur {
2 | static get Model() {
3 | return {
4 | _class: 'blur',
5 | center: '{0.5, 0.5}',
6 | isEnabled: true,
7 | motionAngle: 0,
8 | radius: 0,
9 | saturation: 1,
10 | type: Blur.Type.Gaussian,
11 | };
12 | }
13 |
14 | static get Type() {
15 | return {
16 | Gaussian: 0,
17 | Motion: 1,
18 | Zoom: 2,
19 | Background: 3,
20 | };
21 | }
22 |
23 | /**
24 | * @param {Blur.Model} args
25 | * @param {Blur.Model} json
26 | */
27 | constructor(args, json) {
28 | if (json) Object.assign(this, json);
29 | if (args) Object.assign(this, Blur.Model, args);
30 | }
31 |
32 | /**
33 | * @param {Blur.Model} json
34 | * @returns {Blur}
35 | */
36 | static fromJSON(json) {
37 | return new Blur(null, json);
38 | }
39 | }
40 |
41 | module.exports = Blur;
42 |
--------------------------------------------------------------------------------
/models/Blur/Blur.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Blur = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Blur', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 |
23 | it('should work from user generated', () => {
24 | const blur = new Blur({});
25 | expect(true).toBeTruthy();
26 | });
27 | });
28 |
--------------------------------------------------------------------------------
/models/Blur/index.d.ts:
--------------------------------------------------------------------------------
1 | declare enum BlurType {
2 | Gaussian = 0,
3 | Motion = 1,
4 | Zoom = 2,
5 | Background = 3,
6 | }
7 |
8 | declare class Blur {
9 | _class: 'blur';
10 | center: string;
11 | isEnabled: boolean;
12 | motionAngle: number;
13 | radius: number;
14 | saturation: number;
15 | type: BlurType;
16 |
17 | static readonly Type: BlurType;
18 | static fromJSON(json: Blur): Blur;
19 |
20 | constructor(args: Partial)
21 | constructor(args: any)
22 | constructor(args: null | undefined, json: Blur)
23 | }
24 |
25 | export = Blur;
26 |
--------------------------------------------------------------------------------
/models/Blur/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Blur');
15 |
--------------------------------------------------------------------------------
/models/Border/Border.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Color = require('../Color');
15 | const Fill = require('../Fill');
16 |
17 | /**
18 | * Border class
19 | */
20 | class Border {
21 | /**
22 | * @property {boolean} isEnabled
23 | * @property {Color.Model} color
24 | * @property {Fill.FillType} fillType
25 | * @property {Border.position} position
26 | * @property {integer} thickness
27 | */
28 | static get Model() {
29 | return {
30 | _class: 'border',
31 | isEnabled: false,
32 | color: Color.Model,
33 | fillType: 0,
34 | position: 0,
35 | thickness: 0,
36 | };
37 | }
38 |
39 | /**
40 | *
41 | * @param {Object} args
42 | * @param {Object|String} args.color Sent to {@link Color}
43 | * @param {Fill.FillType} args.fillType
44 | * @param {Border.Position} args.position
45 | * @param {integer} args.thickness
46 | * @param {Border.Model} json
47 | */
48 | constructor(args = {}, json) {
49 | if (json) {
50 | Object.assign(this, json);
51 | } else {
52 | Object.assign(this, {
53 | _class: 'border',
54 | // Default is true, but can be explicitly set to false
55 | isEnabled: args.isEnabled !== false,
56 | color: new Color(args.color),
57 | fillType: Fill.FillType[args.fillType || 'Color'],
58 | position: Border.Position[args.position || 'Center'],
59 | thickness: args.thickness || 1,
60 | });
61 | }
62 | return this;
63 | }
64 | }
65 |
66 | /**
67 | * @enum {integer}
68 | */
69 | Border.Position = {
70 | Inside: 1,
71 | Center: 0,
72 | Outside: 2,
73 | };
74 |
75 | module.exports = Border;
76 |
--------------------------------------------------------------------------------
/models/Border/Border.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Border = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Border', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Border/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 |
3 | declare const enum Position {
4 | Inside = 1,
5 | Center = 0,
6 | Outside = 2
7 | }
8 |
9 | declare class Border {
10 | static Position: typeof Position;
11 |
12 | constructor(args?: any, json?: any);
13 |
14 | _class: 'border';
15 | isEnabled: boolean;
16 | color: Color;
17 | fillType: number;
18 | position: Position;
19 | thickness: number;
20 | }
21 |
22 | export = Border;
23 |
--------------------------------------------------------------------------------
/models/Border/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Border');
15 |
--------------------------------------------------------------------------------
/models/BorderOptions/BorderOptions.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | /**
15 | * Border options
16 | */
17 | class BorderOptions {
18 | /**
19 | * @property {boolean} isEnabled
20 | * @property {integer[]} dashPattern
21 | * @property {BorderOptions.LineCapStyle} lineCapStyle
22 | * @property {BorderOptions.LineJoinStyle} lineJoinStyle
23 | */
24 | static get Model() {
25 | return {
26 | _class: 'borderOptions',
27 | isEnabled: true,
28 | dashPattern: [],
29 | lineCapStyle: 1,
30 | lineJoinStyle: 1,
31 | };
32 | }
33 |
34 | /**
35 | *
36 | * @param {Object} [args]
37 | * @param {integer[]} args.dashPattern
38 | * @param {BorderOptions.LineCapStyle} args.lineCapStyle
39 | * @param {BorderOptions.LineJoinStyle} args.lineJoinStyle
40 | * @param {BorderOptions.Model} json
41 | */
42 | constructor(args = {}, json) {
43 | if (json) {
44 | Object.assign(this, json);
45 | } else {
46 | Object.assign(this, BorderOptions.Model, {
47 | dashPattern: args.dashPattern,
48 | lineCapStyle: BorderOptions.LineCapStyle[args.lineCapStyle || 'butt'],
49 | lineJoinStyle: BorderOptions.LineJoinStyle[args.lineJoinStyle || 'miter'],
50 | isEnabled: args.isEnabled !== false,
51 | });
52 | }
53 | }
54 | }
55 |
56 | /**
57 | * @enum
58 | */
59 | BorderOptions.LineCapStyle = {
60 | butt: 0,
61 | round: 1,
62 | projecting: 2,
63 | };
64 |
65 | /**
66 | * @enum
67 | */
68 | BorderOptions.LineJoinStyle = {
69 | miter: 0,
70 | round: 1,
71 | bevel: 2,
72 | };
73 |
74 | module.exports = BorderOptions;
75 |
--------------------------------------------------------------------------------
/models/BorderOptions/BorderOptions.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const BorderOptions = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('BorderOptions', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/BorderOptions/index.d.ts:
--------------------------------------------------------------------------------
1 | declare const enum LineCapStyle {
2 | butt = 0,
3 | round = 1,
4 | projecting = 2
5 | }
6 | declare const enum LineJoinStyle {
7 | miter = 0,
8 | round = 1,
9 | bevel = 2
10 | }
11 |
12 | declare class BorderOptions {
13 | static LineCapStyle: typeof LineCapStyle;
14 |
15 | static LineJoinStyle: typeof LineJoinStyle;
16 |
17 | constructor(args?: any, json?: any);
18 |
19 | _class: 'borderOptions';
20 | isEnabled: boolean;
21 | dashPattern: number[];
22 | lineCapStyle: LineCapStyle;
23 | lineJoinStyle: LineJoinStyle;
24 | }
25 |
26 | export = BorderOptions;
27 |
--------------------------------------------------------------------------------
/models/BorderOptions/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./BorderOptions');
15 |
--------------------------------------------------------------------------------
/models/Color/Color.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Color = require('./index');
15 | const { Swatch } = require('../index');
16 |
17 | const json = {
18 | _class: 'color',
19 | alpha: 1,
20 | blue: 0.592,
21 | green: 0.592,
22 | red: 0.592,
23 | };
24 |
25 | describe('Color', () => {
26 | it('should work from raw JSON', () => {
27 | const color = new Color(null, json);
28 | expect(color).toBeDefined();
29 | });
30 |
31 | it('should work being user generated', () => {
32 | const color = new Color('#fff');
33 | expect(color).toBeDefined();
34 | });
35 |
36 | it('should have tinycolor methods', () => {
37 | const color = new Color('#fff');
38 | expect(color.toHexString()).toEqual('#ffffff');
39 | });
40 |
41 | it('should be able to be modified with tinycolor methods', () => {
42 | const color = new Color('#000');
43 | color.lighten(100);
44 | expect(color.toHexString()).toEqual('#ffffff');
45 | });
46 |
47 | it('should accept swatchID as property along with color components', () => {
48 | const swatchID = '6D02695C-C1FF-471B-9948-A13985E7618E';
49 | const alpha = 0.77;
50 | const color = new Color({ swatchID, r: 1, g: 0, b: 0, a: alpha });
51 | expect(color.swatchID).toEqual(swatchID);
52 | expect(color.alpha).toEqual(alpha);
53 | expect(color.blue).toEqual(0);
54 | });
55 |
56 | it('should accept result of swatch.asColor()', () => {
57 | const swatch = new Swatch({ color: new Color('purple') });
58 | const refColor = swatch.asColor();
59 | const color = new Color(refColor);
60 | expect(color.swatchID).toEqual(swatch.do_objectID);
61 | expect(color.red).toEqual(refColor.r / 255);
62 | });
63 | });
64 |
--------------------------------------------------------------------------------
/models/Color/index.d.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from 'tinycolor2';
2 |
3 | declare class Color {
4 | _class: 'color';
5 | alpha: number;
6 | blue: number;
7 | green: number;
8 | red: number;
9 | swatchID?: string;
10 |
11 | constructor(args?: any, json?: any);
12 |
13 | set(tinyColor: Instance): Color;
14 |
15 | _getTinyColor(): Instance;
16 | }
17 |
18 | export = Color;
19 |
--------------------------------------------------------------------------------
/models/Color/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Color');
15 |
--------------------------------------------------------------------------------
/models/CurvePoint/CurvePoint.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | /**
15 | * CurvePoints are used to create Shapes
16 | */
17 | class CurvePoint {
18 | /**
19 | * @property {integer} cornerRadius
20 | * @property {String} curveFrom "{0,0}"
21 | * @property {String} curveTo "{0,0}"
22 | * @property {String} point "{0,0}"
23 | * @property {integer} curveMode
24 | * @property {boolean} hasCurveFrom
25 | * @property {boolean} hasCurveTo
26 | */
27 | static get Model() {
28 | return {
29 | _class: 'curvePoint',
30 | cornerRadius: 0,
31 | curveFrom: '{0, 0}',
32 | curveMode: 1,
33 | curveTo: '{0, 0}',
34 | hasCurveFrom: false,
35 | hasCurveTo: false,
36 | point: '{0, 0}',
37 | };
38 | }
39 |
40 | /**
41 | *
42 | * @param {CurvePoint.Model} args
43 | * @param {CurvePoint.Model} json
44 | */
45 | constructor(args = {}, json) {
46 | if (json) {
47 | Object.assign(this, json);
48 | } else {
49 | Object.assign(this, CurvePoint.Model, args);
50 | }
51 | }
52 | }
53 |
54 | module.exports = CurvePoint;
55 |
--------------------------------------------------------------------------------
/models/CurvePoint/CurvePoint.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const CurvePoint = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('CurvePoint', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/CurvePoint/index.d.ts:
--------------------------------------------------------------------------------
1 | declare class CurvePoint {
2 | _class: 'curvePoint';
3 | cornerRadius: number;
4 | curveFrom: string;
5 | curveTo: string;
6 | hasCurveFrom: boolean;
7 | hasCurveTo: boolean;
8 | point: string;
9 |
10 | constructor(args?: any, json?: any);
11 |
12 | }
13 |
14 | export = CurvePoint;
15 |
--------------------------------------------------------------------------------
/models/CurvePoint/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./CurvePoint');
15 |
--------------------------------------------------------------------------------
/models/Document/Document.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Document = require('.');
15 |
16 | describe('Document', () => {
17 | it('should work', () => {
18 | const document = new Document();
19 | expect(document.do_objectID).toBeDefined();
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/models/Document/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 | import Page from '../Page';
3 | import SharedStyle from '../SharedStyle';
4 | import Swatch from '../Swatch';
5 |
6 | declare class Document {
7 | _class: 'document';
8 | do_objectID: string;
9 | assets: {
10 | _class: 'assetCollection';
11 | colors: Color[];
12 | gradients: any[]; // TODO
13 | imageCollections: {
14 | _class: 'imageCollection';
15 | images: any; // TODO
16 | },
17 | images: any[]; // TODO
18 | };
19 | colorSpace: number;
20 | currentPageIndex: number;
21 | foreignLayerStyles: SharedStyle[];
22 | foreignSymbols: any[]; // TODO
23 | foreignTextStyles: SharedStyle[];
24 | layerStyles: {
25 | _class: 'sharedStyleContainer';
26 | objects: SharedStyle[];
27 | };
28 | layerSymbols: {
29 | _class: 'symbolContainer';
30 | objects: any[]; // TODO
31 | };
32 | layerTextStyles: {
33 | _class: 'sharedTextStyleContainer';
34 | objects: SharedStyle[];
35 | };
36 | sharedSwatches: {
37 | _class: 'swatchContainer';
38 | objects: Swatch[];
39 | };
40 | pages: Page[];
41 |
42 | constructor(args?: any, json?: any);
43 |
44 | getLayerStyles(): SharedStyle[];
45 |
46 | getLayerStyle(name: string): SharedStyle | undefined;
47 |
48 | addLayerStyle(style: SharedStyle): Document;
49 |
50 | getTextStyles(): SharedStyle[];
51 |
52 | addTextStyle(style: SharedStyle): Document;
53 |
54 | getSwatches(): Swatch[];
55 |
56 | addSwatch(swatch: Swatch): Document;
57 |
58 | addPage(pageID: string): Document;
59 | }
60 |
61 | export = Document;
62 |
--------------------------------------------------------------------------------
/models/Document/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Document');
15 |
--------------------------------------------------------------------------------
/models/ExportFormat/ExportFormat.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | /**
15 | *
16 | */
17 | class ExportFormat {
18 | static get Model() {
19 | return {
20 | _class: 'exportFormat',
21 | absoluteSize: 0,
22 | fileFormat: 'png',
23 | name: '',
24 | namingScheme: 0,
25 | scale: 1,
26 | visibleScaleType: 0,
27 | };
28 | }
29 |
30 | /**
31 | *
32 | * @param {Object} args
33 | * @param {ExportFormat.Model} json
34 | */
35 | constructor(args = {}, json) {
36 | if (json) {
37 | Object.assign(this, json);
38 | } else {
39 | Object.assign(this, ExportFormat.Model, args);
40 | }
41 | return this;
42 | }
43 | }
44 |
45 | module.exports = ExportFormat;
46 |
--------------------------------------------------------------------------------
/models/ExportFormat/ExportFormat.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const ExportFormat = require('./index');
15 | const json = require('./__ExportFormat.json');
16 |
17 | describe('ExportFormat', () => {
18 | it('should work from raw JSON', () => {
19 | const exportFormat = new ExportFormat(null, json);
20 | expect(JSON.stringify(json, null, 2)).toEqual(JSON.stringify(exportFormat, null, 2));
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/ExportFormat/__ExportFormat.json:
--------------------------------------------------------------------------------
1 | {
2 | "_class": "exportFormat",
3 | "absoluteSize": 0,
4 | "fileFormat": "png",
5 | "name": "",
6 | "namingScheme": 0,
7 | "scale": 1,
8 | "visibleScaleType": 0
9 | }
--------------------------------------------------------------------------------
/models/ExportFormat/index.d.ts:
--------------------------------------------------------------------------------
1 | declare class ExportFormat {
2 | _class: 'exportFormat';
3 | absoluteSize: number;
4 | fileFormat: string;
5 | name: string;
6 | nameScheme: number;
7 | scale: number;
8 | visibleScaleType: number;
9 |
10 | constructor(args?: any, json?: any);
11 | }
12 |
13 | export = ExportFormat;
14 |
--------------------------------------------------------------------------------
/models/ExportFormat/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./ExportFormat');
15 |
--------------------------------------------------------------------------------
/models/ExportOptions/ExportOptions.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | /**
15 | * Options for exporting an artboard
16 | */
17 | class ExportOptions {
18 | /**
19 | * @property {Array} exportFormats
20 | * @property {String[]} includedLayerIds
21 | * @property {integer} layerOptions
22 | * @property {boolean} shouldTrim
23 | */
24 | static get Model() {
25 | return {
26 | _class: 'exportOptions',
27 | exportFormats: [],
28 | includedLayerIds: [],
29 | layerOptions: 0,
30 | shouldTrim: false,
31 | };
32 | }
33 |
34 | /**
35 | *
36 | * @param {ExportOptions.Model} args
37 | * @param {ExportOptions.Model} json
38 | */
39 | constructor(args = {}, json) {
40 | if (json) {
41 | Object.assign(this, json);
42 | } else {
43 | Object.assign(this, ExportOptions.Model, args);
44 | }
45 | return this;
46 | }
47 | }
48 |
49 | module.exports = ExportOptions;
50 |
--------------------------------------------------------------------------------
/models/ExportOptions/ExportOptions.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const ExportOptions = require('./index');
15 | const json = require('./__ExportOptions.json');
16 |
17 | describe('ExportOptions', () => {
18 | it('should work from raw JSON', () => {
19 | const exportOptions = new ExportOptions(null, json);
20 | expect(JSON.stringify(json, null, 2)).toEqual(JSON.stringify(exportOptions, null, 2));
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/ExportOptions/__ExportOptions.json:
--------------------------------------------------------------------------------
1 | {
2 | "_class": "exportOptions",
3 | "exportFormats": [
4 | {
5 | "_class": "exportFormat",
6 | "absoluteSize": 0,
7 | "fileFormat": "png",
8 | "name": "",
9 | "namingScheme": 0,
10 | "scale": 1,
11 | "visibleScaleType": 0
12 | }
13 | ],
14 | "includedLayerIds": [],
15 | "layerOptions": 0,
16 | "shouldTrim": false
17 | }
--------------------------------------------------------------------------------
/models/ExportOptions/index.d.ts:
--------------------------------------------------------------------------------
1 | import ExportFormat from '../ExportFormat';
2 |
3 | declare class ExportOptions {
4 | _class: 'exportOptions';
5 | exportFormats: ExportFormat[];
6 | includedLayerIds: string[];
7 | layerOptions: number;
8 | shouldTrim: boolean;
9 | constructor(args?: any, json?: any);
10 | }
11 |
12 | export = ExportOptions;
13 |
--------------------------------------------------------------------------------
/models/ExportOptions/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./ExportOptions');
15 |
--------------------------------------------------------------------------------
/models/Fill/Fill.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Fill = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Fill', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 |
23 | it('should work from user generated', () => {
24 | const fill = new Fill({
25 | color: '#fff',
26 | });
27 | expect(true).toBeTruthy();
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/models/Fill/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 | import Gradient from '../Gradient';
3 | import GraphicsContextSettings from '../GraphicsContextSettings';
4 |
5 | declare const enum FillType {
6 | Color = 0,
7 | Gradient = 1,
8 | Pattern = 4,
9 | Noise = 5,
10 | }
11 |
12 | declare class Fill {
13 | static FillType: typeof FillType;
14 |
15 | _class: 'fill';
16 | isEnabled: boolean;
17 | color: Color;
18 | fillType: FillType;
19 | noiseIndex: number;
20 | noiseIntensity: number;
21 | patternFillType: number;
22 | patternTileScale: number;
23 | gradient: Gradient;
24 | contextSettings: GraphicsContextSettings;
25 |
26 | constructor(args?: any, json?: any);
27 | }
28 |
29 | export = Fill;
30 |
--------------------------------------------------------------------------------
/models/Fill/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Fill');
15 |
--------------------------------------------------------------------------------
/models/Gradient/Gradient.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Color = require('../Color');
15 |
16 | /**
17 | * Gradient
18 | */
19 | class Gradient {
20 | static get Model() {
21 | return {
22 | _class: 'gradient',
23 | elipseLength: 0,
24 | from: '{0.5, 0}',
25 | to: '{0.5, 1}',
26 | gradientType: 1,
27 | stops: [],
28 | };
29 | }
30 |
31 | /**
32 | *
33 | * @param {Object} args
34 | * @param {Gradient.Model} json
35 | */
36 | constructor(args, json) {
37 | if (json) {
38 | Object.assign(this, json);
39 | } else {
40 | Object.assign(this, Gradient.Model, args);
41 | }
42 | }
43 | }
44 |
45 | Gradient.GradientStop = {
46 | _class: 'gradientStop',
47 | color: Color.Model,
48 | position: 0,
49 | };
50 |
51 | Gradient.GradientType = {
52 | Linear: 0,
53 | Radial: 1,
54 | Angular: 2,
55 | };
56 |
57 | module.exports = Gradient;
58 |
--------------------------------------------------------------------------------
/models/Gradient/Gradient.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Gradient = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Gradient', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Gradient/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 |
3 | declare const enum GradientType {
4 | Linear = 0,
5 | Radial = 1,
6 | Angular = 2
7 | }
8 |
9 | declare class Gradient {
10 | static GradientStop: {
11 | _class: 'gradientStop';
12 | color: Color;
13 | position: number;
14 | };
15 |
16 | static GradientType: typeof GradientType;
17 |
18 | _class: 'gradient';
19 | elipseLength: number;
20 | from: string;
21 | to: string;
22 | gradientType: GradientType;
23 | stops: Array;
24 |
25 | constructor(args?: any, json?: any);
26 | }
27 |
28 | export = Gradient;
29 |
--------------------------------------------------------------------------------
/models/Gradient/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Gradient');
15 |
--------------------------------------------------------------------------------
/models/GraphicsContextSettings/GraphicsContextSettings.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const { blendModeMap } = require('../../utils/maps');
15 |
16 | /**
17 | * Options for exporting an artboard
18 | */
19 | class GraphicsContextSettings {
20 | /**
21 | * @property {integer} blendMode
22 | * @property {float} opacity
23 | */
24 | static get Model() {
25 | return {
26 | _class: 'graphicsContextSettings',
27 | blendMode: 0,
28 | opacity: 1,
29 | };
30 | }
31 |
32 | /**
33 | *
34 | * @param {GraphicsContextSettings.Model} args
35 | * @param {GraphicsContextSettings.Model} json
36 | */
37 | constructor(args = {}, json) {
38 | if (json) {
39 | Object.assign(this, json);
40 | } else {
41 | Object.assign(this, GraphicsContextSettings.Model, args, {
42 | blendMode: blendModeMap[args.blendMode || 'normal'],
43 | opacity: Number.isFinite(args.opacity) ? args.opacity : 1,
44 | });
45 | }
46 | return this;
47 | }
48 | }
49 |
50 | module.exports = GraphicsContextSettings;
51 |
--------------------------------------------------------------------------------
/models/GraphicsContextSettings/GraphicsContextSettings.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const GraphicsContextSettings = require('./index');
15 | const json = require('./__GraphicsContextSettings.json');
16 |
17 | describe('GraphicsContextSettings', () => {
18 | it('should work from raw JSON', () => {
19 | const graphicsContextSettings = new GraphicsContextSettings(null, json);
20 | expect(JSON.stringify(json, null, 2)).toEqual(JSON.stringify(graphicsContextSettings, null, 2));
21 | });
22 |
23 | it('should correctly handle opacity = 0', () => {
24 | const graphicsContextSettings = new GraphicsContextSettings({
25 | opacity: 0,
26 | });
27 |
28 | expect(graphicsContextSettings.opacity).toBe(0);
29 | });
30 | });
31 |
--------------------------------------------------------------------------------
/models/GraphicsContextSettings/__GraphicsContextSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "_class": "graphicsContextSettings",
3 | "blendMode": 0,
4 | "opacity": 1
5 | }
--------------------------------------------------------------------------------
/models/GraphicsContextSettings/index.d.ts:
--------------------------------------------------------------------------------
1 | declare class GraphicsContextSettings {
2 | _class: 'graphicsContextSettings';
3 | blendMode: number;
4 | opacity: number;
5 | constructor(args?: any, json?: any);
6 | }
7 |
8 | export = GraphicsContextSettings;
9 |
--------------------------------------------------------------------------------
/models/GraphicsContextSettings/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./GraphicsContextSettings');
15 |
--------------------------------------------------------------------------------
/models/Group/Group.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Layer = require('../Layer');
16 | const Rect = require('../Rect');
17 | const Style = require('../Style');
18 |
19 | /**
20 | * A group extends
21 | * @extends Layer
22 | *
23 | */
24 | class Group extends Layer {
25 | /**
26 | * @mixes Layer.Model
27 | */
28 | static get Model() {
29 | return {
30 | ...Layer.Model,
31 | _class: 'group',
32 | layerListExpandedType: 2,
33 | resizingConstraint: 63,
34 | hasClickThrough: false,
35 | };
36 | }
37 |
38 | /**
39 | *
40 | * @param {Object} args
41 | * @param {Object} args.frame Sent to {@link Rect}
42 | * @param {Object} args.style Sent to {@link Style}
43 | * @param {Layer[]} args.layers
44 | * @param {Group.Model} json
45 | */
46 | constructor(args = {}, json) {
47 | super(args, json);
48 | if (!json) {
49 | const id = args.id || uuid().toUpperCase();
50 | Object.assign(this, Group.Model, {
51 | do_objectID: id,
52 | name: args.name || id,
53 | frame: new Rect(args.frame),
54 | style: new Style(args.style),
55 | layers: args.layers || [],
56 | });
57 | }
58 |
59 | return this;
60 | }
61 | }
62 |
63 | module.exports = Group;
64 |
--------------------------------------------------------------------------------
/models/Group/Group.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Group = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Group', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Group/index.d.ts:
--------------------------------------------------------------------------------
1 | import Layer from '../Layer';
2 |
3 | declare class Group extends Layer {
4 | _class: string;
5 | hasClickThrough: boolean;
6 | constructor(args?: any, json?: any);
7 | }
8 |
9 | export = Group;
10 |
--------------------------------------------------------------------------------
/models/Group/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Group');
15 |
--------------------------------------------------------------------------------
/models/InnerShadow/InnerShadow.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Color = require('../Color');
15 | const GraphicsContextSettings = require('../GraphicsContextSettings');
16 |
17 | class InnerShadow {
18 | static get Model() {
19 | return {
20 | _class: 'innerShadow',
21 | isEnabled: true,
22 | blurRadius: 3,
23 | color: Color.Model,
24 | contextSettings: GraphicsContextSettings.Model,
25 | offsetX: 0,
26 | offsetY: 1,
27 | spread: 0,
28 | };
29 | }
30 |
31 | constructor(args, json) {
32 | if (json) {
33 | Object.assign(this, json);
34 | } else {
35 | Object.assign(this, InnerShadow.Model, args, {
36 | color: new Color(args.color),
37 | });
38 | }
39 | }
40 | }
41 |
42 | module.exports = InnerShadow;
43 |
--------------------------------------------------------------------------------
/models/InnerShadow/InnerShadow.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const InnerShadow = require('./index');
15 |
16 | const json = require('./__InnerShadow.json');
17 |
18 | describe('InnerShadow', () => {
19 | it('should work from raw JSON', () => {
20 | const innerShadow = new InnerShadow(null, json);
21 | expect(JSON.stringify(json, null, 2)).toEqual(JSON.stringify(innerShadow, null, 2));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/models/InnerShadow/__InnerShadow.json:
--------------------------------------------------------------------------------
1 | {
2 | "_class": "innerShadow",
3 | "isEnabled": true,
4 | "blurRadius": 3,
5 | "offsetX": 0,
6 | "offsetY": 1,
7 | "spread": 0,
8 | "color": {
9 | "_class": "color",
10 | "alpha": 0.5,
11 | "blue": 0,
12 | "green": 0,
13 | "red": 0
14 | },
15 | "contextSettings": {
16 | "_class": "graphicsContextSettings",
17 | "blendMode": 0,
18 | "opacity": 1
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/models/InnerShadow/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 | import GraphicsContextSettings from '../GraphicsContextSettings';
3 |
4 | declare class InnerShadow {
5 | _class: 'innerShadow';
6 | isEnabled: boolean;
7 | blurRadius: number;
8 | color: Color;
9 | contextSettings: GraphicsContextSettings;
10 | offsetX: number;
11 | offsetY: number;
12 | spread: number;
13 |
14 | constructor(args?: any, json?: any);
15 | }
16 |
17 | export = InnerShadow;
18 |
--------------------------------------------------------------------------------
/models/InnerShadow/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./InnerShadow');
15 |
--------------------------------------------------------------------------------
/models/Layer/Layer.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Group = require('../Group');
15 | const Text = require('../Text');
16 |
17 | describe('Layer', () => {
18 | it('should work from raw JSON', () => {
19 | expect(true).toBeTruthy();
20 | });
21 | });
22 |
23 | describe('getLayers', () => {
24 | it('should get all children layers', () => {
25 | const group = new Group({
26 | name: 'group',
27 | });
28 | const text1 = new Text({
29 | name: 'text1',
30 | });
31 | const text2 = new Text({
32 | name: 'text2',
33 | });
34 |
35 | group.addLayer(text1);
36 | group.addLayer(text2);
37 |
38 | const layers = group.getLayers().map((l) => l.name);
39 |
40 | expect(layers.sort()).toEqual(['text1', 'text2'].sort());
41 | });
42 |
43 | it('should only get direct children layers', () => {
44 | const outerGroup = new Group({
45 | name: 'outer group',
46 | });
47 |
48 | const innerGroup = new Group({
49 | name: 'inner group',
50 | });
51 | const text = new Text({
52 | name: 'text',
53 | });
54 |
55 | innerGroup.addLayer(text);
56 | outerGroup.addLayer(innerGroup);
57 |
58 | const layers = outerGroup.getLayers().map((l) => l.name);
59 |
60 | expect(layers.sort()).toEqual(['inner group'].sort());
61 | });
62 | });
63 |
64 | describe('getAllLayers', () => {
65 | it('should get all children layers', () => {
66 | const outerGroup = new Group({
67 | name: 'outer group',
68 | });
69 |
70 | const innerGroup = new Group({
71 | name: 'inner group',
72 | });
73 | const text = new Text({
74 | name: 'text',
75 | });
76 |
77 | innerGroup.addLayer(text);
78 | outerGroup.addLayer(innerGroup);
79 |
80 | const layers = outerGroup.getAllLayers().map((l) => l.name);
81 |
82 | expect(layers.sort()).toEqual(['inner group', 'text'].sort());
83 | });
84 | });
85 |
--------------------------------------------------------------------------------
/models/Layer/index.d.ts:
--------------------------------------------------------------------------------
1 | import ExportOptions from '../ExportOptions';
2 | import Group from '../Group';
3 | import Rect from '../Rect';
4 | import SharedStyle from '../SharedStyle';
5 | import Style from '../Style';
6 |
7 | declare class Layer {
8 | _class: string;
9 | do_objectID: string;
10 | booleanOperation: number;
11 | exportOptions: ExportOptions;
12 | frame: Rect;
13 | isFixedToViewport: boolean;
14 | isFlippedHorizontal: boolean;
15 | isFlippedVertical: boolean;
16 | isLocked: boolean;
17 | isVisible: boolean;
18 | name: string;
19 | nameIsFixed: boolean;
20 | resizingConstraint: number;
21 | resizingType: number;
22 | rotation: number;
23 | shouldBreakMaskChain: boolean;
24 | style: Style;
25 |
26 | constructor(args?: any, json?: any);
27 |
28 | addLayer(layer: Layer): Layer;
29 |
30 | setSharedStyle(style: SharedStyle): void;
31 |
32 | getGroups(): Group[];
33 |
34 | getLayers(predicate?: string | RegExp): Layer[];
35 |
36 | getAllLayers(predicate?: string | RegExp): Layer[];
37 |
38 | getID(): string;
39 | }
40 |
41 | export = Layer;
42 |
--------------------------------------------------------------------------------
/models/Layer/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Layer');
15 |
--------------------------------------------------------------------------------
/models/Meta/Meta.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | /**
15 | * This is an internal class, you shouldn't be directly dealing with this class. It outputs the meta.json file in the top level directory of a Sketch file.
16 | */
17 | class Meta {
18 | /**
19 | * @property {String} commit
20 | * @property {Object} pagesAndArtboards
21 | * @property {integer} version
22 | * @property {Array} fonts
23 | * @property {integer} compatibilityVersion
24 | * @property {String} app
25 | */
26 | static get Model() {
27 | return {
28 | commit: '238f363ed3de77eb1d86e03176f8a10f7928ed51',
29 | pagesAndArtboards: {},
30 | version: 134,
31 | fonts: [],
32 | compatibilityVersion: 99,
33 | app: 'com.bohemiancoding.sketch3',
34 | autosaved: 0,
35 | variant: 'NONAPPSTORE',
36 | created: {
37 | commit: '238f363ed3de77eb1d86e03176f8a10f7928ed51',
38 | appVersion: '69',
39 | build: 107357,
40 | app: 'com.bohemiancoding.sketch3',
41 | compatibilityVersion: 99,
42 | version: 134,
43 | variant: 'NONAPPSTORE',
44 | },
45 | saveHistory: ['NONAPPSTORE.107357'],
46 | appVersion: '69',
47 | build: 107357,
48 | };
49 | }
50 |
51 | /**
52 | *
53 | * @param {Meta.Model} args
54 | * @param {Meta.Model} json
55 | */
56 | constructor(args = {}, json) {
57 | if (json) {
58 | Object.assign(this, json);
59 | } else {
60 | Object.assign(this, Meta.Model, args);
61 | }
62 | }
63 |
64 | addPage(page) {
65 | this.pagesAndArtboards[page.getID()] = {
66 | name: page.name,
67 | artboards: page.getArtboards().reduce((ret, artboard) => {
68 | ret[artboard.do_objectID] = { name: artboard.name };
69 | return ret;
70 | }, {}),
71 | };
72 | }
73 |
74 | addArtboard(pageID, artboard) {
75 | this.pagesAndArtboards[pageID].artboards[artboard.getID()] = {
76 | name: artboard.name,
77 | };
78 | }
79 | }
80 |
81 | module.exports = Meta;
82 |
--------------------------------------------------------------------------------
/models/Meta/Meta.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Meta = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Meta', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Meta/index.d.ts:
--------------------------------------------------------------------------------
1 | import Artboard from '../Artboard';
2 | import Page from '../Page';
3 |
4 | declare class Meta {
5 | commit: string;
6 | pagesAndArtboards: any;
7 | version: number;
8 | fonts: any[]; // TODO
9 | compatibilityVersion: number;
10 | app: string;
11 | autosaved: number;
12 | variant: string;
13 | created: {
14 | commit: string;
15 | appVersion: string;
16 | build: number;
17 | app: string;
18 | compatibilityVersion: number;
19 | version: number;
20 | variant: string;
21 | };
22 | saveHistory: string[];
23 | appVersion: string;
24 | build: string;
25 |
26 | constructor(args?: any, json?: any);
27 |
28 | addPage(page: Page): void;
29 |
30 | addArtboard(pageID: string, artboard: Artboard): void;
31 | }
32 |
33 | export = Meta;
34 |
--------------------------------------------------------------------------------
/models/Meta/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Meta');
15 |
--------------------------------------------------------------------------------
/models/Oval/Oval.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Layer = require('../Layer');
16 | const CurvePoint = require('../CurvePoint');
17 | const Rect = require('../Rect');
18 | const Style = require('../Style');
19 |
20 | const points = ['{0.5, 1}', '{1, 0.5}', '{0.5, 0}', '{0, 0.5}'];
21 | const pointsFrom = [
22 | '{0.77614237490000004, 1}',
23 | '{1, 0.22385762510000001}',
24 | '{0.22385762510000001, 0}',
25 | '{0, 0.77614237490000004}',
26 | ];
27 | const pointsTo = [
28 | '{0.22385762510000001, 1}',
29 | '{1, 0.77614237490000004}',
30 | '{0.77614237490000004, 0}',
31 | '{0, 0.22385762510000001}',
32 | ];
33 |
34 | /**
35 | *
36 | */
37 | class Oval extends Layer {
38 | /**
39 | * @mixes Layer.Model
40 | * @property {boolean} edited
41 | * @property {boolean} isClosed
42 | * @property {integer} pointRadiusBehaviour
43 | * @property {String[]} points
44 | */
45 | static get Model() {
46 | return { ...Layer.Model, _class: 'oval', edited: false, isClosed: true, pointRadiusBehaviour: 1, points: [] };
47 | }
48 |
49 | /**
50 | *
51 | * @param {Object} args
52 | * @param {String} args.name
53 | * @param {integer} args.x
54 | * @param {integer} args.y
55 | * @param {integer} args.height
56 | * @param {integer} args.width
57 | * @param {Object} args.style Passed to {@link LayerStyle}
58 | * @param {Oval.Model} json
59 | */
60 | constructor(args = {}, json) {
61 | super(args, json);
62 | if (!json) {
63 | const id = args.id || uuid().toUpperCase();
64 | Object.assign(this, Oval.Model, {
65 | points: points.map(
66 | (point, index) =>
67 | new CurvePoint({
68 | point,
69 | curveFrom: pointsFrom[index],
70 | curveTo: pointsTo[index],
71 | curveMode: 2,
72 | hasCurveFrom: true,
73 | hasCurveTo: true,
74 | })
75 | ),
76 | do_objectID: id,
77 | frame: new Rect({
78 | x: args.x,
79 | y: args.y,
80 | width: args.width,
81 | height: args.height,
82 | }),
83 | style: new Style(args.style),
84 | name: args.name || id,
85 | });
86 | }
87 | }
88 | }
89 |
90 | module.exports = Oval;
91 |
--------------------------------------------------------------------------------
/models/Oval/Oval.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Oval = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Oval', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Oval/index.d.ts:
--------------------------------------------------------------------------------
1 | import Layer from '../Layer';
2 | import CurvePoint from '../CurvePoint';
3 |
4 | declare class Oval extends Layer {
5 | _class: 'oval';
6 | edited: boolean;
7 | isClosed: boolean;
8 | pointRadiusBehaviour: number;
9 | points: CurvePoint[];
10 | constructor(args?: any, json?: any);
11 | }
12 |
13 | export = Oval;
14 |
--------------------------------------------------------------------------------
/models/Oval/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Oval');
15 |
--------------------------------------------------------------------------------
/models/Page/Page.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Rect = require('../Rect');
16 | const Style = require('../Style');
17 | const Group = require('../Group');
18 |
19 | /**
20 | *
21 | */
22 | class Page extends Group {
23 | /**
24 | * @mixes Group.Model
25 | */
26 | static get Model() {
27 | return { ...Group.Model, _class: 'page' };
28 | }
29 |
30 | /**
31 | *
32 | * @param {Object} args
33 | * @param {Object} args.style {@link Style}
34 | * @param {Page.Model} json
35 | */
36 | constructor(args = {}, json) {
37 | super(args, json);
38 | if (!json) {
39 | const id = args.id || uuid().toUpperCase();
40 | Object.assign(this, Page.Model, {
41 | do_objectID: id,
42 | name: args.name || id,
43 | frame: new Rect(args.frame),
44 | style: new Style(args.style),
45 | layers: args.layers || [],
46 | });
47 | }
48 | }
49 |
50 | getID() {
51 | return this.do_objectID;
52 | }
53 |
54 | /**
55 | *
56 | * @param {function} predicate
57 | * @returns {Artboard[]}
58 | */
59 | getArtboards(predicate) {
60 | const arr = this.layers.filter((layer) => layer._class === 'artboard');
61 | if (predicate) {
62 | return arr.filter(predicate);
63 | }
64 | return arr;
65 | }
66 |
67 | /**
68 | *
69 | * @param {String} name
70 | * @returns {Artboard}
71 | */
72 | getArtboard(name) {
73 | return this.getArtboards().find((artboard) => artboard.name === name);
74 | }
75 |
76 | /**
77 | *
78 | * @param {Artboard} artboard
79 | * @returns {this}
80 | */
81 | addArtboard(artboard) {
82 | this.layers = this.layers.concat(artboard);
83 | return this;
84 | }
85 | }
86 |
87 | module.exports = Page;
88 |
--------------------------------------------------------------------------------
/models/Page/Page.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Page = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Page', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Page/index.d.ts:
--------------------------------------------------------------------------------
1 | import Artboard from '../Artboard';
2 | import Group from '../Group';
3 |
4 | declare class Page extends Group {
5 | _class: 'page';
6 |
7 | constructor(args?: any, json?: any);
8 |
9 | getArtboards(predicate?: string | RegExp): Artboard[];
10 |
11 | getArtboard(name: string): Artboard | undefined;
12 |
13 | addArtboard(artboard: Artboard): Page;
14 | }
15 |
16 | export = Page;
17 |
--------------------------------------------------------------------------------
/models/Page/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Page');
15 |
--------------------------------------------------------------------------------
/models/ParagraphStyle/ParagraphStyle.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const { textAlignmentMap } = require('../../utils/maps');
15 |
16 | class ParagraphStyle {
17 | static get Model() {
18 | return {
19 | _class: 'paragraphStyle',
20 | alignment: 0,
21 | };
22 | }
23 |
24 | constructor(args, json) {
25 | if (json) {
26 | Object.assign(this, json);
27 | } else {
28 | Object.assign(this, ParagraphStyle.Model);
29 | if (args.alignment) this.alignment = textAlignmentMap[args.alignment];
30 | if (args.lineHeight) {
31 | this.maximumLineHeight = args.lineHeight;
32 | this.minimumLineHeight = args.lineHeight;
33 | }
34 | if (args.paragraphSpacing) this.paragraphSpacing = args.paragraphSpacing;
35 | }
36 | }
37 | }
38 |
39 | module.exports = ParagraphStyle;
40 |
--------------------------------------------------------------------------------
/models/ParagraphStyle/index.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | declare const enum Alignment {
15 | LEFT = 0,
16 | RIGHT = 1,
17 | CENTER = 2,
18 | JUSTIFY = 3,
19 | }
20 |
21 | declare class ParagraphStyle {
22 | _class: 'paragraphStyle';
23 | alignment: Alignment;
24 | minimumLineHeight: number;
25 | maximumLineHeight: number;
26 | paragraphSpacing: number;
27 |
28 | constructor(args?: any, json?: any);
29 | }
30 |
31 | export = ParagraphStyle;
32 |
--------------------------------------------------------------------------------
/models/ParagraphStyle/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./ParagraphStyle');
15 |
--------------------------------------------------------------------------------
/models/Rect/Rect.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | /**
15 | * A Rect is a lower-level class used to define the frame of a layer. Don't use this
16 | * if you mean to use a Rectangle instead!
17 | */
18 | class Rect {
19 | /**
20 | * Underlying JSON object structure in a Sketch document
21 | * @property {boolean} constrainProportions
22 | * @property {integer} height
23 | * @property {integer} width
24 | * @property {integer} x
25 | * @property {integer} y
26 | */
27 | static get Model() {
28 | return {
29 | _class: 'rect',
30 | constrainProportions: false,
31 | height: 100,
32 | width: 100,
33 | x: 0,
34 | y: 0,
35 | };
36 | }
37 |
38 | /**
39 | *
40 | * @param {Rect.Model} args
41 | * @param {Rect.Model} json
42 | */
43 | constructor(args = {}, json) {
44 | if (json) {
45 | Object.assign(this, json);
46 | } else {
47 | Object.assign(this, Rect.Model, args);
48 | }
49 | }
50 | }
51 |
52 | module.exports = Rect;
53 |
--------------------------------------------------------------------------------
/models/Rect/Rect.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Rect = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Rect', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Rect/index.d.ts:
--------------------------------------------------------------------------------
1 | declare class Rect {
2 | _class: 'rect';
3 | constrainProportions: boolean;
4 | height: number;
5 | width: number;
6 | x: number;
7 | y: number;
8 | constructor(args?: any, json?: any);
9 | }
10 |
11 | export = Rect;
12 |
--------------------------------------------------------------------------------
/models/Rect/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Rect');
15 |
--------------------------------------------------------------------------------
/models/Rectangle/Rectangle.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Layer = require('../Layer');
16 | const CurvePoint = require('../CurvePoint');
17 | const Rect = require('../Rect');
18 | const Style = require('../Style');
19 |
20 | const points = ['{0, 0}', '{1, 0}', '{1, 1}', '{0, 1}'];
21 |
22 | const cornerRadius = (radius, index) => {
23 | if (radius) {
24 | if (Array.isArray(radius)) {
25 | return radius[index];
26 | }
27 | return radius;
28 | }
29 | return 0;
30 | };
31 | /**
32 | *
33 | */
34 | class Rectangle extends Layer {
35 | /**
36 | * @mixes Layer.Model
37 | * @property {boolean} edited
38 | * @property {boolean} isClosed
39 | * @property {integer} pointRadiusBehaviour
40 | * @property {String[]} points
41 | * @property {integer} fixedRadius
42 | * @property {boolean} hasConvertedToNewRoundCorners
43 | */
44 | static get Model() {
45 | return {
46 | ...Layer.Model,
47 | _class: 'rectangle',
48 | edited: false,
49 | isClosed: true,
50 | pointRadiusBehaviour: 1,
51 | points: [],
52 | fixedRadius: 0,
53 | hasConvertedToNewRoundCorners: true,
54 | };
55 | }
56 |
57 | /**
58 | *
59 | * @param {Object} args
60 | * @param {String} args.name
61 | * @param {integer} args.x
62 | * @param {integer} args.y
63 | * @param {integer} args.height
64 | * @param {integer} args.width
65 | * @param {Object} args.style Passed to {@link LayerStyle}
66 | * @param {Rectangle.Model} json
67 | */
68 | constructor(args = {}, json) {
69 | super(args, json);
70 | if (!json) {
71 | const id = args.id || uuid().toUpperCase();
72 | Object.assign(this, Rectangle.Model, {
73 | points:
74 | args.points ||
75 | points.map(
76 | (point, index) =>
77 | new CurvePoint({
78 | curveFrom: point,
79 | curveTo: point,
80 | cornerRadius: cornerRadius(args.cornerRadius, index),
81 | point,
82 | })
83 | ),
84 | do_objectID: id,
85 | frame: new Rect({
86 | x: args.x,
87 | y: args.y,
88 | width: args.width,
89 | height: args.height,
90 | }),
91 | style: new Style(args.style),
92 | name: args.name || id,
93 | });
94 | }
95 | }
96 | }
97 |
98 | module.exports = Rectangle;
99 |
--------------------------------------------------------------------------------
/models/Rectangle/Rectangle.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Rectangle = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Rectangle', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Rectangle/index.d.ts:
--------------------------------------------------------------------------------
1 | import Layer from '../Layer';
2 | import CurvePoint from '../CurvePoint';
3 |
4 | declare class Rectangle extends Layer {
5 | _class: 'rectangle';
6 | edited: boolean;
7 | isClosed: boolean;
8 | pointRadoisBehaviour: number;
9 | points: CurvePoint[];
10 | fixedRadius: number;
11 | hasConvertedToNewRoundCorners: boolean;
12 | constructor(args?: any, json?: any);
13 | }
14 |
15 | export = Rectangle;
16 |
--------------------------------------------------------------------------------
/models/Rectangle/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Rectangle');
15 |
--------------------------------------------------------------------------------
/models/RulerData/RulerData.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | /**
15 | *
16 | */
17 | class RulerData {
18 | /**
19 | * @property {integer} base
20 | * @property {Array} guides
21 | */
22 | static get Model() {
23 | return {
24 | _class: 'rulerData',
25 | base: 0,
26 | guides: [],
27 | };
28 | }
29 |
30 | /**
31 | *
32 | * @param {RulerData.Model} args
33 | * @param {RulerData.Model} json
34 | */
35 | constructor(args = {}, json) {
36 | if (json) {
37 | Object.assign(this, json);
38 | } else {
39 | Object.assign(this, RulerData.Model, args);
40 | }
41 | }
42 | }
43 |
44 | module.exports = RulerData;
45 |
--------------------------------------------------------------------------------
/models/RulerData/RulerData.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const RulerData = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('RulerData', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/RulerData/index.d.ts:
--------------------------------------------------------------------------------
1 | declare class RulerData {
2 | _class: 'rulerData';
3 | base: number;
4 | guides: any[]; // TODO
5 |
6 | constructor(args?: any, json?: any);
7 | }
8 |
9 | export = RulerData;
--------------------------------------------------------------------------------
/models/RulerData/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./RulerData');
15 |
--------------------------------------------------------------------------------
/models/Shadow/Shadow.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Color = require('../Color');
15 | const GraphicsContextSettings = require('../GraphicsContextSettings');
16 |
17 | class Shadow {
18 | static get Model() {
19 | return {
20 | _class: 'shadow',
21 | isEnabled: true,
22 | blurRadius: 4,
23 | color: Color.Model,
24 | contextSettings: GraphicsContextSettings.Model,
25 | offsetX: 0,
26 | offsetY: 2,
27 | spread: 0,
28 | };
29 | }
30 |
31 | constructor(args, json) {
32 | if (json) {
33 | Object.assign(this, json);
34 | } else {
35 | Object.assign(this, Shadow.Model, args, {
36 | color: new Color(args.color),
37 | });
38 | }
39 | }
40 | }
41 |
42 | module.exports = Shadow;
43 |
--------------------------------------------------------------------------------
/models/Shadow/Shadow.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Shadow = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Shadow', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Shadow/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 | import GraphicsContextSettings from '../GraphicsContextSettings';
3 |
4 | declare class Shadow {
5 | _class: 'shadow';
6 | isEnabled: boolean;
7 | blurRadius: number;
8 | color: Color;
9 | contextSettings: GraphicsContextSettings;
10 | offsetX: number;
11 | offsetY: number;
12 | spread: number;
13 |
14 | constructor(args?: any, json?: any);
15 | }
16 |
17 | export = Shadow;
18 |
--------------------------------------------------------------------------------
/models/Shadow/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Shadow');
15 |
--------------------------------------------------------------------------------
/models/ShapeGroup/ShapeGroup.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const ShapeGroup = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('ShapeGroup', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/ShapeGroup/index.d.ts:
--------------------------------------------------------------------------------
1 | import Layer from '../Layer';
2 |
3 | declare class ShapeGroup extends Layer {
4 | static Rectangle(args: any): ShapeGroup;
5 |
6 | static Oval(args: any): ShapeGroup;
7 |
8 | static ShapePath(args: any): ShapeGroup;
9 |
10 | _class: 'shapeGroup';
11 | clippingMaskMode: number;
12 | hasClippingMask: boolean;
13 | windingRule: number;
14 |
15 | constructor(args?: any, json?: any);
16 | }
17 |
18 | export = ShapeGroup;
19 |
--------------------------------------------------------------------------------
/models/ShapeGroup/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./ShapeGroup');
15 |
--------------------------------------------------------------------------------
/models/ShapePath/ShapePath.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Layer = require('../Layer');
16 | const Rect = require('../Rect');
17 | const Style = require('../Style');
18 |
19 | /**
20 | *
21 | */
22 | class ShapePath extends Layer {
23 | /**
24 | * @mixes Layer.Model
25 | * @property {boolean} edited
26 | * @property {boolean} isClosed
27 | * @property {integer} pointRadiusBehaviour
28 | * @property {String[]} points
29 | */
30 | static get Model() {
31 | return { ...Layer.Model, _class: 'shapePath', edited: true, isClosed: false, pointRadiusBehaviour: 1, points: [] };
32 | }
33 |
34 | /**
35 | *
36 | * @param {Object} args
37 | * @param {String} args.name
38 | * @param {integer} args.x
39 | * @param {integer} args.y
40 | * @param {integer} args.height
41 | * @param {integer} args.width
42 | * @param {Array.} args.points
43 | * @param {Object} args.style Passed to {@link LayerStyle}
44 | * @param {ShapePath.Model} json
45 | */
46 | constructor(args = {}, json) {
47 | super(args, json);
48 | if (!json) {
49 | const id = args.id || uuid().toUpperCase();
50 | Object.assign(this, ShapePath.Model, {
51 | points: args.points || [],
52 | do_objectID: id,
53 | frame: new Rect({
54 | x: args.x,
55 | y: args.y,
56 | width: args.width,
57 | height: args.height,
58 | }),
59 | style: new Style(args.style),
60 | name: args.name || id,
61 | });
62 | }
63 | }
64 | }
65 |
66 | module.exports = ShapePath;
67 |
--------------------------------------------------------------------------------
/models/ShapePath/ShapePath.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const ShapePath = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('ShapePath', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/ShapePath/index.d.ts:
--------------------------------------------------------------------------------
1 | import Layer = require('../Layer');
2 | import CurvePoint = require('../CurvePoint');
3 |
4 | declare class ShapePath extends Layer {
5 | _class: 'shapePath';
6 | edited: boolean;
7 | isClosed: boolean;
8 | pointRadiusBehaviour: number;
9 | points: CurvePoint[];
10 |
11 | constructor(args: any, json: any);
12 | }
13 |
14 | export = ShapePath;
15 |
--------------------------------------------------------------------------------
/models/ShapePath/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./ShapePath');
15 |
--------------------------------------------------------------------------------
/models/SharedStyle/SharedStyle.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Style = require('../Style');
16 |
17 | class SharedStyle {
18 | static LayerStyle(args) {
19 | const id = args.id || uuid().toUpperCase();
20 | return new SharedStyle({
21 | name: args.name,
22 | id,
23 | fills: args.fills,
24 | borders: args.borders,
25 | shadows: args.shadows,
26 | innerShadows: args.innerShadows,
27 | });
28 | }
29 |
30 | static TextStyle(args) {
31 | const id = args.id || uuid().toUpperCase();
32 | return new SharedStyle({
33 | name: args.name,
34 | id,
35 | textStyle: args.textStyle,
36 | });
37 | }
38 |
39 | constructor(args, json) {
40 | if (json) {
41 | Object.assign(this, json);
42 | // Created nested class
43 | this.value = new Style(null, this.value);
44 | } else {
45 | const id = args.id || uuid().toUpperCase();
46 | Object.assign(this, {
47 | name: args.name || 'Name',
48 | do_objectID: id,
49 | _class: 'sharedStyle',
50 | value: new Style({
51 | id,
52 | textStyle: args.textStyle,
53 | borders: args.borders,
54 | fills: args.fills,
55 | shadows: args.shadows,
56 | innerShadows: args.innerShadows,
57 | }),
58 | });
59 | }
60 | }
61 | }
62 |
63 | module.exports = SharedStyle;
64 |
--------------------------------------------------------------------------------
/models/SharedStyle/SharedStyle.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const SharedStyle = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('SharedStyle', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 |
23 | it('should work', () => {
24 | const sharedStyle = new SharedStyle({
25 | name: 'foo',
26 | });
27 | expect(sharedStyle.name).toEqual('foo');
28 | });
29 |
30 | describe('LayerStyle', () => {
31 | it('should work', () => {
32 | const layerStyle = SharedStyle.LayerStyle({
33 | name: 'test',
34 | fills: [
35 | {
36 | color: '#ff0000',
37 | },
38 | ],
39 | });
40 | expect(layerStyle.value.fills[0].color.red).toEqual(1);
41 | });
42 | });
43 |
44 | describe('TextStyle', () => {
45 | it('should work', () => {
46 | const textStyle = SharedStyle.TextStyle({
47 | name: 'test',
48 | textStyle: {
49 | fontName: 'Arial',
50 | fontSize: 10,
51 | },
52 | });
53 | expect(textStyle.value.textStyle.encodedAttributes.MSAttributedStringFontAttribute.attributes).toEqual({
54 | name: 'Arial',
55 | size: 10,
56 | });
57 | });
58 | });
59 | });
60 |
--------------------------------------------------------------------------------
/models/SharedStyle/index.d.ts:
--------------------------------------------------------------------------------
1 | import Style from '../Style';
2 |
3 | declare class SharedStyle {
4 | _class: 'sharedStyle';
5 | name: string;
6 | do_objectID: string;
7 | value: Style;
8 |
9 | static LayerStyle(args: any): SharedStyle;
10 |
11 | static TextStyle(args: any): SharedStyle;
12 |
13 | constructor(args?: any, json?: any);
14 | }
15 |
16 | export = SharedStyle;
17 |
--------------------------------------------------------------------------------
/models/SharedStyle/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./SharedStyle');
15 |
--------------------------------------------------------------------------------
/models/Sketch/index.d.ts:
--------------------------------------------------------------------------------
1 | import fs from 'fs';
2 | import JSZip from 'jszip';
3 | import Meta from '../Meta';
4 | import User from '../User';
5 | import Document from '../Document';
6 | import Page from '../Page';
7 | import SharedStyle from '../SharedStyle';
8 | import Swatch from '../Swatch';
9 |
10 | declare class Sketch {
11 | static fromFile(path: fs.PathLike): Promise;
12 |
13 | static fromExtractedFile(path: fs.PathLike): Promise;
14 |
15 | static addPreview(preview: fs.PathLike): void;
16 |
17 | document: Document;
18 | meta: Meta;
19 | user: User;
20 | pages: Page[];
21 | zip: JSZip;
22 |
23 | constructor(args?: any);
24 |
25 | getPages(predicate?: string | RegExp): Page[];
26 |
27 | getPage(name: string): Page | undefined;
28 |
29 | getLayerStyles(): SharedStyle[];
30 |
31 | getLayerStyle(name: string): SharedStyle | undefined;
32 |
33 | addLayerStyle(style: SharedStyle): void;
34 |
35 | addTextStyle(style: SharedStyle): void;
36 |
37 | getTextStyles(): SharedStyle[];
38 |
39 | addSwatch(swatch: Swatch): void;
40 |
41 | getSwatches(): Swatch[];
42 |
43 | addPage(page: any, args?: any): void;
44 |
45 | addArtboard(pageID: string, artboard: any): void;
46 |
47 | build(output: fs.PathLike | number, compressionLevel: number): Promise;
48 | }
49 |
50 | export = Sketch;
51 |
--------------------------------------------------------------------------------
/models/Sketch/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Sketch');
15 |
--------------------------------------------------------------------------------
/models/Slice/Slice.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Color = require('../Color');
16 | const Style = require('../Style');
17 | const Rect = require('../Rect');
18 | const ExportOptions = require('../ExportOptions');
19 |
20 | class Slice {
21 | static get Model() {
22 | return {
23 | _class: 'slice',
24 | booleanOperation: -1,
25 | isFixedToViewport: false,
26 | isFlippedHorizontal: false,
27 | isFlippedVertical: false,
28 | isLocked: false,
29 | isVisible: true,
30 | layerListExpandedType: 1,
31 | nameIsFixed: false,
32 | resizingConstraint: 63,
33 | resizingType: 0,
34 | rotation: 0,
35 | shouldBreakMaskChain: false,
36 | hasBackgroundColor: false,
37 | };
38 | }
39 |
40 | /**
41 | * @param {Object} args
42 | * @param {Object} json
43 | */
44 | constructor(args, json) {
45 | if (json) {
46 | Object.assign(this, json);
47 | this.exportOptions = new ExportOptions(null, json.exportOptions);
48 | this.frame = new Rect(null, json.frame);
49 | this.style = new Style(null, json.style);
50 | this.backgroundColor = new Color(null, json.backgroundColor);
51 | }
52 | if (args) {
53 | const id = args.id || uuid().toUpperCase();
54 |
55 | Object.assign(this, {
56 | ...Slice.Model,
57 | ...args,
58 | name: args.name || id,
59 | do_objectID: id,
60 | exportOptions: new ExportOptions(args.exportOptions),
61 | frame: new Rect(args.frame),
62 | style: new Style(args.style),
63 | backgroundColor: new Color(args.color),
64 | });
65 | }
66 | }
67 |
68 | static fromJSON(json) {
69 | return new Slice(null, json);
70 | }
71 | }
72 |
73 | module.exports = Slice;
74 |
--------------------------------------------------------------------------------
/models/Slice/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 | import ExportOptions from '../ExportOptions';
3 | import Rect from '../Rect';
4 | import Style from '../Style';
5 |
6 | declare class Slice {
7 | _class: 'slice';
8 | do_objectID: string;
9 | booleanOperation: number;
10 | exportOptions: ExportOptions;
11 | frame: Rect;
12 | isFixedToViewport: boolean;
13 | isFlippedHorizontal: boolean;
14 | isFlippedVertical: boolean;
15 | isLocked: boolean;
16 | isVisible: boolean;
17 | layerListExpandedType: number;
18 | name: string;
19 | nameIsFixed: boolean;
20 | resizingConstraint: number;
21 | resizingType: number;
22 | rotation: number;
23 | shouldBreakMaskChain: boolean;
24 | style: Style;
25 | hasBackgroundColor: boolean;
26 | backgroundColor: Color;
27 |
28 | constructor(args: Partial)
29 | constructor(args: any)
30 | constructor(args: null | undefined, json: Slice)
31 | constructor(args: null | undefined, json: any)
32 |
33 | static fromJSON(json: Slice): Slice
34 | static fromJSON(json: any): Slice
35 | }
36 |
37 | export = Slice;
38 |
--------------------------------------------------------------------------------
/models/Slice/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Slice');
15 |
--------------------------------------------------------------------------------
/models/Star/Star.js:
--------------------------------------------------------------------------------
1 | const uuid = require('uuid-v4');
2 | const Layer = require('../Layer');
3 | const Rect = require('../Rect');
4 | const Style = require('../Style');
5 |
6 | class Star extends Layer {
7 | static get Model() {
8 | return {
9 | ...super.Model,
10 | _class: 'star',
11 | numberOfPoints: 5,
12 | radius: 0,
13 | };
14 | }
15 |
16 | constructor(args, json) {
17 | super(args, json);
18 | if (!json) {
19 | const id = args.id || uuid().toUpperCase();
20 | Object.assign(this, Star.Model, {
21 | do_objectID: id,
22 | name: args.name || id,
23 | style: args.style ? Style.LayerStyle(args.style) : null,
24 | frame: new Rect(args.frame),
25 | });
26 | if (args.numberOfPoints) this.numberOfPoints = args.numberOfPoints;
27 | if (args.radius) this.radius = args.radius;
28 | }
29 | }
30 | }
31 |
32 | module.exports = Star;
33 |
--------------------------------------------------------------------------------
/models/Star/index.d.ts:
--------------------------------------------------------------------------------
1 | import Layer from '../Layer';
2 |
3 | declare class Star extends Layer {
4 | _class: 'star';
5 | numberOfPoints: number;
6 | radius: number;
7 | }
8 |
9 | export = Star;
10 |
--------------------------------------------------------------------------------
/models/Star/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./Star');
2 |
--------------------------------------------------------------------------------
/models/StringAttribute/StringAttribute.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Color = require('../Color');
15 | const ParagraphStyle = require('../ParagraphStyle');
16 | const { verticalAlignmentMap, textTransformMap } = require('../../utils/maps');
17 |
18 | class StringAttribute {
19 | static get Model() {
20 | return {
21 | _class: 'stringAttribute',
22 | location: 0,
23 | length: 1,
24 | attributes: {
25 | MSAttributedStringTextTransformAttribute: 1,
26 | MSAttributedStringFontAttribute: {
27 | _class: 'fontDescriptor',
28 | attributes: {
29 | name: 'Helvetica',
30 | size: 36,
31 | },
32 | },
33 | MSAttributedStringColorAttribute: Color.Model,
34 | textStyleVerticalAlignmentKey: 0,
35 | underlineStyle: 0,
36 | strikethroughStyle: 0,
37 | paragraphStyle: ParagraphStyle.Model,
38 | },
39 | };
40 | }
41 |
42 | constructor(args, json) {
43 | if (json) {
44 | Object.assign(this, json);
45 | } else {
46 | Object.assign(this, StringAttribute.Model, {
47 | location: args.location || 0,
48 | length: args.length || 0,
49 | attributes: {
50 | MSAttributedStringFontAttribute: {
51 | _class: 'fontDescriptor',
52 | attributes: {
53 | name: args.fontName || 'Helvetica',
54 | size: args.fontSize || 16,
55 | },
56 | },
57 | MSAttributedStringTextTransformAttribute: textTransformMap[args.textTransform || 'none'],
58 | MSAttributedStringColorAttribute: new Color(args.color),
59 | textStyleVerticalAlignmentKey: verticalAlignmentMap[args.verticalAlignment || 'top'],
60 | underlineStyle: args.underline ? 1 : 0,
61 | strikethroughStyle: args.strikethrough ? 1 : 0,
62 | kerning: args.kerning || undefined,
63 | paragraphStyle: new ParagraphStyle(args),
64 | },
65 | });
66 | }
67 | }
68 | }
69 |
70 | module.exports = StringAttribute;
71 |
--------------------------------------------------------------------------------
/models/StringAttribute/StringAttribute.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const StringAttribute = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('StringAttribute', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/StringAttribute/index.d.ts:
--------------------------------------------------------------------------------
1 | import Color from '../Color';
2 | import ParagraphStyle = require('../ParagraphStyle');
3 |
4 | declare class StringAttribute {
5 | _class: 'stringAttribute';
6 | location: number;
7 | attributes: {
8 | MSAttributedStringTextTransformAttribute: number;
9 | MSAttributedStringFontAttribute: {
10 | _class: 'fontDescriptor';
11 | attributes: {
12 | name: string;
13 | size: number;
14 | };
15 | };
16 | MSAttributedStringColorAttribute: Color;
17 | textStyleVerticalAlignmentKey: number;
18 | underlineStyle: number;
19 | strikethroughStyle: number;
20 | paragraphStyle: ParagraphStyle;
21 | };
22 | constructor(args?: any, json?: any);
23 | }
24 |
25 | export = StringAttribute;
26 |
--------------------------------------------------------------------------------
/models/StringAttribute/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./StringAttribute');
15 |
--------------------------------------------------------------------------------
/models/Style/Style.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const Style = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('Style', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/Style/index.d.ts:
--------------------------------------------------------------------------------
1 | import Border from '../Border';
2 | import Fill from '../Fill';
3 | import GraphicsContextSettings from '../GraphicsContextSettings';
4 | import Shadow from '../Shadow';
5 | import InnerShadow from '../InnerShadow';
6 | import TextStyle from '../TextStyle';
7 |
8 | declare const enum MarkerType {
9 | none = 0,
10 | openArrow = 1,
11 | filledArrow = 2,
12 | line = 3,
13 | openCircle = 4,
14 | filledCircle = 5,
15 | openSquare = 6,
16 | filledSquare = 7
17 | }
18 |
19 | declare const enum WindingRule { } // TODO
20 |
21 | declare const enum BlendMode {
22 | Normal = 0,
23 | Darken = 1,
24 | Multiply = 2,
25 | ColorBurn = 3,
26 | Lighten = 4,
27 | Screen = 5,
28 | ColorDodge = 6,
29 | Overlay = 7,
30 | SoftLight = 8,
31 | HardLight = 9,
32 | Difference = 10,
33 | Exclusion = 11,
34 | Hue = 12,
35 | Saturation = 13,
36 | Color = 14,
37 | Luminosity = 15
38 | }
39 |
40 | declare class Style {
41 | static MarkerType: typeof MarkerType;
42 |
43 | static WindingRule: typeof WindingRule;
44 |
45 | static BlendMode: typeof BlendMode;
46 |
47 | static LayerStyle(args?: any): Style;
48 |
49 | static TextStyle(args?: any): Style;
50 |
51 | _class: 'style';
52 | do_objectID: string;
53 | startMarkerType: MarkerType;
54 | endMarkerType: MarkerType;
55 | miterLimit: number;
56 | windingRule: number;
57 | borders: Border[];
58 | fills: Fill[];
59 | shadows: Shadow[];
60 | innerShadows: InnerShadow[];
61 | textStyle: TextStyle;
62 | contextSettings: GraphicsContextSettings;
63 |
64 | constructor(args?: any, json?: any);
65 | }
66 |
67 | export = Style;
68 |
--------------------------------------------------------------------------------
/models/Style/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Style');
15 |
--------------------------------------------------------------------------------
/models/Swatch/Swatch.js:
--------------------------------------------------------------------------------
1 | const uuid = require('uuid-v4');
2 | const Color = require('../Color/Color');
3 |
4 | /**
5 | * Also known as 'Color Variables'
6 | */
7 | class Swatch {
8 | static get Model() {
9 | return {
10 | _class: 'swatch',
11 | };
12 | }
13 |
14 | /**
15 | *
16 | * @param {Object} args
17 | * @param {String} args.name
18 | * @param {Color} args.color
19 | * @param {Color.Model} json
20 | */
21 | constructor(args, json) {
22 | if (json) {
23 | Object.assign(this, Swatch.Model, json);
24 | this.value = new Color(this.value);
25 | } else {
26 | const id = args.id || uuid().toUpperCase();
27 | const name = args.name || args.color.toHex().toUpperCase();
28 | Object.assign(this, Swatch.Model, {
29 | name,
30 | do_objectID: id,
31 | value: args.color,
32 | });
33 | }
34 | }
35 |
36 | /**
37 | * Get an object suitable for use in constructing colors
38 | * @returns {Color} A color with the `swatchID` set
39 | */
40 | asColor() {
41 | return { ...this.value.toRgb(), swatchID: this.do_objectID };
42 | }
43 | }
44 |
45 | module.exports = Swatch;
46 |
--------------------------------------------------------------------------------
/models/Swatch/Swatch.test.js:
--------------------------------------------------------------------------------
1 | const Color = require('../Color');
2 | const Swatch = require('./index');
3 |
4 | const json = {
5 | name: 'Test Color',
6 | value: new Color('#c9c'),
7 | };
8 |
9 | describe('Swatch', () => {
10 | it('should work from raw JSON', () => {
11 | const swatch = new Swatch(null, json);
12 | expect(swatch._class).toBe('swatch');
13 | });
14 |
15 | it('should have a default name when no name is given', () => {
16 | const lime = new Color('limegreen');
17 | const unnamedSwatch = new Swatch({ color: lime });
18 | expect(unnamedSwatch.name).toBe('32CD32');
19 |
20 | const namedSwatch = new Swatch({ name: 'Lime', color: lime });
21 | expect(namedSwatch.name).toBe('Lime');
22 | });
23 |
24 | it('asColor should work', () => {
25 | const color = new Color('#F00');
26 | const swatch = new Swatch({ color });
27 | const refColor = swatch.asColor();
28 | expect(refColor.swatchID).not.toBeUndefined();
29 | expect(refColor.swatchID).toBe(swatch.do_objectID);
30 | expect(refColor.r).toBe(255);
31 | expect(refColor.g).toBe(0);
32 | expect(refColor.b).toBe(0);
33 | expect(refColor.a).toBe(1);
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/models/Swatch/index.d.ts:
--------------------------------------------------------------------------------
1 | import { Color } from '..';
2 |
3 | declare class Swatch {
4 | _class: 'swatch';
5 | do_objectID: string;
6 | value: Color;
7 |
8 | constructor(args?: any, json?: any);
9 | }
10 |
11 | export = Swatch;
12 |
--------------------------------------------------------------------------------
/models/Swatch/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./Swatch');
15 |
--------------------------------------------------------------------------------
/models/SymbolInstance/SymbolInstance.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const uuid = require('uuid-v4');
15 | const Layer = require('../Layer');
16 | const ExportOptions = require('../ExportOptions');
17 | const Rect = require('../Rect');
18 | const Style = require('../Style');
19 |
20 | /**
21 | * This class is WIP
22 | */
23 | class SymbolInstance extends Layer {
24 | /**
25 | * The underlying JSON object structure in a Sketch document.
26 | * @mixes Layer.Model
27 | * @property {string} symbolID
28 | * @property {overrideValue[]} overrideValues
29 | */
30 | static get Model() {
31 | return { ...Layer.Model, _class: 'symbolInstance', symbolID: '', overrideValues: [] };
32 | }
33 |
34 | /**
35 | *
36 | * @param {Object} args
37 | * @param {SymbolInstance.Model} json
38 | */
39 | constructor(args = {}, json) {
40 | super(args, json);
41 | if (!json) {
42 | const id = args.id || uuid().toUpperCase();
43 | Object.assign(this, SymbolInstance.Model, {
44 | do_objectID: id,
45 | symbolID: args.symbolID,
46 | exportOptions: new ExportOptions(args.exportOptions),
47 | frame: new Rect(args.frame || {}),
48 | name: args.name || id,
49 | style: new Style(args.style),
50 | });
51 | }
52 | }
53 | }
54 |
55 | module.exports = SymbolInstance;
56 |
--------------------------------------------------------------------------------
/models/SymbolInstance/SymbolInstance.test.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | const SymbolInstance = require('./index');
15 |
16 | const json = {};
17 |
18 | describe('SymbolInstance', () => {
19 | it('should work from raw JSON', () => {
20 | expect(true).toBeTruthy();
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/models/SymbolInstance/__SymbolInstance.json:
--------------------------------------------------------------------------------
1 | {
2 | "_class": "symbolInstance",
3 | "do_objectID": "04E1BC4A-66C7-4856-BA87-E1515F3BDD07",
4 | "booleanOperation": -1,
5 | "exportOptions": {
6 | "_class": "exportOptions",
7 | "exportFormats": [],
8 | "includedLayerIds": [],
9 | "layerOptions": 0,
10 | "shouldTrim": false
11 | },
12 | "frame": {
13 | "_class": "rect",
14 | "constrainProportions": false,
15 | "height": 159,
16 | "width": 238,
17 | "x": 111,
18 | "y": 186
19 | },
20 | "isFixedToViewport": false,
21 | "isFlippedHorizontal": false,
22 | "isFlippedVertical": false,
23 | "isLocked": false,
24 | "isVisible": true,
25 | "layerListExpandedType": 0,
26 | "name": "test",
27 | "nameIsFixed": false,
28 | "resizingConstraint": 63,
29 | "resizingType": 0,
30 | "rotation": 0,
31 | "shouldBreakMaskChain": false,
32 | "clippingMaskMode": 0,
33 | "hasClippingMask": false,
34 | "style": {
35 | "_class": "style",
36 | "endMarkerType": 0,
37 | "miterLimit": 10,
38 | "startMarkerType": 0,
39 | "windingRule": 1
40 | },
41 | "horizontalSpacing": 0,
42 | "overrideValues": [
43 | {
44 | "_class": "overrideValue",
45 | "do_objectID": "3CC4547C-83FE-4A42-A951-D523C23BBCE4",
46 | "overrideName": "95C47E30-81C7-4F67-9794-BD70BC41DCC4_stringValue",
47 | "value": "i can see it"
48 | },
49 | {
50 | "_class": "overrideValue",
51 | "do_objectID": "44D63CA4-C8FF-4E2C-AA15-758356B50355",
52 | "overrideName": "107CD932-1F40-4FEE-92CF-F8E2DBA1B3E0_stringValue",
53 | "value": "in your eyes"
54 | }
55 | ],
56 | "scale": 1,
57 | "symbolID": "4B69D0C7-ADC1-41FD-B718-0FDB54E17620",
58 | "verticalSpacing": 0
59 | }
--------------------------------------------------------------------------------
/models/SymbolInstance/index.d.ts:
--------------------------------------------------------------------------------
1 | import Layer from '../Layer';
2 |
3 | declare class SymbolInstance extends Layer {
4 | symbolID: string;
5 | overrideValues: any[];
6 |
7 | constructor(args?: any, json?: any);
8 | }
9 |
10 | export = SymbolInstance;
11 |
--------------------------------------------------------------------------------
/models/SymbolInstance/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 | * the License. A copy of the License is located at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 | * and limitations under the License.
12 | */
13 |
14 | module.exports = require('./SymbolInstance');
15 |
--------------------------------------------------------------------------------
/models/SymbolMaster/index.d.ts:
--------------------------------------------------------------------------------
1 | import Artboard from '../Artboard';
2 | import Layer from '../Layer';
3 | import SymbolInstance from '../SymbolInstance';
4 |
5 | declare class SymbolMaster extends Artboard {
6 | symbolID: string;
7 | changeIdentifier: number;
8 | overrideProperties: Array