Skip to content

Commit 88517e7

Browse files
committed
feat: update svg-drawing packages
1 parent 2625d97 commit 88517e7

File tree

8 files changed

+366
-1548
lines changed

8 files changed

+366
-1548
lines changed

.github/workflows/test.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [10.x, 12.13.0]
16+
17+
steps:
18+
- name: Begin CI...
19+
uses: actions/checkout@v2
20+
21+
- name: Use Node ${{ matrix.node-version }}
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
26+
- name: Use cached node_modules
27+
uses: actions/cache@v1
28+
with:
29+
path: node_modules
30+
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
31+
restore-keys: |
32+
nodeModules-
33+
- name: Install dependencies
34+
# TODO: add check yarn.lock
35+
# run: yarn install --frozen-lockfile
36+
run: yarn install
37+
env:
38+
CI: true
39+
40+
- name: Lint
41+
run: yarn lint
42+
env:
43+
CI: true
44+
45+
- name: Test
46+
run: yarn test
47+
env:
48+
CI: true

.size-snapshot.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
22
"lib/index.min.js": {
3-
"bundled": 11721,
4-
"minified": 11712,
5-
"gzipped": 3739
3+
"bundled": 12217,
4+
"minified": 12208,
5+
"gzipped": 3754
66
},
77
"lib/index.cjs.js": {
8-
"bundled": 20486,
9-
"minified": 12455,
10-
"gzipped": 3808
8+
"bundled": 21163,
9+
"minified": 12991,
10+
"gzipped": 3821
1111
},
1212
"lib/index.esm.js": {
13-
"bundled": 19981,
14-
"minified": 12114,
15-
"gzipped": 3712,
13+
"bundled": 20559,
14+
"minified": 12586,
15+
"gzipped": 3720,
1616
"treeshaked": {
1717
"rollup": {
18-
"code": 104,
18+
"code": 79,
1919
"import_statements": 14
2020
},
2121
"webpack": {
22-
"code": 1088
22+
"code": 1063
2323
}
2424
}
2525
}

