UNPKG

molstar

Version:

A comprehensive macromolecular library.

153 lines 5.98 kB
"use strict"; /** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ColorSwatch = exports.getAdjustedColorMap = exports.ColorMap = exports.ColorTable = exports.ColorList = exports.Color = void 0; var hcl_1 = require("./spaces/hcl"); var lab_1 = require("./spaces/lab"); function Color(hex) { return hex; } exports.Color = Color; (function (Color) { function toStyle(hexColor) { return "rgb(" + (hexColor >> 16 & 255) + ", " + (hexColor >> 8 & 255) + ", " + (hexColor & 255) + ")"; } Color.toStyle = toStyle; function toHexString(hexColor) { return '0x' + ('000000' + hexColor.toString(16)).slice(-6); } Color.toHexString = toHexString; function toRgbString(hexColor) { return "RGB: " + Color.toRgb(hexColor).join(', '); } Color.toRgbString = toRgbString; function toRgb(hexColor) { return [hexColor >> 16 & 255, hexColor >> 8 & 255, hexColor & 255]; } Color.toRgb = toRgb; function toRgbNormalized(hexColor) { return [(hexColor >> 16 & 255) / 255, (hexColor >> 8 & 255) / 255, (hexColor & 255) / 255]; } Color.toRgbNormalized = toRgbNormalized; function fromRgb(r, g, b) { return ((r << 16) | (g << 8) | b); } Color.fromRgb = fromRgb; function fromNormalizedRgb(r, g, b) { return (((r * 255) << 16) | ((g * 255) << 8) | (b * 255)); } Color.fromNormalizedRgb = fromNormalizedRgb; function fromArray(array, offset) { return fromRgb(array[offset], array[offset + 1], array[offset + 2]); } Color.fromArray = fromArray; function fromNormalizedArray(array, offset) { return fromNormalizedRgb(array[offset], array[offset + 1], array[offset + 2]); } Color.fromNormalizedArray = fromNormalizedArray; /** Copies hex color to rgb array */ function toArray(hexColor, array, offset) { array[offset] = (hexColor >> 16 & 255); array[offset + 1] = (hexColor >> 8 & 255); array[offset + 2] = (hexColor & 255); return array; } Color.toArray = toArray; /** Copies normalized (0 to 1) hex color to rgb array */ function toArrayNormalized(hexColor, array, offset) { array[offset] = (hexColor >> 16 & 255) / 255; array[offset + 1] = (hexColor >> 8 & 255) / 255; array[offset + 2] = (hexColor & 255) / 255; return array; } Color.toArrayNormalized = toArrayNormalized; /** Copies hex color to rgb vec3 */ function toVec3(out, hexColor) { out[0] = (hexColor >> 16 & 255); out[1] = (hexColor >> 8 & 255); out[2] = (hexColor & 255); return out; } Color.toVec3 = toVec3; /** Copies normalized (0 to 1) hex color to rgb vec3 */ function toVec3Normalized(out, hexColor) { out[0] = (hexColor >> 16 & 255) / 255; out[1] = (hexColor >> 8 & 255) / 255; out[2] = (hexColor & 255) / 255; return out; } Color.toVec3Normalized = toVec3Normalized; /** Linear interpolation between two colors in rgb space */ function interpolate(c1, c2, t) { var r1 = c1 >> 16 & 255; var g1 = c1 >> 8 & 255; var b1 = c1 & 255; var r2 = c2 >> 16 & 255; var g2 = c2 >> 8 & 255; var b2 = c2 & 255; var r = r1 + (r2 - r1) * t; var g = g1 + (g2 - g1) * t; var b = b1 + (b2 - b1) * t; return ((r << 16) | (g << 8) | b); } Color.interpolate = interpolate; var tmpSaturateHcl = [0, 0, 0]; function saturate(c, amount) { hcl_1.Hcl.fromColor(tmpSaturateHcl, c); return hcl_1.Hcl.toColor(hcl_1.Hcl.saturate(tmpSaturateHcl, tmpSaturateHcl, amount)); } Color.saturate = saturate; function desaturate(c, amount) { return saturate(c, -amount); } Color.desaturate = desaturate; var tmpDarkenLab = [0, 0, 0]; function darken(c, amount) { lab_1.Lab.fromColor(tmpDarkenLab, c); return lab_1.Lab.toColor(lab_1.Lab.darken(tmpDarkenLab, tmpDarkenLab, amount)); } Color.darken = darken; function lighten(c, amount) { return darken(c, -amount); } Color.lighten = lighten; // function _sRGBToLinear(c) { return (c < 0.04045) ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4); } function sRGBToLinear(c) { return fromNormalizedRgb(_sRGBToLinear((c >> 16 & 255) / 255), _sRGBToLinear((c >> 8 & 255) / 255), _sRGBToLinear((c & 255) / 255)); } Color.sRGBToLinear = sRGBToLinear; function _linearToSRGB(c) { return (c < 0.0031308) ? c * 12.92 : 1.055 * (Math.pow(c, 0.41666)) - 0.055; } function linearToSRGB(c) { return fromNormalizedRgb(_linearToSRGB((c >> 16 & 255) / 255), _linearToSRGB((c >> 8 & 255) / 255), _linearToSRGB((c & 255) / 255)); } Color.linearToSRGB = linearToSRGB; })(Color = exports.Color || (exports.Color = {})); function ColorList(label, type, description, list) { return { label: label, description: description, list: list, type: type }; } exports.ColorList = ColorList; function ColorTable(o) { return o; } exports.ColorTable = ColorTable; function ColorMap(o) { return o; } exports.ColorMap = ColorMap; function getAdjustedColorMap(map, saturation, lightness) { var adjustedMap = {}; for (var e in map) { var c = map[e]; c = Color.saturate(c, saturation); c = Color.darken(c, -lightness); adjustedMap[e] = c; } return adjustedMap; } exports.getAdjustedColorMap = getAdjustedColorMap; function ColorSwatch(l) { return l; } exports.ColorSwatch = ColorSwatch; //# sourceMappingURL=color.js.map