UNPKG

@pixi/utils

Version:

Collection of utilities used by PixiJS

1 lines 3.04 kB
{"version":3,"file":"hex.mjs","sources":["../../src/color/hex.ts"],"sourcesContent":["import { Color } from '@pixi/color';\nimport { deprecation } from '../logging/deprecation';\n\n/**\n * Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0).\n * @memberof PIXI.utils\n * @function hex2rgb\n * @see PIXI.Color.toRgbArray\n * @deprecated since 7.2.0\n * @param {number} hex - The hexadecimal number to convert\n * @param {number[]} [out=[]] - If supplied, this array will be used rather than returning a new one\n * @returns {number[]} An array representing the [R, G, B] of the color where all values are floats.\n */\nexport function hex2rgb(hex: number, out: Array<number> | Float32Array = []): Array<number> | Float32Array\n{\n if (process.env.DEBUG)\n {\n deprecation('7.2.0', 'utils.hex2rgb is deprecated, use Color#toRgbArray instead');\n }\n\n return Color.shared.setValue(hex).toRgbArray(out);\n}\n\n/**\n * Converts a hexadecimal color number to a string.\n * @see PIXI.Color.toHex\n * @deprecated since 7.2.0\n * @memberof PIXI.utils\n * @function hex2string\n * @param {number} hex - Number in hex (e.g., `0xffffff`)\n * @returns {string} The string color (e.g., `\"#ffffff\"`).\n */\nexport function hex2string(hex: number): string\n{\n if (process.env.DEBUG)\n {\n deprecation('7.2.0', 'utils.hex2string is deprecated, use Color#toHex instead');\n }\n\n return Color.shared.setValue(hex).toHex();\n}\n\n/**\n * Converts a string to a hexadecimal color number.\n * @deprecated since 7.2.0\n * @see PIXI.Color.toNumber\n * @memberof PIXI.utils\n * @function string2hex\n * @param {string} string - The string color (e.g., `\"#ffffff\"`)\n * @returns {number} Number in hexadecimal.\n */\nexport function string2hex(string: string): number\n{\n if (process.env.DEBUG)\n {\n deprecation('7.2.0', 'utils.string2hex is deprecated, use Color#toNumber instead');\n }\n\n return Color.shared.setValue(string).toNumber();\n}\n\n/**\n * Converts a color as an [R, G, B] array of normalized floats to a hexadecimal number.\n * @deprecated since 7.2.0\n * @see PIXI.Color.toNumber\n * @memberof PIXI.utils\n * @function rgb2hex\n * @param {number[]} rgb - Array of numbers where all values are normalized floats from 0.0 to 1.0.\n * @returns {number} Number in hexadecimal.\n */\nexport function rgb2hex(rgb: number[] | Float32Array): number\n{\n if (process.env.DEBUG)\n {\n deprecation('7.2.0', 'utils.rgb2hex is deprecated, use Color#toNumber instead');\n }\n\n return Color.shared.setValue(rgb).toNumber();\n}\n"],"names":[],"mappings":";;AAaO,SAAS,QAAQ,KAAa,MAAoC,IACzE;AAGoB,SAAA,YAAA,SAAS,2DAA2D,GAG7E,MAAM,OAAO,SAAS,GAAG,EAAE,WAAW,GAAG;AACpD;AAWO,SAAS,WAAW,KAC3B;AAGoB,SAAA,YAAA,SAAS,yDAAyD,GAG3E,MAAM,OAAO,SAAS,GAAG,EAAE;AACtC;AAWO,SAAS,WAAW,QAC3B;AAGoB,SAAA,YAAA,SAAS,4DAA4D,GAG9E,MAAM,OAAO,SAAS,MAAM,EAAE;AACzC;AAWO,SAAS,QAAQ,KACxB;AAGoB,SAAA,YAAA,SAAS,yDAAyD,GAG3E,MAAM,OAAO,SAAS,GAAG,EAAE;AACtC;"}