-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
3,010 additions
and
2,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: deploy github pages | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
deploy-ghpages: | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Setup Node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- name: install | ||
run: | | ||
yarn install | ||
- name: Build | ||
run: | | ||
yarn demo:prod | ||
- name: Deploy | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_branch: gh-pages | ||
publish_dir: ./dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
# production,distfile | ||
/build | ||
/dist | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,70 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import { useRef, useEffect, useCallback } from 'react'; | ||
import { SvgDrawing } from 'svg-drawing'; | ||
import { downloadBlob } from './utils/downloadBlob'; | ||
export var useSvgDrawing = function (option) { | ||
var renderRef = useRef(null); | ||
var drawingRef = useRef(null); | ||
var getSvgXML = useCallback(function () { | ||
export const useSvgDrawing = (option) => { | ||
const renderRef = useRef(null); | ||
const drawingRef = useRef(null); | ||
const getSvgXML = useCallback(() => { | ||
if (!drawingRef.current) | ||
return null; | ||
return drawingRef.current.toSvgXml(); | ||
}, []); | ||
var download = useCallback(function () { | ||
const download = useCallback(() => { | ||
if (!drawingRef.current) | ||
return; | ||
var base64 = drawingRef.current.toSvgBase64(); | ||
const base64 = drawingRef.current.toSvgBase64(); | ||
if (!base64) | ||
return; | ||
downloadBlob({ | ||
base64: base64, | ||
filename: new Date().toISOString() + ".svg", | ||
base64, | ||
filename: `${new Date().toISOString()}.svg`, | ||
mimeType: 'image/svg+xml' | ||
}); | ||
}, []); | ||
var changePenColor = useCallback(function (penColor) { | ||
const changePenColor = useCallback((penColor) => { | ||
if (!drawingRef.current || !penColor) | ||
return; | ||
drawingRef.current.penColor = penColor; | ||
}, []); | ||
var changePenWidth = useCallback(function (penSise) { | ||
const changePenWidth = useCallback((penSise) => { | ||
if (!drawingRef.current) | ||
return; | ||
drawingRef.current.penWidth = Number(penSise); | ||
}, []); | ||
var clear = useCallback(function () { | ||
const clear = useCallback(() => { | ||
if (!drawingRef.current) | ||
return; | ||
drawingRef.current.clear(); | ||
}, []); | ||
var undo = useCallback(function () { | ||
const undo = useCallback(() => { | ||
if (!drawingRef.current) | ||
return; | ||
var drawingChildren = drawingRef.current.scene.children; | ||
const drawingChildren = drawingRef.current.scene.children; | ||
if (drawingChildren.length === 0) | ||
return; | ||
drawingRef.current.remove(drawingChildren[drawingChildren.length - 1]); | ||
}, []); | ||
useEffect(function () { | ||
useEffect(() => { | ||
if (drawingRef.current) | ||
return; | ||
if (!renderRef.current) | ||
return; | ||
drawingRef.current = new SvgDrawing(__assign(__assign({}, option), { el: renderRef.current, autostart: true })); | ||
drawingRef.current = new SvgDrawing({ | ||
...option, | ||
el: renderRef.current, | ||
autostart: true | ||
}); | ||
}); | ||
return [ | ||
renderRef, | ||
{ | ||
two: drawingRef.current, | ||
changePenWidth: changePenWidth, | ||
changePenColor: changePenColor, | ||
clear: clear, | ||
undo: undo, | ||
getSvgXML: getSvgXML, | ||
download: download | ||
changePenWidth, | ||
changePenColor, | ||
clear, | ||
undo, | ||
getSvgXML, | ||
download | ||
} | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { join, resolve } = require('path') | ||
const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
const { smart } = require('webpack-merge') | ||
const common = require('./webpack.config') | ||
|
||
const isDev = process.env.NODE_ENV !== 'production' | ||
|
||
module.exports = smart(common, { | ||
mode: isDev ? 'development' : 'production', | ||
entry: resolve(__dirname, 'src/example/app.tsx'), | ||
output: { | ||
filename: '[name].bundle.js', | ||
path: resolve(__dirname, 'dist') | ||
}, | ||
devtool: isDev ? 'source-map' : false, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
template: resolve(__dirname, 'src/example/index.html') | ||
}) | ||
], | ||
devServer: { | ||
contentBase: join(__dirname, 'dist'), | ||
compress: true, | ||
port: 8888 | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
const { resolve } = require('path') | ||
const { smart } = require('webpack-merge') | ||
const common = require('./webpack.config') | ||
|
||
const config = { | ||
mode: 'production', | ||
const isDev = process.env.NODE_ENV !== 'production' | ||
|
||
module.exports = smart(common, { | ||
mode: isDev ? 'development' : 'production', | ||
entry: resolve(__dirname, 'src/index.ts'), | ||
output: { | ||
filename: 'index.min.js', | ||
path: resolve('lib'), | ||
library: 'react-hooks-svgdrawing', | ||
libraryTarget: 'umd' | ||
}, | ||
devtool: false, | ||
devtool: isDev ? 'eval-source-map' : false, | ||
externals: { | ||
react: 'react' | ||
}, | ||
plugins: [], | ||
optimization: { | ||
minimize: true | ||
} | ||
} | ||
|
||
module.exports = config | ||
}) |
Oops, something went wrong.