-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
107 lines (98 loc) · 2.57 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @file Artboard Extender
* @version 1.0.0
* @author Akira Maruyama
* @mail [email protected]
*/
const Artboard = require('scenegraph').Artboard;
const { alert, error } = require('./lib/dialogs.js');
// 下に広げる
function expandD_ab(selection) {
move_ab(selection, 10, 0);
}
function expandD_ab100(selection) {
move_ab(selection, 100, 0);
}
// 上に縮める
function shrinkU_ab(selection) {
move_ab(selection, -10, 0);
}
function shrinkU_ab100(selection) {
move_ab(selection, -100, 0);
}
// 左に縮める
function shrinkL_ab(selection) {
move_ab(selection, -10, 1);
}
function shrinkL_ab100(selection) {
move_ab(selection, -100, 1);
}
// 右に広げる
function expandR_ab(selection) {
move_ab(selection, 10, 1);
}
function expandR_ab100(selection) {
move_ab(selection, 100, 1);
}
function move_ab(selection, num, wh) {
if (!checkselection(selection)) {
const init = new Init(selection);
if (wh) {
selection.items[0].resize(init.selw + num, init.selh);
} else {
selection.items[0].resize(init.selw, init.selh + num);
}
}
}
function checkselection(selection) {
const init = new Init(selection);
let app = require('application');
const applang = app.appLanguage;
if (!init.selArtboards || init.selnum == 0) {
if (applang == 'ja') {
error(
'アートボードが選択されていません',
'アートボードを1つだけ選択してください'
);
} else {
error('Artboard is not selected', 'Please select only one artboard.');
}
return true;
} else if (init.selnum >= 2) {
if (applang == 'ja') {
error(
'複数のアートボードが選択されています',
'アートボードを1つだけ選択してください'
);
} else {
error(
'Multiple Artboard is selected',
'Please select only one artboard.'
);
}
return true;
}
}
class Init {
constructor(selection) {
this.selnum = selection.items.length; // get object number
this.selArtboards = selection.hasArtboards; // Is selection artboard? T/F
const node = selection.items[0];
if (this.selArtboards) {
this.selw = node.boundsInParent.width; // get artboard width
this.selh = node.boundsInParent.height; // get artboard height
}
}
}
module.exports = {
commands: {
ExpandD_ab: expandD_ab,
ExpandD_ab100: expandD_ab100,
ShrinkU_ab: shrinkU_ab,
ShrinkU_ab100: shrinkU_ab100,
ExpandR_ab: expandR_ab,
ExpandR_ab100: expandR_ab100,
ShrinkL_ab: shrinkL_ab,
ShrinkL_ab100: shrinkL_ab100
}
};