You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB

2 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. function _export(target, all) {
  6. for(var name in all)Object.defineProperty(target, name, {
  7. enumerable: true,
  8. get: all[name]
  9. });
  10. }
  11. _export(exports, {
  12. withAlphaValue: ()=>withAlphaValue,
  13. default: ()=>withAlphaVariable
  14. });
  15. const _color = require("./color");
  16. function withAlphaValue(color, alphaValue, defaultValue) {
  17. if (typeof color === "function") {
  18. return color({
  19. opacityValue: alphaValue
  20. });
  21. }
  22. let parsed = (0, _color.parseColor)(color, {
  23. loose: true
  24. });
  25. if (parsed === null) {
  26. return defaultValue;
  27. }
  28. return (0, _color.formatColor)({
  29. ...parsed,
  30. alpha: alphaValue
  31. });
  32. }
  33. function withAlphaVariable({ color , property , variable }) {
  34. let properties = [].concat(property);
  35. if (typeof color === "function") {
  36. return {
  37. [variable]: "1",
  38. ...Object.fromEntries(properties.map((p)=>{
  39. return [
  40. p,
  41. color({
  42. opacityVariable: variable,
  43. opacityValue: `var(${variable})`
  44. })
  45. ];
  46. }))
  47. };
  48. }
  49. const parsed = (0, _color.parseColor)(color);
  50. if (parsed === null) {
  51. return Object.fromEntries(properties.map((p)=>[
  52. p,
  53. color
  54. ]));
  55. }
  56. if (parsed.alpha !== undefined) {
  57. // Has an alpha value, return color as-is
  58. return Object.fromEntries(properties.map((p)=>[
  59. p,
  60. color
  61. ]));
  62. }
  63. return {
  64. [variable]: "1",
  65. ...Object.fromEntries(properties.map((p)=>{
  66. return [
  67. p,
  68. (0, _color.formatColor)({
  69. ...parsed,
  70. alpha: `var(${variable})`
  71. })
  72. ];
  73. }))
  74. };
  75. }