jsdom / cssstyle

A Node.js implementation of the CSS Object Model CSSStyleDeclaration interface
MIT License
107 stars 70 forks source link

Allow usage of `calc` for margins #154

Closed coeing closed 6 days ago

coeing commented 1 year ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

I'd like to suggest that TYPES.CALC should be valid for margins as well. I used patch-package to use it in my project and it does not seem to make any problems.

The real change probably has to be done here: https://github.com/jsdom/cssstyle/blob/b527ed722364dc6d156487c652df100572075dee/lib/properties/margin.js#L12

Today I used patch-package to patch cssstyle@2.3.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/cssstyle/lib/properties.js b/node_modules/cssstyle/lib/properties.js
index 7f462f3..2af2e4e 100644
--- a/node_modules/cssstyle/lib/properties.js
+++ b/node_modules/cssstyle/lib/properties.js
@@ -1225,7 +1225,7 @@ var margin_local_var_isValid = function (v) {
   }

   var type = external_dependency_parsers_0.valueType(v);
-  return type === margin_local_var_TYPES.LENGTH || type === margin_local_var_TYPES.PERCENT || type === margin_local_var_TYPES.INTEGER && (v === '0' || v === 0);
+  return type === margin_local_var_TYPES.CALC || type === margin_local_var_TYPES.LENGTH || type === margin_local_var_TYPES.PERCENT || type === margin_local_var_TYPES.INTEGER && (v === '0' || v === 0);
 };

 var margin_local_var_parser = function (v) {

This issue body was partially generated by patch-package.