Skip to content

Commit 858ebdb

Browse files
committed
feat: upgrade TinyColor to 3.3.1, new method "onBackground"
1 parent 8b30909 commit 858ebdb

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

__tests__/Tinycolor_tests.re

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,44 @@ describe("set and get alpha (also tests clone())", () => {
178178
});
179179
});
180180

181+
describe("onBackground()", () => {
182+
let blue = TinyColor.makeFromString("blue");
183+
let red = TinyColor.makeFromString("red");
184+
test("get back same color when no transparency", () => {
185+
switch (blue, red) {
186+
| (Some(blue), Some(red)) =>
187+
expect(TinyColor.onBackground(blue, red) |> TinyColor.toHexString)
188+
== "#0000ff"
189+
| _ => expect(true) == false
190+
}
191+
});
192+
193+
test("get back background color when full transparency", () => {
194+
switch (blue, red) {
195+
| (Some(blue), Some(red)) =>
196+
let blueTransparent = TinyColor.setAlpha(0.0, blue);
197+
expect(
198+
TinyColor.onBackground(blueTransparent, red) |> TinyColor.toHexString,
199+
)
200+
== "#ff0000";
201+
| _ => expect(true) == false
202+
}
203+
});
204+
205+
test("get back mixed color when partly transparent", () => {
206+
switch (blue, red) {
207+
| (Some(blue), Some(red)) =>
208+
let bluePartlyTransparent = TinyColor.setAlpha(0.5, blue);
209+
expect(
210+
TinyColor.onBackground(bluePartlyTransparent, red)
211+
|> TinyColor.toHexString,
212+
)
213+
== "#800080";
214+
| _ => expect(true) == false
215+
}
216+
});
217+
});
218+
181219
describe("getBrightness()", () => {
182220
test("getting brightness for light color", () => {
183221
let color = TinyColor.makeFromString("white");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"bs-platform": "^8.4.2"
2323
},
2424
"dependencies": {
25-
"@ctrl/tinycolor": "^3.1.3"
25+
"@ctrl/tinycolor": "^3.3.1"
2626
}
2727
}

src/TinyColor.re

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ let setAlpha = (alphaValue: float, color: t): t => {
243243
setAlpha(colorClone, alphaValue);
244244
};
245245

246+
[@bs.send] external onBackground: (t, t) => t = "onBackground";
247+
246248
/* STRING REPRESENTATIONS */
247249

248250
[@bs.send] external toHsv: t => Js.t('hsv) = "toHsv";

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@
278278
exec-sh "^0.3.2"
279279
minimist "^1.2.0"
280280

281-
"@ctrl/tinycolor@^3.1.3":
282-
version "3.1.3"
283-
resolved "https://registry.yarnpkg.com/@ctrl/tinycolor/-/tinycolor-3.1.3.tgz#3406f90fd04a394a83fe874b763b7d89edffd4c1"
284-
integrity sha512-dHamDINLG/gF4Q6m3Ndnn4nGfLUCmvhY6Oweudqr2hMAMTIB2NvFrNW5HyjtdbqjNz9Z/unvA+/GI9QqBRgX0g==
281+
"@ctrl/tinycolor@^3.3.1":
282+
version "3.3.1"
283+
resolved "https://registry.yarnpkg.com/@ctrl/tinycolor/-/tinycolor-3.3.1.tgz#fa0efcf813daa43f8a6aef3ddaa80f7e66f1278e"
284+
integrity sha512-jUJrjU62MUgHDSu5JfONfgRM2V7GfN5KknsygfIbxwRZXGeayIzxk4O9GiYgEAr9DG5HJThTF5+a5x3wtrOKzQ==
285285

286286
"@glennsl/bs-jest@^0.6.0":
287287
version "0.6.0"

0 commit comments

Comments
 (0)