├── .appcast.xml ├── .babelrc ├── .eslintrc.json ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── docs ├── easing-gradient-assets.sketch ├── easing-gradient-demo.sketch ├── easing-gradient.jpg └── readme │ ├── banner.png │ ├── banner_big.png │ ├── banner_demo.png │ ├── banner_ease.png │ └── banner_steps.png ├── package.json ├── postcss.config.js ├── prettier.config.js ├── resources ├── App.vue ├── assets │ └── icons │ │ ├── runner.png │ │ └── sketch.png ├── components │ ├── easing-edit.vue │ ├── easing-preview.vue │ ├── helpers │ │ └── ease-map.js │ ├── mixins │ │ ├── misc.js │ │ └── mouse.js │ ├── select-chevrons.vue │ ├── select-color-space.vue │ ├── select-timing-advanced.vue │ ├── select-timing.vue │ ├── social-stuff.vue │ ├── step-edit.vue │ └── stop-edit.vue ├── index.html ├── main.js ├── store │ └── index.js └── styles │ ├── base.css │ ├── main.css │ ├── reset.css │ ├── settings.css │ └── utilities.css ├── src ├── lib │ └── helpers.js ├── main.js └── manifest.json ├── webpack.skpm.config.js └── yarn.lock /.appcast.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [["@babel/preset-env", { "modules": false }]], 3 | "plugins": [ 4 | "@babel/plugin-proposal-optional-chaining", 5 | "@babel/plugin-syntax-dynamic-import", 6 | "@babel/plugin-syntax-import-meta", 7 | "@babel/plugin-proposal-class-properties", 8 | "@babel/plugin-proposal-json-strings" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "browser": true 5 | }, 6 | "extends": "prettier", 7 | "plugins": ["html"], 8 | "rules": { 9 | "strict": 0, 10 | "semi": [2, "never"], 11 | "no-param-reassign": [ 12 | "error", 13 | { 14 | "props": true, 15 | "ignorePropertyModificationsFor": [ 16 | "state", 17 | "acc", 18 | "e", 19 | "ctx", 20 | "req", 21 | "request", 22 | "res", 23 | "response", 24 | "$scope" 25 | ] 26 | } 27 | ] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '...' 14 | 3. Scroll down to '...' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Sketch version (please complete the following information):** 24 | - Version [e.g. 22] 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build artefacts 2 | easing-gradients.sketchplugin 3 | 4 | # npm 5 | node_modules 6 | .npm 7 | npm-debug.log 8 | 9 | # mac 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "javascript.validate.enable": false 3 | } 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at andreas@larsenwork.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Andreas Larsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Sketch Easing Gradient](https://github.com/larsenwork/sketch-easing-gradient/blob/master/docs/readme/banner_big.png?raw=true) 2 | 3 | ## Install 4 | 5 | Get the [latest release](https://github.com/larsenwork/sketch-easing-gradient/releases/latest) or install `Easing Gradient` with `Sketch Runner`. NB: requires Sketch version >= 49. 6 | 7 | ## Get started 8 | 9 | 1. Create a layer with a gradient and make sure it's selected. 10 | 2. In the plugin menu go to `Edit Easing Gradient` 11 | 3. Enjoy the awesomeness. 12 | 13 | ## Next level 14 | 15 | - `Download Demo File` from the plugin menu to get inspired. 16 | - I'd love to see what you've created so please tweet easing gradient "on/off" pictures where you mention @larsenwork so I get notified and can build an example gallery. 17 | 18 | ## Learn more 19 | 20 | Docs, online editor, link to postCSS plugin and more on [larsenwork.com/easing-gradients](https://larsenwork.com/easing-gradients/). 21 | 22 | ## Development 23 | 24 | This plugin was created using `skpm`, with a simple vue app on top — checkout the [skpm Readme](https://github.com/skpm/skpm/blob/master/README.md). 25 | 26 | ## Screenshots 27 | 28 | ![Ease](https://github.com/larsenwork/sketch-easing-gradient/blob/master/docs/readme/banner_ease.png?raw=true) 29 | 30 | ![Steps](https://github.com/larsenwork/sketch-easing-gradient/blob/master/docs/readme/banner_steps.png?raw=true) 31 | -------------------------------------------------------------------------------- /docs/easing-gradient-assets.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/easing-gradient-assets.sketch -------------------------------------------------------------------------------- /docs/easing-gradient-demo.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/easing-gradient-demo.sketch -------------------------------------------------------------------------------- /docs/easing-gradient.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/easing-gradient.jpg -------------------------------------------------------------------------------- /docs/readme/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/readme/banner.png -------------------------------------------------------------------------------- /docs/readme/banner_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/readme/banner_big.png -------------------------------------------------------------------------------- /docs/readme/banner_demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/readme/banner_demo.png -------------------------------------------------------------------------------- /docs/readme/banner_ease.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/readme/banner_ease.png -------------------------------------------------------------------------------- /docs/readme/banner_steps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/docs/readme/banner_steps.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sketch-easing-gradients", 3 | "version": "0.7.2", 4 | "description": "Supercharge your gradients in Sketch with no-linear color mix and custom color spaces", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/larsenwork/sketch-easing-gradient.git" 8 | }, 9 | "engines": { 10 | "sketch": ">=3.0" 11 | }, 12 | "skpm": { 13 | "name": "sketch-easing-gradients", 14 | "manifest": "src/manifest.json", 15 | "main": "easing-gradients.sketchplugin" 16 | }, 17 | "scripts": { 18 | "build": "skpm-build", 19 | "watch": "skpm-build --watch", 20 | "start": "skpm-build --watch --run", 21 | "postinstall": "npm run build && skpm-link", 22 | "lint": "eslint src/**/*.js resources/**/*.js" 23 | }, 24 | "devDependencies": { 25 | "@babel/core": "^7.1.0", 26 | "@babel/plugin-proposal-class-properties": "^7.1.0", 27 | "@babel/plugin-proposal-json-strings": "^7.0.0", 28 | "@babel/plugin-proposal-optional-chaining": "^7.0.0", 29 | "@babel/plugin-syntax-dynamic-import": "^7.0.0", 30 | "@babel/plugin-syntax-import-meta": "^7.0.0", 31 | "@babel/preset-env": "^7.1.0", 32 | "@skpm/builder": "^0.5.10", 33 | "@skpm/extract-loader": "^2.0.2", 34 | "babel-eslint": "^9.0.0", 35 | "babel-loader": "^8.0.2", 36 | "copy-webpack-plugin": "^4.5.2", 37 | "cross-env": "^5.2.0", 38 | "css-loader": "^1.0.0", 39 | "eslint": "^5.6.0", 40 | "eslint-config-airbnb-base": "^13.1.0", 41 | "eslint-config-prettier": "^3.1.0", 42 | "eslint-plugin-html": "^4.0.6", 43 | "eslint-plugin-import": "^2.14.0", 44 | "file-loader": "^2.0.0", 45 | "html-loader": "^0.5.5", 46 | "postcss-input-range": "^4.0.0", 47 | "postcss-loader": "^3.0.0", 48 | "postcss-nested": "^4.1.0", 49 | "style-loader": "^0.23.0", 50 | "vue-loader": "^15.4.2", 51 | "vue-template-compiler": "^2.5.17" 52 | }, 53 | "resources": [ 54 | "resources/**/main.js" 55 | ], 56 | "dependencies": { 57 | "chroma-js": "^1.3.7", 58 | "easing-coordinates": "^2.0.2", 59 | "sketch-module-web-view": "^1.2.3", 60 | "throttleit": "^1.0.0", 61 | "vue": "^2.5.17", 62 | "vue-clipboard2": "^0.2.1", 63 | "vue-feather-icons": "^4.7.1", 64 | "vuex": "^3.0.1" 65 | }, 66 | "resolutions": { 67 | "js-yaml": ">=3.13.1", 68 | "lodash": ">=4.17.11" 69 | }, 70 | "author": "larsenwork ", 71 | "license": "MIT" 72 | } 73 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | 'postcss-nested': {}, 4 | 'postcss-input-range': {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: false, 3 | singleQuote: true, 4 | trailingComma: 'es5', 5 | } 6 | -------------------------------------------------------------------------------- /resources/App.vue: -------------------------------------------------------------------------------- 1 | 49 | 50 | 119 | 120 | 150 | -------------------------------------------------------------------------------- /resources/assets/icons/runner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/resources/assets/icons/runner.png -------------------------------------------------------------------------------- /resources/assets/icons/sketch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larsenwork/sketch-easing-gradient/c6876f8a122b3414dab4d2238761a4df202f1256/resources/assets/icons/sketch.png -------------------------------------------------------------------------------- /resources/components/easing-edit.vue: -------------------------------------------------------------------------------- 1 | 95 | 96 | 104 | 105 | 144 | -------------------------------------------------------------------------------- /resources/components/easing-preview.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 27 | 28 | 41 | -------------------------------------------------------------------------------- /resources/components/helpers/ease-map.js: -------------------------------------------------------------------------------- 1 | export const easeMap = { 2 | 'ease-in-out': { 3 | x1: 0.42, 4 | y1: 0, 5 | x2: 0.58, 6 | y2: 1, 7 | }, 8 | 'ease-out': { 9 | x1: 0, 10 | y1: 0, 11 | x2: 0.58, 12 | y2: 1, 13 | }, 14 | 'ease-in': { 15 | x1: 0.42, 16 | y1: 0, 17 | x2: 1, 18 | y2: 1, 19 | }, 20 | ease: { 21 | x1: 0.25, 22 | y1: 0.1, 23 | x2: 0.25, 24 | y2: 1, 25 | }, 26 | linear: { 27 | x1: 0.25, 28 | y1: 0.25, 29 | x2: 0.75, 30 | y2: 0.75, 31 | }, 32 | } 33 | 34 | export const easeMapAdvancedTypes = [ 35 | 'sine', 36 | 'quad', 37 | 'cubic', 38 | 'quart', 39 | 'quint', 40 | 'expo', 41 | 'circ', 42 | ] 43 | 44 | export const easeMapAdvanced = { 45 | 'ease-in-sine': { 46 | x1: 0.47, 47 | y1: 0, 48 | x2: 0.745, 49 | y2: 0.715, 50 | }, 51 | 'ease-out-sine': { 52 | x1: 0.39, 53 | y1: 0.575, 54 | x2: 0.565, 55 | y2: 1, 56 | }, 57 | 'ease-in-out-sine': { 58 | x1: 0.445, 59 | y1: 0.05, 60 | x2: 0.55, 61 | y2: 0.95, 62 | }, 63 | 'ease-in-quad': { 64 | x1: 0.55, 65 | y1: 0.085, 66 | x2: 0.68, 67 | y2: 0.53, 68 | }, 69 | 'ease-out-quad': { 70 | x1: 0.25, 71 | y1: 0.46, 72 | x2: 0.45, 73 | y2: 0.94, 74 | }, 75 | 'ease-in-out-quad': { 76 | x1: 0.455, 77 | y1: 0.03, 78 | x2: 0.515, 79 | y2: 0.955, 80 | }, 81 | 'ease-in-cubic': { 82 | x1: 0.55, 83 | y1: 0.055, 84 | x2: 0.675, 85 | y2: 0.19, 86 | }, 87 | 'ease-out-cubic': { 88 | x1: 0.215, 89 | y1: 0.61, 90 | x2: 0.355, 91 | y2: 1, 92 | }, 93 | 'ease-in-out-cubic': { 94 | x1: 0.645, 95 | y1: 0.045, 96 | x2: 0.355, 97 | y2: 1, 98 | }, 99 | 'ease-in-quart': { 100 | x1: 0.895, 101 | y1: 0.03, 102 | x2: 0.685, 103 | y2: 0.22, 104 | }, 105 | 'ease-out-quart': { 106 | x1: 0.165, 107 | y1: 0.84, 108 | x2: 0.44, 109 | y2: 1, 110 | }, 111 | 'ease-in-out-quart': { 112 | x1: 0.77, 113 | y1: 0, 114 | x2: 0.175, 115 | y2: 1, 116 | }, 117 | 'ease-in-quint': { 118 | x1: 0.755, 119 | y1: 0.05, 120 | x2: 0.855, 121 | y2: 0.06, 122 | }, 123 | 'ease-out-quint': { 124 | x1: 0.23, 125 | y1: 1, 126 | x2: 0.32, 127 | y2: 1, 128 | }, 129 | 'ease-in-out-quint': { 130 | x1: 0.86, 131 | y1: 0, 132 | x2: 0.07, 133 | y2: 1, 134 | }, 135 | 'ease-in-expo': { 136 | x1: 0.95, 137 | y1: 0.05, 138 | x2: 0.795, 139 | y2: 0.035, 140 | }, 141 | 'ease-out-expo': { 142 | x1: 0.19, 143 | y1: 1, 144 | x2: 0.22, 145 | y2: 1, 146 | }, 147 | 'ease-in-out-expo': { 148 | x1: 1, 149 | y1: 0, 150 | x2: 0, 151 | y2: 1, 152 | }, 153 | 'ease-in-circ': { 154 | x1: 0.6, 155 | y1: 0.04, 156 | x2: 0.98, 157 | y2: 0.335, 158 | }, 159 | 'ease-out-circ': { 160 | x1: 0.075, 161 | y1: 0.82, 162 | x2: 0.165, 163 | y2: 1, 164 | }, 165 | 'ease-in-out-circ': { 166 | x1: 0.785, 167 | y1: 0.135, 168 | x2: 0.15, 169 | y2: 0.86, 170 | }, 171 | } 172 | -------------------------------------------------------------------------------- /resources/components/mixins/misc.js: -------------------------------------------------------------------------------- 1 | export default { 2 | computed: { 3 | isSteps() { 4 | return this.$store.state.timingFunction.includes('steps') 5 | }, 6 | }, 7 | } 8 | -------------------------------------------------------------------------------- /resources/components/mixins/mouse.js: -------------------------------------------------------------------------------- 1 | import throttle from 'throttleit' 2 | 3 | const throttleDuration = 1000 / 60 4 | 5 | export default { 6 | mounted() { 7 | document.addEventListener('mousemove', (event) => { 8 | this.move(event) 9 | }) 10 | document.addEventListener('mouseup', this.up) 11 | }, 12 | methods: { 13 | up() { 14 | this.$store.commit('mouseUp') 15 | }, 16 | down(event, element) { 17 | this.$store.commit( 18 | 'parentBounding', 19 | event.target.parentElement.getBoundingClientRect(), 20 | ) 21 | this.$store.commit('mouseDown', element) 22 | }, 23 | move: throttle(function(event) { // eslint-disable-line 24 | const element = this.$store.state.mouseElement 25 | if (element) { 26 | const cursorX = 27 | typeof event.clientX === 'number' 28 | ? event.clientX 29 | : event.touches[0].clientX 30 | const cursorY = 31 | typeof event.clientY === 'number' 32 | ? event.clientY 33 | : event.touches[0].clientY 34 | const squareLeft = this.$store.state.parentBounding.left 35 | const squareRight = this.$store.state.parentBounding.right 36 | const squareTop = this.$store.state.parentBounding.top 37 | const squareBottom = this.$store.state.parentBounding.bottom 38 | /* eslint-disable no-nested-ternary */ 39 | const xPosition = 40 | cursorX <= squareLeft 41 | ? 0 42 | : cursorX >= squareRight 43 | ? 1 44 | : (cursorX - squareLeft) / (squareRight - squareLeft) 45 | const yPosition = 46 | cursorY <= squareTop 47 | ? 1 48 | : cursorY >= squareBottom 49 | ? 0 50 | : 1 - ((cursorY - squareTop) / (squareBottom - squareTop)) 51 | /* eslint-enable no-nested-ternary */ 52 | this.$store.commit({ 53 | type: 'updateXY', 54 | element, 55 | x: xPosition, 56 | y: yPosition, 57 | }) 58 | } 59 | }, throttleDuration), 60 | }, 61 | } 62 | -------------------------------------------------------------------------------- /resources/components/select-chevrons.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 24 | 25 | 48 | -------------------------------------------------------------------------------- /resources/components/select-color-space.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 36 | -------------------------------------------------------------------------------- /resources/components/select-timing-advanced.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 50 | -------------------------------------------------------------------------------- /resources/components/select-timing.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 43 | -------------------------------------------------------------------------------- /resources/components/social-stuff.vue: -------------------------------------------------------------------------------- 1 | 41 | 42 | 63 | 64 | 70 | -------------------------------------------------------------------------------- /resources/components/step-edit.vue: -------------------------------------------------------------------------------- 1 | 37 | -------------------------------------------------------------------------------- /resources/components/stop-edit.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 11 |
14 |
15 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /resources/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueClipboard from 'vue-clipboard2' 3 | import App from './App.vue' 4 | import store from './store' 5 | import './styles/main.css' 6 | 7 | Vue.use(VueClipboard) 8 | 9 | new Vue({ 10 | el: '#app', 11 | store, 12 | render: h => h(App) 13 | }) 14 | -------------------------------------------------------------------------------- /resources/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | import pluginCall from 'sketch-module-web-view/client' 4 | import easingCoordinates from 'easing-coordinates' 5 | import chroma from 'chroma-js' 6 | import { easeMap, easeMapAdvanced } from '../components/helpers/ease-map' 7 | 8 | Vue.use(Vuex) 9 | 10 | const rounded = (number, precission = 2) => +number.toFixed(precission) 11 | 12 | function isCSSShorthand(state) { 13 | if ( 14 | state.timingFunction == 'ease' || 15 | state.timingFunction == 'ease-in-out' || 16 | state.timingFunction == 'ease-in' || 17 | state.timingFunction == 'ease-out' 18 | ) { 19 | if (!state.timingFunctionAdvanced) { 20 | return true 21 | } 22 | } 23 | return false 24 | } 25 | 26 | function xyxyString(state) { 27 | return `${rounded(state.gradient.ease1.x)}, ${rounded( 28 | state.gradient.ease1.y 29 | )}, ${rounded(state.gradient.ease2.x)}, ${rounded(state.gradient.ease2.y)}` 30 | } 31 | 32 | function polyLineString(coordinates) { 33 | // Add potentially missing coordinates for svg rendering purposes 34 | return coordinates.map(obj => `${obj.x},${1 - obj.y}`).join(' ') 35 | } 36 | 37 | function updateColorStops(state) { 38 | let timingString = '' 39 | if (isCSSShorthand(state)) { 40 | timingString = state.timingFunction 41 | } else if (state.timingFunction == 'steps') { 42 | timingString = `steps(${state.gradient.steps.number}, ${ 43 | state.gradient.steps.skip 44 | })` 45 | } else { 46 | timingString = `cubic-bezier(${rounded(state.gradient.ease1.x)}, ${rounded( 47 | state.gradient.ease1.y 48 | )}, ${rounded(state.gradient.ease2.x)}, ${rounded(state.gradient.ease2.y)})` 49 | } 50 | 51 | const coordinates = easingCoordinates( 52 | timingString, 53 | state.colorStops - 1 // -1 because it takes steps and not stops 54 | ) 55 | 56 | state.polyLineString = polyLineString(coordinates) 57 | const colorCoordinates = coordinates.map(obj => ({ 58 | position: obj.x, 59 | color: chroma 60 | .mix(state.startColor, state.stopColor, obj.y, state.colorSpace) 61 | .rgba(false), 62 | })) 63 | const cssArray = colorCoordinates.map( 64 | obj => `${chroma(obj.color).css('hsl')} ${rounded(obj.position * 100)}%` 65 | ) 66 | const fallbackCSS = `background-image: linear-gradient( 67 | /* Gradient direction goes here */ 68 | ${cssArray.join(',\n ')} 69 | );` 70 | const futureCSS = `background-image: linear-gradient( 71 | /* Gradient direction goes here */ 72 | ${chroma(state.startColor).css('hsl')}, 73 | ${timingString}, 74 | ${chroma(state.stopColor).css('hsl')} 75 | );` 76 | state.css = `/* 77 | * Future CSS (use it today with postCSS-easing-gradients - note your settings colorMode: '${ 78 | state.colorSpace 79 | }' and colorStops: ${state.colorStops}) 80 | */ 81 | .future { 82 | ${futureCSS} 83 | } 84 | 85 | /* 86 | * Fallback CSS 87 | */ 88 | .forNow { 89 | ${fallbackCSS} 90 | } 91 | ` 92 | const sketchArray = colorCoordinates.map(obj => ({ 93 | position: obj.position, 94 | color: chroma(obj.color).hex('rgba'), 95 | })) 96 | pluginCall('updateGradient', JSON.stringify(sketchArray)) 97 | } 98 | 99 | function updateLayerName(state) { 100 | if ( 101 | state.timingFunction.includes('cubic-bezier') || 102 | (state.timingFunction.includes('ease-') && state.timingFunctionAdvanced) 103 | ) { 104 | const bezierFunc = `cubic-bezier(${xyxyString(state)})` 105 | pluginCall( 106 | 'updateName', 107 | `${bezierFunc};${state.colorSpace};${state.colorStops}` 108 | ) 109 | } else if ( 110 | state.timingFunction.includes('ease') || 111 | state.timingFunction.includes('linear') 112 | ) { 113 | pluginCall( 114 | 'updateName', 115 | `${state.timingFunction};${state.colorSpace};${state.colorStops}` 116 | ) 117 | } else if (state.timingFunction.includes('steps')) { 118 | pluginCall( 119 | 'updateName', 120 | `${state.timingFunction}(${state.gradient.steps.number}, ${ 121 | state.gradient.steps.skip 122 | });${state.colorSpace}` 123 | ) 124 | } 125 | updateColorStops(state) 126 | } 127 | 128 | function updateTimingFunction(state) { 129 | const xyxy = xyxyString(state) 130 | // TODO: Add some array.find logic here... 131 | state.timingFunction = easeMap[xyxy] ? easeMap[xyxy] : 'cubic-bezier' 132 | updateLayerName(state) 133 | } 134 | 135 | export default new Vuex.Store({ 136 | state: { 137 | startColor: '', 138 | stopColor: '', 139 | timingFunction: '', 140 | timingFunctionAdvanced: '', 141 | colorSpace: 'lrgb', 142 | polyLineString: [], 143 | parentBounding: {}, 144 | mouseElement: '', 145 | css: '', 146 | colorStops: 15, 147 | gradient: { 148 | ease1: { 149 | x: 0.42, 150 | y: 0, 151 | }, 152 | ease2: { 153 | x: 0.58, 154 | y: 1, 155 | }, 156 | steps: { 157 | number: 4, 158 | skip: 'skip-none', 159 | }, 160 | }, 161 | }, 162 | mutations: { 163 | mouseDown(state, element) { 164 | state.mouseElement = element 165 | }, 166 | mouseUp(state) { 167 | state.mouseElement = '' 168 | }, 169 | parentBounding(state, obj) { 170 | state.parentBounding = obj 171 | }, 172 | updateXY(state, obj) { 173 | state.gradient[`${state.mouseElement}`].x = obj.x 174 | state.gradient[`${state.mouseElement}`].y = obj.y 175 | updateTimingFunction(state) 176 | }, 177 | updateXYXY(state, bezierParams) { 178 | if (!state.timingFunction.includes('steps')) { 179 | let xy 180 | if (bezierParams) { 181 | xy = bezierParams 182 | } else if ( 183 | state.timingFunction.includes('ease-') && 184 | state.timingFunctionAdvanced 185 | ) { 186 | xy = 187 | easeMapAdvanced[ 188 | `${state.timingFunction}-${state.timingFunctionAdvanced}` 189 | ] 190 | } else { 191 | xy = easeMap[state.timingFunction] 192 | } 193 | state.gradient.ease1.x = xy.x1 194 | state.gradient.ease1.y = xy.y1 195 | state.gradient.ease2.x = xy.x2 196 | state.gradient.ease2.y = xy.y2 197 | } 198 | updateLayerName(state) 199 | }, 200 | updateLayerName(state) { 201 | updateLayerName(state) 202 | }, 203 | }, 204 | }) 205 | -------------------------------------------------------------------------------- /resources/styles/base.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --knobSize: var(--spacer-small); 3 | --trackStroke: var(--stroke-large); 4 | } 5 | 6 | * { 7 | -webkit-user-select: none; 8 | cursor: default; 9 | font-family: -apple-system; 10 | -webkit-font-smoothing: antialiased; 11 | } 12 | 13 | a, 14 | a * { 15 | cursor: pointer; 16 | } 17 | 18 | input[type='range'] { 19 | -webkit-appearance: none; 20 | width: 100%; 21 | 22 | &:focus { 23 | outline: none; 24 | } 25 | 26 | &::range-track { 27 | background: var(--color-themed-fg); 28 | width: 100%; 29 | height: var(--trackStroke); 30 | border-radius: calc(var(--trackStroke) / 2); 31 | box-shadow: none; 32 | } 33 | 34 | &::range-thumb { 35 | -webkit-appearance: none; 36 | border-radius: 50%; 37 | width: var(--knobSize); 38 | height: var(--knobSize); 39 | background-color: var(--color-bright); 40 | box-shadow: var(--shadow); 41 | margin-top: calc((var(--knobSize) - var(--trackStroke)) / -2); 42 | 43 | &:hover { 44 | box-shadow: var(--shadow--hover); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /resources/styles/main.css: -------------------------------------------------------------------------------- 1 | @import './reset.css'; 2 | @import './settings.css'; 3 | @import './utilities.css'; 4 | @import './base.css'; 5 | -------------------------------------------------------------------------------- /resources/styles/reset.css: -------------------------------------------------------------------------------- 1 | /*! minireset.css v0.0.3 | MIT License | github.com/jgthms/minireset.css */ 2 | html, 3 | body, 4 | p, 5 | ol, 6 | ul, 7 | li, 8 | dl, 9 | dt, 10 | dd, 11 | blockquote, 12 | figure, 13 | fieldset, 14 | legend, 15 | textarea, 16 | pre, 17 | iframe, 18 | hr, 19 | h1, 20 | h2, 21 | h3, 22 | h4, 23 | h5, 24 | h6 { 25 | margin: 0; 26 | padding: 0; 27 | } 28 | 29 | h1, 30 | h2, 31 | h3, 32 | h4, 33 | h5, 34 | h6 { 35 | font-size: 100%; 36 | font-weight: normal; 37 | } 38 | 39 | ul { 40 | list-style: none; 41 | } 42 | 43 | button, 44 | input, 45 | select, 46 | textarea { 47 | margin: 0; 48 | } 49 | 50 | html { 51 | box-sizing: border-box; 52 | } 53 | 54 | *, 55 | *:before, 56 | *:after { 57 | box-sizing: inherit; 58 | } 59 | 60 | img, 61 | embed, 62 | iframe, 63 | object, 64 | audio, 65 | video { 66 | height: auto; 67 | max-width: 100%; 68 | } 69 | 70 | iframe { 71 | border: 0; 72 | } 73 | 74 | table { 75 | border-collapse: collapse; 76 | border-spacing: 0; 77 | } 78 | 79 | td, 80 | th { 81 | padding: 0; 82 | text-align: left; 83 | } 84 | -------------------------------------------------------------------------------- /resources/styles/settings.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --color-dark: hsl(0, 0%, 8%); 3 | --color-dark-50: hsla(0, 0%, 8%, 0.5); 4 | --color-dark-dimmed: hsl(0, 0%, 4%); 5 | --color-dark-dimmed-transparent: hsla(0, 0%, 4%, 0); 6 | --color-dark-dimmed-more: hsl(0, 0%, 0%); 7 | --color-bright: hsl(0, 0%, 100%); 8 | --color-bright-50: hsl(0, 0%, 100%, 0.5); 9 | --color-bright-dimmed: hsl(0, 0%, 96%); 10 | --color-bright-dimmed-transparent: hsla(0, 0%, 96%, 0); 11 | --color-bright-dimmed-more: hsl(0, 0%, 92%); 12 | --color-brand: hsl(330, 100%, 45%); 13 | --color-themed-bg: var(--color-dark); 14 | --color-themed-bg-dimmed: var(--color-dark-dimmed); 15 | --color-themed-bg-dimmed-transparent: var(--color-dark-dimmed-transparent); 16 | --color-themed-bg-dimmed-more: var(--color-dark-dimmed-more); 17 | --color-themed-fg: var(--color-bright); 18 | --color-themed-fg-72: var(--color-bright-50); 19 | 20 | --lineLength-maxWidth: 35rem; 21 | --img-maxWidth: 51rem; 22 | 23 | --fontSize-html: 1.063rem; 24 | --fontSize-h2: 1.412rem; 25 | --fontSize-h1: 2rem; 26 | 27 | --lineHeight-body: 1.647rem; 28 | --lineHeight-margin-xsmall: calc(var(--lineHeight-body) / 4 * 1); 29 | --lineHeight-margin-small: calc(var(--lineHeight-body) / 4 * 3); 30 | --lineHeight-margin-medium: calc(var(--lineHeight-body) / 4 * 6); 31 | --lineHeight-margin-large: calc(var(--lineHeight-body) / 4 * 9); 32 | 33 | --spacer-xsmall: calc(var(--fontSize-h1) / 4); 34 | --spacer-small: calc(var(--fontSize-h1) / 2); 35 | --spacer-medium: var(--fontSize-h1); 36 | --spacer-large: calc(var(--fontSize-h1) * 2); 37 | 38 | --stroke-xsmall: 1px; 39 | --stroke-small: 1px; 40 | --stroke-medium: 2px; 41 | --stroke-large: 4px; 42 | --stroke-large--unitLess: 4; 43 | --stroke-xsmall--highRes: 0.5px; 44 | 45 | --opacity-low: 0.25; 46 | --opacity-mid: 0.5; 47 | --opacity-high: 0.95; 48 | 49 | --transitionDuration: 0.3s; 50 | --transitionFunction: ease; 51 | --transition: var(--transitionDuration) var(--transitionFunction); 52 | 53 | --zIndex-nav: 60; 54 | --zIndex-notification: 50; 55 | --zIndex-modal: 40; 56 | --zIndex-overlay: 30; 57 | --zIndex-editorSettings: 20; 58 | --zIndex-editor: 10; 59 | --zIndex-githubCorner: 1; 60 | 61 | --shadow1: 0 2px 16px hsla(0, 0%, 0%, 0.08); 62 | --shadow2: 0 0.25px 2px hsla(0, 0%, 0%, 0.16); 63 | --shadow1--hover: 0 5px 40px hsla(0, 0%, 0%, 0.12); 64 | --shadow2--hover: 0 1px 8px hsla(0, 0%, 0%, 0.08); 65 | --shadow: var(--shadow1), var(--shadow2), inset 0 2px 16px hsla(0, 0%, 0%, 0), 66 | inset 0 0.25px 2px hsla(0, 0%, 0%, 0); 67 | --shadow--inset: 0 5px 40px hsla(0, 0%, 0%, 0), 0 1px 8px hsla(0, 0%, 0%, 0), 68 | inset 0 1px 8px hsla(0, 0%, 0%, 0.08), 69 | inset 0 0.25px 2px hsla(0, 0%, 0%, 0.16); 70 | --shadow--hover: var(--shadow1--hover), var(--shadow2--hover), 71 | inset 0 2px 16px hsla(0, 0%, 0%, 0), inset 0 0.25px 2px hsla(0, 0%, 0%, 0); 72 | 73 | /* Sketch specific sizes... */ 74 | --fontSize-html: 0.8rem; 75 | --fontSize-h2: 1.62rem; 76 | --fontSize-h1: 2.62rem; 77 | --lineHeight-body: 1.6rem; 78 | } 79 | 80 | .theme-secondary { 81 | --color-themed-bg: var(--color-bright); 82 | --color-themed-bg-dimmed: var(--color-bright-dimmed); 83 | --color-themed-bg-dimmed-more: var(--color-bright-dimmed-more); 84 | --color-themed-bg-dimmed-transparent: var(--color-bright-dimmed-transparent); 85 | --color-themed-fg: var(--color-dark); 86 | --color-themed-fg-72: var(--color-dark-50); 87 | } 88 | 89 | html { 90 | font-size: var(--fontSize-html); 91 | } 92 | -------------------------------------------------------------------------------- /resources/styles/utilities.css: -------------------------------------------------------------------------------- 1 | .u-lineLength { 2 | max-width: var(--lineLength-maxWidth); 3 | margin-left: auto; 4 | margin-right: auto; 5 | } 6 | 7 | /* Positioning */ 8 | .u-position-relative { 9 | position: relative; 10 | } 11 | 12 | .u-position-cover { 13 | position: absolute; 14 | top: 0; 15 | left: 0; 16 | width: 100%; 17 | height: 100%; 18 | } 19 | 20 | .u-container { 21 | padding-right: var(--spacer-small); 22 | padding-left: var(--spacer-small); 23 | width: 100%; 24 | } 25 | 26 | .u-section { 27 | margin-bottom: var(--lineHeight-margin-large); 28 | } 29 | 30 | .u-section:last-child { 31 | margin-bottom: calc( 32 | var(--lineHeight-margin-large) + var(--lineHeight-margin-small) 33 | ); 34 | } 35 | 36 | .u-no-padding { 37 | padding: 0 !important; 38 | } 39 | 40 | .u-no-margin { 41 | margin: 0 !important; 42 | } 43 | 44 | .u-knob { 45 | border-radius: 50%; 46 | width: calc(1.5 * var(--spacer-small)); 47 | height: calc(1.5 * var(--spacer-small)); 48 | position: absolute; 49 | background-color: var(--color-bright); 50 | box-shadow: var(--shadow); 51 | transform: translate(-50%, -50%); 52 | 53 | &:hover { 54 | box-shadow: var(--shadow--hover); 55 | } 56 | } 57 | 58 | .u-grid { 59 | display: grid; 60 | grid-gap: var(--spacer-small); 61 | } 62 | 63 | .u-aspect--1-1, 64 | .u-aspect--2-3 { 65 | position: relative; 66 | width: 100%; 67 | 68 | &::before { 69 | width: 100%; 70 | content: ''; 71 | display: flex; 72 | } 73 | 74 | & > * { 75 | position: absolute; 76 | top: 0; 77 | left: 0; 78 | width: 100%; 79 | height: 100%; 80 | } 81 | } 82 | 83 | .u-aspect--1-1::before { 84 | padding-top: 100%; 85 | } 86 | 87 | .u-aspect--2-3::before { 88 | padding-top: calc(100% * 2 / 3); 89 | } 90 | 91 | .u-marginBottom { 92 | margin-bottom: var(--lineHeight-margin-small); 93 | } 94 | 95 | .u-marginTop { 96 | margin-top: var(--lineHeight-margin-small); 97 | } 98 | 99 | .u-textUppercase { 100 | text-transform: uppercase; 101 | } 102 | 103 | .u-textCapitalize { 104 | text-transform: capitalize; 105 | } 106 | 107 | /* Inputs */ 108 | .u-input { 109 | -webkit-appearance: none; 110 | display: flex; 111 | background: var(--color-themed-bg); 112 | color: var(--color-themed-fg); 113 | font-size: inherit; 114 | padding: var(--spacer-xsmall); 115 | border-radius: var(--spacer-xsmall); 116 | border-width: 0; 117 | border-color: var(--color-themed-bg); 118 | transition: var(--transition); 119 | box-shadow: var(--shadow); 120 | overflow: hidden; 121 | width: 100%; 122 | 123 | &:hover { 124 | box-shadow: var(--shadow--hover); 125 | } 126 | 127 | &:focus { 128 | outline: none; 129 | } 130 | 131 | &:active { 132 | box-shadow: var(--shadow--inset); 133 | transition: 0.1s var(--transitionFunction); 134 | transform: translateY(1px); 135 | } 136 | 137 | &:disabled { 138 | opacity: var(--opacity-mid); 139 | } 140 | } 141 | 142 | .u-input--inline { 143 | width: auto; 144 | } 145 | 146 | .u-input-label { 147 | display: block; 148 | margin-bottom: var(--lineHeight-margin-xsmall); 149 | font-weight: 700; 150 | opacity: 0.7; 151 | } 152 | 153 | /* Icons */ 154 | .u-icon { 155 | width: 16px; 156 | height: 16px; 157 | } 158 | 159 | .u-icon--chevronUp { 160 | position: absolute; 161 | right: 0; 162 | top: 0; 163 | } 164 | 165 | .u-icon--chevronDown { 166 | position: absolute; 167 | right: 0; 168 | bottom: 0; 169 | } 170 | -------------------------------------------------------------------------------- /src/lib/helpers.js: -------------------------------------------------------------------------------- 1 | const UI = require('sketch/ui') // eslint-disable-line import/no-unresolved 2 | 3 | export function openUrl(url) { 4 | return NSWorkspace.sharedWorkspace().openURL(NSURL.URLWithString(url)) // eslint-disable-line no-undef, max-len 5 | } 6 | 7 | export function getLayerParams(layer, gradientFill) { 8 | const gradientParams = layer.name 9 | .split('🌈') 10 | .pop() 11 | .split(';') 12 | .map(item => item.trim()) 13 | const gradientStops = gradientFill.gradient.stops 14 | const gradientStopFirst = gradientStops[0] 15 | const gradientStopLast = gradientStops.pop() 16 | let timing = 'linear' 17 | let colorSpace = 'lrgb' 18 | let colorStops = 15 19 | 20 | if (gradientParams.length === 3) { 21 | ;[timing, colorSpace, colorStops] = gradientParams 22 | } else if (gradientParams.length === 2) { 23 | ;[timing, colorSpace] = gradientParams 24 | } else if (layer.name.includes('🌈')) { 25 | UI.message("🌈 ⚠️ Couldn't parse the layer name. Setting defaults.") 26 | } else { 27 | UI.message('No 🌈 in layer name. Setting defaults.') 28 | } 29 | 30 | const paramsAsString = JSON.stringify([ 31 | gradientStopFirst.color, 32 | timing, 33 | gradientStopLast.color, 34 | colorSpace, 35 | colorStops, 36 | ]) 37 | 38 | return paramsAsString 39 | } 40 | 41 | export function getGradientFillMaybe(layer) { 42 | return layer?.style?.fills.find( 43 | fill => fill.fill === 'Gradient' && fill.enabled 44 | ) 45 | } 46 | 47 | export function getSelectedLayerMaybe(selection) { 48 | if (selection?.length === 1 && selection?.layers?.length > 0) { 49 | return selection.layers[0] 50 | } 51 | return null 52 | } 53 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import BrowserWindow from 'sketch-module-web-view' 2 | import * as helpers from './lib/helpers' 3 | 4 | const UI = require('sketch/ui') // eslint-disable-line import/no-unresolved 5 | const dom = require('sketch/dom') // eslint-disable-line import/no-unresolved 6 | 7 | const options = { 8 | identifier: 'easing-gradient', 9 | title: 'Easing Gradient', 10 | width: 400, 11 | height: 300, 12 | alwaysOnTop: true, 13 | } 14 | 15 | const selectedLayer = helpers.getSelectedLayerMaybe( 16 | dom.getSelectedDocument().selectedLayers 17 | ) 18 | const gradientFill = helpers.getGradientFillMaybe(selectedLayer) 19 | 20 | export function onEaseGradient() { 21 | if (!selectedLayer) { 22 | UI.message('🌈 ⚠️ Please select a layer') 23 | } else if (!gradientFill) { 24 | UI.message( 25 | '🌈 ⚠️ Please check: layer has at least one enabled gradient fill' 26 | ) 27 | } else { 28 | const browserWindow = new BrowserWindow(options) 29 | const { webContents } = browserWindow 30 | 31 | // Show the window when the page has loaded 32 | browserWindow.once('ready-to-show', () => { 33 | browserWindow.show() 34 | }) 35 | 36 | // Close the window when we blur 37 | browserWindow.once('blur', () => { 38 | browserWindow.close() 39 | }) 40 | 41 | // Send gradient parameters to the webview once it's loaded 42 | webContents.once('did-finish-load', () => { 43 | webContents.executeJavaScript( 44 | `setGradientParams('${helpers.getLayerParams( 45 | selectedLayer, 46 | gradientFill 47 | )}')` 48 | ) 49 | }) 50 | 51 | // Handler to update name of gradient layer 52 | webContents.on('updateName', params => { 53 | const nameWithOutParams = selectedLayer.name.split('🌈')[0].trim() 54 | selectedLayer.name = `${nameWithOutParams} 🌈${params}` 55 | }) 56 | 57 | // Handler to update gradient of gradient layer 58 | webContents.on('updateGradient', stopsAsJSON => { 59 | gradientFill.gradient.stops = JSON.parse(stopsAsJSON) 60 | }) 61 | 62 | // Handler to open url 63 | webContents.on('openUrl', url => { 64 | helpers.openUrl(url) 65 | }) 66 | 67 | // Handler to show message 68 | webContents.on('showMessage', msg => { 69 | UI.message(`🌈 ${msg}`) 70 | }) 71 | // Load the html template 72 | browserWindow.loadURL(require('../resources/index.html')) // eslint-disable-line global-require 73 | } 74 | } 75 | 76 | export function onDemo() { 77 | helpers.openUrl( 78 | 'https://github.com/larsenwork/sketch-easing-gradient/blob/master/docs/easing-gradient-demo.sketch?raw=true' 79 | ) 80 | } 81 | 82 | export function onGitHub() { 83 | helpers.openUrl('https://github.com/larsenwork/sketch-easing-gradient/issues') 84 | } 85 | 86 | export function onLarsenwork() { 87 | helpers.openUrl('https://larsenwork.com/easing-gradients') 88 | } 89 | 90 | export function onPostcss() { 91 | helpers.openUrl('https://github.com/larsenwork/postcss-easing-gradients/') 92 | } 93 | -------------------------------------------------------------------------------- /src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "🌈 Easing Gradient", 3 | "description": 4 | "Supercharge your gradients in Sketch with no-linear color mix and custom color spaces", 5 | "icon": "icons/sketch.png", 6 | "identifier": "com.larsenwork.sketch.easing-gradient", 7 | "author": "@larsenwork", 8 | "authorEmail": "andreas@larsenwork.com", 9 | "compatibleVersion": 49, 10 | "bundleVersion": 1, 11 | "commands": [ 12 | { 13 | "script": "./main.js", 14 | "shortcut": "command alt g", 15 | "identifier": "easing-gradient", 16 | "description": 17 | "Create, edit and generate CSS. Make sure to select a layer with a gradient fill first.", 18 | "icon": "icons/runner.png", 19 | "name": "Edit Easing Gradient", 20 | "handler": "onEaseGradient" 21 | }, 22 | { 23 | "name": "Download Demo File", 24 | "icon": "icons/runner.png", 25 | "identifier": "demo", 26 | "script": "./main.js", 27 | "handler": "onDemo" 28 | }, 29 | { 30 | "name": "Ideas and Issues", 31 | "icon": "icons/runner.png", 32 | "identifier": "github", 33 | "script": "./main.js", 34 | "handler": "onGitHub" 35 | }, 36 | { 37 | "name": "Online Docs and Editor", 38 | "icon": "icons/runner.png", 39 | "identifier": "larsenwork", 40 | "script": "./main.js", 41 | "handler": "onLarsenwork" 42 | }, 43 | { 44 | "name": "PostCSS Plugin", 45 | "icon": "icons/runner.png", 46 | "identifier": "postcss", 47 | "script": "./main.js", 48 | "handler": "onPostcss" 49 | } 50 | ], 51 | "menu": { 52 | "items": ["easing-gradient", "-", "demo", "github", "larsenwork", "postcss"] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /webpack.skpm.config.js: -------------------------------------------------------------------------------- 1 | const CopyWebpackPlugin = require('copy-webpack-plugin') 2 | const VueLoaderPlugin = require('vue-loader/lib/plugin') 3 | 4 | /* eslint-disable no-param-reassign */ 5 | module.exports = function(config, isNotResources) { 6 | config.module.rules = [ 7 | ...config.module.rules, 8 | { 9 | test: /\.(html)$/, 10 | use: [ 11 | { 12 | loader: '@skpm/extract-loader', 13 | }, 14 | { 15 | loader: 'html-loader', 16 | options: { 17 | attrs: ['img:src', 'link:href'], 18 | interpolate: true, 19 | }, 20 | }, 21 | ], 22 | }, 23 | { 24 | test: /\.(css)$/, 25 | use: [ 26 | 'style-loader', 27 | { loader: 'css-loader', options: { importLoaders: 1 } }, 28 | 'postcss-loader', 29 | ], 30 | }, 31 | { 32 | test: /\.(png|jpg|gif|svg|sketch)$/, 33 | loader: 'file-loader', 34 | options: { 35 | name: '[name].[ext]?[hash]', 36 | }, 37 | }, 38 | { 39 | test: /\.(vue)$/, 40 | loader: 'vue-loader', 41 | }, 42 | ] 43 | if (!isNotResources) { 44 | config.plugins = [ 45 | ...config.plugins, 46 | new CopyWebpackPlugin([ 47 | { 48 | from: 'resources/assets', 49 | to: '', 50 | ignore: ['*.sketch'], 51 | }, 52 | ]), 53 | new VueLoaderPlugin(), 54 | ] 55 | } 56 | config.resolve = { 57 | extensions: ['.js', '.vue', '.json'], 58 | } 59 | } 60 | --------------------------------------------------------------------------------