@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.
@@ -0,0 +1,427 @@
1
+ import { Plugin as Plugin$1, Kernel as Kernel$1 } from '@oxog/types';
2
+ import { KernelInstance } from '@oxog/plugin';
3
+
4
+ type PigmentOptions = {
5
+ level?: 0 | 1 | 2 | 3;
6
+ forceColor?: boolean;
7
+ noColor?: boolean;
8
+ plugins?: Plugin<PigmentContext>[];
9
+ };
10
+ type ColorSupport = {
11
+ level: 0 | 1 | 2 | 3;
12
+ hasBasic: boolean;
13
+ has256: boolean;
14
+ has16m: boolean;
15
+ };
16
+ type Styler = (text: string) => string;
17
+ type Style = {
18
+ name: string;
19
+ code: number;
20
+ open: string;
21
+ close: string;
22
+ type: 'modifier' | 'color';
23
+ background?: boolean;
24
+ };
25
+ type Pigment = {
26
+ bold: Pigment;
27
+ dim: Pigment;
28
+ italic: Pigment;
29
+ underline: Pigment;
30
+ strikethrough: Pigment;
31
+ inverse: Pigment;
32
+ hidden: Pigment;
33
+ reset: Pigment;
34
+ black: Pigment;
35
+ red: Pigment;
36
+ green: Pigment;
37
+ yellow: Pigment;
38
+ blue: Pigment;
39
+ magenta: Pigment;
40
+ cyan: Pigment;
41
+ white: Pigment;
42
+ blackBright: Pigment;
43
+ redBright: Pigment;
44
+ greenBright: Pigment;
45
+ yellowBright: Pigment;
46
+ blueBright: Pigment;
47
+ magentaBright: Pigment;
48
+ cyanBright: Pigment;
49
+ whiteBright: Pigment;
50
+ gray: Pigment;
51
+ grey: Pigment;
52
+ bgBlack: Pigment;
53
+ bgRed: Pigment;
54
+ bgGreen: Pigment;
55
+ bgYellow: Pigment;
56
+ bgBlue: Pigment;
57
+ bgMagenta: Pigment;
58
+ bgCyan: Pigment;
59
+ bgWhite: Pigment;
60
+ bgBlackBright: Pigment;
61
+ bgRedBright: Pigment;
62
+ bgGreenBright: Pigment;
63
+ bgYellowBright: Pigment;
64
+ bgBlueBright: Pigment;
65
+ bgMagentaBright: Pigment;
66
+ bgCyanBright: Pigment;
67
+ bgWhiteBright: Pigment;
68
+ bgGray: Pigment;
69
+ bgGrey: Pigment;
70
+ ansi256(code: number): Pigment;
71
+ bgAnsi256(code: number): Pigment;
72
+ rgb(r: number, g: number, b: number): Pigment;
73
+ bgRgb(r: number, g: number, b: number): Pigment;
74
+ hex(color: string): Pigment;
75
+ bgHex(color: string): Pigment;
76
+ hsl(h: number, s: number, l: number): Pigment;
77
+ bgHsl(h: number, s: number, l: number): Pigment;
78
+ (text: string): string;
79
+ };
80
+ /**
81
+ * Plugin interface - re-exported from @oxog/types.
82
+ * Use this for creating Pigment-compatible plugins.
83
+ */
84
+ type Plugin<TContext = unknown> = Plugin$1<TContext>;
85
+ /**
86
+ * Kernel interface - re-exported from @oxog/types.
87
+ */
88
+ type Kernel<TContext = unknown> = Kernel$1<TContext>;
89
+ /**
90
+ * Pigment kernel type - extended KernelInstance from @oxog/plugin.
91
+ */
92
+ type PigmentKernel<TContext = PigmentContext> = KernelInstance<TContext, PigmentEvents>;
93
+ /**
94
+ * Pigment context shared between plugins.
95
+ */
96
+ interface PigmentContext {
97
+ /** Current color level */
98
+ level: 0 | 1 | 2 | 3;
99
+ /** Whether colors are enabled */
100
+ enabled: boolean;
101
+ /** Color support information */
102
+ colorSupport: ColorSupport;
103
+ /** Registered styles map */
104
+ styles?: Map<string, StyleFunction>;
105
+ /** Colors map */
106
+ colors?: {
107
+ foreground: Record<string, number>;
108
+ background: Record<string, number>;
109
+ all: Record<string, number>;
110
+ };
111
+ /** Utility functions */
112
+ utils?: {
113
+ hexToRgb: (hex: string) => {
114
+ r: number;
115
+ g: number;
116
+ b: number;
117
+ };
118
+ hslToRgb: (h: number, s: number, l: number) => {
119
+ r: number;
120
+ g: number;
121
+ b: number;
122
+ };
123
+ rgbToAnsi256: (r: number, g: number, b: number) => number;
124
+ detectColorSupport: (level?: 0 | 1 | 2 | 3) => ColorSupport;
125
+ supportsColor: (level?: 0 | 1 | 2 | 3) => ColorSupport;
126
+ };
127
+ }
128
+ /**
129
+ * Pigment event map for type-safe events.
130
+ */
131
+ interface PigmentEvents {
132
+ 'plugin:register': {
133
+ plugin: Plugin<PigmentContext>;
134
+ };
135
+ 'plugin:unregister': {
136
+ plugin: Plugin<PigmentContext>;
137
+ };
138
+ 'plugin:init': {
139
+ plugin: Plugin<PigmentContext>;
140
+ };
141
+ 'plugin:destroy': {
142
+ plugin: Plugin<PigmentContext>;
143
+ };
144
+ 'context:change': PigmentContext;
145
+ 'style:apply': {
146
+ name: string;
147
+ text: string;
148
+ };
149
+ 'error': Error;
150
+ [key: string]: unknown;
151
+ }
152
+ /**
153
+ * Style function type.
154
+ */
155
+ type StyleFunction = {
156
+ (text: string): string;
157
+ open: string;
158
+ close: string;
159
+ };
160
+ type ThemePreset = 'monokai' | 'dracula' | 'nord' | 'github' | 'vscode' | 'tokyo-night' | 'catppuccin' | 'one-dark' | 'solarized';
161
+ type BoxBorder = 'single' | 'double' | 'rounded' | 'bold' | 'classic';
162
+ type GradientPluginOptions = {
163
+ steps?: number;
164
+ };
165
+ type ThemePluginOptions = {
166
+ preset?: ThemePreset;
167
+ custom?: Record<string, string>;
168
+ };
169
+ type BoxPluginOptions = {
170
+ border?: BoxBorder;
171
+ padding?: number;
172
+ };
173
+ type PigmentPluginOptions = {
174
+ theme?: ThemePreset;
175
+ level?: 0 | 1 | 2 | 3;
176
+ };
177
+ type Platform = {
178
+ isNode: boolean;
179
+ isBrowser: boolean;
180
+ isWindows: boolean;
181
+ isCI: boolean;
182
+ hasTTY: boolean;
183
+ };
184
+ type ThemePresetColors = {
185
+ keyword: string;
186
+ string: string;
187
+ number: string;
188
+ comment: string;
189
+ error: string;
190
+ success: string;
191
+ warning: string;
192
+ info: string;
193
+ };
194
+ type SemanticPluginOptions = {
195
+ success?: string;
196
+ error?: string;
197
+ warning?: string;
198
+ info?: string;
199
+ debug?: string;
200
+ };
201
+ type BoxChars = {
202
+ tl: string;
203
+ tr: string;
204
+ bl: string;
205
+ br: string;
206
+ h: string;
207
+ v: string;
208
+ };
209
+ type KernelOptions<TContext> = {
210
+ context?: TContext;
211
+ };
212
+ /**
213
+ * Event handler type.
214
+ */
215
+ type EventHandler = (data?: unknown) => void;
216
+
217
+ /**
218
+ * Core plugin that provides 16 base ANSI colors + bright variants.
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const pigment = createPigment();
223
+ * pigment.red('Error!');
224
+ * pigment.greenBright('Success!');
225
+ * ```
226
+ */
227
+ declare function baseColorsPlugin(): Plugin<PigmentContext>;
228
+
229
+ /**
230
+ * Core plugin that provides text modifiers (bold, dim, italic, etc.).
231
+ *
232
+ * @example
233
+ * ```typescript
234
+ * const pigment = createPigment();
235
+ * pigment.bold('Bold text');
236
+ * pigment.italic.underline('Styled text');
237
+ * ```
238
+ */
239
+ declare function modifiersPlugin(): Plugin<PigmentContext>;
240
+
241
+ /**
242
+ * Core plugin that provides 256-color palette support.
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * const pigment = createPigment();
247
+ * pigment.ansi256(196)('Bright red');
248
+ * pigment.bgAnsi256(21)('Blue background');
249
+ * ```
250
+ */
251
+ declare function ansi256Plugin(): Plugin<PigmentContext>;
252
+
253
+ /**
254
+ * Core plugin that provides RGB, HEX, and HSL color support.
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * const pigment = createPigment();
259
+ * pigment.rgb(255, 136, 0)('Orange text');
260
+ * pigment.hex('#FF8800')('Orange text');
261
+ * pigment.hsl(30, 100, 50)('Orange text');
262
+ * ```
263
+ */
264
+ declare function trueColorPlugin(): Plugin<PigmentContext>;
265
+
266
+ /**
267
+ * Core plugin that provides nested/composed style support.
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * const pigment = createPigment();
272
+ * pigment.red(`Error: ${pigment.bold('critical')} issue`);
273
+ * ```
274
+ */
275
+ declare function nestingPlugin(): Plugin<PigmentContext>;
276
+
277
+ /**
278
+ * Core plugin that handles environment detection (NO_COLOR, FORCE_COLOR, TTY).
279
+ *
280
+ * Respects environment variables:
281
+ * - NO_COLOR - disables all colors
282
+ * - FORCE_COLOR - forces color level (0, 1, 2, 3)
283
+ * - TERM - terminal type detection
284
+ * - CI - CI environment detection
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * const pigment = createPigment();
289
+ * // Automatically detects environment
290
+ * ```
291
+ */
292
+ declare function environmentPlugin(): Plugin<PigmentContext>;
293
+
294
+ /**
295
+ * Optional plugin that provides smooth color gradients between two colors.
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * import { createPigment } from '@oxog/pigment';
300
+ * import { gradientPlugin } from '@oxog/pigment/plugins';
301
+ *
302
+ * const pigment = createPigment({
303
+ * plugins: [gradientPlugin()]
304
+ * });
305
+ *
306
+ * pigment.gradient('red', 'blue')('Gradient text');
307
+ * pigment.rainbow('Rainbow text');
308
+ * ```
309
+ */
310
+ declare function gradientPlugin(options?: GradientPluginOptions): Plugin<PigmentContext>;
311
+
312
+ /**
313
+ * Optional plugin that provides predefined color themes.
314
+ *
315
+ * @example
316
+ * ```typescript
317
+ * import { createPigment } from '@oxog/pigment';
318
+ * import { themePlugin } from '@oxog/pigment/plugins';
319
+ *
320
+ * const pigment = createPigment({
321
+ * plugins: [themePlugin({ preset: 'monokai' })]
322
+ * });
323
+ *
324
+ * pigment.theme.keyword('const');
325
+ * pigment.theme.string('"hello"');
326
+ * pigment.theme.error('Error!');
327
+ * ```
328
+ *
329
+ * Available presets: monokai, dracula, nord, github, vscode, tokyo-night, catppuccin, one-dark, solarized
330
+ */
331
+ declare function themePlugin(options?: ThemePluginOptions): Plugin<PigmentContext>;
332
+
333
+ /**
334
+ * Optional plugin that provides semantic colors (success, error, warning, info, debug).
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * import { createPigment } from '@oxog/pigment';
339
+ * import { semanticPlugin } from '@oxog/pigment/plugins';
340
+ *
341
+ * const pigment = createPigment({
342
+ * plugins: [semanticPlugin()]
343
+ * });
344
+ *
345
+ * pigment.success('✓ Task completed');
346
+ * pigment.error('✗ Task failed');
347
+ * pigment.warning('⚠ Check this');
348
+ * pigment.info('ℹ Note');
349
+ * pigment.debug('[DEBUG] value');
350
+ * ```
351
+ */
352
+ declare function semanticPlugin(options?: SemanticPluginOptions): Plugin<PigmentContext>;
353
+
354
+ /**
355
+ * Optional plugin that provides box drawing with borders.
356
+ *
357
+ * @example
358
+ * ```typescript
359
+ * import { createPigment } from '@oxog/pigment';
360
+ * import { boxPlugin } from '@oxog/pigment/plugins';
361
+ *
362
+ * const pigment = createPigment({
363
+ * plugins: [boxPlugin()]
364
+ * });
365
+ *
366
+ * pigment.box('Hello World');
367
+ * // ┌─────────────┐
368
+ * // │ Hello World │
369
+ * // └─────────────┘
370
+ *
371
+ * pigment.box('Error!', { border: 'double', borderColor: 'red' });
372
+ * ```
373
+ */
374
+ declare function boxPlugin(options?: BoxPluginOptions): Plugin<PigmentContext>;
375
+
376
+ /**
377
+ * Optional plugin that provides tagged template literal syntax.
378
+ *
379
+ * @example
380
+ * ```typescript
381
+ * import { createPigment } from '@oxog/pigment';
382
+ * import { templatePlugin } from '@oxog/pigment/plugins';
383
+ *
384
+ * const pigment = createPigment({
385
+ * plugins: [templatePlugin()]
386
+ * });
387
+ *
388
+ * console.log(pigment`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
389
+ * ```
390
+ */
391
+ declare function templatePlugin(): Plugin<PigmentContext>;
392
+
393
+ /**
394
+ * Plugin that adds Pigment color support to any @oxog kernel.
395
+ * Use this in @oxog/log, @oxog/cli, etc.
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * // In @oxog/log or @oxog/cli
400
+ * import { pigmentPlugin } from '@oxog/pigment/plugins';
401
+ *
402
+ * const log = createLogger();
403
+ * log.use(pigmentPlugin()); // Adds color support to logger
404
+ *
405
+ * // Now log has access to colors
406
+ * log.pigment.red('Error message');
407
+ * ```
408
+ */
409
+ declare function pigmentPlugin<TContext = unknown>(options?: PigmentPluginOptions): Plugin<TContext>;
410
+
411
+ declare const index_ansi256Plugin: typeof ansi256Plugin;
412
+ declare const index_baseColorsPlugin: typeof baseColorsPlugin;
413
+ declare const index_boxPlugin: typeof boxPlugin;
414
+ declare const index_environmentPlugin: typeof environmentPlugin;
415
+ declare const index_gradientPlugin: typeof gradientPlugin;
416
+ declare const index_modifiersPlugin: typeof modifiersPlugin;
417
+ declare const index_nestingPlugin: typeof nestingPlugin;
418
+ declare const index_pigmentPlugin: typeof pigmentPlugin;
419
+ declare const index_semanticPlugin: typeof semanticPlugin;
420
+ declare const index_templatePlugin: typeof templatePlugin;
421
+ declare const index_themePlugin: typeof themePlugin;
422
+ declare const index_trueColorPlugin: typeof trueColorPlugin;
423
+ declare namespace index {
424
+ export { index_ansi256Plugin as ansi256Plugin, index_baseColorsPlugin as baseColorsPlugin, index_boxPlugin as boxPlugin, index_environmentPlugin as environmentPlugin, index_gradientPlugin as gradientPlugin, index_modifiersPlugin as modifiersPlugin, index_nestingPlugin as nestingPlugin, index_pigmentPlugin as pigmentPlugin, index_semanticPlugin as semanticPlugin, index_templatePlugin as templatePlugin, index_themePlugin as themePlugin, index_trueColorPlugin as trueColorPlugin };
425
+ }
426
+
427
+ export { templatePlugin as A, type BoxBorder as B, type ColorSupport as C, pigmentPlugin as D, type EventHandler as E, type GradientPluginOptions as G, type Kernel as K, type PigmentKernel as P, type Styler as S, type ThemePreset as T, type PigmentOptions as a, type Pigment as b, type Platform as c, type Plugin as d, type PigmentContext as e, type PigmentEvents as f, type Style as g, type StyleFunction as h, index as i, type ThemePluginOptions as j, type BoxPluginOptions as k, type PigmentPluginOptions as l, type SemanticPluginOptions as m, type ThemePresetColors as n, type BoxChars as o, type KernelOptions as p, baseColorsPlugin as q, modifiersPlugin as r, ansi256Plugin as s, trueColorPlugin as t, nestingPlugin as u, environmentPlugin as v, gradientPlugin as w, themePlugin as x, semanticPlugin as y, boxPlugin as z };