nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: playcanvas/engine
Pull request #4689 (2022-10-03 10:18:14)

Implementation of math.nerestPowerOfTwo function
math helper function


Patch:
diff --git a/src/math/math.js b/src/math/math.js
index 13b30cc62..7f669e1a6 100644
--- a/src/math/math.js
+++ b/src/math/math.js
@@ -182,6 +182,16 @@ const math = {
         return val;
     },
 
+    /**
+     * Returns the nearest (smaller or larger) power of 2 for the specified value.
+     *
+     * @param {number} val - The value for which to calculate the nearest power of 2.
+     * @returns {number} The nearest power of 2.
+     */
+    nearestPowerOfTwo: function (val) {
+        return Math.pow(2, Math.round(Math.log(val) / Math.log(2)));
+    },
+
     /**
      * Return a pseudo-random number between min and max. The number generated is in the range
      * [min, max), that is inclusive of the minimum but exclusive of the maximum.


Test patch:
diff --git a/test/math/math.test.mjs b/test/math/math.test.mjs
index 77e9424ba..ad26d682a 100644
--- a/test/math/math.test.mjs
+++ b/test/math/math.test.mjs
@@ -201,6 +201,23 @@ describe('math', function () {
 
     });
 
+    describe('#nearestPowerOfTwo', function () {
+
+        it('returns the nearest power of two', function () {
+            expect(math.nearestPowerOfTwo(0)).to.equal(0);
+            expect(math.nearestPowerOfTwo(1)).to.equal(1);
+            expect(math.nearestPowerOfTwo(2)).to.equal(2);
+            expect(math.nearestPowerOfTwo(3)).to.equal(4);
+            expect(math.nearestPowerOfTwo(4)).to.equal(4);
+            expect(math.nearestPowerOfTwo(5)).to.equal(4);
+            expect(math.nearestPowerOfTwo(6)).to.equal(8);
+            expect(math.nearestPowerOfTwo(7)).to.equal(8);
+            expect(math.nearestPowerOfTwo(8)).to.equal(8);
+            expect(math.nearestPowerOfTwo(9)).to.equal(8);
+        });
+
+    });
+
     describe('#powerOfTwo', function () {
 
         it('returns true when the value is a power of two', function () {
Repository: jsdom/cssstyle
Pull request #107 (2019-10-25 00:02:15)

Add support for `ch` unit
Adds support for standard `ch` unit: https://caniuse.com/#feat=ch-unit


Patch:
diff --git a/lib/parsers.js b/lib/parsers.js
index 7beb6a6..3d8d620 100644
--- a/lib/parsers.js
+++ b/lib/parsers.js
@@ -22,7 +22,7 @@ exports.TYPES = {
 // rough regular expressions
 var integerRegEx = /^[-+]?[0-9]+$/;
 var numberRegEx = /^[-+]?[0-9]*\.?[0-9]+$/;
-var lengthRegEx = /^(0|[-+]?[0-9]*\.?[0-9]+(in|cm|em|mm|pt|pc|px|ex|rem|vh|vw))$/;
+var lengthRegEx = /^(0|[-+]?[0-9]*\.?[0-9]+(in|cm|em|mm|pt|pc|px|ex|rem|vh|vw|ch))$/;
 var percentRegEx = /^[-+]?[0-9]*\.?[0-9]+%$/;
 var urlRegEx = /^url\(\s*([^)]*)\s*\)$/;
 var stringRegEx = /^("[^"]*"|'[^']*')$/;


Test patch:
diff --git a/lib/parsers.test.js b/lib/parsers.test.js
index 5d960ff..d7db528 100644
--- a/lib/parsers.test.js
+++ b/lib/parsers.test.js
@@ -44,6 +44,13 @@ describe('valueType', () => {
 
     expect(output).toEqual(parsers.TYPES.COLOR);
   });
+
+  it('returns length for 100ch', () => {
+    let input = '100ch';
+    let output = parsers.valueType(input);
+
+    expect(output).toEqual(parsers.TYPES.LENGTH);
+  });
 });
 describe('parseInteger', () => {
   it.todo('test');
Repository: jsdom/cssstyle
Pull request #111 (2020-01-23 14:50:39)

feat: Implement read/write of custom properties
Part of #89 which is blocking https://github.com/facebook/react/pull/17896.

I did not implement full support since this requires more work and is only partially useful for JSDOM because resolution of values of the css variables requires the cascade. 

Browser behavior: https://codesandbox.io/s/css-custom-properties-access-423ni


Patch:
diff --git a/lib/CSSStyleDeclaration.js b/lib/CSSStyleDeclaration.js
index 0bb9ece..bded9a4 100644
--- a/lib/CSSStyleDeclaration.js
+++ b/lib/CSSStyleDeclaration.js
@@ -56,6 +56,11 @@ CSSStyleDeclaration.prototype = {
       this.removeProperty(name);
       return;
     }
+    var isCustomProperty = name.indexOf('--') === 0;
+    if (isCustomProperty) {
+      this._setProperty(name, value, priority);
+      return;
+    }
     var lowercaseName = name.toLowerCase();
     if (!allProperties.has(lowercaseName) && !allExtraProperties.has(lowercaseName)) {
       return;


Test patch:
diff --git a/lib/CSSStyleDeclaration.test.js b/lib/CSSStyleDeclaration.test.js
index a246036..d0cba23 100644
--- a/lib/CSSStyleDeclaration.test.js
+++ b/lib/CSSStyleDeclaration.test.js
@@ -518,4 +518,33 @@ describe('CSSStyleDeclaration', () => {
     expect(0).toEqual(style.length);
     expect(undefined).toEqual(style[0]);
   });
+
+  test('getPropertyValue for custom properties in cssText', () => {
+    const style = new CSSStyleDeclaration();
+    style.cssText = '--foo: red';
+
+    expect(style.getPropertyValue('--foo')).toEqual('red');
+  });
+
+  test('getPropertyValue for custom properties with setProperty', () => {
+    const style = new CSSStyleDeclaration();
+    style.setProperty('--bar', 'blue');
+
+    expect(style.getPropertyValue('--bar')).toEqual('blue');
+  });
+
+  test('getPropertyValue for custom properties with object setter', () => {
+    const style = new CSSStyleDeclaration();
+    style['--baz'] = 'yellow';
+
+    expect(style.getPropertyValue('--baz')).toEqual('');
+  });
+
+  test('custom properties are case-sensitive', () => {
+    const style = new CSSStyleDeclaration();
+    style.cssText = '--fOo: purple';
+
+    expect(style.getPropertyValue('--foo')).toEqual('');
+    expect(style.getPropertyValue('--fOo')).toEqual('purple');
+  });
 });
Repository: jsdom/cssstyle
Pull request #175 (2024-06-26 13:06:43)

Add calc support for margin and padding
Add support for `calc` for `margin` and `padding`. Other properties such as `width`, `top`, ... already support calc.

More properties should support `calc`, but I haven't included them all in this PR:
- `background-position: calc(100% - 0%) calc(100% - 10%)`. Not included because `parse` function splits on whitespace, but whitespace can also occur inside calc parentheses.
- `border-bottom-width` (and other "length" types): uses `parseLength` (from `parsers.js`), didn't want to change because too many usages. It could be done though, for example `parseMeasurement` already allows `calc`.

This PR should fix https://github.com/jsdom/cssstyle/issues/154

BramMeerten: @domenic could you please have a look at this small PR?

Patch:
diff --git a/lib/properties/margin.js b/lib/properties/margin.js
index 3a42cd7..fc6f031 100644
--- a/lib/properties/margin.js
+++ b/lib/properties/margin.js
@@ -12,6 +12,7 @@ var isValid = function (v) {
     type === TYPES.NULL_OR_EMPTY_STR ||
     type === TYPES.LENGTH ||
     type === TYPES.PERCENT ||
+    type === TYPES.CALC ||
     (type === TYPES.INTEGER && (v === '0' || v === 0))
   );
 };
diff --git a/lib/properties/padding.js b/lib/properties/padding.js
index 3848913..a82900b 100644
--- a/lib/properties/padding.js
+++ b/lib/properties/padding.js
@@ -9,6 +9,7 @@ var isValid = function (v) {
     type === TYPES.NULL_OR_EMPTY_STR ||
     type === TYPES.LENGTH ||
     type === TYPES.PERCENT ||
+    type === TYPES.CALC ||
     (type === TYPES.INTEGER && (v === '0' || v === 0))
   );
 };


Test patch:
diff --git a/test/CSSStyleDeclaration.js b/test/CSSStyleDeclaration.js
index 0ee7cd4..b2f20a2 100644
--- a/test/CSSStyleDeclaration.js
+++ b/test/CSSStyleDeclaration.js
@@ -727,9 +727,19 @@ describe('CSSStyleDeclaration', () => {
     assert.strictEqual(style.getPropertyValue('--fOo'), 'purple');
   });
 
-  it('supports calc', () => {
-    const style = new CSSStyleDeclaration();
-    style.setProperty('width', 'calc(100% - 100px)');
-    assert.strictEqual(style.getPropertyValue('width'), 'calc(100% - 100px)');
-  });
+  for (const property of [
+    'width',
+    'height',
+    'margin',
+    'margin-top',
+    'bottom',
+    'right',
+    'padding',
+  ]) {
+    it(`supports calc for ${property}`, () => {
+      const style = new CSSStyleDeclaration();
+      style.setProperty(property, 'calc(100% - 100px)');
+      assert.strictEqual(style.getPropertyValue(property), 'calc(100% - 100px)');
+    });
+  }
 });