7cba6a2e793992201ea1f79f189f031b69c63ad0a83655923788e42a951bc64ac5cb1166de51129c7de0c253326584d3dd86cc11aee26df2408a0325aa5105 723 B

12345678910111213141516171819202122232425
  1. import { TinyColor } from './index.js';
  2. import { convertToPercentage } from './util.js';
  3. /**
  4. * If input is an object, force 1 into "1.0" to handle ratios properly
  5. * String input requires "1.0" as input, so 1 will be treated as 1
  6. */
  7. export function fromRatio(ratio, opts) {
  8. var newColor = {
  9. r: convertToPercentage(ratio.r),
  10. g: convertToPercentage(ratio.g),
  11. b: convertToPercentage(ratio.b),
  12. };
  13. if (ratio.a !== undefined) {
  14. newColor.a = Number(ratio.a);
  15. }
  16. return new TinyColor(newColor, opts);
  17. }
  18. /** old random function */
  19. export function legacyRandom() {
  20. return new TinyColor({
  21. r: Math.random(),
  22. g: Math.random(),
  23. b: Math.random(),
  24. });
  25. }