README.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
[![npm version](https://badge.fury.io/js/react-hooks-svgdrawing.svg)](https://www.npmjs.com/package/react-hooks-svgdrawing) [![npm download](https://img.shields.io/npm/dt/react-hooks-svgdrawing.svg)](https://www.npmjs.com/package/react-hooks-svgdrawing)
44

5-
### introduction
6-
7-
`react-hooks-svgdrawing` is react drawing library.
5+
`react-hooks-svgdrawing` is React drawing library. This library is a React extension of [svg-drawing](https://github.com/kmkzt/svg-drawing)
86

97
**[demo](https://kmkzt.github.io/react-hooks-svgdrawing/)**
108

@@ -16,55 +14,70 @@ yarn add react react-hooks-svgdrawing
1614

1715
## How to use
1816

19-
started
17+
This is example.
2018

2119
```javascript
2220
import React from 'react'
2321
import { useSvgDrawing } from 'react-hooks-svgdrawing'
2422

2523
const Drawing = () => {
26-
const [
27-
renderRef,
28-
action
29-
] = useSvgDrawing()
30-
return <div ref={renderRef}>
24+
const [renderRef, draw] = useSvgDrawing()
25+
// Drawing area will be resized to fit the rendering area
26+
return <div style={{ width: 500, height: 500 }} ref={renderRef} />
3127
}
3228
```
3329

34-
Drawing init options.
30+
useSvgDrawing options.
3531

3632
```javascript
37-
const [renderRef, action] = useSvgDrawing({
33+
const [renderRef, draw] = useSvgDrawing({
3834
penWidth: 10, // pen width
39-
penColor: '#e00', // pen color
40-
width: 300, // drawing area width
41-
height: 300 // drawing area height
35+
penColor: '#e00' // pen color
36+
close: true // Use close command for path. Default is false.
37+
curve: false, // Use curve command for path. Default is true.
38+
delay: 60, // Set how many ms to draw points every.
39+
fill: ''// Set fill attribute for path. default is `none`
4240
})
4341
```
4442

4543
Drawing methods.
4644

4745
```javascript
48-
// action
49-
const [renderRef, action] = useSvgDrawing()
50-
51-
// drawing all clear
52-
action.clear()
53-
54-
// svg download
55-
action.download()
56-
57-
// undo drawing
58-
action.undo()
59-
60-
// change pen config
61-
action.changePenColor('#00b')
62-
// change pen widht
63-
action.changePenWidth(10)
46+
const [renderRef, draw] = useSvgDrawing()
47+
48+
// Call the SvgDrawing. Access the current settings of penWidth, penColor etc
49+
// Details are https://github.com/kmkzt/svg-drawing.
50+
console.log(draw.instance.penColor) // #333
51+
console.log(draw.instance.penWidth // 1
52+
53+
// Erase all drawing.
54+
draw.clear()
55+
56+
// Download image.
57+
draw.download() // default svg download
58+
draw.download('svg')
59+
draw.download('png')
60+
draw.download('jpg')
61+
62+
// Undo drawing.
63+
draw.undo()
64+
65+
// Change pen config
66+
draw.changePenColor('#00b')
67+
// Change pen width
68+
draw.changePenWidth(10)
69+
// Change fill attribure of svg path element.
70+
draw.changFill('#00b')
71+
// Change throttle delay of drawing
72+
draw.changeDelay(10)
73+
// Set whether to use curved comma for svg path element.
74+
draw.changCurve(false)
75+
// Set whether to use curved comma for svg path element.
76+
draw.changeClose(true)
6477

6578
// get svgXML
6679
// return SVGElement
67-
console.log(action.getSvgXML()) // <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="500" viewBox="0 0 500 500"><defs></defs><g id="two-0" transform="matrix(1 0 0 1 0 0)" opacity="1"><path transform="matrix(1 0 0 1 0 0)" d="..." fill="transparent" stroke="#000" stroke-width="3" stroke-opacity="1" fill-opacity="1" class="" visibility="visible" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="4" id="two-1"></path></g></svg>
80+
console.log(draw.getSvgXML()) // <svg width="502" height="502"><path stroke-width="3" stroke="#000" fill="none" stroke-linejoin="round" stroke-linecap="round" d="M 156.671875 284.7265625 C 156.671875 286.1465625 156.671875 287.89984375 156.671875 291.83984375 ...
6881
```
6982
7083
[example code](src/example/)

jest.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
22
transform: {
3-
'^.+\\.(ts|tsx)$': 'ts-jest',
4-
'^.+\\.(js|jsx)$': 'babel-jest'
3+
'^.+\\.(t|j)sx?$': 'babel-jest'
54
},
65
testRegex: '(\\.|/)(test|spec)\\.(t|j)sx?$',
76
moduleNameMapper: {

package.json

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"name": "react-hooks-svgdrawing",
33
"version": "1.3.0",
44
"license": "MIT",
5-
"description": "react svg drawing library.",
5+
"description": "React svg drawing library. This library is a React extension of svg-drawing.",
66
"author": "kmkzt<[email protected]>",
77
"keywords": [
88
"react",
99
"svg",
1010
"drawing",
11-
"two.js"
11+
"svg-drawing"
1212
],
1313
"type": "module",
1414
"types": "lib/index.d.ts",
@@ -30,43 +30,40 @@
3030
"email": "[email protected]"
3131
},
3232
"scripts": {
33+
"dev": "NODE_ENV=development webpack-dev-server",
3334
"prod": "npm-run-all lib:*",
3435
"lib:clear": "rimraf lib/*",
3536
"lib:rollup": "NODE_ENV=production rollup -c",
3637
"lib:tsc": "NODE_ENV=production tsc --emitDeclarationOnly",
37-
"demo:dev": "NODE_ENV=development webpack-dev-server",
3838
"demo:prod": "NODE_ENV=production webpack -p",
39-
"test": "NODE_ENV=test jest --passWithNoTests",
39+
"test": "npm-run-all test:*",
40+
"test:unit": "NODE_ENV=test jest --passWithNoTests",
41+
"test:type": "NODE_ENV=production tsc --noEmit",
4042
"prepare": "yarn prod",
4143
"release": "release-it"
4244
},
4345
"dependencies": {
44-
"svg-drawing": "2.0.0-alpha.4"
46+
"svg-drawing": "2.0.0"
4547
},
4648
"peerDependencies": {
4749
"react": ">=16.8.0"
4850
},
4951
"devDependencies": {
5052
"@babel/core": "7.9.6",
5153
"@babel/plugin-transform-runtime": "7.9.6",
52-
"@babel/polyfill": "7.8.7",
5354
"@babel/preset-env": "7.9.6",
5455
"@babel/preset-react": "7.9.4",
5556
"@babel/preset-typescript": "7.9.0",
5657
"@rollup/plugin-commonjs": "11.0.2",
5758
"@rollup/plugin-json": "4.0.2",
5859
"@rollup/plugin-node-resolve": "7.1.1",
5960
"@rollup/plugin-replace": "2.3.1",
60-
"@types/autoprefixer": "9.6.1",
61-
"@types/babel-core": "6.25.6",
62-
"@types/babel__core": "7.1.2",
6361
"@types/dotenv-webpack": "1.7.0",
6462
"@types/eslint": "6.8.0",
6563
"@types/eslint-plugin-prettier": "3.1.0",
6664
"@types/html-webpack-plugin": "3.2.1",
6765
"@types/jest": "24.0.18",
6866
"@types/node": "12.7.3",
69-
"@types/node-sass": "4.11.0",
7067
"@types/prettier": "1.18.2",
7168
"@types/react": "16.9.2",
7269
"@types/react-dom": "16.9.0",
@@ -79,14 +76,10 @@
7976
"@typescript-eslint/eslint-plugin": "2.31.0",
8077
"@typescript-eslint/parser": "2.31.0",
8178
"@typescript-eslint/typescript-estree": "2.31.0",
82-
"autoprefixer": "9.6.1",
83-
"babel-core": "6.26.3",
8479
"babel-jest": "24.9.0",
8580
"babel-loader": "8.0.6",
8681
"babel-plugin-add-module-exports": "1.0.2",
8782
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
88-
"babel-preset-es2015": "6.24.1",
89-
"css-loader": "3.2.0",
9083
"eslint": "6.8.0",
9184
"eslint-config-prettier": "6.11.0",
9285
"eslint-loader": "4.0.2",
@@ -96,9 +89,7 @@
9689
"html-loader": "0.5.5",
9790
"html-webpack-plugin": "3.2.0",
9891
"jest": "24.9.0",
99-
"node-sass": "4.12.0",
10092
"npm-run-all": "4.1.5",
101-
"postcss-loader": "3.0.0",
10293
"pressure": "2.1.2",
10394
"prettier": "1.18.2",
10495
"react": "16.9.0",
@@ -111,9 +102,6 @@
111102
"rollup-plugin-size-snapshot": "0.11.0",
112103
"rollup-plugin-sourcemaps": "0.5.0",
113104
"rollup-plugin-terser": "5.2.0",
114-
"sass-loader": "8.0.0",
115-
"style-loader": "1.0.0",
116-
"ts-jest": "24.0.2",
117105
"ts-loader": "6.0.4",
118106
"tsconfig-paths-webpack-plugin": "3.2.0",
119107
"typescript": "3.6.2",

0 commit comments

Comments
 (0)