-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
bbee5bf
commit 5a6e72a
Showing
15 changed files
with
131 additions
and
11 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ node_modules/ | |
package-lock.json | ||
src/animate/ | ||
*.bat | ||
*.map | ||
|
||
# misc | ||
.DS_Store | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import ReactWaterMark from './watermark/react'; | ||
import VueWaterMark from './watermark/vue'; | ||
import NativeWaterMark from './watermark/native'; | ||
|
||
export default ReactWaterMark; | ||
|
||
export { | ||
ReactWaterMark, | ||
VueWaterMark | ||
VueWaterMark, | ||
NativeWaterMark | ||
} |
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
Empty file.
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,77 @@ | ||
import debounce from '@utils/debounce'; | ||
import style from '@styles'; | ||
import { canRedraw, drawCanvas, drawSvg } from '@utils/draw'; | ||
import { getDevicePixelRatio } from '@utils/devicePixelRatio'; | ||
import { addEventListen, DOMContentLoaded } from '@utils/eventListener'; | ||
|
||
window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback){ | ||
window.setTimeout(callback, 1000 / 60); | ||
}; | ||
|
||
function NativeWaterMark(props = {}){ | ||
if(!props || typeof props !== 'object'){ | ||
return console.warn('error'); | ||
} | ||
if(this instanceof NativeWaterMark){ | ||
return this.init(props); | ||
} | ||
return new NativeWaterMark(props); | ||
} | ||
NativeWaterMark.prototype = { | ||
constructor: NativeWaterMark, | ||
canvas: document.createElement('canvas'), | ||
init: function(props){ | ||
document.body.appendChild(this.canvas); | ||
this.login = props.login; | ||
this.code = props.code; | ||
this.ie = !!window['ActiveXObject'] || 'ActiveXObject' in window; | ||
// ie11以下不兼容pointer-event,故使用svg | ||
this.draw = !!window['ActiveXObject'] ? drawSvg : drawCanvas; | ||
this.canvas.className = style.waterMark; | ||
this.initWaterMark(); | ||
this.loadWaterMark(); | ||
}, | ||
initWaterMark() { | ||
this.can = this.canvas; | ||
if (!this.can){ | ||
return requestAnimationFrame(() => { | ||
this.initWaterMark(); | ||
}); | ||
} | ||
if (this.ctx) return; | ||
this.ctx = this.can.getContext('2d'); // eslint-disable-line | ||
this.ratio = getDevicePixelRatio(this.ctx); | ||
// 每个小块的宽高 | ||
this.w = 100; | ||
this.h = 80; | ||
this.waterMark(); | ||
}, | ||
loadWaterMark() { | ||
let isLoad = true; | ||
DOMContentLoaded(() => { | ||
isLoad && this.waterMark() | ||
isLoad = null; | ||
}); | ||
addEventListen('load', () => { | ||
isLoad && this.waterMark(); | ||
isLoad = null; | ||
}); | ||
|
||
const redraw = canRedraw.bind(this); | ||
addEventListen('resize', debounce(() => { | ||
redraw() && this.waterMark(); | ||
}, 200)) | ||
}, | ||
waterMark() { | ||
if (!this.can){ | ||
this.initWaterMark(); | ||
return false; | ||
} | ||
// 更新屏幕宽高 | ||
this.width = window.innerWidth || document.documentElement.clientWidth || document.documentElement.offsetHeight || document.body.clientWidth; | ||
this.height = window.innerHeight || document.documentElement.clientWidth || document.documentElement.offsetHeight || document.body.clientHeight; | ||
this.draw(); | ||
} | ||
} | ||
|
||
export default NativeWaterMark; |
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,17 @@ | ||
const fs = require('fs'); | ||
|
||
export default dir => { | ||
if(!dir || typeof dir !== 'string'){ | ||
return {}; | ||
} | ||
const path = dir + (dir.endsWith('/') ? '' : '/'); | ||
let allEntry = {}; | ||
const files = fs.readdirSync(path); | ||
files.forEach(item => { | ||
let stat = fs.lstatSync(path + item) | ||
if (stat.isDirectory() === true) { | ||
allEntry[item + '/index'] = `${path}${item}`; | ||
} | ||
}); | ||
return allEntry; | ||
} |
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