@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,128 @@
|
|
|
1
|
+
// Export current document - based on PS "Save a Copy" mechanism
|
|
2
|
+
// params: { filePath, format, jpegQuality, jpegMatte, pngInterlace, pngCompression,
|
|
3
|
+
// tiffCompression, tiffByteOrder, tiffLayers, tiffTransparency,
|
|
4
|
+
// embedColorProfile }
|
|
5
|
+
|
|
6
|
+
var _result = (function () {
|
|
7
|
+
if (app.documents.length === 0) return "Error:No document is open.";
|
|
8
|
+
|
|
9
|
+
var doc = app.activeDocument;
|
|
10
|
+
var filePath = params.filePath;
|
|
11
|
+
var format = (params.format || "png").toLowerCase();
|
|
12
|
+
|
|
13
|
+
if (!filePath) {
|
|
14
|
+
filePath = Folder.desktop + "/" + doc.name.replace(/\.[^\.]+$/, "") + "." + format;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var file = new File(filePath);
|
|
18
|
+
var folder = file.parent;
|
|
19
|
+
if (!folder.exists) folder.create();
|
|
20
|
+
|
|
21
|
+
var desc1 = new ActionDescriptor();
|
|
22
|
+
var desc2 = new ActionDescriptor();
|
|
23
|
+
|
|
24
|
+
if (format === "jpeg" || format === "jpg") {
|
|
25
|
+
// quality: 0-12, default 10
|
|
26
|
+
var quality = params.jpegQuality != undefined ? params.jpegQuality : 10;
|
|
27
|
+
desc2.putInteger(stringIDToTypeID("extendedQuality"), quality);
|
|
28
|
+
|
|
29
|
+
// matte color for transparent areas: "none" / "white" / "black" / "foregroundColor" / "backgroundColor"
|
|
30
|
+
var matte = (params.jpegMatte || "none").toLowerCase();
|
|
31
|
+
var matteMap = {
|
|
32
|
+
none: "none",
|
|
33
|
+
white: "white",
|
|
34
|
+
black: "black",
|
|
35
|
+
foreground: "foregroundColor",
|
|
36
|
+
background: "backgroundColor",
|
|
37
|
+
};
|
|
38
|
+
var matteValue = matteMap[matte] || "none";
|
|
39
|
+
desc2.putEnumerated(
|
|
40
|
+
stringIDToTypeID("matte"),
|
|
41
|
+
stringIDToTypeID("matteColor"),
|
|
42
|
+
stringIDToTypeID(matteValue)
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
desc1.putObject(stringIDToTypeID("as"), stringIDToTypeID("JPEG"), desc2);
|
|
46
|
+
} else if (format === "png") {
|
|
47
|
+
// interlace: 0=none, 1=interlaced
|
|
48
|
+
var interlace = params.pngInterlace ? 1 : 0;
|
|
49
|
+
try {
|
|
50
|
+
desc2.putInteger(stringIDToTypeID("PNGInterlaceType"), interlace);
|
|
51
|
+
} catch (e) {}
|
|
52
|
+
|
|
53
|
+
// compression: 0-9, default 6
|
|
54
|
+
var compression = params.pngCompression != undefined ? params.pngCompression : 6;
|
|
55
|
+
try {
|
|
56
|
+
desc2.putInteger(stringIDToTypeID("compression"), compression);
|
|
57
|
+
} catch (e) {}
|
|
58
|
+
|
|
59
|
+
desc1.putObject(stringIDToTypeID("as"), stringIDToTypeID("PNGFormat"), desc2);
|
|
60
|
+
} else if (format === "tiff" || format === "tif") {
|
|
61
|
+
// byte order: "IBMPC" (Windows/Intel) or "macintosh" (Mac)
|
|
62
|
+
var byteOrder = (params.tiffByteOrder || "ibm").toLowerCase();
|
|
63
|
+
var byteOrderValue = byteOrder === "mac" || byteOrder === "macintosh" ? "macintosh" : "IBMPC";
|
|
64
|
+
try {
|
|
65
|
+
desc2.putEnumerated(
|
|
66
|
+
stringIDToTypeID("byteOrder"),
|
|
67
|
+
stringIDToTypeID("platform"),
|
|
68
|
+
stringIDToTypeID(byteOrderValue)
|
|
69
|
+
);
|
|
70
|
+
} catch (e) {}
|
|
71
|
+
|
|
72
|
+
// compression: "none" / "LZW" / "ZIPCompression" / "JPEG"
|
|
73
|
+
var tiffComp = (params.tiffCompression || "none").toLowerCase();
|
|
74
|
+
var tiffCompMap = { lzw: "LZW", zip: "ZIPCompression", jpeg: "JPEG", none: "none" };
|
|
75
|
+
var tiffCompValue = tiffCompMap[tiffComp] || "none";
|
|
76
|
+
try {
|
|
77
|
+
desc2.putEnumerated(
|
|
78
|
+
stringIDToTypeID("encoding"),
|
|
79
|
+
stringIDToTypeID("encoding"),
|
|
80
|
+
stringIDToTypeID(tiffCompValue)
|
|
81
|
+
);
|
|
82
|
+
} catch (e) {}
|
|
83
|
+
|
|
84
|
+
// save layers
|
|
85
|
+
if (params.tiffLayers != undefined) {
|
|
86
|
+
try {
|
|
87
|
+
desc2.putBoolean(stringIDToTypeID("layerOrder"), params.tiffLayers);
|
|
88
|
+
} catch (e) {}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// transparency
|
|
92
|
+
if (params.tiffTransparency != undefined) {
|
|
93
|
+
try {
|
|
94
|
+
desc2.putBoolean(stringIDToTypeID("transparency"), params.tiffTransparency);
|
|
95
|
+
} catch (e) {}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
desc1.putObject(stringIDToTypeID("as"), stringIDToTypeID("TIFF"), desc2);
|
|
99
|
+
} else if (format === "bmp") {
|
|
100
|
+
desc1.putObject(stringIDToTypeID("as"), stringIDToTypeID("BMPFormat"), desc2);
|
|
101
|
+
} else if (format === "tga" || format === "targa") {
|
|
102
|
+
// resolution: 16 / 24 / 32, default 24
|
|
103
|
+
var tgaRes = params.tgaDepth != undefined ? params.tgaDepth : 24;
|
|
104
|
+
try {
|
|
105
|
+
desc2.putInteger(stringIDToTypeID("resolution"), tgaRes);
|
|
106
|
+
} catch (e) {}
|
|
107
|
+
try {
|
|
108
|
+
desc2.putBoolean(stringIDToTypeID("rLECompression"), true);
|
|
109
|
+
} catch (e) {}
|
|
110
|
+
desc1.putObject(stringIDToTypeID("as"), stringIDToTypeID("targaFormat"), desc2);
|
|
111
|
+
} else {
|
|
112
|
+
return "Error:Unsupported format: " + format;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// embed ICC color profile
|
|
116
|
+
if (params.embedColorProfile != undefined) {
|
|
117
|
+
try {
|
|
118
|
+
desc1.putBoolean(stringIDToTypeID("ICC"), params.embedColorProfile);
|
|
119
|
+
} catch (e) {}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
desc1.putPath(stringIDToTypeID("in"), file);
|
|
123
|
+
desc1.putBoolean(stringIDToTypeID("copy"), true);
|
|
124
|
+
executeAction(stringIDToTypeID("save"), desc1, DialogModes.NO);
|
|
125
|
+
|
|
126
|
+
return "OK";
|
|
127
|
+
})();
|
|
128
|
+
_result;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
//#region JSON
|
|
2
|
+
|
|
3
|
+
// JSON
|
|
4
|
+
if (typeof JSON !== "object") {
|
|
5
|
+
JSON = {};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
(function () {
|
|
9
|
+
"use strict";
|
|
10
|
+
|
|
11
|
+
var rx_one = /^[\],:{}\s]*$/;
|
|
12
|
+
var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
|
|
13
|
+
var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
|
|
14
|
+
var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
|
|
15
|
+
var rx_escapable =
|
|
16
|
+
/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
17
|
+
var rx_dangerous =
|
|
18
|
+
/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
19
|
+
|
|
20
|
+
function f(n) {
|
|
21
|
+
// Format integers to have at least two digits.
|
|
22
|
+
return n < 10 ? "0" + n : n;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function this_value() {
|
|
26
|
+
return this.valueOf();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof Date.prototype.toJSON !== "function") {
|
|
30
|
+
Date.prototype.toJSON = function () {
|
|
31
|
+
return isFinite(this.valueOf())
|
|
32
|
+
? this.getUTCFullYear() +
|
|
33
|
+
"-" +
|
|
34
|
+
f(this.getUTCMonth() + 1) +
|
|
35
|
+
"-" +
|
|
36
|
+
f(this.getUTCDate()) +
|
|
37
|
+
"T" +
|
|
38
|
+
f(this.getUTCHours()) +
|
|
39
|
+
":" +
|
|
40
|
+
f(this.getUTCMinutes()) +
|
|
41
|
+
":" +
|
|
42
|
+
f(this.getUTCSeconds()) +
|
|
43
|
+
"Z"
|
|
44
|
+
: null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
Boolean.prototype.toJSON = this_value;
|
|
48
|
+
Number.prototype.toJSON = this_value;
|
|
49
|
+
String.prototype.toJSON = this_value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var gap;
|
|
53
|
+
var indent;
|
|
54
|
+
var meta;
|
|
55
|
+
var rep;
|
|
56
|
+
|
|
57
|
+
function quote(string) {
|
|
58
|
+
rx_escapable.lastIndex = 0;
|
|
59
|
+
return rx_escapable.test(string)
|
|
60
|
+
? '"' +
|
|
61
|
+
string.replace(rx_escapable, function (a) {
|
|
62
|
+
var c = meta[a];
|
|
63
|
+
return typeof c === "string"
|
|
64
|
+
? c
|
|
65
|
+
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
|
66
|
+
}) +
|
|
67
|
+
'"'
|
|
68
|
+
: '"' + string + '"';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function str(key, holder) {
|
|
72
|
+
var i; // The loop counter.
|
|
73
|
+
var k; // The member key.
|
|
74
|
+
var v; // The member value.
|
|
75
|
+
var length;
|
|
76
|
+
var mind = gap;
|
|
77
|
+
var partial;
|
|
78
|
+
var value = holder[key];
|
|
79
|
+
|
|
80
|
+
if (value && typeof value === "object" && typeof value.toJSON === "function") {
|
|
81
|
+
value = value.toJSON(key);
|
|
82
|
+
}
|
|
83
|
+
if (typeof rep === "function") {
|
|
84
|
+
value = rep.call(holder, key, value);
|
|
85
|
+
}
|
|
86
|
+
switch (typeof value) {
|
|
87
|
+
case "string":
|
|
88
|
+
return quote(value);
|
|
89
|
+
|
|
90
|
+
case "number":
|
|
91
|
+
return isFinite(value) ? String(value) : "null";
|
|
92
|
+
|
|
93
|
+
case "boolean":
|
|
94
|
+
case "null":
|
|
95
|
+
return String(value);
|
|
96
|
+
case "object":
|
|
97
|
+
if (!value) {
|
|
98
|
+
return "null";
|
|
99
|
+
}
|
|
100
|
+
gap += indent;
|
|
101
|
+
partial = [];
|
|
102
|
+
if (Object.prototype.toString.apply(value) === "[object Array]") {
|
|
103
|
+
length = value.length;
|
|
104
|
+
for (i = 0; i < length; i += 1) {
|
|
105
|
+
partial[i] = str(i, value) || "null";
|
|
106
|
+
}
|
|
107
|
+
v =
|
|
108
|
+
partial.length === 0
|
|
109
|
+
? "[]"
|
|
110
|
+
: gap
|
|
111
|
+
? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
|
|
112
|
+
: "[" + partial.join(",") + "]";
|
|
113
|
+
gap = mind;
|
|
114
|
+
return v;
|
|
115
|
+
}
|
|
116
|
+
if (rep && typeof rep === "object") {
|
|
117
|
+
length = rep.length;
|
|
118
|
+
for (i = 0; i < length; i += 1) {
|
|
119
|
+
if (typeof rep[i] === "string") {
|
|
120
|
+
k = rep[i];
|
|
121
|
+
v = str(k, value);
|
|
122
|
+
if (v) {
|
|
123
|
+
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
for (k in value) {
|
|
129
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
130
|
+
v = str(k, value);
|
|
131
|
+
if (v) {
|
|
132
|
+
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
v =
|
|
138
|
+
partial.length === 0
|
|
139
|
+
? "{}"
|
|
140
|
+
: gap
|
|
141
|
+
? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
|
|
142
|
+
: "{" + partial.join(",") + "}";
|
|
143
|
+
gap = mind;
|
|
144
|
+
return v;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (typeof JSON.stringify !== "function") {
|
|
148
|
+
meta = {
|
|
149
|
+
// table of character substitutions
|
|
150
|
+
"\b": "\\b",
|
|
151
|
+
"\t": "\\t",
|
|
152
|
+
"\n": "\\n",
|
|
153
|
+
"\f": "\\f",
|
|
154
|
+
"\r": "\\r",
|
|
155
|
+
'"': '\\"',
|
|
156
|
+
"\\": "\\\\",
|
|
157
|
+
};
|
|
158
|
+
JSON.stringify = function (value, replacer, space) {
|
|
159
|
+
var i;
|
|
160
|
+
gap = "";
|
|
161
|
+
indent = "";
|
|
162
|
+
if (typeof space === "number") {
|
|
163
|
+
for (i = 0; i < space; i += 1) {
|
|
164
|
+
indent += " ";
|
|
165
|
+
}
|
|
166
|
+
} else if (typeof space === "string") {
|
|
167
|
+
indent = space;
|
|
168
|
+
}
|
|
169
|
+
rep = replacer;
|
|
170
|
+
if (
|
|
171
|
+
replacer &&
|
|
172
|
+
typeof replacer !== "function" &&
|
|
173
|
+
(typeof replacer !== "object" || typeof replacer.length !== "number")
|
|
174
|
+
) {
|
|
175
|
+
throw new Error("JSON.stringify");
|
|
176
|
+
}
|
|
177
|
+
return str("", { "": value });
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
})();
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
|
|
184
|
+
function getPropertyReference(key) {
|
|
185
|
+
var ref = new ActionReference();
|
|
186
|
+
ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID(key));
|
|
187
|
+
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
188
|
+
return ref;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
var output = null;
|
|
192
|
+
var ref;
|
|
193
|
+
try {
|
|
194
|
+
var document = {};
|
|
195
|
+
|
|
196
|
+
ref = getPropertyReference("title");
|
|
197
|
+
document.name = executeActionGet(ref).getString(stringIDToTypeID("title"));
|
|
198
|
+
|
|
199
|
+
ref = getPropertyReference("documentID");
|
|
200
|
+
document.id = executeActionGet(ref).getInteger(stringIDToTypeID("documentID"));
|
|
201
|
+
|
|
202
|
+
ref = getPropertyReference("width");
|
|
203
|
+
document.width = executeActionGet(ref).getInteger(stringIDToTypeID("width"));
|
|
204
|
+
ref = getPropertyReference("height");
|
|
205
|
+
document.height = executeActionGet(ref).getInteger(stringIDToTypeID("height"));
|
|
206
|
+
|
|
207
|
+
ref = getPropertyReference("resolution");
|
|
208
|
+
document.resolution = executeActionGet(ref).getInteger(stringIDToTypeID("resolution"));
|
|
209
|
+
|
|
210
|
+
ref = getPropertyReference("isDirty");
|
|
211
|
+
document.isDirty = executeActionGet(ref).getBoolean(stringIDToTypeID("isDirty"));
|
|
212
|
+
|
|
213
|
+
ref = getPropertyReference("fileReference");
|
|
214
|
+
var documentDescriptor = executeActionGet(ref);
|
|
215
|
+
if (documentDescriptor.hasKey(stringIDToTypeID("fileReference"))) {
|
|
216
|
+
document.filePath = File.decode(documentDescriptor.getPath(stringIDToTypeID("fileReference")));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
output = JSON.stringify(document);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
output = null;
|
|
222
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const filepath = params.path;
|
|
2
|
+
|
|
3
|
+
const desc = new ActionDescriptor();
|
|
4
|
+
desc.putBoolean(stringIDToTypeID("dontRecord"), false);
|
|
5
|
+
desc.putBoolean(stringIDToTypeID("forceNotify"), true);
|
|
6
|
+
desc.putPath(stringIDToTypeID("null"), new File(filepath));
|
|
7
|
+
executeAction(stringIDToTypeID("open"), desc, DialogModes.NO);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Save the active document. With `params.savePath`, save-as a PSD (maximize
|
|
2
|
+
// compatibility) to that path and bind the document to it; without it, save the
|
|
3
|
+
// document in place. Returns "OK", or an "Error:"-prefixed string the JsxRunner
|
|
4
|
+
// turns into a thrown error.
|
|
5
|
+
let result;
|
|
6
|
+
try {
|
|
7
|
+
const savePath = typeof params !== "undefined" && params ? params.savePath : undefined;
|
|
8
|
+
if (savePath) {
|
|
9
|
+
const saveDesc = new ActionDescriptor();
|
|
10
|
+
const psdOptions = new ActionDescriptor();
|
|
11
|
+
psdOptions.putBoolean(stringIDToTypeID("maximizeCompatibility"), true);
|
|
12
|
+
saveDesc.putObject(charIDToTypeID("As "), charIDToTypeID("Pht3"), psdOptions);
|
|
13
|
+
saveDesc.putPath(charIDToTypeID("In "), new File(savePath));
|
|
14
|
+
saveDesc.putInteger(charIDToTypeID("DocI"), app.activeDocument.id);
|
|
15
|
+
saveDesc.putBoolean(charIDToTypeID("LwCs"), true);
|
|
16
|
+
saveDesc.putEnumerated(
|
|
17
|
+
stringIDToTypeID("saveStage"),
|
|
18
|
+
stringIDToTypeID("saveStageType"),
|
|
19
|
+
stringIDToTypeID("saveBegin")
|
|
20
|
+
);
|
|
21
|
+
executeAction(charIDToTypeID("save"), saveDesc, DialogModes.NO);
|
|
22
|
+
} else {
|
|
23
|
+
const ref_save = new ActionReference();
|
|
24
|
+
ref_save.putEnumerated(
|
|
25
|
+
stringIDToTypeID("document"),
|
|
26
|
+
charIDToTypeID("Ordn"),
|
|
27
|
+
charIDToTypeID("Trgt")
|
|
28
|
+
);
|
|
29
|
+
const setDescriptor = new ActionDescriptor();
|
|
30
|
+
setDescriptor.putReference(stringIDToTypeID("null"), ref_save);
|
|
31
|
+
executeAction(stringIDToTypeID("save"), setDescriptor, DialogModes.NO);
|
|
32
|
+
}
|
|
33
|
+
result = "OK";
|
|
34
|
+
} catch (e) {
|
|
35
|
+
result = "Error: saveDocument failed: " + e.message;
|
|
36
|
+
}
|
|
37
|
+
result;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
var filePath = params.filePath;
|
|
2
|
+
var targetLayerId = params.id != undefined && params.id !== "" ? Number(params.id) : null;
|
|
3
|
+
var layerName = params.name;
|
|
4
|
+
var replace = false;
|
|
5
|
+
|
|
6
|
+
function getDocumentSize() {
|
|
7
|
+
var ref1 = new ActionReference();
|
|
8
|
+
ref1.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("width"));
|
|
9
|
+
ref1.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
10
|
+
var width = executeActionGet(ref1).getUnitDoubleValue(stringIDToTypeID("width"));
|
|
11
|
+
|
|
12
|
+
var ref2 = new ActionReference();
|
|
13
|
+
ref2.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("height"));
|
|
14
|
+
ref2.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
15
|
+
var height = executeActionGet(ref2).getUnitDoubleValue(stringIDToTypeID("height"));
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
width: width,
|
|
19
|
+
height: height,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function rename(str) {
|
|
24
|
+
var desc = new ActionDescriptor();
|
|
25
|
+
var ref = new ActionReference();
|
|
26
|
+
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
27
|
+
desc.putReference(charIDToTypeID("null"), ref);
|
|
28
|
+
var desc2 = new ActionDescriptor();
|
|
29
|
+
desc2.putString(charIDToTypeID("Nm "), str);
|
|
30
|
+
desc.putObject(charIDToTypeID("T "), charIDToTypeID("Lyr "), desc2);
|
|
31
|
+
executeAction(charIDToTypeID("setd"), desc, DialogModes.NO);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function addImageLayer(filePath, name, insertIndex) {
|
|
35
|
+
var desc = new ActionDescriptor();
|
|
36
|
+
desc.putPath(charIDToTypeID("null"), new File(filePath));
|
|
37
|
+
|
|
38
|
+
var idFTcs = charIDToTypeID("FTcs");
|
|
39
|
+
var idQCSt = charIDToTypeID("QCSt");
|
|
40
|
+
var idQcsa = charIDToTypeID("Qcsa");
|
|
41
|
+
desc.putEnumerated(idFTcs, idQCSt, idQcsa);
|
|
42
|
+
|
|
43
|
+
executeAction(charIDToTypeID("Plc "), desc, DialogModes.NO);
|
|
44
|
+
rasterizeLayer();
|
|
45
|
+
rename(name);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
if (insertIndex != undefined) {
|
|
49
|
+
moveLayer(insertIndex);
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function rasterizeLayer() {
|
|
55
|
+
var desc = new ActionDescriptor();
|
|
56
|
+
var ref = new ActionReference();
|
|
57
|
+
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
58
|
+
desc.putReference(charIDToTypeID("null"), ref);
|
|
59
|
+
executeAction(stringIDToTypeID("rasterizeLayer"), desc, DialogModes.NO);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function moveLayer(targetIndex) {
|
|
63
|
+
var desc = new ActionDescriptor();
|
|
64
|
+
var ref1 = new ActionReference();
|
|
65
|
+
ref1.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
66
|
+
desc.putReference(charIDToTypeID("null"), ref1);
|
|
67
|
+
var ref2 = new ActionReference();
|
|
68
|
+
ref2.putIndex(charIDToTypeID("Lyr "), targetIndex);
|
|
69
|
+
desc.putReference(charIDToTypeID("T "), ref2);
|
|
70
|
+
executeAction(charIDToTypeID("move"), desc, DialogModes.NO);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function deleteLayer(layerID) {
|
|
74
|
+
var desc = new ActionDescriptor();
|
|
75
|
+
var ref = new ActionReference();
|
|
76
|
+
ref.putIdentifier(stringIDToTypeID("layer"), layerID);
|
|
77
|
+
desc.putReference(charIDToTypeID("null"), ref);
|
|
78
|
+
executeAction(charIDToTypeID("Dlt "), desc, DialogModes.NO);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getLayerIndexByID(id) {
|
|
82
|
+
var ref1 = new ActionReference();
|
|
83
|
+
ref1.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("itemIndex"));
|
|
84
|
+
ref1.putIdentifier(stringIDToTypeID("layer"), id);
|
|
85
|
+
return executeActionGet(ref1).getInteger(stringIDToTypeID("itemIndex"));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function getLayerIDByIndex(layerIndex) {
|
|
89
|
+
var ref1 = new ActionReference();
|
|
90
|
+
ref1.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerID"));
|
|
91
|
+
ref1.putIdentifier(stringIDToTypeID("layer"), layerIndex);
|
|
92
|
+
return executeActionGet(ref1).getInteger(stringIDToTypeID("layerID"));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getLayerInfoByIndex(layerIndex) {
|
|
96
|
+
var ref1 = new ActionReference();
|
|
97
|
+
ref1.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerID"));
|
|
98
|
+
ref1.putIndex(stringIDToTypeID("layer"), layerIndex);
|
|
99
|
+
var ref2 = new ActionReference();
|
|
100
|
+
ref2.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("group"));
|
|
101
|
+
ref2.putIndex(stringIDToTypeID("layer"), layerIndex);
|
|
102
|
+
return {
|
|
103
|
+
layerID: executeActionGet(ref1).getInteger(stringIDToTypeID("layerID")),
|
|
104
|
+
group: executeActionGet(ref2).getBoolean(stringIDToTypeID("group")),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getInsertInfo(id) {
|
|
109
|
+
var insertIndex = getLayerIndexByID(id);
|
|
110
|
+
var origins = [id];
|
|
111
|
+
|
|
112
|
+
function tryGetNextInfo() {
|
|
113
|
+
try {
|
|
114
|
+
var info = getLayerInfoByIndex(insertIndex + 1);
|
|
115
|
+
if (info.group) {
|
|
116
|
+
insertIndex = insertIndex + 1;
|
|
117
|
+
origins.push(info.layerID);
|
|
118
|
+
tryGetNextInfo();
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {}
|
|
121
|
+
}
|
|
122
|
+
tryGetNextInfo();
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
insertIndex: insertIndex,
|
|
126
|
+
origins: origins,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getLayerBoundsByIndex(index) {
|
|
131
|
+
var lr = new ActionReference();
|
|
132
|
+
lr.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("bounds"));
|
|
133
|
+
lr.putIndex(stringIDToTypeID("layer"), index);
|
|
134
|
+
var value = executeActionGet(lr).getObjectValue(stringIDToTypeID("bounds"));
|
|
135
|
+
return {
|
|
136
|
+
left: value.getUnitDoubleValue(stringIDToTypeID("left")),
|
|
137
|
+
top: value.getUnitDoubleValue(stringIDToTypeID("top")),
|
|
138
|
+
right: value.getUnitDoubleValue(stringIDToTypeID("right")),
|
|
139
|
+
bottom: value.getUnitDoubleValue(stringIDToTypeID("bottom")),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getLayerIdByIndex(index) {
|
|
144
|
+
var idRef = new ActionReference();
|
|
145
|
+
idRef.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerID"));
|
|
146
|
+
idRef.putIndex(stringIDToTypeID("layer"), index);
|
|
147
|
+
return executeActionGet(idRef).getInteger(stringIDToTypeID("layerID"));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
var layerId;
|
|
151
|
+
try {
|
|
152
|
+
function toTransform() {
|
|
153
|
+
var insertIndex;
|
|
154
|
+
|
|
155
|
+
if (targetLayerId != null && !isNaN(targetLayerId)) {
|
|
156
|
+
var data = getInsertInfo(targetLayerId);
|
|
157
|
+
insertIndex = data.insertIndex;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
addImageLayer(filePath, layerName, insertIndex);
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
if (insertIndex) {
|
|
164
|
+
layerId = getLayerIdByIndex(insertIndex);
|
|
165
|
+
} else {
|
|
166
|
+
layerId = app.activeDocument.activeLayer.id;
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {}
|
|
169
|
+
}
|
|
170
|
+
app.activeDocument.suspendHistory("导入图片", "toTransform()");
|
|
171
|
+
|
|
172
|
+
// if (replace) {
|
|
173
|
+
// var origins = data.origins;
|
|
174
|
+
// for (var i = 0; i < origins.length; i++) {
|
|
175
|
+
// deleteLayer(origins[i]);
|
|
176
|
+
// }
|
|
177
|
+
// }
|
|
178
|
+
} catch (error) {
|
|
179
|
+
alert(error.message);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
layerId;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var wdth = params.width; //描边宽度
|
|
2
|
+
var opct = params.opct; //透明度
|
|
3
|
+
var location = params.location; //位置 Insd Otsd
|
|
4
|
+
var h = params.h;
|
|
5
|
+
var s = params.s;
|
|
6
|
+
var b = params.b;
|
|
7
|
+
try {
|
|
8
|
+
app.activeDocument.selection.bounds;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw new Error("请先选中一个选区");
|
|
11
|
+
}
|
|
12
|
+
function createSelection() {
|
|
13
|
+
//新建一个图层
|
|
14
|
+
try {
|
|
15
|
+
var idMk = charIDToTypeID("Mk ");
|
|
16
|
+
var desc4597 = new ActionDescriptor();
|
|
17
|
+
var idnull = charIDToTypeID("null");
|
|
18
|
+
var ref73 = new ActionReference();
|
|
19
|
+
var idLyr = charIDToTypeID("Lyr ");
|
|
20
|
+
ref73.putClass(idLyr);
|
|
21
|
+
desc4597.putReference(idnull, ref73);
|
|
22
|
+
executeAction(idMk, desc4597, DialogModes.NO);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
throw new Error("图层转换失败");
|
|
25
|
+
}
|
|
26
|
+
//描边
|
|
27
|
+
try {
|
|
28
|
+
var desc1 = new ActionDescriptor();
|
|
29
|
+
desc1.putInteger(charIDToTypeID("Wdth"), wdth);
|
|
30
|
+
desc1.putEnumerated(charIDToTypeID("Lctn"), charIDToTypeID("StrL"), charIDToTypeID(location));
|
|
31
|
+
desc1.putUnitDouble(charIDToTypeID("Opct"), charIDToTypeID("#Prc"), opct);
|
|
32
|
+
desc1.putEnumerated(charIDToTypeID("Md "), charIDToTypeID("BlnM"), charIDToTypeID("Nrml"));
|
|
33
|
+
var desc2 = new ActionDescriptor();
|
|
34
|
+
desc2.putUnitDouble(charIDToTypeID("H "), charIDToTypeID("#Ang"), h);
|
|
35
|
+
desc2.putDouble(charIDToTypeID("Strt"), s);
|
|
36
|
+
desc2.putDouble(charIDToTypeID("Brgh"), b);
|
|
37
|
+
desc1.putObject(charIDToTypeID("Clr "), charIDToTypeID("HSBC"), desc2);
|
|
38
|
+
executeAction(charIDToTypeID("Strk"), desc1, DialogModes.NO);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw new Error("创建描边选区失败");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
app.activeDocument.suspendHistory("创建选区描边", "createSelection()");
|
|
44
|
+
app.activeDocument.activeLayer.id;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
app.activeDocument.activeLayer.id;
|