Skip to content

Commit 32bdd0c

Browse files
committed
Build production files
1 parent 01ee256 commit 32bdd0c

File tree

2 files changed

+145
-53
lines changed

2 files changed

+145
-53
lines changed

dist/explode_shape_layer.jsx

Lines changed: 144 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
var configs = {
22
title: 'Explode layer tool',
3+
debug : false,
34
log : true,
45
itemAmountWarning : 50,
6+
dryRun : false,
57
};
68

7-
function consLog(text) {
9+
function cLog(text) {
810
if (configs.log)
911
$.writeln(text);
1012
}
1113

14+
function cDebug(text) {
15+
if (configs.debug)
16+
$.writeln(text);
17+
}
18+
1219
function listMatchNames(object) {
1320

1421
for(var i=1; i <= object.numProperties; i++) {
@@ -20,57 +27,121 @@ function listMatchNames(object) {
2027

2128
}
2229

23-
_progressBar = new Window('palette', configs.title, undefined, {
24-
resizeable : false,
25-
borderless : 'not quite true',
26-
});
27-
28-
_progressBar.preferredSize = [420, 40];
29-
_progressBar.bar = _progressBar.add("progressbar", undefined, 0, 100);
30-
_progressBar.bar.value = 0;
31-
_progressBar.bar.preferredSize.width = 400;
32-
_progressBar.bar.show()
33-
34-
_progressBar.barInfos = _progressBar.add("statictext", undefined, 'Loading, please wait', {
35-
justify: 'center'
36-
});
37-
_progressBar.barInfos.preferredSize = [400, 17];
38-
39-
_progressBar.make = function (min, max, current) {
40-
this.barProps = {
41-
min : min,
42-
max : max,
43-
current : current,
30+
function ExecutionTime() {
31+
32+
var startTime;
33+
var endTime;
34+
var execTime;
35+
36+
this.constructor = function () {}
37+
38+
this.start = function () {
39+
startTime = new Date().getTime();
40+
}
41+
42+
this.stop = function () {
43+
endTime = new Date().getTime()
44+
execTime = endTime - startTime;
45+
}
46+
47+
this.time = function () {
48+
return 'Execution time : ' + Math.floor(execTime / 1000) + 's ' + (execTime % 1000) + 'ms';
4449
}
45-
this.barProps.total = (this.barProps.max - this.barProps.min) + 1;
46-
this.barProps.step = (this.barProps.current - this.barProps.min) + 1;
47-
}
4850

49-
_progressBar.updateBar = function () {
50-
this.bar.value = Math.round(( (this.barProps.step) * 100) / this.barProps.max)
51-
consLog('Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total);
52-
this.barInfos.text = 'Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total;
5351
}
5452

55-
_progressBar.showBar = function () { this.show(); }
53+
function ProgressBar(min, max, current) {
54+
55+
var _window,
56+
_progressBar,
57+
_infos,
58+
_real,
59+
_cursor,
60+
_isVisible;
61+
62+
this.testInfos = 'Processing element :current on :max';
63+
64+
this.constructor = function(min, max, current) {
5665

57-
_progressBar.hideBar = function () { this.hide(); }
66+
_this = this;
67+
_isVisible = false;
68+
69+
_real = { min : min, max : max, current : current };
70+
_cursor = { min : 0, max : 100, current : 0 };
71+
72+
_cursor.max = (_real.max - _real.min) + 1;
73+
74+
// Instanciate the window
75+
_window = new Window('palette', configs.title, undefined, {
76+
resizeable : false,
77+
borderless : 'not quite true',
78+
});
79+
_window.preferredSize = [420, 40];
80+
81+
// Instanciate the progress bar
82+
_progressBar = _window.add("progressbar", undefined, _cursor.min, _cursor.max);
83+
_progressBar.preferredSize.width = 400;
84+
_progressBar.show();
85+
86+
// Instanciate text infos
87+
_infos = _window.add("statictext", undefined, 'Loading, please wait', {
88+
justify: 'center'
89+
});
90+
_infos.preferredSize = [400, 17];
91+
92+
this.update(current);
93+
94+
95+
return this;
96+
97+
}
98+
99+
this.start = function () {
100+
_isVisible = true;
101+
this.update(_real.current)
102+
_window.show();
103+
}
104+
105+
this.end = function () {
106+
_window.hide();
107+
}
108+
109+
this.update = function(step) {
110+
111+
_real.current = step;
112+
_cursor.current = (_real.current + 1) - _real.min;
113+
114+
var infos = this.testInfos
115+
.replace(':current', _cursor.current)
116+
.replace(':max', _cursor.max);
117+
118+
_progressBar.value = _cursor.current;
119+
_infos.text = infos;
120+
121+
cDebug(infos);
122+
123+
updateGraphics();
124+
}
125+
126+
function updateGraphics() {
127+
if(!_isVisible) return;
128+
_window.update();
129+
}
130+
131+
return this.constructor(min, max, current);
58132

59-
_progressBar.setCurrent = function (current, text) {
60-
this.barProps.current = current;
61-
this.barProps.step = (this.barProps.current - this.barProps.min) + 1;
62-
this.updateBar();
63-
this.update();
64133
}
65134

135+
// this.bar.value = Math.round(( (this.barProps.step) * 100) / this.barProps.max)
136+
66137
/*
67138
* @requires utils.jsx
68139
* @requires progressBar.jsx
69140
*/
70141

71142
function explodeLayer(layer) {
72143

73-
consLog('==============\n==============');
144+
cLog('Exploding layer : ' + layer.name);
74145

75146
// Get the elements of the original shape layer
76147
var contents = layer.property("Contents");
@@ -87,15 +158,15 @@ function explodeLayer(layer) {
87158

88159
}
89160

90-
_progressBar.make(1, contents.numProperties, 1);
91-
_progressBar.showBar();
161+
var pb = new ProgressBar(1, contents.numProperties, 1);
162+
pb.start();
92163

93164
// Browse through contents array
94165
for(var i = contents.numProperties; i > 0; i--) {
95166

96167
// Get the original property
97168
var _prop = contents.property(i);
98-
_progressBar.setCurrent(contents.numProperties - i)
169+
pb.update(contents.numProperties - i)
99170

100171
// Skip the property if not enabled
101172
if (!_prop.enabled) continue;
@@ -105,6 +176,7 @@ function explodeLayer(layer) {
105176

106177
new_layer.name = layer.name + ' - ' + _prop.name;
107178
new_layer.enabled = false;
179+
new_layer.shy = true;
108180

109181
layers.push(new_layer);
110182

@@ -116,12 +188,16 @@ function explodeLayer(layer) {
116188

117189
}
118190

119-
_progressBar.hideBar();
191+
pb.end();
120192

121193
for(var i = 0; i < layers.length; i++) {
122194
layers[i].enabled = true;
195+
layers[i].shy = false;
196+
if(configs.dryRun) layers[i].remove();
123197
}
124198

199+
return layers;
200+
125201
}
126202

127203
function explode() {
@@ -140,7 +216,29 @@ function explode() {
140216
return;
141217
}
142218

143-
explodeLayer(selectedLayer);
219+
cLog('==================')
220+
221+
cLog('Configs :')
222+
for(config in configs) {
223+
if(configs.hasOwnProperty(config))
224+
cLog(' ' + config + ' : ' + configs[config])
225+
}
226+
227+
cLog('')
228+
229+
var execTime = new ExecutionTime();
230+
execTime.start();
231+
232+
var hideShyLayers_originalState = selectedLayer.containingComp.hideShyLayers;
233+
selectedLayer.containingComp.hideShyLayers = true;
234+
235+
var layers = explodeLayer(selectedLayer);
236+
237+
selectedLayer.moveToBeginning()
238+
selectedLayer.containingComp.hideShyLayers = hideShyLayers_originalState;
239+
240+
execTime.stop();
241+
cLog(execTime.time());
144242

145243
}
146244

@@ -166,7 +264,7 @@ function copyProperties(origin, target, prefix) {
166264

167265
if(!_prop.enabled || !target.canAddProperty(_prop.matchName)) return;
168266

169-
consLog(prefix + _prop.matchName);
267+
cDebug(prefix + _prop.matchName);
170268

171269
var prop = target.addProperty(_prop.matchName);
172270

@@ -177,7 +275,7 @@ function copyProperties(origin, target, prefix) {
177275
break;
178276

179277
case 'ADBE Vector Materials Group':
180-
consLog(prefix + '-- skipped');
278+
cDebug(prefix + '-- skipped');
181279
break;
182280

183281
case 'ADBE Vector Graphic - Stroke':
@@ -306,7 +404,7 @@ function createUI(that) {
306404

307405
if(that instanceof Panel) {
308406

309-
var myPanel = that;
407+
var _panel = that;
310408

311409
} else {
312410

@@ -319,20 +417,14 @@ function createUI(that) {
319417

320418
var btn = _panel.add("button", [10, 10, 100, 30], "Explode layer");
321419

322-
_panel.text = configs.title;
420+
// _panel.text = configs.title;
323421
_panel.bounds.width = 120;
324422
_panel.bounds.height = 40;
325423

326424
btn.onClick = function() {
327425

328-
var startTime = new Date().getTime();
329-
330426
explode();
331427

332-
var execTime = new Date().getTime() - startTime;
333-
334-
consLog('Execution time : ' + Math.floor(execTime / 1000) + 's ' + (execTime % 1000) + 'ms');
335-
336428
}
337429

338430
return _panel;

dist/explode_shape_layer.min.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
function consLog(r){configs.log&&$.writeln(r)}function listMatchNames(r){for(var e=1;e<=r.numProperties;e++){var o=r.property(e);consLog(o.matchName+"("+o.name+")")}}function explodeLayer(r){consLog("==============\n==============");var e=r.property("Contents"),o=[];if(!(e.numProperties>configs.itemAmountWarning)||confirm("You have more than "+configs.itemAmountWarning+" elements. Execution time might be long, are you sure you want to continue ?")){_progressBar.make(1,e.numProperties,1),_progressBar.showBar();for(a=e.numProperties;a>0;a--){var t=e.property(a);if(_progressBar.setCurrent(e.numProperties-a),t.enabled){var p=emptyDuplicateLayer(r);p.name=r.name+" - "+t.name,p.enabled=!1,o.push(p),p.property("Contents").canAddProperty(t.matchName)&&copyProperties(t,p.property("Contents").addProperty(t.matchName),"")}}_progressBar.hideBar();for(var a=0;a<o.length;a++)o[a].enabled=!0}}function explode(){if(app.project.activeItem.selectedLayers.length>1)alert("Select a single shape layer");else{var r=app.project.activeItem.selectedLayers[0];void 0!=r&&"ADBE Vector Layer"===r.matchName?explodeLayer(r):alert("Select a shape layer")}}function emptyDuplicateLayer(r){var e=r.containingComp.layers.addShape();return copyProperty("anchorPoint",r,e),copyProperty("position",r,e),copyProperty("scale",r,e),copyProperty("rotation",r,e),copyProperty("opacity",r,e),e}function copyProperties(r,e,o){for(var t=1;t<=r.numProperties;t++){var p=r.property(t);if(!p.enabled||!e.canAddProperty(p.matchName))return;consLog(o+p.matchName);var a=e.addProperty(p.matchName);switch(p.matchName){case"ADBE Vector Filter - Merge":copyProperty("mode",p,a);break;case"ADBE Vector Materials Group":consLog(o+"-- skipped");break;case"ADBE Vector Graphic - Stroke":copyPropertyStroke(p,a);break;case"ADBE Vector Graphic - Fill":copyPropertyFill(p,a);break;case"ADBE Vector Transform Group":copyPropertyTransform(p,a);break;case"ADBE Vector Shape - Rect":copyPropertyRect(p,a);break;case"ADBE Vector Shape - Ellipse":copyPropertyEllipse(p,a);break;case"ADBE Vector Shape - Star":copyPropertyStar(p,a);break;case"ADBE Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":copyProperties(p,a,o+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(p,a);break;case"ADBE Vector Blend Mode":a.setValue(p.value)}}}function copyProperty(r,e,o){o[r].setValue(e[r].value)}function copyPropertyShape(r,e){e.property("ADBE Vector Shape").setValue(r.property("ADBE Vector Shape").value)}function copyPropertyStroke(r,e){copyProperty("composite",r,e),copyProperty("color",r,e),copyProperty("strokeWidth",r,e),copyProperty("lineCap",r,e),copyProperty("lineJoin",r,e),copyProperty("miterLimit",r,e)}function copyPropertyFill(r,e){copyProperty("composite",r,e),copyProperty("fillRule",r,e),copyProperty("color",r,e)}function copyPropertyTransform(r,e){copyProperty("anchorPoint",r,e),copyProperty("position",r,e),copyProperty("scale",r,e),copyProperty("skew",r,e),copyProperty("skewAxis",r,e),copyProperty("rotation",r,e),copyProperty("opacity",r,e)}function copyPropertyRect(r,e){copyProperty("shapeDirection",r,e),copyProperty("size",r,e),copyProperty("position",r,e),copyProperty("roundness",r,e)}function copyPropertyEllipse(r,e){copyProperty("shapeDirection",r,e),copyProperty("size",r,e),copyProperty("position",r,e)}function copyPropertyStar(r,e){copyProperty("shapeDirection",r,e),copyProperty("type",r,e),copyProperty("points",r,e),copyProperty("position",r,e),copyProperty("rotation",r,e),copyProperty("innerRadius",r,e),copyProperty("outerRadius",r,e),copyProperty("innerRoundness",r,e),copyProperty("outerRoundness",r,e)}function createUI(r){if(r instanceof Panel);else{var e=new Window("palette",configs.title,void 0,{resizeable:!0});e.show()}var o=e.add("button",[10,10,100,30],"Explode layer");return e.text=configs.title,e.bounds.width=120,e.bounds.height=40,o.onClick=function(){var r=(new Date).getTime();explode();var e=(new Date).getTime()-r;consLog("Execution time : "+Math.floor(e/1e3)+"s "+e%1e3+"ms")},e}var configs={title:"Explode layer tool",log:!0,itemAmountWarning:50};_progressBar=new Window("palette",configs.title,void 0,{resizeable:!1,borderless:"not quite true"}),_progressBar.preferredSize=[420,40],_progressBar.bar=_progressBar.add("progressbar",void 0,0,100),_progressBar.bar.value=0,_progressBar.bar.preferredSize.width=400,_progressBar.bar.show(),_progressBar.barInfos=_progressBar.add("statictext",void 0,"Loading, please wait",{justify:"center"}),_progressBar.barInfos.preferredSize=[400,17],_progressBar.make=function(r,e,o){this.barProps={min:r,max:e,current:o},this.barProps.total=this.barProps.max-this.barProps.min+1,this.barProps.step=this.barProps.current-this.barProps.min+1},_progressBar.updateBar=function(){this.bar.value=Math.round(100*this.barProps.step/this.barProps.max),consLog("Processing element "+(this.barProps.step+1)+" on "+this.barProps.total),this.barInfos.text="Processing element "+(this.barProps.step+1)+" on "+this.barProps.total},_progressBar.showBar=function(){this.show()},_progressBar.hideBar=function(){this.hide()},_progressBar.setCurrent=function(r,e){this.barProps.current=r,this.barProps.step=this.barProps.current-this.barProps.min+1,this.updateBar(),this.update()};var _panel=createUI(this);
1+
function cLog(e){configs.log&&$.writeln(e)}function cDebug(e){configs.debug&&$.writeln(e)}function listMatchNames(e){for(var r=1;r<=e.numProperties;r++){var o=e.property(r);consLog(o.matchName+"("+o.name+")")}}function ExecutionTime(){var e,r,o;this.constructor=function(){},this.start=function(){e=(new Date).getTime()},this.stop=function(){r=(new Date).getTime(),o=r-e},this.time=function(){return"Execution time : "+Math.floor(o/1e3)+"s "+o%1e3+"ms"}}function ProgressBar(e,r,o){function t(){s&&n.update()}var n,p,c,i,a,s;return this.testInfos="Processing element :current on :max",this.constructor=function(e,r,o){return _this=this,s=!1,i={min:e,max:r,current:o},a={min:0,max:100,current:0},a.max=i.max-i.min+1,n=new Window("palette",configs.title,void 0,{resizeable:!1,borderless:"not quite true"}),n.preferredSize=[420,40],p=n.add("progressbar",void 0,a.min,a.max),p.preferredSize.width=400,p.show(),c=n.add("statictext",void 0,"Loading, please wait",{justify:"center"}),c.preferredSize=[400,17],this.update(o),this},this.start=function(){s=!0,this.update(i.current),n.show()},this.end=function(){n.hide()},this.update=function(e){i.current=e,a.current=i.current+1-i.min;var r=this.testInfos.replace(":current",a.current).replace(":max",a.max);p.value=a.current,c.text=r,cDebug(r),t()},this.constructor(e,r,o)}function explodeLayer(e){cLog("Exploding layer : "+e.name);var r=e.property("Contents"),o=[];if(!(r.numProperties>configs.itemAmountWarning)||confirm("You have more than "+configs.itemAmountWarning+" elements. Execution time might be long, are you sure you want to continue ?")){var t=new ProgressBar(1,r.numProperties,1);t.start();for(c=r.numProperties;c>0;c--){var n=r.property(c);if(t.update(r.numProperties-c),n.enabled){var p=emptyDuplicateLayer(e);p.name=e.name+" - "+n.name,p.enabled=!1,p.shy=!0,o.push(p),p.property("Contents").canAddProperty(n.matchName)&&copyProperties(n,p.property("Contents").addProperty(n.matchName),"")}}t.end();for(var c=0;c<o.length;c++)o[c].enabled=!0,o[c].shy=!1,configs.dryRun&&o[c].remove();return o}}function explode(){if(app.project.activeItem.selectedLayers.length>1)alert("Select a single shape layer");else{var e=app.project.activeItem.selectedLayers[0];if(void 0!=e&&"ADBE Vector Layer"===e.matchName){cLog("=================="),cLog("Configs :");for(config in configs)configs.hasOwnProperty(config)&&cLog(" "+config+" : "+configs[config]);cLog("");var r=new ExecutionTime;r.start();var o=e.containingComp.hideShyLayers;e.containingComp.hideShyLayers=!0;explodeLayer(e);e.moveToBeginning(),e.containingComp.hideShyLayers=o,r.stop(),cLog(r.time())}else alert("Select a shape layer")}}function emptyDuplicateLayer(e){var r=e.containingComp.layers.addShape();return copyProperty("anchorPoint",e,r),copyProperty("position",e,r),copyProperty("scale",e,r),copyProperty("rotation",e,r),copyProperty("opacity",e,r),r}function copyProperties(e,r,o){for(var t=1;t<=e.numProperties;t++){var n=e.property(t);if(!n.enabled||!r.canAddProperty(n.matchName))return;cDebug(o+n.matchName);var p=r.addProperty(n.matchName);switch(n.matchName){case"ADBE Vector Filter - Merge":copyProperty("mode",n,p);break;case"ADBE Vector Materials Group":cDebug(o+"-- skipped");break;case"ADBE Vector Graphic - Stroke":copyPropertyStroke(n,p);break;case"ADBE Vector Graphic - Fill":copyPropertyFill(n,p);break;case"ADBE Vector Transform Group":copyPropertyTransform(n,p);break;case"ADBE Vector Shape - Rect":copyPropertyRect(n,p);break;case"ADBE Vector Shape - Ellipse":copyPropertyEllipse(n,p);break;case"ADBE Vector Shape - Star":copyPropertyStar(n,p);break;case"ADBE Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":copyProperties(n,p,o+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(n,p);break;case"ADBE Vector Blend Mode":p.setValue(n.value)}}}function copyProperty(e,r,o){o[e].setValue(r[e].value)}function copyPropertyShape(e,r){r.property("ADBE Vector Shape").setValue(e.property("ADBE Vector Shape").value)}function copyPropertyStroke(e,r){copyProperty("composite",e,r),copyProperty("color",e,r),copyProperty("strokeWidth",e,r),copyProperty("lineCap",e,r),copyProperty("lineJoin",e,r),copyProperty("miterLimit",e,r)}function copyPropertyFill(e,r){copyProperty("composite",e,r),copyProperty("fillRule",e,r),copyProperty("color",e,r)}function copyPropertyTransform(e,r){copyProperty("anchorPoint",e,r),copyProperty("position",e,r),copyProperty("scale",e,r),copyProperty("skew",e,r),copyProperty("skewAxis",e,r),copyProperty("rotation",e,r),copyProperty("opacity",e,r)}function copyPropertyRect(e,r){copyProperty("shapeDirection",e,r),copyProperty("size",e,r),copyProperty("position",e,r),copyProperty("roundness",e,r)}function copyPropertyEllipse(e,r){copyProperty("shapeDirection",e,r),copyProperty("size",e,r),copyProperty("position",e,r)}function copyPropertyStar(e,r){copyProperty("shapeDirection",e,r),copyProperty("type",e,r),copyProperty("points",e,r),copyProperty("position",e,r),copyProperty("rotation",e,r),copyProperty("innerRadius",e,r),copyProperty("outerRadius",e,r),copyProperty("innerRoundness",e,r),copyProperty("outerRoundness",e,r)}function createUI(e){if(e instanceof Panel)var r=e;else(r=new Window("palette",configs.title,void 0,{resizeable:!0})).show();var o=r.add("button",[10,10,100,30],"Explode layer");return r.bounds.width=120,r.bounds.height=40,o.onClick=function(){explode()},r}var configs={title:"Explode layer tool",debug:!1,log:!0,itemAmountWarning:50,dryRun:!1},_panel=createUI(this);

0 commit comments

Comments
 (0)