├── .gitignore ├── example ├── loading.gif ├── thumb.jpg ├── thumb2.jpg ├── zhihu.jpg ├── zhihu.js ├── zhihu.html ├── demo.css └── demo.html ├── .babelrc ├── dist ├── canvastools.css.map ├── canvastools.min.js ├── canvastools.min.css ├── canvastools.css ├── canvastools.js └── canvastools.js.map ├── postcss.config.js ├── src ├── js │ ├── closet.js │ ├── template.js │ ├── utils.js │ └── main.js └── scss │ └── canvastools.scss ├── LICENSE ├── README.md ├── package.json └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /node_modules 3 | /package-lock.json 4 | /.sass-cache -------------------------------------------------------------------------------- /example/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S-mohan/canvasTools/HEAD/example/loading.gif -------------------------------------------------------------------------------- /example/thumb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S-mohan/canvasTools/HEAD/example/thumb.jpg -------------------------------------------------------------------------------- /example/thumb2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S-mohan/canvasTools/HEAD/example/thumb2.jpg -------------------------------------------------------------------------------- /example/zhihu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/S-mohan/canvasTools/HEAD/example/zhihu.jpg -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": ["babel-plugin-add-module-exports"] 4 | } -------------------------------------------------------------------------------- /dist/canvastools.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":[],"names":[],"mappings":"","file":"canvastools.css","sourceRoot":""} -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "plugins": { 3 | // to edit target browsers: use "browserlist" field in package.json 4 | "autoprefixer": { 5 | browsers: ['last 2 versions'] 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /src/js/closet.js: -------------------------------------------------------------------------------- 1 | //Element.closet Polyfill 2 | //https://developer.mozilla.org/en-US/docs/Web/API/Element/closest 3 | if (window.Element && !Element.prototype.closest) { 4 | Element.prototype.closest = 5 | function(s) { 6 | var matches = (this.document || this.ownerDocument).querySelectorAll(s), 7 | i, 8 | el = this; 9 | do { 10 | i = matches.length; 11 | while (--i >= 0 && matches.item(i) !== el) {}; 12 | } while ((i < 0) && (el = el.parentElement)); 13 | return el; 14 | }; 15 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Smohan 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 | # CanvasTools 2 | Screenshot tool based on canvas 3 | 4 | > 基于Canvas的截图辅助工具集。包含矩形,椭圆,画笔,文字等多种工具以及撤销,保存等各种功能 5 | 6 |  7 | 8 | #### [项目地址](https://smohan.net/lab/canvastools) 9 | #### [DEMO](https://s-mohan.github.io/demo/canvastools/demo.html) 10 | #### [仿知乎截图反馈](https://s-mohan.github.io/demo/canvastools/zhihu.html) 11 | 12 | 项目构思来源于知乎建议反馈功能中的截图反馈。期初看到该功能,惊为天人,不得不佩服知乎对用户体验的细节追求。然后又对比和参考了QQ截图(基本样式来源于此),花了三天时间完成了`CanvasTools`项目的构建。 13 | 截止目前,在完成了大部分功能的同时,也学习了大部分的`Canvas API`: 14 | 15 | ### 可用功能 16 | 17 | - 矩形工具 18 | - 椭圆工具 19 | - 画笔工具 20 | - 文字工具 21 | - 马赛克工具 22 | - 撤销功能 23 | - 保存功能(`IE10+`) 24 | 25 | ### 待完成功能 26 | 27 | - 橡皮擦工具 28 | 29 | ### 如何使用 30 | 31 | #### 1.使用NPM 32 | 33 | ```javascript 34 | npm install 35 | //dev 36 | npm run dev 37 | //build 38 | npm run build 39 | ``` 40 | 41 | 42 | #### 2.直接使用 43 | 44 | 1.页面`head`标签中引入 45 | ```html 46 | 47 | ``` 48 | 2.在`body`中创建`canvas`以及用来放置工具条的容器 49 | ```html 50 | ... 51 | 52 |
53 | ... 54 | ``` 55 | 3.在 `