-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSS.plugin.jsfl
More file actions
113 lines (96 loc) · 3.1 KB
/
CSS.plugin.jsfl
File metadata and controls
113 lines (96 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var meta;
var frames;
function getPluginInfo(lang)
{
// fl.trace("==== getPluginInfo");
// fl.trace(lang);
// fl.trace("---- getPluginInfo");
pluginInfo = new Object();
pluginInfo.id = "CSS Keyframe Animations v1";
pluginInfo.name = "CSS Keyframe Animations";
pluginInfo.ext = "css";
pluginInfo.capabilities = new Object();
pluginInfo.capabilities.canRotate = false;
pluginInfo.capabilities.canTrim = false;
pluginInfo.capabilities.canShapePad = false;
pluginInfo.capabilities.canBorderPad = false;
pluginInfo.capabilities.canStackDuplicateFrames = true;
return pluginInfo;
}
function beginExport(meta)
{
// initialize frames array
frames = [];
fl.trace("** Export started **");
return "";
}
function frameExport(frame)
{
// store frame for future use
frames.push( frame );
return "";
}
function endExport(meta)
{
var fps = fl.getDocumentDOM().frameRate,
totalFrames = frames.length,
startFrame,endFrame,
currentName,currentFrame,
numFrames,keyframes,
i = 0,
j,tmp,
output = "";
while(i<totalFrames) {
//=== store start frame and get symbol name
startFrame = i;
currentName = frames[startFrame].symbolName;
fl.trace("Processing symbol \"" + currentName + "\"");
//=== find end frame
for(endFrame=startFrame+1;endFrame<totalFrames;endFrame++){
if ( currentName != frames[endFrame].symbolName ) {
--endFrame;
break;
}
}
//=== export symbol animtion
numFrames = endFrame - startFrame;
currentFrame = frames[startFrame];
currentName = currentName.replace(" ",""); // todo: remove more invalid characters ?
tmp = (numFrames / fps).toFixed(2);
//= create class
output += "." + currentName + " {\n";
output += "\tbackground: url(" + meta.image + ");\n";
output += "\tdisplay: block;\n";
output += "\twidth: " + currentFrame.frame.w + "px;\n";
output += "\theight: " + currentFrame.frame.h + "px;\n";
output += "\tmargin: 0;\n";
output += "\tpadding: 0;\n";
output += "\t-webkit-animation: " + currentName + " " + tmp + "s infinite;\n";
output += "\t-moz-animation: " + currentName + " " + tmp + "s infinite;\n";
output += "\t-ms-animation: " + currentName + " " + tmp + "s infinite;\n";
output += "\t-o-animation: " + currentName + " " + tmp + "s infinite;\n";
output += "\tanimation: " + currentName + " " + tmp + "s infinite;\n";
output += "}\n";
output += "\n";
//= gather keyframes
keyframes = "keyframes " + currentName + " {\n";
for(j=0;j<numFrames;j++){
currentFrame = frames[j+startFrame];
keyframes += "\t" + (Math.round(10000/numFrames*j)/100) + "%, ";
tmp = Math.round(10000/numFrames*(j+1))/100;
keyframes += ((j==numFrames-1)?tmp:(tmp-0.01).toFixed(2)) + "% ";
keyframes += "{ background-position: " + (-currentFrame.frame.x) + "px " + (-currentFrame.frame.y) + "px; }\n";
}
keyframes += "}\n\n";
//= duplicate keyframes using vendor prefixes
output += "@-webkit-" + keyframes;
output += "@-moz-" + keyframes;
output += "@-ms-" + keyframes;
output += "@-o-" + keyframes;
output += "@" + keyframes;
//=== iterate
i = endFrame + 1;
}
fl.trace("** Export finished **");
return output;
}