Skip to content

Commit

Permalink
Allow usage of strings in autoFocus.focusOn (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
magdakwiecien authored Oct 3, 2024
1 parent 91e8568 commit 6558301
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion __TESTS__/unit/values/gravity/Gravity.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Gravity} from "../../../../src/qualifiers/gravity";
import {Gravity, autoGravity} from "../../../../src/qualifiers/gravity";
import {focusOn} from "../../../../src/qualifiers/autoFocus";
import {crop} from "../../../../src/actions/resize";
import {Transformation} from "../../../../src";

Expand All @@ -16,4 +17,12 @@ describe('Gravity Qualifier', () => {
.gravity('auto')).toString();
expect(tx).toContain('c_crop,g_auto,h_250,w_250');
});
it('Can use any string in autoFocus.focusOn()', ()=>{
const tx = new Transformation()
.resize(crop()
.width(250)
.height(250)
.gravity(autoGravity().autoFocus(focusOn("ball")))).toString();
expect(tx).toContain('c_crop,g_auto:ball,h_250,w_250');
});
});
5 changes: 3 additions & 2 deletions src/qualifiers/autoFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class AutoFocus extends QualifierValue {
* @param {Qualifiers.FocusOn} obj The object to focus on.
* @param {number} weight
*/
static focusOn(obj: FocusOnValue, weight?: number): AutoFocus {
return new AutoFocus(obj, weight);
static focusOn(obj: FocusOnValue | string, weight?: number): AutoFocus {
const focusOn = obj instanceof FocusOnValue ? obj : new FocusOnValue(obj);
return new AutoFocus(focusOn, weight);
}

constructor(focusOn: FocusOnValue, weight?: number | string) {
Expand Down

0 comments on commit 6558301

Please sign in to comment.