dothtml 5.0.4 → 5.1.1

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.
Files changed (54) hide show
  1. package/.vscode/launch.json +34 -0
  2. package/.vscode/settings.json +2 -1
  3. package/lib/component.d.ts +12 -3
  4. package/lib/dot-util.d.ts +13 -0
  5. package/lib/dothtml.d.ts +1 -1
  6. package/lib/dothtml.js +1 -1
  7. package/lib/i-dot.d.ts +4 -4
  8. package/lib/styling/css-types.ts/css-angle.d.ts +7 -0
  9. package/lib/styling/css-types.ts/css-color.d.ts +9 -0
  10. package/lib/styling/css-types.ts/css-complex.d.ts +7 -0
  11. package/lib/styling/css-types.ts/css-data-type.d.ts +5 -0
  12. package/lib/styling/css-types.ts/css-length.d.ts +7 -0
  13. package/lib/styling/css-types.ts/css-number.d.ts +6 -0
  14. package/lib/styling/css-types.ts/css-transform.d.ts +38 -0
  15. package/lib/styling/css-types.ts/css-unknown.d.ts +6 -0
  16. package/lib/styling/css-types.ts/css-url.d.ts +6 -0
  17. package/lib/{i-dotcss.d.ts → styling/i-dotcss.d.ts} +192 -42
  18. package/lib/styling/style-builder.d.ts +24 -0
  19. package/lib/styling/unit-function-tables.d.ts +10 -0
  20. package/package.json +2 -2
  21. package/src/component.ts +77 -31
  22. package/src/dot-util.ts +37 -1
  23. package/src/dot.ts +2 -2
  24. package/src/dothtml.ts +1 -1
  25. package/src/i-dot.ts +1 -1
  26. package/src/styling/css-types.ts/css-angle.ts +18 -0
  27. package/src/styling/css-types.ts/css-color.ts +229 -0
  28. package/src/styling/css-types.ts/css-complex.ts +20 -0
  29. package/src/styling/css-types.ts/css-data-type.ts +9 -0
  30. package/src/styling/css-types.ts/css-length.ts +20 -0
  31. package/src/styling/css-types.ts/css-number.ts +12 -0
  32. package/src/styling/css-types.ts/css-transform.ts +220 -0
  33. package/src/styling/css-types.ts/css-unknown.ts +13 -0
  34. package/src/styling/css-types.ts/css-url.ts +41 -0
  35. package/src/{i-dotcss.ts → styling/i-dotcss.ts} +206 -49
  36. package/src/styling/style-builder.ts +963 -0
  37. package/src/styling/unit-function-tables.ts +24 -0
  38. package/unittests/basic-functionality.test.ts +1 -1
  39. package/unittests/calc.test.ts +2 -0
  40. package/unittests/{component-decorator.-.ts → components/component-decorator.-.ts} +0 -0
  41. package/unittests/{components-data.test.ts → components/components-data.test.ts} +3 -3
  42. package/unittests/{components.test.ts → components/components.test.ts} +5 -4
  43. package/unittests/input-bindings.test.ts +6 -6
  44. package/unittests/non-function-props-rerender.test.ts +85 -0
  45. package/unittests/styling/animations.test.ts +14 -0
  46. package/unittests/styling/inline-styling.test.ts +18 -0
  47. package/unittests/styling/pseudo-selectors.test.ts +29 -0
  48. package/unittests/styling/transformations.test.ts +234 -0
  49. package/{lib/dot-component-legacy.d.ts → unittests/styling/value-interpretation.test.ts} +0 -0
  50. package/lib/dot-document.d.ts +0 -0
  51. package/lib/style-builder.d.ts +0 -3
  52. package/src/dot-component-legacy.ts +0 -79
  53. package/src/dot-document.ts +0 -0
  54. package/src/style-builder.ts +0 -1516
package/src/component.ts CHANGED
@@ -4,7 +4,7 @@ import { ClassPrefix, eachK, GlobalComponentStack, isF, sT } from "./dot-util";
4
4
  import ERR from "./err";
5
5
  import { IDotDocument, IDotElement, IDotElementDocument, IDotGenericElement } from "./i-dot";
6
6
  import { ArgCallback, ArrayArgCallback, AttrArgCallback } from "./arg-callback-obj";
