@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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/dist/contract-C4vydf6-.d.ts +1270 -0
  3. package/dist/contract.d.ts +3 -0
  4. package/dist/contract.js +19 -0
  5. package/dist/contract.js.map +1 -0
  6. package/dist/index.d.ts +8 -0
  7. package/dist/index.js +2482 -0
  8. package/dist/index.js.map +1 -0
  9. package/jsx/Action/autoCutout.jsx +12 -0
  10. package/jsx/Action/redo.jsx +5 -0
  11. package/jsx/Action/removeBackground.jsx +10 -0
  12. package/jsx/Common/alert.jsx +4 -0
  13. package/jsx/Common/debug.jsx +43 -0
  14. package/jsx/Common/event-dispatch.jsx +4 -0
  15. package/jsx/Document/exportDocument.jsx +128 -0
  16. package/jsx/Document/getDocumentInfo.jsx +222 -0
  17. package/jsx/Document/openPsd.jsx +6 -0
  18. package/jsx/Document/openPsdFile.jsx +7 -0
  19. package/jsx/Document/saveDocument.jsx +37 -0
  20. package/jsx/Layer/addImageLayer.jsx +182 -0
  21. package/jsx/Layer/createSelectionStroke.jsx +44 -0
  22. package/jsx/Layer/getActiveLayerID.jsx +1 -0
  23. package/jsx/Layer/getLayerBounds.jsx +114 -0
  24. package/jsx/Layer/getLayerInfo.jsx +323 -0
  25. package/jsx/Layer/getLayerPixmap.jsx +337 -0
  26. package/jsx/Layer/getSelection.jsx +6 -0
  27. package/jsx/Layer/layer.jsx +284 -0
  28. package/jsx/Layer/saveEngineDataToLayer.jsx +26 -0
  29. package/jsx/Layer/setLayerWorkpathMask.jsx +126 -0
  30. package/jsx/Layer/transformLayer.jsx +121 -0
  31. package/jsx/Selection/getSelectionPath.jsx +389 -0
  32. package/jsx/Selection/pathtosvg.jsx +257 -0
  33. package/jsx/Selection/registerEvent.jsx +10 -0
  34. package/jsx/Selection/selectiontopath.jsx +9 -0
  35. package/jsx/polyfills/Array.js +159 -0
  36. package/jsx/polyfills/Function.js +29 -0
  37. package/jsx/polyfills/JSON.js +182 -0
  38. package/jsx/polyfills/Number.js +24 -0
  39. package/jsx/polyfills/Object.js +80 -0
  40. package/jsx/polyfills/String.js +87 -0
  41. package/jsx/types/extendscript/README.md +34 -0
  42. package/jsx/types/extendscript/actions.d.ts +148 -0
  43. package/jsx/types/extendscript/application.d.ts +74 -0
  44. package/jsx/types/extendscript/channel.d.ts +70 -0
  45. package/jsx/types/extendscript/color.d.ts +92 -0
  46. package/jsx/types/extendscript/document.d.ts +110 -0
  47. package/jsx/types/extendscript/enums.d.ts +796 -0
  48. package/jsx/types/extendscript/index.d.ts +504 -0
  49. package/jsx/types/extendscript/layer.d.ts +530 -0
  50. package/jsx/types/extendscript/misc.d.ts +274 -0
  51. package/jsx/types/extendscript/open-options.d.ts +86 -0
  52. package/jsx/types/extendscript/path.d.ts +196 -0
  53. package/jsx/types/extendscript/save-options.d.ts +144 -0
  54. package/jsx/types/extendscript/selection.d.ts +191 -0
  55. package/jsx/types/extendscript/text.d.ts +169 -0
  56. package/main.js +16 -0
  57. package/package.json +75 -0
