@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,337 @@
|
|
|
1
|
+
/*global params, stringIDToTypeID, charIDToTypeID,
|
|
2
|
+
ActionDescriptor, ActionList, executeAction, DialogModes */
|
|
3
|
+
|
|
4
|
+
// Required params:
|
|
5
|
+
// - documentId: The ID of the document requested
|
|
6
|
+
// - layerSpec: Either the layer ID of the desired layer as a number, or an object of the form
|
|
7
|
+
// {firstLayerIndex: number, lastLayerIndex: number, hidden: Array.<number>=} specifying the
|
|
8
|
+
// desired index range, inclusive, and (optionally) an array of indices to hide.
|
|
9
|
+
// Note that the number form takes a layer ID, *not* a layer index.
|
|
10
|
+
// - boundsOnly: Whether to only request the bounds fo the pixmap
|
|
11
|
+
// Either use absolute scaling by specifying which part of the doc should be transformed into what shape:
|
|
12
|
+
// - inputRect: { left: ..., top: ..., right: ..., bottom: ... }
|
|
13
|
+
// - outputRect: { left: ..., top: ..., right: ..., bottom: ... }
|
|
14
|
+
// Or use relative scaling by specifying horizontal and vertical factors:
|
|
15
|
+
// - scaleX: The x-dimension scale factor (e.g. 0.5 for half size) for the output pixmap
|
|
16
|
+
// - scaleY: The y-dimension scale factor (e.g. 0.5 for half size) for the output pixmap
|
|
17
|
+
//
|
|
18
|
+
// Optional params:
|
|
19
|
+
// - useSmartScaling: setting to "true" causes shapes to be scaled in the "smart" way, which (confusingly)
|
|
20
|
+
// means that stroke effects (e.g. rounded rect corners) are *not* scaled. (Default: false)
|
|
21
|
+
// - includeAncestorMasks: setting to "true" causes exported layer to be clipped by any ancestor
|
|
22
|
+
// masks that are visible (Default: false)
|
|
23
|
+
// - convertToWorkingRGBProfile: If true, performs a color conversion on the pixels
|
|
24
|
+
// before they are sent to generator. The color is converted to the working RGB profile (specified for
|
|
25
|
+
// the document in PS). By default (when this setting is false), the "raw" RGB data is sent, which is
|
|
26
|
+
// what is usually desired. (Default: false)
|
|
27
|
+
// - useICCProfile: String with the ICC color profile to use. If set this overrides
|
|
28
|
+
// the convertToWorkingRGBProfile flag. A common value is "sRGB IEC61966-2.1". (Default: "")
|
|
29
|
+
// - getICCProfileData: If true then the final ICC profile for the image is included
|
|
30
|
+
// along with the returned pixamp (added after PS 16.1)
|
|
31
|
+
// - allowDither: controls whether any dithering could possibly happen in the color conversion
|
|
32
|
+
// to 8-bit RGB. If false, then dithering will definitely not occur, regardless of either
|
|
33
|
+
// the value of useColorSettingsDither and the color settings in Photoshop. (Default: false)
|
|
34
|
+
// - useColorSettingsDither: If allowDither is true, then this controls whether to (if true) defer to
|
|
35
|
+
// the user's color settings in PS, or (if false) to force dither in any case where a
|
|
36
|
+
// conversion to 8-bit RGB would otherwise be lossy. If allowDither is false, then the
|
|
37
|
+
// value of this parameter is ignored. (Default: false)
|
|
38
|
+
// - interpolationType: Force pixmap scaling to use the given interpolation method.
|
|
39
|
+
// If defined, the value should be one of the Generator.prototype.INTERPOLATION constants. Otherwise,
|
|
40
|
+
// Photoshop's default interpolation type (as specified in Preferences > Image Interpolation) is used.
|
|
41
|
+
// (Default: undefined)
|
|
42
|
+
// - forceSmartPSDPixelScaling: If true, forces PSD Smart objects to be scaled completely in pixel space
|
|
43
|
+
// (as opposed to scaling vectors, text, etc. in a smoother fashion.) In PS 15.0 and earlier
|
|
44
|
+
// pixel space scaling was the only option. So, setting this to "true" will replicate older behavior
|
|
45
|
+
// (Default: false)
|
|
46
|
+
// - clipToDocumentBounds: If true, crops returned pixels to the document bounds.
|
|
47
|
+
// By default, all pixels for the specified layers are returned, even if they lie outside the document
|
|
48
|
+
// bounds (e.g. if the document was cropped without "Delete Cropped Pixels" checked).
|
|
49
|
+
// Note that this option *cannot* be used with an inputRect/outputRect scaling. If inputRect/outputRect
|
|
50
|
+
// is set, this setting will be ignored and the pixels will not be cropped to document bounds.
|
|
51
|
+
// (Default: false)
|
|
52
|
+
// - clipBounds: crops retuned pixels to the given bounds
|
|
53
|
+
// - usePSClipping: if present use clipBounds to clip image
|
|
54
|
+
// - compId: number, layer comp ID (optionally and exclusive of compIndex)
|
|
55
|
+
// - compIndex: number, layer comp index (optionally and exclusive of compId)
|
|
56
|
+
// - maxDimension: number, maximal dimension of pixmap in pixels
|
|
57
|
+
|
|
58
|
+
var DEFAULT_MAX_DIMENSION = 10000;
|
|
59
|
+
|
|
60
|
+
var actionDescriptor = new ActionDescriptor(),
|
|
61
|
+
transform = null;
|
|
62
|
+
|
|
63
|
+
// Add a transform if necessary
|
|
64
|
+
if (params.inputRect && params.outputRect) {
|
|
65
|
+
transform = new ActionDescriptor();
|
|
66
|
+
|
|
67
|
+
// The part of the document to use
|
|
68
|
+
var inputRect = params.inputRect,
|
|
69
|
+
psInputRect = new ActionList();
|
|
70
|
+
|
|
71
|
+
psInputRect.putUnitDouble(charIDToTypeID("#Pxl"), inputRect.left);
|
|
72
|
+
psInputRect.putUnitDouble(charIDToTypeID("#Pxl"), inputRect.top);
|
|
73
|
+
|
|
74
|
+
psInputRect.putUnitDouble(charIDToTypeID("#Pxl"), inputRect.right);
|
|
75
|
+
psInputRect.putUnitDouble(charIDToTypeID("#Pxl"), inputRect.bottom);
|
|
76
|
+
|
|
77
|
+
transform.putList(stringIDToTypeID("rectangle"), psInputRect);
|
|
78
|
+
|
|
79
|
+
// Where to move the four corners
|
|
80
|
+
var outputRect = params.outputRect,
|
|
81
|
+
psOutputCorners = new ActionList();
|
|
82
|
+
|
|
83
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.left);
|
|
84
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.top);
|
|
85
|
+
|
|
86
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.right);
|
|
87
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.top);
|
|
88
|
+
|
|
89
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.right);
|
|
90
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.bottom);
|
|
91
|
+
|
|
92
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.left);
|
|
93
|
+
psOutputCorners.putUnitDouble(charIDToTypeID("#Pxl"), outputRect.bottom);
|
|
94
|
+
|
|
95
|
+
transform.putList(stringIDToTypeID("quadrilateral"), psOutputCorners);
|
|
96
|
+
|
|
97
|
+
// Absolute scaling may not keep the aspect ratio intact, in which case effects
|
|
98
|
+
// cannot be scaled. To be consistent, turn it off for all of absolute scaling
|
|
99
|
+
// transform.putBoolean(stringIDToTypeID("scaleStyles"), false);
|
|
100
|
+
} else if (params.scaleX && params.scaleY && (params.scaleX !== 1 || params.scaleY !== 1)) {
|
|
101
|
+
transform = new ActionDescriptor();
|
|
102
|
+
|
|
103
|
+
if (!params.useSmartScaling) {
|
|
104
|
+
transform.putBoolean(stringIDToTypeID("forceDumbScaling"), true);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
transform.putDouble(charIDToTypeID("Wdth"), params.scaleX * 100);
|
|
108
|
+
transform.putDouble(charIDToTypeID("Hght"), params.scaleY * 100);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (transform) {
|
|
112
|
+
// interpolation and scaling options are only relevant in cases where a transform
|
|
113
|
+
// is going to happen. So, we only bother to set them if we're actually going
|
|
114
|
+
// to add a transform descriptor
|
|
115
|
+
|
|
116
|
+
if (!params.useSmartScaling) {
|
|
117
|
+
transform.putBoolean(stringIDToTypeID("forceDumbScaling"), true);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (params.hasOwnProperty("interpolationType")) {
|
|
121
|
+
transform.putEnumerated(
|
|
122
|
+
stringIDToTypeID("interpolation"),
|
|
123
|
+
stringIDToTypeID("interpolationType"),
|
|
124
|
+
stringIDToTypeID(params.interpolationType)
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
actionDescriptor.putEnumerated(
|
|
128
|
+
stringIDToTypeID("interpolation"),
|
|
129
|
+
stringIDToTypeID("interpolationType"),
|
|
130
|
+
stringIDToTypeID(params.interpolationType)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (params.hasOwnProperty("forceSmartPSDPixelScaling")) {
|
|
135
|
+
transform.putBoolean(
|
|
136
|
+
stringIDToTypeID("forceSmartPSDPixelScaling"),
|
|
137
|
+
!!params.forceSmartPSDPixelScaling
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// actually add the transform descriptor to the main descriptor
|
|
142
|
+
actionDescriptor.putObject(
|
|
143
|
+
stringIDToTypeID("transform"),
|
|
144
|
+
stringIDToTypeID("transform"),
|
|
145
|
+
transform
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
actionDescriptor.putInteger(stringIDToTypeID("documentID"), params.documentId);
|
|
150
|
+
actionDescriptor.putInteger(
|
|
151
|
+
stringIDToTypeID("width"),
|
|
152
|
+
params.maxDimension || DEFAULT_MAX_DIMENSION
|
|
153
|
+
);
|
|
154
|
+
actionDescriptor.putInteger(
|
|
155
|
+
stringIDToTypeID("height"),
|
|
156
|
+
params.maxDimension || DEFAULT_MAX_DIMENSION
|
|
157
|
+
);
|
|
158
|
+
actionDescriptor.putInteger(stringIDToTypeID("format"), 2);
|
|
159
|
+
|
|
160
|
+
if (typeof params.layerSpec === "object") {
|
|
161
|
+
actionDescriptor.putInteger(stringIDToTypeID("firstLayer"), params.layerSpec.firstLayerIndex);
|
|
162
|
+
actionDescriptor.putInteger(stringIDToTypeID("lastLayer"), params.layerSpec.lastLayerIndex);
|
|
163
|
+
if (params.layerSpec.hasOwnProperty("hidden") && params.layerSpec.hidden.length > 0) {
|
|
164
|
+
var i,
|
|
165
|
+
hiddenIndiciesMap = {},
|
|
166
|
+
settingsList = new ActionList(),
|
|
167
|
+
hiddenLayerDesc = new ActionDescriptor(),
|
|
168
|
+
visibleLayerDesc = new ActionDescriptor(),
|
|
169
|
+
hiddenLayerSettings = new ActionDescriptor(),
|
|
170
|
+
lsID = stringIDToTypeID("layerSettings");
|
|
171
|
+
|
|
172
|
+
hiddenLayerSettings.putBoolean(stringIDToTypeID("enabled"), false);
|
|
173
|
+
hiddenLayerDesc.putObject(lsID, lsID, hiddenLayerSettings);
|
|
174
|
+
|
|
175
|
+
// We have to add a descriptor for every layer in order, so first
|
|
176
|
+
// build a map to make it easier to do this.
|
|
177
|
+
for (i = 0; i < params.layerSpec.hidden.length; ++i) {
|
|
178
|
+
hiddenIndiciesMap[params.layerSpec.hidden[i]] = true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Loop over every layer, and add either a hidden or visible descriptor
|
|
182
|
+
// based on the map we built.
|
|
183
|
+
for (i = params.layerSpec.firstLayerIndex; i <= params.layerSpec.lastLayerIndex; ++i) {
|
|
184
|
+
if (hiddenIndiciesMap[i]) {
|
|
185
|
+
settingsList.putObject(lsID, hiddenLayerDesc);
|
|
186
|
+
} else {
|
|
187
|
+
settingsList.putObject(lsID, visibleLayerDesc);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
actionDescriptor.putList(stringIDToTypeID("layerSettings"), settingsList);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
actionDescriptor.putInteger(stringIDToTypeID("layerID"), params.layerSpec);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (params.hasOwnProperty("compId")) {
|
|
198
|
+
actionDescriptor.putInteger(stringIDToTypeID("compID"), params.compId);
|
|
199
|
+
} else if (params.hasOwnProperty("compIndex")) {
|
|
200
|
+
actionDescriptor.putInteger(stringIDToTypeID("compIndex"), params.compIndex);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// includeAncestors
|
|
204
|
+
if (!params.includeAncestorMasks) {
|
|
205
|
+
actionDescriptor.putEnumerated(
|
|
206
|
+
stringIDToTypeID("includeAncestors"),
|
|
207
|
+
stringIDToTypeID("includeLayers"),
|
|
208
|
+
stringIDToTypeID("includeNone")
|
|
209
|
+
);
|
|
210
|
+
} else {
|
|
211
|
+
actionDescriptor.putEnumerated(
|
|
212
|
+
stringIDToTypeID("includeAncestors"),
|
|
213
|
+
stringIDToTypeID("includeLayers"),
|
|
214
|
+
stringIDToTypeID("includeVisible")
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// includeAdjustors
|
|
219
|
+
var includeAdjustors = stringIDToTypeID("includeVisible");
|
|
220
|
+
if (params.includeAdjustors != undefined) {
|
|
221
|
+
includeAdjustors = params.includeAdjustors
|
|
222
|
+
? stringIDToTypeID("includeVisible")
|
|
223
|
+
: stringIDToTypeID("includeNone");
|
|
224
|
+
}
|
|
225
|
+
actionDescriptor.putEnumerated(
|
|
226
|
+
stringIDToTypeID("includeAdjustors"),
|
|
227
|
+
stringIDToTypeID("includeLayers"),
|
|
228
|
+
includeAdjustors
|
|
229
|
+
);
|
|
230
|
+
// includeChildren
|
|
231
|
+
var includeChildren = stringIDToTypeID("includeVisible");
|
|
232
|
+
if (params.includeChildren != undefined) {
|
|
233
|
+
includeChildren = params.includeChildren
|
|
234
|
+
? stringIDToTypeID("includeVisible")
|
|
235
|
+
: stringIDToTypeID("includeNone");
|
|
236
|
+
}
|
|
237
|
+
actionDescriptor.putEnumerated(
|
|
238
|
+
stringIDToTypeID("includeChildren"),
|
|
239
|
+
stringIDToTypeID("includeLayers"),
|
|
240
|
+
includeChildren
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
// includeClipBase
|
|
244
|
+
var includeClipBase = stringIDToTypeID("includeVisible");
|
|
245
|
+
if (params.includeClipBase != undefined) {
|
|
246
|
+
includeClipBase = params.includeClipBase
|
|
247
|
+
? stringIDToTypeID("includeVisible")
|
|
248
|
+
: stringIDToTypeID("includeNone");
|
|
249
|
+
}
|
|
250
|
+
actionDescriptor.putEnumerated(
|
|
251
|
+
stringIDToTypeID("includeClipBase"),
|
|
252
|
+
stringIDToTypeID("includeLayers"),
|
|
253
|
+
includeClipBase
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
// includeClipped
|
|
257
|
+
var includeClipped = stringIDToTypeID("includeVisible");
|
|
258
|
+
if (params.includeClipped != undefined) {
|
|
259
|
+
includeClipped = params.includeClipped
|
|
260
|
+
? stringIDToTypeID("includeVisible")
|
|
261
|
+
: stringIDToTypeID("includeNone");
|
|
262
|
+
}
|
|
263
|
+
actionDescriptor.putEnumerated(
|
|
264
|
+
stringIDToTypeID("includeClipped"),
|
|
265
|
+
stringIDToTypeID("includeLayers"),
|
|
266
|
+
includeClipped
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
//
|
|
270
|
+
if (params.hasOwnProperty("convertToWorkingRGBProfile")) {
|
|
271
|
+
actionDescriptor.putBoolean(
|
|
272
|
+
stringIDToTypeID("convertToWorkingRGBProfile"),
|
|
273
|
+
!!params.convertToWorkingRGBProfile
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (params.hasOwnProperty("useICCProfile")) {
|
|
278
|
+
actionDescriptor.putString(stringIDToTypeID("useICCProfile"), String(params.useICCProfile));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (params.hasOwnProperty("getICCProfileData")) {
|
|
282
|
+
actionDescriptor.putBoolean(stringIDToTypeID("sendThumbnailProfile"), !!params.getICCProfileData);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// NOTE: on the PS side, allowDither and useColorSettingsDither default to "true" if they are
|
|
286
|
+
// not set at all. However, in Generator, the common case will be that we do NOT want to dither,
|
|
287
|
+
// regardless of the settings in PS. So, on the Generator side, we default to false (hence the !! on
|
|
288
|
+
// the params properties).
|
|
289
|
+
actionDescriptor.putBoolean(stringIDToTypeID("allowDither"), !!params.allowDither);
|
|
290
|
+
actionDescriptor.putBoolean(
|
|
291
|
+
stringIDToTypeID("useColorSettingsDither"),
|
|
292
|
+
!!params.useColorSettingsDither
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
if (params.hasOwnProperty("clipToDocumentBounds")) {
|
|
296
|
+
actionDescriptor.putBoolean(
|
|
297
|
+
stringIDToTypeID("clipToDocumentBounds"),
|
|
298
|
+
!!params.clipToDocumentBounds
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (params.clipBounds) {
|
|
303
|
+
// The part of the document to use
|
|
304
|
+
var clipBounds = params.clipBounds,
|
|
305
|
+
psClipRect = new ActionDescriptor();
|
|
306
|
+
|
|
307
|
+
psClipRect.putUnitDouble(stringIDToTypeID("left"), charIDToTypeID("#Pxl"), clipBounds.left);
|
|
308
|
+
psClipRect.putUnitDouble(stringIDToTypeID("top"), charIDToTypeID("#Pxl"), clipBounds.top);
|
|
309
|
+
|
|
310
|
+
psClipRect.putUnitDouble(stringIDToTypeID("right"), charIDToTypeID("#Pxl"), clipBounds.right);
|
|
311
|
+
psClipRect.putUnitDouble(stringIDToTypeID("bottom"), charIDToTypeID("#Pxl"), clipBounds.bottom);
|
|
312
|
+
|
|
313
|
+
actionDescriptor.putObject(
|
|
314
|
+
stringIDToTypeID("clipBounds"),
|
|
315
|
+
stringIDToTypeID("clipBounds"),
|
|
316
|
+
psClipRect
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (params.boundsOnly) {
|
|
321
|
+
actionDescriptor.putBoolean(stringIDToTypeID("boundsOnly"), params.boundsOnly);
|
|
322
|
+
}
|
|
323
|
+
actionDescriptor.putBoolean(stringIDToTypeID("bounds"), params.bounds);
|
|
324
|
+
//needs to be set explicitly as a boolean
|
|
325
|
+
if (params.thread === true || params.thread === false) {
|
|
326
|
+
actionDescriptor.putBoolean(stringIDToTypeID("thread"), params.thread);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
var result;
|
|
330
|
+
try {
|
|
331
|
+
result = executeAction(
|
|
332
|
+
stringIDToTypeID("sendLayerThumbnailToNetworkClient"),
|
|
333
|
+
actionDescriptor,
|
|
334
|
+
DialogModes.NO
|
|
335
|
+
);
|
|
336
|
+
} catch (error) {}
|
|
337
|
+
result;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
var id = params.layerID;
|
|
2
|
+
var layerBounds = undefined;
|
|
3
|
+
|
|
4
|
+
function Layer(id) {
|
|
5
|
+
this.id = id;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// --------- 实例方法 -----------------
|
|
9
|
+
/**
|
|
10
|
+
* 获取当前实例图层的名称
|
|
11
|
+
* @return {string}
|
|
12
|
+
*/
|
|
13
|
+
Layer.prototype.name = function () {
|
|
14
|
+
var layerReference = new ActionReference();
|
|
15
|
+
layerReference.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("Nm "));
|
|
16
|
+
layerReference.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
17
|
+
var descriptor = executeActionGet(layerReference);
|
|
18
|
+
return descriptor.getString(charIDToTypeID("Nm "));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 获取当前实例图层的层级
|
|
23
|
+
* @return {number}
|
|
24
|
+
*/
|
|
25
|
+
Layer.prototype.index = function () {
|
|
26
|
+
var layerReference = new ActionReference();
|
|
27
|
+
layerReference.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("ItmI"));
|
|
28
|
+
layerReference.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
29
|
+
var descriptor = executeActionGet(layerReference);
|
|
30
|
+
return descriptor.getInteger(charIDToTypeID("ItmI"));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 获取当前实例图层的类型
|
|
35
|
+
* @return {number}
|
|
36
|
+
*/
|
|
37
|
+
Layer.prototype.kind = function () {
|
|
38
|
+
var layerReference = new ActionReference();
|
|
39
|
+
layerReference.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerKind"));
|
|
40
|
+
layerReference.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
41
|
+
var descriptor = executeActionGet(layerReference);
|
|
42
|
+
return descriptor.getInteger(stringIDToTypeID("layerKind"));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 获取当前实例图层的尺寸
|
|
47
|
+
* @return {{x: number, width: number, y: number, height: number}}
|
|
48
|
+
*/
|
|
49
|
+
Layer.prototype.bounds = function () {
|
|
50
|
+
var layerReference = new ActionReference();
|
|
51
|
+
layerReference.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("bounds"));
|
|
52
|
+
layerReference.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
53
|
+
var layerDescriptor = executeActionGet(layerReference);
|
|
54
|
+
var rectangle = layerDescriptor.getObjectValue(stringIDToTypeID("bounds"));
|
|
55
|
+
var left = rectangle.getUnitDoubleValue(charIDToTypeID("Left"));
|
|
56
|
+
var top = rectangle.getUnitDoubleValue(charIDToTypeID("Top "));
|
|
57
|
+
var right = rectangle.getUnitDoubleValue(charIDToTypeID("Rght"));
|
|
58
|
+
var bottom = rectangle.getUnitDoubleValue(charIDToTypeID("Btom"));
|
|
59
|
+
return { x: left, y: top, width: right - left, height: bottom - top };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 判断当前图层的显示/隐藏
|
|
64
|
+
* @return {boolean}
|
|
65
|
+
*/
|
|
66
|
+
Layer.prototype.visible = function () {
|
|
67
|
+
var layerReference = new ActionReference();
|
|
68
|
+
layerReference.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("Vsbl"));
|
|
69
|
+
layerReference.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
70
|
+
var descriptor = executeActionGet(layerReference);
|
|
71
|
+
if (descriptor.hasKey(charIDToTypeID("Vsbl")) == false) return false;
|
|
72
|
+
return descriptor.getBoolean(charIDToTypeID("Vsbl"));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 获取形状图层的填充颜色
|
|
77
|
+
* @return {null|*[]}
|
|
78
|
+
*/
|
|
79
|
+
Layer.prototype.solidFill = function () {
|
|
80
|
+
var kind = this.kind();
|
|
81
|
+
if (kind === 4) {
|
|
82
|
+
// 只有形状图层才能获取到图层填充属性
|
|
83
|
+
var layerReference = new ActionReference();
|
|
84
|
+
// 形状图层的填充和其它属性在adjuestment下面
|
|
85
|
+
layerReference.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("adjustment"));
|
|
86
|
+
layerReference.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
87
|
+
var descriptor = executeActionGet(layerReference);
|
|
88
|
+
var adjustment = descriptor.getList(stringIDToTypeID("adjustment")); // adjustment是一个ActionList
|
|
89
|
+
var result = [];
|
|
90
|
+
for (var i = 0; i < adjustment.count; i++) {
|
|
91
|
+
var item = adjustment.getObjectValue(i);
|
|
92
|
+
var color = item.getObjectValue(stringIDToTypeID("color"));
|
|
93
|
+
var red = color.getInteger(stringIDToTypeID("red"));
|
|
94
|
+
var green = color.getInteger(stringIDToTypeID("grain"));
|
|
95
|
+
var blue = color.getInteger(stringIDToTypeID("blue"));
|
|
96
|
+
result.push({ red: red, green: green, blue: blue });
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 获取图层描边效果
|
|
105
|
+
* @return {{size: *, color: {red: *, green: *, blue: *}, opacity: *}|null}
|
|
106
|
+
*/
|
|
107
|
+
Layer.prototype.strokeFx = function () {
|
|
108
|
+
var layerReference = new ActionReference();
|
|
109
|
+
// 所有的图层效果,都在layerEffects下面
|
|
110
|
+
layerReference.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerEffects"));
|
|
111
|
+
layerReference.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
112
|
+
var descriptor = executeActionGet(layerReference);
|
|
113
|
+
var layerEffects = descriptor.getList(stringIDToTypeID("layerEffects"));
|
|
114
|
+
var frameFX = layerEffects.getObjectValue(stringIDToTypeID("frameFX"));
|
|
115
|
+
var enabled = frameFX.getBoolean(stringIDToTypeID("enabled"));
|
|
116
|
+
if (enabled) {
|
|
117
|
+
var size = frameFX.getInteger(stringIDToTypeID("size"));
|
|
118
|
+
var opacity = frameFX.getInteger(stringIDToTypeID("opacity"));
|
|
119
|
+
var color = frameFX.getObjectValue(stringIDToTypeID("color"));
|
|
120
|
+
var red = color.getInteger(stringIDToTypeID("red"));
|
|
121
|
+
var green = color.getInteger(stringIDToTypeID("grain"));
|
|
122
|
+
var blue = color.getInteger(stringIDToTypeID("blue"));
|
|
123
|
+
return {
|
|
124
|
+
size: size,
|
|
125
|
+
opacity: opacity,
|
|
126
|
+
color: { red: red, green: green, blue: blue },
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 选中当前实例图层
|
|
134
|
+
*/
|
|
135
|
+
Layer.prototype.select = function () {
|
|
136
|
+
var current = new ActionReference();
|
|
137
|
+
current.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
138
|
+
var desc = new ActionDescriptor();
|
|
139
|
+
desc.putReference(charIDToTypeID("null"), current);
|
|
140
|
+
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 显示当前实例对象图层
|
|
145
|
+
*/
|
|
146
|
+
Layer.prototype.show = function () {
|
|
147
|
+
var desc1 = new ActionDescriptor();
|
|
148
|
+
var list1 = new ActionList();
|
|
149
|
+
var ref1 = new ActionReference();
|
|
150
|
+
ref1.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
151
|
+
list1.putReference(ref1);
|
|
152
|
+
desc1.putList(charIDToTypeID("null"), list1);
|
|
153
|
+
executeAction(charIDToTypeID("Shw "), desc1, DialogModes.NO);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 隐藏当前实例对象图层
|
|
158
|
+
*/
|
|
159
|
+
Layer.prototype.hide = function () {
|
|
160
|
+
var current = new ActionReference();
|
|
161
|
+
var desc242 = new ActionDescriptor();
|
|
162
|
+
var list10 = new ActionList();
|
|
163
|
+
current.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
164
|
+
list10.putReference(current);
|
|
165
|
+
desc242.putList(charIDToTypeID("null"), list10);
|
|
166
|
+
executeAction(charIDToTypeID("Hd "), desc242, DialogModes.NO);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 栅格化当前实例图层
|
|
171
|
+
*/
|
|
172
|
+
Layer.prototype.rasterize = function () {
|
|
173
|
+
var desc7 = new ActionDescriptor();
|
|
174
|
+
var ref4 = new ActionReference();
|
|
175
|
+
ref4.putIdentifier(charIDToTypeID("Lyr "), this.id);
|
|
176
|
+
desc7.putReference(charIDToTypeID("null"), ref4);
|
|
177
|
+
executeAction(stringIDToTypeID("rasterizeLayer"), desc7, DialogModes.NO);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 修改图层名称
|
|
182
|
+
* @param newNameString
|
|
183
|
+
*/
|
|
184
|
+
Layer.prototype.setName = function (newNameString) {
|
|
185
|
+
var desc26 = new ActionDescriptor();
|
|
186
|
+
var ref13 = new ActionReference();
|
|
187
|
+
// 只能对当前选中的图层操作
|
|
188
|
+
ref13.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
189
|
+
desc26.putReference(charIDToTypeID("null"), ref13);
|
|
190
|
+
var desc27 = new ActionDescriptor();
|
|
191
|
+
desc27.putString(charIDToTypeID("Nm "), newNameString);
|
|
192
|
+
desc26.putObject(charIDToTypeID("T "), charIDToTypeID("Lyr "), desc27);
|
|
193
|
+
executeAction(charIDToTypeID("setd"), desc26, DialogModes.NO);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// --------- 类方法 -----------------
|
|
197
|
+
/**
|
|
198
|
+
* 获取选中的图层列表
|
|
199
|
+
* @return Layer[]
|
|
200
|
+
*/
|
|
201
|
+
Layer.getSelectedLayers = function () {
|
|
202
|
+
var targetLayersTypeId = stringIDToTypeID("targetLayersIDs");
|
|
203
|
+
var selectedLayersReference = new ActionReference();
|
|
204
|
+
selectedLayersReference.putProperty(charIDToTypeID("Prpr"), targetLayersTypeId);
|
|
205
|
+
selectedLayersReference.putEnumerated(
|
|
206
|
+
charIDToTypeID("Dcmn"),
|
|
207
|
+
charIDToTypeID("Ordn"),
|
|
208
|
+
charIDToTypeID("Trgt")
|
|
209
|
+
);
|
|
210
|
+
var desc = executeActionGet(selectedLayersReference);
|
|
211
|
+
var layers = [];
|
|
212
|
+
if (desc.hasKey(targetLayersTypeId)) {
|
|
213
|
+
// have selected layers
|
|
214
|
+
var list = desc.getList(targetLayersTypeId);
|
|
215
|
+
for (var i = 0; i < list.count; i++) {
|
|
216
|
+
var ar = list.getReference(i);
|
|
217
|
+
var layerId = ar.getIdentifier();
|
|
218
|
+
layers.push(new Layer(layerId));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// WIN CC2019的情况下,默认一个背景图层,会获取到ID是0
|
|
223
|
+
if (layers.length === 1 && layers[0].id === "0") {
|
|
224
|
+
layers = [];
|
|
225
|
+
selectedLayersReference = new ActionReference();
|
|
226
|
+
selectedLayersReference.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("LyrI"));
|
|
227
|
+
selectedLayersReference.putEnumerated(
|
|
228
|
+
charIDToTypeID("Lyr "),
|
|
229
|
+
charIDToTypeID("Ordn"),
|
|
230
|
+
charIDToTypeID("Trgt")
|
|
231
|
+
);
|
|
232
|
+
var descriptor = executeActionGet(selectedLayersReference);
|
|
233
|
+
var id = descriptor.getInteger(charIDToTypeID("LyrI"));
|
|
234
|
+
layers.push(new Layer(id));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return layers;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 根据名称获取图层
|
|
242
|
+
*/
|
|
243
|
+
Layer.getLayersByName = function () {
|
|
244
|
+
try {
|
|
245
|
+
var ref = new ActionReference();
|
|
246
|
+
ref.putName(charIDToTypeID("Lyr "), name);
|
|
247
|
+
var layerDesc = executeActionGet(ref);
|
|
248
|
+
var layerId = layerDesc.getInteger(charIDToTypeID("LyrI"));
|
|
249
|
+
return new Layer(layerId);
|
|
250
|
+
} catch (e) {
|
|
251
|
+
$.writeln(e.toSting());
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* 高效的遍历图层方法
|
|
258
|
+
*/
|
|
259
|
+
Layer.loopLayers = function (callback) {
|
|
260
|
+
var ref = new ActionReference();
|
|
261
|
+
// 当前文档的图层数量属性key
|
|
262
|
+
ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("NmbL"));
|
|
263
|
+
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
264
|
+
var desc = executeActionGet(ref);
|
|
265
|
+
var layerCount = desc.getInteger(charIDToTypeID("NmbL"));
|
|
266
|
+
$.writeln("count: " + layerCount);
|
|
267
|
+
// 索引起始值,会受是否有背景图层影响,需要做一下处理
|
|
268
|
+
var i = 0;
|
|
269
|
+
try {
|
|
270
|
+
activeDocument.backgroundLayer;
|
|
271
|
+
} catch (e) {
|
|
272
|
+
i = 1;
|
|
273
|
+
}
|
|
274
|
+
// 开始逐级遍历图层index,根据index来获取到图层实例
|
|
275
|
+
for (i; i < layerCount; i++) {
|
|
276
|
+
var ref = new ActionReference();
|
|
277
|
+
ref.putIndex(charIDToTypeID("Lyr "), i);
|
|
278
|
+
var desc = executeActionGet(ref);
|
|
279
|
+
var id = desc.getInteger(stringIDToTypeID("layerID"));
|
|
280
|
+
var layer = new Layer(id);
|
|
281
|
+
// 根据需要进行操作
|
|
282
|
+
callback && callback(layer);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const layerName = params.layerName;
|
|
2
|
+
const data = params.data;
|
|
3
|
+
const config = params.config;
|
|
4
|
+
|
|
5
|
+
function saveEngineData(layerName, data, config) {
|
|
6
|
+
config = config || {};
|
|
7
|
+
|
|
8
|
+
const refLay_gs = new ActionReference();
|
|
9
|
+
refLay_gs.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("generatorSettings"));
|
|
10
|
+
refLay_gs.putName(stringIDToTypeID("layer"), layerName);
|
|
11
|
+
|
|
12
|
+
const settingsDesc = new ActionDescriptor();
|
|
13
|
+
settingsDesc.putString(stringIDToTypeID("data"), data);
|
|
14
|
+
|
|
15
|
+
if (config.engine) settingsDesc.putString(stringIDToTypeID("engine"), config.engine);
|
|
16
|
+
if (config.version) settingsDesc.putString(stringIDToTypeID("version"), config.version);
|
|
17
|
+
|
|
18
|
+
const setDescriptor = new ActionDescriptor();
|
|
19
|
+
setDescriptor.putReference(stringIDToTypeID("null"), refLay_gs);
|
|
20
|
+
setDescriptor.putObject(stringIDToTypeID("to"), stringIDToTypeID("null"), settingsDesc);
|
|
21
|
+
setDescriptor.putString(charIDToTypeID("Prpr"), "engineData");
|
|
22
|
+
executeAction(charIDToTypeID("setd"), setDescriptor, DialogModes.NO);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
saveEngineData(layerName, data, config);
|
|
26
|
+
} catch (error) {}
|