7
- import IDotCss from "./i-dotcss";
7
+ import IDotCss from "./styling/i-dotcss";
8
8
 
9
9
  interface IPropertyContainer{
10
10
  activePropConstructor: Function;
@@ -19,6 +19,22 @@ interface IPropertyContainer{
19
19
 
20
20
  abstract class Component{
21
21
 
22
+ /**
23
+ * Used internally to indicate the first time $updateStyles is called.
24
+ * This method is called by the static component builder when the component is created.
25
+ * If a prop is accessed within the style builder, the getter reads this field to mark $updateStyles as a dependency.
26
+ */
27
+ #initializingStyles: boolean = false;
28
+ #initializingBuild: boolean = false;
29
+ // A bit messy but gets us to MVP for this feature.
30
+ // Ideally this should be made a singleton somehow, perhaps put in the property metadata.
31
+ #rebuildStylesOnPropChange: {[propName: string]: true} = {};
32
+ #rebuildBuilderOnPropChange: {[propName: string]: true} = {};
33
+
34
+ /**
35
+ * Called once per component, on the first build.
36
+ * TODO: this shouldn't require an instance of the component. Please experiment with fixing this.
37
+ */
22
38
  static initializeComponent<T extends Component>(obj: T): void{
23
39
  if(!(obj.constructor as any).__dotComponentInitialized) {
24
40
  (obj.constructor as any).__dotComponentInitialized = true;
@@ -36,7 +52,7 @@ abstract class Component{
36
52
 
37
53
  }
38
54
 
39
- static build<T extends Component>(obj: T): Element{
55
+ static build<T extends Component>(obj: T): HTMLElement{
40
56
  Component.initializeComponent(obj);
41
57
 
42
58
  GlobalComponentStack.push(obj);
@@ -87,20 +103,45 @@ abstract class Component{
87
103
 
88
104
  Component.initializeEventHandlers(obj);
89
105
 
106
+ Component.rebuild(obj);
107
+
108
+ // TODO: would be great to do this without a timer, once the DOM is updated.
109
+ // May require some type of queueing system within dot.
110
+ obj.ready && sT(()=>{
111
+ GlobalComponentStack.push(obj);
112
+ obj.ready();
113
+ GlobalComponentStack.pop()
114
+ }, 0);
115
+
116
+ GlobalComponentStack.pop();
117
+
118
+ return obj.$el;
119
+ }
120
+
121
+ /**
122
+ * Called any time the component needs to be completely rebuilt.
123
+ */
124
+ static rebuild<T extends Component>(obj: T) {
125
+
126
+ let oldEl = obj.$el;
127
+
128
+ if(!obj.__eventsInitialized) obj.#initializingBuild = true;
90
129
  let ret = obj.builder(...obj.__args);
130
+ obj.#initializingBuild = false;
91
131
 
92
132
  let lst = ret.getLast();
93
133
  (!lst || (lst.parentNode.childNodes.length > 1)) && ERR("C#", obj.name || obj.constructor.name || "(unnamed obj)");
94
134
 
95
-
96
-
97
- // Some weird ass logic to support legacy named components and the new syntax.
98
- // if(classNumb || n) ret = (obj instanceof DotDocument ? obj : dot)._appendOrCreateDocument(dot.scopeClass(classNumb, ret));
99
- // ret = ret.scopeClass(ret, (obj.constructor as any).__dotClassNumb);
100
-
101
- obj["__$el"] = obj.$el || lst;
135
+
136
+ // Note: I don't know what the justification was for using $obj.el, but all tests pass without it.
137
+ // It was removed to facilitate rebuilding the component (during a prop change).
138
+ obj["__$el"] = /*obj.$el ||*/ lst;
102
139
  obj.$el["__dothtml_component"] = obj;
103
-
140
+
141
+ if(oldEl){
142
+ // Clean it up and replace it with the new element!
143
+ }
144
+
104
145
  // TODO: would there be a way to not have to create obj function for each instance?
105
146
  if(obj.style) {
106
147
  // obj will be the officially supported way to use dothtml.
@@ -115,23 +156,13 @@ abstract class Component{
115
156
  obj.style(dot.css);
116
157
  dot.css.unscope();
117
158
  }
159
+ if(!obj.__eventsInitialized) obj.#initializingStyles = true;
118
160
  obj.$updateStyles();
161
+ obj.#initializingStyles = false;
119
162
  //styler();
120
163
  }
121
164
 
122
165
  obj.built && obj.built();
123
-
124
- // TODO: would be great to do this without a timer, once the DOM is updated.
125
- // May require some type of queueing system within dot.
126
- obj.ready && sT(()=>{
127
- GlobalComponentStack.push(obj);
128
- obj.ready();
129
- GlobalComponentStack.pop()
130
- }, 0);
131
-
132
- GlobalComponentStack.pop();
133
-
134
- return obj.$el;
135
166
  }
136
167
 
137
168
  static initializeEventHandlers(obj){
@@ -238,6 +269,14 @@ abstract class Component{
238
269
  if(!ar) ar = cc.__propContainer.propDependencies[name] = [];
239
270
  ar.push(cb);
240
271
  }
272
+
273
+ // Again I find this a weird way to do it that kind of side-steps the above approach, but it gets the job done and is dead simple.
274
+ if(cc.#initializingStyles){
275
+ cc.#rebuildStylesOnPropChange[name] = true;
276
+ }
277
+ if(cc.#initializingBuild){
278
+ cc.#rebuildBuilderOnPropChange[name] = true;
279
+ }
241
280
  }
242
281
 
243
282
  static updateProp(obj: Component, name: string){
@@ -246,14 +285,21 @@ abstract class Component{
246
285
 
247
286
  // // {f:contentCallback,startNode:startNode, endNode:endNode,condition:condition}
248
287
  let updateStyles = false;
249
- for(let i = 0; i < (ar||[]).length; i++){
250
- let arg = ar[i];
251
- // TODO: this could be used to update attributes.
252
- // But right now that relies exclusively on function setters. It's a bit weird.
253
- arg.updateContent(dot, value);
254
-
255
- if(arg instanceof AttrArgCallback && arg.attr == "class"){
256
- updateStyles = true;
288
+ if(false && obj.#rebuildBuilderOnPropChange[name] && !obj.#initializingBuild){
289
+ // Call the builder again.
290
+ }
291
+ else{
292
+ // Maybe update specific areas.
293
+ // This is admittedly more efficient.
294
+ for(let i = 0; i < (ar||[]).length; i++){
295
+ let arg = ar[i];
296
+ // TODO: this could be used to update attributes.
297
+ // But right now that relies exclusively on function setters. It's a bit weird.
298
+ arg.updateContent(dot, value);
299
+
300
+ if(obj.#rebuildStylesOnPropChange[name] || (arg instanceof AttrArgCallback && arg.attr == "class")){
301
+ updateStyles = true;
302
+ }
257
303
  }
258
304
  }
259
305
 
@@ -337,7 +383,7 @@ abstract class Component{
337
383
  return this.__$el;
338
384
  }
339
385
 
340
- $refs: {[key: string]: Element} = {};
386
+ $refs: {[key: string]: HTMLElement} = {};
341
387
 
342
388
  /**
343
389
  * Name of the component (optional). If provided, dot and the VDBO will be extended.
package/src/dot-util.ts CHANGED
@@ -30,4 +30,40 @@ class _ClassPrefix{
30
30
 
31
31
  export const ClassPrefix = new _ClassPrefix()
32
32
 
33
- export const GlobalComponentStack: Array<Component> = [];
33
+ export const GlobalComponentStack: Array<Component> = [];
34
+
35
+
36
+ export type AnimationType = "geometric"|"exponential"|"ease"|"linear";
37
+
38
+ export var floatRegex = new RegExp("[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?", "g");
39
+
40
+ /**
41
+ * Function that takes in a bunch of parameters and steps the start value toward the target based on timeRemaining and style.
42
+ * currentValue is the current value.
43
+ * targetValue is the target valaue.
44
+ * timeRemaining is the time remaining in ms.
45
+ * stepProgress is the size of this step.
46
+ * totalDuration is the duration of the entire animation from start to finish (not just this step).
47
+ * style is the type of transition (geometric=exponential, ease, linear).
48
+ * Returns the result.
49
+ */
50
+ export function numberStep(startValue: number, targetValue: number, currentTime: number, totalDuration: number, style: AnimationType){
51
+
52
+ startValue = Number(startValue);
53
+ targetValue = Number(targetValue);
54
+
55
+ var timeRemaining = totalDuration - currentTime;
56
+
57
+ switch(style){
58
+ case "geometric":
59
+ 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.
60
+ // var m = Math.exp(-1 / timeRemaining);
61
+ // return targetValue + m * (startValue - targetValue);
62
+ case "ease":
63
+ var m = (-Math.cos(Math.PI * (currentTime / totalDuration)) + 1) * 0.5;
64
+ return startValue + m * (targetValue - startValue);
65
+ case "linear":
66
+ default:
67
+ return startValue + (targetValue - startValue) * (currentTime / totalDuration);
68
+ }
69
+ }
package/src/dot.ts CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  import eventBus from "./event-bus";
3
3
  import {IDotCore, IDotGenericElement} from "./i-dot";
4
- import dotcss from "./style-builder";
4
+ import dotcss, { _Builder } from "./styling/style-builder";
5
5
  import ERR from "./err";
6
6
  import { DotContent, IDotElementDocument, IDotDocument } from "./i-dot";
7
7
  import { ClassPrefix, eachK, GlobalComponentStack, isF, sT, str } from "./dot-util";
@@ -706,7 +706,7 @@ ext("attr", function(attr, value, arg3?){
706
706
  if (!isF(value)) {
707
707
 
708
708
  // Objects (except for the css builder :/)
709
- if(typeof value == "object" && !(value instanceof dot.css["_Builder"])){
709
+ if(typeof value == "object" && !(value instanceof _Builder)){
710
710
  var originalValue = value;
711
711
  var valueSetter = function(){
712
712
  var str = "";
package/src/dothtml.ts CHANGED
@@ -29,6 +29,6 @@ dot.Component = Component;
29
29
  export default dot;
30
30
  export {default as DotComponent} from "./component";
31
31
  export {IDotElement} from "./i-dot";
32
- export {default as IDotCss} from "./i-dotcss";
32
+ export {default as IDotCss} from "./styling/i-dotcss";
33
33
 
34
34
  // https://www.youtube.com/JoshSideris
package/src/i-dot.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import EventBus from "./event-bus";
2
2
  import type Component from "./component";
3
- import IDotCss, { IDotcssProp } from "./i-dotcss";
3
+ import IDotCss, { IDotcssProp } from "./styling/i-dotcss";
4
4
 
5
5
  export type DotContentPrimitive = string|number|boolean;
6
6
  export type DotContentBasic = DotContentPrimitive|Node|Element|NodeList|Component|IDotDocument//typeof DotDocument;
@@ -0,0 +1,18 @@
1
+ import { floatRegex } from "../../dot-util";
2
+ import CssDataType from "./css-data-type";
3
+
4
+ export default class CssAngle extends CssDataType{
5
+ angle: number;
6
+ units: string;
7
+ constructor(value: string|number){
8
+ super("angle");
9
+ value = value || "0deg";
10
+ if(!isNaN(value as number)) value = `${Math.round(value as number)}deg`;
11
+ this.angle = Number((value as string).match(floatRegex)[0]);
12
+ this.units = (value as string).split(floatRegex)[1] || "deg";
13
+ }
14
+
15
+ toString(){
16
+ return this.angle + this.units;
17
+ }
18
+ }
@@ -0,0 +1,229 @@
1
+ import CssDataType from "./css-data-type";
2
+
3
+ export default class CssColor extends CssDataType{
4
+ r: number;
5
+ g: number;
6
+ b: number;
7
+ a: number;
8
+ constructor(value){
9
+ super("color");
10
+ this.r = 0;
11
+ this.g = 0;
12
+ this.b = 0;
13
+ this.a = 1;
14
+ if(value.length == 1) {
15
+ value = value[0];
16
+ if(value == "" || value == "none" || value == "initial" || value == "inherit"){} //Nothing more needs to be done.
17
+ else if(!isNaN(value)){
18
+ this.b = value & 0xFF;
19
+ value >>= 8;
20
+ this.g = value & 0xFF;
21
+ value >>= 8;
22
+ this.r = value & 0xFF;
23
+ }
24
+ else if(value[0] == "#"){
25
+ var cH = value.split("#")[1];
26
+ if(cH.length == 3){
27
+ this.r = Number("0x" + cH[0] + "" + cH[0]);
28
+ this.g = Number("0x" + cH[1] + "" + cH[1]);
29
+ this.b = Number("0x" + cH[2] + "" + cH[2]);
30
+
31
+ }
32
+ else if(cH.length == 6){
33
+ this.r = Number("0x" + cH[0] + "" + cH[1]);
34
+ this.g = Number("0x" + cH[2] + "" + cH[3]);
35
+ this.b = Number("0x" + cH[4] + "" + cH[5]);
36
+ }
37
+ //else throw value + " is not a valid color"; //or just stick with black.
38
+ }
39
+ else if(value.toLowerCase().indexOf("rgb") === 0){
40
+ //This also handles rgba.
41
+ var cData = value.split("(")[1];
42
+ cData = cData.split(")")[0];
43
+ cData = cData.split(",");
44
+ if(cData.length == 3 || cData.length == 4){
45
+ this.r = Number(cData[0]);
46
+ this.g = Number(cData[1]);
47
+ this.b = Number(cData[2]);
48
+ this.a = Number(cData[3] || 1);
49
+ }
50
+ }
51
+ else{
52
+ var r = 0;
53
+ var g = 0;
54
+ var b = 0;
55
+ switch(value.toLowerCase()){
56
+ case 'aliceblue':r=0xF0;g=0xF8;b=0xFF;break;
57
+ case 'antiquewhite':r=0xFA;g=0xEB;b=0xD7;break;
58
+ case 'aqua':r=0x00;g=0xFF;b=0xFF;break;
59
+ case 'aquamarine':r=0x7F;g=0xFF;b=0xD4;break;
60
+ case 'azure':r=0xF0;g=0xFF;b=0xFF;break;
61
+ case 'beige':r=0xF5;g=0xF5;b=0xDC;break;
62
+ case 'bisque':r=0xFF;g=0xE4;b=0xC4;break;
63
+ case 'black':r=0x00;g=0x00;b=0x00;break;
64
+ case 'blanchedalmond':r=0xFF;g=0xEB;b=0xCD;break;
65
+ case 'blue':r=0x00;g=0x00;b=0xFF;break;
66
+ case 'blueviolet':r=0x8A;g=0x2B;b=0xE2;break;
67
+ case 'brown':r=0xA5;g=0x2A;b=0x2A;break;
68
+ case 'burlywood':r=0xDE;g=0xB8;b=0x87;break;
69
+ case 'cadetblue':r=0x5F;g=0x9E;b=0xA0;break;
70
+ case 'chartreuse':r=0x7F;g=0xFF;b=0x00;break;
71
+ case 'chocolate':r=0xD2;g=0x69;b=0x1E;break;
72
+ case 'coral':r=0xFF;g=0x7F;b=0x50;break;
73
+ case 'cornflowerblue':r=0x64;g=0x95;b=0xED;break;
74
+ case 'cornsilk':r=0xFF;g=0xF8;b=0xDC;break;
75
+ case 'crimson':r=0xDC;g=0x14;b=0x3C;break;
76
+ case 'cyan':r=0x00;g=0xFF;b=0xFF;break;
77
+ case 'darkblue':r=0x00;g=0x00;b=0x8B;break;
78
+ case 'darkcyan':r=0x00;g=0x8B;b=0x8B;break;
79
+ case 'darkgoldenrod':r=0xB8;g=0x86;b=0x0B;break;
80
+ case 'darkgray':r=0xA9;g=0xA9;b=0xA9;break;
81
+ case 'darkgrey':r=0xA9;g=0xA9;b=0xA9;break;
82
+ case 'darkgreen':r=0x00;g=0x64;b=0x00;break;
83
+ case 'darkkhaki':r=0xBD;g=0xB7;b=0x6B;break;
84
+ case 'darkmagenta':r=0x8B;g=0x00;b=0x8B;break;
85
+ case 'darkolivegreen':r=0x55;g=0x6B;b=0x2F;break;
86
+ case 'darkorange':r=0xFF;g=0x8C;b=0x00;break;
87
+ case 'darkorchid':r=0x99;g=0x32;b=0xCC;break;
88
+ case 'darkred':r=0x8B;g=0x00;b=0x00;break;
89
+ case 'darksalmon':r=0xE9;g=0x96;b=0x7A;break;
90
+ case 'darkseagreen':r=0x8F;g=0xBC;b=0x8F;break;
91
+ case 'darkslateblue':r=0x48;g=0x3D;b=0x8B;break;
92
+ case 'darkslategray':r=0x2F;g=0x4F;b=0x4F;break;
93
+ case 'darkslategrey':r=0x2F;g=0x4F;b=0x4F;break;
94
+ case 'darkturquoise':r=0x00;g=0xCE;b=0xD1;break;
95
+ case 'darkviolet':r=0x94;g=0x00;b=0xD3;break;
96
+ case 'deeppink':r=0xFF;g=0x14;b=0x93;break;
97
+ case 'deepskyblue':r=0x00;g=0xBF;b=0xFF;break;
98
+ case 'dimgray':r=0x69;g=0x69;b=0x69;break;
99
+ case 'dimgrey':r=0x69;g=0x69;b=0x69;break;
100
+ case 'dodgerblue':r=0x1E;g=0x90;b=0xFF;break;
101
+ case 'firebrick':r=0xB2;g=0x22;b=0x22;break;
102
+ case 'floralwhite':r=0xFF;g=0xFA;b=0xF0;break;
103
+ case 'forestgreen':r=0x22;g=0x8B;b=0x22;break;
104
+ case 'fuchsia':r=0xFF;g=0x00;b=0xFF;break;
105
+ case 'gainsboro':r=0xDC;g=0xDC;b=0xDC;break;
106
+ case 'ghostwhite':r=0xF8;g=0xF8;b=0xFF;break;
107
+ case 'gold':r=0xFF;g=0xD7;b=0x00;break;
108
+ case 'goldenrod':r=0xDA;g=0xA5;b=0x20;break;
109
+ case 'gray':r=0x80;g=0x80;b=0x80;break;
110
+ case 'grey':r=0x80;g=0x80;b=0x80;break;
111
+ case 'green':r=0x00;g=0x80;b=0x00;break;
112
+ case 'greenyellow':r=0xAD;g=0xFF;b=0x2F;break;
113
+ case 'honeydew':r=0xF0;g=0xFF;b=0xF0;break;
114
+ case 'hotpink':r=0xFF;g=0x69;b=0xB4;break;
115
+ case 'indianred':r=0xCD;g=0x5C;b=0x5C;break;
116
+ case 'indigo':r=0x4B;g=0x00;b=0x82;break;
117
+ case 'ivory':r=0xFF;g=0xFF;b=0xF0;break;
118
+ case 'khaki':r=0xF0;g=0xE6;b=0x8C;break;
119
+ case 'lavender':r=0xE6;g=0xE6;b=0xFA;break;
120
+ case 'lavenderblush':r=0xFF;g=0xF0;b=0xF5;break;
121
+ case 'lawngreen':r=0x7C;g=0xFC;b=0x00;break;
122
+ case 'lemonchiffon':r=0xFF;g=0xFA;b=0xCD;break;
123
+ case 'lightblue':r=0xAD;g=0xD8;b=0xE6;break;
124
+ case 'lightcoral':r=0xF0;g=0x80;b=0x80;break;
125
+ case 'lightcyan':r=0xE0;g=0xFF;b=0xFF;break;
126
+ case 'lightgoldenrodyellow':r=0xFA;g=0xFA;b=0xD2;break;
127
+ case 'lightgray':r=0xD3;g=0xD3;b=0xD3;break;
128
+ case 'lightgrey':r=0xD3;g=0xD3;b=0xD3;break;
129
+ case 'lightgreen':r=0x90;g=0xEE;b=0x90;break;
130
+ case 'lightpink':r=0xFF;g=0xB6;b=0xC1;break;
131
+ case 'lightsalmon':r=0xFF;g=0xA0;b=0x7A;break;
132
+ case 'lightseagreen':r=0x20;g=0xB2;b=0xAA;break;
133
+ case 'lightskyblue':r=0x87;g=0xCE;b=0xFA;break;
134
+ case 'lightslategray':r=0x77;g=0x88;b=0x99;break;
135
+ case 'lightslategrey':r=0x77;g=0x88;b=0x99;break;
136
+ case 'lightsteelblue':r=0xB0;g=0xC4;b=0xDE;break;
137
+ case 'lightyellow':r=0xFF;g=0xFF;b=0xE0;break;
138
+ case 'lime':r=0x00;g=0xFF;b=0x00;break;
139
+ case 'limegreen':r=0x32;g=0xCD;b=0x32;break;
140
+ case 'linen':r=0xFA;g=0xF0;b=0xE6;break;
141
+ case 'magenta':r=0xFF;g=0x00;b=0xFF;break;
142
+ case 'maroon':r=0x80;g=0x00;b=0x00;break;
143
+ case 'mediumaquamarine':r=0x66;g=0xCD;b=0xAA;break;
144
+ case 'mediumblue':r=0x00;g=0x00;b=0xCD;break;
145
+ case 'mediumorchid':r=0xBA;g=0x55;b=0xD3;break;
146
+ case 'mediumpurple':r=0x93;g=0x70;b=0xDB;break;
147
+ case 'mediumseagreen':r=0x3C;g=0xB3;b=0x71;break;
148
+ case 'mediumslateblue':r=0x7B;g=0x68;b=0xEE;break;
149
+ case 'mediumspringgreen':r=0x00;g=0xFA;b=0x9A;break;
150
+ case 'mediumturquoise':r=0x48;g=0xD1;b=0xCC;break;
151
+ case 'mediumvioletred':r=0xC7;g=0x15;b=0x85;break;
152
+ case 'midnightblue':r=0x19;g=0x19;b=0x70;break;
153
+ case 'mintcream':r=0xF5;g=0xFF;b=0xFA;break;
154
+ case 'mistyrose':r=0xFF;g=0xE4;b=0xE1;break;
155
+ case 'moccasin':r=0xFF;g=0xE4;b=0xB5;break;
156
+ case 'navajowhite':r=0xFF;g=0xDE;b=0xAD;break;
157
+ case 'navy':r=0x00;g=0x00;b=0x80;break;
158
+ case 'oldlace':r=0xFD;g=0xF5;b=0xE6;break;
159
+ case 'olive':r=0x80;g=0x80;b=0x00;break;
160
+ case 'olivedrab':r=0x6B;g=0x8E;b=0x23;break;
161
+ case 'orange':r=0xFF;g=0xA5;b=0x00;break;
162
+ case 'orangered':r=0xFF;g=0x45;b=0x00;break;
163
+ case 'orchid':r=0xDA;g=0x70;b=0xD6;break;
164
+ case 'palegoldenrod':r=0xEE;g=0xE8;b=0xAA;break;
165
+ case 'palegreen':r=0x98;g=0xFB;b=0x98;break;
166
+ case 'paleturquoise':r=0xAF;g=0xEE;b=0xEE;break;
167
+ case 'palevioletred':r=0xDB;g=0x70;b=0x93;break;
168
+ case 'papayawhip':r=0xFF;g=0xEF;b=0xD5;break;
169
+ case 'peachpuff':r=0xFF;g=0xDA;b=0xB9;break;
170
+ case 'peru':r=0xCD;g=0x85;b=0x3F;break;
171
+ case 'pink':r=0xFF;g=0xC0;b=0xCB;break;
172
+ case 'plum':r=0xDD;g=0xA0;b=0xDD;break;
173
+ case 'powderblue':r=0xB0;g=0xE0;b=0xE6;break;
174
+ case 'purple':r=0x80;g=0x00;b=0x80;break;
175
+ case 'rebeccapurple':r=0x66;g=0x33;b=0x99;break;
176
+ case 'red':r=0xFF;g=0x00;b=0x00;break;
177
+ case 'rosybrown':r=0xBC;g=0x8F;b=0x8F;break;
178
+ case 'royalblue':r=0x41;g=0x69;b=0xE1;break;
179
+ case 'saddlebrown':r=0x8B;g=0x45;b=0x13;break;
180
+ case 'salmon':r=0xFA;g=0x80;b=0x72;break;
181
+ case 'sandybrown':r=0xF4;g=0xA4;b=0x60;break;
182
+ case 'seagreen':r=0x2E;g=0x8B;b=0x57;break;
183
+ case 'seashell':r=0xFF;g=0xF5;b=0xEE;break;
184
+ case 'sienna':r=0xA0;g=0x52;b=0x2D;break;
185
+ case 'silver':r=0xC0;g=0xC0;b=0xC0;break;
186
+ case 'skyblue':r=0x87;g=0xCE;b=0xEB;break;
187
+ case 'slateblue':r=0x6A;g=0x5A;b=0xCD;break;
188
+ case 'slategray':r=0x70;g=0x80;b=0x90;break;
189
+ case 'slategrey':r=0x70;g=0x80;b=0x90;break;
190
+ case 'snow':r=0xFF;g=0xFA;b=0xFA;break;
191
+ case 'springgreen':r=0x00;g=0xFF;b=0x7F;break;
192
+ case 'steelblue':r=0x46;g=0x82;b=0xB4;break;
193
+ case 'tan':r=0xD2;g=0xB4;b=0x8C;break;
194
+ case 'teal':r=0x00;g=0x80;b=0x80;break;
195
+ case 'thistle':r=0xD8;g=0xBF;b=0xD8;break;
196
+ case 'tomato':r=0xFF;g=0x63;b=0x47;break;
197
+ case 'turquoise':r=0x40;g=0xE0;b=0xD0;break;
198
+ case 'violet':r=0xEE;g=0x82;b=0xEE;break;
199
+ case 'wheat':r=0xF5;g=0xDE;b=0xB3;break;
200
+ case 'white':r=0xFF;g=0xFF;b=0xFF;break;
201
+ case 'whitesmoke':r=0xF5;g=0xF5;b=0xF5;break;
202
+ case 'yellow':r=0xFF;g=0xFF;b=0x00;break;
203
+ case 'yellowgreen':r=0x9A;g=0xCD;b=0x32;break;
204
+ }
205
+ this.r = r;
206
+ this.g = g;
207
+ this.b = b;
208
+ }
209
+ }
210
+ else if(value.length == 3 || value.length == 4){
211
+ this.r = value[0];
212
+ this.g = value[1];
213
+ this.b = value[2];
214
+ if(value.length == 4){
215
+ this.a = value[3];
216
+ }
217
+ }
218
+ }
219
+
220
+ toString(){
221
+ var R = Math.round;
222
+ var X = Math.max;
223
+ var N = Math.min;
224
+ if(this.a == 1)
225
+ return "rgb(" + N(255, X(0, R(this.r))) + ", " + N(255, X(0, R(this.g))) + ", " + N(255, X(0, R(this.b))) + ")";
226
+ else
227
+ 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)) + ")";
228
+ }
229
+ }
@@ -0,0 +1,20 @@
1
+ import { floatRegex } from "../../dot-util";
2
+ import CssDataType from "./css-data-type";
3
+
4
+ export default class CssComplex extends CssDataType{
5
+ parts: string[];
6
+ numbers: string;
7
+ constructor(value){
8
+ super("complex");
9
+ this.parts = (" " + value + " ").split(floatRegex);
10
+ this.numbers = value.match(floatRegex);
11
+ }
12
+
13
+ toString(){
14
+ var ret = this.parts[0];
15
+ for(var i = 0; i < this.numbers.length; i++){
16
+ ret += this.numbers[i] + this.parts[i+1];
17
+ }
18
+ return ret;
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ export declare type CssDataTypeToken = "url"|"number"|"length"|"angle"|"color"|"transformation"|"complex"|"unknown";
2
+
3
+ export default abstract class CssDataType{
4
+ type: CssDataTypeToken;
5
+
6
+ constructor(type: CssDataTypeToken){
7
+ this.type = type;
8
+ }
9
+ }
@@ -0,0 +1,20 @@
1
+ import { floatRegex } from "../../dot-util";
2
+ import CssDataType from "./css-data-type";
3
+
4
+ //TODO: this should support multiple lengths.
5
+ // TODO: add some test cases to test these.
6
+ export default class CssLength extends CssDataType{
7
+ length: number;
8
+ units: string;
9
+ constructor (value:string|number){
10
+ super("length")
11
+ value = value || "0px";
12
+ if(!isNaN(value as number)) value = Math.round(value as number) + "px";
13
+ this.length = Number((value as string).match(floatRegex)[0]);
14
+ this.units = (value as string).split(floatRegex)[1] || "px";
15
+ }
16
+
17
+ toString(){
18
+ return `${this.length}${this.units}`;
19
+ }
20
+ }
@@ -0,0 +1,12 @@
1
+ import CssDataType from "./css-data-type";
2
+
3
+ export default class CssNumber extends CssDataType{
4
+ value: number;
5
+ constructor(value){
6
+ super("number");
7
+ this.value = Number(value);
8
+ }
9
+ toString(){
10
+ return this.value;
11
+ }
12
+ }