-
Notifications
You must be signed in to change notification settings - Fork 1
/
mvarstore.js
72 lines (59 loc) · 1.62 KB
/
mvarstore.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import varstore from './varstore.js'
const pub = varstore({
paperWidth: 210, //mm
paperHeight: 297, //mm
printerMargin: 20, //mm
imageMargin: 5, //mm
columns: 0,
rows: 0
})
//calculated
let _printWidth = 0 //mm
let _printHeight = 0 //mm
let _imageWidth = 0 //mm
let _imageHeight = 0 //mm
function calcImageWidth(){
_printWidth = pub.paperWidth() - 2 * pub.printerMargin()
_imageWidth = (_printWidth - (pub.columns() - 1) * pub.imageMargin()) / pub.columns()
}
function calcImageHeight(){
_printHeight = pub.paperHeight() - 2 * pub.printerMargin()
_imageHeight = (_printHeight - (pub.rows() - 1) * pub.imageMargin()) / pub.rows()
}
function calcImageWidthHeight(){
calcImageWidth()
calcImageHeight()
}
pub.on_paperWidth_changed(calcImageWidth)
pub.on_paperHeight_changed(calcImageHeight)
pub.on_printerMargin_changed(calcImageWidthHeight)
pub.on_imageMargin_changed(calcImageWidthHeight)
pub.on_columns_changed(calcImageWidth)
pub.on_rows_changed(calcImageHeight)
pub.printWidth = () => _printWidth
pub.printHeight = () => _printHeight
pub.imageWidth = () => _imageWidth
pub.imageHeight = () => _imageHeight
let _preColumnsChange
const _columnsFunc = pub.columns
pub.columns = function(v) {
if(typeof v === 'undefined'){
return _columnsFunc()
}else{
_preColumnsChange(pub.columns(), v)
_columnsFunc(v)
}
}
pub.preColumnsChange = (func) => {_preColumnsChange = func}
let _preRowsChange
const _rowsFunc = pub.rows
pub.rows = function(v) {
if(typeof v === 'undefined'){
return _rowsFunc()
}else{
_preRowsChange(pub.rows(), v)
_rowsFunc(v)
}
}
pub.preRowsChange = (func) => {_preRowsChange = func}
export default pub