-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathmain.js
69 lines (64 loc) · 1.89 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
const {getNudgeValue, openSettingDialog, createAlert} = require('./modules/helper');
async function shrinkWidth(selection) {
objectResize(selection.items, 'width', -await getNudgeValue('normal'));
}
async function extendWidth(selection) {
objectResize(selection.items, 'width', await getNudgeValue('normal'));
}
async function shrinkHeight(selection) {
objectResize(selection.items, 'height', -await getNudgeValue('normal'));
}
async function extendHeight(selection) {
objectResize(selection.items, 'height', await getNudgeValue('normal'));
}
async function shrinkGWidth(selection) {
objectResize(selection.items, 'width', -await getNudgeValue('larger'));
}
async function extendGWidth(selection) {
objectResize(selection.items, 'width', await getNudgeValue('larger'));
}
async function shrinkGHeight(selection) {
objectResize(selection.items, 'height', -await getNudgeValue('larger'));
}
async function extendGHeight(selection) {
objectResize(selection.items, 'height', await getNudgeValue('larger'));
}
// main
function objectResize(sel, side, shift) {
if (0 === sel.length) {
const dialog = createAlert('ALERT_TITLE', 'ALERT_MESSAGE');
dialog.showModal();
return false;
}
switch (side) {
case 'width':
sel.forEach(function (obj) {
let bounds = obj.boundsInParent;
let width = bounds.width + shift;
if (0 > width) width = 1;
obj.resize(width, bounds.height);
});
break;
case 'height':
sel.forEach(function (obj) {
let bounds = obj.boundsInParent;
let height = bounds.height + shift;
if (0 > height) height = 1;
obj.resize(bounds.width, height);
});
break;
}
}
module.exports = {
commands: {
"ShrinkW": shrinkWidth,
"ExtendW": extendWidth,
"ShrinkH": shrinkHeight,
"ExtendH": extendHeight,
"ShrinkGW": shrinkGWidth,
"ExtendGW": extendGWidth,
"ShrinkGH": shrinkGHeight,
"ExtendGH": extendGHeight,
"Settings": openSettingDialog
}
};