@oxog/pigment 1.1.0 → 1.2.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @oxog/pigment
2
2
 
3
- Zero-dependency terminal styling with micro-kernel architecture and Chalk drop-in compatibility.
3
+ Terminal styling with a micro-kernel plugin architecture and a Chalk-style chainable API.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@oxog/pigment)](https://www.npmjs.com/package/@oxog/pigment)
6
6
  [![Build](https://img.shields.io/github/actions/workflow/publish.yml/ersinkoc/pigment)](https://github.com/ersinkoc/pigment)
@@ -10,15 +10,14 @@ Zero-dependency terminal styling with micro-kernel architecture and Chalk drop-i
10
10
 
11
11
  ## Features
12
12
 
13
- - **Zero Dependencies** - No external packages, implements everything from scratch
13
+ - **Zero runtime dependencies** - The `@oxog/plugin` kernel and `@oxog/types` are bundled into the build
14
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
15
+ - **Micro-Kernel Architecture** - Plugin system for extensibility
16
+ - **Chalk-style API** - Chainable default export (`chalk.red.bold('x')`) with a settable `level`; close to Chalk v5, not a full drop-in
17
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
18
+ - **Full Color Support** - 16 base colors, 256 colors, true color (RGB/HEX/HSL), downsampled to what the terminal supports
19
+ - **Environment Aware** - Respects NO_COLOR, FORCE_COLOR, TTY detection; plain text at color level 0
20
20
  - **TypeScript** - Strict mode with full type safety
21
- - **Tree Shakeable** - Optimize bundle size with individual imports
22
21
 
23
22
  ## Installation
24
23
 
@@ -42,7 +41,7 @@ pigment.underline.yellow('Warning');
42
41
  pigment.red(`Error: ${pigment.bold('critical')} issue`);
43
42
  ```
44
43
 
45
- ### Function Composition API (Tree-Shakeable)
44
+ ### Function Composition API
46
45
 
47
46
  ```typescript
48
47
  import { bold, red, compose } from '@oxog/pigment';
@@ -61,7 +60,8 @@ console.log(highlight('IMPORTANT'));
61
60
  ```typescript
62
61
  import { createPigment } from '@oxog/pigment';
63
62
 
64
- const styled = createPigment()
63
+ // `builder` returns a new builder on every access
64
+ const styled = createPigment().builder
65
65
  .bold()
66
66
  .red()
67
67
  .bgWhite()
@@ -70,18 +70,19 @@ const styled = createPigment()
70
70
  console.log(styled);
71
71
  ```
72
72
 
73
- ### Chalk Drop-in Compatibility
73
+ ### Chalk-Style Default Export
74
74
 
75
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
76
  import chalk from '@oxog/pigment';
77
+
82
78
  console.log(chalk.red.bold('Error'));
79
+ console.log(chalk.hex('#FF8800').underline('Orange'));
80
+ chalk.level = 0; // plain text from now on, like chalk
83
81
  ```
84
82
 
83
+ Close to Chalk v5 for everyday use, but not a full drop-in: there are no `Chalk`,
84
+ `chalkStderr` or `modifierNames` exports and no tagged templates.
85
+
85
86
  ## Colors
86
87
 
87
88
  ### 16 Base Colors
@@ -167,14 +168,15 @@ pigment.bgHsl(210, 100, 50)('Blue background');
167
168
  ## Environment Detection
168
169
 
169
170
  ```typescript
170
- import { pigment, supportsColor, resetColorSupportCache } from '@oxog/pigment';
171
+ import { createPigment, supportsColor, resetColorSupportCache } from '@oxog/pigment';
171
172
 
172
173
  // Check color support
173
- console.log(supportsColor);
174
+ console.log(supportsColor());
174
175
  // { level: 3, hasBasic: true, has256: true, has16m: true }
175
176
 
176
177
  // Override level
177
- const pigment = createPigment({ level: 3 });
178
+ const p = createPigment({ level: 2 });
179
+ p.hex('#FF8800')('Orange'); // downsampled to ANSI 256: \x1b[38;5;214m
178
180
 
179
181
  // Reset cached detection (useful for testing)
180
182
  resetColorSupportCache();
@@ -182,9 +184,24 @@ resetColorSupportCache();
182
184
 
183
185
  ### Environment Variables
184
186
 
185
- - `NO_COLOR` - Disables all colors
186
- - `FORCE_COLOR` - Forces color level (0, 1, 2, 3)
187
- - `TERM` - Terminal type detection
187
+ - `FORCE_COLOR` - Forces the color level (`''`/`true` = 1, `false` = 0, or `0`-`3`); wins over `NO_COLOR`
188
+ - `NO_COLOR` - Disables colors (non-empty value)
189
+ - `TERM` / `COLORTERM` - `dumb` disables colors; `*256color` = level 2; `truecolor`/`24bit` = level 3
190
+
191
+ Without a TTY (piped output) colors are off unless `CI` is set.
192
+
193
+ ### Color Levels
194
+
195
+ Output follows the level of the instance, like chalk:
196
+
197
+ | Level | Output |
198
+ |-------|--------|
199
+ | 0 | Plain text, no ANSI codes |
200
+ | 1 | 16 colors; rgb/hex/hsl/ansi256 become the closest basic color |
201
+ | 2 | 256 colors; rgb/hex/hsl become the closest ANSI 256 color |
202
+ | 3 | 24-bit true color |
203
+
204
+ Standalone stylers (`red`, `compose(...)`) use the detected level.
188
205
 
189
206
  ## Plugin System
190
207
 
@@ -212,6 +229,11 @@ environmentPlugin
212
229
 
213
230
  ### Optional Plugins (Opt-in)
214
231
 
232
+ Optional plugins add methods to an instance. Pass them to `createPigment({ plugins })` or
233
+ add them later with `pigment.use(plugin)` (returns the instance). Their output follows the
234
+ instance's color level. Calling a method whose plugin is not installed throws a
235
+ `PluginError` naming the plugin.
236
+
215
237
  #### Gradient Plugin
216
238
 
217
239
  ```typescript
@@ -220,12 +242,11 @@ import { gradientPlugin } from '@oxog/pigment/plugins';
220
242
 
221
243
  const pigment = createPigment({ plugins: [gradientPlugin({ steps: 10 })] });
222
244
 
223
- // Linear gradient
224
- pigment.gradient('red', 'blue')('Gradient text');
245
+ // Linear gradient: '#hex', 'rgb(r, g, b)' or [r, g, b]
225
246
  pigment.gradient('#FF0000', '#0000FF')('Hex gradient');
226
- pigment.gradient([255, 0, 0], [0, 0, 255])('RGB gradient');
247
+ pigment.gradient([255, 0, 0], 'rgb(0, 0, 255)')('RGB gradient');
227
248
 
228
- // Rainbow gradient
249
+ // Rainbow
229
250
  pigment.rainbow('Rainbow text');
230
251
  ```
231
252
 
@@ -236,13 +257,14 @@ import { themePlugin } from '@oxog/pigment/plugins';
236
257
 
237
258
  const pigment = createPigment({ plugins: [themePlugin({ preset: 'monokai' })] });
238
259
 
239
- // Theme colors
240
- pigment.theme.keyword('const'); // Orange
241
- pigment.theme.string('"hello"'); // Yellow
242
- pigment.theme.number('42'); // Purple
243
- pigment.theme.comment('// note'); // Gray
244
- pigment.theme.error('Error!'); // Red
245
- pigment.theme.success('Done!'); // Green
260
+ pigment.theme.keyword('const');
261
+ pigment.theme.string('"hello"');
262
+ pigment.theme.number('42');
263
+ pigment.theme.comment('// note');
264
+ pigment.theme.error('Error!');
265
+ pigment.theme.success('Done!');
266
+ pigment.theme.warning('Careful');
267
+ pigment.theme.info('Note');
246
268
  ```
247
269
 
248
270
  **Available Presets**: monokai, dracula, nord, github, vscode, tokyo-night, catppuccin, one-dark, solarized
@@ -254,20 +276,14 @@ import { semanticPlugin } from '@oxog/pigment/plugins';
254
276
 
255
277
  const pigment = createPigment({ plugins: [semanticPlugin()] });
256
278
 
257
- pigment.success('✓ Task completed'); // Green
258
- pigment.error('✗ Task failed'); // Red
259
- pigment.warning('⚠ Check this'); // Yellow
260
- pigment.info('ℹ Note'); // Blue
261
- pigment.debug('[DEBUG] value'); // Gray
262
-
263
- // Custom colors
264
- semanticPlugin({
265
- success: '#00FF00',
266
- error: '#FF0000',
267
- warning: '#FFAA00',
268
- info: '#00AAFF',
269
- debug: '#888888'
270
- })
279
+ pigment.success('✓ Task completed');
280
+ pigment.error('✗ Task failed');
281
+ pigment.warning('⚠ Check this');
282
+ pigment.info('ℹ Note');
283
+ pigment.debug('[DEBUG] value');
284
+
285
+ // Custom colors (hex)
286
+ semanticPlugin({ success: '#00FF00', error: '#FF0000', warning: '#FFAA00', info: '#00AAFF', debug: '#888888' });
271
287
  ```
272
288
 
273
289
  #### Box Plugin
@@ -277,19 +293,15 @@ import { boxPlugin } from '@oxog/pigment/plugins';
277
293
 
278
294
  const pigment = createPigment({ plugins: [boxPlugin()] });
279
295
 
280
- // Simple box
281
296
  pigment.box('Hello World');
282
297
  // ┌─────────────┐
283
298
  // │ Hello World │
284
299
  // └─────────────┘
285
300
 
286
- // Styled box
287
- pigment.box('Error!', { border: 'double', padding: 2 });
288
- // ╔═════════════╗
289
- // ║ ║
290
- // ║ Error! ║
291
- // ║ ║
292
- // ╚═════════════╝
301
+ pigment.box('Error!', { border: 'double', padding: 0, bgColor: '#300000' });
302
+ // ╔══════╗
303
+ // ║Error!║
304
+ // ╚══════╝
293
305
  ```
294
306
 
295
307
  **Border Styles**: single, double, rounded, bold, classic
@@ -301,20 +313,23 @@ import { templatePlugin } from '@oxog/pigment/plugins';
301
313
 
302
314
  const pigment = createPigment({ plugins: [templatePlugin()] });
303
315
 
304
- // Tagged template
305
- console.log(pigment`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
306
-
307
- // Nested styles
308
- console.log(pigment`{bold.red CRITICAL:} {dim system failure}`);
316
+ // {style text} blocks, style chains with dots; blocks nest
317
+ console.log(pigment.template`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
318
+ console.log(pigment.template`{bold.red CRITICAL:} {dim system {underline failure}}`);
309
319
  ```
310
320
 
321
+ Interpolated values are inserted as-is and never parsed as blocks.
322
+
311
323
  ### Ecosystem Plugin
312
324
 
313
325
  ```typescript
314
326
  import { pigmentPlugin } from '@oxog/pigment/plugins';
315
327
 
316
- // For @oxog/log, @oxog/cli
317
- log.use(pigmentPlugin({ theme: 'monokai', level: 3 }));
328
+ // On any @oxog/plugin kernel: adds kernel.pigment (a pigment instance)
329
+ import { createKernel } from '@oxog/pigment';
330
+
331
+ const kernel = createKernel();
332
+ kernel.use(pigmentPlugin({ theme: 'monokai', level: 3 }));
318
333
  ```
319
334
 
320
335
  ## API Reference
@@ -325,11 +340,15 @@ log.use(pigmentPlugin({ theme: 'monokai', level: 3 }));
325
340
  import { createPigment } from '@oxog/pigment';
326
341
 
327
342
  const pigment = createPigment({
328
- level: 3, // Force color level
329
- forceColor: false, // Force color output
330
- noColor: false, // Disable all colors
331
- plugins: [] // Custom plugins
343
+ level: 3, // Color level 0-3 (default: detected)
344
+ forceColor: false, // Use options.level, or 3, even without color support
345
+ noColor: false, // Level 0: plain text
346
+ plugins: [] // Plugins to install
332
347
  });
348
+
349
+ pigment.level; // 0-3
350
+ pigment.builder; // new BuilderPigment on every access
351
+ pigment.use(plugin); // install a plugin, returns the instance
333
352
  ```
334
353
 
335
354
  ### Type Definitions
@@ -369,7 +388,7 @@ interface Pigment {
369
388
  | Platform | Output | Auto-Detection |
370
389
  |----------|---------|---------------|
371
390
  | Node.js | ANSI escape codes | ✅ TTY, TERM, CI |
372
- | Browser | CSS %c styling | ✅ Browser API |
391
+ | Browser | ANSI escape codes (level 1 by default) | Fixed level 1 |
373
392
 
374
393
  ## Technical Specifications
375
394
 
@@ -379,22 +398,15 @@ interface Pigment {
379
398
  | Module Format | ESM + CJS |
380
399
  | Node.js | >= 18 |
381
400
  | TypeScript | >= 5.0 |
382
- | Bundle (core) | < 3KB gzipped |
383
- | Bundle (all plugins) | < 12KB gzipped |
384
- | Test Coverage | 100% target |
401
+ | `dist/index.js` | ~70 KB, ~15 KB gzipped (bundles `@oxog/plugin` and `@oxog/types`) |
402
+ | `dist/plugins/index.js` | ~62 KB, ~14 KB gzipped |
403
+ | Test Coverage | 100% (enforced) |
385
404
 
386
405
  ## Dependencies
387
406
 
388
- ```json
389
- {
390
- "dependencies": {
391
- "@oxog/types": "^1.0.1",
392
- "@oxog/plugin": "^1.0.0"
393
- }
394
- }
395
- ```
396
-
397
- **@oxog ecosystem only** - Only @oxog packages as dependencies, no external libraries.
407
+ None at runtime. The `@oxog/plugin` micro-kernel and the `@oxog/types` code and
408
+ types Pigment uses are bundled into `dist` (JavaScript and type declarations),
409
+ so installing `@oxog/pigment` installs nothing else.
398
410
 
399
411
  ## License
400
412