dothtml 5.2.9 → 5.2.11
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/lib/arg-callback-obj.d.ts +29 -29
- package/lib/arg-callback-obj.js +63 -63
- package/lib/built-in-components/nav-link.d.ts +8 -8
- package/lib/built-in-components/nav-link.js +23 -23
- package/lib/built-in-components/router.d.ts +57 -57
- package/lib/built-in-components/router.js +281 -281
- package/lib/built-in-components/router.js.map +1 -1
- package/lib/component.d.ts +82 -82
- package/lib/component.js +328 -328
- package/lib/dot-util.d.ts +26 -26
- package/lib/dot-util.js +61 -61
- package/lib/dot.d.ts +5 -5
- package/lib/dot.js +1121 -1095
- package/lib/dot.js.map +1 -1
- package/lib/dothtml.d.ts +29 -28
- package/lib/dothtml.js +14 -37
- package/lib/dothtml.js.map +1 -1
- package/lib/err.d.ts +2 -2
- package/lib/err.js +25 -25
- package/lib/event-bus.d.ts +10 -10
- package/lib/event-bus.js +36 -36
- package/lib/i-dot.d.ts +689 -674
- package/lib/i-dot.js +2 -2
- package/lib/node-polyfill.d.ts +2 -2
- package/lib/node-polyfill.js +13 -13
- package/lib/observable-array.d.ts +49 -49
- package/lib/observable-array.js +273 -273
- package/lib/pages/home-page.d.ts +9 -0
- package/lib/pages/home-page.js +24 -0
- package/lib/pages/home-page.js.map +1 -0
- package/lib/styling/css-types.ts/css-angle.d.ts +7 -7
- package/lib/styling/css-types.ts/css-angle.js +21 -21
- package/lib/styling/css-types.ts/css-color.d.ts +9 -9
- package/lib/styling/css-types.ts/css-color.js +823 -823
- package/lib/styling/css-types.ts/css-complex.d.ts +7 -7
- package/lib/styling/css-types.ts/css-complex.js +22 -22
- package/lib/styling/css-types.ts/css-data-type.d.ts +5 -5
- package/lib/styling/css-types.ts/css-data-type.js +8 -8
- package/lib/styling/css-types.ts/css-filter.d.ts +22 -22
- package/lib/styling/css-types.ts/css-filter.js +120 -120
- package/lib/styling/css-types.ts/css-length.d.ts +7 -7
- package/lib/styling/css-types.ts/css-length.js +23 -23
- package/lib/styling/css-types.ts/css-number.d.ts +6 -6
- package/lib/styling/css-types.ts/css-number.js +16 -16
- package/lib/styling/css-types.ts/css-percentage.d.ts +5 -5
- package/lib/styling/css-types.ts/css-percentage.js +12 -12
- package/lib/styling/css-types.ts/css-transform.d.ts +38 -38
- package/lib/styling/css-types.ts/css-transform.js +182 -182
- package/lib/styling/css-types.ts/css-unknown.d.ts +6 -6
- package/lib/styling/css-types.ts/css-unknown.js +16 -16
- package/lib/styling/css-types.ts/css-url.d.ts +6 -6
- package/lib/styling/css-types.ts/css-url.js +44 -44
- package/lib/styling/i-dotcss.d.ts +1085 -1085
- package/lib/styling/i-dotcss.js +2 -2
- package/lib/styling/style-builder.d.ts +24 -24
- package/lib/styling/style-builder.js +814 -814
- package/lib/styling/unit-function-tables.d.ts +10 -10
- package/lib/styling/unit-function-tables.js +26 -26
- package/package.json +9 -8
|
@@ -1,815 +1,815 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports._Builder = void 0;
|
|
7
|
-
const unit_function_tables_1 = require("./unit-function-tables");
|
|
8
|
-
const css_angle_1 = __importDefault(require("./css-types.ts/css-angle"));
|
|
9
|
-
const css_color_1 = __importDefault(require("./css-types.ts/css-color"));
|
|
10
|
-
const css_complex_1 = __importDefault(require("./css-types.ts/css-complex"));
|
|
11
|
-
const css_length_1 = __importDefault(require("./css-types.ts/css-length"));
|
|
12
|
-
const css_number_1 = __importDefault(require("./css-types.ts/css-number"));
|
|
13
|
-
const css_transform_1 = __importDefault(require("./css-types.ts/css-transform"));
|
|
14
|
-
const css_unknown_1 = __importDefault(require("./css-types.ts/css-unknown"));
|
|
15
|
-
const css_url_1 = __importDefault(require("./css-types.ts/css-url"));
|
|
16
|
-
const dot_util_1 = require("../dot-util");
|
|
17
|
-
const css_filter_1 = __importDefault(require("./css-types.ts/css-filter"));
|
|
18
|
-
//Latest Update.
|
|
19
|
-
/*
|
|
20
|
-
* - Wrapped code in anonymous function.
|
|
21
|
-
* - Hid _Builder and _StyleProperty.
|
|
22
|
-
* - Increased compatibility with IE 8, 9, and 10.
|
|
23
|
-
* - Allowed 0-length animations.
|
|
24
|
-
* 5.1
|
|
25
|
-
* - Typified style builder.
|
|
26
|
-
* - Fixed up transformations and redid transform builder.
|
|
27
|
-
* - Removed some old junk.
|
|
28
|
-
*/
|
|
29
|
-
const STATIC_SYLES_ATTR = "data-dot-static-styles";
|
|
30
|
-
// Rename this to DotcssHelpers.
|
|
31
|
-
// The name Dotcss2 comes from a time when this was a clone of dotcss with "private" members.
|
|
32
|
-
class Dotcss2 {
|
|
33
|
-
constructor() {
|
|
34
|
-
//Inverse of framerate in ms/frame.
|
|
35
|
-
// Used for old browsers that don't support requestAnimationFrameframe.
|
|
36
|
-
this.fxInterval = 1000 / 60;
|
|
37
|
-
this.lastBuilder = null;
|
|
38
|
-
this.scopeStack = [];
|
|
39
|
-
this.globalStyleElement = null;
|
|
40
|
-
}
|
|
41
|
-
animateFull(element, jsFriendlyProp, propType, startValue, targetValue, finalValue, currentTime, totalDuration, animationStyle, callback, lastValue) {
|
|
42
|
-
if (lastValue && element.style[jsFriendlyProp] != lastValue)
|
|
43
|
-
return; //Animation can be cancelled any time by setting the value directly.
|
|
44
|
-
if (totalDuration - currentTime > 0) {
|
|
45
|
-
switch (propType) {
|
|
46
|
-
case "color":
|
|
47
|
-
var r = Math.round((0, dot_util_1.numberStep)(startValue.r, targetValue.r, currentTime, totalDuration, animationStyle));
|
|
48
|
-
var g = Math.round((0, dot_util_1.numberStep)(startValue.g, targetValue.g, currentTime, totalDuration, animationStyle));
|
|
49
|
-
var b = Math.round((0, dot_util_1.numberStep)(startValue.b, targetValue.b, currentTime, totalDuration, animationStyle));
|
|
50
|
-
var a = dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.a, targetValue.a, currentTime, totalDuration, animationStyle)); //TODO: make sure this doesn't need to be rounded or something.
|
|
51
|
-
dotcss(element)[jsFriendlyProp](r, g, b, a);
|
|
52
|
-
break;
|
|
53
|
-
case "length":
|
|
54
|
-
dotcss(element)[jsFriendlyProp](dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.length, targetValue.length, currentTime, totalDuration, animationStyle), startValue.units) + startValue.units);
|
|
55
|
-
break;
|
|
56
|
-
case "transformation":
|
|
57
|
-
var newTransform = "";
|
|
58
|
-
//startValue and targetValue are guaranteed to have the same template.
|
|
59
|
-
for (var i = 0; i < startValue.transformations.length; i++) {
|
|
60
|
-
var t1 = startValue.transformations[i];
|
|
61
|
-
var t2 = targetValue.transformations[i];
|
|
62
|
-
newTransform += t1.transformation + "(";
|
|
63
|
-
for (var k = 0; k < t1.args.length; k++) {
|
|
64
|
-
var v1 = t1.args[k];
|
|
65
|
-
var v2 = t2.args[k];
|
|
66
|
-
var actualV1 = isNaN(v1) ? v1.length || v1.angle || v1.value || 0 : v1;
|
|
67
|
-
var actualV2 = isNaN(v2) ? v2.length || v2.angle || v2.value || 0 : v2;
|
|
68
|
-
var units = isNaN(v1) ? v1.units : "";
|
|
69
|
-
newTransform += dotcss.formatNumberValue((0, dot_util_1.numberStep)(actualV1, actualV2, currentTime, totalDuration, animationStyle), units) + units + ",";
|
|
70
|
-
}
|
|
71
|
-
newTransform = newTransform.substring(0, newTransform.length - 1);
|
|
72
|
-
newTransform += ") ";
|
|
73
|
-
}
|
|
74
|
-
dotcss(element)[jsFriendlyProp](newTransform);
|
|
75
|
-
break;
|
|
76
|
-
default:
|
|
77
|
-
switch (startValue.type) {
|
|
78
|
-
case "number":
|
|
79
|
-
dotcss(element)[jsFriendlyProp](dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.value, targetValue.value, currentTime, totalDuration, animationStyle)));
|
|
80
|
-
break;
|
|
81
|
-
case "complex":
|
|
82
|
-
var newVal = "";
|
|
83
|
-
for (var i = 0; i < startValue.numbers.length; i++) {
|
|
84
|
-
newVal += startValue.parts[i];
|
|
85
|
-
newVal += dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.numbers[i], targetValue.numbers[i], currentTime, totalDuration, animationStyle));
|
|
86
|
-
}
|
|
87
|
-
newVal += startValue.parts[startValue.parts.length - 1];
|
|
88
|
-
dotcss(element)[jsFriendlyProp](newVal);
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
console.warn("Unexpected data type for animation.");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
var now = (window.performance && window.performance.now) ? window.performance.now() : null;
|
|
95
|
-
//var reachedAnimFrame = false;
|
|
96
|
-
//TODO: there could be a memory leak here. Need to investigate.
|
|
97
|
-
//Because we're creating a lot of new functions. Are they being released?
|
|
98
|
-
var last = element.style[jsFriendlyProp];
|
|
99
|
-
var nextStep = function (timestamp) {
|
|
100
|
-
var change = (now ? (window.performance.now() - now) : dotcss2.fxInterval);
|
|
101
|
-
dotcss2.animateFull(element, jsFriendlyProp, propType, startValue, targetValue, finalValue, currentTime + change, totalDuration, animationStyle, callback, last);
|
|
102
|
-
};
|
|
103
|
-
if (window.requestAnimationFrame) {
|
|
104
|
-
window.requestAnimationFrame(nextStep);
|
|
105
|
-
//setTimeout(function(){if(!reachedAnimFrame) console.log("ERROR");}, 100);
|
|
106
|
-
}
|
|
107
|
-
else
|
|
108
|
-
window.setTimeout(nextStep, dotcss2.fxInterval);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
//TODO: verify that decimal values are properly handled here.
|
|
112
|
-
dotcss(element)[jsFriendlyProp](finalValue);
|
|
113
|
-
if (callback)
|
|
114
|
-
callback();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//Takes the property and generates all the dotcss and builder functions.
|
|
118
|
-
extendDothtml(prop, jsFriendlyProp, type) {
|
|
119
|
-
//Create the new function by extending the builder.
|
|
120
|
-
let _b = _Builder.prototype;
|
|
121
|
-
_b[jsFriendlyProp] = function () {
|
|
122
|
-
if (arguments.length == 0)
|
|
123
|
-
return this;
|
|
124
|
-
var args = [];
|
|
125
|
-
for (var i = 0; i < arguments.length; i++)
|
|
126
|
-
args.push(arguments[i]);
|
|
127
|
-
// TODO: Why can't I just pass arguments directly into this function?
|
|
128
|
-
// Try it.
|
|
129
|
-
var value = dotcss2.convertStyleIntoDotCssObject(args, type).toString();
|
|
130
|
-
var newCss = prop + ":" + value + ";";
|
|
131
|
-
this.currentCss += newCss;
|
|
132
|
-
// console.log(`SETTING ${jsFriendlyProp}:`, this.toString());
|
|
133
|
-
// this.toString()
|
|
134
|
-
if (this.targets) {
|
|
135
|
-
for (var q = 0; q < this.targets.length; q++) {
|
|
136
|
-
//this.targets[q].style += newCss;
|
|
137
|
-
var t = this.targets[q];
|
|
138
|
-
if (t.tagName == "STYLE")
|
|
139
|
-
t.innerHTML = t.innerHTML.substring(0, t.innerHTML.length - 1) + prop + ":" + value + ";}";
|
|
140
|
-
else
|
|
141
|
-
t.style[jsFriendlyProp] = value;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return this;
|
|
145
|
-
};
|
|
146
|
-
//Add the new function to the dotcss object so that it can be accessed without doing dotcss().
|
|
147
|
-
dotcss2.addPropFunctionToDotCssObject(jsFriendlyProp);
|
|
148
|
-
//Each unit of length will also have its own version of this function (assuming this is a length property).
|
|
149
|
-
if (type == "length") {
|
|
150
|
-
for (var u = 0; u < unit_function_tables_1.AllLengthUnits.length; u++) {
|
|
151
|
-
var uu = unit_function_tables_1.AllLengthUnits[u];
|
|
152
|
-
(function (uu) {
|
|
153
|
-
_b[jsFriendlyProp + (uu.jsName || uu.unit)] = function () {
|
|
154
|
-
for (var i = 0; i < arguments.length; i++)
|
|
155
|
-
arguments[i] = arguments[i] + uu.unit.toLowerCase();
|
|
156
|
-
return _b[jsFriendlyProp].apply(this, arguments);
|
|
157
|
-
};
|
|
158
|
-
})(uu);
|
|
159
|
-
dotcss2.addPropFunctionToDotCssObject(jsFriendlyProp + (uu.jsName || uu.unit));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
//_b[jsFriendlyProp].__proto__ = Object.create(_StyleProperty.prototype);
|
|
163
|
-
_b[jsFriendlyProp].type = type;
|
|
164
|
-
_b[jsFriendlyProp].jsFriendlyProp = jsFriendlyProp;
|
|
165
|
-
// This is weird. It looks like I was trying to implement some form of multilpe inheritance.
|
|
166
|
-
// This should really be upgraded.
|
|
167
|
-
for (var k in _StyleProperty.prototype) {
|
|
168
|
-
if (_b[jsFriendlyProp][k] === undefined)
|
|
169
|
-
_b[jsFriendlyProp][k] = _StyleProperty.prototype[k];
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
//Returns a JSON object representation of value specific to the cssDataType passed in.
|
|
173
|
-
convertStyleIntoDotCssObject(value, cssDataType) {
|
|
174
|
-
//if(!value) return null;
|
|
175
|
-
if (!(value instanceof Array))
|
|
176
|
-
value = [value];
|
|
177
|
-
if (cssDataType == "color")
|
|
178
|
-
return new css_color_1.default(value);
|
|
179
|
-
else if (cssDataType == "url")
|
|
180
|
-
return new css_url_1.default(value);
|
|
181
|
-
else if (cssDataType == "length" && (!isNaN(value[0]) || (value[0].indexOf(" ") == -1 && value[0].replace(dot_util_1.floatRegex, "") != value[0])))
|
|
182
|
-
return new css_length_1.default(value[0]);
|
|
183
|
-
else if (cssDataType == "transformation")
|
|
184
|
-
return (new css_transform_1.default(value[0])).toString();
|
|
185
|
-
else if (cssDataType == "filter")
|
|
186
|
-
return (new css_filter_1.default(value[0])).toString();
|
|
187
|
-
else {
|
|
188
|
-
if (value[0] === ""
|
|
189
|
-
|| ((isNaN(value[0]))
|
|
190
|
-
&& ("" + value[0]).replace(dot_util_1.floatRegex, "") == value[0]))
|
|
191
|
-
return new css_unknown_1.default(value[0]); //No numbers.
|
|
192
|
-
if (isNaN(value[0]))
|
|
193
|
-
return new css_complex_1.default(value[0]); //Numbers
|
|
194
|
-
else
|
|
195
|
-
return new css_number_1.default(value[0]); //Just a number.
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
;
|
|
199
|
-
//Ensures that two complex values match.
|
|
200
|
-
compareComplexDataTypes(value1, value2) {
|
|
201
|
-
if (value1.type != "complex" || value2.type != "complex")
|
|
202
|
-
return false;
|
|
203
|
-
if (value1.numbers.length != value2.numbers.length)
|
|
204
|
-
return false;
|
|
205
|
-
if (value1.parts.length != value2.parts.length)
|
|
206
|
-
return false;
|
|
207
|
-
for (var i = 0; i < value1.parts.length; i++) {
|
|
208
|
-
if (value1.parts[i] != value2.parts[i])
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
;
|
|
214
|
-
//Adds a builder function directly to the dotcss object so that dotcss doesn't
|
|
215
|
-
//have to be used as a function when a target doesn't need to be specified.
|
|
216
|
-
addPropFunctionToDotCssObject(funcName) {
|
|
217
|
-
dotcss[funcName] = function () {
|
|
218
|
-
var n = new _Builder();
|
|
219
|
-
return n[funcName].apply(n, arguments);
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
;
|
|
223
|
-
// Might remove this.
|
|
224
|
-
// I think this doesn't work. Removing now. Not sure what it was supposed to do.
|
|
225
|
-
// makeTransformFunction(fn){
|
|
226
|
-
// dotcss[fn] = function(){
|
|
227
|
-
// var n = new Transform();
|
|
228
|
-
// return n[fn].apply(n, arguments);
|
|
229
|
-
// };
|
|
230
|
-
// }
|
|
231
|
-
computedStyleOrActualStyle(element, property) {
|
|
232
|
-
return window.getComputedStyle(element)[property] || element.style[property];
|
|
233
|
-
}
|
|
234
|
-
;
|
|
235
|
-
modDeg(a) {
|
|
236
|
-
if (a < 0)
|
|
237
|
-
a = 360 - ((-a) % 360);
|
|
238
|
-
return a % 360;
|
|
239
|
-
}
|
|
240
|
-
;
|
|
241
|
-
}
|
|
242
|
-
const dotcss2 = new Dotcss2();
|
|
243
|
-
const dotcss = function (query) {
|
|
244
|
-
//this.currentCss = "";
|
|
245
|
-
var target = null;
|
|
246
|
-
if (query) {
|
|
247
|
-
// console.log(query, "?");
|
|
248
|
-
if (typeof query == "string") {
|
|
249
|
-
// Creating a style tag. Might not be supported forever.
|
|
250
|
-
if (query.length > 2 && query.indexOf("{}") == query.length - 2) {
|
|
251
|
-
// TODO: this needs further testing, particularly when mulitple sytles are set on the same page.
|
|
252
|
-
// Be sure to set up some tests.
|
|
253
|
-
query = query.substring(0, query.length - 2);
|
|
254
|
-
if (!dotcss2.globalStyleElement) {
|
|
255
|
-
dotcss2.globalStyleElement = document.createElement("style");
|
|
256
|
-
document.head.appendChild(dotcss2.globalStyleElement);
|
|
257
|
-
}
|
|
258
|
-
target = [dotcss2.globalStyleElement];
|
|
259
|
-
target[0].innerHTML += query + "{}\r\n";
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
// This is overly complicated, but here is the spiel.
|
|
263
|
-
// If there's an element on the scopeStack, it should be used with the querySelectorAll.
|
|
264
|
-
// BUT, querySelectorAll doesn't actually select the element it's currently on, which is a requirement for dothtml.
|
|
265
|
-
// To make matters worse, if we do querySelectorAll on the element's parents, we may accidentally select its siblings!!
|
|
266
|
-
// To fix this, we get a list from querySelectorAll on the element, then push the element itself to that list
|
|
267
|
-
// iff it is in the list of elements queried from its parent.
|
|
268
|
-
// In addition to all of that, we don't want scoped styles to be applied to child components.
|
|
269
|
-
var s0 = dotcss2.scopeStack[0];
|
|
270
|
-
// if(s0 instanceof Component){
|
|
271
|
-
// s0 = s0.$el;
|
|
272
|
-
// }
|
|
273
|
-
// If we're doing scoped, and it's an element.
|
|
274
|
-
if (s0 && s0.parentNode && s0.querySelectorAll) {
|
|
275
|
-
// console.log(s0);
|
|
276
|
-
target = getScopedNodeList(query, s0);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
target = document.querySelectorAll(query);
|
|
280
|
-
}
|
|
281
|
-
// target = referencePt.querySelectorAll(query);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if ((query instanceof NodeList) || (query instanceof Array))
|
|
285
|
-
target = query;
|
|
286
|
-
if (query instanceof Node)
|
|
287
|
-
target = [query]; //Doesn't need to be a NodeList. Just iterable.
|
|
288
|
-
}
|
|
289
|
-
dotcss2.lastBuilder = new _Builder(target);
|
|
290
|
-
return dotcss2.lastBuilder;
|
|
291
|
-
}; // We do this because many of the dotcss methods are generated at runtime. Greatly reduces build size.
|
|
292
|
-
dotcss.version = "0.16.0";
|
|
293
|
-
function getScopedNodeList(query, s0) {
|
|
294
|
-
// Get all of the matching child elements of the component. This will not include s0 itself, but it does include nested components.
|
|
295
|
-
// So we will need to manipulate this collection.
|
|
296
|
-
// querySelectorAll returns a NodeList, which we need to convert into an Array.
|
|
297
|
-
var target = Array.from(s0.querySelectorAll(query));
|
|
298
|
-
// console.log(query, s0.className);
|
|
299
|
-
// Exclude nested components.
|
|
300
|
-
for (var t = 0; t < target.length; t++) {
|
|
301
|
-
var T = target[t];
|
|
302
|
-
// Is it a nested component??
|
|
303
|
-
if (T["__dothtml_component"]) {
|
|
304
|
-
// It's a component. Remove it, and all of it's descendants.
|
|
305
|
-
target.splice(t, 1);
|
|
306
|
-
t--;
|
|
307
|
-
var subTargets = T.querySelectorAll(query);
|
|
308
|
-
for (var s = 0; s < subTargets.length; s++) {
|
|
309
|
-
let S = subTargets[s];
|
|
310
|
-
target.splice(target.indexOf(S, t + 1), 1);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
// Loop through all the sibling nodes until we find s0.
|
|
315
|
-
var parentTargets = Array.from(s0.parentNode.querySelectorAll(query));
|
|
316
|
-
var p = parentTargets.indexOf(s0);
|
|
317
|
-
if (p != -1) {
|
|
318
|
-
target.unshift(parentTargets[p]);
|
|
319
|
-
}
|
|
320
|
-
return target;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* The dotcss builder gets extended with all of the css functions at runtime.
|
|
324
|
-
*/
|
|
325
|
-
class _Builder {
|
|
326
|
-
constructor(targets) {
|
|
327
|
-
this.currentCss = "";
|
|
328
|
-
this.targets = targets ?? null;
|
|
329
|
-
}
|
|
330
|
-
toString() {
|
|
331
|
-
// console.log("CALLED TOSTRING!", this.currentCss);
|
|
332
|
-
return this.currentCss;
|
|
333
|
-
}
|
|
334
|
-
// These methods are a bit strange to have here.
|
|
335
|
-
// They should probably be a part of the dotcss core object or something.
|
|
336
|
-
// Also, they're the only items that are explicitly part of the builder rather than generated.
|
|
337
|
-
//Usage:
|
|
338
|
-
//hide()
|
|
339
|
-
//hide(duration, complete)
|
|
340
|
-
//hide(options)
|
|
341
|
-
//Options
|
|
342
|
-
// display: inline-block, block, etc.
|
|
343
|
-
// duration: duration in ms.
|
|
344
|
-
// complete: on-complete callback.
|
|
345
|
-
// hideStyle: fade, shrink, or normal
|
|
346
|
-
// animationStyle: linear or exponential
|
|
347
|
-
hide(style) {
|
|
348
|
-
if (this.targets) {
|
|
349
|
-
var arg0 = arguments[0] || {};
|
|
350
|
-
var arg0N = arg0;
|
|
351
|
-
var arg0O = arg0;
|
|
352
|
-
var ops = {};
|
|
353
|
-
ops.duration = arg0O.duration || (isNaN(arg0N) ? 0 : arg0N) || 0;
|
|
354
|
-
//ops.display = arg0.display || "none";
|
|
355
|
-
//ops.opacity = arg0.opacity || null;
|
|
356
|
-
//ops.width = arg0.width || null;
|
|
357
|
-
//ops.height = arg0.height || null;
|
|
358
|
-
ops.complete = arg0O.complete || (typeof arguments[1] == "function" ? arguments[1] : (typeof arguments[2] == "function" ? arguments[2] : function () { }));
|
|
359
|
-
ops.hideStyle = arg0O.hideStyle || "normal";
|
|
360
|
-
ops.animationStyle = arg0O.animationStyle || (typeof arguments[1] == "string" ? arguments[1] : "ease");
|
|
361
|
-
if (ops.duration > 0) {
|
|
362
|
-
let doneCnt = 0;
|
|
363
|
-
let m = 0;
|
|
364
|
-
let q = this.targets.length;
|
|
365
|
-
for (let i = 0; i < this.targets.length; i++) {
|
|
366
|
-
let w = this.targets[i].style.width;
|
|
367
|
-
let h = this.targets[i].style.height;
|
|
368
|
-
let oStr = this.targets[i].style.opacity;
|
|
369
|
-
let o;
|
|
370
|
-
if (!oStr || oStr === "")
|
|
371
|
-
o = 1;
|
|
372
|
-
else
|
|
373
|
-
o = Number(oStr);
|
|
374
|
-
let ov = this.targets[i].style.overflow;
|
|
375
|
-
if (ops.hideStyle != "fade") {
|
|
376
|
-
this.targets[i].style.overflow = "hidden";
|
|
377
|
-
m += 2;
|
|
378
|
-
(function (that, t, w, h, ov) {
|
|
379
|
-
dotcss(t).width.animate(0, ops.duration, ops.animationStyle, function () {
|
|
380
|
-
dotcss(t).display("none").width(w).overflow(ov); //Restore original overflow value. Only needs to be done once.
|
|
381
|
-
doneCnt++;
|
|
382
|
-
if (doneCnt >= m * q)
|
|
383
|
-
ops.complete(that);
|
|
384
|
-
});
|
|
385
|
-
dotcss(t).height.animate(0, ops.duration, ops.animationStyle, function () {
|
|
386
|
-
dotcss(t).display("none").height(h);
|
|
387
|
-
doneCnt++;
|
|
388
|
-
if (doneCnt >= m * q)
|
|
389
|
-
ops.complete(that);
|
|
390
|
-
});
|
|
391
|
-
})(this, this.targets[i], w, h, ov);
|
|
392
|
-
}
|
|
393
|
-
if (ops.hideStyle != "shrink") {
|
|
394
|
-
m++;
|
|
395
|
-
(function (that, t, o) {
|
|
396
|
-
return dotcss(t).opacity.animate(0, ops.duration, ops.animationStyle, function () {
|
|
397
|
-
dotcss(t).display("none").opacity(o);
|
|
398
|
-
doneCnt++;
|
|
399
|
-
if (doneCnt >= m * q)
|
|
400
|
-
ops.complete(that);
|
|
401
|
-
});
|
|
402
|
-
})(this, this.targets[i], o);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
dotcss(this.targets).display("none");
|
|
408
|
-
ops.complete(this); //This sets the display to none.
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
return this;
|
|
412
|
-
}
|
|
413
|
-
//Usage:
|
|
414
|
-
//show()
|
|
415
|
-
//show(duration, complete)
|
|
416
|
-
//show(options)
|
|
417
|
-
//Options
|
|
418
|
-
// display: inline-block, block, etc.
|
|
419
|
-
// opacity: final opacity.
|
|
420
|
-
// width: final width.
|
|
421
|
-
// height: final height.
|
|
422
|
-
// duration: duration in ms.
|
|
423
|
-
// complete: on-complete callback.
|
|
424
|
-
// showStyle: fade, grow, or normal
|
|
425
|
-
// animationStyle: linear or exponential
|
|
426
|
-
show(style) {
|
|
427
|
-
if (this.targets) {
|
|
428
|
-
let arg0 = arguments[0] || {};
|
|
429
|
-
let arg0N = arg0;
|
|
430
|
-
let arg0O = arg0;
|
|
431
|
-
let ops = {};
|
|
432
|
-
ops.duration = arg0O.duration || (isNaN(arg0N) ? 0 : arg0N) || 0;
|
|
433
|
-
ops.display = arg0O.display || "block";
|
|
434
|
-
ops.opacity = arg0O.opacity;
|
|
435
|
-
ops.width = arg0O.width || null;
|
|
436
|
-
ops.height = arg0O.height || null;
|
|
437
|
-
ops.complete = arg0O.complete || (typeof arguments[1] == "function" ? arguments[1] : (typeof arguments[2] == "function" ? arguments[2] : function () { }));
|
|
438
|
-
ops.showStyle = arg0O.showStyle || "normal";
|
|
439
|
-
ops.animationStyle = arg0O.animationStyle || (typeof arguments[1] == "string" ? arguments[1] : "ease");
|
|
440
|
-
if (ops.duration > 0) {
|
|
441
|
-
let doneCnt = 0;
|
|
442
|
-
let q = this.targets.length;
|
|
443
|
-
let m = 0;
|
|
444
|
-
for (let i = 0; i < this.targets.length; i++) {
|
|
445
|
-
let o = ops.opacity;
|
|
446
|
-
if (ops.opacity === undefined) {
|
|
447
|
-
o = parseFloat(this.targets[i].style.opacity) || 1;
|
|
448
|
-
}
|
|
449
|
-
if (ops.showStyle != "fade") {
|
|
450
|
-
m += 2;
|
|
451
|
-
let w = ops.width || this.targets[i].style.width;
|
|
452
|
-
let h = ops.height || this.targets[i].style.height;
|
|
453
|
-
dotcss(this.targets[i]).width(0);
|
|
454
|
-
dotcss(this.targets[i]).height(0);
|
|
455
|
-
// console.log(doneCnt + " " + q*m);
|
|
456
|
-
dotcss(this.targets[i]).width.animate(w, ops.duration, ops.animationStyle, function () { doneCnt++; if (doneCnt >= q * m)
|
|
457
|
-
ops.complete(); });
|
|
458
|
-
dotcss(this.targets[i]).height.animate(h, ops.duration, ops.animationStyle, function () { doneCnt++; if (doneCnt >= q * m)
|
|
459
|
-
ops.complete(); });
|
|
460
|
-
}
|
|
461
|
-
//let o = this.targets[i].style.opacity; //Guess I should fade to 1?
|
|
462
|
-
dotcss(this.targets[i]).opacity(0);
|
|
463
|
-
dotcss(this.targets[i]).display(ops.display);
|
|
464
|
-
if (ops.showStyle != "grow") {
|
|
465
|
-
m++;
|
|
466
|
-
dotcss(this.targets[i]).opacity.animate(o, ops.duration, ops.animationStyle, function () { doneCnt++; if (doneCnt == q * m)
|
|
467
|
-
ops.complete(); });
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
return dotcss(this.targets).display(ops.display);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
return this;
|
|
476
|
-
}
|
|
477
|
-
fadeOut(duration, complete) {
|
|
478
|
-
return this.hide({
|
|
479
|
-
duration: isNaN(duration) ? 400 : Number(duration),
|
|
480
|
-
hideStyle: "fade",
|
|
481
|
-
complete: complete
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
;
|
|
485
|
-
fadeIn(duration, complete) {
|
|
486
|
-
return this.show({
|
|
487
|
-
duration: isNaN(duration) ? 400 : Number(duration),
|
|
488
|
-
showStyle: "fade",
|
|
489
|
-
complete: complete
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
;
|
|
493
|
-
}
|
|
494
|
-
exports._Builder = _Builder;
|
|
495
|
-
// This could be better handeld. Consider putting it inside the dotcss class.
|
|
496
|
-
dotcss.prototype.toString = _Builder.prototype.toString;
|
|
497
|
-
// Why do we need this?
|
|
498
|
-
class _StyleProperty {
|
|
499
|
-
constructor() {
|
|
500
|
-
//Have to add these back since we're going to replace the __proto__ of a function with this new prototype.
|
|
501
|
-
this.apply = Function.apply;
|
|
502
|
-
this.call = Function.call;
|
|
503
|
-
this.type = null;
|
|
504
|
-
this.jsFriendlyProp = null;
|
|
505
|
-
}
|
|
506
|
-
//toString override gets the value.
|
|
507
|
-
toString() {
|
|
508
|
-
if (dotcss2.lastBuilder.targets) {
|
|
509
|
-
// TODO: this doesn't make sense. Please figure it out.
|
|
510
|
-
let ret = null;
|
|
511
|
-
if (dotcss2.lastBuilder.targets.length > 1) {
|
|
512
|
-
ret = [];
|
|
513
|
-
for (let i = 0; i < dotcss2.lastBuilder.targets.length; i++) {
|
|
514
|
-
ret.push(dotcss2.lastBuilder.targets[i].style[this.jsFriendlyProp]);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
else
|
|
518
|
-
ret = dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp];
|
|
519
|
-
return ret;
|
|
520
|
-
}
|
|
521
|
-
else
|
|
522
|
-
return null;
|
|
523
|
-
}
|
|
524
|
-
//val is another special function that breaks the value into a special object.
|
|
525
|
-
val() {
|
|
526
|
-
if (dotcss2.lastBuilder.targets) {
|
|
527
|
-
let ret = null;
|
|
528
|
-
// TODO: something wrong with this. Types don't check out.
|
|
529
|
-
if (dotcss2.lastBuilder.targets.length > 1) {
|
|
530
|
-
ret = null;
|
|
531
|
-
for (let i = 0; i < dotcss2.lastBuilder.targets.length; i++) {
|
|
532
|
-
if (dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp]) {
|
|
533
|
-
ret.push(dotcss2.convertStyleIntoDotCssObject(dotcss2.lastBuilder.targets[i].style[this.jsFriendlyProp], this.type));
|
|
534
|
-
}
|
|
535
|
-
else
|
|
536
|
-
ret.push(null);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
if (dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp]) {
|
|
541
|
-
ret = dotcss2.convertStyleIntoDotCssObject(dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp], this.type);
|
|
542
|
-
}
|
|
543
|
-
else
|
|
544
|
-
ret = null;
|
|
545
|
-
}
|
|
546
|
-
return ret;
|
|
547
|
-
}
|
|
548
|
-
else
|
|
549
|
-
return null;
|
|
550
|
-
}
|
|
551
|
-
//Ability to animate just like jquery.
|
|
552
|
-
//complete does not get called if the animation was cancelled.
|
|
553
|
-
animate(value, duration, style, complete) {
|
|
554
|
-
duration = isNaN(duration) ? 400 : (duration || 0);
|
|
555
|
-
if (dotcss2.lastBuilder && dotcss2.lastBuilder.targets) {
|
|
556
|
-
if (!complete && style && style.call && style.apply) { //Fix params.
|
|
557
|
-
complete = style;
|
|
558
|
-
style = undefined;
|
|
559
|
-
}
|
|
560
|
-
for (let i = 0; i < dotcss2.lastBuilder.targets.length; i++) {
|
|
561
|
-
let target = dotcss2.lastBuilder.targets[i];
|
|
562
|
-
let oldValue = null;
|
|
563
|
-
let newValue = null;
|
|
564
|
-
let finalValue = null; //newValue might be in different units from the final value...
|
|
565
|
-
//Get the old and new values.
|
|
566
|
-
newValue = dotcss2.convertStyleIntoDotCssObject(value, this.type);
|
|
567
|
-
//If it's a transformation, a little extra work is required.
|
|
568
|
-
//Need to frame all the rotations properly, and combine both the new and the old transformations.
|
|
569
|
-
if (this.type == "transformation") {
|
|
570
|
-
//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.
|
|
571
|
-
//Reason being: linear transformations on matrices are inaccurate. Rotations end up scaling the target.
|
|
572
|
-
//Don't want to get the computed value for transformations.
|
|
573
|
-
oldValue = dotcss2.convertStyleIntoDotCssObject(target.style[this.jsFriendlyProp], this.type);
|
|
574
|
-
}
|
|
575
|
-
if (!oldValue) { //Standard. Happens when the type is not a transformation.
|
|
576
|
-
oldValue = dotcss2.convertStyleIntoDotCssObject(dotcss2.computedStyleOrActualStyle(target, this.jsFriendlyProp), this.type);
|
|
577
|
-
}
|
|
578
|
-
finalValue = newValue.toString();
|
|
579
|
-
//Do a little type/unit checking.
|
|
580
|
-
if (this.type == "length") {
|
|
581
|
-
if (oldValue.units != newValue.units) {
|
|
582
|
-
//Need to rectify this.
|
|
583
|
-
//This can get messy. If one of the lengths is zero, it would minimize the likelihood of an error.
|
|
584
|
-
if (oldValue.length == 0) {
|
|
585
|
-
oldValue.units = newValue.units;
|
|
586
|
-
oldValue.length = 0;
|
|
587
|
-
}
|
|
588
|
-
else if (newValue.length == 0) {
|
|
589
|
-
newValue.units = oldValue.units;
|
|
590
|
-
newValue.length = 0;
|
|
591
|
-
}
|
|
592
|
-
else {
|
|
593
|
-
//Things are messy. Try to mitigate. Convert the old value into the new units, as best we can.
|
|
594
|
-
let currentLengthPx = dotcss.lengthToPx(oldValue.toString(), this.jsFriendlyProp, target);
|
|
595
|
-
let newLengthPx = dotcss.lengthToPx(newValue.toString(), this.jsFriendlyProp, target);
|
|
596
|
-
oldValue.length = currentLengthPx;
|
|
597
|
-
oldValue.units = "px";
|
|
598
|
-
newValue.length = newLengthPx;
|
|
599
|
-
newValue.units = "px";
|
|
600
|
-
//Won't need this anymore.
|
|
601
|
-
//console.warn("Couldn't animate " + this.jsFriendlyProp + ". Inconsistent units.");
|
|
602
|
-
//return dotcss2._lastBuilder;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
else if (this.type == "color") { } //OK
|
|
607
|
-
else if (this.type == "transformation") {
|
|
608
|
-
//Couple things to do here.
|
|
609
|
-
//1. The old and new values must contain the exact same transformation template.
|
|
610
|
-
//2. Angles in the old transformation should be reframed so that they are close to the new angles (or should they)
|
|
611
|
-
let startTransform = "";
|
|
612
|
-
let desiredTransform = "";
|
|
613
|
-
let oldIndex = oldValue.transformations.length - 1;
|
|
614
|
-
let newIndex = newValue.transformations.length - 1;
|
|
615
|
-
while (oldIndex >= 0 || newIndex >= 0) {
|
|
616
|
-
let transformToAdd = "";
|
|
617
|
-
let oldTransformValues = null;
|
|
618
|
-
let newTransformValues = null;
|
|
619
|
-
if (oldIndex >= 0 && newIndex >= 0 && oldValue.transformations[oldIndex].transformation == newValue.transformations[newIndex].transformation) {
|
|
620
|
-
let currentOldT = oldValue.transformations[oldIndex];
|
|
621
|
-
let currentNewT = newValue.transformations[newIndex];
|
|
622
|
-
transformToAdd = currentOldT.transformation;
|
|
623
|
-
oldTransformValues = currentOldT.args;
|
|
624
|
-
newTransformValues = currentNewT.args;
|
|
625
|
-
oldIndex--;
|
|
626
|
-
newIndex--;
|
|
627
|
-
}
|
|
628
|
-
else if (oldIndex >= newIndex) {
|
|
629
|
-
let currentOldT = oldValue.transformations[oldIndex];
|
|
630
|
-
transformToAdd = currentOldT.transformation;
|
|
631
|
-
oldTransformValues = currentOldT.args;
|
|
632
|
-
if (transformToAdd == "matrix") {
|
|
633
|
-
newTransformValues = [1, 0, 0, 1, 0, 0];
|
|
634
|
-
}
|
|
635
|
-
else if (transformToAdd == "matrix3d") {
|
|
636
|
-
newTransformValues = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
let filler = (transformToAdd.indexOf("scale") == -1) ? 0 : 1;
|
|
640
|
-
newTransformValues = [];
|
|
641
|
-
for (let j = 0; j < oldTransformValues.length; j++)
|
|
642
|
-
newTransformValues.push(!isNaN(oldTransformValues[j]) ? filler : (!isNaN(oldTransformValues[j].angle) ? new css_angle_1.default(0) : (!isNaN(oldTransformValues[j].length) ? new css_length_1.default(0) : (0))));
|
|
643
|
-
}
|
|
644
|
-
oldIndex--;
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
let currentNewT = newValue.transformations[newIndex];
|
|
648
|
-
transformToAdd = currentNewT.transformation;
|
|
649
|
-
newTransformValues = currentNewT.args;
|
|
650
|
-
if (transformToAdd == "matrix") {
|
|
651
|
-
oldTransformValues = [1, 0, 0, 1, 0, 0];
|
|
652
|
-
}
|
|
653
|
-
else if (transformToAdd == "matrix3d") {
|
|
654
|
-
oldTransformValues = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
let filler = (transformToAdd.indexOf("scale") == -1) ? 0 : 1;
|
|
658
|
-
oldTransformValues = [];
|
|
659
|
-
for (let j = 0; j < newTransformValues.length; j++)
|
|
660
|
-
oldTransformValues.push(!isNaN(newTransformValues[j]) ? filler : (!isNaN(newTransformValues[j].angle) ? new css_angle_1.default(0) : (!isNaN(newTransformValues[j].length) ? new css_length_1.default(0) : (0))));
|
|
661
|
-
}
|
|
662
|
-
newIndex--;
|
|
663
|
-
}
|
|
664
|
-
startTransform = ") " + startTransform;
|
|
665
|
-
desiredTransform = ") " + desiredTransform;
|
|
666
|
-
//Handle special values here.
|
|
667
|
-
if (transformToAdd.indexOf("rotate") != -1) {
|
|
668
|
-
let oldAngle = oldTransformValues[oldTransformValues.length - 1].angle;
|
|
669
|
-
let newAngle = newTransformValues[newTransformValues.length - 1].angle;
|
|
670
|
-
let sep = dotcss.angleSubtract(newAngle, oldAngle);
|
|
671
|
-
oldTransformValues[oldTransformValues.length - 1].angle = newAngle - sep;
|
|
672
|
-
}
|
|
673
|
-
for (let j = oldTransformValues.length - 1; j >= 0; j--) {
|
|
674
|
-
startTransform = "," + oldTransformValues[i] + startTransform;
|
|
675
|
-
desiredTransform = "," + newTransformValues[i] + desiredTransform;
|
|
676
|
-
}
|
|
677
|
-
startTransform = transformToAdd + "(" + startTransform.substring(1);
|
|
678
|
-
desiredTransform = transformToAdd + "(" + desiredTransform.substring(1);
|
|
679
|
-
}
|
|
680
|
-
oldValue = dotcss2.convertStyleIntoDotCssObject(startTransform, "transformation");
|
|
681
|
-
newValue = dotcss2.convertStyleIntoDotCssObject(desiredTransform, "transformation");
|
|
682
|
-
}
|
|
683
|
-
else if (oldValue.type == "number" && newValue.type == "number") { } //OK
|
|
684
|
-
else if (oldValue.type == "complex" && newValue.type == "complex") {
|
|
685
|
-
if (!dotcss2.compareComplexDataTypes(oldValue, newValue)) {
|
|
686
|
-
console.warn("Couldn't animate " + this.jsFriendlyProp + ". Value mismatch.");
|
|
687
|
-
continue;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
else {
|
|
691
|
-
console.warn("Couldn't animate " + this.jsFriendlyProp + ". Not a recognizable length, color, or number.");
|
|
692
|
-
continue;
|
|
693
|
-
}
|
|
694
|
-
dotcss2.animateFull(target, this.jsFriendlyProp, oldValue.type || this.type, oldValue, newValue, finalValue, dotcss2.fxInterval, duration, style || "ease", complete);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
return dotcss2.lastBuilder;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
;
|
|
701
|
-
dotcss.formatNumberValue = function (value, unit) {
|
|
702
|
-
switch (unit) {
|
|
703
|
-
case "px": return Math.round(value);
|
|
704
|
-
default: return Math.round(value * 100) / 100;
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
// TODO: figure out a way to add vMargin, hMargin, vPadding, etc.
|
|
708
|
-
const _allProps = {
|
|
709
|
-
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",
|
|
710
|
-
length: "background-Size|block-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|gap|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|text-Indent",
|
|
711
|
-
url: "background-Image|border-Image|list-Style-Image|content|image-Orientation",
|
|
712
|
-
transformation: "transform",
|
|
713
|
-
filter: "filter|backdrop-Filter",
|
|
714
|
-
misc: "appearance|aspect-Ratio|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-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|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"
|
|
715
|
-
};
|
|
716
|
-
// const _allTransforms = [
|
|
717
|
-
// "matrix",
|
|
718
|
-
// "matrix3d",
|
|
719
|
-
// "translate",
|
|
720
|
-
// "translate3d",
|
|
721
|
-
// "translateX",
|
|
722
|
-
// "translateY",
|
|
723
|
-
// "translateZ",
|
|
724
|
-
// "scale",
|
|
725
|
-
// "scale3d",
|
|
726
|
-
// "scaleX",
|
|
727
|
-
// "scaleY",
|
|
728
|
-
// "scaleZ",
|
|
729
|
-
// "rotate",
|
|
730
|
-
// "rotate3d",
|
|
731
|
-
// "rotateX",
|
|
732
|
-
// "rotateY",
|
|
733
|
-
// "rotateZ",
|
|
734
|
-
// "skew",
|
|
735
|
-
// "skewX",
|
|
736
|
-
// "skewY",
|
|
737
|
-
// "perspective"
|
|
738
|
-
// ]
|
|
739
|
-
// TODO: this may have been intended to be private.
|
|
740
|
-
dotcss.matrixMultiply3D = function (A, B) {
|
|
741
|
-
if (A.length != 16 || B.length != 16)
|
|
742
|
-
throw "3D matrices must be arrays of 16 length.";
|
|
743
|
-
var ret = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
744
|
-
for (var y = 0; y < 4; y++)
|
|
745
|
-
for (var x = 0; x < 4; x++)
|
|
746
|
-
for (var i = 0; i < 4; i++)
|
|
747
|
-
ret[y + x * 4] += Number(A[y + i * 4]) * Number(B[i + x * 4]);
|
|
748
|
-
return ret;
|
|
749
|
-
};
|
|
750
|
-
//Public functions.
|
|
751
|
-
// TODO: this doesn't really belong in here. This is like a math lib.
|
|
752
|
-
// // TODO: I don't think these are really needed. The css types take care of these.
|
|
753
|
-
// dotcss.angleSubtract = function(a: number, b: number):number{
|
|
754
|
-
// if(a < 0) a = 360 - ((-a) % 360); else a = a % 360;
|
|
755
|
-
// if(b < 0) b = 360 - ((-b) % 360); else b = b % 360;
|
|
756
|
-
// var phi = Math.abs(b - a) % 360;
|
|
757
|
-
// var d = phi > 180 ? 360 - phi : phi;
|
|
758
|
-
// var sign = (a - b >= 0 && a - b <= 180) || (a - b <=-180 && a- b>= -360) ? 1 : -1;
|
|
759
|
-
// return d * sign;
|
|
760
|
-
// };
|
|
761
|
-
// //Special handler for building urls.
|
|
762
|
-
// dotcss.url = function(url: string): string{
|
|
763
|
-
// return `url('${url}')`;
|
|
764
|
-
// };
|
|
765
|
-
// //Special handler for building rgb colors.
|
|
766
|
-
// dotcss.rgb = function(r: number, g: number, b: number): string{
|
|
767
|
-
// return `rgb(${r},${g},${b})`;
|
|
768
|
-
// };
|
|
769
|
-
// //Special handler for building rgba colors.
|
|
770
|
-
// dotcss.rgba = function(r: number, g: number, b: number, a: number): string{
|
|
771
|
-
// return `rgba(${r},${g},${b},${a})`;
|
|
772
|
-
// };
|
|
773
|
-
// We don't do this anymore.
|
|
774
|
-
// dotcss.buildTransform = function(){
|
|
775
|
-
// return new dotcss2._Transform();
|
|
776
|
-
// };
|
|
777
|
-
dotcss["cacheScopedStaticStyles"] = function (el) {
|
|
778
|
-
let elements = getScopedNodeList("*", el);
|
|
779
|
-
for (let element of elements) {
|
|
780
|
-
if (element.hasAttribute("style")) {
|
|
781
|
-
element.setAttribute(STATIC_SYLES_ATTR, element.getAttribute("style"));
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
dotcss["clearDynamicStyles"] = function (el) {
|
|
786
|
-
let elements = getScopedNodeList("*", el);
|
|
787
|
-
for (let element of elements) {
|
|
788
|
-
element.removeAttribute("style");
|
|
789
|
-
if (element.hasAttribute(STATIC_SYLES_ATTR)) {
|
|
790
|
-
element.setAttribute("style", element.getAttribute(STATIC_SYLES_ATTR));
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
dotcss.scopeToEl = function (el) {
|
|
795
|
-
dotcss2.scopeStack.unshift(el);
|
|
796
|
-
return this;
|
|
797
|
-
};
|
|
798
|
-
dotcss.unscope = function () {
|
|
799
|
-
dotcss2.scopeStack.shift();
|
|
800
|
-
return this;
|
|
801
|
-
};
|
|
802
|
-
//Build dotcss.
|
|
803
|
-
for (var k in _allProps) {
|
|
804
|
-
let P = _allProps[k].split("|");
|
|
805
|
-
for (var i in P) {
|
|
806
|
-
dotcss2.extendDothtml(P[i].toLowerCase(), P[i].replace(new RegExp("-", "g"), ""), k);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
// for(let i: number = 0; i < _allLengthUnits.length; i++) dotcss2.makeTransformFunction(_allLengthUnits[i]);
|
|
810
|
-
//dotcss = new dotcss();
|
|
811
|
-
// for (var k in _b) {
|
|
812
|
-
// if(_Builder[k] === undefined) dotcss[k] = _p[k];
|
|
813
|
-
// }
|
|
814
|
-
exports.default = dotcss;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports._Builder = void 0;
|
|
7
|
+
const unit_function_tables_1 = require("./unit-function-tables");
|
|
8
|
+
const css_angle_1 = __importDefault(require("./css-types.ts/css-angle"));
|
|
9
|
+
const css_color_1 = __importDefault(require("./css-types.ts/css-color"));
|
|
10
|
+
const css_complex_1 = __importDefault(require("./css-types.ts/css-complex"));
|
|
11
|
+
const css_length_1 = __importDefault(require("./css-types.ts/css-length"));
|
|
12
|
+
const css_number_1 = __importDefault(require("./css-types.ts/css-number"));
|
|
13
|
+
const css_transform_1 = __importDefault(require("./css-types.ts/css-transform"));
|
|
14
|
+
const css_unknown_1 = __importDefault(require("./css-types.ts/css-unknown"));
|
|
15
|
+
const css_url_1 = __importDefault(require("./css-types.ts/css-url"));
|
|
16
|
+
const dot_util_1 = require("../dot-util");
|
|
17
|
+
const css_filter_1 = __importDefault(require("./css-types.ts/css-filter"));
|
|
18
|
+
//Latest Update.
|
|
19
|
+
/*
|
|
20
|
+
* - Wrapped code in anonymous function.
|
|
21
|
+
* - Hid _Builder and _StyleProperty.
|
|
22
|
+
* - Increased compatibility with IE 8, 9, and 10.
|
|
23
|
+
* - Allowed 0-length animations.
|
|
24
|
+
* 5.1
|
|
25
|
+
* - Typified style builder.
|
|
26
|
+
* - Fixed up transformations and redid transform builder.
|
|
27
|
+
* - Removed some old junk.
|
|
28
|
+
*/
|
|
29
|
+
const STATIC_SYLES_ATTR = "data-dot-static-styles";
|
|
30
|
+
// Rename this to DotcssHelpers.
|
|
31
|
+
// The name Dotcss2 comes from a time when this was a clone of dotcss with "private" members.
|
|
32
|
+
class Dotcss2 {
|
|
33
|
+
constructor() {
|
|
34
|
+
//Inverse of framerate in ms/frame.
|
|
35
|
+
// Used for old browsers that don't support requestAnimationFrameframe.
|
|
36
|
+
this.fxInterval = 1000 / 60;
|
|
37
|
+
this.lastBuilder = null;
|
|
38
|
+
this.scopeStack = [];
|
|
39
|
+
this.globalStyleElement = null;
|
|
40
|
+
}
|
|
41
|
+
animateFull(element, jsFriendlyProp, propType, startValue, targetValue, finalValue, currentTime, totalDuration, animationStyle, callback, lastValue) {
|
|
42
|
+
if (lastValue && element.style[jsFriendlyProp] != lastValue)
|
|
43
|
+
return; //Animation can be cancelled any time by setting the value directly.
|
|
44
|
+
if (totalDuration - currentTime > 0) {
|
|
45
|
+
switch (propType) {
|
|
46
|
+
case "color":
|
|
47
|
+
var r = Math.round((0, dot_util_1.numberStep)(startValue.r, targetValue.r, currentTime, totalDuration, animationStyle));
|
|
48
|
+
var g = Math.round((0, dot_util_1.numberStep)(startValue.g, targetValue.g, currentTime, totalDuration, animationStyle));
|
|
49
|
+
var b = Math.round((0, dot_util_1.numberStep)(startValue.b, targetValue.b, currentTime, totalDuration, animationStyle));
|
|
50
|
+
var a = dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.a, targetValue.a, currentTime, totalDuration, animationStyle)); //TODO: make sure this doesn't need to be rounded or something.
|
|
51
|
+
dotcss(element)[jsFriendlyProp](r, g, b, a);
|
|
52
|
+
break;
|
|
53
|
+
case "length":
|
|
54
|
+
dotcss(element)[jsFriendlyProp](dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.length, targetValue.length, currentTime, totalDuration, animationStyle), startValue.units) + startValue.units);
|
|
55
|
+
break;
|
|
56
|
+
case "transformation":
|
|
57
|
+
var newTransform = "";
|
|
58
|
+
//startValue and targetValue are guaranteed to have the same template.
|
|
59
|
+
for (var i = 0; i < startValue.transformations.length; i++) {
|
|
60
|
+
var t1 = startValue.transformations[i];
|
|
61
|
+
var t2 = targetValue.transformations[i];
|
|
62
|
+
newTransform += t1.transformation + "(";
|
|
63
|
+
for (var k = 0; k < t1.args.length; k++) {
|
|
64
|
+
var v1 = t1.args[k];
|
|
65
|
+
var v2 = t2.args[k];
|
|
66
|
+
var actualV1 = isNaN(v1) ? v1.length || v1.angle || v1.value || 0 : v1;
|
|
67
|
+
var actualV2 = isNaN(v2) ? v2.length || v2.angle || v2.value || 0 : v2;
|
|
68
|
+
var units = isNaN(v1) ? v1.units : "";
|
|
69
|
+
newTransform += dotcss.formatNumberValue((0, dot_util_1.numberStep)(actualV1, actualV2, currentTime, totalDuration, animationStyle), units) + units + ",";
|
|
70
|
+
}
|
|
71
|
+
newTransform = newTransform.substring(0, newTransform.length - 1);
|
|
72
|
+
newTransform += ") ";
|
|
73
|
+
}
|
|
74
|
+
dotcss(element)[jsFriendlyProp](newTransform);
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
switch (startValue.type) {
|
|
78
|
+
case "number":
|
|
79
|
+
dotcss(element)[jsFriendlyProp](dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.value, targetValue.value, currentTime, totalDuration, animationStyle)));
|
|
80
|
+
break;
|
|
81
|
+
case "complex":
|
|
82
|
+
var newVal = "";
|
|
83
|
+
for (var i = 0; i < startValue.numbers.length; i++) {
|
|
84
|
+
newVal += startValue.parts[i];
|
|
85
|
+
newVal += dotcss.formatNumberValue((0, dot_util_1.numberStep)(startValue.numbers[i], targetValue.numbers[i], currentTime, totalDuration, animationStyle));
|
|
86
|
+
}
|
|
87
|
+
newVal += startValue.parts[startValue.parts.length - 1];
|
|
88
|
+
dotcss(element)[jsFriendlyProp](newVal);
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
console.warn("Unexpected data type for animation.");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var now = (window.performance && window.performance.now) ? window.performance.now() : null;
|
|
95
|
+
//var reachedAnimFrame = false;
|
|
96
|
+
//TODO: there could be a memory leak here. Need to investigate.
|
|
97
|
+
//Because we're creating a lot of new functions. Are they being released?
|
|
98
|
+
var last = element.style[jsFriendlyProp];
|
|
99
|
+
var nextStep = function (timestamp) {
|
|
100
|
+
var change = (now ? (window.performance.now() - now) : dotcss2.fxInterval);
|
|
101
|
+
dotcss2.animateFull(element, jsFriendlyProp, propType, startValue, targetValue, finalValue, currentTime + change, totalDuration, animationStyle, callback, last);
|
|
102
|
+
};
|
|
103
|
+
if (window.requestAnimationFrame) {
|
|
104
|
+
window.requestAnimationFrame(nextStep);
|
|
105
|
+
//setTimeout(function(){if(!reachedAnimFrame) console.log("ERROR");}, 100);
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
window.setTimeout(nextStep, dotcss2.fxInterval);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
//TODO: verify that decimal values are properly handled here.
|
|
112
|
+
dotcss(element)[jsFriendlyProp](finalValue);
|
|
113
|
+
if (callback)
|
|
114
|
+
callback();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//Takes the property and generates all the dotcss and builder functions.
|
|
118
|
+
extendDothtml(prop, jsFriendlyProp, type) {
|
|
119
|
+
//Create the new function by extending the builder.
|
|
120
|
+
let _b = _Builder.prototype;
|
|
121
|
+
_b[jsFriendlyProp] = function () {
|
|
122
|
+
if (arguments.length == 0)
|
|
123
|
+
return this;
|
|
124
|
+
var args = [];
|
|
125
|
+
for (var i = 0; i < arguments.length; i++)
|
|
126
|
+
args.push(arguments[i]);
|
|
127
|
+
// TODO: Why can't I just pass arguments directly into this function?
|
|
128
|
+
// Try it.
|
|
129
|
+
var value = dotcss2.convertStyleIntoDotCssObject(args, type).toString();
|
|
130
|
+
var newCss = prop + ":" + value + ";";
|
|
131
|
+
this.currentCss += newCss;
|
|
132
|
+
// console.log(`SETTING ${jsFriendlyProp}:`, this.toString());
|
|
133
|
+
// this.toString()
|
|
134
|
+
if (this.targets) {
|
|
135
|
+
for (var q = 0; q < this.targets.length; q++) {
|
|
136
|
+
//this.targets[q].style += newCss;
|
|
137
|
+
var t = this.targets[q];
|
|
138
|
+
if (t.tagName == "STYLE")
|
|
139
|
+
t.innerHTML = t.innerHTML.substring(0, t.innerHTML.length - 1) + prop + ":" + value + ";}";
|
|
140
|
+
else
|
|
141
|
+
t.style[jsFriendlyProp] = value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return this;
|
|
145
|
+
};
|
|
146
|
+
//Add the new function to the dotcss object so that it can be accessed without doing dotcss().
|
|
147
|
+
dotcss2.addPropFunctionToDotCssObject(jsFriendlyProp);
|
|
148
|
+
//Each unit of length will also have its own version of this function (assuming this is a length property).
|
|
149
|
+
if (type == "length") {
|
|
150
|
+
for (var u = 0; u < unit_function_tables_1.AllLengthUnits.length; u++) {
|
|
151
|
+
var uu = unit_function_tables_1.AllLengthUnits[u];
|
|
152
|
+
(function (uu) {
|
|
153
|
+
_b[jsFriendlyProp + (uu.jsName || uu.unit)] = function () {
|
|
154
|
+
for (var i = 0; i < arguments.length; i++)
|
|
155
|
+
arguments[i] = arguments[i] + uu.unit.toLowerCase();
|
|
156
|
+
return _b[jsFriendlyProp].apply(this, arguments);
|
|
157
|
+
};
|
|
158
|
+
})(uu);
|
|
159
|
+
dotcss2.addPropFunctionToDotCssObject(jsFriendlyProp + (uu.jsName || uu.unit));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//_b[jsFriendlyProp].__proto__ = Object.create(_StyleProperty.prototype);
|
|
163
|
+
_b[jsFriendlyProp].type = type;
|
|
164
|
+
_b[jsFriendlyProp].jsFriendlyProp = jsFriendlyProp;
|
|
165
|
+
// This is weird. It looks like I was trying to implement some form of multilpe inheritance.
|
|
166
|
+
// This should really be upgraded.
|
|
167
|
+
for (var k in _StyleProperty.prototype) {
|
|
168
|
+
if (_b[jsFriendlyProp][k] === undefined)
|
|
169
|
+
_b[jsFriendlyProp][k] = _StyleProperty.prototype[k];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//Returns a JSON object representation of value specific to the cssDataType passed in.
|
|
173
|
+
convertStyleIntoDotCssObject(value, cssDataType) {
|
|
174
|
+
//if(!value) return null;
|
|
175
|
+
if (!(value instanceof Array))
|
|
176
|
+
value = [value];
|
|
177
|
+
if (cssDataType == "color")
|
|
178
|
+
return new css_color_1.default(value);
|
|
179
|
+
else if (cssDataType == "url")
|
|
180
|
+
return new css_url_1.default(value);
|
|
181
|
+
else if (cssDataType == "length" && (!isNaN(value[0]) || (value[0].indexOf(" ") == -1 && value[0].replace(dot_util_1.floatRegex, "") != value[0])))
|
|
182
|
+
return new css_length_1.default(value[0]);
|
|
183
|
+
else if (cssDataType == "transformation")
|
|
184
|
+
return (new css_transform_1.default(value[0])).toString();
|
|
185
|
+
else if (cssDataType == "filter")
|
|
186
|
+
return (new css_filter_1.default(value[0])).toString();
|
|
187
|
+
else {
|
|
188
|
+
if (value[0] === ""
|
|
189
|
+
|| ((isNaN(value[0]))
|
|
190
|
+
&& ("" + value[0]).replace(dot_util_1.floatRegex, "") == value[0]))
|
|
191
|
+
return new css_unknown_1.default(value[0]); //No numbers.
|
|
192
|
+
if (isNaN(value[0]))
|
|
193
|
+
return new css_complex_1.default(value[0]); //Numbers
|
|
194
|
+
else
|
|
195
|
+
return new css_number_1.default(value[0]); //Just a number.
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
;
|
|
199
|
+
//Ensures that two complex values match.
|
|
200
|
+
compareComplexDataTypes(value1, value2) {
|
|
201
|
+
if (value1.type != "complex" || value2.type != "complex")
|
|
202
|
+
return false;
|
|
203
|
+
if (value1.numbers.length != value2.numbers.length)
|
|
204
|
+
return false;
|
|
205
|
+
if (value1.parts.length != value2.parts.length)
|
|
206
|
+
return false;
|
|
207
|
+
for (var i = 0; i < value1.parts.length; i++) {
|
|
208
|
+
if (value1.parts[i] != value2.parts[i])
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
;
|
|
214
|
+
//Adds a builder function directly to the dotcss object so that dotcss doesn't
|
|
215
|
+
//have to be used as a function when a target doesn't need to be specified.
|
|
216
|
+
addPropFunctionToDotCssObject(funcName) {
|
|
217
|
+
dotcss[funcName] = function () {
|
|
218
|
+
var n = new _Builder();
|
|
219
|
+
return n[funcName].apply(n, arguments);
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
;
|
|
223
|
+
// Might remove this.
|
|
224
|
+
// I think this doesn't work. Removing now. Not sure what it was supposed to do.
|
|
225
|
+
// makeTransformFunction(fn){
|
|
226
|
+
// dotcss[fn] = function(){
|
|
227
|
+
// var n = new Transform();
|
|
228
|
+
// return n[fn].apply(n, arguments);
|
|
229
|
+
// };
|
|
230
|
+
// }
|
|
231
|
+
computedStyleOrActualStyle(element, property) {
|
|
232
|
+
return window.getComputedStyle(element)[property] || element.style[property];
|
|
233
|
+
}
|
|
234
|
+
;
|
|
235
|
+
modDeg(a) {
|
|
236
|
+
if (a < 0)
|
|
237
|
+
a = 360 - ((-a) % 360);
|
|
238
|
+
return a % 360;
|
|
239
|
+
}
|
|
240
|
+
;
|
|
241
|
+
}
|
|
242
|
+
const dotcss2 = new Dotcss2();
|
|
243
|
+
const dotcss = function (query) {
|
|
244
|
+
//this.currentCss = "";
|
|
245
|
+
var target = null;
|
|
246
|
+
if (query) {
|
|
247
|
+
// console.log(query, "?");
|
|
248
|
+
if (typeof query == "string") {
|
|
249
|
+
// Creating a style tag. Might not be supported forever.
|
|
250
|
+
if (query.length > 2 && query.indexOf("{}") == query.length - 2) {
|
|
251
|
+
// TODO: this needs further testing, particularly when mulitple sytles are set on the same page.
|
|
252
|
+
// Be sure to set up some tests.
|
|
253
|
+
query = query.substring(0, query.length - 2);
|
|
254
|
+
if (!dotcss2.globalStyleElement) {
|
|
255
|
+
dotcss2.globalStyleElement = document.createElement("style");
|
|
256
|
+
document.head.appendChild(dotcss2.globalStyleElement);
|
|
257
|
+
}
|
|
258
|
+
target = [dotcss2.globalStyleElement];
|
|
259
|
+
target[0].innerHTML += query + "{}\r\n";
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
// This is overly complicated, but here is the spiel.
|
|
263
|
+
// If there's an element on the scopeStack, it should be used with the querySelectorAll.
|
|
264
|
+
// BUT, querySelectorAll doesn't actually select the element it's currently on, which is a requirement for dothtml.
|
|
265
|
+
// To make matters worse, if we do querySelectorAll on the element's parents, we may accidentally select its siblings!!
|
|
266
|
+
// To fix this, we get a list from querySelectorAll on the element, then push the element itself to that list
|
|
267
|
+
// iff it is in the list of elements queried from its parent.
|
|
268
|
+
// In addition to all of that, we don't want scoped styles to be applied to child components.
|
|
269
|
+
var s0 = dotcss2.scopeStack[0];
|
|
270
|
+
// if(s0 instanceof Component){
|
|
271
|
+
// s0 = s0.$el;
|
|
272
|
+
// }
|
|
273
|
+
// If we're doing scoped, and it's an element.
|
|
274
|
+
if (s0 && s0.parentNode && s0.querySelectorAll) {
|
|
275
|
+
// console.log(s0);
|
|
276
|
+
target = getScopedNodeList(query, s0);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
target = document.querySelectorAll(query);
|
|
280
|
+
}
|
|
281
|
+
// target = referencePt.querySelectorAll(query);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if ((query instanceof NodeList) || (query instanceof Array))
|
|
285
|
+
target = query;
|
|
286
|
+
if (query instanceof Node)
|
|
287
|
+
target = [query]; //Doesn't need to be a NodeList. Just iterable.
|
|
288
|
+
}
|
|
289
|
+
dotcss2.lastBuilder = new _Builder(target);
|
|
290
|
+
return dotcss2.lastBuilder;
|
|
291
|
+
}; // We do this because many of the dotcss methods are generated at runtime. Greatly reduces build size.
|
|
292
|
+
dotcss.version = "0.16.0";
|
|
293
|
+
function getScopedNodeList(query, s0) {
|
|
294
|
+
// Get all of the matching child elements of the component. This will not include s0 itself, but it does include nested components.
|
|
295
|
+
// So we will need to manipulate this collection.
|
|
296
|
+
// querySelectorAll returns a NodeList, which we need to convert into an Array.
|
|
297
|
+
var target = Array.from(s0.querySelectorAll(query));
|
|
298
|
+
// console.log(query, s0.className);
|
|
299
|
+
// Exclude nested components.
|
|
300
|
+
for (var t = 0; t < target.length; t++) {
|
|
301
|
+
var T = target[t];
|
|
302
|
+
// Is it a nested component??
|
|
303
|
+
if (T["__dothtml_component"]) {
|
|
304
|
+
// It's a component. Remove it, and all of it's descendants.
|
|
305
|
+
target.splice(t, 1);
|
|
306
|
+
t--;
|
|
307
|
+
var subTargets = T.querySelectorAll(query);
|
|
308
|
+
for (var s = 0; s < subTargets.length; s++) {
|
|
309
|
+
let S = subTargets[s];
|
|
310
|
+
target.splice(target.indexOf(S, t + 1), 1);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Loop through all the sibling nodes until we find s0.
|
|
315
|
+
var parentTargets = Array.from(s0.parentNode.querySelectorAll(query));
|
|
316
|
+
var p = parentTargets.indexOf(s0);
|
|
317
|
+
if (p != -1) {
|
|
318
|
+
target.unshift(parentTargets[p]);
|
|
319
|
+
}
|
|
320
|
+
return target;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* The dotcss builder gets extended with all of the css functions at runtime.
|
|
324
|
+
*/
|
|
325
|
+
class _Builder {
|
|
326
|
+
constructor(targets) {
|
|
327
|
+
this.currentCss = "";
|
|
328
|
+
this.targets = targets ?? null;
|
|
329
|
+
}
|
|
330
|
+
toString() {
|
|
331
|
+
// console.log("CALLED TOSTRING!", this.currentCss);
|
|
332
|
+
return this.currentCss;
|
|
333
|
+
}
|
|
334
|
+
// These methods are a bit strange to have here.
|
|
335
|
+
// They should probably be a part of the dotcss core object or something.
|
|
336
|
+
// Also, they're the only items that are explicitly part of the builder rather than generated.
|
|
337
|
+
//Usage:
|
|
338
|
+
//hide()
|
|
339
|
+
//hide(duration, complete)
|
|
340
|
+
//hide(options)
|
|
341
|
+
//Options
|
|
342
|
+
// display: inline-block, block, etc.
|
|
343
|
+
// duration: duration in ms.
|
|
344
|
+
// complete: on-complete callback.
|
|
345
|
+
// hideStyle: fade, shrink, or normal
|
|
346
|
+
// animationStyle: linear or exponential
|
|
347
|
+
hide(style) {
|
|
348
|
+
if (this.targets) {
|
|
349
|
+
var arg0 = arguments[0] || {};
|
|
350
|
+
var arg0N = arg0;
|
|
351
|
+
var arg0O = arg0;
|
|
352
|
+
var ops = {};
|
|
353
|
+
ops.duration = arg0O.duration || (isNaN(arg0N) ? 0 : arg0N) || 0;
|
|
354
|
+
//ops.display = arg0.display || "none";
|
|
355
|
+
//ops.opacity = arg0.opacity || null;
|
|
356
|
+
//ops.width = arg0.width || null;
|
|
357
|
+
//ops.height = arg0.height || null;
|
|
358
|
+
ops.complete = arg0O.complete || (typeof arguments[1] == "function" ? arguments[1] : (typeof arguments[2] == "function" ? arguments[2] : function () { }));
|
|
359
|
+
ops.hideStyle = arg0O.hideStyle || "normal";
|
|
360
|
+
ops.animationStyle = arg0O.animationStyle || (typeof arguments[1] == "string" ? arguments[1] : "ease");
|
|
361
|
+
if (ops.duration > 0) {
|
|
362
|
+
let doneCnt = 0;
|
|
363
|
+
let m = 0;
|
|
364
|
+
let q = this.targets.length;
|
|
365
|
+
for (let i = 0; i < this.targets.length; i++) {
|
|
366
|
+
let w = this.targets[i].style.width;
|
|
367
|
+
let h = this.targets[i].style.height;
|
|
368
|
+
let oStr = this.targets[i].style.opacity;
|
|
369
|
+
let o;
|
|
370
|
+
if (!oStr || oStr === "")
|
|
371
|
+
o = 1;
|
|
372
|
+
else
|
|
373
|
+
o = Number(oStr);
|
|
374
|
+
let ov = this.targets[i].style.overflow;
|
|
375
|
+
if (ops.hideStyle != "fade") {
|
|
376
|
+
this.targets[i].style.overflow = "hidden";
|
|
377
|
+
m += 2;
|
|
378
|
+
(function (that, t, w, h, ov) {
|
|
379
|
+
dotcss(t).width.animate(0, ops.duration, ops.animationStyle, function () {
|
|
380
|
+
dotcss(t).display("none").width(w).overflow(ov); //Restore original overflow value. Only needs to be done once.
|
|
381
|
+
doneCnt++;
|
|
382
|
+
if (doneCnt >= m * q)
|
|
383
|
+
ops.complete(that);
|
|
384
|
+
});
|
|
385
|
+
dotcss(t).height.animate(0, ops.duration, ops.animationStyle, function () {
|
|
386
|
+
dotcss(t).display("none").height(h);
|
|
387
|
+
doneCnt++;
|
|
388
|
+
if (doneCnt >= m * q)
|
|
389
|
+
ops.complete(that);
|
|
390
|
+
});
|
|
391
|
+
})(this, this.targets[i], w, h, ov);
|
|
392
|
+
}
|
|
393
|
+
if (ops.hideStyle != "shrink") {
|
|
394
|
+
m++;
|
|
395
|
+
(function (that, t, o) {
|
|
396
|
+
return dotcss(t).opacity.animate(0, ops.duration, ops.animationStyle, function () {
|
|
397
|
+
dotcss(t).display("none").opacity(o);
|
|
398
|
+
doneCnt++;
|
|
399
|
+
if (doneCnt >= m * q)
|
|
400
|
+
ops.complete(that);
|
|
401
|
+
});
|
|
402
|
+
})(this, this.targets[i], o);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
dotcss(this.targets).display("none");
|
|
408
|
+
ops.complete(this); //This sets the display to none.
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
//Usage:
|
|
414
|
+
//show()
|
|
415
|
+
//show(duration, complete)
|
|
416
|
+
//show(options)
|
|
417
|
+
//Options
|
|
418
|
+
// display: inline-block, block, etc.
|
|
419
|
+
// opacity: final opacity.
|
|
420
|
+
// width: final width.
|
|
421
|
+
// height: final height.
|
|
422
|
+
// duration: duration in ms.
|
|
423
|
+
// complete: on-complete callback.
|
|
424
|
+
// showStyle: fade, grow, or normal
|
|
425
|
+
// animationStyle: linear or exponential
|
|
426
|
+
show(style) {
|
|
427
|
+
if (this.targets) {
|
|
428
|
+
let arg0 = arguments[0] || {};
|
|
429
|
+
let arg0N = arg0;
|
|
430
|
+
let arg0O = arg0;
|
|
431
|
+
let ops = {};
|
|
432
|
+
ops.duration = arg0O.duration || (isNaN(arg0N) ? 0 : arg0N) || 0;
|
|
433
|
+
ops.display = arg0O.display || "block";
|
|
434
|
+
ops.opacity = arg0O.opacity;
|
|
435
|
+
ops.width = arg0O.width || null;
|
|
436
|
+
ops.height = arg0O.height || null;
|
|
437
|
+
ops.complete = arg0O.complete || (typeof arguments[1] == "function" ? arguments[1] : (typeof arguments[2] == "function" ? arguments[2] : function () { }));
|
|
438
|
+
ops.showStyle = arg0O.showStyle || "normal";
|
|
439
|
+
ops.animationStyle = arg0O.animationStyle || (typeof arguments[1] == "string" ? arguments[1] : "ease");
|
|
440
|
+
if (ops.duration > 0) {
|
|
441
|
+
let doneCnt = 0;
|
|
442
|
+
let q = this.targets.length;
|
|
443
|
+
let m = 0;
|
|
444
|
+
for (let i = 0; i < this.targets.length; i++) {
|
|
445
|
+
let o = ops.opacity;
|
|
446
|
+
if (ops.opacity === undefined) {
|
|
447
|
+
o = parseFloat(this.targets[i].style.opacity) || 1;
|
|
448
|
+
}
|
|
449
|
+
if (ops.showStyle != "fade") {
|
|
450
|
+
m += 2;
|
|
451
|
+
let w = ops.width || this.targets[i].style.width;
|
|
452
|
+
let h = ops.height || this.targets[i].style.height;
|
|
453
|
+
dotcss(this.targets[i]).width(0);
|
|
454
|
+
dotcss(this.targets[i]).height(0);
|
|
455
|
+
// console.log(doneCnt + " " + q*m);
|
|
456
|
+
dotcss(this.targets[i]).width.animate(w, ops.duration, ops.animationStyle, function () { doneCnt++; if (doneCnt >= q * m)
|
|
457
|
+
ops.complete(); });
|
|
458
|
+
dotcss(this.targets[i]).height.animate(h, ops.duration, ops.animationStyle, function () { doneCnt++; if (doneCnt >= q * m)
|
|
459
|
+
ops.complete(); });
|
|
460
|
+
}
|
|
461
|
+
//let o = this.targets[i].style.opacity; //Guess I should fade to 1?
|
|
462
|
+
dotcss(this.targets[i]).opacity(0);
|
|
463
|
+
dotcss(this.targets[i]).display(ops.display);
|
|
464
|
+
if (ops.showStyle != "grow") {
|
|
465
|
+
m++;
|
|
466
|
+
dotcss(this.targets[i]).opacity.animate(o, ops.duration, ops.animationStyle, function () { doneCnt++; if (doneCnt == q * m)
|
|
467
|
+
ops.complete(); });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
return dotcss(this.targets).display(ops.display);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return this;
|
|
476
|
+
}
|
|
477
|
+
fadeOut(duration, complete) {
|
|
478
|
+
return this.hide({
|
|
479
|
+
duration: isNaN(duration) ? 400 : Number(duration),
|
|
480
|
+
hideStyle: "fade",
|
|
481
|
+
complete: complete
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
;
|
|
485
|
+
fadeIn(duration, complete) {
|
|
486
|
+
return this.show({
|
|
487
|
+
duration: isNaN(duration) ? 400 : Number(duration),
|
|
488
|
+
showStyle: "fade",
|
|
489
|
+
complete: complete
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
;
|
|
493
|
+
}
|
|
494
|
+
exports._Builder = _Builder;
|
|
495
|
+
// This could be better handeld. Consider putting it inside the dotcss class.
|
|
496
|
+
dotcss.prototype.toString = _Builder.prototype.toString;
|
|
497
|
+
// Why do we need this?
|
|
498
|
+
class _StyleProperty {
|
|
499
|
+
constructor() {
|
|
500
|
+
//Have to add these back since we're going to replace the __proto__ of a function with this new prototype.
|
|
501
|
+
this.apply = Function.apply;
|
|
502
|
+
this.call = Function.call;
|
|
503
|
+
this.type = null;
|
|
504
|
+
this.jsFriendlyProp = null;
|
|
505
|
+
}
|
|
506
|
+
//toString override gets the value.
|
|
507
|
+
toString() {
|
|
508
|
+
if (dotcss2.lastBuilder.targets) {
|
|
509
|
+
// TODO: this doesn't make sense. Please figure it out.
|
|
510
|
+
let ret = null;
|
|
511
|
+
if (dotcss2.lastBuilder.targets.length > 1) {
|
|
512
|
+
ret = [];
|
|
513
|
+
for (let i = 0; i < dotcss2.lastBuilder.targets.length; i++) {
|
|
514
|
+
ret.push(dotcss2.lastBuilder.targets[i].style[this.jsFriendlyProp]);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
else
|
|
518
|
+
ret = dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp];
|
|
519
|
+
return ret;
|
|
520
|
+
}
|
|
521
|
+
else
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
//val is another special function that breaks the value into a special object.
|
|
525
|
+
val() {
|
|
526
|
+
if (dotcss2.lastBuilder.targets) {
|
|
527
|
+
let ret = null;
|
|
528
|
+
// TODO: something wrong with this. Types don't check out.
|
|
529
|
+
if (dotcss2.lastBuilder.targets.length > 1) {
|
|
530
|
+
ret = null;
|
|
531
|
+
for (let i = 0; i < dotcss2.lastBuilder.targets.length; i++) {
|
|
532
|
+
if (dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp]) {
|
|
533
|
+
ret.push(dotcss2.convertStyleIntoDotCssObject(dotcss2.lastBuilder.targets[i].style[this.jsFriendlyProp], this.type));
|
|
534
|
+
}
|
|
535
|
+
else
|
|
536
|
+
ret.push(null);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
if (dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp]) {
|
|
541
|
+
ret = dotcss2.convertStyleIntoDotCssObject(dotcss2.lastBuilder.targets[0].style[this.jsFriendlyProp], this.type);
|
|
542
|
+
}
|
|
543
|
+
else
|
|
544
|
+
ret = null;
|
|
545
|
+
}
|
|
546
|
+
return ret;
|
|
547
|
+
}
|
|
548
|
+
else
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
//Ability to animate just like jquery.
|
|
552
|
+
//complete does not get called if the animation was cancelled.
|
|
553
|
+
animate(value, duration, style, complete) {
|
|
554
|
+
duration = isNaN(duration) ? 400 : (duration || 0);
|
|
555
|
+
if (dotcss2.lastBuilder && dotcss2.lastBuilder.targets) {
|
|
556
|
+
if (!complete && style && style.call && style.apply) { //Fix params.
|
|
557
|
+
complete = style;
|
|
558
|
+
style = undefined;
|
|
559
|
+
}
|
|
560
|
+
for (let i = 0; i < dotcss2.lastBuilder.targets.length; i++) {
|
|
561
|
+
let target = dotcss2.lastBuilder.targets[i];
|
|
562
|
+
let oldValue = null;
|
|
563
|
+
let newValue = null;
|
|
564
|
+
let finalValue = null; //newValue might be in different units from the final value...
|
|
565
|
+
//Get the old and new values.
|
|
566
|
+
newValue = dotcss2.convertStyleIntoDotCssObject(value, this.type);
|
|
567
|
+
//If it's a transformation, a little extra work is required.
|
|
568
|
+
//Need to frame all the rotations properly, and combine both the new and the old transformations.
|
|
569
|
+
if (this.type == "transformation") {
|
|
570
|
+
//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.
|
|
571
|
+
//Reason being: linear transformations on matrices are inaccurate. Rotations end up scaling the target.
|
|
572
|
+
//Don't want to get the computed value for transformations.
|
|
573
|
+
oldValue = dotcss2.convertStyleIntoDotCssObject(target.style[this.jsFriendlyProp], this.type);
|
|
574
|
+
}
|
|
575
|
+
if (!oldValue) { //Standard. Happens when the type is not a transformation.
|
|
576
|
+
oldValue = dotcss2.convertStyleIntoDotCssObject(dotcss2.computedStyleOrActualStyle(target, this.jsFriendlyProp), this.type);
|
|
577
|
+
}
|
|
578
|
+
finalValue = newValue.toString();
|
|
579
|
+
//Do a little type/unit checking.
|
|
580
|
+
if (this.type == "length") {
|
|
581
|
+
if (oldValue.units != newValue.units) {
|
|
582
|
+
//Need to rectify this.
|
|
583
|
+
//This can get messy. If one of the lengths is zero, it would minimize the likelihood of an error.
|
|
584
|
+
if (oldValue.length == 0) {
|
|
585
|
+
oldValue.units = newValue.units;
|
|
586
|
+
oldValue.length = 0;
|
|
587
|
+
}
|
|
588
|
+
else if (newValue.length == 0) {
|
|
589
|
+
newValue.units = oldValue.units;
|
|
590
|
+
newValue.length = 0;
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
//Things are messy. Try to mitigate. Convert the old value into the new units, as best we can.
|
|
594
|
+
let currentLengthPx = dotcss.lengthToPx(oldValue.toString(), this.jsFriendlyProp, target);
|
|
595
|
+
let newLengthPx = dotcss.lengthToPx(newValue.toString(), this.jsFriendlyProp, target);
|
|
596
|
+
oldValue.length = currentLengthPx;
|
|
597
|
+
oldValue.units = "px";
|
|
598
|
+
newValue.length = newLengthPx;
|
|
599
|
+
newValue.units = "px";
|
|
600
|
+
//Won't need this anymore.
|
|
601
|
+
//console.warn("Couldn't animate " + this.jsFriendlyProp + ". Inconsistent units.");
|
|
602
|
+
//return dotcss2._lastBuilder;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
else if (this.type == "color") { } //OK
|
|
607
|
+
else if (this.type == "transformation") {
|
|
608
|
+
//Couple things to do here.
|
|
609
|
+
//1. The old and new values must contain the exact same transformation template.
|
|
610
|
+
//2. Angles in the old transformation should be reframed so that they are close to the new angles (or should they)
|
|
611
|
+
let startTransform = "";
|
|
612
|
+
let desiredTransform = "";
|
|
613
|
+
let oldIndex = oldValue.transformations.length - 1;
|
|
614
|
+
let newIndex = newValue.transformations.length - 1;
|
|
615
|
+
while (oldIndex >= 0 || newIndex >= 0) {
|
|
616
|
+
let transformToAdd = "";
|
|
617
|
+
let oldTransformValues = null;
|
|
618
|
+
let newTransformValues = null;
|
|
619
|
+
if (oldIndex >= 0 && newIndex >= 0 && oldValue.transformations[oldIndex].transformation == newValue.transformations[newIndex].transformation) {
|
|
620
|
+
let currentOldT = oldValue.transformations[oldIndex];
|
|
621
|
+
let currentNewT = newValue.transformations[newIndex];
|
|
622
|
+
transformToAdd = currentOldT.transformation;
|
|
623
|
+
oldTransformValues = currentOldT.args;
|
|
624
|
+
newTransformValues = currentNewT.args;
|
|
625
|
+
oldIndex--;
|
|
626
|
+
newIndex--;
|
|
627
|
+
}
|
|
628
|
+
else if (oldIndex >= newIndex) {
|
|
629
|
+
let currentOldT = oldValue.transformations[oldIndex];
|
|
630
|
+
transformToAdd = currentOldT.transformation;
|
|
631
|
+
oldTransformValues = currentOldT.args;
|
|
632
|
+
if (transformToAdd == "matrix") {
|
|
633
|
+
newTransformValues = [1, 0, 0, 1, 0, 0];
|
|
634
|
+
}
|
|
635
|
+
else if (transformToAdd == "matrix3d") {
|
|
636
|
+
newTransformValues = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
let filler = (transformToAdd.indexOf("scale") == -1) ? 0 : 1;
|
|
640
|
+
newTransformValues = [];
|
|
641
|
+
for (let j = 0; j < oldTransformValues.length; j++)
|
|
642
|
+
newTransformValues.push(!isNaN(oldTransformValues[j]) ? filler : (!isNaN(oldTransformValues[j].angle) ? new css_angle_1.default(0) : (!isNaN(oldTransformValues[j].length) ? new css_length_1.default(0) : (0))));
|
|
643
|
+
}
|
|
644
|
+
oldIndex--;
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
let currentNewT = newValue.transformations[newIndex];
|
|
648
|
+
transformToAdd = currentNewT.transformation;
|
|
649
|
+
newTransformValues = currentNewT.args;
|
|
650
|
+
if (transformToAdd == "matrix") {
|
|
651
|
+
oldTransformValues = [1, 0, 0, 1, 0, 0];
|
|
652
|
+
}
|
|
653
|
+
else if (transformToAdd == "matrix3d") {
|
|
654
|
+
oldTransformValues = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
657
|
+
let filler = (transformToAdd.indexOf("scale") == -1) ? 0 : 1;
|
|
658
|
+
oldTransformValues = [];
|
|
659
|
+
for (let j = 0; j < newTransformValues.length; j++)
|
|
660
|
+
oldTransformValues.push(!isNaN(newTransformValues[j]) ? filler : (!isNaN(newTransformValues[j].angle) ? new css_angle_1.default(0) : (!isNaN(newTransformValues[j].length) ? new css_length_1.default(0) : (0))));
|
|
661
|
+
}
|
|
662
|
+
newIndex--;
|
|
663
|
+
}
|
|
664
|
+
startTransform = ") " + startTransform;
|
|
665
|
+
desiredTransform = ") " + desiredTransform;
|
|
666
|
+
//Handle special values here.
|
|
667
|
+
if (transformToAdd.indexOf("rotate") != -1) {
|
|
668
|
+
let oldAngle = oldTransformValues[oldTransformValues.length - 1].angle;
|
|
669
|
+
let newAngle = newTransformValues[newTransformValues.length - 1].angle;
|
|
670
|
+
let sep = dotcss.angleSubtract(newAngle, oldAngle);
|
|
671
|
+
oldTransformValues[oldTransformValues.length - 1].angle = newAngle - sep;
|
|
672
|
+
}
|
|
673
|
+
for (let j = oldTransformValues.length - 1; j >= 0; j--) {
|
|
674
|
+
startTransform = "," + oldTransformValues[i] + startTransform;
|
|
675
|
+
desiredTransform = "," + newTransformValues[i] + desiredTransform;
|
|
676
|
+
}
|
|
677
|
+
startTransform = transformToAdd + "(" + startTransform.substring(1);
|
|
678
|
+
desiredTransform = transformToAdd + "(" + desiredTransform.substring(1);
|
|
679
|
+
}
|
|
680
|
+
oldValue = dotcss2.convertStyleIntoDotCssObject(startTransform, "transformation");
|
|
681
|
+
newValue = dotcss2.convertStyleIntoDotCssObject(desiredTransform, "transformation");
|
|
682
|
+
}
|
|
683
|
+
else if (oldValue.type == "number" && newValue.type == "number") { } //OK
|
|
684
|
+
else if (oldValue.type == "complex" && newValue.type == "complex") {
|
|
685
|
+
if (!dotcss2.compareComplexDataTypes(oldValue, newValue)) {
|
|
686
|
+
console.warn("Couldn't animate " + this.jsFriendlyProp + ". Value mismatch.");
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
console.warn("Couldn't animate " + this.jsFriendlyProp + ". Not a recognizable length, color, or number.");
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
dotcss2.animateFull(target, this.jsFriendlyProp, oldValue.type || this.type, oldValue, newValue, finalValue, dotcss2.fxInterval, duration, style || "ease", complete);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return dotcss2.lastBuilder;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
;
|
|
701
|
+
dotcss.formatNumberValue = function (value, unit) {
|
|
702
|
+
switch (unit) {
|
|
703
|
+
case "px": return Math.round(value);
|
|
704
|
+
default: return Math.round(value * 100) / 100;
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
// TODO: figure out a way to add vMargin, hMargin, vPadding, etc.
|
|
708
|
+
const _allProps = {
|
|
709
|
+
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",
|
|
710
|
+
length: "background-Size|block-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|gap|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|text-Indent",
|
|
711
|
+
url: "background-Image|border-Image|list-Style-Image|content|image-Orientation",
|
|
712
|
+
transformation: "transform",
|
|
713
|
+
filter: "filter|backdrop-Filter",
|
|
714
|
+
misc: "appearance|aspect-Ratio|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-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|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"
|
|
715
|
+
};
|
|
716
|
+
// const _allTransforms = [
|
|
717
|
+
// "matrix",
|
|
718
|
+
// "matrix3d",
|
|
719
|
+
// "translate",
|
|
720
|
+
// "translate3d",
|
|
721
|
+
// "translateX",
|
|
722
|
+
// "translateY",
|
|
723
|
+
// "translateZ",
|
|
724
|
+
// "scale",
|
|
725
|
+
// "scale3d",
|
|
726
|
+
// "scaleX",
|
|
727
|
+
// "scaleY",
|
|
728
|
+
// "scaleZ",
|
|
729
|
+
// "rotate",
|
|
730
|
+
// "rotate3d",
|
|
731
|
+
// "rotateX",
|
|
732
|
+
// "rotateY",
|
|
733
|
+
// "rotateZ",
|
|
734
|
+
// "skew",
|
|
735
|
+
// "skewX",
|
|
736
|
+
// "skewY",
|
|
737
|
+
// "perspective"
|
|
738
|
+
// ]
|
|
739
|
+
// TODO: this may have been intended to be private.
|
|
740
|
+
dotcss.matrixMultiply3D = function (A, B) {
|
|
741
|
+
if (A.length != 16 || B.length != 16)
|
|
742
|
+
throw "3D matrices must be arrays of 16 length.";
|
|
743
|
+
var ret = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
744
|
+
for (var y = 0; y < 4; y++)
|
|
745
|
+
for (var x = 0; x < 4; x++)
|
|
746
|
+
for (var i = 0; i < 4; i++)
|
|
747
|
+
ret[y + x * 4] += Number(A[y + i * 4]) * Number(B[i + x * 4]);
|
|
748
|
+
return ret;
|
|
749
|
+
};
|
|
750
|
+
//Public functions.
|
|
751
|
+
// TODO: this doesn't really belong in here. This is like a math lib.
|
|
752
|
+
// // TODO: I don't think these are really needed. The css types take care of these.
|
|
753
|
+
// dotcss.angleSubtract = function(a: number, b: number):number{
|
|
754
|
+
// if(a < 0) a = 360 - ((-a) % 360); else a = a % 360;
|
|
755
|
+
// if(b < 0) b = 360 - ((-b) % 360); else b = b % 360;
|
|
756
|
+
// var phi = Math.abs(b - a) % 360;
|
|
757
|
+
// var d = phi > 180 ? 360 - phi : phi;
|
|
758
|
+
// var sign = (a - b >= 0 && a - b <= 180) || (a - b <=-180 && a- b>= -360) ? 1 : -1;
|
|
759
|
+
// return d * sign;
|
|
760
|
+
// };
|
|
761
|
+
// //Special handler for building urls.
|
|
762
|
+
// dotcss.url = function(url: string): string{
|
|
763
|
+
// return `url('${url}')`;
|
|
764
|
+
// };
|
|
765
|
+
// //Special handler for building rgb colors.
|
|
766
|
+
// dotcss.rgb = function(r: number, g: number, b: number): string{
|
|
767
|
+
// return `rgb(${r},${g},${b})`;
|
|
768
|
+
// };
|
|
769
|
+
// //Special handler for building rgba colors.
|
|
770
|
+
// dotcss.rgba = function(r: number, g: number, b: number, a: number): string{
|
|
771
|
+
// return `rgba(${r},${g},${b},${a})`;
|
|
772
|
+
// };
|
|
773
|
+
// We don't do this anymore.
|
|
774
|
+
// dotcss.buildTransform = function(){
|
|
775
|
+
// return new dotcss2._Transform();
|
|
776
|
+
// };
|
|
777
|
+
dotcss["cacheScopedStaticStyles"] = function (el) {
|
|
778
|
+
let elements = getScopedNodeList("*", el);
|
|
779
|
+
for (let element of elements) {
|
|
780
|
+
if (element.hasAttribute("style")) {
|
|
781
|
+
element.setAttribute(STATIC_SYLES_ATTR, element.getAttribute("style"));
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
dotcss["clearDynamicStyles"] = function (el) {
|
|
786
|
+
let elements = getScopedNodeList("*", el);
|
|
787
|
+
for (let element of elements) {
|
|
788
|
+
element.removeAttribute("style");
|
|
789
|
+
if (element.hasAttribute(STATIC_SYLES_ATTR)) {
|
|
790
|
+
element.setAttribute("style", element.getAttribute(STATIC_SYLES_ATTR));
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
dotcss.scopeToEl = function (el) {
|
|
795
|
+
dotcss2.scopeStack.unshift(el);
|
|
796
|
+
return this;
|
|
797
|
+
};
|
|
798
|
+
dotcss.unscope = function () {
|
|
799
|
+
dotcss2.scopeStack.shift();
|
|
800
|
+
return this;
|
|
801
|
+
};
|
|
802
|
+
//Build dotcss.
|
|
803
|
+
for (var k in _allProps) {
|
|
804
|
+
let P = _allProps[k].split("|");
|
|
805
|
+
for (var i in P) {
|
|
806
|
+
dotcss2.extendDothtml(P[i].toLowerCase(), P[i].replace(new RegExp("-", "g"), ""), k);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
// for(let i: number = 0; i < _allLengthUnits.length; i++) dotcss2.makeTransformFunction(_allLengthUnits[i]);
|
|
810
|
+
//dotcss = new dotcss();
|
|
811
|
+
// for (var k in _b) {
|
|
812
|
+
// if(_Builder[k] === undefined) dotcss[k] = _p[k];
|
|
813
|
+
// }
|
|
814
|
+
exports.default = dotcss;
|
|
815
815
|
//# sourceMappingURL=style-builder.js.map
|