@acemir/cssom 0.9.23 → 0.9.25

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.
@@ -16,19 +16,30 @@ CSSOM.CSSSupportsRule = function CSSSupportsRule() {
16
16
  CSSOM.CSSConditionRule.call(this);
17
17
  };
18
18
 
19
- CSSOM.CSSSupportsRule.prototype = new CSSOM.CSSConditionRule();
19
+ CSSOM.CSSSupportsRule.prototype = Object.create(CSSOM.CSSConditionRule.prototype);
20
20
  CSSOM.CSSSupportsRule.prototype.constructor = CSSOM.CSSSupportsRule;
21
- CSSOM.CSSSupportsRule.prototype.type = 12;
21
+
22
+ Object.setPrototypeOf(CSSOM.CSSSupportsRule, CSSOM.CSSConditionRule);
23
+
24
+ Object.defineProperty(CSSOM.CSSSupportsRule.prototype, "type", {
25
+ value: 12,
26
+ writable: false
27
+ });
22
28
 
23
29
  Object.defineProperty(CSSOM.CSSSupportsRule.prototype, "cssText", {
24
30
  get: function() {
25
- var cssTexts = [];
26
-
27
- for (var i = 0, length = this.cssRules.length; i < length; i++) {
28
- cssTexts.push(this.cssRules[i].cssText);
31
+ var values = "";
32
+ var valuesArr = [" {"];
33
+ if (this.cssRules.length) {
34
+ valuesArr.push(this.cssRules.reduce(function(acc, rule){
35
+ if (rule.cssText !== "") {
36
+ acc.push(rule.cssText);
37
+ }
38
+ return acc;
39
+ }, []).join("\n "));
29
40
  }
30
-
31
- return "@supports " + this.conditionText + " {" + (cssTexts.length ? "\n " + cssTexts.join("\n ") : "") + "\n}";
41
+ values = valuesArr.join("\n ") + "\n}";
42
+ return "@supports " + this.conditionText + values;
32
43
  }
33
44
  });
34
45
 
@@ -15,9 +15,11 @@ CSSOM.CSSValueExpression = function CSSValueExpression(token, idx) {
15
15
  this._idx = idx;
16
16
  };
17
17
 
18
- CSSOM.CSSValueExpression.prototype = new CSSOM.CSSValue();
18
+ CSSOM.CSSValueExpression.prototype = Object.create(CSSOM.CSSValue.prototype);
19
19
  CSSOM.CSSValueExpression.prototype.constructor = CSSOM.CSSValueExpression;
20
20
 
21
+ Object.setPrototypeOf(CSSOM.CSSValueExpression, CSSOM.CSSValue);
22
+
21
23
  /**
22
24
  * parse css expression() value
23
25
  *
package/lib/MediaList.js CHANGED
@@ -26,7 +26,9 @@ CSSOM.MediaList.prototype = {
26
26
  * @param {string} value
27
27
  */
28
28
  set mediaText(value) {
29
- var values = value.split(",");
29
+ var values = value.split(",").filter(function(text){
30
+ return !!text;
31
+ });
30
32
  var length = this.length = values.length;
31
33
  for (var i=0; i<length; i++) {
32
34
  this[i] = values[i].trim();
package/lib/StyleSheet.js CHANGED
@@ -6,15 +6,38 @@ var CSSOM = {
6
6
 
7
7
 
8
8
  /**
9
- * @constructor
10
9
  * @see http://dev.w3.org/csswg/cssom/#the-stylesheet-interface
11
10
  */
12
11
  CSSOM.StyleSheet = function StyleSheet() {
12
+ this.__href = null;
13
+ this.__ownerNode = null;
14
+ this.__title = null;
13
15
  this.__media = new CSSOM.MediaList();
14
16
  this.__parentStyleSheet = null;
17
+ this.disabled = false;
15
18
  };
16
19
 
17
20
  Object.defineProperties(CSSOM.StyleSheet.prototype, {
21
+ type: {
22
+ get: function() {
23
+ return "text/css";
24
+ }
25
+ },
26
+ href: {
27
+ get: function() {
28
+ return this.__href;
29
+ }
30
+ },
31
+ ownerNode: {
32
+ get: function() {
33
+ return this.__ownerNode;
34
+ }
35
+ },
36
+ title: {
37
+ get: function() {
38
+ return this.__title;
39
+ }
40
+ },
18
41
  media: {
19
42
  get: function() {
20
43
  return this.__media;
package/lib/errorUtils.js CHANGED
@@ -1,3 +1,9 @@
1
+ //.CommonJS
2
+ var CSSOM = {
3
+ getGlobalObject: require('./CSSOM').getGlobalObject
4
+ }
5
+ ///CommonJS
6
+
1
7
  // Utility functions for CSSOM error handling
2
8
 
3
9
  /**
@@ -10,19 +16,8 @@
10
16
  * @return {Function} The error constructor
11
17
  */
12
18
  function getErrorConstructor(context, errorType) {
13
- // Try parentStyleSheet.__globalObject first
14
- if (context.parentStyleSheet && context.parentStyleSheet.__globalObject && context.parentStyleSheet.__globalObject[errorType]) {
15
- return context.parentStyleSheet.__globalObject[errorType];
16
- }
17
-
18
- // Try __parentStyleSheet (alternative naming)
19
- if (context.__parentStyleSheet && context.__parentStyleSheet.__globalObject && context.__parentStyleSheet.__globalObject[errorType]) {
20
- return context.__parentStyleSheet.__globalObject[errorType];
21
- }
22
-
23
- // Try __globalObject on the context itself
24
- if (context.__globalObject && context.__globalObject[errorType]) {
25
- return context.__globalObject[errorType];
19
+ if (CSSOM.getGlobalObject() && CSSOM.getGlobalObject()[errorType]) {
20
+ return CSSOM.getGlobalObject()[errorType];
26
21
  }
27
22
 
28
23
  // Fall back to native constructor
@@ -31,6 +26,19 @@ function getErrorConstructor(context, errorType) {
31
26
  eval(errorType);
32
27
  }
33
28
 
29
+ /**
30
+ * Creates an appropriate error with context-aware constructor.
31
+ *
32
+ * @param {Object} context - The CSSOM object (rule, stylesheet, etc.)
33
+ * @param {string} errorType - The error type ('TypeError', 'RangeError', 'DOMException', etc.)
34
+ * @param {string} message - The error message
35
+ * @param {string} [name] - Optional name for DOMException
36
+ */
37
+ function createError(context, errorType, message, name) {
38
+ var ErrorConstructor = getErrorConstructor(context, errorType);
39
+ return new ErrorConstructor(message, name);
40
+ }
41
+
34
42
  /**
35
43
  * Creates and throws an appropriate error with context-aware constructor.
36
44
  *
@@ -40,9 +48,7 @@ function getErrorConstructor(context, errorType) {
40
48
  * @param {string} [name] - Optional name for DOMException
41
49
  */
42
50
  function throwError(context, errorType, message, name) {
43
- var ErrorConstructor = getErrorConstructor(context, errorType);
44
- var error = new ErrorConstructor(message, name);
45
- throw error;
51
+ throw createError(context, errorType, message, name);
46
52
  }
47
53
 
48
54
  /**
@@ -95,6 +101,7 @@ function throwIndexError(context, methodName, objectName, index, maxIndex, name)
95
101
  }
96
102
 
97
103
  var errorUtils = {
104
+ createError: createError,
98
105
  getErrorConstructor: getErrorConstructor,
99
106
  throwError: throwError,
100
107
  throwMissingArguments: throwMissingArguments,
package/lib/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ exports.setup = require('./CSSOM').setup;
4
+
3
5
  require('./errorUtils');
4
6
 
5
7
  exports.CSSStyleDeclaration = require('./CSSStyleDeclaration').CSSStyleDeclaration;