@oxog/pigment 1.1.1 → 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 +5 -12
- package/dist/index-DsggPsSl.d.cts +1482 -0
- package/dist/index-DsggPsSl.d.ts +1482 -0
- package/dist/index.cjs +64 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +64 -43
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +62 -41
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +1 -3
- package/dist/plugins/index.d.ts +1 -3
- package/dist/plugins/index.js +62 -41
- package/dist/plugins/index.js.map +1 -1
- package/package.json +21 -11
- package/dist/index-C_LwyWae.d.cts +0 -564
- package/dist/index-C_LwyWae.d.ts +0 -564
|
@@ -0,0 +1,1482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in types that should not be recursed into.
|
|
3
|
+
*/
|
|
4
|
+
type Builtin = Function | Date | Error | RegExp | Generator | {
|
|
5
|
+
readonly [Symbol.toStringTag]: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Deep partial - all nested properties optional.
|
|
9
|
+
*
|
|
10
|
+
* Recursively makes all properties and nested properties optional.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* interface User {
|
|
15
|
+
* name: string;
|
|
16
|
+
* address: {
|
|
17
|
+
* street: string;
|
|
18
|
+
* city: string;
|
|
19
|
+
* };
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* const partial: DeepPartial<User> = {
|
|
23
|
+
* name: 'John',
|
|
24
|
+
* address: {
|
|
25
|
+
* street: 'Main St'
|
|
26
|
+
* // city is optional
|
|
27
|
+
* }
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
type DeepPartial<T> = T extends Builtin ? T : T extends object ? {
|
|
32
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
33
|
+
} : T;
|
|
34
|
+
/**
|
|
35
|
+
* Value that may be a promise.
|
|
36
|
+
*
|
|
37
|
+
* Represents a value that can be either synchronous or asynchronous.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* function process(data: string): MaybePromise<string> {
|
|
42
|
+
* if (useCache) {
|
|
43
|
+
* return cachedData; // Synchronous
|
|
44
|
+
* }
|
|
45
|
+
* return fetchData(); // Promise
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Unsubscribe function returned by event subscriptions.
|
|
52
|
+
*
|
|
53
|
+
* Call this function to unsubscribe from an event.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const unsubscribe = eventEmitter.on('event', handler);
|
|
58
|
+
* // Later, when done listening:
|
|
59
|
+
* unsubscribe();
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
type Unsubscribe = () => void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @oxog/types - Plugin and Kernel interfaces
|
|
66
|
+
* @author Ersin Koç
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Standard plugin interface for @oxog ecosystem.
|
|
71
|
+
*
|
|
72
|
+
* A plugin is a self-contained module that can be registered with a Kernel.
|
|
73
|
+
* Plugins can depend on other plugins and communicate through the Kernel's
|
|
74
|
+
* event system.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const myPlugin: Plugin = {
|
|
79
|
+
* name: 'my-plugin',
|
|
80
|
+
* version: '1.0.0',
|
|
81
|
+
* dependencies: ['logger'],
|
|
82
|
+
* install(kernel) {
|
|
83
|
+
* kernel.on('init', () => console.log('Plugin installed'));
|
|
84
|
+
* },
|
|
85
|
+
* onInit(context) {
|
|
86
|
+
* // Called after all plugins installed
|
|
87
|
+
* },
|
|
88
|
+
* onDestroy() {
|
|
89
|
+
* // Cleanup resources
|
|
90
|
+
* },
|
|
91
|
+
* onError(error) {
|
|
92
|
+
* console.error('Plugin error:', error);
|
|
93
|
+
* }
|
|
94
|
+
* };
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
interface Plugin$2<TContext = unknown> {
|
|
98
|
+
/** Unique plugin identifier (kebab-case) */
|
|
99
|
+
readonly name: string;
|
|
100
|
+
/** Semantic version (e.g., "1.0.0") */
|
|
101
|
+
readonly version: string;
|
|
102
|
+
/** Plugin dependencies by name */
|
|
103
|
+
readonly dependencies?: readonly string[];
|
|
104
|
+
/** Called when plugin is registered with the kernel */
|
|
105
|
+
install(kernel: Kernel$1<TContext>): void;
|
|
106
|
+
/** Called after ALL plugins are installed */
|
|
107
|
+
onInit?(context: TContext): MaybePromise<void>;
|
|
108
|
+
/** Called when plugin is unregistered */
|
|
109
|
+
onDestroy?(): MaybePromise<void>;
|
|
110
|
+
/** Called when an error occurs in this plugin */
|
|
111
|
+
onError?(error: Error): void;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Micro-kernel interface for @oxog packages.
|
|
115
|
+
*
|
|
116
|
+
* The Kernel manages plugins and provides event communication between them.
|
|
117
|
+
* It maintains a plugin registry and exposes methods for plugin lifecycle
|
|
118
|
+
* management.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // Register a plugin
|
|
123
|
+
* kernel.use(myPlugin);
|
|
124
|
+
*
|
|
125
|
+
* // Get a plugin
|
|
126
|
+
* const plugin = kernel.getPlugin('logger');
|
|
127
|
+
*
|
|
128
|
+
* // Check if plugin exists
|
|
129
|
+
* if (kernel.hasPlugin('logger')) {
|
|
130
|
+
* // Plugin is registered
|
|
131
|
+
* }
|
|
132
|
+
*
|
|
133
|
+
* // Emit event
|
|
134
|
+
* kernel.emit('user:login', { userId: '123' });
|
|
135
|
+
*
|
|
136
|
+
* // Subscribe to events
|
|
137
|
+
* const unsubscribe = kernel.on('user:login', (payload) => {
|
|
138
|
+
* console.log('User logged in:', payload);
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
interface Kernel$1<TContext = unknown> {
|
|
143
|
+
/** Register a plugin */
|
|
144
|
+
use(plugin: Plugin$2<TContext>): this;
|
|
145
|
+
/** Unregister a plugin by name */
|
|
146
|
+
unregister(name: string): boolean;
|
|
147
|
+
/** Get registered plugin by name */
|
|
148
|
+
getPlugin<T extends Plugin$2<TContext> = Plugin$2<TContext>>(name: string): T | undefined;
|
|
149
|
+
/** List all registered plugins */
|
|
150
|
+
listPlugins(): ReadonlyArray<Plugin$2<TContext>>;
|
|
151
|
+
/** Check if plugin is registered */
|
|
152
|
+
hasPlugin(name: string): boolean;
|
|
153
|
+
/** Emit event to all plugins */
|
|
154
|
+
emit<K extends string>(event: K, payload?: unknown): void;
|
|
155
|
+
/** Subscribe to kernel events */
|
|
156
|
+
on<K extends string>(event: K, handler: (payload: unknown) => void): Unsubscribe;
|
|
157
|
+
/** Get shared context */
|
|
158
|
+
getContext(): TContext;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @oxog/types - Event system types
|
|
163
|
+
* @author Ersin Koç
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Base event map interface.
|
|
168
|
+
*
|
|
169
|
+
* Defines the structure for event payloads. `EventHandler` and
|
|
170
|
+
* `TypedEventEmitter` accept any object type, so a plain interface works
|
|
171
|
+
* without extending this one; extend it only when you want arbitrary
|
|
172
|
+
* string events to be allowed.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* interface MyEvents extends EventMap {
|
|
177
|
+
* 'user:login': { userId: string; timestamp: number };
|
|
178
|
+
* 'user:logout': { userId: string };
|
|
179
|
+
* 'error': Error;
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
interface EventMap {
|
|
184
|
+
[event: string]: unknown;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Error handling strategy for plugin lifecycle.
|
|
189
|
+
*
|
|
190
|
+
* - `'isolate'`: Plugin errors don't affect other plugins (default)
|
|
191
|
+
* - `'fail-fast'`: First error stops the entire kernel
|
|
192
|
+
* - `'collect'`: Collect all errors and throw AggregateError at the end
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const kernel = createKernel({ errorStrategy: 'isolate' });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
type ErrorStrategy = 'isolate' | 'fail-fast' | 'collect';
|
|
200
|
+
/**
|
|
201
|
+
* Kernel configuration options.
|
|
202
|
+
*
|
|
203
|
+
* @template TContext - The type of shared context between plugins
|
|
204
|
+
* @template TEvents - The event map for typed events
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const kernel = createKernel<AppContext, AppEvents>({
|
|
209
|
+
* context: { env: 'production' },
|
|
210
|
+
* errorStrategy: 'fail-fast',
|
|
211
|
+
* onError: (error, name) => console.error(`[${name}]`, error)
|
|
212
|
+
* });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
interface KernelConfig<TContext, TEvents extends object> {
|
|
216
|
+
/** Initial shared context value */
|
|
217
|
+
context?: TContext;
|
|
218
|
+
/** Error handling strategy */
|
|
219
|
+
errorStrategy?: ErrorStrategy;
|
|
220
|
+
/** Global error handler called when any plugin errors */
|
|
221
|
+
onError?: (error: Error, pluginName: string) => void;
|
|
222
|
+
/** Hook called before kernel initialization starts */
|
|
223
|
+
onBeforeInit?: () => MaybePromise<void>;
|
|
224
|
+
/** Hook called after kernel initialization completes */
|
|
225
|
+
onAfterInit?: () => MaybePromise<void>;
|
|
226
|
+
/** Hook called before kernel destruction starts */
|
|
227
|
+
onBeforeDestroy?: () => MaybePromise<void>;
|
|
228
|
+
/** Hook called after kernel destruction completes */
|
|
229
|
+
onAfterDestroy?: () => MaybePromise<void>;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The kernel object as seen from a plugin's `install()` hook.
|
|
233
|
+
*
|
|
234
|
+
* `KernelInstance` declares an index signature so plugins can attach their own
|
|
235
|
+
* API to the kernel during `install()` - the documented extension pattern. The
|
|
236
|
+
* upstream `Kernel` interface has no such signature, so widening it here is
|
|
237
|
+
* what makes `install(kernel) { kernel.log = ... }` typecheck while keeping
|
|
238
|
+
* every upstream method available.
|
|
239
|
+
*/
|
|
240
|
+
type InstallableKernel<TContext = unknown> = Kernel$1<TContext> & Record<string, any>;
|
|
241
|
+
/**
|
|
242
|
+
* A plugin, with an `install()` hook that receives the indexable kernel.
|
|
243
|
+
*
|
|
244
|
+
* Structurally identical to the upstream `Plugin` except for the widened
|
|
245
|
+
* `install` parameter, which is contravariant-safe in both directions: an
|
|
246
|
+
* upstream `Plugin` is still assignable here, and a plugin declared with this
|
|
247
|
+
* type is still assignable to the upstream `Plugin`.
|
|
248
|
+
*
|
|
249
|
+
* @template TContext - The shared context type
|
|
250
|
+
*/
|
|
251
|
+
interface Plugin$1<TContext = unknown> extends Omit<Plugin$2<TContext>, 'install'> {
|
|
252
|
+
/**
|
|
253
|
+
* Called when plugin is registered with the kernel.
|
|
254
|
+
*
|
|
255
|
+
* Declared with method syntax so a context-agnostic `Plugin` can be used
|
|
256
|
+
* with a kernel that has a specific context type.
|
|
257
|
+
*/
|
|
258
|
+
install(kernel: InstallableKernel<TContext>): void;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Internal kernel events emitted during lifecycle.
|
|
262
|
+
*
|
|
263
|
+
* These events are always available regardless of user-defined events.
|
|
264
|
+
*
|
|
265
|
+
* @internal
|
|
266
|
+
*/
|
|
267
|
+
interface InternalKernelEvents extends EventMap {
|
|
268
|
+
'plugin:install': {
|
|
269
|
+
name: string;
|
|
270
|
+
version: string;
|
|
271
|
+
};
|
|
272
|
+
'plugin:init': {
|
|
273
|
+
name: string;
|
|
274
|
+
};
|
|
275
|
+
'plugin:destroy': {
|
|
276
|
+
name: string;
|
|
277
|
+
};
|
|
278
|
+
'plugin:error': {
|
|
279
|
+
name: string;
|
|
280
|
+
error: Error;
|
|
281
|
+
};
|
|
282
|
+
'kernel:init': {
|
|
283
|
+
timestamp: number;
|
|
284
|
+
};
|
|
285
|
+
'kernel:ready': {
|
|
286
|
+
timestamp: number;
|
|
287
|
+
plugins: string[];
|
|
288
|
+
};
|
|
289
|
+
'kernel:destroy': {
|
|
290
|
+
timestamp: number;
|
|
291
|
+
};
|
|
292
|
+
'kernel:destroyed': {
|
|
293
|
+
timestamp: number;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Kernel Instance - Main micro-kernel implementation.
|
|
299
|
+
*
|
|
300
|
+
* Provides plugin registration, lifecycle management, event bus,
|
|
301
|
+
* and plugin queries. This is the core of the @oxog/plugin system.
|
|
302
|
+
*
|
|
303
|
+
* @module kernel
|
|
304
|
+
*/
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Micro-kernel instance for plugin management.
|
|
308
|
+
*
|
|
309
|
+
* The kernel is the central component that manages plugins throughout
|
|
310
|
+
* their lifecycle: registration → initialization → operation → destruction.
|
|
311
|
+
*
|
|
312
|
+
* Features:
|
|
313
|
+
* - Fluent chainable API
|
|
314
|
+
* - Automatic dependency resolution
|
|
315
|
+
* - Type-safe event bus
|
|
316
|
+
* - Configurable error handling
|
|
317
|
+
* - Shared context management
|
|
318
|
+
* - Dynamic plugin management
|
|
319
|
+
*
|
|
320
|
+
* @template TContext - Type of shared context between plugins
|
|
321
|
+
* @template TEvents - Event map for typed events
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* const kernel = createKernel();
|
|
326
|
+
* kernel.use(loggerPlugin).use(dbPlugin);
|
|
327
|
+
* await kernel.init();
|
|
328
|
+
* // ... use kernel ...
|
|
329
|
+
* await kernel.destroy();
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
/**
|
|
333
|
+
* Combined event type that includes both user events and internal kernel events.
|
|
334
|
+
*
|
|
335
|
+
* NOTE: this must be a plain intersection, NOT `Omit<TEvents, keyof
|
|
336
|
+
* InternalKernelEvents> & InternalKernelEvents`. `EventMap` declares a string
|
|
337
|
+
* index signature (`[event: string]: unknown`), so `keyof TEvents` collapses to
|
|
338
|
+
* `string` and `Omit` erases every user-declared event type - making every
|
|
339
|
+
* event payload `unknown`. Intersecting preserves the declared properties.
|
|
340
|
+
*
|
|
341
|
+
* A user event that collides with an internal name is therefore typed as the
|
|
342
|
+
* intersection of both payloads rather than being silently replaced by the
|
|
343
|
+
* internal one. For a custom payload on an internal event name, subscribe with
|
|
344
|
+
* `onWildcard()` or `onPattern()`.
|
|
345
|
+
*
|
|
346
|
+
* @internal
|
|
347
|
+
*/
|
|
348
|
+
type CombinedEvents<TEvents extends object> = TEvents & InternalKernelEvents;
|
|
349
|
+
declare class KernelInstance<TContext, TEvents extends object> {
|
|
350
|
+
private state;
|
|
351
|
+
private plugins;
|
|
352
|
+
private context;
|
|
353
|
+
private events;
|
|
354
|
+
private resolver;
|
|
355
|
+
private errorBoundary;
|
|
356
|
+
private lifecycle;
|
|
357
|
+
private config;
|
|
358
|
+
/**
|
|
359
|
+
* Map of pending plugin initialization promises.
|
|
360
|
+
* Used to track and await late plugin initializations.
|
|
361
|
+
* @internal
|
|
362
|
+
*/
|
|
363
|
+
private pendingInits;
|
|
364
|
+
/**
|
|
365
|
+
* Emit an internal kernel event.
|
|
366
|
+
*
|
|
367
|
+
* Internal events are always valid since CombinedEvents includes
|
|
368
|
+
* InternalKernelEvents with correct types. The cast is safe because
|
|
369
|
+
* Omit<TEvents, keyof InternalKernelEvents> & InternalKernelEvents
|
|
370
|
+
* guarantees internal event keys have InternalKernelEvents types.
|
|
371
|
+
*
|
|
372
|
+
* @internal
|
|
373
|
+
*/
|
|
374
|
+
private emitInternal;
|
|
375
|
+
/**
|
|
376
|
+
* Extended kernel namespace for plugins.
|
|
377
|
+
*
|
|
378
|
+
* Plugins can add properties to this object during their
|
|
379
|
+
* `install()` hook to expose functionality to other plugins.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* const plugin: Plugin = {
|
|
384
|
+
* name: 'logger',
|
|
385
|
+
* install(kernel) {
|
|
386
|
+
* kernel.log = (...args) => console.log(...args);
|
|
387
|
+
* }
|
|
388
|
+
* };
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
[key: string]: any;
|
|
392
|
+
/**
|
|
393
|
+
* Create a new kernel instance.
|
|
394
|
+
*
|
|
395
|
+
* @param config - Optional kernel configuration
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* const kernel = new KernelInstance({
|
|
400
|
+
* context: { env: 'production' },
|
|
401
|
+
* errorStrategy: 'isolate',
|
|
402
|
+
* onError: (err, name) => console.error(`[${name}]`, err)
|
|
403
|
+
* });
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
constructor(config?: KernelConfig<TContext, TEvents>);
|
|
407
|
+
/**
|
|
408
|
+
* Register a plugin with the kernel.
|
|
409
|
+
*
|
|
410
|
+
* The plugin's `install()` hook is called immediately and
|
|
411
|
+
* synchronously. The plugin will be initialized when `init()` is
|
|
412
|
+
* called, in dependency order.
|
|
413
|
+
*
|
|
414
|
+
* @param plugin - The plugin to register
|
|
415
|
+
* @returns This kernel instance for chaining
|
|
416
|
+
* @throws {PluginError} If kernel is destroyed or plugin name is duplicate
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```typescript
|
|
420
|
+
* kernel
|
|
421
|
+
* .use(loggerPlugin)
|
|
422
|
+
* .use(databasePlugin)
|
|
423
|
+
* .use(apiPlugin);
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
use(plugin: Plugin$1<TContext>): this;
|
|
427
|
+
/**
|
|
428
|
+
* Wait for a specific plugin's initialization to complete.
|
|
429
|
+
*
|
|
430
|
+
* This is useful when adding plugins after kernel initialization.
|
|
431
|
+
*
|
|
432
|
+
* @param name - Plugin name to wait for
|
|
433
|
+
* @returns Promise that resolves when plugin is initialized
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* kernel.use(latePlugin);
|
|
438
|
+
* await kernel.waitForPlugin('late-plugin');
|
|
439
|
+
* // Now safe to use late-plugin
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
waitForPlugin(name: string): Promise<void>;
|
|
443
|
+
/**
|
|
444
|
+
* Wait for all pending plugin initializations to complete.
|
|
445
|
+
*
|
|
446
|
+
* @returns Promise that resolves when all pending plugins are initialized
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* kernel.use(plugin1).use(plugin2);
|
|
451
|
+
* await kernel.waitForAll();
|
|
452
|
+
* // All plugins are now initialized
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
waitForAll(): Promise<void>;
|
|
456
|
+
/**
|
|
457
|
+
* Initialize a plugin after ensuring all its dependencies are ready.
|
|
458
|
+
*
|
|
459
|
+
* Waits for pending dependency initializations and validates that
|
|
460
|
+
* all dependencies are in Ready state before proceeding.
|
|
461
|
+
*
|
|
462
|
+
* @internal
|
|
463
|
+
*/
|
|
464
|
+
private initializeWithDependencies;
|
|
465
|
+
/**
|
|
466
|
+
* Initialize a single plugin by name.
|
|
467
|
+
*
|
|
468
|
+
* @internal
|
|
469
|
+
*/
|
|
470
|
+
private initializePlugin;
|
|
471
|
+
/**
|
|
472
|
+
* Register multiple plugins at once.
|
|
473
|
+
*
|
|
474
|
+
* @param plugins - Array of plugins to register
|
|
475
|
+
* @returns This kernel instance for chaining
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```typescript
|
|
479
|
+
* kernel.useAll([loggerPlugin, dbPlugin, apiPlugin]);
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
useAll(plugins: Plugin$1<TContext>[]): this;
|
|
483
|
+
/**
|
|
484
|
+
* Unregister a plugin from the kernel.
|
|
485
|
+
*
|
|
486
|
+
* If the kernel is initialized and the plugin has an `onDestroy`
|
|
487
|
+
* hook, it will be called before removal. Note: this is the synchronous
|
|
488
|
+
* version from the Kernel interface - for proper async cleanup, use
|
|
489
|
+
* `unregisterAsync()` instead.
|
|
490
|
+
*
|
|
491
|
+
* WARNING: If the plugin is currently initializing, the sync version
|
|
492
|
+
* cannot properly wait for initialization to complete. Use `unregisterAsync()`
|
|
493
|
+
* for proper cleanup of initializing plugins.
|
|
494
|
+
*
|
|
495
|
+
* @param name - Name of the plugin to unregister
|
|
496
|
+
* @returns true if removed, false if not found
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```typescript
|
|
500
|
+
* kernel.unregister('old-plugin');
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
unregister(name: string): boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Unregister a plugin from the kernel (async version).
|
|
506
|
+
*
|
|
507
|
+
* This is the async version that properly awaits onDestroy.
|
|
508
|
+
* If the plugin is currently initializing, it waits for initialization
|
|
509
|
+
* to complete before calling onDestroy to prevent resource leaks.
|
|
510
|
+
*
|
|
511
|
+
* @param name - Name of the plugin to unregister
|
|
512
|
+
* @returns Promise resolving to true if removed, false if not found
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* await kernel.unregisterAsync('old-plugin');
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
unregisterAsync(name: string): Promise<boolean>;
|
|
520
|
+
/**
|
|
521
|
+
* Replace an existing plugin with a new version.
|
|
522
|
+
*
|
|
523
|
+
* Unregisters the existing plugin and registers the new one.
|
|
524
|
+
* If the kernel is initialized, the new plugin will be initialized.
|
|
525
|
+
*
|
|
526
|
+
* @param plugin - The new plugin to register
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* await kernel.replace(updatedPlugin);
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
replace(plugin: Plugin$1<TContext>): Promise<void>;
|
|
534
|
+
/**
|
|
535
|
+
* Reload a plugin (destroy then re-initialize).
|
|
536
|
+
*
|
|
537
|
+
* Calls the plugin's `onDestroy` and `onInit` hooks in sequence.
|
|
538
|
+
* Only works if the kernel is initialized.
|
|
539
|
+
*
|
|
540
|
+
* @param name - Name of the plugin to reload
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```typescript
|
|
544
|
+
* await kernel.reload('config-plugin');
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
reload(name: string): Promise<void>;
|
|
548
|
+
/**
|
|
549
|
+
* Initialize all plugins.
|
|
550
|
+
*
|
|
551
|
+
* Resolves dependencies, calls `onBeforeInit`, initializes all
|
|
552
|
+
* plugins in dependency order, calls `onAfterInit`.
|
|
553
|
+
*
|
|
554
|
+
* @throws {PluginError} If circular dependencies detected
|
|
555
|
+
* @throws {PluginError} If missing dependencies detected
|
|
556
|
+
* @throws {AggregateError} If errors occurred and strategy is 'collect'
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```typescript
|
|
560
|
+
* await kernel.init();
|
|
561
|
+
* console.log('Kernel is ready!');
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
init(): Promise<void>;
|
|
565
|
+
/**
|
|
566
|
+
* Destroy all plugins.
|
|
567
|
+
*
|
|
568
|
+
* Calls `onBeforeDestroy`, destroys all plugins in reverse
|
|
569
|
+
* dependency order, calls `onAfterDestroy`, clears all event
|
|
570
|
+
* subscriptions.
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* ```typescript
|
|
574
|
+
* await kernel.destroy();
|
|
575
|
+
* console.log('Kernel destroyed');
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
destroy(): Promise<void>;
|
|
579
|
+
/**
|
|
580
|
+
* Check if the kernel is initialized.
|
|
581
|
+
*
|
|
582
|
+
* @returns true if kernel is in Ready state
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* if (kernel.isInitialized()) {
|
|
587
|
+
* // Safe to use plugins
|
|
588
|
+
* }
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
isInitialized(): boolean;
|
|
592
|
+
/**
|
|
593
|
+
* Check if the kernel is destroyed.
|
|
594
|
+
*
|
|
595
|
+
* @returns true if kernel is in Destroyed state
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* if (kernel.isDestroyed()) {
|
|
600
|
+
* console.log('Kernel no longer usable');
|
|
601
|
+
* }
|
|
602
|
+
* ```
|
|
603
|
+
*/
|
|
604
|
+
isDestroyed(): boolean;
|
|
605
|
+
/**
|
|
606
|
+
* Get a plugin by name.
|
|
607
|
+
*
|
|
608
|
+
* @param name - Plugin name
|
|
609
|
+
* @returns The plugin or undefined if not found
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```typescript
|
|
613
|
+
* const logger = kernel.getPlugin('logger');
|
|
614
|
+
* if (logger) {
|
|
615
|
+
* console.log(`Logger v${logger.version}`);
|
|
616
|
+
* }
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
getPlugin<T extends Plugin$1<TContext> = Plugin$1<TContext>>(name: string): T | undefined;
|
|
620
|
+
/**
|
|
621
|
+
* Check if a plugin is registered.
|
|
622
|
+
*
|
|
623
|
+
* @param name - Plugin name
|
|
624
|
+
* @returns true if plugin is registered
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```typescript
|
|
628
|
+
* if (kernel.hasPlugin('logger')) {
|
|
629
|
+
* // Logger is available
|
|
630
|
+
* }
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
633
|
+
hasPlugin(name: string): boolean;
|
|
634
|
+
/**
|
|
635
|
+
* List all registered plugins.
|
|
636
|
+
*
|
|
637
|
+
* @returns Readonly array of plugins
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```typescript
|
|
641
|
+
* const plugins = kernel.listPlugins();
|
|
642
|
+
* console.log(`Installed ${plugins.length} plugins`);
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
listPlugins(): ReadonlyArray<Plugin$1<TContext>>;
|
|
646
|
+
/**
|
|
647
|
+
* Get all plugin names.
|
|
648
|
+
*
|
|
649
|
+
* @returns Array of plugin names
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* const names = kernel.getPluginNames();
|
|
654
|
+
* // ['logger', 'database', 'api']
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
getPluginNames(): string[];
|
|
658
|
+
/**
|
|
659
|
+
* Get the dependency graph.
|
|
660
|
+
*
|
|
661
|
+
* @returns Object mapping plugin names to their dependencies
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```typescript
|
|
665
|
+
* const graph = kernel.getDependencyGraph();
|
|
666
|
+
* // { api: ['database', 'cache'], database: [], cache: ['database'] }
|
|
667
|
+
* ```
|
|
668
|
+
*/
|
|
669
|
+
getDependencyGraph(): Record<string, string[]>;
|
|
670
|
+
/**
|
|
671
|
+
* Subscribe to an event.
|
|
672
|
+
*
|
|
673
|
+
* @param event - Event name
|
|
674
|
+
* @param handler - Event handler function
|
|
675
|
+
* @returns Unsubscribe function
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* ```typescript
|
|
679
|
+
* const unsub = kernel.on('user:login', (payload) => {
|
|
680
|
+
* console.log('User logged in:', payload.userId);
|
|
681
|
+
* });
|
|
682
|
+
* // Call unsub() to unsubscribe
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
on<K extends keyof CombinedEvents<TEvents>>(event: K, handler: (payload: CombinedEvents<TEvents>[K]) => void): Unsubscribe;
|
|
686
|
+
/**
|
|
687
|
+
* Subscribe to an event for a single emission.
|
|
688
|
+
*
|
|
689
|
+
* @param event - Event name
|
|
690
|
+
* @param handler - Event handler function
|
|
691
|
+
* @returns Unsubscribe function (usually not needed)
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```typescript
|
|
695
|
+
* kernel.once('kernel:ready', () => {
|
|
696
|
+
* console.log('Kernel is ready!');
|
|
697
|
+
* });
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
once<K extends keyof CombinedEvents<TEvents>>(event: K, handler: (payload: CombinedEvents<TEvents>[K]) => void): Unsubscribe;
|
|
701
|
+
/**
|
|
702
|
+
* Unsubscribe from an event.
|
|
703
|
+
*
|
|
704
|
+
* @param event - Event name
|
|
705
|
+
* @param handler - Handler to remove
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```typescript
|
|
709
|
+
* const handler = (payload) => console.log(payload);
|
|
710
|
+
* kernel.on('event', handler);
|
|
711
|
+
* kernel.off('event', handler);
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
off<K extends keyof CombinedEvents<TEvents>>(event: K, handler: (payload: CombinedEvents<TEvents>[K]) => void): void;
|
|
715
|
+
/**
|
|
716
|
+
* Emit an event to all subscribers.
|
|
717
|
+
*
|
|
718
|
+
* @param event - Event name
|
|
719
|
+
* @param payload - Event payload
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```typescript
|
|
723
|
+
* kernel.emit('user:login', { userId: '123', timestamp: Date.now() });
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
emit<K extends keyof CombinedEvents<TEvents>>(event: K, payload: CombinedEvents<TEvents>[K]): void;
|
|
727
|
+
/**
|
|
728
|
+
* Subscribe to all events (wildcard).
|
|
729
|
+
*
|
|
730
|
+
* @param handler - Handler receiving (event, payload)
|
|
731
|
+
* @returns Unsubscribe function
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* ```typescript
|
|
735
|
+
* kernel.onWildcard((event, payload) => {
|
|
736
|
+
* console.log(`[${event}]`, payload);
|
|
737
|
+
* });
|
|
738
|
+
* ```
|
|
739
|
+
*/
|
|
740
|
+
onWildcard(handler: (event: string, payload: unknown) => void): Unsubscribe;
|
|
741
|
+
/**
|
|
742
|
+
* Subscribe to events matching a pattern.
|
|
743
|
+
*
|
|
744
|
+
* @param pattern - Pattern like `'user:*'`
|
|
745
|
+
* @param handler - Handler receiving (event, payload)
|
|
746
|
+
* @returns Unsubscribe function
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* ```typescript
|
|
750
|
+
* kernel.onPattern('user:*', (event, payload) => {
|
|
751
|
+
* console.log('User event:', event);
|
|
752
|
+
* });
|
|
753
|
+
* ```
|
|
754
|
+
*/
|
|
755
|
+
onPattern(pattern: string, handler: (event: string, payload: unknown) => void): Unsubscribe;
|
|
756
|
+
/**
|
|
757
|
+
* Get the current context.
|
|
758
|
+
*
|
|
759
|
+
* @returns The shared context object
|
|
760
|
+
*
|
|
761
|
+
* @example
|
|
762
|
+
* ```typescript
|
|
763
|
+
* const ctx = kernel.getContext();
|
|
764
|
+
* console.log(ctx.env);
|
|
765
|
+
* ```
|
|
766
|
+
*/
|
|
767
|
+
getContext(): TContext;
|
|
768
|
+
/**
|
|
769
|
+
* Update the context with a partial merge (shallow).
|
|
770
|
+
*
|
|
771
|
+
* Only top-level properties are merged. For deep merging of
|
|
772
|
+
* nested objects, use `deepUpdateContext()`.
|
|
773
|
+
*
|
|
774
|
+
* @param partial - Partial context to merge
|
|
775
|
+
*
|
|
776
|
+
* @example
|
|
777
|
+
* ```typescript
|
|
778
|
+
* kernel.updateContext({ env: 'production' });
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
updateContext(partial: Partial<TContext>): void;
|
|
782
|
+
/**
|
|
783
|
+
* Update the context with a deep merge.
|
|
784
|
+
*
|
|
785
|
+
* Nested objects are recursively merged instead of being replaced.
|
|
786
|
+
* Arrays are replaced, not merged.
|
|
787
|
+
*
|
|
788
|
+
* Use this when you have nested configuration and want to update
|
|
789
|
+
* only specific nested properties without losing other nested values.
|
|
790
|
+
*
|
|
791
|
+
* @param partial - Partial context to deep merge
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* ```typescript
|
|
795
|
+
* interface Context { config: { db: string; api: string } };
|
|
796
|
+
* const kernel = createKernel<Context>({
|
|
797
|
+
* context: { config: { db: 'localhost', api: 'http://localhost' } }
|
|
798
|
+
* });
|
|
799
|
+
*
|
|
800
|
+
* // Deep merge - only updates db, keeps api
|
|
801
|
+
* kernel.deepUpdateContext({ config: { db: 'postgres://prod' } });
|
|
802
|
+
* kernel.getContext(); // { config: { db: 'postgres://prod', api: 'http://localhost' } }
|
|
803
|
+
* ```
|
|
804
|
+
*/
|
|
805
|
+
deepUpdateContext(partial: DeepPartial<TContext>): void;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* @oxog/plugin - Micro-kernel plugin system
|
|
810
|
+
*
|
|
811
|
+
* A lightweight, typed plugin system with lifecycle management,
|
|
812
|
+
* event bus, and dependency resolution.
|
|
813
|
+
*
|
|
814
|
+
* @packageDocumentation
|
|
815
|
+
*
|
|
816
|
+
* @example
|
|
817
|
+
* ```typescript
|
|
818
|
+
* import { createKernel } from '@oxog/plugin';
|
|
819
|
+
*
|
|
820
|
+
* const kernel = createKernel();
|
|
821
|
+
* kernel.use(myPlugin);
|
|
822
|
+
* await kernel.init();
|
|
823
|
+
* ```
|
|
824
|
+
*/
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Create a new micro-kernel instance.
|
|
828
|
+
*
|
|
829
|
+
* The kernel is the central component that manages plugins throughout
|
|
830
|
+
* their lifecycle. It provides plugin registration, lifecycle hooks,
|
|
831
|
+
* type-safe events, dependency resolution, and shared context.
|
|
832
|
+
*
|
|
833
|
+
* @template TContext - Type of shared context between plugins
|
|
834
|
+
* @template TEvents - Event map for typed events
|
|
835
|
+
* @param options - Optional kernel configuration
|
|
836
|
+
* @returns A new kernel instance
|
|
837
|
+
*
|
|
838
|
+
* @example
|
|
839
|
+
* ```typescript
|
|
840
|
+
* // Simple usage
|
|
841
|
+
* const kernel = createKernel();
|
|
842
|
+
* ```
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
845
|
+
* ```typescript
|
|
846
|
+
* // With context type
|
|
847
|
+
* interface AppContext {
|
|
848
|
+
* env: 'development' | 'production';
|
|
849
|
+
* debug: boolean;
|
|
850
|
+
* }
|
|
851
|
+
*
|
|
852
|
+
* const kernel = createKernel<AppContext>({
|
|
853
|
+
* context: { env: 'development', debug: true }
|
|
854
|
+
* });
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```typescript
|
|
859
|
+
* // With typed events
|
|
860
|
+
* interface AppEvents {
|
|
861
|
+
* 'user:login': { userId: string; timestamp: number };
|
|
862
|
+
* 'user:logout': { userId: string };
|
|
863
|
+
* }
|
|
864
|
+
*
|
|
865
|
+
* const kernel = createKernel<{}, AppEvents>();
|
|
866
|
+
*
|
|
867
|
+
* kernel.on('user:login', (payload) => {
|
|
868
|
+
* // payload is typed as { userId: string; timestamp: number }
|
|
869
|
+
* console.log(`User ${payload.userId} logged in at ${payload.timestamp}`);
|
|
870
|
+
* });
|
|
871
|
+
*
|
|
872
|
+
* kernel.emit('user:login', { userId: '123', timestamp: Date.now() });
|
|
873
|
+
* ```
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```typescript
|
|
877
|
+
* // With full configuration
|
|
878
|
+
* interface AppContext {
|
|
879
|
+
* config: { apiUrl: string };
|
|
880
|
+
* }
|
|
881
|
+
*
|
|
882
|
+
* const kernel = createKernel<AppContext, {}>({
|
|
883
|
+
* context: {
|
|
884
|
+
* config: { apiUrl: 'https://api.example.com' }
|
|
885
|
+
* },
|
|
886
|
+
* errorStrategy: 'isolate', // 'isolate' | 'fail-fast' | 'collect'
|
|
887
|
+
* onError: (error, pluginName) => {
|
|
888
|
+
* console.error(`[${pluginName}] Error:`, error.message);
|
|
889
|
+
* },
|
|
890
|
+
* onBeforeInit: async () => {
|
|
891
|
+
* console.log('Initializing kernel...');
|
|
892
|
+
* },
|
|
893
|
+
* onAfterInit: async () => {
|
|
894
|
+
* console.log('Kernel ready!');
|
|
895
|
+
* },
|
|
896
|
+
* onBeforeDestroy: async () => {
|
|
897
|
+
* console.log('Destroying kernel...');
|
|
898
|
+
* },
|
|
899
|
+
* onAfterDestroy: async () => {
|
|
900
|
+
* console.log('Kernel destroyed');
|
|
901
|
+
* }
|
|
902
|
+
* });
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
declare function createKernel<TContext = unknown, TEvents extends object = EventMap>(options?: {
|
|
906
|
+
/** Initial shared context value */
|
|
907
|
+
context?: TContext;
|
|
908
|
+
/** Error handling strategy: 'isolate' | 'fail-fast' | 'collect' */
|
|
909
|
+
errorStrategy?: 'isolate' | 'fail-fast' | 'collect';
|
|
910
|
+
/** Global error handler called when any plugin errors */
|
|
911
|
+
onError?: (error: Error, pluginName: string) => void;
|
|
912
|
+
/** Hook called before kernel initialization starts */
|
|
913
|
+
onBeforeInit?: () => void | Promise<void>;
|
|
914
|
+
/** Hook called after kernel initialization completes */
|
|
915
|
+
onAfterInit?: () => void | Promise<void>;
|
|
916
|
+
/** Hook called before kernel destruction starts */
|
|
917
|
+
onBeforeDestroy?: () => void | Promise<void>;
|
|
918
|
+
/** Hook called after kernel destruction completes */
|
|
919
|
+
onAfterDestroy?: () => void | Promise<void>;
|
|
920
|
+
}): KernelInstance<TContext, TEvents>;
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Builder-pattern Pigment for explicit composition.
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* ```typescript
|
|
927
|
+
* const builder = new BuilderPigment(kernel);
|
|
928
|
+
* const styled = builder.bold().red().paint('Error!');
|
|
929
|
+
* ```
|
|
930
|
+
*/
|
|
931
|
+
declare class BuilderPigment {
|
|
932
|
+
private styles;
|
|
933
|
+
private readonly kernel;
|
|
934
|
+
constructor(kernel?: PigmentKernel);
|
|
935
|
+
/** The instance's color level (true color when there is no kernel). */
|
|
936
|
+
private get level();
|
|
937
|
+
bold(): this;
|
|
938
|
+
dim(): this;
|
|
939
|
+
italic(): this;
|
|
940
|
+
underline(): this;
|
|
941
|
+
strikethrough(): this;
|
|
942
|
+
inverse(): this;
|
|
943
|
+
hidden(): this;
|
|
944
|
+
reset(): this;
|
|
945
|
+
black(): this;
|
|
946
|
+
red(): this;
|
|
947
|
+
green(): this;
|
|
948
|
+
yellow(): this;
|
|
949
|
+
blue(): this;
|
|
950
|
+
magenta(): this;
|
|
951
|
+
cyan(): this;
|
|
952
|
+
white(): this;
|
|
953
|
+
blackBright(): this;
|
|
954
|
+
redBright(): this;
|
|
955
|
+
greenBright(): this;
|
|
956
|
+
yellowBright(): this;
|
|
957
|
+
blueBright(): this;
|
|
958
|
+
magentaBright(): this;
|
|
959
|
+
cyanBright(): this;
|
|
960
|
+
whiteBright(): this;
|
|
961
|
+
gray(): this;
|
|
962
|
+
grey(): this;
|
|
963
|
+
bgBlack(): this;
|
|
964
|
+
bgRed(): this;
|
|
965
|
+
bgGreen(): this;
|
|
966
|
+
bgYellow(): this;
|
|
967
|
+
bgBlue(): this;
|
|
968
|
+
bgMagenta(): this;
|
|
969
|
+
bgCyan(): this;
|
|
970
|
+
bgWhite(): this;
|
|
971
|
+
bgBlackBright(): this;
|
|
972
|
+
bgRedBright(): this;
|
|
973
|
+
bgGreenBright(): this;
|
|
974
|
+
bgYellowBright(): this;
|
|
975
|
+
bgBlueBright(): this;
|
|
976
|
+
bgMagentaBright(): this;
|
|
977
|
+
bgCyanBright(): this;
|
|
978
|
+
bgWhiteBright(): this;
|
|
979
|
+
bgGray(): this;
|
|
980
|
+
bgGrey(): this;
|
|
981
|
+
ansi256(code: number): this;
|
|
982
|
+
bgAnsi256(code: number): this;
|
|
983
|
+
rgb(r: number, g: number, b: number): this;
|
|
984
|
+
bgRgb(r: number, g: number, b: number): this;
|
|
985
|
+
hex(color: string): this;
|
|
986
|
+
bgHex(color: string): this;
|
|
987
|
+
hsl(h: number, s: number, l: number): this;
|
|
988
|
+
bgHsl(h: number, s: number, l: number): this;
|
|
989
|
+
paint(text: string): string;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
type PigmentOptions = {
|
|
993
|
+
level?: 0 | 1 | 2 | 3;
|
|
994
|
+
forceColor?: boolean;
|
|
995
|
+
noColor?: boolean;
|
|
996
|
+
plugins?: Plugin<PigmentContext>[];
|
|
997
|
+
};
|
|
998
|
+
type ColorSupport = {
|
|
999
|
+
level: 0 | 1 | 2 | 3;
|
|
1000
|
+
hasBasic: boolean;
|
|
1001
|
+
has256: boolean;
|
|
1002
|
+
has16m: boolean;
|
|
1003
|
+
};
|
|
1004
|
+
type Styler = (text: string) => string;
|
|
1005
|
+
type Style = {
|
|
1006
|
+
name: string;
|
|
1007
|
+
code: number;
|
|
1008
|
+
open: string;
|
|
1009
|
+
close: string;
|
|
1010
|
+
type: 'modifier' | 'color';
|
|
1011
|
+
background?: boolean;
|
|
1012
|
+
};
|
|
1013
|
+
type Pigment = {
|
|
1014
|
+
/** Returns the (styled) text when colors are supported, otherwise an empty string */
|
|
1015
|
+
visible: (text: string) => string;
|
|
1016
|
+
bold: Pigment;
|
|
1017
|
+
dim: Pigment;
|
|
1018
|
+
italic: Pigment;
|
|
1019
|
+
underline: Pigment;
|
|
1020
|
+
strikethrough: Pigment;
|
|
1021
|
+
inverse: Pigment;
|
|
1022
|
+
hidden: Pigment;
|
|
1023
|
+
reset: Pigment;
|
|
1024
|
+
black: Pigment;
|
|
1025
|
+
red: Pigment;
|
|
1026
|
+
green: Pigment;
|
|
1027
|
+
yellow: Pigment;
|
|
1028
|
+
blue: Pigment;
|
|
1029
|
+
magenta: Pigment;
|
|
1030
|
+
cyan: Pigment;
|
|
1031
|
+
white: Pigment;
|
|
1032
|
+
blackBright: Pigment;
|
|
1033
|
+
redBright: Pigment;
|
|
1034
|
+
greenBright: Pigment;
|
|
1035
|
+
yellowBright: Pigment;
|
|
1036
|
+
blueBright: Pigment;
|
|
1037
|
+
magentaBright: Pigment;
|
|
1038
|
+
cyanBright: Pigment;
|
|
1039
|
+
whiteBright: Pigment;
|
|
1040
|
+
gray: Pigment;
|
|
1041
|
+
grey: Pigment;
|
|
1042
|
+
bgBlack: Pigment;
|
|
1043
|
+
bgRed: Pigment;
|
|
1044
|
+
bgGreen: Pigment;
|
|
1045
|
+
bgYellow: Pigment;
|
|
1046
|
+
bgBlue: Pigment;
|
|
1047
|
+
bgMagenta: Pigment;
|
|
1048
|
+
bgCyan: Pigment;
|
|
1049
|
+
bgWhite: Pigment;
|
|
1050
|
+
bgBlackBright: Pigment;
|
|
1051
|
+
bgRedBright: Pigment;
|
|
1052
|
+
bgGreenBright: Pigment;
|
|
1053
|
+
bgYellowBright: Pigment;
|
|
1054
|
+
bgBlueBright: Pigment;
|
|
1055
|
+
bgMagentaBright: Pigment;
|
|
1056
|
+
bgCyanBright: Pigment;
|
|
1057
|
+
bgWhiteBright: Pigment;
|
|
1058
|
+
bgGray: Pigment;
|
|
1059
|
+
bgGrey: Pigment;
|
|
1060
|
+
ansi256(code: number): Pigment;
|
|
1061
|
+
bgAnsi256(code: number): Pigment;
|
|
1062
|
+
rgb(r: number, g: number, b: number): Pigment;
|
|
1063
|
+
bgRgb(r: number, g: number, b: number): Pigment;
|
|
1064
|
+
hex(color: string): Pigment;
|
|
1065
|
+
bgHex(color: string): Pigment;
|
|
1066
|
+
hsl(h: number, s: number, l: number): Pigment;
|
|
1067
|
+
bgHsl(h: number, s: number, l: number): Pigment;
|
|
1068
|
+
(text: string): string;
|
|
1069
|
+
};
|
|
1070
|
+
/**
|
|
1071
|
+
* A color accepted by plugin methods: `'#rrggbb'` / `'#rgb'`, `'rgb(r, g, b)'`
|
|
1072
|
+
* or `[r, g, b]`.
|
|
1073
|
+
*/
|
|
1074
|
+
type ColorInput = string | readonly [number, number, number];
|
|
1075
|
+
/** Theme color roles used by `themePlugin`. */
|
|
1076
|
+
type ThemeColorType = 'keyword' | 'string' | 'number' | 'comment' | 'error' | 'success' | 'warning' | 'info';
|
|
1077
|
+
/** Options for `pigment.box()` (`boxPlugin`). */
|
|
1078
|
+
type BoxOptions = {
|
|
1079
|
+
border?: BoxBorder;
|
|
1080
|
+
padding?: number;
|
|
1081
|
+
/** Background color for the whole box. */
|
|
1082
|
+
bgColor?: string;
|
|
1083
|
+
};
|
|
1084
|
+
/**
|
|
1085
|
+
* Methods added to an instance by the optional plugins. Each one throws a
|
|
1086
|
+
* `PluginError` naming the plugin to install when it is missing.
|
|
1087
|
+
*/
|
|
1088
|
+
type PigmentPluginApi = {
|
|
1089
|
+
/** gradientPlugin: color each character along a gradient. */
|
|
1090
|
+
gradient(start: ColorInput, end: ColorInput): (text: string) => string;
|
|
1091
|
+
/** gradientPlugin: rainbow-colored text. */
|
|
1092
|
+
rainbow(text: string): string;
|
|
1093
|
+
/** themePlugin: style text with a theme role color. */
|
|
1094
|
+
theme: Record<ThemeColorType, (text: string) => string>;
|
|
1095
|
+
/** semanticPlugin */
|
|
1096
|
+
success(text: string): string;
|
|
1097
|
+
/** semanticPlugin */
|
|
1098
|
+
error(text: string): string;
|
|
1099
|
+
/** semanticPlugin */
|
|
1100
|
+
warning(text: string): string;
|
|
1101
|
+
/** semanticPlugin */
|
|
1102
|
+
info(text: string): string;
|
|
1103
|
+
/** semanticPlugin */
|
|
1104
|
+
debug(text: string): string;
|
|
1105
|
+
/** boxPlugin: draw a box around text. */
|
|
1106
|
+
box(text: string, options?: BoxOptions): string;
|
|
1107
|
+
/** templatePlugin: tagged template with `{style.chain text}` blocks. */
|
|
1108
|
+
template(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
1109
|
+
};
|
|
1110
|
+
/**
|
|
1111
|
+
* What `createPigment()` returns (and the `pigment` export): the chainable
|
|
1112
|
+
* styler plus instance members.
|
|
1113
|
+
*/
|
|
1114
|
+
type PigmentInstance = Pigment & PigmentPluginApi & {
|
|
1115
|
+
/** A new builder on every access. */
|
|
1116
|
+
readonly builder: BuilderPigment;
|
|
1117
|
+
readonly level: number;
|
|
1118
|
+
readonly supportsColor: ColorSupport;
|
|
1119
|
+
/** Install a plugin on this instance; returns the instance. */
|
|
1120
|
+
use(plugin: Plugin<PigmentContext>): PigmentInstance;
|
|
1121
|
+
};
|
|
1122
|
+
/**
|
|
1123
|
+
* Plugin interface - re-exported from @oxog/types.
|
|
1124
|
+
* Use this for creating Pigment-compatible plugins.
|
|
1125
|
+
*/
|
|
1126
|
+
type Plugin<TContext = unknown> = Plugin$2<TContext>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Kernel interface - re-exported from @oxog/types.
|
|
1129
|
+
*/
|
|
1130
|
+
type Kernel<TContext = unknown> = Kernel$1<TContext>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Pigment kernel type - extended KernelInstance from @oxog/plugin.
|
|
1133
|
+
*/
|
|
1134
|
+
type PigmentKernel<TContext = PigmentContext> = KernelInstance<TContext, PigmentEvents>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Pigment context shared between plugins.
|
|
1137
|
+
*/
|
|
1138
|
+
interface PigmentContext {
|
|
1139
|
+
/** Current color level */
|
|
1140
|
+
level: 0 | 1 | 2 | 3;
|
|
1141
|
+
/** Whether colors are enabled */
|
|
1142
|
+
enabled: boolean;
|
|
1143
|
+
/** Color support information */
|
|
1144
|
+
colorSupport: ColorSupport;
|
|
1145
|
+
/** Registered styles map */
|
|
1146
|
+
styles?: Map<string, StyleFunction>;
|
|
1147
|
+
environment?: {
|
|
1148
|
+
isCI: boolean;
|
|
1149
|
+
noColor: boolean;
|
|
1150
|
+
forceColor: boolean;
|
|
1151
|
+
term: string;
|
|
1152
|
+
};
|
|
1153
|
+
/** Colors map */
|
|
1154
|
+
colors?: {
|
|
1155
|
+
foreground: Record<string, number>;
|
|
1156
|
+
background: Record<string, number>;
|
|
1157
|
+
all: Record<string, number>;
|
|
1158
|
+
};
|
|
1159
|
+
/** Utility functions */
|
|
1160
|
+
utils?: {
|
|
1161
|
+
hexToRgb: (hex: string) => {
|
|
1162
|
+
r: number;
|
|
1163
|
+
g: number;
|
|
1164
|
+
b: number;
|
|
1165
|
+
};
|
|
1166
|
+
hslToRgb: (h: number, s: number, l: number) => {
|
|
1167
|
+
r: number;
|
|
1168
|
+
g: number;
|
|
1169
|
+
b: number;
|
|
1170
|
+
};
|
|
1171
|
+
rgbToAnsi256: (r: number, g: number, b: number) => number;
|
|
1172
|
+
detectColorSupport: (level?: 0 | 1 | 2 | 3) => ColorSupport;
|
|
1173
|
+
supportsColor: (level?: 0 | 1 | 2 | 3) => ColorSupport;
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Pigment event map for type-safe events.
|
|
1178
|
+
*/
|
|
1179
|
+
interface PigmentEvents {
|
|
1180
|
+
'plugin:register': {
|
|
1181
|
+
plugin: Plugin<PigmentContext>;
|
|
1182
|
+
};
|
|
1183
|
+
'plugin:unregister': {
|
|
1184
|
+
plugin: Plugin<PigmentContext>;
|
|
1185
|
+
};
|
|
1186
|
+
'plugin:init': {
|
|
1187
|
+
plugin: Plugin<PigmentContext>;
|
|
1188
|
+
};
|
|
1189
|
+
'plugin:destroy': {
|
|
1190
|
+
plugin: Plugin<PigmentContext>;
|
|
1191
|
+
};
|
|
1192
|
+
'context:change': PigmentContext;
|
|
1193
|
+
'style:apply': {
|
|
1194
|
+
name: string;
|
|
1195
|
+
text: string;
|
|
1196
|
+
};
|
|
1197
|
+
'error': Error;
|
|
1198
|
+
[key: string]: unknown;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Style function type.
|
|
1202
|
+
*/
|
|
1203
|
+
type StyleFunction = {
|
|
1204
|
+
(text: string): string;
|
|
1205
|
+
open: string;
|
|
1206
|
+
close: string;
|
|
1207
|
+
};
|
|
1208
|
+
type ThemePreset = 'monokai' | 'dracula' | 'nord' | 'github' | 'vscode' | 'tokyo-night' | 'catppuccin' | 'one-dark' | 'solarized';
|
|
1209
|
+
type BoxBorder = 'single' | 'double' | 'rounded' | 'bold' | 'classic';
|
|
1210
|
+
type GradientPluginOptions = {
|
|
1211
|
+
steps?: number;
|
|
1212
|
+
};
|
|
1213
|
+
type ThemePluginOptions = {
|
|
1214
|
+
preset?: ThemePreset;
|
|
1215
|
+
custom?: Record<string, string>;
|
|
1216
|
+
};
|
|
1217
|
+
type BoxPluginOptions = {
|
|
1218
|
+
border?: BoxBorder;
|
|
1219
|
+
padding?: number;
|
|
1220
|
+
};
|
|
1221
|
+
type PigmentPluginOptions = {
|
|
1222
|
+
theme?: ThemePreset;
|
|
1223
|
+
level?: 0 | 1 | 2 | 3;
|
|
1224
|
+
};
|
|
1225
|
+
type Platform = {
|
|
1226
|
+
isNode: boolean;
|
|
1227
|
+
isBrowser: boolean;
|
|
1228
|
+
isWindows: boolean;
|
|
1229
|
+
isCI: boolean;
|
|
1230
|
+
hasTTY: boolean;
|
|
1231
|
+
};
|
|
1232
|
+
type ThemePresetColors = {
|
|
1233
|
+
keyword: string;
|
|
1234
|
+
string: string;
|
|
1235
|
+
number: string;
|
|
1236
|
+
comment: string;
|
|
1237
|
+
error: string;
|
|
1238
|
+
success: string;
|
|
1239
|
+
warning: string;
|
|
1240
|
+
info: string;
|
|
1241
|
+
};
|
|
1242
|
+
type SemanticPluginOptions = {
|
|
1243
|
+
success?: string;
|
|
1244
|
+
error?: string;
|
|
1245
|
+
warning?: string;
|
|
1246
|
+
info?: string;
|
|
1247
|
+
debug?: string;
|
|
1248
|
+
};
|
|
1249
|
+
type BoxChars = {
|
|
1250
|
+
tl: string;
|
|
1251
|
+
tr: string;
|
|
1252
|
+
bl: string;
|
|
1253
|
+
br: string;
|
|
1254
|
+
h: string;
|
|
1255
|
+
v: string;
|
|
1256
|
+
};
|
|
1257
|
+
type KernelOptions<TContext> = {
|
|
1258
|
+
context?: TContext;
|
|
1259
|
+
};
|
|
1260
|
+
/**
|
|
1261
|
+
* Event handler type.
|
|
1262
|
+
*/
|
|
1263
|
+
type EventHandler = (data?: unknown) => void;
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Core plugin that provides 16 base ANSI colors + bright variants.
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```typescript
|
|
1270
|
+
* const pigment = createPigment();
|
|
1271
|
+
* pigment.red('Error!');
|
|
1272
|
+
* pigment.greenBright('Success!');
|
|
1273
|
+
* ```
|
|
1274
|
+
*/
|
|
1275
|
+
declare function baseColorsPlugin(): Plugin<PigmentContext>;
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Core plugin that provides text modifiers (bold, dim, italic, etc.).
|
|
1279
|
+
*
|
|
1280
|
+
* @example
|
|
1281
|
+
* ```typescript
|
|
1282
|
+
* const pigment = createPigment();
|
|
1283
|
+
* pigment.bold('Bold text');
|
|
1284
|
+
* pigment.italic.underline('Styled text');
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
declare function modifiersPlugin(): Plugin<PigmentContext>;
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* Core plugin that provides 256-color palette support.
|
|
1291
|
+
*
|
|
1292
|
+
* @example
|
|
1293
|
+
* ```typescript
|
|
1294
|
+
* const pigment = createPigment();
|
|
1295
|
+
* pigment.ansi256(196)('Bright red');
|
|
1296
|
+
* pigment.bgAnsi256(21)('Blue background');
|
|
1297
|
+
* ```
|
|
1298
|
+
*/
|
|
1299
|
+
declare function ansi256Plugin(): Plugin<PigmentContext>;
|
|
1300
|
+
|
|
1301
|
+
/**
|
|
1302
|
+
* Core plugin that provides RGB, HEX, and HSL color support.
|
|
1303
|
+
*
|
|
1304
|
+
* @example
|
|
1305
|
+
* ```typescript
|
|
1306
|
+
* const pigment = createPigment();
|
|
1307
|
+
* pigment.rgb(255, 136, 0)('Orange text');
|
|
1308
|
+
* pigment.hex('#FF8800')('Orange text');
|
|
1309
|
+
* pigment.hsl(30, 100, 50)('Orange text');
|
|
1310
|
+
* ```
|
|
1311
|
+
*/
|
|
1312
|
+
declare function trueColorPlugin(): Plugin<PigmentContext>;
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* Core plugin that enables nested/composed style support.
|
|
1316
|
+
*
|
|
1317
|
+
* Nesting is handled directly in applyStyles() by replacing inner reset codes
|
|
1318
|
+
* with outer style reopeners. This plugin just sets the enabled flag for
|
|
1319
|
+
* compatibility and to indicate nesting support is active.
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* ```typescript
|
|
1323
|
+
* const pigment = createPigment();
|
|
1324
|
+
* // Nested styles work automatically:
|
|
1325
|
+
* pigment.red(`Error: ${pigment.blue('details')} here`);
|
|
1326
|
+
* // Output: "Error: " (red), "details" (blue), " here" (red again)
|
|
1327
|
+
* ```
|
|
1328
|
+
*/
|
|
1329
|
+
declare function nestingPlugin(): Plugin<PigmentContext>;
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Core plugin that handles environment detection (NO_COLOR, FORCE_COLOR, TTY).
|
|
1333
|
+
*
|
|
1334
|
+
* Respects environment variables:
|
|
1335
|
+
* - NO_COLOR - disables all colors
|
|
1336
|
+
* - FORCE_COLOR - forces color level (0, 1, 2, 3)
|
|
1337
|
+
* - TERM - terminal type detection
|
|
1338
|
+
* - CI - CI environment detection
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* ```typescript
|
|
1342
|
+
* const pigment = createPigment();
|
|
1343
|
+
* // Automatically detects environment
|
|
1344
|
+
* ```
|
|
1345
|
+
*/
|
|
1346
|
+
declare function environmentPlugin(): Plugin<PigmentContext>;
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Optional plugin that provides smooth color gradients between two colors.
|
|
1350
|
+
*
|
|
1351
|
+
* @example
|
|
1352
|
+
* ```typescript
|
|
1353
|
+
* import { createPigment } from '@oxog/pigment';
|
|
1354
|
+
* import { gradientPlugin } from '@oxog/pigment/plugins';
|
|
1355
|
+
*
|
|
1356
|
+
* const pigment = createPigment({
|
|
1357
|
+
* plugins: [gradientPlugin()]
|
|
1358
|
+
* });
|
|
1359
|
+
*
|
|
1360
|
+
* pigment.gradient('red', 'blue')('Gradient text');
|
|
1361
|
+
* pigment.rainbow('Rainbow text');
|
|
1362
|
+
* ```
|
|
1363
|
+
*/
|
|
1364
|
+
declare function gradientPlugin(options?: GradientPluginOptions): Plugin<PigmentContext>;
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Optional plugin that provides predefined color themes.
|
|
1368
|
+
*
|
|
1369
|
+
* @example
|
|
1370
|
+
* ```typescript
|
|
1371
|
+
* import { createPigment } from '@oxog/pigment';
|
|
1372
|
+
* import { themePlugin } from '@oxog/pigment/plugins';
|
|
1373
|
+
*
|
|
1374
|
+
* const pigment = createPigment({
|
|
1375
|
+
* plugins: [themePlugin({ preset: 'monokai' })]
|
|
1376
|
+
* });
|
|
1377
|
+
*
|
|
1378
|
+
* pigment.theme.keyword('const');
|
|
1379
|
+
* pigment.theme.string('"hello"');
|
|
1380
|
+
* pigment.theme.error('Error!');
|
|
1381
|
+
* ```
|
|
1382
|
+
*
|
|
1383
|
+
* Available presets: monokai, dracula, nord, github, vscode, tokyo-night, catppuccin, one-dark, solarized
|
|
1384
|
+
*/
|
|
1385
|
+
declare function themePlugin(options?: ThemePluginOptions): Plugin<PigmentContext>;
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Optional plugin that provides semantic colors (success, error, warning, info, debug).
|
|
1389
|
+
*
|
|
1390
|
+
* @example
|
|
1391
|
+
* ```typescript
|
|
1392
|
+
* import { createPigment } from '@oxog/pigment';
|
|
1393
|
+
* import { semanticPlugin } from '@oxog/pigment/plugins';
|
|
1394
|
+
*
|
|
1395
|
+
* const pigment = createPigment({
|
|
1396
|
+
* plugins: [semanticPlugin()]
|
|
1397
|
+
* });
|
|
1398
|
+
*
|
|
1399
|
+
* pigment.success('✓ Task completed');
|
|
1400
|
+
* pigment.error('✗ Task failed');
|
|
1401
|
+
* pigment.warning('⚠ Check this');
|
|
1402
|
+
* pigment.info('ℹ Note');
|
|
1403
|
+
* pigment.debug('[DEBUG] value');
|
|
1404
|
+
* ```
|
|
1405
|
+
*/
|
|
1406
|
+
declare function semanticPlugin(options?: SemanticPluginOptions): Plugin<PigmentContext>;
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* Optional plugin that provides box drawing with borders.
|
|
1410
|
+
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* ```typescript
|
|
1413
|
+
* import { createPigment } from '@oxog/pigment';
|
|
1414
|
+
* import { boxPlugin } from '@oxog/pigment/plugins';
|
|
1415
|
+
*
|
|
1416
|
+
* const pigment = createPigment({
|
|
1417
|
+
* plugins: [boxPlugin()]
|
|
1418
|
+
* });
|
|
1419
|
+
*
|
|
1420
|
+
* pigment.box('Hello World');
|
|
1421
|
+
* // ┌─────────────┐
|
|
1422
|
+
* // │ Hello World │
|
|
1423
|
+
* // └─────────────┘
|
|
1424
|
+
*
|
|
1425
|
+
* pigment.box('Error!', { border: 'double', padding: 2 });
|
|
1426
|
+
* ```
|
|
1427
|
+
*/
|
|
1428
|
+
declare function boxPlugin(options?: BoxPluginOptions): Plugin<PigmentContext>;
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* Optional plugin that provides tagged template literal syntax.
|
|
1432
|
+
*
|
|
1433
|
+
* @example
|
|
1434
|
+
* ```typescript
|
|
1435
|
+
* import { createPigment } from '@oxog/pigment';
|
|
1436
|
+
* import { templatePlugin } from '@oxog/pigment/plugins';
|
|
1437
|
+
*
|
|
1438
|
+
* const pigment = createPigment({
|
|
1439
|
+
* plugins: [templatePlugin()]
|
|
1440
|
+
* });
|
|
1441
|
+
*
|
|
1442
|
+
* console.log(pigment.template`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
|
|
1443
|
+
* console.log(pigment.template`{bold.red CRITICAL:} {dim system {underline failure}}`);
|
|
1444
|
+
* ```
|
|
1445
|
+
*/
|
|
1446
|
+
declare function templatePlugin(): Plugin<PigmentContext>;
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* Plugin that adds Pigment color support to any @oxog kernel.
|
|
1450
|
+
* Use this in @oxog/log, @oxog/cli, etc.
|
|
1451
|
+
*
|
|
1452
|
+
* @example
|
|
1453
|
+
* ```typescript
|
|
1454
|
+
* // In @oxog/log or @oxog/cli
|
|
1455
|
+
* import { pigmentPlugin } from '@oxog/pigment/plugins';
|
|
1456
|
+
*
|
|
1457
|
+
* const log = createLogger();
|
|
1458
|
+
* log.use(pigmentPlugin()); // Adds color support to logger
|
|
1459
|
+
*
|
|
1460
|
+
* // Now log has access to colors
|
|
1461
|
+
* log.pigment.red('Error message');
|
|
1462
|
+
* ```
|
|
1463
|
+
*/
|
|
1464
|
+
declare function pigmentPlugin<TContext = unknown>(options?: PigmentPluginOptions): Plugin<TContext>;
|
|
1465
|
+
|
|
1466
|
+
declare const index_ansi256Plugin: typeof ansi256Plugin;
|
|
1467
|
+
declare const index_baseColorsPlugin: typeof baseColorsPlugin;
|
|
1468
|
+
declare const index_boxPlugin: typeof boxPlugin;
|
|
1469
|
+
declare const index_environmentPlugin: typeof environmentPlugin;
|
|
1470
|
+
declare const index_gradientPlugin: typeof gradientPlugin;
|
|
1471
|
+
declare const index_modifiersPlugin: typeof modifiersPlugin;
|
|
1472
|
+
declare const index_nestingPlugin: typeof nestingPlugin;
|
|
1473
|
+
declare const index_pigmentPlugin: typeof pigmentPlugin;
|
|
1474
|
+
declare const index_semanticPlugin: typeof semanticPlugin;
|
|
1475
|
+
declare const index_templatePlugin: typeof templatePlugin;
|
|
1476
|
+
declare const index_themePlugin: typeof themePlugin;
|
|
1477
|
+
declare const index_trueColorPlugin: typeof trueColorPlugin;
|
|
1478
|
+
declare namespace index {
|
|
1479
|
+
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 };
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
export { environmentPlugin as A, type BoxBorder as B, type ColorSupport as C, gradientPlugin as D, type EventHandler as E, modifiersPlugin as F, type GradientPluginOptions as G, nestingPlugin as H, pigmentPlugin as I, semanticPlugin as J, type Kernel as K, templatePlugin as L, type MaybePromise as M, themePlugin as N, trueColorPlugin as O, type PigmentOptions as P, type Styler as S, type ThemeColorType as T, type Unsubscribe as U, type PigmentInstance as a, type Pigment as b, type Platform as c, type BoxChars as d, type BoxOptions as e, type BoxPluginOptions as f, BuilderPigment as g, type ColorInput as h, type KernelOptions as i, type PigmentContext as j, type PigmentEvents as k, type PigmentKernel as l, type PigmentPluginApi as m, type PigmentPluginOptions as n, type Plugin as o, type SemanticPluginOptions as p, type Style as q, type StyleFunction as r, type ThemePluginOptions as s, type ThemePreset as t, type ThemePresetColors as u, createKernel as v, index as w, ansi256Plugin as x, baseColorsPlugin as y, boxPlugin as z };
|