@oxog/pigment 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ersin Koc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,406 @@
1
+ # @oxog/pigment
2
+
3
+ Zero-dependency terminal styling with micro-kernel architecture and Chalk drop-in compatibility.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@oxog/pigment)](https://www.npmjs.com/package/@oxog/pigment)
6
+ [![Build](https://img.shields.io/github/actions/workflow/publish.yml/ersinkoc/pigment)](https://github.com/ersinkoc/pigment)
7
+ [![Coverage](https://img.shields.io/codecov/c/github/ersinkoc/pigment?token=)](https://github.com/ersinkoc/pigment)
8
+ [![License](https://img.shields.io/npm/l/@oxog/pigment)](https://github.com/ersinkoc/pigment)
9
+ [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@oxog/pigment)](https://bundlephobia.com/result?p=@oxog/pigment)
10
+
11
+ ## Features
12
+
13
+ - **Zero Dependencies** - No external packages, implements everything from scratch
14
+ - **Universal Runtime** - Works in Node.js and browsers with same API
15
+ - **Micro-Kernel Architecture** - Powerful plugin system for extensibility
16
+ - **Chalk Compatible** - Drop-in replacement for Chalk v5
17
+ - **Multiple API Styles** - Proxy chaining, function composition, builder pattern
18
+ - **Full Color Support** - 16 base colors, 256 colors, true color (RGB/HEX/HSL)
19
+ - **Environment Aware** - Respects NO_COLOR, FORCE_COLOR, TTY detection
20
+ - **TypeScript** - Strict mode with full type safety
21
+ - **Tree Shakeable** - Optimize bundle size with individual imports
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @oxog/pigment
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ### Proxy-Based Chaining API (Primary)
32
+
33
+ ```typescript
34
+ import { pigment } from '@oxog/pigment';
35
+
36
+ // Chain styles naturally
37
+ pigment.bold.red('Error!');
38
+ pigment.italic.blue.bgWhite('Info');
39
+ pigment.underline.yellow('Warning');
40
+
41
+ // Nested styles
42
+ pigment.red(`Error: ${pigment.bold('critical')} issue`);
43
+ ```
44
+
45
+ ### Function Composition API (Tree-Shakeable)
46
+
47
+ ```typescript
48
+ import { bold, red, compose } from '@oxog/pigment';
49
+
50
+ // Compose styles
51
+ const error = compose(bold, red);
52
+ console.log(error('Something went wrong'));
53
+
54
+ // Reusable styles
55
+ const highlight = compose(bold, red);
56
+ console.log(highlight('IMPORTANT'));
57
+ ```
58
+
59
+ ### Builder Pattern API
60
+
61
+ ```typescript
62
+ import { createPigment } from '@oxog/pigment';
63
+
64
+ const styled = createPigment()
65
+ .bold()
66
+ .red()
67
+ .bgWhite()
68
+ .paint('Styled text');
69
+
70
+ console.log(styled);
71
+ ```
72
+
73
+ ### Chalk Drop-in Compatibility
74
+
75
+ ```typescript
76
+ // Before (Chalk)
77
+ import chalk from 'chalk';
78
+ console.log(chalk.red.bold('Error'));
79
+
80
+ // After (Pigment) - just change import
81
+ import chalk from '@oxog/pigment';
82
+ console.log(chalk.red.bold('Error'));
83
+ ```
84
+
85
+ ## Colors
86
+
87
+ ### 16 Base Colors
88
+
89
+ ```typescript
90
+ pigment.black('text');
91
+ pigment.red('text');
92
+ pigment.green('text');
93
+ pigment.yellow('text');
94
+ pigment.blue('text');
95
+ pigment.magenta('text');
96
+ pigment.cyan('text');
97
+ pigment.white('text');
98
+ ```
99
+
100
+ ### Bright Variants
101
+
102
+ ```typescript
103
+ pigment.blackBright('text'); // alias: gray
104
+ pigment.redBright('text');
105
+ pigment.greenBright('text');
106
+ pigment.yellowBright('text');
107
+ pigment.blueBright('text');
108
+ pigment.magentaBright('text');
109
+ pigment.cyanBright('text');
110
+ pigment.whiteBright('text');
111
+ ```
112
+
113
+ ### Background Colors
114
+
115
+ ```typescript
116
+ pigment.bgRed('text');
117
+ pigment.bgGreen('text');
118
+ pigment.bgBlue('text');
119
+ pigment.bgYellow('text');
120
+ // ... all 16 colors
121
+ pigment.bgRedBright('text');
122
+ ```
123
+
124
+ ## Modifiers
125
+
126
+ ```typescript
127
+ pigment.bold('Bold text');
128
+ pigment.dim('Dimmed text');
129
+ pigment.italic('Italic text');
130
+ pigment.underline('Underlined text');
131
+ pigment.strikethrough('Strikethrough text');
132
+ pigment.inverse('Inverse colors');
133
+ pigment.hidden('Hidden text');
134
+ pigment.reset('Reset all styles');
135
+ ```
136
+
137
+ ## Extended Colors
138
+
139
+ ### ANSI 256
140
+
141
+ ```typescript
142
+ pigment.ansi256(196)('Bright red');
143
+ pigment.bgAnsi256(21)('Blue background');
144
+ ```
145
+
146
+ ### True Color (RGB)
147
+
148
+ ```typescript
149
+ pigment.rgb(255, 136, 0)('Orange text');
150
+ pigment.bgRgb(0, 120, 255)('Blue background');
151
+ ```
152
+
153
+ ### HEX Colors
154
+
155
+ ```typescript
156
+ pigment.hex('#FF8800')('Orange text');
157
+ pigment.bgHex('#0078FF')('Blue background');
158
+ ```
159
+
160
+ ### HSL Colors
161
+
162
+ ```typescript
163
+ pigment.hsl(30, 100, 50)('Orange text');
164
+ pigment.bgHsl(210, 100, 50)('Blue background');
165
+ ```
166
+
167
+ ## Environment Detection
168
+
169
+ ```typescript
170
+ import { pigment, supportsColor } from '@oxog/pigment';
171
+
172
+ // Check color support
173
+ console.log(supportsColor);
174
+ // { level: 3, hasBasic: true, has256: true, has16m: true }
175
+
176
+ // Override level
177
+ const pigment = createPigment({ level: 3 });
178
+ ```
179
+
180
+ ### Environment Variables
181
+
182
+ - `NO_COLOR` - Disables all colors
183
+ - `FORCE_COLOR` - Forces color level (0, 1, 2, 3)
184
+ - `TERM` - Terminal type detection
185
+
186
+ ## Plugin System
187
+
188
+ ### Core Plugins (Always Loaded)
189
+
190
+ ```typescript
191
+ // 16 ANSI colors
192
+ baseColorsPlugin
193
+
194
+ // Text modifiers
195
+ modifiersPlugin
196
+
197
+ // 256-color palette
198
+ ansi256Plugin
199
+
200
+ // RGB/HEX/HSL color support
201
+ trueColorPlugin
202
+
203
+ // Nested/composed styles
204
+ nestingPlugin
205
+
206
+ // Environment detection
207
+ environmentPlugin
208
+ ```
209
+
210
+ ### Optional Plugins (Opt-in)
211
+
212
+ #### Gradient Plugin
213
+
214
+ ```typescript
215
+ import { createPigment } from '@oxog/pigment';
216
+ import { gradientPlugin } from '@oxog/pigment/plugins';
217
+
218
+ const pigment = createPigment({ plugins: [gradientPlugin({ steps: 10 })] });
219
+
220
+ // Linear gradient
221
+ pigment.gradient('red', 'blue')('Gradient text');
222
+ pigment.gradient('#FF0000', '#0000FF')('Hex gradient');
223
+ pigment.gradient([255, 0, 0], [0, 0, 255])('RGB gradient');
224
+
225
+ // Rainbow gradient
226
+ pigment.rainbow('Rainbow text');
227
+ ```
228
+
229
+ #### Theme Plugin
230
+
231
+ ```typescript
232
+ import { themePlugin } from '@oxog/pigment/plugins';
233
+
234
+ const pigment = createPigment({ plugins: [themePlugin({ preset: 'monokai' })] });
235
+
236
+ // Theme colors
237
+ pigment.theme.keyword('const'); // Orange
238
+ pigment.theme.string('"hello"'); // Yellow
239
+ pigment.theme.number('42'); // Purple
240
+ pigment.theme.comment('// note'); // Gray
241
+ pigment.theme.error('Error!'); // Red
242
+ pigment.theme.success('Done!'); // Green
243
+ ```
244
+
245
+ **Available Presets**: monokai, dracula, nord, github, vscode, tokyo-night, catppuccin, one-dark, solarized
246
+
247
+ #### Semantic Plugin
248
+
249
+ ```typescript
250
+ import { semanticPlugin } from '@oxog/pigment/plugins';
251
+
252
+ const pigment = createPigment({ plugins: [semanticPlugin()] });
253
+
254
+ pigment.success('✓ Task completed'); // Green
255
+ pigment.error('✗ Task failed'); // Red
256
+ pigment.warning('⚠ Check this'); // Yellow
257
+ pigment.info('ℹ Note'); // Blue
258
+ pigment.debug('[DEBUG] value'); // Gray
259
+
260
+ // Custom colors
261
+ semanticPlugin({
262
+ success: '#00FF00',
263
+ error: '#FF0000',
264
+ warning: '#FFAA00',
265
+ info: '#00AAFF',
266
+ debug: '#888888'
267
+ })
268
+ ```
269
+
270
+ #### Box Plugin
271
+
272
+ ```typescript
273
+ import { boxPlugin } from '@oxog/pigment/plugins';
274
+
275
+ const pigment = createPigment({ plugins: [boxPlugin()] });
276
+
277
+ // Simple box
278
+ pigment.box('Hello World');
279
+ // ┌─────────────┐
280
+ // │ Hello World │
281
+ // └─────────────┘
282
+
283
+ // Styled box
284
+ pigment.box('Error!', { border: 'double', padding: 2 });
285
+ // ╔═════════════╗
286
+ // ║ ║
287
+ // ║ Error! ║
288
+ // ║ ║
289
+ // ╚═════════════╝
290
+ ```
291
+
292
+ **Border Styles**: single, double, rounded, bold, classic
293
+
294
+ #### Template Plugin
295
+
296
+ ```typescript
297
+ import { templatePlugin } from '@oxog/pigment/plugins';
298
+
299
+ const pigment = createPigment({ plugins: [templatePlugin()] });
300
+
301
+ // Tagged template
302
+ console.log(pigment`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
303
+
304
+ // Nested styles
305
+ console.log(pigment`{bold.red CRITICAL:} {dim system failure}`);
306
+ ```
307
+
308
+ ### Ecosystem Plugin
309
+
310
+ ```typescript
311
+ import { pigmentPlugin } from '@oxog/pigment/plugins';
312
+
313
+ // For @oxog/log, @oxog/cli
314
+ log.use(pigmentPlugin({ theme: 'monokai', level: 3 }));
315
+ ```
316
+
317
+ ## API Reference
318
+
319
+ ### createPigment
320
+
321
+ ```typescript
322
+ import { createPigment } from '@oxog/pigment';
323
+
324
+ const pigment = createPigment({
325
+ level: 3, // Force color level
326
+ forceColor: false, // Force color output
327
+ noColor: false, // Disable all colors
328
+ plugins: [] // Custom plugins
329
+ });
330
+ ```
331
+
332
+ ### Type Definitions
333
+
334
+ ```typescript
335
+ interface Pigment {
336
+ // Text modifiers
337
+ bold: Pigment;
338
+ dim: Pigment;
339
+ italic: Pigment;
340
+ // ... all modifiers
341
+
342
+ // Foreground colors
343
+ black: Pigment;
344
+ red: Pigment;
345
+ green: Pigment;
346
+ // ... all colors
347
+
348
+ // Background colors
349
+ bgBlack: Pigment;
350
+ bgRed: Pigment;
351
+ // ... all background colors
352
+
353
+ // Extended colors
354
+ ansi256(code: number): Pigment;
355
+ rgb(r: number, g: number, b: number): Pigment;
356
+ hex(color: string): Pigment;
357
+ hsl(h: number, s: number, l: number): Pigment;
358
+
359
+ // Function call
360
+ (text: string): string;
361
+ }
362
+ ```
363
+
364
+ ## Platform Support
365
+
366
+ | Platform | Output | Auto-Detection |
367
+ |----------|---------|---------------|
368
+ | Node.js | ANSI escape codes | ✅ TTY, TERM, CI |
369
+ | Browser | CSS %c styling | ✅ Browser API |
370
+
371
+ ## Technical Specifications
372
+
373
+ | Requirement | Value |
374
+ |-------------|-------|
375
+ | Runtime | Universal (Node.js + Browser) |
376
+ | Module Format | ESM + CJS |
377
+ | Node.js | >= 18 |
378
+ | TypeScript | >= 5.0 |
379
+ | Bundle (core) | < 3KB gzipped |
380
+ | Bundle (all plugins) | < 12KB gzipped |
381
+ | Test Coverage | 100% target |
382
+
383
+ ## Dependencies
384
+
385
+ ```json
386
+ {
387
+ "dependencies": {
388
+ "@oxog/types": "^1.0.1",
389
+ "@oxog/plugin": "^1.0.0"
390
+ }
391
+ }
392
+ ```
393
+
394
+ **@oxog ecosystem only** - Only @oxog packages as dependencies, no external libraries.
395
+
396
+ ## License
397
+
398
+ MIT © Ersin Koç
399
+
400
+ ## Links
401
+
402
+ - [GitHub](https://github.com/ersinkoc/pigment)
403
+ - [Website](https://pigment.oxog.dev)
404
+ - [npm](https://www.npmjs.com/package/@oxog/pigment)
405
+
406
+ Made with ❤️ by Ersin KOÇ