-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from arvindcheenu/2.0
✨ New in v.2.0 : Lose some features, Gain even more!
- Loading branch information
Showing
25 changed files
with
184 additions
and
499 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,4 @@ | ||
import Matercolor from '../src/index.js'; | ||
|
||
const PurplePalette = new Matercolor ('#6200EE'); | ||
console.log ('\n\nPALETTE CLASS\n\n'); | ||
console.log (JSON.stringify (PurplePalette, null, 2)); | ||
// Matercolor {color: "#6200EE", options: Object, palette: function (), constructor: Object} | ||
console.log ('\n\nPALETTE OBJECT\n\n'); | ||
console.log (JSON.stringify (PurplePalette.palette (), null, 2)); | ||
/** | ||
* Object {primary: Object} | ||
primary: Object | ||
50: Object | ||
100: Object | ||
200: Object | ||
300: Object | ||
400: Object | ||
500: Object | ||
600: Object | ||
700: Object | ||
800: Object | ||
900: Object | ||
A100: Object | ||
A200: Object | ||
A400: Object | ||
A700: Object | ||
secondary : Object | ||
50: Object | ||
100: Object | ||
200: Object | ||
300: Object | ||
400: Object | ||
500: Object | ||
600: Object | ||
700: Object | ||
800: Object | ||
900: Object | ||
A100: Object | ||
A200: Object | ||
A400: Object | ||
A700: Object | ||
*/ | ||
|
||
console.log ('\n\nPRIMARY PALETTE SHADES\n\n'); | ||
console.log (JSON.stringify (PurplePalette.shades ('primary'), null, 2)); | ||
// Object {light: Object, main: Object, dark: Object} | ||
console.log ('\n\nPRIMARY PALETTE ACCENTS\n\n'); | ||
console.log (JSON.stringify (PurplePalette.accents ('primary'), null, 2)); | ||
// Object {A100: Object, A200: Object, A400: Object, A700: Object} | ||
|
||
console.log ('\n\nSECONDARY PALETTE SHADES\n\n'); | ||
console.log (JSON.stringify (PurplePalette.shades ('secondary'), null, 2)); | ||
// Object {light: Object, main: Object, dark: Object} | ||
console.log ('\n\nSECONDARY PALETTE ACCENTS\n\n'); | ||
console.log (JSON.stringify (PurplePalette.accents ('secondary'), null, 2)); | ||
// Object {A100: Object, A200: Object, A400: Object, A700: Object} | ||
const Matercolor = require ('../dist/index.js'); | ||
const Purple = new Matercolor ('#6200EE', {showContrastText: true}); | ||
console.log ('\n\n PALETTE OBJECT\n\n'); | ||
console.log (JSON.stringify (Purple.palette, null, 2)); |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,89 @@ | ||
import { keys, defaultOptions } from './global.constants.js' | ||
import { | ||
normalizeRGB, rgbToHex, hexToRgba, RGBToCYMK, RGBToHSL, getContrastText, getComplementary | ||
normalizeRGB, | ||
rgbToHex, | ||
hexToRgba, | ||
getContrastText, | ||
rotateColorBy | ||
} from './color.utils.js' | ||
import { createPallete } from './goldenPalettes.js' | ||
export default class Matercolor { | ||
constructor (color, options) { | ||
this.palette = {} | ||
this.color = color | ||
const complementary = getComplementary(color) | ||
this.complementary = () => complementary | ||
this.options = options | ||
? Object.assign(defaultOptions, options) | ||
: defaultOptions | ||
const paletteObject = {} | ||
this.palette = () => paletteObject | ||
this.getPalette() | ||
this.complementary = () => rotateColorBy(this.color, 180) | ||
this.firstAnalogous = () => rotateColorBy(this.color, -30) | ||
this.secondAnalogous = () => rotateColorBy(this.color, 30) | ||
this.firstTriadic = () => rotateColorBy(this.color, 60) | ||
this.secondTriadic = () => rotateColorBy(this.color, 120) | ||
this.palette.primary = this.makePalette('primary') | ||
this.palette.complementary = this.makePalette('complementary') | ||
this.palette.analogous = {} | ||
this.palette.analogous.first = this.makePalette('firstAnalogous') | ||
this.palette.analogous.second = this.makePalette('secondAnalogous') | ||
this.palette.triadic = {} | ||
this.palette.triadic.first = this.makePalette('firstTriadic') | ||
this.palette.triadic.second = this.makePalette('secondTriadic') | ||
} | ||
|
||
shades (paletteType) { | ||
return { | ||
light: this.palette()[paletteType][this.options.light], | ||
main: this.palette()[paletteType][this.options.main], | ||
dark: this.palette()[paletteType][this.options.dark] | ||
makePalette (paletteName) { | ||
const localObject = {} | ||
let Color | ||
if (paletteName === 'primary') { | ||
Color = hexToRgba(this.color) | ||
} else if (paletteName === 'complementary') { | ||
Color = hexToRgba(this.complementary()) | ||
} else if (paletteName === 'firstAnalogous') { | ||
Color = hexToRgba(this.firstAnalogous()) | ||
} else if (paletteName === 'secondAnalogous') { | ||
Color = hexToRgba(this.secondAnalogous()) | ||
} else if (paletteName === 'analogous') { | ||
const analogousObject = {} | ||
analogousObject.first = this.makePalette('firstAnalogous') | ||
analogousObject.second = this.makePalette('secondAnalogous') | ||
return analogousObject | ||
} else if (paletteName === 'firstTriadic') { | ||
Color = hexToRgba(this.firstTriadic()) | ||
} else if (paletteName === 'secondTriadic') { | ||
Color = hexToRgba(this.secondTriadic()) | ||
} else if (paletteName === 'triadic') { | ||
const triadicObject = {} | ||
triadicObject.first = this.makePalette('firstTriadic') | ||
triadicObject.second = this.makePalette('secondTriadic') | ||
return triadicObject | ||
} | ||
} | ||
|
||
accents (paletteType) { | ||
return { | ||
A100: this.palette()[paletteType].A100, | ||
A200: this.palette()[paletteType].A200, | ||
A400: this.palette()[paletteType].A400, | ||
A700: this.palette()[paletteType].A700 | ||
} | ||
} | ||
|
||
getPalette () { | ||
this.palette().primary = {} | ||
this.palette().secondary = {} | ||
const primaryPalette = createPallete( | ||
normalizeRGB(hexToRgba(this.color)) | ||
).map(u => rgbToHex( | ||
Math.round(u.red * 255), | ||
Math.round(u.green * 255), | ||
Math.round(u.blue * 255) | ||
)) | ||
const primaryAccents = createPallete( | ||
normalizeRGB(hexToRgba(this.color)), | ||
true | ||
).map(u => rgbToHex( | ||
Math.round(u.red * 255), | ||
Math.round(u.green * 255), | ||
Math.round(u.blue * 255) | ||
)) | ||
const secondaryPalette = createPallete( | ||
normalizeRGB(hexToRgba(this.complementary())) | ||
).map(u => rgbToHex( | ||
Math.round(u.red * 255), | ||
Math.round(u.green * 255), | ||
Math.round(u.blue * 255) | ||
)) | ||
const secondaryAccents = createPallete( | ||
normalizeRGB(hexToRgba(this.complementary())), | ||
true | ||
).map(u => rgbToHex( | ||
Math.round(u.red * 255), | ||
Math.round(u.green * 255), | ||
Math.round(u.blue * 255) | ||
)) | ||
primaryPalette.push(...primaryAccents) | ||
for (let i = 0; i < keys.length; i += 1) { | ||
const colorObject = {} | ||
colorObject.hex = primaryPalette[i] | ||
colorObject.rgb = hexToRgba(primaryPalette[i]) | ||
colorObject.rgb.string = `rgb(${colorObject.rgb.r},${colorObject.rgb.g},${colorObject.rgb.b})` | ||
colorObject.hsl = RGBToHSL(colorObject.rgb) | ||
colorObject.cymk = RGBToCYMK(colorObject.rgb) | ||
colorObject.contrastText = getContrastText( | ||
colorObject.rgb, | ||
this.options.threshold | ||
const newPalette = createPallete(normalizeRGB(Color)).map(u => | ||
rgbToHex( | ||
Math.round(u.red * 255), | ||
Math.round(u.green * 255), | ||
Math.round(u.blue * 255) | ||
) | ||
this.palette().primary[keys[i]] = colorObject | ||
} | ||
secondaryPalette.push(...secondaryAccents) | ||
for (let i = 0; i < keys.length; i += 1) { | ||
const colorObject = {} | ||
colorObject.hex = secondaryPalette[i] | ||
colorObject.rgb = hexToRgba(secondaryPalette[i]) | ||
colorObject.rgb.string = `rgb(${colorObject.rgb.r},${colorObject.rgb.g},${colorObject.rgb.b})` | ||
colorObject.hsl = RGBToHSL(colorObject.rgb) | ||
colorObject.cymk = RGBToCYMK(colorObject.rgb) | ||
colorObject.contrastText = getContrastText( | ||
colorObject.rgb, | ||
this.options.threshold | ||
) | ||
const newAccents = createPallete(normalizeRGB(Color), true).map(u => | ||
rgbToHex( | ||
Math.round(u.red * 255), | ||
Math.round(u.green * 255), | ||
Math.round(u.blue * 255) | ||
) | ||
this.palette().secondary[keys[i]] = colorObject | ||
) | ||
newPalette.push(...newAccents) | ||
for (let i = 0; i < keys.length; i += 1) { | ||
let colorObject = {} | ||
if (this.options.showContrastText) { | ||
colorObject.hex = newPalette[i] | ||
const rgb = hexToRgba(newPalette[i]) | ||
colorObject.contrastText = getContrastText( | ||
rgb, | ||
this.options.threshold | ||
) | ||
} else { | ||
colorObject = newPalette[i] | ||
} | ||
localObject[keys[i]] = colorObject | ||
} | ||
return localObject | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import test from "ava" | ||
import { componentToHex } from "../../src/color.utils" | ||
import test from 'ava' | ||
import { componentToHex } from '../../src/color.utils' | ||
test('left pads zero if single digit hex', t => { | ||
t.is(componentToHex("f"), "0f") | ||
}) | ||
t.is(componentToHex('f'), '0f') | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.