dothtml 5.0.4 → 5.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/.vscode/launch.json +34 -0
- package/.vscode/settings.json +2 -1
- package/lib/component.d.ts +1 -1
- package/lib/dot-util.d.ts +13 -0
- package/lib/dothtml.d.ts +1 -1
- package/lib/dothtml.js +1 -1
- package/lib/i-dot.d.ts +4 -4
- package/lib/styling/css-types.ts/css-angle.d.ts +7 -0
- package/lib/styling/css-types.ts/css-color.d.ts +9 -0
- package/lib/styling/css-types.ts/css-complex.d.ts +7 -0
- package/lib/styling/css-types.ts/css-data-type.d.ts +5 -0
- package/lib/styling/css-types.ts/css-length.d.ts +7 -0
- package/lib/styling/css-types.ts/css-number.d.ts +6 -0
- package/lib/styling/css-types.ts/css-transform.d.ts +38 -0
- package/lib/styling/css-types.ts/css-unknown.d.ts +6 -0
- package/lib/styling/css-types.ts/css-url.d.ts +6 -0
- package/lib/{i-dotcss.d.ts → styling/i-dotcss.d.ts} +192 -42
- package/lib/styling/style-builder.d.ts +24 -0
- package/lib/styling/unit-function-tables.d.ts +10 -0
- package/package.json +2 -2
- package/src/component.ts +1 -1
- package/src/dot-util.ts +37 -1
- package/src/dot.ts +2 -2
- package/src/dothtml.ts +1 -1
- package/src/i-dot.ts +1 -1
- package/src/styling/css-types.ts/css-angle.ts +18 -0
- package/src/styling/css-types.ts/css-color.ts +229 -0
- package/src/styling/css-types.ts/css-complex.ts +20 -0
- package/src/styling/css-types.ts/css-data-type.ts +9 -0
- package/src/styling/css-types.ts/css-length.ts +20 -0
- package/src/styling/css-types.ts/css-number.ts +12 -0
- package/src/styling/css-types.ts/css-transform.ts +220 -0
- package/src/styling/css-types.ts/css-unknown.ts +13 -0
- package/src/styling/css-types.ts/css-url.ts +41 -0
- package/src/{i-dotcss.ts → styling/i-dotcss.ts} +206 -49
- package/src/styling/style-builder.ts +963 -0
- package/src/styling/unit-function-tables.ts +24 -0
- package/unittests/basic-functionality.test.ts +1 -1
- package/unittests/calc.test.ts +2 -0
- package/unittests/{component-decorator.-.ts → components/component-decorator.-.ts} +0 -0
- package/unittests/{components-data.test.ts → components/components-data.test.ts} +3 -3
- package/unittests/{components.test.ts → components/components.test.ts} +5 -4
- package/unittests/input-bindings.test.ts +6 -6
- package/unittests/non-function-props-rerender.test.ts +85 -0
- package/unittests/styling/animations.test.ts +14 -0
- package/unittests/styling/inline-styling.test.ts +18 -0
- package/unittests/styling/pseudo-selectors.test.ts +1 -0
- package/unittests/styling/transformations.test.ts +234 -0
- package/{lib/dot-document.d.ts → unittests/styling/value-interpretation.test.ts} +0 -0
- package/lib/style-builder.d.ts +0 -3
- package/src/dot-document.ts +0 -0
- package/src/style-builder.ts +0 -1516
package/src/style-builder.ts
DELETED
|
@@ -1,1516 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import IDotCss, { HideParams, LengthProp, ShowParams } from "./i-dotcss";
|
|
4
|
-
|
|
5
|
-
//Latest Update.
|
|
6
|
-
/*
|
|
7
|
-
* - Wrapped code in anonymous function.
|
|
8
|
-
* - Hid _Builder and _StyleProperty.
|
|
9
|
-
* - Increased compatibility with IE 8, 9, and 10.
|
|
10
|
-
* - Allowed 0-length animations.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const STATIC_SYLES_ATTR = "data-dot-static-styles";
|
|
14
|
-
|
|
15
|
-
const dotcss: IDotCss = function(query){
|
|
16
|
-
//this.currentCss = "";
|
|
17
|
-
var target = null;
|
|
18
|
-
if(query){
|
|
19
|
-
// console.log(query, "?");
|
|
20
|
-
if( typeof query == "string" ) {
|
|
21
|
-
// Creating a style tag. Might not be supported forever.
|
|
22
|
-
if(query.length > 2 && query.indexOf("{}") == query.length - 2){
|
|
23
|
-
query = query.substring(0, query.length - 2);
|
|
24
|
-
target = [document.createElement("style")];
|
|
25
|
-
document.head.appendChild(target[0]);
|
|
26
|
-
target[0].innerHTML = query + "{}";
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
// This is overly complicated, but here is the spiel.
|
|
30
|
-
// If there's an element on the scopeStack, it should be used with the querySelectorAll.
|
|
31
|
-
// BUT, querySelectorAll doesn't actually select the element it's currently on, which is a requirement for dothtml.
|
|
32
|
-
// To make matters worse, if we do querySelectorAll on the element's parents, we may accidentally select its siblings!!
|
|
33
|
-
// To fix this, we get a list from querySelectorAll on the element, then push the element itself to that list
|
|
34
|
-
// iff it is in the list of elements queried from its parent.
|
|
35
|
-
// In addition to all of that, we don't want scoped styles to be applied to child components.
|
|
36
|
-
var s0 = scopeStack[0];
|
|
37
|
-
// if(s0 instanceof Component){
|
|
38
|
-
// s0 = s0.$el;
|
|
39
|
-
// }
|
|
40
|
-
// If we're doing scoped, and it's an element.
|
|
41
|
-
if(s0 && s0.parentNode && s0.querySelectorAll){
|
|
42
|
-
// console.log(s0);
|
|
43
|
-
target = getScopedNodeList(query, s0);
|
|
44
|
-
}
|
|
45
|
-
else{
|
|
46
|
-
target = document.querySelectorAll(query as string);
|
|
47
|
-
}
|
|
48
|
-
// target = referencePt.querySelectorAll(query);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if((query instanceof NodeList) || (query instanceof Array)) target = query;
|
|
53
|
-
if(query instanceof Node) target = [query]; //Doesn't need to be a NodeList. Just iterable.
|
|
54
|
-
}
|
|
55
|
-
dotcss2._lastBuilder = new _Builder(target);
|
|
56
|
-
return dotcss2._lastBuilder;
|
|
57
|
-
} as IDotCss;
|
|
58
|
-
|
|
59
|
-
// Easier way to extend dotcss with private methods without type concerns.
|
|
60
|
-
const dotcss2 = dotcss as any;
|
|
61
|
-
|
|
62
|
-
dotcss.version = "0.16.0";
|
|
63
|
-
|
|
64
|
-
//Inverse of framerate in ms/frame.
|
|
65
|
-
dotcss2._fxInterval = 1000 / 60;
|
|
66
|
-
|
|
67
|
-
dotcss2._lastBuilder = null;
|
|
68
|
-
|
|
69
|
-
dotcss2._floatRegex = new RegExp("[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?", "g");
|
|
70
|
-
|
|
71
|
-
var scopeStack = [];
|
|
72
|
-
|
|
73
|
-
function getScopedNodeList(query: String, s0: Element): Array<HTMLElement>{
|
|
74
|
-
// Get all of the matching child elements of the component. This will not include s0 itself, but it does include nested components.
|
|
75
|
-
// So we will need to manipulate this collection.
|
|
76
|
-
// querySelectorAll returns a NodeList, which we need to convert into an Array.
|
|
77
|
-
var target = Array.from(s0.querySelectorAll(query as any));
|
|
78
|
-
// console.log(query, s0.className);
|
|
79
|
-
|
|
80
|
-
// Exclude nested components.
|
|
81
|
-
for(var t = 0; t < target.length; t++){
|
|
82
|
-
var T = target[t];
|
|
83
|
-
|
|
84
|
-
// Is it a nested component??
|
|
85
|
-
if(T["__dothtml_component"]){
|
|
86
|
-
// It's a component. Remove it, and all of it's descendants.
|
|
87
|
-
target.splice(t, 1);
|
|
88
|
-
t--;
|
|
89
|
-
|
|
90
|
-
var subTargets = T.querySelectorAll(query as any);
|
|
91
|
-
for(var s = 0; s < subTargets.length; s++){
|
|
92
|
-
let S = subTargets[s];
|
|
93
|
-
target.splice(target.indexOf(S, t + 1), 1);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Loop through all the sibling nodes until we find s0.
|
|
99
|
-
var parentTargets = Array.from(s0.parentNode.querySelectorAll(query as any));
|
|
100
|
-
|
|
101
|
-
var p = parentTargets.indexOf(s0);
|
|
102
|
-
if(p != -1){
|
|
103
|
-
target.unshift(parentTargets[p]);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return target;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function _Builder(target?: string|Element){
|
|
110
|
-
this.currentCss = "";
|
|
111
|
-
this.target = target;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
dotcss2._Builder = _Builder;
|
|
115
|
-
|
|
116
|
-
var _b = _Builder.prototype;
|
|
117
|
-
|
|
118
|
-
_b.toString = dotcss.prototype.toString = function(){
|
|
119
|
-
// console.log("CALLED TOSTRING!", this.currentCss);
|
|
120
|
-
return this.currentCss;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
//Usage:
|
|
124
|
-
//hide()
|
|
125
|
-
//hide(duration, complete)
|
|
126
|
-
//hide(options)
|
|
127
|
-
//Options
|
|
128
|
-
// display: inline-block, block, etc.
|
|
129
|
-
// duration: duration in ms.
|
|
130
|
-
// complete: on-complete callback.
|
|
131
|
-
// hideStyle: fade, shrink, or normal
|
|
132
|
-
// animationStyle: linear or exponential
|
|
133
|
-
_b.hide = function(){
|
|
134
|
-
if(this.target){
|
|
135
|
-
var arg0: HideParams|number = arguments[0] || {};
|
|
136
|
-
var arg0N = arg0 as number;
|
|
137
|
-
var arg0O = arg0 as HideParams;
|
|
138
|
-
var ops: HideParams = {};
|
|
139
|
-
ops.duration = arg0O.duration || (isNaN(arg0N) ? 0 : arg0N) || 0;
|
|
140
|
-
//ops.display = arg0.display || "none";
|
|
141
|
-
//ops.opacity = arg0.opacity || null;
|
|
142
|
-
//ops.width = arg0.width || null;
|
|
143
|
-
//ops.height = arg0.height || null;
|
|
144
|
-
ops.complete = arg0O.complete || (typeof arguments[1] == "function" ? arguments[1] : (typeof arguments[2] == "function" ? arguments[2] : function(){}));
|
|
145
|
-
ops.hideStyle = arg0O.hideStyle || "normal";
|
|
146
|
-
ops.animationStyle = arg0O.animationStyle || (typeof arguments[1] == "string" ? arguments[1] as any : "ease");
|
|
147
|
-
|
|
148
|
-
if(ops.duration > 0){
|
|
149
|
-
var doneCnt = 0;
|
|
150
|
-
var m = 0;
|
|
151
|
-
var q = this.target.length;
|
|
152
|
-
for(var i = 0; i < this.target.length; i++){
|
|
153
|
-
var w = this.target[i].style.width;
|
|
154
|
-
var h = this.target[i].style.height;
|
|
155
|
-
var o = this.target[i].style.opacity;
|
|
156
|
-
if(o === "") o = 1;
|
|
157
|
-
var ov = this.target[i].style.overflow;
|
|
158
|
-
if(ops.hideStyle != "fade"){
|
|
159
|
-
this.target[i].style.overflow = "hidden";
|
|
160
|
-
m += 2;
|
|
161
|
-
(function(that, t, w, h, ov){
|
|
162
|
-
dotcss(t).width.animate(0, ops.duration, ops.animationStyle, function(){
|
|
163
|
-
dotcss(t).display("none").width(w).overflow(ov); //Restore original overflow value. Only needs to be done once.
|
|
164
|
-
doneCnt++; if(doneCnt >= m * q) ops.complete(that);
|
|
165
|
-
});
|
|
166
|
-
dotcss(t).height.animate(0, ops.duration, ops.animationStyle, function(){
|
|
167
|
-
dotcss(t).display("none").height(h);
|
|
168
|
-
doneCnt++; if(doneCnt >= m * q) ops.complete(that);
|
|
169
|
-
});
|
|
170
|
-
})(this, this.target[i], w, h, ov);
|
|
171
|
-
}
|
|
172
|
-
if(ops.hideStyle != "shrink"){
|
|
173
|
-
m++;
|
|
174
|
-
(function(that, t, o){
|
|
175
|
-
return dotcss(t).opacity.animate(0, ops.duration, ops.animationStyle, function(){
|
|
176
|
-
dotcss(t).display("none").opacity(o);
|
|
177
|
-
doneCnt++; if(doneCnt >= m * q) ops.complete(that);
|
|
178
|
-
});
|
|
179
|
-
})(this, this.target[i], o);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else{
|
|
184
|
-
dotcss(this.target).display("none");
|
|
185
|
-
ops.complete(this); //This sets the display to none.
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return this;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
//Usage:
|
|
192
|
-
//show()
|
|
193
|
-
//show(duration, complete)
|
|
194
|
-
//show(options)
|
|
195
|
-
//Options
|
|
196
|
-
// display: inline-block, block, etc.
|
|
197
|
-
// opacity: final opacity.
|
|
198
|
-
// width: final width.
|
|
199
|
-
// height: final height.
|
|
200
|
-
// duration: duration in ms.
|
|
201
|
-
// complete: on-complete callback.
|
|
202
|
-
// showStyle: fade, grow, or normal
|
|
203
|
-
// animationStyle: linear or exponential
|
|
204
|
-
_b.show = function(){
|
|
205
|
-
if(this.target){
|
|
206
|
-
var arg0 = arguments[0] || {};
|
|
207
|
-
var arg0N = arg0 as number;
|
|
208
|
-
var arg0O = arg0 as ShowParams;
|
|
209
|
-
var ops: ShowParams = {};
|
|
210
|
-
ops.duration = arg0O.duration || (isNaN(arg0N) ? 0 : arg0N) || 0;
|
|
211
|
-
ops.display = arg0O.display || "block";
|
|
212
|
-
ops.opacity = arg0O.opacity;
|
|
213
|
-
ops.width = arg0O.width || null;
|
|
214
|
-
ops.height = arg0O.height || null;
|
|
215
|
-
ops.complete = arg0O.complete || (typeof arguments[1] == "function" ? arguments[1] : (typeof arguments[2] == "function" ? arguments[2] : function(){}));
|
|
216
|
-
ops.showStyle = arg0O.showStyle || "normal";
|
|
217
|
-
ops.animationStyle = arg0O.animationStyle || (typeof arguments[1] == "string" ? arguments[1] as any : "ease");
|
|
218
|
-
|
|
219
|
-
if(ops.duration > 0){
|
|
220
|
-
var doneCnt = 0;
|
|
221
|
-
var q = this.target.length;
|
|
222
|
-
var m = 0;
|
|
223
|
-
for(var i = 0; i < this.target.length; i++){
|
|
224
|
-
var o = ops.opacity;
|
|
225
|
-
if(ops.opacity === undefined){
|
|
226
|
-
o = parseFloat(this.target[i].style.opacity) || 1;
|
|
227
|
-
}
|
|
228
|
-
if(ops.showStyle != "fade"){
|
|
229
|
-
m += 2;
|
|
230
|
-
var w = ops.width || this.target[i].style.width;
|
|
231
|
-
var h = ops.height || this.target[i].style.height;
|
|
232
|
-
|
|
233
|
-
dotcss(this.target[i]).width(0);
|
|
234
|
-
dotcss(this.target[i]).height(0);
|
|
235
|
-
// console.log(doneCnt + " " + q*m);
|
|
236
|
-
dotcss(this.target[i]).width.animate(w, ops.duration, ops.animationStyle, function(){doneCnt++; if(doneCnt >= q * m) ops.complete();});
|
|
237
|
-
dotcss(this.target[i]).height.animate(h, ops.duration, ops.animationStyle, function(){doneCnt++; if(doneCnt >= q * m) ops.complete();});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
//var o = this.target[i].style.opacity; //Guess I should fade to 1?
|
|
241
|
-
dotcss(this.target[i]).opacity(0);
|
|
242
|
-
dotcss(this.target[i]).display(ops.display);
|
|
243
|
-
|
|
244
|
-
if(ops.showStyle != "grow"){
|
|
245
|
-
m++;
|
|
246
|
-
dotcss(this.target[i]).opacity.animate(o, ops.duration, ops.animationStyle, function(){doneCnt++; if(doneCnt == q * m) ops.complete();});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
else{
|
|
251
|
-
return dotcss(this.target).display(ops.display);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return this;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
_b.fadeOut = function(duration, complete){
|
|
258
|
-
return this.hide({
|
|
259
|
-
duration: isNaN(duration) ? 400 : Number(duration),
|
|
260
|
-
hideStyle: "fade",
|
|
261
|
-
complete: complete
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
_b.fadeIn = function(duration, complete){
|
|
266
|
-
return this.show({
|
|
267
|
-
duration: isNaN(duration) ? 400 : Number(duration),
|
|
268
|
-
showStyle: "fade",
|
|
269
|
-
complete: complete
|
|
270
|
-
});
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
//TYPES:
|
|
274
|
-
dotcss2._Url = function(value){
|
|
275
|
-
this.type = "url";
|
|
276
|
-
this.url = null;
|
|
277
|
-
if(!value || value.length == 0 || (value.length == 1 && value[0] == "" || value[0] == "none" || value[0] == "initial" || value[0] == "inherit")){
|
|
278
|
-
this.url = null;
|
|
279
|
-
}
|
|
280
|
-
else{
|
|
281
|
-
this.url = [];
|
|
282
|
-
for(var i = 0; i < value.length; i++){
|
|
283
|
-
var currentURL = "";
|
|
284
|
-
if(value[i].toLowerCase().indexOf("url") === 0){
|
|
285
|
-
var url = value[i].substring(value[i].indexOf("("), value[i].lastIndexOf(")")).trim();
|
|
286
|
-
if((url.indexOf("\"") && url.lastIndexOf("\"") == url.length - 1) ||
|
|
287
|
-
(url.indexOf("'") && url.lastIndexOf("'") == url.length - 1)){
|
|
288
|
-
url = url.substring(1, url.length - 1);
|
|
289
|
-
}
|
|
290
|
-
this.url.push(url);
|
|
291
|
-
}
|
|
292
|
-
else{
|
|
293
|
-
this.url.push(value[i]);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
dotcss2._Url.prototype.toString = function(){
|
|
300
|
-
if(!this.url) return "none";
|
|
301
|
-
else
|
|
302
|
-
{
|
|
303
|
-
var ret = [];
|
|
304
|
-
for(var i = 0; i < this.url.length; i++){
|
|
305
|
-
ret.push("url(\"" + this.url[i] + "\")");
|
|
306
|
-
}
|
|
307
|
-
return ret.join(", ");
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
dotcss2._Color = function(value){
|
|
312
|
-
this.type = "color";
|
|
313
|
-
this.r = 0;
|
|
314
|
-
this.g = 0;
|
|
315
|
-
this.b = 0;
|
|
316
|
-
this.a = 1;
|
|
317
|
-
if(value.length == 1) {
|
|
318
|
-
value = value[0];
|
|
319
|
-
if(value == "" || value == "none" || value == "initial" || value == "inherit"){} //Nothing more needs to be done.
|
|
320
|
-
else if(!isNaN(value)){
|
|
321
|
-
this.b = value & 0xFF;
|
|
322
|
-
value >>= 8;
|
|
323
|
-
this.g = value & 0xFF;
|
|
324
|
-
value >>= 8;
|
|
325
|
-
this.r = value & 0xFF;
|
|
326
|
-
}
|
|
327
|
-
else if(value[0] == "#"){
|
|
328
|
-
var cH = value.split("#")[1];
|
|
329
|
-
if(cH.length == 3){
|
|
330
|
-
this.r = Number("0x" + cH[0] + "" + cH[0]);
|
|
331
|
-
this.g = Number("0x" + cH[1] + "" + cH[1]);
|
|
332
|
-
this.b = Number("0x" + cH[2] + "" + cH[2]);
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
else if(cH.length == 6){
|
|
336
|
-
this.r = Number("0x" + cH[0] + "" + cH[1]);
|
|
337
|
-
this.g = Number("0x" + cH[2] + "" + cH[3]);
|
|
338
|
-
this.b = Number("0x" + cH[4] + "" + cH[5]);
|
|
339
|
-
}
|
|
340
|
-
//else throw value + " is not a valid color"; //or just stick with black.
|
|
341
|
-
}
|
|
342
|
-
else if(value.toLowerCase().indexOf("rgb") === 0){
|
|
343
|
-
//This also handles rgba.
|
|
344
|
-
var cData = value.split("(")[1];
|
|
345
|
-
cData = cData.split(")")[0];
|
|
346
|
-
cData = cData.split(",");
|
|
347
|
-
if(cData.length == 3 || cData.length == 4){
|
|
348
|
-
this.r = Number(cData[0]);
|
|
349
|
-
this.g = Number(cData[1]);
|
|
350
|
-
this.b = Number(cData[2]);
|
|
351
|
-
this.a = Number(cData[3] || 1);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
else{
|
|
355
|
-
var r = 0;
|
|
356
|
-
var g = 0;
|
|
357
|
-
var b = 0;
|
|
358
|
-
switch(value.toLowerCase()){
|
|
359
|
-
case 'aliceblue':r=0xF0;g=0xF8;b=0xFF;break;
|
|
360
|
-
case 'antiquewhite':r=0xFA;g=0xEB;b=0xD7;break;
|
|
361
|
-
case 'aqua':r=0x00;g=0xFF;b=0xFF;break;
|
|
362
|
-
case 'aquamarine':r=0x7F;g=0xFF;b=0xD4;break;
|
|
363
|
-
case 'azure':r=0xF0;g=0xFF;b=0xFF;break;
|
|
364
|
-
case 'beige':r=0xF5;g=0xF5;b=0xDC;break;
|
|
365
|
-
case 'bisque':r=0xFF;g=0xE4;b=0xC4;break;
|
|
366
|
-
case 'black':r=0x00;g=0x00;b=0x00;break;
|
|
367
|
-
case 'blanchedalmond':r=0xFF;g=0xEB;b=0xCD;break;
|
|
368
|
-
case 'blue':r=0x00;g=0x00;b=0xFF;break;
|
|
369
|
-
case 'blueviolet':r=0x8A;g=0x2B;b=0xE2;break;
|
|
370
|
-
case 'brown':r=0xA5;g=0x2A;b=0x2A;break;
|
|
371
|
-
case 'burlywood':r=0xDE;g=0xB8;b=0x87;break;
|
|
372
|
-
case 'cadetblue':r=0x5F;g=0x9E;b=0xA0;break;
|
|
373
|
-
case 'chartreuse':r=0x7F;g=0xFF;b=0x00;break;
|
|
374
|
-
case 'chocolate':r=0xD2;g=0x69;b=0x1E;break;
|
|
375
|
-
case 'coral':r=0xFF;g=0x7F;b=0x50;break;
|
|
376
|
-
case 'cornflowerblue':r=0x64;g=0x95;b=0xED;break;
|
|
377
|
-
case 'cornsilk':r=0xFF;g=0xF8;b=0xDC;break;
|
|
378
|
-
case 'crimson':r=0xDC;g=0x14;b=0x3C;break;
|
|
379
|
-
case 'cyan':r=0x00;g=0xFF;b=0xFF;break;
|
|
380
|
-
case 'darkblue':r=0x00;g=0x00;b=0x8B;break;
|
|
381
|
-
case 'darkcyan':r=0x00;g=0x8B;b=0x8B;break;
|
|
382
|
-
case 'darkgoldenrod':r=0xB8;g=0x86;b=0x0B;break;
|
|
383
|
-
case 'darkgray':r=0xA9;g=0xA9;b=0xA9;break;
|
|
384
|
-
case 'darkgrey':r=0xA9;g=0xA9;b=0xA9;break;
|
|
385
|
-
case 'darkgreen':r=0x00;g=0x64;b=0x00;break;
|
|
386
|
-
case 'darkkhaki':r=0xBD;g=0xB7;b=0x6B;break;
|
|
387
|
-
case 'darkmagenta':r=0x8B;g=0x00;b=0x8B;break;
|
|
388
|
-
case 'darkolivegreen':r=0x55;g=0x6B;b=0x2F;break;
|
|
389
|
-
case 'darkorange':r=0xFF;g=0x8C;b=0x00;break;
|
|
390
|
-
case 'darkorchid':r=0x99;g=0x32;b=0xCC;break;
|
|
391
|
-
case 'darkred':r=0x8B;g=0x00;b=0x00;break;
|
|
392
|
-
case 'darksalmon':r=0xE9;g=0x96;b=0x7A;break;
|
|
393
|
-
case 'darkseagreen':r=0x8F;g=0xBC;b=0x8F;break;
|
|
394
|
-
case 'darkslateblue':r=0x48;g=0x3D;b=0x8B;break;
|
|
395
|
-
case 'darkslategray':r=0x2F;g=0x4F;b=0x4F;break;
|
|
396
|
-
case 'darkslategrey':r=0x2F;g=0x4F;b=0x4F;break;
|
|
397
|
-
case 'darkturquoise':r=0x00;g=0xCE;b=0xD1;break;
|
|
398
|
-
case 'darkviolet':r=0x94;g=0x00;b=0xD3;break;
|
|
399
|
-
case 'deeppink':r=0xFF;g=0x14;b=0x93;break;
|
|
400
|
-
case 'deepskyblue':r=0x00;g=0xBF;b=0xFF;break;
|
|
401
|
-
case 'dimgray':r=0x69;g=0x69;b=0x69;break;
|
|
402
|
-
case 'dimgrey':r=0x69;g=0x69;b=0x69;break;
|
|
403
|
-
case 'dodgerblue':r=0x1E;g=0x90;b=0xFF;break;
|
|
404
|
-
case 'firebrick':r=0xB2;g=0x22;b=0x22;break;
|
|
405
|
-
case 'floralwhite':r=0xFF;g=0xFA;b=0xF0;break;
|
|
406
|
-
case 'forestgreen':r=0x22;g=0x8B;b=0x22;break;
|
|
407
|
-
case 'fuchsia':r=0xFF;g=0x00;b=0xFF;break;
|
|
408
|
-
case 'gainsboro':r=0xDC;g=0xDC;b=0xDC;break;
|
|
409
|
-
case 'ghostwhite':r=0xF8;g=0xF8;b=0xFF;break;
|
|
410
|
-
case 'gold':r=0xFF;g=0xD7;b=0x00;break;
|
|
411
|
-
case 'goldenrod':r=0xDA;g=0xA5;b=0x20;break;
|
|
412
|
-
case 'gray':r=0x80;g=0x80;b=0x80;break;
|
|
413
|
-
case 'grey':r=0x80;g=0x80;b=0x80;break;
|
|
414
|
-
case 'green':r=0x00;g=0x80;b=0x00;break;
|
|
415
|
-
case 'greenyellow':r=0xAD;g=0xFF;b=0x2F;break;
|
|
416
|
-
case 'honeydew':r=0xF0;g=0xFF;b=0xF0;break;
|
|
417
|
-
case 'hotpink':r=0xFF;g=0x69;b=0xB4;break;
|
|
418
|
-
case 'indianred':r=0xCD;g=0x5C;b=0x5C;break;
|
|
419
|
-
case 'indigo':r=0x4B;g=0x00;b=0x82;break;
|
|
420
|
-
case 'ivory':r=0xFF;g=0xFF;b=0xF0;break;
|
|
421
|
-
case 'khaki':r=0xF0;g=0xE6;b=0x8C;break;
|
|
422
|
-
case 'lavender':r=0xE6;g=0xE6;b=0xFA;break;
|
|
423
|
-
case 'lavenderblush':r=0xFF;g=0xF0;b=0xF5;break;
|
|
424
|
-
case 'lawngreen':r=0x7C;g=0xFC;b=0x00;break;
|
|
425
|
-
case 'lemonchiffon':r=0xFF;g=0xFA;b=0xCD;break;
|
|
426
|
-
case 'lightblue':r=0xAD;g=0xD8;b=0xE6;break;
|
|
427
|
-
case 'lightcoral':r=0xF0;g=0x80;b=0x80;break;
|
|
428
|
-
case 'lightcyan':r=0xE0;g=0xFF;b=0xFF;break;
|
|
429
|
-
case 'lightgoldenrodyellow':r=0xFA;g=0xFA;b=0xD2;break;
|
|
430
|
-
case 'lightgray':r=0xD3;g=0xD3;b=0xD3;break;
|
|
431
|
-
case 'lightgrey':r=0xD3;g=0xD3;b=0xD3;break;
|
|
432
|
-
case 'lightgreen':r=0x90;g=0xEE;b=0x90;break;
|
|
433
|
-
case 'lightpink':r=0xFF;g=0xB6;b=0xC1;break;
|
|
434
|
-
case 'lightsalmon':r=0xFF;g=0xA0;b=0x7A;break;
|
|
435
|
-
case 'lightseagreen':r=0x20;g=0xB2;b=0xAA;break;
|
|
436
|
-
case 'lightskyblue':r=0x87;g=0xCE;b=0xFA;break;
|
|
437
|
-
case 'lightslategray':r=0x77;g=0x88;b=0x99;break;
|
|
438
|
-
case 'lightslategrey':r=0x77;g=0x88;b=0x99;break;
|
|
439
|
-
case 'lightsteelblue':r=0xB0;g=0xC4;b=0xDE;break;
|
|
440
|
-
case 'lightyellow':r=0xFF;g=0xFF;b=0xE0;break;
|
|
441
|
-
case 'lime':r=0x00;g=0xFF;b=0x00;break;
|
|
442
|
-
case 'limegreen':r=0x32;g=0xCD;b=0x32;break;
|
|
443
|
-
case 'linen':r=0xFA;g=0xF0;b=0xE6;break;
|
|
444
|
-
case 'magenta':r=0xFF;g=0x00;b=0xFF;break;
|
|
445
|
-
case 'maroon':r=0x80;g=0x00;b=0x00;break;
|
|
446
|
-
case 'mediumaquamarine':r=0x66;g=0xCD;b=0xAA;break;
|
|
447
|
-
case 'mediumblue':r=0x00;g=0x00;b=0xCD;break;
|
|
448
|
-
case 'mediumorchid':r=0xBA;g=0x55;b=0xD3;break;
|
|
449
|
-
case 'mediumpurple':r=0x93;g=0x70;b=0xDB;break;
|
|
450
|
-
case 'mediumseagreen':r=0x3C;g=0xB3;b=0x71;break;
|
|
451
|
-
case 'mediumslateblue':r=0x7B;g=0x68;b=0xEE;break;
|
|
452
|
-
case 'mediumspringgreen':r=0x00;g=0xFA;b=0x9A;break;
|
|
453
|
-
case 'mediumturquoise':r=0x48;g=0xD1;b=0xCC;break;
|
|
454
|
-
case 'mediumvioletred':r=0xC7;g=0x15;b=0x85;break;
|
|
455
|
-
case 'midnightblue':r=0x19;g=0x19;b=0x70;break;
|
|
456
|
-
case 'mintcream':r=0xF5;g=0xFF;b=0xFA;break;
|
|
457
|
-
case 'mistyrose':r=0xFF;g=0xE4;b=0xE1;break;
|
|
458
|
-
case 'moccasin':r=0xFF;g=0xE4;b=0xB5;break;
|
|
459
|
-
case 'navajowhite':r=0xFF;g=0xDE;b=0xAD;break;
|
|
460
|
-
case 'navy':r=0x00;g=0x00;b=0x80;break;
|
|
461
|
-
case 'oldlace':r=0xFD;g=0xF5;b=0xE6;break;
|
|
462
|
-
case 'olive':r=0x80;g=0x80;b=0x00;break;
|
|
463
|
-
case 'olivedrab':r=0x6B;g=0x8E;b=0x23;break;
|
|
464
|
-
case 'orange':r=0xFF;g=0xA5;b=0x00;break;
|
|
465
|
-
case 'orangered':r=0xFF;g=0x45;b=0x00;break;
|
|
466
|
-
case 'orchid':r=0xDA;g=0x70;b=0xD6;break;
|
|
467
|
-
case 'palegoldenrod':r=0xEE;g=0xE8;b=0xAA;break;
|
|
468
|
-
case 'palegreen':r=0x98;g=0xFB;b=0x98;break;
|
|
469
|
-
case 'paleturquoise':r=0xAF;g=0xEE;b=0xEE;break;
|
|
470
|
-
case 'palevioletred':r=0xDB;g=0x70;b=0x93;break;
|
|
471
|
-
case 'papayawhip':r=0xFF;g=0xEF;b=0xD5;break;
|
|
472
|
-
case 'peachpuff':r=0xFF;g=0xDA;b=0xB9;break;
|
|
473
|
-
case 'peru':r=0xCD;g=0x85;b=0x3F;break;
|
|
474
|
-
case 'pink':r=0xFF;g=0xC0;b=0xCB;break;
|
|
475
|
-
case 'plum':r=0xDD;g=0xA0;b=0xDD;break;
|
|
476
|
-
case 'powderblue':r=0xB0;g=0xE0;b=0xE6;break;
|
|
477
|
-
case 'purple':r=0x80;g=0x00;b=0x80;break;
|
|
478
|
-
case 'rebeccapurple':r=0x66;g=0x33;b=0x99;break;
|
|
479
|
-
case 'red':r=0xFF;g=0x00;b=0x00;break;
|
|
480
|
-
case 'rosybrown':r=0xBC;g=0x8F;b=0x8F;break;
|
|
481
|
-
case 'royalblue':r=0x41;g=0x69;b=0xE1;break;
|
|
482
|
-
case 'saddlebrown':r=0x8B;g=0x45;b=0x13;break;
|
|
483
|
-
case 'salmon':r=0xFA;g=0x80;b=0x72;break;
|
|
484
|
-
case 'sandybrown':r=0xF4;g=0xA4;b=0x60;break;
|
|
485
|
-
case 'seagreen':r=0x2E;g=0x8B;b=0x57;break;
|
|
486
|
-
case 'seashell':r=0xFF;g=0xF5;b=0xEE;break;
|
|
487
|
-
case 'sienna':r=0xA0;g=0x52;b=0x2D;break;
|
|
488
|
-
case 'silver':r=0xC0;g=0xC0;b=0xC0;break;
|
|
489
|
-
case 'skyblue':r=0x87;g=0xCE;b=0xEB;break;
|
|
490
|
-
case 'slateblue':r=0x6A;g=0x5A;b=0xCD;break;
|
|
491
|
-
case 'slategray':r=0x70;g=0x80;b=0x90;break;
|
|
492
|
-
case 'slategrey':r=0x70;g=0x80;b=0x90;break;
|
|
493
|
-
case 'snow':r=0xFF;g=0xFA;b=0xFA;break;
|
|
494
|
-
case 'springgreen':r=0x00;g=0xFF;b=0x7F;break;
|
|
495
|
-
case 'steelblue':r=0x46;g=0x82;b=0xB4;break;
|
|
496
|
-
case 'tan':r=0xD2;g=0xB4;b=0x8C;break;
|
|
497
|
-
case 'teal':r=0x00;g=0x80;b=0x80;break;
|
|
498
|
-
case 'thistle':r=0xD8;g=0xBF;b=0xD8;break;
|
|
499
|
-
case 'tomato':r=0xFF;g=0x63;b=0x47;break;
|
|
500
|
-
case 'turquoise':r=0x40;g=0xE0;b=0xD0;break;
|
|
501
|
-
case 'violet':r=0xEE;g=0x82;b=0xEE;break;
|
|
502
|
-
case 'wheat':r=0xF5;g=0xDE;b=0xB3;break;
|
|
503
|
-
case 'white':r=0xFF;g=0xFF;b=0xFF;break;
|
|
504
|
-
case 'whitesmoke':r=0xF5;g=0xF5;b=0xF5;break;
|
|
505
|
-
case 'yellow':r=0xFF;g=0xFF;b=0x00;break;
|
|
506
|
-
case 'yellowgreen':r=0x9A;g=0xCD;b=0x32;break;
|
|
507
|
-
}
|
|
508
|
-
this.r = r;
|
|
509
|
-
this.g = g;
|
|
510
|
-
this.b = b;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
else if(value.length == 3 || value.length == 4){
|
|
514
|
-
this.r = value[0];
|
|
515
|
-
this.g = value[1];
|
|
516
|
-
this.b = value[2];
|
|
517
|
-
if(value.length == 4){
|
|
518
|
-
this.a = value[3];
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
dotcss2._Color.prototype.toString = function(){
|
|
525
|
-
var R = Math.round;
|
|
526
|
-
var X = Math.max;
|
|
527
|
-
var N = Math.min;
|
|
528
|
-
if(this.a == 1)
|
|
529
|
-
return "rgb(" + N(255, X(0, R(this.r))) + ", " + N(255, X(0, R(this.g))) + ", " + N(255, X(0, R(this.b))) + ")";
|
|
530
|
-
else
|
|
531
|
-
return "rgba(" + N(255, X(0, R(this.r))) + ", " + N(255, X(0, R(this.g))) + ", " + N(255, X(0, R(this.b))) + ", " + N(1, X(0, this.a)) + ")";
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
//TODO: this should support multiple lengths.
|
|
535
|
-
dotcss2._Length = function(value){
|
|
536
|
-
value = value || "0px";
|
|
537
|
-
if(!isNaN(value)) value = Math.round(value) + "px";
|
|
538
|
-
this.type = "length";
|
|
539
|
-
this.length = Number(value.match(dotcss2._floatRegex)[0]);
|
|
540
|
-
this.units = value.split(dotcss2._floatRegex)[1] || "px";
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
dotcss2._Length.prototype.toString = function(){
|
|
544
|
-
return this.length + this.units;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
dotcss2._Angle = function(value){
|
|
548
|
-
value = value || "0deg";
|
|
549
|
-
if(!isNaN(value)) value = Math.round(value) + "px";
|
|
550
|
-
this.type = "angle";
|
|
551
|
-
this.angle = Number(value.match(dotcss2._floatRegex)[0]);
|
|
552
|
-
this.units = value.split(dotcss2._floatRegex)[1] || "deg";
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
dotcss2._Angle.prototype.toString = function(){
|
|
556
|
-
return this.angle + this.units;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
dotcss2._Transform = function(value){
|
|
560
|
-
this.type = "transformation";
|
|
561
|
-
this.transformations = [];
|
|
562
|
-
//this.finalMatrix = [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];
|
|
563
|
-
if(value == "" || value == "none" || value == "initial" || value == "inherit" || ("" + value).indexOf("(") == -1){
|
|
564
|
-
//this.value = "matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)";
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
//var ret = {value: value, type: cssDataType};
|
|
568
|
-
var transformations = value.split(/\)\s*/); transformations.pop(); for(var i = 0; i < transformations.length; i++) transformations[i] += ")";
|
|
569
|
-
var cos = Math.cos; var sin = Math.sin; var tan = Math.tan;
|
|
570
|
-
for(var t = 0; t < transformations.length; t++){
|
|
571
|
-
var trans = transformations[t].trim();
|
|
572
|
-
var parts = trans.split(/[\(\)]/);
|
|
573
|
-
var func = parts[0]
|
|
574
|
-
var p = parts[1].split(/\s*,\s*/)
|
|
575
|
-
|
|
576
|
-
if(this[func]){
|
|
577
|
-
this[func].apply(this, p);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
dotcss2._Transform.prototype.toString = function(){
|
|
583
|
-
var ret = "";
|
|
584
|
-
for(var i = 0; i < this.transformations.length; i++){
|
|
585
|
-
var t = this.transformations[i];
|
|
586
|
-
ret += t.transformation + "(";
|
|
587
|
-
for(var k = 0; k < t.args.length; k++){
|
|
588
|
-
ret += t.args[k] + ",";
|
|
589
|
-
}
|
|
590
|
-
ret = ret.substring(0, ret.length - 1);
|
|
591
|
-
ret += ") ";
|
|
592
|
-
}
|
|
593
|
-
return ret.trim();
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
dotcss2._Transform.prototype._updateValue = function(transformation, args){
|
|
597
|
-
//this.finalMatrix = dotcss.matrixMultiply3D(m, this.finalMatrix);
|
|
598
|
-
this.transformations.push({transformation: transformation, args: args});
|
|
599
|
-
/*if(this.value.length > 0) this.value += " ";
|
|
600
|
-
this.value += transformation + "(";
|
|
601
|
-
for(var i = 0; i < args.length; i++){
|
|
602
|
-
this.value += args[i] + (i == args.length -1 ? "" : ",")
|
|
603
|
-
}*/
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
dotcss2._Transform.prototype.matrix3d = function(...value: Array<number>){
|
|
607
|
-
var p = value;
|
|
608
|
-
if(p.length == 16){
|
|
609
|
-
this.finalMatrix = dotcss.matrixMultiply3D(p, this.finalMatrix);
|
|
610
|
-
this._updateValue("matrix3d", p);
|
|
611
|
-
}
|
|
612
|
-
else throw "matrix3d requires 16 parameters.";
|
|
613
|
-
return this;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
dotcss2._Transform.prototype.matrix = function(...value: Array<number>){
|
|
617
|
-
var p = value;
|
|
618
|
-
if(p.length == 6){
|
|
619
|
-
this._updateValue("matrix", p/*, [p[0], p[1], 0, 0, p[2], p[3], 0, 0, 0, 0, 1, 0, p[4], p[5], 0, 1]*/);
|
|
620
|
-
}
|
|
621
|
-
else if(p.length == 16){
|
|
622
|
-
this.matrix3d.apply(this, p);
|
|
623
|
-
}
|
|
624
|
-
else throw "matrix requires 6 parameters.";
|
|
625
|
-
return this;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
dotcss2._Transform.prototype.translate = function(){
|
|
629
|
-
var p = arguments;
|
|
630
|
-
if(p.length == 1){
|
|
631
|
-
var x = dotcss.lengthToPx(p[0]);
|
|
632
|
-
this._updateValue("translate", [new dotcss2._Length(x + "px")]/*, [1,0,0,0,0,1,0,0,0,0,1,0,x,0,0,1]*/);
|
|
633
|
-
}
|
|
634
|
-
else if(p.length == 2){
|
|
635
|
-
var x = dotcss.lengthToPx(p[0]);
|
|
636
|
-
var y = dotcss.lengthToPx(p[1]);
|
|
637
|
-
this._updateValue("translate", [new dotcss2._Length(x + "px"), new dotcss2._Length(y + "px")]/*, [1,0,0,0,0,1,0,0,0,0,1,0,x,y,0,1]*/);
|
|
638
|
-
}
|
|
639
|
-
else if(p.length == 3) this.translate3d.apply(this, p);
|
|
640
|
-
else throw "translate requires 1 or 2 parameters.";
|
|
641
|
-
return this;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
dotcss2._Transform.prototype.translate3d = function(){
|
|
645
|
-
var p = arguments;
|
|
646
|
-
if(p.length == 3){
|
|
647
|
-
var x = dotcss.lengthToPx(p[0]);
|
|
648
|
-
var y = dotcss.lengthToPx(p[1]);
|
|
649
|
-
var z = dotcss.lengthToPx(p[2]);
|
|
650
|
-
this._updateValue("translate3d", [new dotcss2._Length(x + "px"), new dotcss2._Length(y + "px"), new dotcss2._Length(z + "px")]/*, [1,0,0,0,0,1,0,0,0,0,1,0,x,y,z,1]*/);
|
|
651
|
-
}
|
|
652
|
-
else throw "translate3d requires 3 parameters.";
|
|
653
|
-
return this;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
dotcss2._Transform.prototype.translateX = function(){
|
|
657
|
-
var p = arguments;
|
|
658
|
-
if(p.length == 1){
|
|
659
|
-
//var x = dotcss.lengthToPx(p[0]);
|
|
660
|
-
//this._updateValue("translateX", [new dotcss2._Length(x + "px")]/*, [1,0,0,0,0,1,0,0,0,0,1,0,x,0,0,1]*/);
|
|
661
|
-
this.translate(p[0], 0);
|
|
662
|
-
}
|
|
663
|
-
else throw "translateX requires 1 parameter.";
|
|
664
|
-
return this;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
dotcss2._Transform.prototype.translateY = function(){
|
|
668
|
-
var p = arguments;
|
|
669
|
-
if(p.length == 1){
|
|
670
|
-
//var y = dotcss.lengthToPx(p[0]);
|
|
671
|
-
//this._updateValue("translateY", [new dotcss2._Length(y + "px")]/*, [1,0,0,0,0,1,0,0,0,0,1,0,0,y,0,1]*/);
|
|
672
|
-
this.translate(0, p[0]);
|
|
673
|
-
}
|
|
674
|
-
else throw "translateY requires 1 parameter.";
|
|
675
|
-
return this;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
dotcss2._Transform.prototype.translateZ = function(){
|
|
679
|
-
var p = arguments;
|
|
680
|
-
if(p.length == 1){
|
|
681
|
-
//var z = dotcss.lengthToPx(p[0]);
|
|
682
|
-
//this._updateValue("translateZ", [new dotcss2._Length(z + "px")]/*, [1,0,0,0,0,1,0,0,0,0,1,0,0,0,z,1]*/);
|
|
683
|
-
this.translate3d(0, 0, p[0]);
|
|
684
|
-
}
|
|
685
|
-
else throw "translateZ requires 1 parameter.";
|
|
686
|
-
return this;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
dotcss2._Transform.prototype.scale = function(){
|
|
690
|
-
var p = arguments;
|
|
691
|
-
if(p.length == 2){
|
|
692
|
-
this._updateValue("scale", p/*, [p[0],0,0,0,0,p[1],0,0,0,0,1,0,0,0,0,1]*/);
|
|
693
|
-
}
|
|
694
|
-
else if(p.length == 3) this.scale3d.apply(this, p)
|
|
695
|
-
else throw "scale requires 2 parameters.";
|
|
696
|
-
return this;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
dotcss2._Transform.prototype.scale3d = function(){
|
|
700
|
-
var p = arguments;
|
|
701
|
-
if(p.length == 3){
|
|
702
|
-
this._updateValue("scale3d", p/*, [p[0],0,0,0,0,p[1],0,0,0,0,p[2],0,0,0,0,1]*/);
|
|
703
|
-
}
|
|
704
|
-
else throw "scale3d requires 3 parameters.";
|
|
705
|
-
return this;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
dotcss2._Transform.prototype.scaleX = function(){
|
|
709
|
-
var p = arguments;
|
|
710
|
-
if(p.length == 1){
|
|
711
|
-
//this._updateValue("scaleX", p/*, [p[0],0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]*/);
|
|
712
|
-
this.scale(p[0],1);
|
|
713
|
-
}
|
|
714
|
-
else throw "scaleX requires 1 parameter.";
|
|
715
|
-
return this;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
dotcss2._Transform.prototype.scaleY = function(){
|
|
719
|
-
var p = arguments;
|
|
720
|
-
if(p.length == 1){
|
|
721
|
-
//this._updateValue("scaleY", p/*, [1,0,0,0,0,p[0],0,0,0,0,1,0,0,0,0,1]*/);
|
|
722
|
-
this.scale(1,p[0]);
|
|
723
|
-
}
|
|
724
|
-
else throw "scaleY requires 1 parameter.";
|
|
725
|
-
return this;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
dotcss2._Transform.prototype.scaleZ = function(){
|
|
729
|
-
var p = arguments;
|
|
730
|
-
if(p.length == 1){
|
|
731
|
-
//this._updateValue("scaleZ", p/*, [1,0,0,0,0,1,0,0,0,0,p[0],0,0,0,0,1]*/);
|
|
732
|
-
this.scale3d(1,1,p[0]);
|
|
733
|
-
}
|
|
734
|
-
else throw "scaleZ requires 1 parameter.";
|
|
735
|
-
return this;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
dotcss2._Transform.prototype.rotate = function(){
|
|
739
|
-
var p = arguments;
|
|
740
|
-
if(p.length == 1){
|
|
741
|
-
var a = dotcss.angleToDeg(p[0]);
|
|
742
|
-
this._updateValue("rotate", [new dotcss2._Angle(a + "deg")]/*, [Math.cos(a),Math.sin(a),0,0,-Math.sin(axxx),Math.cos(axxx),0,0,0,0,1,0,0,0,0,1]*/);
|
|
743
|
-
}
|
|
744
|
-
else throw "scaleZ requires 1 parameter.";
|
|
745
|
-
return this;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
dotcss2._Transform.prototype.rotate3d = function(){
|
|
749
|
-
var p = arguments;
|
|
750
|
-
if(p.length == 4){
|
|
751
|
-
var x = p[0];
|
|
752
|
-
var y = p[1];
|
|
753
|
-
var z = p[2];
|
|
754
|
-
var a = dotcss.angleToDeg(p[3]);
|
|
755
|
-
/*var C = 1 - cos(axx);
|
|
756
|
-
var S = sin(axx);*/
|
|
757
|
-
this._updateValue("rotate3d", [x, y, z, new dotcss2._Angle(a + "deg")]/*,
|
|
758
|
-
[1+C*(x*x-1), z*S+x*y*C, -y*S+x*z*C, 0,
|
|
759
|
-
-z*S+x*y*C, 1+C*(y*y-1), x*S+y*z*C, 0,
|
|
760
|
-
y*S+x*z*C, -x*S+y*z*C, 1+C*(z*z-1), 0,
|
|
761
|
-
0, 0, 0, 1]*/
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
else throw "rotate3d requires 4 parameters.";
|
|
765
|
-
return this;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
dotcss2._Transform.prototype.rotateX = function(){
|
|
769
|
-
var p = arguments;
|
|
770
|
-
if(p.length == 1){
|
|
771
|
-
var a = dotcss.angleToDeg(p[0]);
|
|
772
|
-
this._updateValue("rotateX", [new dotcss2._Angle(a + "deg")]/*, [1,0,0,0,0,Math.cos(axx),Math.sin(axx),0,0,-Math.sin(axx),Math.cos(axx),0,0,0,0,1]*/);
|
|
773
|
-
//this.rotate3d(1, 0, 0, p[0]);
|
|
774
|
-
}
|
|
775
|
-
else throw "rotateX requires 1 parameter.";
|
|
776
|
-
return this;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
dotcss2._Transform.prototype.rotateY = function(){
|
|
780
|
-
var p = arguments;
|
|
781
|
-
if(p.length == 1){
|
|
782
|
-
//this might be faster:
|
|
783
|
-
var a = dotcss.angleToDeg(p[0]);
|
|
784
|
-
this._updateValue("rotateY", [new dotcss2._Angle(a + "deg")]/*, [Math.cos(xxa),0,-Math.sin(axxx),0,0,1,0,0,Math.sin(xxx),0,Math.cos(xxx),0,0,0,0,1]*/);
|
|
785
|
-
//this.rotate3d(0, 1, 0, p[0]);
|
|
786
|
-
}
|
|
787
|
-
else throw "rotateY requires 1 parameter.";
|
|
788
|
-
return this;
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
dotcss2._Transform.prototype.rotateZ = function(){
|
|
792
|
-
this.rotate.apply(this, arguments);
|
|
793
|
-
return this;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
dotcss2._Transform.prototype.skew = function(){
|
|
797
|
-
var p = arguments;
|
|
798
|
-
if(p.length == 1){
|
|
799
|
-
var ax = dotcss.angleToDeg(p[0]);
|
|
800
|
-
this._updateValue("skew", [new dotcss2._Angle(ax + "deg")]/*, [1,0,0,0,Math.tan(axxxxx),1,0,0,0,0,1,0,0,0,0,1]*/);
|
|
801
|
-
}
|
|
802
|
-
else if(p.length == 2){
|
|
803
|
-
var ax = dotcss.angleToDeg(p[0]);
|
|
804
|
-
var ay = dotcss.angleToDeg(p[1]);
|
|
805
|
-
this._updateValue("skew", [new dotcss2._Angle(ax + "deg"), new dotcss2._Angle(ay + "deg")]/*, [1,Math.tan(axxxy),0,0,Math.tan(axxxx),1,0,0,0,0,1,0,0,0,0,1]*/);
|
|
806
|
-
}
|
|
807
|
-
else throw "skew requires 1 or 2 parameters.";
|
|
808
|
-
return this;
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
dotcss2._Transform.prototype.skewX = function(){
|
|
812
|
-
var p = arguments;
|
|
813
|
-
if(p.length == 1) this.skew.apply(this, p) //Makes things easier.
|
|
814
|
-
else throw "skewX requires 1 parameter.";
|
|
815
|
-
return this;
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
dotcss2._Transform.prototype.skewY = function(){
|
|
819
|
-
var p = arguments;
|
|
820
|
-
if(p.length == 1) this.skew.apply(this, [0, p[0]]) //Makes things easier.
|
|
821
|
-
else throw "skewY requires 1 parameter.";
|
|
822
|
-
return this;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
dotcss2._Transform.prototype.perspective = function(){
|
|
826
|
-
var p = arguments;
|
|
827
|
-
if(p.length == 1){
|
|
828
|
-
var d = dotcss.lengthToPx(p[0]);
|
|
829
|
-
this._updateValue("perspective", [new dotcss2._Length(d + "px")]/*, [1,0,0,0,0,1,0,0,0,0,1,0,0,0,dotcss.formatNumberValue(-1 / d),1]*/);
|
|
830
|
-
}
|
|
831
|
-
else throw "perspective requires 1 parameter.";
|
|
832
|
-
return this;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
dotcss2._Complex = function(value){
|
|
836
|
-
this.type = "complex";
|
|
837
|
-
this.parts = (" " + value + " ").split(dotcss2._floatRegex);
|
|
838
|
-
this.numbers = value.match(dotcss2._floatRegex);
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
dotcss2._Complex.prototype.toString = function(){
|
|
842
|
-
var ret = this.parts[0];
|
|
843
|
-
for(var i = 0; i < this.numbers.length; i++){
|
|
844
|
-
ret += this.numbers[i] + this.parts[i+1];
|
|
845
|
-
}
|
|
846
|
-
return ret;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
dotcss2._Number = function(value){
|
|
850
|
-
this.type = "number";
|
|
851
|
-
this.value = Number(value);
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
dotcss2._Number.prototype.toString = function(){
|
|
855
|
-
return this.value;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
dotcss2._Unknown = function(value){
|
|
859
|
-
this.type = "unknown";
|
|
860
|
-
this.value = value;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
dotcss2._Unknown.prototype.toString = function(){
|
|
864
|
-
return this.value;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
function _StyleProperty(){
|
|
868
|
-
this.type = null;
|
|
869
|
-
this.jsFriendlyProp = null;
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
//toString override gets the value.
|
|
873
|
-
_StyleProperty.prototype.toString = function(){
|
|
874
|
-
if(dotcss2._lastBuilder.target){
|
|
875
|
-
var ret = null;
|
|
876
|
-
if(dotcss2._lastBuilder.target.length > 1){
|
|
877
|
-
ret = [];
|
|
878
|
-
for(var i = 0; i < dotcss2._lastBuilder.target.length; i++){
|
|
879
|
-
ret.push(dotcss2._lastBuilder.target[i].style[this.jsFriendlyProp]);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
else ret = dotcss2._lastBuilder.target[0].style[this.jsFriendlyProp];
|
|
883
|
-
return ret;
|
|
884
|
-
}
|
|
885
|
-
else return null;
|
|
886
|
-
};
|
|
887
|
-
|
|
888
|
-
//val is another special function that breaks the value into a special object.
|
|
889
|
-
_StyleProperty.prototype.val = function(){
|
|
890
|
-
if(dotcss2._lastBuilder.target){
|
|
891
|
-
var ret = null;
|
|
892
|
-
if(dotcss2._lastBuilder.target.length > 1){
|
|
893
|
-
ret = null;
|
|
894
|
-
for(var i = 0; i < dotcss2._lastBuilder.target.length; i++){
|
|
895
|
-
if(dotcss2._lastBuilder.target[0].style[this.jsFriendlyProp]){
|
|
896
|
-
ret.push(dotcss2._convertStyleIntoDotCssObject(dotcss2._lastBuilder.target[i].style[this.jsFriendlyProp], this.type));
|
|
897
|
-
}
|
|
898
|
-
else ret.push(null);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
else{
|
|
902
|
-
if(dotcss2._lastBuilder.target[0].style[this.jsFriendlyProp]){
|
|
903
|
-
ret = dotcss2._convertStyleIntoDotCssObject(dotcss2._lastBuilder.target[0].style[this.jsFriendlyProp], this.type)
|
|
904
|
-
}
|
|
905
|
-
else ret = null;
|
|
906
|
-
}
|
|
907
|
-
return ret;
|
|
908
|
-
}
|
|
909
|
-
else return null;
|
|
910
|
-
};
|
|
911
|
-
|
|
912
|
-
//Ability to animate just like jquery.
|
|
913
|
-
//complete does not get called if the animation was cancelled.
|
|
914
|
-
_StyleProperty.prototype.animate = function(value, duration, style, complete){
|
|
915
|
-
duration = isNaN(duration) ? 400 : (duration || 0);
|
|
916
|
-
if(dotcss2._lastBuilder && dotcss2._lastBuilder.target){
|
|
917
|
-
if(!complete && style && style.call && style.apply){ //Fix params.
|
|
918
|
-
complete = style;
|
|
919
|
-
style = undefined;
|
|
920
|
-
}
|
|
921
|
-
for(var i = 0; i < dotcss2._lastBuilder.target.length; i++){
|
|
922
|
-
var target = dotcss2._lastBuilder.target[i];
|
|
923
|
-
var oldValue = null;
|
|
924
|
-
var newValue = null;
|
|
925
|
-
var finalValue = null; //newValue might be in different units from the final value...
|
|
926
|
-
|
|
927
|
-
//Get the old and new values.
|
|
928
|
-
newValue = dotcss2._convertStyleIntoDotCssObject(value, this.type);
|
|
929
|
-
|
|
930
|
-
//If it's a transformation, a little extra work is required.
|
|
931
|
-
//Need to frame all the rotations properly, and combine both the new and the old transformations.
|
|
932
|
-
if(this.type == "transformation"){
|
|
933
|
-
//Special handling. We'd like to consider the transformation as a complex data type first, then if that's not possible, convert it into a matrix data type.
|
|
934
|
-
//Reason being: linear transformations on matrices are inaccurate. Rotations end up scaling the target.
|
|
935
|
-
//Don't want to get the computed value for transformations.
|
|
936
|
-
oldValue = dotcss2._convertStyleIntoDotCssObject(target.style[this.jsFriendlyProp], this.type);
|
|
937
|
-
}
|
|
938
|
-
if(!oldValue){ //Standard. Happens when the type is not a transformation.
|
|
939
|
-
oldValue = dotcss2._convertStyleIntoDotCssObject(dotcss2._computedStyleOrActualStyle(target, this.jsFriendlyProp), this.type);
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
finalValue = newValue.toString();
|
|
943
|
-
|
|
944
|
-
//Do a little type/unit checking.
|
|
945
|
-
|
|
946
|
-
if(this.type == "length"){
|
|
947
|
-
if(oldValue.units != newValue.units){
|
|
948
|
-
//Need to rectify this.
|
|
949
|
-
//This can get messy. If one of the lengths is zero, it would minimize the likelihood of an error.
|
|
950
|
-
if(oldValue.length == 0){
|
|
951
|
-
oldValue.units = newValue.units;
|
|
952
|
-
oldValue.length = 0;
|
|
953
|
-
}
|
|
954
|
-
else if(newValue.length == 0){
|
|
955
|
-
newValue.units = oldValue.units;
|
|
956
|
-
newValue.length = 0;
|
|
957
|
-
}
|
|
958
|
-
else{
|
|
959
|
-
//Things are messy. Try to mitigate. Convert the old value into the new units, as best we can.
|
|
960
|
-
var currentLengthPx = dotcss.lengthToPx(oldValue.toString(), this.jsFriendlyProp, target);
|
|
961
|
-
var newLengthPx = dotcss.lengthToPx(newValue.toString(), this.jsFriendlyProp, target);
|
|
962
|
-
oldValue.length = currentLengthPx;
|
|
963
|
-
oldValue.units = "px";
|
|
964
|
-
newValue.length = newLengthPx;
|
|
965
|
-
newValue.units = "px";
|
|
966
|
-
|
|
967
|
-
//Won't need this anymore.
|
|
968
|
-
//console.warn("Couldn't animate " + this.jsFriendlyProp + ". Inconsistent units.");
|
|
969
|
-
//return dotcss2._lastBuilder;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
else if(this.type == "color"){} //OK
|
|
974
|
-
else if(this.type == "transformation"){
|
|
975
|
-
//Couple things to do here.
|
|
976
|
-
//1. The old and new values must contain the exact same transformation template.
|
|
977
|
-
//2. Angles in the old transformation should be reframed so that they are close to the new angles (or should they)
|
|
978
|
-
|
|
979
|
-
var startTransform = "";
|
|
980
|
-
var desiredTransform = "";
|
|
981
|
-
var oldIndex = oldValue.transformations.length - 1;
|
|
982
|
-
var newIndex = newValue.transformations.length - 1;
|
|
983
|
-
while(oldIndex >= 0 || newIndex >= 0){
|
|
984
|
-
var transformToAdd = "";
|
|
985
|
-
var oldTransformValues = null;
|
|
986
|
-
var newTransformValues = null;
|
|
987
|
-
if(oldIndex >= 0 && newIndex >= 0 && oldValue.transformations[oldIndex].transformation == newValue.transformations[newIndex].transformation){
|
|
988
|
-
var currentOldT = oldValue.transformations[oldIndex];
|
|
989
|
-
var currentNewT = newValue.transformations[newIndex];
|
|
990
|
-
|
|
991
|
-
transformToAdd = currentOldT.transformation;
|
|
992
|
-
oldTransformValues = currentOldT.args;
|
|
993
|
-
newTransformValues = currentNewT.args;
|
|
994
|
-
|
|
995
|
-
oldIndex--;
|
|
996
|
-
newIndex--;
|
|
997
|
-
}
|
|
998
|
-
else if(oldIndex >= newIndex){
|
|
999
|
-
var currentOldT = oldValue.transformations[oldIndex];
|
|
1000
|
-
transformToAdd = currentOldT.transformation;
|
|
1001
|
-
oldTransformValues = currentOldT.args;
|
|
1002
|
-
if(transformToAdd == "matrix"){
|
|
1003
|
-
newTransformValues = [1,0, 0,1, 0,0];
|
|
1004
|
-
}
|
|
1005
|
-
else if(transformToAdd == "matrix3d"){
|
|
1006
|
-
newTransformValues = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1];
|
|
1007
|
-
}
|
|
1008
|
-
else {
|
|
1009
|
-
var filler = (transformToAdd.indexOf("scale") == -1) ? 0 : 1;
|
|
1010
|
-
newTransformValues = [];
|
|
1011
|
-
for(var j = 0; j < oldTransformValues.length; j++) newTransformValues.push(!isNaN(oldTransformValues[j]) ? filler : (
|
|
1012
|
-
!isNaN(oldTransformValues[j].angle) ? new dotcss2._Angle(0) : (
|
|
1013
|
-
!isNaN(oldTransformValues[j].length) ? new dotcss2._Length(0) : (0)
|
|
1014
|
-
)));
|
|
1015
|
-
}
|
|
1016
|
-
oldIndex--;
|
|
1017
|
-
}
|
|
1018
|
-
else{
|
|
1019
|
-
var currentNewT = newValue.transformations[newIndex];
|
|
1020
|
-
transformToAdd = currentNewT.transformation;
|
|
1021
|
-
newTransformValues = currentNewT.args;
|
|
1022
|
-
if(transformToAdd == "matrix"){
|
|
1023
|
-
oldTransformValues = [1,0, 0,1, 0,0];
|
|
1024
|
-
}
|
|
1025
|
-
else if(transformToAdd == "matrix3d"){
|
|
1026
|
-
oldTransformValues = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1];
|
|
1027
|
-
}
|
|
1028
|
-
else {
|
|
1029
|
-
var filler = (transformToAdd.indexOf("scale") == -1) ? 0 : 1;
|
|
1030
|
-
oldTransformValues = [];
|
|
1031
|
-
for(var j = 0; j < newTransformValues.length; j++) oldTransformValues.push(!isNaN(newTransformValues[j]) ? filler : (
|
|
1032
|
-
!isNaN(newTransformValues[j].angle) ? new dotcss2._Angle(0) : (
|
|
1033
|
-
!isNaN(newTransformValues[j].length) ? new dotcss2._Length(0) : (0)
|
|
1034
|
-
)));
|
|
1035
|
-
}
|
|
1036
|
-
newIndex--;
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
startTransform = ") " + startTransform;
|
|
1040
|
-
desiredTransform = ") " + desiredTransform;
|
|
1041
|
-
//Handle special values here.
|
|
1042
|
-
if(transformToAdd.indexOf("rotate") != -1){
|
|
1043
|
-
var oldAngle = oldTransformValues[oldTransformValues.length - 1].angle;
|
|
1044
|
-
var newAngle = newTransformValues[newTransformValues.length - 1].angle;
|
|
1045
|
-
var sep = dotcss.angleSubtract(newAngle, oldAngle);
|
|
1046
|
-
oldTransformValues[oldTransformValues.length - 1].angle = newAngle - sep;
|
|
1047
|
-
}
|
|
1048
|
-
for(var j = oldTransformValues.length - 1; j >= 0; j--){
|
|
1049
|
-
startTransform = "," + oldTransformValues[i] + startTransform;
|
|
1050
|
-
desiredTransform = "," + newTransformValues[i] + desiredTransform;
|
|
1051
|
-
}
|
|
1052
|
-
startTransform = transformToAdd + "(" + startTransform.substring(1);
|
|
1053
|
-
desiredTransform = transformToAdd + "(" + desiredTransform.substring(1);
|
|
1054
|
-
}
|
|
1055
|
-
oldValue = dotcss2._convertStyleIntoDotCssObject(startTransform, "transformation");
|
|
1056
|
-
newValue = dotcss2._convertStyleIntoDotCssObject(desiredTransform, "transformation");
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
else if(oldValue.type == "number" && newValue.type == "number"){} //OK
|
|
1060
|
-
else if(oldValue.type == "complex" && newValue.type == "complex"){
|
|
1061
|
-
if(!dotcss2._compareComplexDataTypes(oldValue, newValue)){
|
|
1062
|
-
console.warn("Couldn't animate " + this.jsFriendlyProp + ". Value mismatch.");
|
|
1063
|
-
continue;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
else{
|
|
1067
|
-
console.warn("Couldn't animate " + this.jsFriendlyProp + ". Not a recognizable length, color, or number.");
|
|
1068
|
-
continue;
|
|
1069
|
-
}
|
|
1070
|
-
dotcss2._animate(target, this.jsFriendlyProp, oldValue.type || this.type, oldValue, newValue, finalValue, dotcss2._fxInterval, duration, style || "ease", complete);
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
return dotcss2._lastBuilder;
|
|
1074
|
-
};
|
|
1075
|
-
|
|
1076
|
-
//Have to add these back since we're going to replace the __proto__ of a function with this new prototype.
|
|
1077
|
-
_StyleProperty.prototype.apply = Function.apply;
|
|
1078
|
-
_StyleProperty.prototype.call = Function.call;
|
|
1079
|
-
|
|
1080
|
-
dotcss2._animate = function(element, jsFriendlyProp, propType, startValue, targetValue, finalValue, currentTime, totalDuration, animationStyle, callback, lastValue){
|
|
1081
|
-
if(lastValue && element.style[jsFriendlyProp] != lastValue) return; //Animation can be cancelled any time by setting the value directly.
|
|
1082
|
-
|
|
1083
|
-
if(totalDuration - currentTime > 0){
|
|
1084
|
-
switch(propType){
|
|
1085
|
-
case "color":
|
|
1086
|
-
var r = Math.round(dotcss2._numberStep(startValue.r, targetValue.r, currentTime, totalDuration, animationStyle));
|
|
1087
|
-
var g = Math.round(dotcss2._numberStep(startValue.g, targetValue.g, currentTime, totalDuration, animationStyle ));
|
|
1088
|
-
var b = Math.round(dotcss2._numberStep(startValue.b, targetValue.b, currentTime, totalDuration, animationStyle ));
|
|
1089
|
-
var a = dotcss.formatNumberValue(dotcss2._numberStep(startValue.a, targetValue.a, currentTime, totalDuration, animationStyle )); //TODO: make sure this doesn't need to be rounded or something.
|
|
1090
|
-
dotcss(element)[jsFriendlyProp](r, g, b, a);
|
|
1091
|
-
break;
|
|
1092
|
-
case "length":
|
|
1093
|
-
dotcss(element)[jsFriendlyProp](dotcss.formatNumberValue(dotcss2._numberStep(startValue.length, targetValue.length, currentTime, totalDuration, animationStyle), startValue.units) + startValue.units);
|
|
1094
|
-
break;
|
|
1095
|
-
case "transformation":
|
|
1096
|
-
var newTransform = "";
|
|
1097
|
-
//startValue and targetValue are guaranteed to have the same template.
|
|
1098
|
-
for(var i = 0; i < startValue.transformations.length; i++){
|
|
1099
|
-
var t1 = startValue.transformations[i];
|
|
1100
|
-
var t2 = targetValue.transformations[i];
|
|
1101
|
-
newTransform += t1.transformation + "(";
|
|
1102
|
-
for(var k = 0; k < t1.args.length; k++){
|
|
1103
|
-
var v1 = t1.args[k];
|
|
1104
|
-
var v2 = t2.args[k];
|
|
1105
|
-
var actualV1 = isNaN(v1) ? v1.length || v1.angle || v1.value || 0 : v1;
|
|
1106
|
-
var actualV2 = isNaN(v2) ? v2.length || v2.angle || v2.value || 0 : v2;
|
|
1107
|
-
var units = isNaN(v1) ? v1.units : "";
|
|
1108
|
-
newTransform += dotcss.formatNumberValue(dotcss2._numberStep(actualV1, actualV2, currentTime, totalDuration, animationStyle), units) + units + ",";
|
|
1109
|
-
}
|
|
1110
|
-
newTransform = newTransform.substring(0, newTransform.length - 1);
|
|
1111
|
-
newTransform += ") ";
|
|
1112
|
-
}
|
|
1113
|
-
dotcss(element)[jsFriendlyProp](newTransform);
|
|
1114
|
-
break;
|
|
1115
|
-
default:
|
|
1116
|
-
switch(startValue.type){
|
|
1117
|
-
case "number":
|
|
1118
|
-
dotcss(element)[jsFriendlyProp](dotcss.formatNumberValue(dotcss2._numberStep(startValue.value, targetValue.value, currentTime, totalDuration, animationStyle)));
|
|
1119
|
-
break;
|
|
1120
|
-
case "complex":
|
|
1121
|
-
var newVal = "";
|
|
1122
|
-
for(var i = 0; i < startValue.numbers.length; i++){
|
|
1123
|
-
newVal += startValue.parts[i];
|
|
1124
|
-
newVal += dotcss.formatNumberValue(dotcss2._numberStep(startValue.numbers[i], targetValue.numbers[i], currentTime, totalDuration, animationStyle))
|
|
1125
|
-
}
|
|
1126
|
-
newVal += startValue.parts[startValue.parts.length - 1];
|
|
1127
|
-
|
|
1128
|
-
dotcss(element)[jsFriendlyProp](newVal);
|
|
1129
|
-
break;
|
|
1130
|
-
default:
|
|
1131
|
-
console.warn("Unexpected data type for animation.");
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
var now = (window.performance && window.performance.now) ? window.performance.now() : null;
|
|
1136
|
-
//var reachedAnimFrame = false;
|
|
1137
|
-
//TODO: there could be a memory leak here. Need to investigate.
|
|
1138
|
-
//Because we're creating a lot of new functions. Are they being released?
|
|
1139
|
-
var last = element.style[jsFriendlyProp];
|
|
1140
|
-
var nextStep = function(timestamp){
|
|
1141
|
-
var change = (now ? (window.performance.now() - now) : dotcss2._fxInterval);
|
|
1142
|
-
dotcss2._animate(element, jsFriendlyProp, propType, startValue, targetValue, finalValue, currentTime + change, totalDuration, animationStyle, callback, last);
|
|
1143
|
-
}
|
|
1144
|
-
if(window.requestAnimationFrame) {
|
|
1145
|
-
window.requestAnimationFrame(nextStep);
|
|
1146
|
-
//setTimeout(function(){if(!reachedAnimFrame) console.log("ERROR");}, 100);
|
|
1147
|
-
}
|
|
1148
|
-
else window.setTimeout(nextStep, dotcss2._fxInterval);
|
|
1149
|
-
}
|
|
1150
|
-
else{
|
|
1151
|
-
//TODO: verify that decimal values are properly handled here.
|
|
1152
|
-
dotcss(element)[jsFriendlyProp](finalValue);
|
|
1153
|
-
if(callback) callback();
|
|
1154
|
-
}
|
|
1155
|
-
};
|
|
1156
|
-
|
|
1157
|
-
//Function that takes in a bunch of parameters and steps the start value toward the target based on timeRemaining and style.
|
|
1158
|
-
//currentValue is the current value.
|
|
1159
|
-
//targetValue is the target valaue.
|
|
1160
|
-
//timeRemaining is the time remaining in ms.
|
|
1161
|
-
//stepProgress is the size of this step.
|
|
1162
|
-
//totalDuration is the duration of the entire animation from start to finish (not just this step).
|
|
1163
|
-
//style is the type of transition (geometric=exponential, ease, linear).
|
|
1164
|
-
//Returns the result.
|
|
1165
|
-
dotcss2._numberStep = function(startValue, targetValue, currentTime, totalDuration, style){
|
|
1166
|
-
|
|
1167
|
-
startValue = Number(startValue);
|
|
1168
|
-
targetValue = Number(targetValue);
|
|
1169
|
-
|
|
1170
|
-
var timeRemaining = totalDuration - currentTime;
|
|
1171
|
-
|
|
1172
|
-
switch(style){
|
|
1173
|
-
case "geometric":
|
|
1174
|
-
case "exponential"://This is kind of stupid now that we have ease. I might come back and add it in the future. For now assume ease.
|
|
1175
|
-
// var m = Math.exp(-1 / timeRemaining);
|
|
1176
|
-
// return targetValue + m * (startValue - targetValue);
|
|
1177
|
-
case "ease":
|
|
1178
|
-
var m = (-Math.cos(Math.PI * (currentTime / totalDuration)) + 1) * 0.5;
|
|
1179
|
-
return startValue + m * (targetValue - startValue);
|
|
1180
|
-
case "linear":
|
|
1181
|
-
default:
|
|
1182
|
-
return startValue + (targetValue - startValue) * (currentTime / totalDuration);
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
|
|
1186
|
-
dotcss.formatNumberValue = function(value, unit){
|
|
1187
|
-
switch(unit){
|
|
1188
|
-
case "px": return Math.round(value);
|
|
1189
|
-
default: return Math.round(value * 100) / 100;
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
|
|
1193
|
-
var _allProps = {
|
|
1194
|
-
color: "color|background-Color|border-Bottom-Color|border-Color|border-Left-Color|border-Right-Color|border-Top-Color|text-Decoration-Color|outline-Color|column-Rule-Color",
|
|
1195
|
-
length: "background-Size|border-Bottom-Left-Radius|border-Bottom-Right-Radius|border-Bottom-Width|border-Image-Width|border-Left-Width|border-Radius|border-Right-Width|border-Top-Left-Radius|border-Top-Right-Radius|border-Top-Width|border-Width|bottom|height|left|margin|margin-Bottom|margin-Left|margin-Right|margin-Top|max-Height|max-Width|min-Height|min-Width|padding|padding-Bottom|padding-Left|padding-Right|padding-Top|right|top|width|line-Height|flex-Basis|font-Size",
|
|
1196
|
-
url: "background-Image|border-Image|list-Style-Image|content|image-Orientation",
|
|
1197
|
-
transformation: "transformation",
|
|
1198
|
-
misc: "opacity|background|background-Attachment|background-Blend-Mode|background-Position|background-Repeat|background-Clip|background-Origin|border|border-Bottom|border-Bottom-Style|border-Image-Outset|border-Image-Repeat|border-Image-Slice|border-Image-Source|border-Left|border-Left-Style|border-Right|border-Right-Style|border-Style|border-Top|border-Top-Style|box-Decoration-Break|box-Shadow|clear|clip|display|float|overflow|box|overflow-X|overflow-Y|position|visibility|vertical-Align|z-Index|align-Content|align-Items|align-Self|flex|flex-Basis|flex-Direction|flex-Flow|flex-Grow|flex-Shrink|flex-Wrap|grid|grid-Area|grid-Auto-Columns|grid-auto-Rows|grid-Column|grid-Column-End|grid-Column-Gap|grid-Column-Start|grid-Gap|grid-Row|grid-Row-End|grid-Row-Gap|grid-Row-Start|grid-Template|grid-Template-Areas|grid-Template-Columns|grid-Template-Rows|justify-Content|order|hanging-Punctuation|hyphens|letter-Spacing|line-Break|overflow-Wrap|tab-Size|text-Align|text-Align-Last|text-Combine-Upright|text-Indent|text-Justify|text-Transform|white-Space|word-Break|word-Spacing|word-Wrap|text-Decoration|text-Decoration-Line|text-Decoration-Style|text-Shadow|text-Underline-Position|font|font-Family|font-Feature-Settings|font-Kerning|font-Language-Override|font-Size-Adjust|font-Stretch|font-Style|font-Synthesis|font-Variant|font-Variant-Alternates|font-Variant-Caps|font-Variant-East-Asian|font-Variant-Ligatures|font-Variant-Numeric|font-Variant-Position|font-Weight|direction|text-Orientation|text-Combine-Upright|unicode-Bidi|user-Select|writing-Mode|border-Collapse|border-Spacing|caption-Side|empty-Cells|table-Layout|counter-Increment|counter-Reset|list-Style|list-Style-Position|list-Style-Type|animation|animation-Delay|animation-Direction|animation-Duration|animation-Fill-Mode|animation-Iteration-Count|animation-Name|animation-Play-State|animation-Timing-Function|backface-Visibility|perspective2d|perspective-Origin|transform-Origin|transform-Style|transition|transition-Property|transition-Duration|transition-Timing-Function|transition-Delay|box-Sizing|cursor|ime-Mode|nav-Down|nav-Index|nav-Left|nav-Right|nav-Up|outline|outline-Offset|outline-Style|outline-Width|resize|text-Overflow|break-After|break-Before|break-Inside|column-Count|column-Fill|column-Gap|column-Rule|column-Rule-Style|column-Rule-Width|column-Span|column-Width|columns|widows|orphans|page-Break-After|page-Break-Before|page-Break-Inside|marks|quotes|filter|image-Rendering|image-Resolution|object-Fit|object-Position|mask|mask-Type|mark|mark-After|mark-Before|phonemes|rest|rest-After|rest-Before|voice-Balance|voice-Duration|voice-Pitch|voice-Pitch-Range|voice-Rate|voice-Stress|voice-Volume|marquee-Direction|marquee-Play-Count|marquee-Speed|marquee-Style|pointer-Events"
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
var _allLengthUnits = [
|
|
1202
|
-
{unit:"Em"},
|
|
1203
|
-
{unit:"Ex"},
|
|
1204
|
-
{unit:"Ch"},
|
|
1205
|
-
{unit:"Rem"},
|
|
1206
|
-
{unit:"Vw"},
|
|
1207
|
-
{unit:"Vh"},
|
|
1208
|
-
{unit:"Vmin"},
|
|
1209
|
-
{unit:"Vmax"},
|
|
1210
|
-
{unit:"%", jsName:"P"},
|
|
1211
|
-
{unit:"Cm"},
|
|
1212
|
-
{unit:"Mm"},
|
|
1213
|
-
{unit:"In"},
|
|
1214
|
-
{unit:"Px"},
|
|
1215
|
-
{unit:"Pt"},
|
|
1216
|
-
{unit:"Pc"}
|
|
1217
|
-
];
|
|
1218
|
-
|
|
1219
|
-
var _allTransforms = [
|
|
1220
|
-
"matrix",
|
|
1221
|
-
"matrix3d",
|
|
1222
|
-
"translate",
|
|
1223
|
-
"translate3d",
|
|
1224
|
-
"translateX",
|
|
1225
|
-
"translateY",
|
|
1226
|
-
"translateZ",
|
|
1227
|
-
"scale",
|
|
1228
|
-
"scale3d",
|
|
1229
|
-
"scaleX",
|
|
1230
|
-
"scaleY",
|
|
1231
|
-
"scaleZ",
|
|
1232
|
-
"rotate",
|
|
1233
|
-
"rotate3d",
|
|
1234
|
-
"rotateX",
|
|
1235
|
-
"rotateY",
|
|
1236
|
-
"rotateZ",
|
|
1237
|
-
"skew",
|
|
1238
|
-
"skewX",
|
|
1239
|
-
"skewY",
|
|
1240
|
-
"perspective"
|
|
1241
|
-
]
|
|
1242
|
-
|
|
1243
|
-
dotcss.matrixMultiply3D = function(A: Array<number>, B: Array<number>){
|
|
1244
|
-
if(A.length != 16 || B.length != 16) throw "3D matrices must be arrays of 16 length.";
|
|
1245
|
-
var ret = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
|
1246
|
-
for(var y = 0; y < 4; y++)
|
|
1247
|
-
for(var x = 0; x < 4; x++)
|
|
1248
|
-
for(var i = 0; i < 4; i++)
|
|
1249
|
-
ret[y + x * 4] += Number(A[y + i * 4]) * Number(B[i + x * 4]);
|
|
1250
|
-
return ret;
|
|
1251
|
-
};
|
|
1252
|
-
dotcss.angleToDeg = function(a: number|string){
|
|
1253
|
-
if(!isNaN(a as number)) return Number(a); //If there are no units, assume deg.
|
|
1254
|
-
a = (a as string).trim();
|
|
1255
|
-
if(a.indexOf("deg") != -1) return dotcss.formatNumberValue(Number(a.split("deg")[0]));
|
|
1256
|
-
else if(a.indexOf("grad") != -1) return dotcss.formatNumberValue(Number(a.split("grad")[0]) * 0.9);
|
|
1257
|
-
else if(a.indexOf("rad") != -1) return dotcss.formatNumberValue(Number(a.split("rad")[0]) * 180 / Math.PI);
|
|
1258
|
-
else if(a.indexOf("turn") != -1) return dotcss.formatNumberValue(Number(a.split("turn")[0]) * 360);
|
|
1259
|
-
else throw a + " does not have valid units for an angle."
|
|
1260
|
-
};
|
|
1261
|
-
dotcss.lengthToPx = function(l: string|number, prop: LengthProp, element: Element){
|
|
1262
|
-
var R = Math.round;
|
|
1263
|
-
var N = Number;
|
|
1264
|
-
if(!isNaN(l as number)) return R(N(l)); //If there are no units, assume px.
|
|
1265
|
-
l = (l as string).trim();
|
|
1266
|
-
var S = l.split;
|
|
1267
|
-
//Absolute:
|
|
1268
|
-
if(l.indexOf("px") != -1) return R(N(l.split("px")[0]));
|
|
1269
|
-
else if(l.indexOf("in") != -1) return R(N(l.split("in")[0]) * 96);
|
|
1270
|
-
else if(l.indexOf("pt") != -1) return R(N(l.split("pt")[0]) * 96 / 72);
|
|
1271
|
-
else if(l.indexOf("pc") != -1) return R(N(l.split("pc")[0]) * 16);
|
|
1272
|
-
else if(l.indexOf("cm") != -1) return R(N(l.split("cm")[0]) * 96 / 2.54);
|
|
1273
|
-
else if(l.indexOf("mm") != -1) return R(N(l.split("mm")[0]) * 96 / 25.4);
|
|
1274
|
-
else if(l.indexOf("q") != -1) return R(N(l.split("q")[0]) * 96 / 101.6);
|
|
1275
|
-
//Technically relative:
|
|
1276
|
-
else if(l.indexOf("vw") != -1) return R(N(l.split("vw")[0]) * 0.01 * Math.max(document.documentElement.clientWidth, window.innerWidth || 0));
|
|
1277
|
-
else if(l.indexOf("vh") != -1) return R(N(l.split("vh")[0]) * 0.01 * Math.max(document.documentElement.clientHeight, window.innerHeight || 0));
|
|
1278
|
-
else if(l.indexOf("vmin") != -1) return Math.min(dotcss.lengthToPx(R(N(l.split("vmin")[0]+ "vw"))), R(N(l.split("vmin")[0]+ "vx"))); //I know this is slow, but it's compact, and it's not like this is a common unit.
|
|
1279
|
-
else if(l.indexOf("vmax") != -1) return Math.max(dotcss.lengthToPx(R(N(l.split("vmin")[0]+ "vw"))), R(N(l.split("vmin")[0]+ "vx")));
|
|
1280
|
-
else if(l.indexOf("rem") != -1) return R(N(l.split("rem")[0]) * dotcss.lengthToPx(dotcss2._computedStyleOrActualStyle(document.body, "fontSize"))); //Couldn't get a stack overflow if it's a computed value. Always in px.
|
|
1281
|
-
|
|
1282
|
-
//Absolutely relative:
|
|
1283
|
-
else if (prop && element) {
|
|
1284
|
-
//If we're setting things relative to font sizes, that's easy.
|
|
1285
|
-
//Can't animate ex or ch. Sorry.
|
|
1286
|
-
if(l.indexOf("em") != -1) return R(N(l.split("em")[0]) * dotcss.lengthToPx(dotcss2._computedStyleOrActualStyle(element, "fontSize")));
|
|
1287
|
-
|
|
1288
|
-
var ref = null;
|
|
1289
|
-
switch(prop){
|
|
1290
|
-
case "maxHeight":
|
|
1291
|
-
case "minHeight":
|
|
1292
|
-
case "top":
|
|
1293
|
-
case "bottom":
|
|
1294
|
-
case "height":
|
|
1295
|
-
if(!element.parentNode) throw "Cannot convert " + l + " " + prop + " to px for an element that has no parent."
|
|
1296
|
-
ref = dotcss.lengthToPx(dotcss2._computedStyleOrActualStyle(element.parentNode, "height"));
|
|
1297
|
-
break;
|
|
1298
|
-
case "maxHidth":
|
|
1299
|
-
case "minWidth":
|
|
1300
|
-
case "right":
|
|
1301
|
-
case "left":
|
|
1302
|
-
case "width":
|
|
1303
|
-
case "margin": //Yes, all padding and margins are relative to width.
|
|
1304
|
-
case "marginTop":
|
|
1305
|
-
case "marginBottom":
|
|
1306
|
-
case "marginLeft":
|
|
1307
|
-
case "marginRight":
|
|
1308
|
-
case "outlineOffset":
|
|
1309
|
-
case "padding":
|
|
1310
|
-
case "paddingTop":
|
|
1311
|
-
case "paddingBottom":
|
|
1312
|
-
case "paddingLeft":
|
|
1313
|
-
case "paddingRight":
|
|
1314
|
-
ref = dotcss.lengthToPx(dotcss2._computedStyleOrActualStyle(element.parentNode, "width"));
|
|
1315
|
-
if(!element.parentNode) throw "Cannot convert " + l + " " + prop + " to px for an element that has no parent."
|
|
1316
|
-
break;
|
|
1317
|
-
case "lineHeight": //Always relative to font. Would actually be nice to be able to set this relative to container though
|
|
1318
|
-
ref = dotcss.lengthToPx(dotcss2._computedStyleOrActualStyle(element, "fontSize"));
|
|
1319
|
-
break;
|
|
1320
|
-
case "fontSize": //Thought this is not strictly allowed in css, we'll assume it means relative to current element's height.
|
|
1321
|
-
ref = dotcss.lengthToPx(dotcss2._computedStyleOrActualStyle(element, "height"));
|
|
1322
|
-
break;
|
|
1323
|
-
default:
|
|
1324
|
-
throw "Unable to convert the value " + l + " to px for " + prop + ".";
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
if(isNaN(ref)) throw "Convert the value " + l + " to px for " + prop + " because the value it is relative to is not a number.";
|
|
1328
|
-
|
|
1329
|
-
if(l.indexOf("%") != -1) return R(N(l.split("%")[0]) * 0.01 * ref);
|
|
1330
|
-
else throw "The units of " + l + " are not recognized by dotcss.";
|
|
1331
|
-
}
|
|
1332
|
-
else throw l + " does not have valid units for an absolute length.";
|
|
1333
|
-
};
|
|
1334
|
-
|
|
1335
|
-
//Returns a JSON object representation of value specific to the cssDataType passed in.
|
|
1336
|
-
dotcss2._convertStyleIntoDotCssObject = function(value, cssDataType){
|
|
1337
|
-
//if(!value) return null;
|
|
1338
|
-
if(!(value instanceof Array)) value = [value];
|
|
1339
|
-
if(cssDataType == "color") return new dotcss2._Color(value);
|
|
1340
|
-
else if (cssDataType == "url") return new dotcss2._Url(value);
|
|
1341
|
-
else if (cssDataType == "length" && (!isNaN(value[0]) || (value[0].indexOf(" ") == -1 && value[0].replace(dotcss2._floatRegex, "") != value[0]))) return new dotcss2._Length(value[0]);
|
|
1342
|
-
else if (cssDataType == "transformation") return new dotcss2._Transform(value[0].toString())
|
|
1343
|
-
else{
|
|
1344
|
-
if(value[0] === ""
|
|
1345
|
-
|| (
|
|
1346
|
-
(isNaN(value[0]))
|
|
1347
|
-
&& ("" + value[0]).replace(dotcss2._floatRegex, "") == value[0])
|
|
1348
|
-
) return new dotcss2._Unknown(value[0]); //No numbers.
|
|
1349
|
-
if(isNaN(value[0])) return new dotcss2._Complex(value[0]); //Numbers
|
|
1350
|
-
else return new dotcss2._Number(value[0]); //Just a number.
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
};
|
|
1354
|
-
|
|
1355
|
-
//Ensures that two complex values match.
|
|
1356
|
-
dotcss2._compareComplexDataTypes = function(value1, value2){
|
|
1357
|
-
if(value1.type != "complex" || value2.type != "complex") return false;
|
|
1358
|
-
if(value1.numbers.length != value2.numbers.length) return false;
|
|
1359
|
-
if(value1.parts.length != value2.parts.length) return false;
|
|
1360
|
-
for(var i = 0; i < value1.parts.length; i++){
|
|
1361
|
-
if(value1.parts[i] != value2.parts[i]) return false;
|
|
1362
|
-
}
|
|
1363
|
-
return true;
|
|
1364
|
-
};
|
|
1365
|
-
|
|
1366
|
-
//Adds a builder function directly to the dotcss object so that dotcss doesn't
|
|
1367
|
-
//have to be used as a function when a target doesn't need to be specified.
|
|
1368
|
-
dotcss2._addPropFunctionToDotCssObject = function(funcName){
|
|
1369
|
-
dotcss[funcName] = function(){
|
|
1370
|
-
var n = new _Builder();
|
|
1371
|
-
return n[funcName].apply(n, arguments);
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
|
|
1375
|
-
//Takes the property and generates all the dotcss and builder functions.
|
|
1376
|
-
dotcss2._makeFunction = function(prop, jsFriendlyProp, type){
|
|
1377
|
-
//Create the new function.
|
|
1378
|
-
_b[jsFriendlyProp] = function(){
|
|
1379
|
-
|
|
1380
|
-
if(arguments.length == 0) return this;
|
|
1381
|
-
var args = [];
|
|
1382
|
-
for(var i = 0; i < arguments.length; i++) args.push(arguments[i]);
|
|
1383
|
-
var value = dotcss2._convertStyleIntoDotCssObject(args, type).toString();
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
var newCss = prop + ":" + value + ";";
|
|
1387
|
-
this.currentCss += newCss;
|
|
1388
|
-
// console.log(`SETTING ${jsFriendlyProp}:`, this.toString());
|
|
1389
|
-
// this.toString()
|
|
1390
|
-
|
|
1391
|
-
if(this.target){
|
|
1392
|
-
for(var q = 0; q < this.target.length; q++){
|
|
1393
|
-
//this.target[q].style += newCss;
|
|
1394
|
-
var t = this.target[q];
|
|
1395
|
-
if(t.tagName == "STYLE") t.innerHTML = t.innerHTML.substring(0, t.innerHTML.length - 1) + prop + ":" + value + ";}";
|
|
1396
|
-
else t.style[jsFriendlyProp] = value;
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
return this;
|
|
1401
|
-
}
|
|
1402
|
-
//Add the new function to the dotcss object so that it can be accessed without doing dotcss().
|
|
1403
|
-
dotcss2._addPropFunctionToDotCssObject(jsFriendlyProp);
|
|
1404
|
-
|
|
1405
|
-
//Each unit of length will also have its own version of this function (assuming this is a length property).
|
|
1406
|
-
if(type == "length"){
|
|
1407
|
-
for(var u = 0; u < _allLengthUnits.length; u++){
|
|
1408
|
-
var uu = _allLengthUnits[u];
|
|
1409
|
-
(function(uu){
|
|
1410
|
-
_b[jsFriendlyProp + (uu.jsName || uu.unit)] = function(){
|
|
1411
|
-
for(var i = 0; i < arguments.length; i++) arguments[i] = arguments[i] + uu.unit.toLowerCase();
|
|
1412
|
-
return _b[jsFriendlyProp].apply(this, arguments);
|
|
1413
|
-
}
|
|
1414
|
-
})(uu);
|
|
1415
|
-
dotcss2._addPropFunctionToDotCssObject(jsFriendlyProp + (uu.jsName || uu.unit));
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
//_b[jsFriendlyProp].__proto__ = Object.create(_StyleProperty.prototype);
|
|
1420
|
-
_b[jsFriendlyProp].type = type;
|
|
1421
|
-
_b[jsFriendlyProp].jsFriendlyProp = jsFriendlyProp;
|
|
1422
|
-
|
|
1423
|
-
for (var k in _StyleProperty.prototype) {
|
|
1424
|
-
if(_b[jsFriendlyProp][k] === undefined) _b[jsFriendlyProp][k] = _StyleProperty.prototype[k];
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
|
|
1428
|
-
dotcss2._makeTransformFunction = function(fn){
|
|
1429
|
-
dotcss[fn] = function(){
|
|
1430
|
-
var n = new dotcss2._Transform();
|
|
1431
|
-
return n[fn].apply(n, arguments);
|
|
1432
|
-
};
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
dotcss2._computedStyleOrActualStyle = function(element, property){
|
|
1436
|
-
return window.getComputedStyle(element)[property] || element.style[property];
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
dotcss2._modDeg = function(a){
|
|
1440
|
-
if(a < 0) a = 360 - ((-a) % 360);
|
|
1441
|
-
return a % 360;
|
|
1442
|
-
};
|
|
1443
|
-
|
|
1444
|
-
//Public functions.
|
|
1445
|
-
|
|
1446
|
-
dotcss.angleSubtract = function(a, b){
|
|
1447
|
-
if(a < 0) a = 360 - ((-a) % 360); else a = a % 360;
|
|
1448
|
-
if(b < 0) b = 360 - ((-b) % 360); else b = b % 360;
|
|
1449
|
-
var phi = Math.abs(b - a) % 360;
|
|
1450
|
-
var d = phi > 180 ? 360 - phi : phi;
|
|
1451
|
-
var sign = (a - b >= 0 && a - b <= 180) || (a - b <=-180 && a- b>= -360) ? 1 : -1;
|
|
1452
|
-
return d * sign;
|
|
1453
|
-
};
|
|
1454
|
-
|
|
1455
|
-
//Special handler for building urls.
|
|
1456
|
-
dotcss.url = function(url){
|
|
1457
|
-
return "url('" + url + "')";
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
|
-
//Special handler for building rgb colors.
|
|
1461
|
-
dotcss.rgb = function(r, g, b){
|
|
1462
|
-
return "rgb(" + r + ", " + g + ", " + b + ")";
|
|
1463
|
-
};
|
|
1464
|
-
|
|
1465
|
-
//Special handler for building rgba colors.
|
|
1466
|
-
dotcss.rgba = function(r, g, b, a){
|
|
1467
|
-
return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
|
|
1468
|
-
};
|
|
1469
|
-
|
|
1470
|
-
dotcss.buildTransform = function(){
|
|
1471
|
-
return new dotcss2._Transform();
|
|
1472
|
-
};
|
|
1473
|
-
|
|
1474
|
-
dotcss["cacheScopedStaticStyles"] = function(el: HTMLElement){
|
|
1475
|
-
let elements = getScopedNodeList("*", el);
|
|
1476
|
-
for(let element of elements){
|
|
1477
|
-
if(element.hasAttribute("style")){
|
|
1478
|
-
element.setAttribute(STATIC_SYLES_ATTR, element.getAttribute("style"));
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
dotcss["clearDynamicStyles"] = function(el: HTMLElement){
|
|
1484
|
-
let elements = getScopedNodeList("*", el);
|
|
1485
|
-
for(let element of elements){
|
|
1486
|
-
element.removeAttribute("style");
|
|
1487
|
-
if(element.hasAttribute(STATIC_SYLES_ATTR)){
|
|
1488
|
-
element.setAttribute("style", element.getAttribute(STATIC_SYLES_ATTR));
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
dotcss.scopeToEl = function(el: HTMLElement){
|
|
1494
|
-
scopeStack.unshift(el);
|
|
1495
|
-
return this;
|
|
1496
|
-
};
|
|
1497
|
-
dotcss.unscope = function(){
|
|
1498
|
-
scopeStack.shift();
|
|
1499
|
-
return this;
|
|
1500
|
-
};
|
|
1501
|
-
|
|
1502
|
-
//Build dotcss.
|
|
1503
|
-
for(var k in _allProps) {
|
|
1504
|
-
let P = _allProps[k].split("|");
|
|
1505
|
-
for(var i in P){
|
|
1506
|
-
dotcss2._makeFunction(P[i].toLowerCase(), P[i].replace(new RegExp("-", "g"), ""), k);
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
for(let i: number = 0; i < _allLengthUnits.length; i++) dotcss2._makeTransformFunction(_allLengthUnits[i]);
|
|
1510
|
-
//dotcss = new dotcss();
|
|
1511
|
-
|
|
1512
|
-
// for (var k in _b) {
|
|
1513
|
-
// if(_Builder[k] === undefined) dotcss[k] = _p[k];
|
|
1514
|
-
// }
|
|
1515
|
-
|
|
1516
|
-
export default dotcss;
|