@@ -0,0 +1,114 @@
1
+ var layerID = params.layerID;
2
+ var layerBounds = undefined;
3
+
4
+ var lr = new ActionReference();
5
+ lr.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerKind"));
6
+ lr.putIdentifier(stringIDToTypeID("layer"), layerID);
7
+ var layerKind = executeActionGet(lr).getDouble(stringIDToTypeID("layerKind"));
8
+
9
+ if (layerKind == 7) {
10
+ var rawBounds = [8096, 8096, 0, 0];
11
+ var lr = new ActionReference();
12
+ lr.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("itemIndex"));
13
+ lr.putIdentifier(stringIDToTypeID("layer"), layerID);
14
+ var index = executeActionGet(lr).getInteger(stringIDToTypeID("itemIndex"));
15
+
16
+ try {
17
+ if (activeDocument.backgroundLayer) index -= 1;
18
+ } catch (error) {}
19
+
20
+ var _flag = 1;
21
+ var _index = index - 1;
22
+ var _visibleFlag = 999;
23
+ while (_flag) {
24
+ var ref = new ActionReference();
25
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerKind"));
26
+ ref.putIndex(stringIDToTypeID("layer"), _index);
27
+ var layerKind = executeActionGet(ref).getDouble(stringIDToTypeID("layerKind"));
28
+
29
+ var refPrpr = new ActionReference();
30
+ refPrpr.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("visible"));
31
+ refPrpr.putIndex(stringIDToTypeID("layer"), _index);
32
+ var layerVisible = executeActionGet(refPrpr).getBoolean(stringIDToTypeID("visible"));
33
+
34
+ if (layerKind == 7) {
35
+ _flag += 1;
36
+ _index -= 1;
37
+ if (!layerVisible) _visibleFlag = _flag;
38
+ continue;
39
+ }
40
+ if (layerKind == 13) {
41
+ _flag -= 1;
42
+ _index -= 1;
43
+ continue;
44
+ }
45
+ if (_flag >= _visibleFlag) {
46
+ _index -= 1;
47
+ continue;
48
+ }
49
+
50
+ refPrpr = new ActionReference();
51
+ refPrpr.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("group"));
52
+ refPrpr.putIndex(stringIDToTypeID("layer"), _index);
53
+ var layerGroup = executeActionGet(refPrpr).getBoolean(stringIDToTypeID("group"));
54
+ if (layerGroup || !layerVisible) {
55
+ _index -= 1;
56
+ continue;
57
+ }
58
+
59
+ var ref3 = new ActionReference();
60
+ ref3.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("bounds"));
61
+ ref3.putIndex(stringIDToTypeID("layer"), _index);
62
+ var layerBounds = executeActionGet(ref3).getObjectValue(stringIDToTypeID("bounds"));
63
+
64
+ var boundslist = [];
65
+ boundslist.push(layerBounds.getUnitDoubleValue(stringIDToTypeID("left")));
66
+ boundslist.push(layerBounds.getUnitDoubleValue(stringIDToTypeID("top")));
67
+ boundslist.push(layerBounds.getUnitDoubleValue(stringIDToTypeID("right")));
68
+ boundslist.push(layerBounds.getUnitDoubleValue(stringIDToTypeID("bottom")));
69
+
70
+ if (boundslist[0] != 0 || boundslist[1] != 0 || boundslist[2] != 0 || boundslist[3] != 0) {
71
+ if (rawBounds[0] > boundslist[0]) rawBounds[0] = boundslist[0];
72
+ if (rawBounds[1] > boundslist[1]) rawBounds[1] = boundslist[1];
73
+ if (rawBounds[2] < boundslist[2]) rawBounds[2] = boundslist[2];
74
+ if (rawBounds[3] < boundslist[3]) rawBounds[3] = boundslist[3];
75
+ }
76
+
77
+ _index -= 1;
78
+ _visibleFlag = 999;
79
+ if (_index == -1) break;
80
+ }
81
+ layerBounds =
82
+ '{\"left\":' +
83
+ boundslist[0] +
84
+ "," +
85
+ '\"top\":' +
86
+ boundslist[1] +
87
+ "," +
88
+ '\"right\":' +
89
+ boundslist[2] +
90
+ "," +
91
+ '\"bottom\":' +
92
+ boundslist[3] +
93
+ "}";
94
+ } else {
95
+ var lr = new ActionReference();
96
+ lr.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("bounds"));
97
+ lr.putIdentifier(stringIDToTypeID("layer"), layerID);
98
+ var value = executeActionGet(lr).getObjectValue(stringIDToTypeID("bounds"));
99
+ layerBounds =
100
+ '{\"left\":' +
101
+ value.getUnitDoubleValue(stringIDToTypeID("left")) +
102
+ "," +
103
+ '\"top\":' +
104
+ value.getUnitDoubleValue(stringIDToTypeID("top")) +
105
+ "," +
106
+ '\"right\":' +
107
+ value.getUnitDoubleValue(stringIDToTypeID("right")) +
108
+ "," +
109
+ '\"bottom\":' +
110
+ value.getUnitDoubleValue(stringIDToTypeID("bottom")) +
111
+ "}";
112
+ }
113
+
114
+ layerBounds;
@@ -0,0 +1,323 @@
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
+ var layerID = params.layerID;
185
+ var layerIndex = params.layerIndex;
186
+ if (layerIndex != undefined) {
187
+ var idRef = new ActionReference();
188
+ idRef.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerID"));
189
+ idRef.putIndex(stringIDToTypeID("layer"), layerIndex);
190
+ layerID = executeActionGet(idRef).getInteger(stringIDToTypeID("layerID"));
191
+ }
192
+
193
+ var _getChildren = params.getChildren != undefined ? params.getChildren : false;
194
+
195
+ function getLayerInfoByID(layerID) {
196
+ var result = {};
197
+ result.id = layerID;
198
+ // index
199
+ // var ref = new ActionReference();
200
+ // ref.putProperty(
201
+ // charIDToTypeID("Prpr"),
202
+ // stringIDToTypeID("hasBackgroundLayer")
203
+ // );
204
+ // ref.putEnumerated(
205
+ // charIDToTypeID("Dcmn"),
206
+ // charIDToTypeID("Ordn"),
207
+ // charIDToTypeID("Trgt")
208
+ // );
209
+
210
+ // var hasBackgroundLayer = executeActionGet(ref).getBoolean(
211
+ // stringIDToTypeID("hasBackgroundLayer")
212
+ // );
213
+
214
+ var ref = new ActionReference();
215
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("itemIndex"));
216
+ ref.putIdentifier(stringIDToTypeID("layer"), layerID);
217
+ result.index = executeActionGet(ref).getInteger(stringIDToTypeID("itemIndex"));
218
+ // type
219
+ var ref = new ActionReference();
220
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerKind"));
221
+ ref.putIdentifier(stringIDToTypeID("layer"), layerID);
222
+ result.type = executeActionGet(ref).getDouble(stringIDToTypeID("layerKind"));
223
+ // name
224
+ var ref = new ActionReference();
225
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("name"));
226
+ ref.putIdentifier(stringIDToTypeID("layer"), layerID);
227
+ result.name = executeActionGet(ref).getString(stringIDToTypeID("name"));
228
+
229
+ // visible
230
+ var ref = new ActionReference();
231
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("visible"));
232
+ ref.putIdentifier(stringIDToTypeID("layer"), layerID);
233
+ result.visible = executeActionGet(ref).getBoolean(stringIDToTypeID("visible"));
234
+
235
+ // clip
236
+ var ref = new ActionReference();
237
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("group"));
238
+ ref.putIdentifier(stringIDToTypeID("layer"), layerID);
239
+ result.clip = executeActionGet(ref).getBoolean(stringIDToTypeID("group"));
240
+ //generatorSettings todo
241
+
242
+ //bounds
243
+ try {
244
+ var ref = new ActionReference();
245
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("bounds"));
246
+ ref.putIdentifier(stringIDToTypeID("layer"), layerID);
247
+ var layerDescriptor = executeActionGet(ref);
248
+
249
+ var rectangle = layerDescriptor.getObjectValue(stringIDToTypeID("bounds"));
250
+ var left = rectangle.getUnitDoubleValue(charIDToTypeID("Left"));
251
+ var top = rectangle.getUnitDoubleValue(charIDToTypeID("Top "));
252
+ var right = rectangle.getUnitDoubleValue(charIDToTypeID("Rght"));
253
+ var bottom = rectangle.getUnitDoubleValue(charIDToTypeID("Btom"));
254
+
255
+ result.rect = {
256
+ x: left,
257
+ y: top,
258
+ width: right - left,
259
+ height: bottom - top,
260
+ };
261
+ result.bounds = {
262
+ left: left,
263
+ right: right,
264
+ top: top,
265
+ bottom: bottom,
266
+ };
267
+ } catch (error) {
268
+ alert("error " + error.message);
269
+ }
270
+
271
+ // layers
272
+ if (_getChildren) {
273
+ result.children = layerTreeCollection(result.index - 1, 0, undefined).layers;
274
+ }
275
+ return result;
276
+ }
277
+
278
+ function layerTreeCollection(from, to, items) {
279
+ items = items ? items : [];
280
+ for (var index = from; index >= to; index--) {
281
+ var ref = new ActionReference();
282
+ ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerKind"));
283
+ ref.putIndex(stringIDToTypeID("layer"), index);
284
+ var type = executeActionGet(ref).getDouble(stringIDToTypeID("layerKind"));
285
+
286
+ if (type == 13) {
287
+ return {
288
+ layers: items,
289
+ index: index,
290
+ };
291
+ }
292
+ var layer = getLayerInfoByIndex(index);
293
+
294
+ if (type == 7) {
295
+ var result = layerTreeCollection(index - 1, to, undefined);
296
+ layer.layers = result.layers;
297
+ index = result.index;
298
+ }
299
+ items.push(layer);
300
+ }
301
+ return {
302
+ layers: items,
303
+ index: 0,
304
+ };
305
+ }
306
+
307
+ var result = undefined;
308
+ try {
309
+ if (!layerID) {
310
+ var ref1 = new ActionReference();
311
+ ref1.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerID"));
312
+ ref1.putEnumerated(
313
+ stringIDToTypeID("layer"),
314
+ stringIDToTypeID("ordinal"),
315
+ stringIDToTypeID("targetEnum")
316
+ );
317
+ layerID = executeActionGet(ref1).getInteger(stringIDToTypeID("layerID"));
318
+ }
319
+ result = JSON.stringify(getLayerInfoByID(layerID));
320
+ } catch (error) {
321
+ result = "Error:获取的图层信息错误";
322
+ }
323
+ result;