7657431d64d0f151635822f7f53e7d2f07b2489710fbbb5a00f2d7180b5fce5c8e68c7b65fa11221d655e35f8e32c04b19b62c5bca69ca4dc124400ec4f4ef 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import { HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces.js';
  2. export interface TinyColorOptions {
  3. format: string;
  4. gradientType: string;
  5. }
  6. export type ColorInput = string | number | RGB | RGBA | HSL | HSLA | HSV | HSVA | TinyColor;
  7. export type ColorFormats = 'rgb' | 'prgb' | 'hex' | 'hex3' | 'hex4' | 'hex6' | 'hex8' | 'name' | 'hsl' | 'hsv';
  8. export declare class TinyColor {
  9. /** red */
  10. r: number;
  11. /** green */
  12. g: number;
  13. /** blue */
  14. b: number;
  15. /** alpha */
  16. a: number;
  17. /** the format used to create the tinycolor instance */
  18. format: ColorFormats;
  19. /** input passed into the constructer used to create the tinycolor instance */
  20. originalInput: ColorInput;
  21. /** the color was successfully parsed */
  22. isValid: boolean;
  23. gradientType?: string;
  24. /** rounded alpha */
  25. roundA: number;
  26. constructor(color?: ColorInput, opts?: Partial<TinyColorOptions>);
  27. isDark(): boolean;
  28. isLight(): boolean;
  29. /**
  30. * Returns the perceived brightness of the color, from 0-255.
  31. */
  32. getBrightness(): number;
  33. /**
  34. * Returns the perceived luminance of a color, from 0-1.
  35. */
  36. getLuminance(): number;
  37. /**
  38. * Returns the alpha value of a color, from 0-1.
  39. */
  40. getAlpha(): number;
  41. /**
  42. * Sets the alpha value on the current color.
  43. *
  44. * @param alpha - The new alpha value. The accepted range is 0-1.
  45. */
  46. setAlpha(alpha?: string | number): this;
  47. /**
  48. * Returns whether the color is monochrome.
  49. */
  50. isMonochrome(): boolean;
  51. /**
  52. * Returns the object as a HSVA object.
  53. */
  54. toHsv(): Numberify<HSVA>;
  55. /**
  56. * Returns the hsva values interpolated into a string with the following format:
  57. * "hsva(xxx, xxx, xxx, xx)".
  58. */
  59. toHsvString(): string;
  60. /**
  61. * Returns the object as a HSLA object.
  62. */
  63. toHsl(): Numberify<HSLA>;
  64. /**
  65. * Returns the hsla values interpolated into a string with the following format:
  66. * "hsla(xxx, xxx, xxx, xx)".
  67. */
  68. toHslString(): string;
  69. /**
  70. * Returns the hex value of the color.
  71. * @param allow3Char will shorten hex value to 3 char if possible
  72. */
  73. toHex(allow3Char?: boolean): string;
  74. /**
  75. * Returns the hex value of the color -with a # prefixed.
  76. * @param allow3Char will shorten hex value to 3 char if possible
  77. */
  78. toHexString(allow3Char?: boolean): string;
  79. /**
  80. * Returns the hex 8 value of the color.
  81. * @param allow4Char will shorten hex value to 4 char if possible
  82. */
  83. toHex8(allow4Char?: boolean): string;
  84. /**
  85. * Returns the hex 8 value of the color -with a # prefixed.
  86. * @param allow4Char will shorten hex value to 4 char if possible
  87. */
  88. toHex8String(allow4Char?: boolean): string;
  89. /**
  90. * Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
  91. * @param allowShortChar will shorten hex value to 3 or 4 char if possible
  92. */
  93. toHexShortString(allowShortChar?: boolean): string;
  94. /**
  95. * Returns the object as a RGBA object.
  96. */
  97. toRgb(): Numberify<RGBA>;
  98. /**
  99. * Returns the RGBA values interpolated into a string with the following format:
  100. * "RGBA(xxx, xxx, xxx, xx)".
  101. */
  102. toRgbString(): string;
  103. /**
  104. * Returns the object as a RGBA object.
  105. */
  106. toPercentageRgb(): RGBA;
  107. /**
  108. * Returns the RGBA relative values interpolated into a string
  109. */
  110. toPercentageRgbString(): string;
  111. /**
  112. * The 'real' name of the color -if there is one.
  113. */
  114. toName(): string | false;
  115. /**
  116. * String representation of the color.
  117. *
  118. * @param format - The format to be used when displaying the string representation.
  119. */
  120. toString<T extends 'name'>(format: T): boolean | string;
  121. toString<T extends ColorFormats>(format?: T): string;
  122. toNumber(): number;
  123. clone(): TinyColor;
  124. /**
  125. * Lighten the color a given amount. Providing 100 will always return white.
  126. * @param amount - valid between 1-100
  127. */
  128. lighten(amount?: number): TinyColor;
  129. /**
  130. * Brighten the color a given amount, from 0 to 100.
  131. * @param amount - valid between 1-100
  132. */
  133. brighten(amount?: number): TinyColor;
  134. /**
  135. * Darken the color a given amount, from 0 to 100.
  136. * Providing 100 will always return black.
  137. * @param amount - valid between 1-100
  138. */
  139. darken(amount?: number): TinyColor;
  140. /**
  141. * Mix the color with pure white, from 0 to 100.
  142. * Providing 0 will do nothing, providing 100 will always return white.
  143. * @param amount - valid between 1-100
  144. */
  145. tint(amount?: number): TinyColor;
  146. /**
  147. * Mix the color with pure black, from 0 to 100.
  148. * Providing 0 will do nothing, providing 100 will always return black.
  149. * @param amount - valid between 1-100
  150. */
  151. shade(amount?: number): TinyColor;
  152. /**
  153. * Desaturate the color a given amount, from 0 to 100.
  154. * Providing 100 will is the same as calling greyscale
  155. * @param amount - valid between 1-100
  156. */
  157. desaturate(amount?: number): TinyColor;
  158. /**
  159. * Saturate the color a given amount, from 0 to 100.
  160. * @param amount - valid between 1-100
  161. */
  162. saturate(amount?: number): TinyColor;
  163. /**
  164. * Completely desaturates a color into greyscale.
  165. * Same as calling `desaturate(100)`
  166. */
  167. greyscale(): TinyColor;
  168. /**
  169. * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
  170. * Values outside of this range will be wrapped into this range.
  171. */
  172. spin(amount: number): TinyColor;
  173. /**
  174. * Mix the current color a given amount with another color, from 0 to 100.
  175. * 0 means no mixing (return current color).
  176. */
  177. mix(color: ColorInput, amount?: number): TinyColor;
  178. analogous(results?: number, slices?: number): TinyColor[];
  179. /**
  180. * taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js
  181. */
  182. complement(): TinyColor;
  183. monochromatic(results?: number): TinyColor[];
  184. splitcomplement(): TinyColor[];
  185. /**
  186. * Compute how the color would appear on a background
  187. */
  188. onBackground(background: ColorInput): TinyColor;
  189. /**
  190. * Alias for `polyad(3)`
  191. */
  192. triad(): TinyColor[];
  193. /**
  194. * Alias for `polyad(4)`
  195. */
  196. tetrad(): TinyColor[];
  197. /**
  198. * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...)
  199. * monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...
  200. */
  201. polyad(n: number): TinyColor[];
  202. /**
  203. * compare color vs current color
  204. */
  205. equals(color?: ColorInput): boolean;
  206. }
  207. export declare function tinycolor(color?: ColorInput, opts?: Partial<TinyColorOptions>): TinyColor;