Skip to content

Commit

Permalink
Update for no CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGriffiths committed Nov 5, 2021
1 parent 7a0e87d commit 0a8c65d
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 2,338 deletions.
17 changes: 5 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
* @return {function} The resultant name/function map.
*/
export function chalkish(palette: any): Function;
export const console: any;
export const metadata: {
readonly name: string;
readonly description: string;
readonly copyright: any;
readonly license: string;
readonly bugs: string;
readonly bin: string;
version: (style?: number) => string;
};
/**
* Create a map of trucolor instances from a map of name/color values.
* @param {Object} options Options to pass to trucolor creation.
Expand All @@ -22,7 +12,11 @@ export const metadata: {
*/
export function palette(options: any, palette: any): any;
declare function parser(color: any): Processor[];
export function render(processor: any, options?: {}): any;
export function render(processor: any, { type, format, force, }: {
type?: string;
format: any;
force: any;
}): any;
/**
* Create a simple, sharable palette
* @param {Object} options Options to pass to trucolor creation.
Expand Down Expand Up @@ -60,7 +54,6 @@ export function render(processor: any, options?: {}): any;
* }
*/
export function simple(options: any): any;
export function simplePalette(options: any): any;
/**
* Color retreival API. Will return different values if called with a cli or sgr context.
* @name Trucolor
Expand Down
45 changes: 10 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import _ from 'lodash';
import { createConsole } from 'verbosity';
import meta from '@thebespokepixel/meta';
import { tinycolor, TinyColor, names } from '@thebespokepixel/es-tinycolor';
import converter from 'color-convert';
import SGRcomposer from 'sgr-composer';
import terminal from 'term-ng';
import { readPackageSync } from 'read-pkg';
import escStringRE from 'escape-string-regexp';
import converter from 'color-convert';

class Processor {
constructor(colorname) {
Expand All @@ -29,7 +25,6 @@ class Processor {
this.haveQueue = false;
this.namePrefix = '';
this.nameSuffix = '';
console.debug(`New Process: ${this.baseName}`);
}
render() {
return this.haveSource ? _.reduce(this.queue,
Expand All @@ -55,7 +50,6 @@ class Processor {
return this.haveSource && this.interpreter.rgb
}
lock(lockedName) {
console.debug(`Process name locked: ${lockedName}`);
this.lockedName = lockedName;
}
get locked() {
Expand Down Expand Up @@ -88,73 +82,59 @@ class Processor {
}
background() {
this.attrs = 'background';
console.debug('Special::background');
}
bold() {
this.attrs = 'bold';
console.debug('Special::bold');
}
dim() {
this.attrs = 'dim';
console.debug('Special::dim');
}
italic() {
this.attrs = 'italic';
console.debug('Special::italic');
}
invert() {
this.attrs = 'invert';
console.debug('Special::invert');
}
underline() {
this.attrs = 'underline';
console.debug('Special::underline');
}
blink() {
this.attrs = 'blink';
console.debug('Special::blink');
}
saturate(args) {
this.addStep(color => color.saturate(args.percent));
this.namePrefix = `sat-${this.namePrefix}`;
this.nameSuffix = `${this.nameSuffix}-${args.percent}`;
console.debug('Process::saturate', args.percent);
}
desaturate(args) {
this.addStep(color => color.desaturate(args.percent));
this.namePrefix = `des-${this.namePrefix}`;
this.nameSuffix = `${this.nameSuffix}-${args.percent}`;
console.debug('Process::desaturate', args.percent);
}
darken(args) {
this.addStep(color => color.darken(args.percent));
this.namePrefix = `dark-${this.namePrefix}`;
this.nameSuffix = `${this.nameSuffix}-${args.percent}`;
console.debug('Process::darken', args.percent);
}
lighten(args) {
this.addStep(color => color.lighten(args.percent));
this.namePrefix = `light-${this.namePrefix}`;
this.nameSuffix = `${this.nameSuffix}-${args.percent}`;
console.debug('Process::lighten', args.percent);
}
spin(args) {
this.addStep(color => color.spin(-args.rotation));
this.namePrefix = `spin-${this.namePrefix}`;
this.nameSuffix = `${this.nameSuffix}-${Math.abs(args.rotation)}`;
console.debug('Process::spin', args.rotation);
}
mono() {
this.addStep(color => color.greyscale());
this.namePrefix = `mono-${this.namePrefix}`;
this.nameSuffix = `${this.nameSuffix}}`;
console.debug('Process::mono');
}
mix(args) {
this.addStep(color => TinyColor.mix(color, args.color, 50));
this.namePrefix = `mix-${this.namePrefix}`;
this.nameSuffix = `${this.nameSuffix}-${args.color}`;
console.debug('Process::mix', args.color);
}
}
function processor(name) {
Expand Down Expand Up @@ -317,7 +297,6 @@ class Interpreter {
}
this.baseName = source.name;
this.baseColor = source.space === 'SGR' ? source.name : tinycolor(source.rgb ? `rgb(${source.rgb})` : source.name);
console.debug(`Color (${this.baseName}) ${this.baseColor} from ${this.source.space} as ${this.source.human}`);
}
get name() {
return this.baseName
Expand Down Expand Up @@ -448,14 +427,15 @@ function parser(color) {

const pkg = readPackageSync();
const colorLevel = terminal.color.level || 0;
function render(processor, options = {}) {
const {
format: outputFormat,
} = options;
function render(processor, {
type = 'default',
format,
force,
}) {
const color = processor.render();
const isReset = ['normal', 'reset'].includes(processor.name);
const sgrComposer = new SGRcomposer(
options.force || colorLevel,
force || colorLevel,
Object.assign(processor.attrs, processor.hasSource ? {
color: isReset ? processor.name : color.toRgbArray(),
} : {}),
Expand All @@ -478,8 +458,8 @@ function render(processor, options = {}) {
default:
return pkg.config.cli[type]
}
})(global.trucolorCLItype);
switch (outputFormat) {
})(type);
switch (format) {
case 'cli':
return {
name: processor.human,
Expand Down Expand Up @@ -587,8 +567,6 @@ const palette$1 = {
reset: 'reset',
};

const console = createConsole({outStream: process.stderr});
const metadata = meta(dirname(fileURLToPath(import.meta.url)));
/**
* Color retreival API. Will return different values if called with a cli or sgr context.
* @name Trucolor
Expand Down Expand Up @@ -674,8 +652,5 @@ function chalkish(palette) {
function simple(options) {
return palette(options, palette$1)
}
function simplePalette(options) {
return palette(options, palette$1)
}

export { chalkish, console, metadata, palette, parser as parse, render, simple, simplePalette, trucolor };
export { chalkish, palette, parser as parse, render, simple, trucolor };
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Mark Griffiths
Copyright (c) 2021 Mark Griffiths

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
Binary file removed media/ByteTree.png
Binary file not shown.
Binary file removed media/CCLogo.png
Binary file not shown.
Binary file removed media/example.png
Binary file not shown.
Binary file removed media/formatters.png
Binary file not shown.
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
"main": "index.js",
"types": "index.d.ts",
"type": "module",
"bin": {
"trucolor": "./bin/trucolor"
},
"files": [
"index.js",
"index.d.ts",
"bin/"
"index.d.ts"
],
"bugs": {
"url": "https://github.com/thebespokepixel/trucolor/issues"
Expand Down Expand Up @@ -80,7 +76,6 @@
},
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@types/estree": "^0.0.50",
"ava": "^4.0.0-rc.1",
Expand Down Expand Up @@ -110,7 +105,7 @@
"url": "git+https://github.com/thebespokepixel/trucolor.git"
},
"scripts": {
"build": "rollup -c && chmod 755 trucolor.js && npm run readme",
"build": "rollup -c && npm run readme",
"test": "xo && c8 --reporter=text ava",
"doc-serve": "documentation serve --watch --theme node_modules/documentation-theme-bespoke --github --config src/docs/documentation.yml --project-name $npm_package_name --project-version $npm_package_version src/index.js",
"doc-build": "documentation build --format html --output docs --theme node_modules/documentation-theme-bespoke --github --config src/docs/documentation.yml --project-name $npm_package_name --project-version $npm_package_version src/index.js",
Expand All @@ -122,7 +117,6 @@
"semicolon": false,
"ignores": [
"index.js",
"trucolor.js",
"index.d.ts",
"docs/**",
"coverage/**"
Expand Down Expand Up @@ -183,4 +177,4 @@
]
]
}
}
}
Loading

0 comments on commit 0a8c65d

Please sign in to comment.