@ps-generator-bridge/generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/contract-C4vydf6-.d.ts +1270 -0
- package/dist/contract.d.ts +3 -0
- package/dist/contract.js +19 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2482 -0
- package/dist/index.js.map +1 -0
- package/jsx/Action/autoCutout.jsx +12 -0
- package/jsx/Action/redo.jsx +5 -0
- package/jsx/Action/removeBackground.jsx +10 -0
- package/jsx/Common/alert.jsx +4 -0
- package/jsx/Common/debug.jsx +43 -0
- package/jsx/Common/event-dispatch.jsx +4 -0
- package/jsx/Document/exportDocument.jsx +128 -0
- package/jsx/Document/getDocumentInfo.jsx +222 -0
- package/jsx/Document/openPsd.jsx +6 -0
- package/jsx/Document/openPsdFile.jsx +7 -0
- package/jsx/Document/saveDocument.jsx +37 -0
- package/jsx/Layer/addImageLayer.jsx +182 -0
- package/jsx/Layer/createSelectionStroke.jsx +44 -0
- package/jsx/Layer/getActiveLayerID.jsx +1 -0
- package/jsx/Layer/getLayerBounds.jsx +114 -0
- package/jsx/Layer/getLayerInfo.jsx +323 -0
- package/jsx/Layer/getLayerPixmap.jsx +337 -0
- package/jsx/Layer/getSelection.jsx +6 -0
- package/jsx/Layer/layer.jsx +284 -0
- package/jsx/Layer/saveEngineDataToLayer.jsx +26 -0
- package/jsx/Layer/setLayerWorkpathMask.jsx +126 -0
- package/jsx/Layer/transformLayer.jsx +121 -0
- package/jsx/Selection/getSelectionPath.jsx +389 -0
- package/jsx/Selection/pathtosvg.jsx +257 -0
- package/jsx/Selection/registerEvent.jsx +10 -0
- package/jsx/Selection/selectiontopath.jsx +9 -0
- package/jsx/polyfills/Array.js +159 -0
- package/jsx/polyfills/Function.js +29 -0
- package/jsx/polyfills/JSON.js +182 -0
- package/jsx/polyfills/Number.js +24 -0
- package/jsx/polyfills/Object.js +80 -0
- package/jsx/polyfills/String.js +87 -0
- package/jsx/types/extendscript/README.md +34 -0
- package/jsx/types/extendscript/actions.d.ts +148 -0
- package/jsx/types/extendscript/application.d.ts +74 -0
- package/jsx/types/extendscript/channel.d.ts +70 -0
- package/jsx/types/extendscript/color.d.ts +92 -0
- package/jsx/types/extendscript/document.d.ts +110 -0
- package/jsx/types/extendscript/enums.d.ts +796 -0
- package/jsx/types/extendscript/index.d.ts +504 -0
- package/jsx/types/extendscript/layer.d.ts +530 -0
- package/jsx/types/extendscript/misc.d.ts +274 -0
- package/jsx/types/extendscript/open-options.d.ts +86 -0
- package/jsx/types/extendscript/path.d.ts +196 -0
- package/jsx/types/extendscript/save-options.d.ts +144 -0
- package/jsx/types/extendscript/selection.d.ts +191 -0
- package/jsx/types/extendscript/text.d.ts +169 -0
- package/main.js +16 -0
- package/package.json +75 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var layerID = params.id;
|
|
2
|
+
var blurSeed = params.blur || 0;
|
|
3
|
+
|
|
4
|
+
function setSelectionArea(rect) {
|
|
5
|
+
var desc1 = new ActionDescriptor();
|
|
6
|
+
var ref1 = new ActionReference();
|
|
7
|
+
var idChnl = charIDToTypeID("Chnl");
|
|
8
|
+
var idfsel = charIDToTypeID("fsel");
|
|
9
|
+
ref1.putProperty(idChnl, idfsel);
|
|
10
|
+
desc1.putReference(charIDToTypeID("null"), ref1);
|
|
11
|
+
|
|
12
|
+
var idT = charIDToTypeID("T ");
|
|
13
|
+
var desc2 = new ActionDescriptor();
|
|
14
|
+
|
|
15
|
+
var idLeft = charIDToTypeID("Left");
|
|
16
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
17
|
+
desc2.putUnitDouble(idLeft, idPxl, rect.x - blurSeed);
|
|
18
|
+
|
|
19
|
+
var idTop = charIDToTypeID("Top ");
|
|
20
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
21
|
+
desc2.putUnitDouble(idTop, idPxl, rect.y - blurSeed);
|
|
22
|
+
|
|
23
|
+
var idBtom = charIDToTypeID("Btom");
|
|
24
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
25
|
+
desc2.putUnitDouble(idBtom, idPxl, rect.y + rect.height + blurSeed);
|
|
26
|
+
|
|
27
|
+
var idRght = charIDToTypeID("Rght");
|
|
28
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
29
|
+
desc2.putUnitDouble(idRght, idPxl, rect.x + rect.width + blurSeed);
|
|
30
|
+
|
|
31
|
+
var idRctn = charIDToTypeID("Rctn");
|
|
32
|
+
desc1.putObject(idT, idRctn, desc2);
|
|
33
|
+
|
|
34
|
+
executeAction(charIDToTypeID("setd"), desc1, DialogModes.NO);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function setSelectionBlur(blurSeed) {
|
|
38
|
+
var idFthr = charIDToTypeID("Fthr");
|
|
39
|
+
var desc1 = new ActionDescriptor();
|
|
40
|
+
var idRds = charIDToTypeID("Rds ");
|
|
41
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
42
|
+
desc1.putUnitDouble(idRds, idPxl, blurSeed);
|
|
43
|
+
var idselectionModifyEffectAtCanvasBounds = stringIDToTypeID(
|
|
44
|
+
"selectionModifyEffectAtCanvasBounds"
|
|
45
|
+
);
|
|
46
|
+
desc1.putBoolean(idselectionModifyEffectAtCanvasBounds, false);
|
|
47
|
+
executeAction(idFthr, desc1, DialogModes.NO);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function makeMaskFromSelection() {
|
|
51
|
+
var idMk = charIDToTypeID("Mk ");
|
|
52
|
+
var desc1 = new ActionDescriptor();
|
|
53
|
+
var idNw = charIDToTypeID("Nw ");
|
|
54
|
+
var idChnl = charIDToTypeID("Chnl");
|
|
55
|
+
desc1.putClass(idNw, idChnl);
|
|
56
|
+
var idAt = charIDToTypeID("At ");
|
|
57
|
+
var ref659 = new ActionReference();
|
|
58
|
+
var idChnl = charIDToTypeID("Chnl");
|
|
59
|
+
var idChnl = charIDToTypeID("Chnl");
|
|
60
|
+
var idMsk = charIDToTypeID("Msk ");
|
|
61
|
+
ref659.putEnumerated(idChnl, idChnl, idMsk);
|
|
62
|
+
desc1.putReference(idAt, ref659);
|
|
63
|
+
var idUsng = charIDToTypeID("Usng");
|
|
64
|
+
var idUsrM = charIDToTypeID("UsrM");
|
|
65
|
+
var idRvlS = charIDToTypeID("RvlS");
|
|
66
|
+
desc1.putEnumerated(idUsng, idUsrM, idRvlS);
|
|
67
|
+
executeAction(idMk, desc1, DialogModes.NO);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function selectLayerById(layerId) {
|
|
71
|
+
var idslct = charIDToTypeID("slct");
|
|
72
|
+
var desc1 = new ActionDescriptor();
|
|
73
|
+
var idnull = charIDToTypeID("null");
|
|
74
|
+
var ref1 = new ActionReference();
|
|
75
|
+
ref1.putIdentifier(stringIDToTypeID("layer"), layerId);
|
|
76
|
+
desc1.putReference(idnull, ref1);
|
|
77
|
+
executeAction(idslct, desc1, DialogModes.NO);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function workpathToSelection() {
|
|
81
|
+
var idsetd = charIDToTypeID("setd");
|
|
82
|
+
var desc1 = new ActionDescriptor();
|
|
83
|
+
var idnull = charIDToTypeID("null");
|
|
84
|
+
var ref1 = new ActionReference();
|
|
85
|
+
var idChnl = charIDToTypeID("Chnl");
|
|
86
|
+
var idfsel = charIDToTypeID("fsel");
|
|
87
|
+
ref1.putProperty(idChnl, idfsel);
|
|
88
|
+
desc1.putReference(idnull, ref1);
|
|
89
|
+
var idT = charIDToTypeID("T ");
|
|
90
|
+
var ref2 = new ActionReference();
|
|
91
|
+
var idPath = charIDToTypeID("Path");
|
|
92
|
+
var idWrPt = charIDToTypeID("WrPt");
|
|
93
|
+
ref2.putProperty(idPath, idWrPt);
|
|
94
|
+
desc1.putReference(idT, ref2);
|
|
95
|
+
var idVrsn = charIDToTypeID("Vrsn");
|
|
96
|
+
desc1.putInteger(idVrsn, 1);
|
|
97
|
+
var idvectorMaskParams = stringIDToTypeID("vectorMaskParams");
|
|
98
|
+
desc1.putBoolean(idvectorMaskParams, true);
|
|
99
|
+
executeAction(idsetd, desc1, DialogModes.NO);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function clearWorkpath() {
|
|
103
|
+
var idDlt = charIDToTypeID("Dlt ");
|
|
104
|
+
var desc = new ActionDescriptor();
|
|
105
|
+
var idnull = charIDToTypeID("null");
|
|
106
|
+
var ref1 = new ActionReference();
|
|
107
|
+
var idPath = charIDToTypeID("Path");
|
|
108
|
+
var idWrPt = charIDToTypeID("WrPt");
|
|
109
|
+
ref1.putProperty(idPath, idWrPt);
|
|
110
|
+
desc.putReference(idnull, ref1);
|
|
111
|
+
executeAction(idDlt, desc, DialogModes.NO);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
if (!layerID) throw new Error("Layer ID is not defined");
|
|
116
|
+
|
|
117
|
+
selectLayerById(layerID);
|
|
118
|
+
workpathToSelection();
|
|
119
|
+
if (blurSeed > 0) {
|
|
120
|
+
setSelectionBlur(blurSeed);
|
|
121
|
+
}
|
|
122
|
+
makeMaskFromSelection();
|
|
123
|
+
clearWorkpath();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
alert("[setLayerMask] " + error.message);
|
|
126
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var targetLayerId = params.id;
|
|
2
|
+
var rect = params.rect;
|
|
3
|
+
|
|
4
|
+
function getLayerBoundsById(id) {
|
|
5
|
+
var lr = new ActionReference();
|
|
6
|
+
lr.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("bounds"));
|
|
7
|
+
lr.putIdentifier(stringIDToTypeID("layer"), id);
|
|
8
|
+
var value = executeActionGet(lr).getObjectValue(stringIDToTypeID("bounds"));
|
|
9
|
+
return {
|
|
10
|
+
left: value.getUnitDoubleValue(stringIDToTypeID("left")),
|
|
11
|
+
top: value.getUnitDoubleValue(stringIDToTypeID("top")),
|
|
12
|
+
right: value.getUnitDoubleValue(stringIDToTypeID("right")),
|
|
13
|
+
bottom: value.getUnitDoubleValue(stringIDToTypeID("bottom")),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function resizeLayer(id, size) {
|
|
18
|
+
var bounds = getLayerBoundsById(id);
|
|
19
|
+
|
|
20
|
+
var idTrnf = charIDToTypeID("Trnf");
|
|
21
|
+
var desc1 = new ActionDescriptor();
|
|
22
|
+
var idnull = charIDToTypeID("null");
|
|
23
|
+
|
|
24
|
+
var ref1 = new ActionReference();
|
|
25
|
+
ref1.putIdentifier(stringIDToTypeID("layer"), id);
|
|
26
|
+
desc1.putReference(idnull, ref1);
|
|
27
|
+
|
|
28
|
+
var idFTcs = charIDToTypeID("FTcs");
|
|
29
|
+
var idQCSt = charIDToTypeID("QCSt");
|
|
30
|
+
var idQcsa = charIDToTypeID("Qcsa");
|
|
31
|
+
desc1.putEnumerated(idFTcs, idQCSt, idQcsa);
|
|
32
|
+
|
|
33
|
+
var idOfst = charIDToTypeID("Ofst");
|
|
34
|
+
var desc2 = new ActionDescriptor();
|
|
35
|
+
var idHrzn = charIDToTypeID("Hrzn");
|
|
36
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
37
|
+
desc2.putUnitDouble(idHrzn, idPxl, 0);
|
|
38
|
+
var idVrtc = charIDToTypeID("Vrtc");
|
|
39
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
40
|
+
desc2.putUnitDouble(idVrtc, idPxl, 0);
|
|
41
|
+
var idOfst = charIDToTypeID("Ofst");
|
|
42
|
+
desc1.putObject(idOfst, idOfst, desc2);
|
|
43
|
+
|
|
44
|
+
var percentX = (size.width / (bounds.right - bounds.left)) * 100;
|
|
45
|
+
var percentY = (size.height / (bounds.bottom - bounds.top)) * 100;
|
|
46
|
+
|
|
47
|
+
var idWdth = charIDToTypeID("Wdth");
|
|
48
|
+
var idPrc = charIDToTypeID("#Prc");
|
|
49
|
+
desc1.putUnitDouble(idWdth, idPrc, percentX);
|
|
50
|
+
var idHght = charIDToTypeID("Hght");
|
|
51
|
+
var idPrc = charIDToTypeID("#Prc");
|
|
52
|
+
desc1.putUnitDouble(idHght, idPrc, percentY);
|
|
53
|
+
var idLnkd = charIDToTypeID("Lnkd");
|
|
54
|
+
|
|
55
|
+
desc1.putBoolean(idLnkd, true);
|
|
56
|
+
var idIntr = charIDToTypeID("Intr");
|
|
57
|
+
var idIntp = charIDToTypeID("Intp");
|
|
58
|
+
var idBcbc = charIDToTypeID("Bcbc");
|
|
59
|
+
desc1.putEnumerated(idIntr, idIntp, idBcbc);
|
|
60
|
+
executeAction(idTrnf, desc1, DialogModes.NO);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function moveLayer(id, pos) {
|
|
64
|
+
var bounds = getLayerBoundsById(id);
|
|
65
|
+
|
|
66
|
+
var offsetX = pos.x - bounds.left;
|
|
67
|
+
var offsetY = pos.y - bounds.top;
|
|
68
|
+
|
|
69
|
+
var idTrnf = charIDToTypeID("Trnf");
|
|
70
|
+
var desc1 = new ActionDescriptor();
|
|
71
|
+
var idnull = charIDToTypeID("null");
|
|
72
|
+
|
|
73
|
+
var ref1 = new ActionReference();
|
|
74
|
+
ref1.putIdentifier(stringIDToTypeID("layer"), id);
|
|
75
|
+
desc1.putReference(idnull, ref1);
|
|
76
|
+
|
|
77
|
+
var idFTcs = charIDToTypeID("FTcs");
|
|
78
|
+
var idQCSt = charIDToTypeID("QCSt");
|
|
79
|
+
var idQcsa = charIDToTypeID("Qcsa");
|
|
80
|
+
desc1.putEnumerated(idFTcs, idQCSt, idQcsa);
|
|
81
|
+
var idOfst = charIDToTypeID("Ofst");
|
|
82
|
+
var desc2 = new ActionDescriptor();
|
|
83
|
+
var idHrzn = charIDToTypeID("Hrzn");
|
|
84
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
85
|
+
desc2.putUnitDouble(idHrzn, idPxl, offsetX);
|
|
86
|
+
var idVrtc = charIDToTypeID("Vrtc");
|
|
87
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
88
|
+
desc2.putUnitDouble(idVrtc, idPxl, offsetY);
|
|
89
|
+
var idOfst = charIDToTypeID("Ofst");
|
|
90
|
+
desc1.putObject(idOfst, idOfst, desc2);
|
|
91
|
+
|
|
92
|
+
var idLnkd = charIDToTypeID("Lnkd");
|
|
93
|
+
desc1.putBoolean(idLnkd, true);
|
|
94
|
+
var idIntr = charIDToTypeID("Intr");
|
|
95
|
+
var idIntp = charIDToTypeID("Intp");
|
|
96
|
+
var idBcbc = charIDToTypeID("Bcbc");
|
|
97
|
+
desc1.putEnumerated(idIntr, idIntp, idBcbc);
|
|
98
|
+
executeAction(idTrnf, desc1, DialogModes.NO);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function transformLayer(id, pos, size) {
|
|
102
|
+
if (size) {
|
|
103
|
+
resizeLayer(id, size);
|
|
104
|
+
}
|
|
105
|
+
if (pos) {
|
|
106
|
+
moveLayer(id, pos);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
function toTransform() {
|
|
112
|
+
transformLayer(
|
|
113
|
+
targetLayerId,
|
|
114
|
+
{ x: rect.x, y: rect.y },
|
|
115
|
+
{ width: rect.width, height: rect.height }
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
app.activeDocument.suspendHistory("图片变化", "toTransform()");
|
|
119
|
+
} catch (error) {
|
|
120
|
+
alert(error.message);
|
|
121
|
+
}
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
var expand = params.expand || 0;
|
|
2
|
+
|
|
3
|
+
//#region JSON
|
|
4
|
+
|
|
5
|
+
// JSON
|
|
6
|
+
if (typeof JSON !== "object") {
|
|
7
|
+
JSON = {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
(function () {
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
var rx_one = /^[\],:{}\s]*$/;
|
|
14
|
+
var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
|
|
15
|
+
var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
|
|
16
|
+
var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
|
|
17
|
+
var rx_escapable =
|
|
18
|
+
/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
19
|
+
var rx_dangerous =
|
|
20
|
+
/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
21
|
+
|
|
22
|
+
function f(n) {
|
|
23
|
+
// Format integers to have at least two digits.
|
|
24
|
+
return n < 10 ? "0" + n : n;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function this_value() {
|
|
28
|
+
return this.valueOf();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (typeof Date.prototype.toJSON !== "function") {
|
|
32
|
+
Date.prototype.toJSON = function () {
|
|
33
|
+
return isFinite(this.valueOf())
|
|
34
|
+
? this.getUTCFullYear() +
|
|
35
|
+
"-" +
|
|
36
|
+
f(this.getUTCMonth() + 1) +
|
|
37
|
+
"-" +
|
|
38
|
+
f(this.getUTCDate()) +
|
|
39
|
+
"T" +
|
|
40
|
+
f(this.getUTCHours()) +
|
|
41
|
+
":" +
|
|
42
|
+
f(this.getUTCMinutes()) +
|
|
43
|
+
":" +
|
|
44
|
+
f(this.getUTCSeconds()) +
|
|
45
|
+
"Z"
|
|
46
|
+
: null;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
Boolean.prototype.toJSON = this_value;
|
|
50
|
+
Number.prototype.toJSON = this_value;
|
|
51
|
+
String.prototype.toJSON = this_value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var gap;
|
|
55
|
+
var indent;
|
|
56
|
+
var meta;
|
|
57
|
+
var rep;
|
|
58
|
+
|
|
59
|
+
function quote(string) {
|
|
60
|
+
rx_escapable.lastIndex = 0;
|
|
61
|
+
return rx_escapable.test(string)
|
|
62
|
+
? '"' +
|
|
63
|
+
string.replace(rx_escapable, function (a) {
|
|
64
|
+
var c = meta[a];
|
|
65
|
+
return typeof c === "string"
|
|
66
|
+
? c
|
|
67
|
+
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
|
68
|
+
}) +
|
|
69
|
+
'"'
|
|
70
|
+
: '"' + string + '"';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function str(key, holder) {
|
|
74
|
+
var i; // The loop counter.
|
|
75
|
+
var k; // The member key.
|
|
76
|
+
var v; // The member value.
|
|
77
|
+
var length;
|
|
78
|
+
var mind = gap;
|
|
79
|
+
var partial;
|
|
80
|
+
var value = holder[key];
|
|
81
|
+
|
|
82
|
+
if (value && typeof value === "object" && typeof value.toJSON === "function") {
|
|
83
|
+
value = value.toJSON(key);
|
|
84
|
+
}
|
|
85
|
+
if (typeof rep === "function") {
|
|
86
|
+
value = rep.call(holder, key, value);
|
|
87
|
+
}
|
|
88
|
+
switch (typeof value) {
|
|
89
|
+
case "string":
|
|
90
|
+
return quote(value);
|
|
91
|
+
|
|
92
|
+
case "number":
|
|
93
|
+
return isFinite(value) ? String(value) : "null";
|
|
94
|
+
|
|
95
|
+
case "boolean":
|
|
96
|
+
case "null":
|
|
97
|
+
return String(value);
|
|
98
|
+
case "object":
|
|
99
|
+
if (!value) {
|
|
100
|
+
return "null";
|
|
101
|
+
}
|
|
102
|
+
gap += indent;
|
|
103
|
+
partial = [];
|
|
104
|
+
if (Object.prototype.toString.apply(value) === "[object Array]") {
|
|
105
|
+
length = value.length;
|
|
106
|
+
for (i = 0; i < length; i += 1) {
|
|
107
|
+
partial[i] = str(i, value) || "null";
|
|
108
|
+
}
|
|
109
|
+
v =
|
|
110
|
+
partial.length === 0
|
|
111
|
+
? "[]"
|
|
112
|
+
: gap
|
|
113
|
+
? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
|
|
114
|
+
: "[" + partial.join(",") + "]";
|
|
115
|
+
gap = mind;
|
|
116
|
+
return v;
|
|
117
|
+
}
|
|
118
|
+
if (rep && typeof rep === "object") {
|
|
119
|
+
length = rep.length;
|
|
120
|
+
for (i = 0; i < length; i += 1) {
|
|
121
|
+
if (typeof rep[i] === "string") {
|
|
122
|
+
k = rep[i];
|
|
123
|
+
v = str(k, value);
|
|
124
|
+
if (v) {
|
|
125
|
+
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
for (k in value) {
|
|
131
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
132
|
+
v = str(k, value);
|
|
133
|
+
if (v) {
|
|
134
|
+
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
v =
|
|
140
|
+
partial.length === 0
|
|
141
|
+
? "{}"
|
|
142
|
+
: gap
|
|
143
|
+
? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
|
|
144
|
+
: "{" + partial.join(",") + "}";
|
|
145
|
+
gap = mind;
|
|
146
|
+
return v;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (typeof JSON.stringify !== "function") {
|
|
150
|
+
meta = {
|
|
151
|
+
// table of character substitutions
|
|
152
|
+
"\b": "\\b",
|
|
153
|
+
"\t": "\\t",
|
|
154
|
+
"\n": "\\n",
|
|
155
|
+
"\f": "\\f",
|
|
156
|
+
"\r": "\\r",
|
|
157
|
+
'"': '\\"',
|
|
158
|
+
"\\": "\\\\",
|
|
159
|
+
};
|
|
160
|
+
JSON.stringify = function (value, replacer, space) {
|
|
161
|
+
var i;
|
|
162
|
+
gap = "";
|
|
163
|
+
indent = "";
|
|
164
|
+
if (typeof space === "number") {
|
|
165
|
+
for (i = 0; i < space; i += 1) {
|
|
166
|
+
indent += " ";
|
|
167
|
+
}
|
|
168
|
+
} else if (typeof space === "string") {
|
|
169
|
+
indent = space;
|
|
170
|
+
}
|
|
171
|
+
rep = replacer;
|
|
172
|
+
if (
|
|
173
|
+
replacer &&
|
|
174
|
+
typeof replacer !== "function" &&
|
|
175
|
+
(typeof replacer !== "object" || typeof replacer.length !== "number")
|
|
176
|
+
) {
|
|
177
|
+
throw new Error("JSON.stringify");
|
|
178
|
+
}
|
|
179
|
+
return str("", { "": value });
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
})();
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
|
|
186
|
+
Array.prototype.map = function (f) {
|
|
187
|
+
var retArr = [];
|
|
188
|
+
for (var i = 0, e = this.length; i < e; i++) {
|
|
189
|
+
retArr[i] = f(this[i], i);
|
|
190
|
+
}
|
|
191
|
+
return retArr;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
Array.prototype.filter = function (f) {
|
|
195
|
+
var retArr = [];
|
|
196
|
+
for (var i = 0, e = this.length; i < e; i++) {
|
|
197
|
+
if (f(this[i], i)) {
|
|
198
|
+
retArr.push(this[i]);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return retArr;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
Array.prototype.forEach = function (f) {
|
|
205
|
+
this.map(f);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
Array.from = function (iterable) {
|
|
209
|
+
var retArr = [];
|
|
210
|
+
for (var i = 0, e = iterable.length; i < e; i++) {
|
|
211
|
+
retArr.push(iterable[i]);
|
|
212
|
+
}
|
|
213
|
+
return retArr;
|
|
214
|
+
};
|
|
215
|
+
//
|
|
216
|
+
var Point = function (kind, x, y) {
|
|
217
|
+
this.kind = kind;
|
|
218
|
+
this.x = x;
|
|
219
|
+
this.y = y;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
Point.prototype = {
|
|
223
|
+
toString: function () {
|
|
224
|
+
var base = [this.kind];
|
|
225
|
+
if (this.in) {
|
|
226
|
+
base = base.concat(["(", this.in.x, this.in.y, ")"]);
|
|
227
|
+
}
|
|
228
|
+
base = base.concat([this.x, this.y]);
|
|
229
|
+
if (this.out) {
|
|
230
|
+
base = base.concat(["(", this.out.x, this.out.y, ")"]);
|
|
231
|
+
}
|
|
232
|
+
return base.join(" ");
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
var BBox = function () {
|
|
237
|
+
this.mx = 9999999;
|
|
238
|
+
this.my = 9999999;
|
|
239
|
+
this.MX = -9999999;
|
|
240
|
+
this.MY = -9999999;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
BBox.prototype = {
|
|
244
|
+
grow: function (p) {
|
|
245
|
+
if (!p) return;
|
|
246
|
+
if (p.x < this.mx) {
|
|
247
|
+
this.mx = p.x;
|
|
248
|
+
}
|
|
249
|
+
if (p.y < this.my) {
|
|
250
|
+
this.my = p.y;
|
|
251
|
+
}
|
|
252
|
+
if (p.x > this.MX) {
|
|
253
|
+
this.MX = p.x;
|
|
254
|
+
}
|
|
255
|
+
if (p.y > this.MY) {
|
|
256
|
+
this.MY = p.y;
|
|
257
|
+
}
|
|
258
|
+
this.grow(p.in);
|
|
259
|
+
this.grow(p.out);
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
var pointTypes = {
|
|
264
|
+
"PointKind.CORNERPOINT": "P",
|
|
265
|
+
"PointKind.SMOOTHPOINT": "C",
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
//
|
|
269
|
+
function improvePoint(point) {
|
|
270
|
+
var kind = pointTypes[point.kind];
|
|
271
|
+
var coord = point.anchor;
|
|
272
|
+
var x = Math.round(coord[0]);
|
|
273
|
+
var y = Math.round(coord[1]);
|
|
274
|
+
var obj = new Point(kind, x, y);
|
|
275
|
+
|
|
276
|
+
if (kind === "C") {
|
|
277
|
+
var d;
|
|
278
|
+
if (point.leftDirection) {
|
|
279
|
+
d = point.leftDirection.map(Math.round);
|
|
280
|
+
obj.out = { x: d[0], y: d[1] };
|
|
281
|
+
}
|
|
282
|
+
if (point.rightDirection) {
|
|
283
|
+
d = point.rightDirection.map(Math.round);
|
|
284
|
+
obj.in = { x: d[0], y: d[1] };
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return obj;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// convert all points in a subpath to easier to parse form
|
|
292
|
+
function handleSubPath(subpath) {
|
|
293
|
+
var pathPoints = Array.from(subpath.pathPoints);
|
|
294
|
+
return pathPoints.map(improvePoint);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function cullUnclosedSubPathItem(subpath) {
|
|
298
|
+
return subpath.closed;
|
|
299
|
+
}
|
|
300
|
+
function handlePath(path) {
|
|
301
|
+
var subPaths = Array.from(path.subPathItems).filter(cullUnclosedSubPathItem);
|
|
302
|
+
return subPaths.map(handleSubPath);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function tryGetWorkPath(pathItems) {
|
|
306
|
+
var len = pathItems.length;
|
|
307
|
+
if (len == 0) return undefined;
|
|
308
|
+
var lastPath = pathItems[len - 1];
|
|
309
|
+
if (lastPath.kind != PathKind.WORKPATH) return undefined;
|
|
310
|
+
return lastPath;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function expandSelectionArea(size) {
|
|
314
|
+
var idExpn = charIDToTypeID("Expn");
|
|
315
|
+
var desc = new ActionDescriptor();
|
|
316
|
+
var idBy = charIDToTypeID("By ");
|
|
317
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
318
|
+
desc.putUnitDouble(idBy, idPxl, size);
|
|
319
|
+
var idselectionModifyEffectAtCanvasBounds = stringIDToTypeID(
|
|
320
|
+
"selectionModifyEffectAtCanvasBounds"
|
|
321
|
+
);
|
|
322
|
+
desc.putBoolean(idselectionModifyEffectAtCanvasBounds, false);
|
|
323
|
+
executeAction(idExpn, desc, DialogModes.NO);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function makeWorkpathFromSelection() {
|
|
327
|
+
var idMk = charIDToTypeID("Mk ");
|
|
328
|
+
var desc = new ActionDescriptor();
|
|
329
|
+
var idnull = charIDToTypeID("null");
|
|
330
|
+
var ref1 = new ActionReference();
|
|
331
|
+
var idPath = charIDToTypeID("Path");
|
|
332
|
+
ref1.putClass(idPath);
|
|
333
|
+
desc.putReference(idnull, ref1);
|
|
334
|
+
var idFrom = charIDToTypeID("From");
|
|
335
|
+
var ref2 = new ActionReference();
|
|
336
|
+
var idcsel = charIDToTypeID("csel");
|
|
337
|
+
var idfsel = charIDToTypeID("fsel");
|
|
338
|
+
ref2.putProperty(idcsel, idfsel);
|
|
339
|
+
desc.putReference(idFrom, ref2);
|
|
340
|
+
var idTlrn = charIDToTypeID("Tlrn");
|
|
341
|
+
var idPxl = charIDToTypeID("#Pxl");
|
|
342
|
+
desc.putUnitDouble(idTlrn, idPxl, 2.0);
|
|
343
|
+
executeAction(idMk, desc, DialogModes.NO);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
var data = {};
|
|
347
|
+
try {
|
|
348
|
+
function getSelectionAndPath() {
|
|
349
|
+
try {
|
|
350
|
+
var activeDoc = app.activeDocument;
|
|
351
|
+
app.preferences.rulerUnits = Units.PIXELS;
|
|
352
|
+
var hasSelection;
|
|
353
|
+
|
|
354
|
+
try {
|
|
355
|
+
hasSelection = activeDoc.selection.bounds;
|
|
356
|
+
} catch (error) {}
|
|
357
|
+
|
|
358
|
+
if (hasSelection) {
|
|
359
|
+
if (expand > 0) {
|
|
360
|
+
expandSelectionArea(expand);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
var selectionBounds = activeDoc.selection.bounds;
|
|
364
|
+
data.bounds = {
|
|
365
|
+
left: selectionBounds[0].value,
|
|
366
|
+
top: selectionBounds[1].value,
|
|
367
|
+
right: selectionBounds[2].value,
|
|
368
|
+
bottom: selectionBounds[3].value,
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
//
|
|
372
|
+
makeWorkpathFromSelection();
|
|
373
|
+
//
|
|
374
|
+
var workPathItem = tryGetWorkPath(activeDoc.pathItems);
|
|
375
|
+
|
|
376
|
+
if (workPathItem) {
|
|
377
|
+
data.path = handlePath(workPathItem);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
} catch (error) {
|
|
381
|
+
alert("[getSelectionPath] " + error.message);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
app.activeDocument.suspendHistory("getSelectionAndPath", "getSelectionAndPath()");
|
|
385
|
+
} catch (error) {
|
|
386
|
+
alert(error.message);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
data = JSON.stringify(data);
|