cssstyle 0.2.31 → 0.2.37

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/.npmignore CHANGED
@@ -0,0 +1 @@
1
+ node_module
@@ -95,6 +95,7 @@ CSSStyleDeclaration.prototype = {
95
95
 
96
96
  var prevValue = this._values[name];
97
97
  delete this._values[name];
98
+ delete this._importants[name];
98
99
 
99
100
  var index = Array.prototype.indexOf.call(this, name);
100
101
  if (index < 0) {
package/lib/parsers.js CHANGED
@@ -470,7 +470,7 @@ exports.shorthandParser = function parse(v, shorthand_for) {
470
470
  var type = exports.valueType(v);
471
471
  if (type === exports.TYPES.NULL_OR_EMPTY_STR) {
472
472
  Object.keys(shorthand_for).forEach(function (property) {
473
- obj[property] = v;
473
+ obj[property] = '';
474
474
  });
475
475
  return obj;
476
476
  }
@@ -519,7 +519,10 @@ exports.shorthandSetter = function (property, shorthand_for) {
519
519
  // in case it gets translated into something else (0 -> 0px)
520
520
  obj[subprop] = this[camel];
521
521
  this.removeProperty(subprop);
522
- this._values[subprop] = obj[subprop];
522
+ // don't add in empty properties
523
+ if (obj[subprop] !== '') {
524
+ this._values[subprop] = obj[subprop];
525
+ }
523
526
  }, this);
524
527
  Object.keys(shorthand_for).forEach(function (subprop) {
525
528
  if (!obj.hasOwnProperty(subprop)) {
@@ -585,31 +588,72 @@ exports.implicitSetter = function (property_before, property_after, isValid, par
585
588
  return undefined;
586
589
  }
587
590
 
588
- parts = parts.map(function (part) {
591
+ parts = parts.map(function (part) {
589
592
  return parser(part);
590
593
  });
591
594
  this._setProperty(property_before + property_after, parts.join(' '));
592
- if (parts.length === 1) {
595
+ if (parts.length === 1) {
593
596
  parts[1] = parts[0];
594
597
  }
595
- if (parts.length === 2) {
598
+ if (parts.length === 2) {
596
599
  parts[2] = parts[0];
597
600
  }
598
- if (parts.length === 3) {
601
+ if (parts.length === 3) {
599
602
  parts[3] = parts[1];
600
603
  }
601
604
 
602
- for (var i = 0; i < 4; i++) {
603
- var property = property_before + "-" + part_names[i] + property_after;
604
- this.removeProperty(property);
605
- if (parts[i] !== '') {
605
+ for (var i = 0; i < 4; i++) {
606
+ var property = property_before + "-" + part_names[i] + property_after;
607
+ this.removeProperty(property);
608
+ if (parts[i] !== '') {
606
609
  this._values[property] = parts[i];
607
610
  }
608
- }
609
- return v;
611
+ }
612
+ return v;
613
+ };
614
+ };
615
+
616
+ //
617
+ // Companion to implicitSetter, but for the individual parts.
618
+ // This sets the individual value, and checks to see if all four
619
+ // sub-parts are set. If so, it sets the shorthand version and removes
620
+ // the individual parts from the cssText.
621
+ //
622
+ exports.subImplicitSetter = function (prefix, part, isValid, parser) {
623
+ var property = prefix + '-' + part;
624
+ var subparts = [prefix+"-top", prefix+"-right", prefix+"-bottom", prefix+"-left"];
625
+
626
+ return function (v) {
627
+ if (typeof v === 'number') {
628
+ v = v.toString();
629
+ }
630
+ if (typeof v !== 'string') {
631
+ return undefined;
632
+ }
633
+ if (!isValid(v)) {
634
+ return undefined;
635
+ }
636
+ v = parser(v);
637
+ this._setProperty(property,v);
638
+ var parts = [];
639
+ for (var i = 0; i < 4; i++) {
640
+ if (this._values[subparts[i]] == null || this._values[subparts[i]] === '') {
641
+ break;
642
+ }
643
+ parts.push(this._values[subparts[i]]);
644
+ }
645
+ if (parts.length === 4) {
646
+ for (i = 0; i < 4; i++) {
647
+ this.removeProperty(subparts[i]);
648
+ this._values[subparts[i]] = parts[i];
649
+ }
650
+ this._setProperty(prefix,parts.join(" "));
651
+ }
652
+ return v;
610
653
  };
611
654
  };
612
655
 
656
+
613
657
  var camel_to_dashed = /[A-Z]/g;
614
658
  /*jslint regexp: true*/
615
659
  var first_segment = /^\([^\-]\)-/;
@@ -5,6 +5,9 @@ var parsers = require('../parsers');
5
5
  var valid_keywords = ['top', 'center', 'bottom', 'left', 'right'];
6
6
 
7
7
  var parse = function parse(v) {
8
+ if (v === '' || v === null) {
9
+ return undefined;
10
+ }
8
11
  var parts = v.split(/\s+/);
9
12
  if (parts.length > 2 || parts.length < 1) {
10
13
  return undefined;
@@ -7,6 +7,9 @@ var parsers = require('../parsers');
7
7
  // if two, the first applies to the horizontal and the second applies to vertical spacing
8
8
 
9
9
  var parse = function parse(v) {
10
+ if (v === '' || v === null) {
11
+ return undefined;
12
+ }
10
13
  if (v.toLowerCase() === 'inherit') {
11
14
  return v;
12
15
  }
@@ -5,6 +5,9 @@ var valueType = require('../parsers').valueType;
5
5
 
6
6
  var partsRegEx = /\s*,\s*/;
7
7
  module.exports.isValid = function isValid(v) {
8
+ if (v === '' || v === null) {
9
+ return true;
10
+ }
8
11
  var parts = v.split(partsRegEx);
9
12
  var len = parts.length;
10
13
  var i;
@@ -2,9 +2,19 @@
2
2
 
3
3
  var parseMeasurement = require('../parsers').parseMeasurement;
4
4
 
5
+ function parse(v) {
6
+ if (String(v).toLowerCase() === 'auto') {
7
+ return 'auto';
8
+ }
9
+ if (String(v).toLowerCase() === 'inherit') {
10
+ return 'inherit';
11
+ }
12
+ return parseMeasurement(v);
13
+ }
14
+
5
15
  module.exports.definition = {
6
16
  set: function (v) {
7
- this._setProperty('height', parseMeasurement(v));
17
+ this._setProperty('height', parse(v));
8
18
  },
9
19
  get: function () {
10
20
  return this.getPropertyValue('height');
@@ -8,7 +8,7 @@ var isValid = function (v) {
8
8
  return true;
9
9
  }
10
10
  var type = parsers.valueType(v);
11
- return type === TYPES.LENGTH || type === TYPES.PERCENT;
11
+ return type === TYPES.LENGTH || type === TYPES.PERCENT || (type === TYPES.INTEGER && (v === '0' || v === 0));
12
12
  };
13
13
 
14
14
  var parser = function (v) {
@@ -17,7 +17,7 @@ var parser = function (v) {
17
17
  return V;
18
18
  }
19
19
  return parsers.parseMeasurement(v);
20
- }
20
+ };
21
21
 
22
22
  var mySetter = parsers.implicitSetter('margin', '', isValid, parser);
23
23
  var myGlobal = parsers.implicitSetter('margin', '', function () {
@@ -28,10 +28,10 @@ var myGlobal = parsers.implicitSetter('margin', '', function () {
28
28
 
29
29
  module.exports.definition = {
30
30
  set: function (v) {
31
- if (typeof v === "number") {
31
+ if (typeof v === "number") {
32
32
  v = String(v);
33
33
  }
34
- if (typeof v !== "string") {
34
+ if (typeof v !== "string") {
35
35
  return;
36
36
  }
37
37
  var V = v.toLowerCase();
@@ -54,3 +54,6 @@ module.exports.definition = {
54
54
  enumerable: true,
55
55
  configurable: true
56
56
  };
57
+
58
+ module.exports.isValid = isValid;
59
+ module.exports.parser = parser;
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var margin = require('./margin.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('margin-bottom', v);
6
- },
7
+ set: parsers.subImplicitSetter('margin', 'bottom', margin.isValid, margin.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('margin-bottom');
9
10
  },
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var margin = require('./margin.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('margin-left', v);
6
- },
7
+ set: parsers.subImplicitSetter('margin', 'left', margin.isValid, margin.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('margin-left');
9
10
  },
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var margin = require('./margin.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('margin-right', v);
6
- },
7
+ set: parsers.subImplicitSetter('margin', 'right', margin.isValid, margin.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('margin-right');
9
10
  },
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var margin = require('./margin.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('margin-top', v);
6
- },
7
+ set: parsers.subImplicitSetter('margin', 'top', margin.isValid, margin.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('margin-top');
9
10
  },
@@ -5,12 +5,12 @@ var TYPES = parsers.TYPES;
5
5
 
6
6
  var isValid = function (v) {
7
7
  var type = parsers.valueType(v);
8
- return type === TYPES.LENGTH || type === TYPES.PERCENT;
8
+ return type === TYPES.LENGTH || type === TYPES.PERCENT || (type === TYPES.INTEGER && (v === '0' || v === 0));
9
9
  };
10
10
 
11
11
  var parser = function (v) {
12
12
  return parsers.parseMeasurement(v);
13
- }
13
+ };
14
14
 
15
15
  var mySetter = parsers.implicitSetter('padding', '', isValid, parser);
16
16
  var myGlobal = parsers.implicitSetter('padding', '', function () {
@@ -21,10 +21,10 @@ var myGlobal = parsers.implicitSetter('padding', '', function () {
21
21
 
22
22
  module.exports.definition = {
23
23
  set: function (v) {
24
- if (typeof v === "number") {
24
+ if (typeof v === "number") {
25
25
  v = String(v);
26
26
  }
27
- if (typeof v !== "string") {
27
+ if (typeof v !== "string") {
28
28
  return;
29
29
  }
30
30
  var V = v.toLowerCase();
@@ -47,3 +47,6 @@ module.exports.definition = {
47
47
  enumerable: true,
48
48
  configurable: true
49
49
  };
50
+
51
+ module.exports.isValid = isValid;
52
+ module.exports.parser = parser;
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var padding = require('./padding.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('padding-bottom', v);
6
- },
7
+ set: parsers.subImplicitSetter('padding', 'bottom', padding.isValid, padding.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('padding-bottom');
9
10
  },
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var padding = require('./padding.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('padding-left', v);
6
- },
7
+ set: parsers.subImplicitSetter('padding', 'left', padding.isValid, padding.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('padding-left');
9
10
  },
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var padding = require('./padding.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('padding-right', v);
6
- },
7
+ set: parsers.subImplicitSetter('padding', 'right', padding.isValid, padding.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('padding-right');
9
10
  },
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var padding = require('./padding.js');
4
+ var parsers = require('../parsers.js');
5
+
3
6
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('padding-top', v);
6
- },
7
+ set: parsers.subImplicitSetter('padding', 'top', padding.isValid, padding.parser),
7
8
  get: function () {
8
9
  return this.getPropertyValue('padding-top');
9
10
  },
@@ -2,9 +2,19 @@
2
2
 
3
3
  var parseMeasurement = require('../parsers').parseMeasurement;
4
4
 
5
+ function parse(v) {
6
+ if (String(v).toLowerCase() === 'auto') {
7
+ return 'auto';
8
+ }
9
+ if (String(v).toLowerCase() === 'inherit') {
10
+ return 'inherit';
11
+ }
12
+ return parseMeasurement(v);
13
+ }
14
+
5
15
  module.exports.definition = {
6
16
  set: function (v) {
7
- this._setProperty('width', parseMeasurement(v));
17
+ this._setProperty('width', parse(v));
8
18
  },
9
19
  get: function () {
10
20
  return this.getPropertyValue('width');