@oxog/pigment 1.0.2 → 1.1.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/dist/index.cjs CHANGED
@@ -49,7 +49,7 @@ __export(index_exports, {
49
49
  blueBright: () => blueBright,
50
50
  bold: () => bold,
51
51
  compose: () => compose,
52
- createKernel: () => import_plugin2.createKernel,
52
+ createKernel: () => W,
53
53
  createPigment: () => createPigment,
54
54
  cyan: () => cyan,
55
55
  cyanBright: () => cyanBright,
@@ -91,8 +91,464 @@ __export(index_exports, {
91
91
  });
92
92
  module.exports = __toCommonJS(index_exports);
93
93
 
94
- // src/core/factory.ts
95
- var import_plugin = require("@oxog/plugin");
94
+ // node_modules/@oxog/plugin/dist/index.js
95
+ var import_types = require("@oxog/types");
96
+ var import_types2 = require("@oxog/types");
97
+ var x = ((i) => (i.Created = "created", i.Initializing = "initializing", i.Ready = "ready", i.Destroying = "destroying", i.Destroyed = "destroyed", i))(x || {});
98
+ var h = class {
99
+ context;
100
+ constructor(e) {
101
+ this.context = e;
102
+ }
103
+ get() {
104
+ return this.context;
105
+ }
106
+ update(e) {
107
+ this.context = Object.assign(this.context, e);
108
+ }
109
+ deepUpdate(e) {
110
+ let t = this.deepMerge(this.context, e);
111
+ this.context = Object.assign(this.context, t);
112
+ }
113
+ deepMerge(e, t) {
114
+ if (t === null || typeof t != "object") return t;
115
+ if (Array.isArray(t)) return [...t];
116
+ if (e === null || typeof e != "object" || Array.isArray(e)) return { ...t };
117
+ let n = { ...e };
118
+ for (let r of Object.keys(t)) {
119
+ let i = t[r], a = n[r];
120
+ n[r] = this.deepMerge(a, i);
121
+ }
122
+ return n;
123
+ }
124
+ };
125
+ var u = class {
126
+ handlers = /* @__PURE__ */ new Map();
127
+ wildcardHandlers = new Array();
128
+ patternHandlers = /* @__PURE__ */ new Map();
129
+ onceWrappers = /* @__PURE__ */ new Map();
130
+ on(e, t) {
131
+ let n = String(e);
132
+ this.handlers.has(n) || this.handlers.set(n, []);
133
+ let r = this.handlers.get(n), i = t;
134
+ return r.includes(i) || r.push(i), () => {
135
+ let a = this.handlers.get(n);
136
+ if (a) {
137
+ let s = a.indexOf(i);
138
+ s !== -1 && a.splice(s, 1);
139
+ }
140
+ };
141
+ }
142
+ once(e, t) {
143
+ let n = t, r = String(e), i = this.onceWrappers.get(r);
144
+ i || (i = /* @__PURE__ */ new Map(), this.onceWrappers.set(r, i));
145
+ let a = (s) => {
146
+ i.delete(n), this.off(e, a), t(s);
147
+ };
148
+ return i.set(n, a), this.on(e, a);
149
+ }
150
+ off(e, t) {
151
+ let n = String(e), r = this.handlers.get(n);
152
+ if (r) {
153
+ let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l = r.indexOf(o);
154
+ l !== -1 && (r.splice(l, 1), s && a.delete(i));
155
+ }
156
+ }
157
+ emit(e, t) {
158
+ let n = String(e), r = this.handlers.get(n);
159
+ if (r) for (let i of [...r]) try {
160
+ i(t);
161
+ } catch {
162
+ }
163
+ for (let i of [...this.wildcardHandlers]) try {
164
+ i(n, t);
165
+ } catch {
166
+ }
167
+ for (let [i, a] of this.patternHandlers) if (this.matchPattern(i, n)) for (let s of [...a]) try {
168
+ s(n, t);
169
+ } catch {
170
+ }
171
+ }
172
+ onWildcard(e) {
173
+ return this.wildcardHandlers.includes(e) || this.wildcardHandlers.push(e), () => {
174
+ let t = this.wildcardHandlers.indexOf(e);
175
+ t !== -1 && this.wildcardHandlers.splice(t, 1);
176
+ };
177
+ }
178
+ onPattern(e, t) {
179
+ this.patternHandlers.has(e) || this.patternHandlers.set(e, []);
180
+ let n = this.patternHandlers.get(e);
181
+ return n.includes(t) || n.push(t), () => {
182
+ let r = this.patternHandlers.get(e);
183
+ if (r) {
184
+ let i = r.indexOf(t);
185
+ i !== -1 && r.splice(i, 1);
186
+ }
187
+ };
188
+ }
189
+ clear() {
190
+ this.handlers.clear(), this.wildcardHandlers.length = 0, this.patternHandlers.clear(), this.onceWrappers.clear();
191
+ }
192
+ matchPattern(e, t) {
193
+ if (e === "*") return true;
194
+ if (e.endsWith(":*")) {
195
+ let n = e.slice(0, -2);
196
+ return t.startsWith(n + ":");
197
+ }
198
+ return e === t;
199
+ }
200
+ };
201
+ var f = class {
202
+ graph = /* @__PURE__ */ new Map();
203
+ addPlugin(e, t = []) {
204
+ this.graph.set(e, [...t]);
205
+ }
206
+ removePlugin(e) {
207
+ this.graph.delete(e);
208
+ for (let t of this.graph.values()) {
209
+ let n = t.indexOf(e);
210
+ n !== -1 && t.splice(n, 1);
211
+ }
212
+ }
213
+ validateSinglePlugin(e) {
214
+ let t = this.graph.get(e);
215
+ if (!t) return;
216
+ for (let r of t) if (!this.graph.has(r)) throw new import_types.PluginError(`Missing dependency: '${r}' required by '${e}'`, e);
217
+ let n = this.detectCycle();
218
+ if (n && n.includes(e)) throw new import_types.PluginError(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
219
+ }
220
+ resolve() {
221
+ let e = /* @__PURE__ */ new Map(), t = [], n = [], r = /* @__PURE__ */ new Map();
222
+ for (let [s, o] of this.graph) {
223
+ let l = o.filter((p) => this.graph.has(p));
224
+ r.set(s, l);
225
+ }
226
+ for (let [s, o] of this.graph) for (let l of o) if (!this.graph.has(l)) throw new import_types.PluginError(`Missing dependency: '${l}' required by '${s}'`, s);
227
+ for (let [s, o] of r) e.set(s, o.length), o.length === 0 && t.push(s);
228
+ let i = /* @__PURE__ */ new Map();
229
+ for (let [s, o] of r) for (let l of o) {
230
+ let p = i.get(l);
231
+ p ? p.push(s) : i.set(l, [s]);
232
+ }
233
+ let a = 0;
234
+ for (; a < t.length; ) {
235
+ let s = t[a++];
236
+ n.push(s);
237
+ for (let o of i.get(s) ?? []) e.set(o, e.get(o) - 1), e.get(o) === 0 && t.push(o);
238
+ }
239
+ if (n.length !== r.size) {
240
+ let s = this.detectCycle();
241
+ throw new import_types.PluginError(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
242
+ }
243
+ return n;
244
+ }
245
+ detectCycle() {
246
+ let r = /* @__PURE__ */ new Map();
247
+ for (let a of this.graph.keys()) r.set(a, 0);
248
+ let i = (a, s) => {
249
+ r.set(a, 1), s.push(a);
250
+ for (let o of this.graph.get(a)) if (this.graph.has(o)) {
251
+ if (r.get(o) === 1) {
252
+ let l = s.indexOf(o);
253
+ return [...s.slice(l), o];
254
+ }
255
+ if (r.get(o) === 0) {
256
+ let l = i(o, s);
257
+ if (l) return l;
258
+ }
259
+ }
260
+ return s.pop(), r.set(a, 2), null;
261
+ };
262
+ for (let a of this.graph.keys()) if (r.get(a) === 0) {
263
+ let s = i(a, []);
264
+ if (s) return s;
265
+ }
266
+ return null;
267
+ }
268
+ getGraph() {
269
+ let e = {};
270
+ for (let [t, n] of this.graph) e[t] = [...n];
271
+ return e;
272
+ }
273
+ clear() {
274
+ this.graph.clear();
275
+ }
276
+ };
277
+ var v = class {
278
+ strategy;
279
+ globalHandler;
280
+ errors = [];
281
+ constructor(e, t) {
282
+ this.strategy = e, this.globalHandler = t;
283
+ }
284
+ getStrategy() {
285
+ return this.strategy;
286
+ }
287
+ async withBoundary(e, t, n) {
288
+ try {
289
+ return await n();
290
+ } catch (r) {
291
+ let i = r instanceof Error ? r : new Error(String(r));
292
+ throw await this.handleError(e, t, i), i;
293
+ }
294
+ }
295
+ async handleError(e, t, n) {
296
+ if (t.onError) try {
297
+ t.onError(n);
298
+ } catch {
299
+ }
300
+ if (this.globalHandler) try {
301
+ this.globalHandler(n, e);
302
+ } catch {
303
+ }
304
+ this.strategy === "collect" && this.errors.push(n);
305
+ }
306
+ throwIfErrors() {
307
+ if (this.strategy === "collect" && this.errors.length > 0) {
308
+ let e = new AggregateError(this.errors, `${this.errors.length} plugin error(s) occurred`);
309
+ throw this.clearErrors(), e;
310
+ }
311
+ }
312
+ clearErrors() {
313
+ this.errors = [];
314
+ }
315
+ getErrors() {
316
+ return Object.freeze([...this.errors]);
317
+ }
318
+ };
319
+ var m = class {
320
+ async initialize(e, t, n, r, i) {
321
+ let a = r.getStrategy();
322
+ for (let s of t) {
323
+ let o = e.get(s);
324
+ if (o && o.state !== "ready") {
325
+ o.state = "initializing";
326
+ try {
327
+ await r.withBoundary(s, o.plugin, async () => {
328
+ o.plugin.onInit && await o.plugin.onInit(n);
329
+ }), o.state = "ready", o.initializedAt = Date.now(), i?.(s);
330
+ } catch (l) {
331
+ if (a === "fail-fast") throw l;
332
+ o.state = "failed";
333
+ }
334
+ }
335
+ }
336
+ }
337
+ async destroy(e, t, n, r) {
338
+ let i = n.getStrategy(), a = [...t].reverse();
339
+ for (let s of a) {
340
+ let o = e.get(s);
341
+ if (o) {
342
+ o.state = "destroying";
343
+ try {
344
+ await n.withBoundary(s, o.plugin, async () => {
345
+ o.plugin.onDestroy && await o.plugin.onDestroy();
346
+ });
347
+ } catch (l) {
348
+ if (i === "fail-fast") throw l;
349
+ }
350
+ o.state = "destroyed", r?.(s);
351
+ }
352
+ }
353
+ }
354
+ };
355
+ var c = class {
356
+ state = "created";
357
+ plugins = /* @__PURE__ */ new Map();
358
+ context;
359
+ events;
360
+ resolver;
361
+ errorBoundary;
362
+ lifecycle;
363
+ config;
364
+ pendingInits = /* @__PURE__ */ new Map();
365
+ emitInternal(e, t) {
366
+ this.events.emit(e, t);
367
+ }
368
+ constructor(e) {
369
+ this.config = e || {}, this.context = new h(this.config.context ?? {}), this.events = new u(), this.resolver = new f(), this.errorBoundary = new v(this.config.errorStrategy || "isolate", this.config.onError), this.lifecycle = new m();
370
+ }
371
+ use(e) {
372
+ if (this.state === "destroyed") throw new import_types.PluginError("Cannot add plugins to destroyed kernel", "kernel");
373
+ if (this.state === "initializing") throw new import_types.PluginError("Cannot add plugins while kernel is initializing. Register all plugins before calling init(), or wait until kernel is ready.", "kernel");
374
+ if (this.plugins.has(e.name)) throw new import_types.PluginError(`Plugin '${e.name}' is already registered`, "kernel");
375
+ let t = { plugin: e, state: "registered" };
376
+ this.plugins.set(e.name, t), this.resolver.addPlugin(e.name, [...e.dependencies || []]);
377
+ try {
378
+ if (this.state === "ready" && this.resolver.validateSinglePlugin(e.name), e.install(this), this.emitInternal("plugin:install", { name: e.name, version: e.version }), this.state === "ready") {
379
+ let n = this.initializeWithDependencies(e.name);
380
+ this.pendingInits.set(e.name, n), n.finally(() => {
381
+ this.pendingInits.delete(e.name);
382
+ });
383
+ }
384
+ } catch (n) {
385
+ throw this.pendingInits.delete(e.name), this.plugins.delete(e.name), this.resolver.removePlugin(e.name), n;
386
+ }
387
+ return this;
388
+ }
389
+ async waitForPlugin(e) {
390
+ let t = this.pendingInits.get(e);
391
+ t && await t;
392
+ }
393
+ async waitForAll() {
394
+ await Promise.all(this.pendingInits.values());
395
+ }
396
+ async initializeWithDependencies(e) {
397
+ let t = this.plugins.get(e);
398
+ if (!t) return;
399
+ let n = t.plugin.dependencies || [];
400
+ for (let r of n) {
401
+ let i = this.pendingInits.get(r);
402
+ i && await i;
403
+ }
404
+ for (let r of n) {
405
+ let i = this.plugins.get(r);
406
+ if (!i || i.state !== "ready") {
407
+ t.state = "failed";
408
+ let a = new import_types.PluginError(`Dependency '${r}' is not ready for plugin '${e}'`, e);
409
+ this.emitInternal("plugin:error", { name: e, error: a });
410
+ return;
411
+ }
412
+ }
413
+ await this.initializePlugin(e);
414
+ }
415
+ async initializePlugin(e) {
416
+ let t = this.plugins.get(e);
417
+ if (!(!t || t.state !== "registered")) try {
418
+ t.state = "initializing", await this.errorBoundary.withBoundary(e, t.plugin, async () => {
419
+ t.plugin.onInit && await t.plugin.onInit(this.context.get());
420
+ }), t.state = "ready", t.initializedAt = Date.now(), this.emitInternal("plugin:init", { name: e });
421
+ } catch (n) {
422
+ t.state = "failed", this.emitInternal("plugin:error", { name: e, error: n });
423
+ }
424
+ }
425
+ useAll(e) {
426
+ for (let t of e) this.use(t);
427
+ return this;
428
+ }
429
+ unregister(e) {
430
+ let t = this.plugins.get(e);
431
+ if (!t) return false;
432
+ let n = this.pendingInits.get(e);
433
+ return t.state === "initializing" && n ? (n.finally(() => {
434
+ if (t.plugin.onDestroy) return t.plugin.onDestroy();
435
+ }).then(() => this.emitInternal("plugin:destroy", { name: e })).catch(() => {
436
+ }), this.pendingInits.delete(e)) : t.state === "ready" && t.plugin.onDestroy && Promise.resolve().then(() => t.plugin.onDestroy()).then(() => this.emitInternal("plugin:destroy", { name: e })).catch(() => {
437
+ }), this.plugins.delete(e), this.resolver.removePlugin(e), true;
438
+ }
439
+ async unregisterAsync(e) {
440
+ let t = this.plugins.get(e);
441
+ if (!t) return false;
442
+ let n = this.pendingInits.get(e);
443
+ if (t.state === "initializing" && n) {
444
+ try {
445
+ await n;
446
+ } catch {
447
+ }
448
+ this.pendingInits.delete(e);
449
+ }
450
+ if ((t.state === "ready" || t.state === "failed") && t.plugin.onDestroy) try {
451
+ await t.plugin.onDestroy(), this.emitInternal("plugin:destroy", { name: e });
452
+ } catch {
453
+ }
454
+ return this.plugins.delete(e), this.resolver.removePlugin(e), true;
455
+ }
456
+ async replace(e) {
457
+ await this.unregisterAsync(e.name), this.use(e), this.state === "ready" && await this.waitForPlugin(e.name);
458
+ }
459
+ async reload(e) {
460
+ let t = this.plugins.get(e);
461
+ if (!t) return;
462
+ let n = this.errorBoundary.getStrategy();
463
+ if (t.state === "ready") {
464
+ try {
465
+ t.plugin.onDestroy && await this.errorBoundary.withBoundary(e, t.plugin, async () => t.plugin.onDestroy()), this.emitInternal("plugin:destroy", { name: e });
466
+ } catch (r) {
467
+ if (n === "fail-fast") throw r;
468
+ }
469
+ t.state = "registered";
470
+ try {
471
+ t.plugin.onInit && await this.errorBoundary.withBoundary(e, t.plugin, async () => t.plugin.onInit(this.context.get())), t.state = "ready", this.emitInternal("plugin:init", { name: e });
472
+ } catch (r) {
473
+ if (n === "fail-fast") throw r;
474
+ t.state = "failed";
475
+ }
476
+ }
477
+ }
478
+ async init() {
479
+ if (this.state !== "created") throw new import_types.PluginError("Kernel already initialized", "kernel");
480
+ this.state = "initializing";
481
+ try {
482
+ this.config.onBeforeInit && await this.config.onBeforeInit();
483
+ let e = this.resolver.resolve();
484
+ this.emitInternal("kernel:init", { timestamp: Date.now() }), await this.lifecycle.initialize(this.plugins, e, this.context.get(), this.errorBoundary, (t) => this.emitInternal("plugin:init", { name: t })), this.state = "ready", this.emitInternal("kernel:ready", { timestamp: Date.now(), plugins: Array.from(this.plugins.keys()) }), this.config.onAfterInit && await this.config.onAfterInit(), this.errorBoundary.throwIfErrors();
485
+ } catch (e) {
486
+ throw this.state = "created", e;
487
+ }
488
+ }
489
+ async destroy() {
490
+ if (this.state === "destroyed") return;
491
+ this.state = "destroying", this.config.onBeforeDestroy && await this.config.onBeforeDestroy(), this.emitInternal("kernel:destroy", { timestamp: Date.now() }), await Promise.allSettled(this.pendingInits.values());
492
+ let e;
493
+ try {
494
+ e = this.resolver.resolve();
495
+ } catch {
496
+ e = Array.from(this.plugins.keys());
497
+ }
498
+ await this.lifecycle.destroy(this.plugins, e, this.errorBoundary, (t) => this.emitInternal("plugin:destroy", { name: t })), this.state = "destroyed", this.emitInternal("kernel:destroyed", { timestamp: Date.now() }), this.events.clear(), this.config.onAfterDestroy && await this.config.onAfterDestroy();
499
+ }
500
+ isInitialized() {
501
+ return this.state === "ready";
502
+ }
503
+ isDestroyed() {
504
+ return this.state === "destroyed";
505
+ }
506
+ getPlugin(e) {
507
+ return this.plugins.get(e)?.plugin;
508
+ }
509
+ hasPlugin(e) {
510
+ return this.plugins.has(e);
511
+ }
512
+ listPlugins() {
513
+ return Array.from(this.plugins.values()).map((e) => e.plugin);
514
+ }
515
+ getPluginNames() {
516
+ return Array.from(this.plugins.keys());
517
+ }
518
+ getDependencyGraph() {
519
+ return this.resolver.getGraph();
520
+ }
521
+ on(e, t) {
522
+ return this.events.on(e, t);
523
+ }
524
+ once(e, t) {
525
+ return this.events.once(e, t);
526
+ }
527
+ off(e, t) {
528
+ this.events.off(e, t);
529
+ }
530
+ emit(e, t) {
531
+ this.events.emit(e, t);
532
+ }
533
+ onWildcard(e) {
534
+ return this.events.onWildcard(e);
535
+ }
536
+ onPattern(e, t) {
537
+ return this.events.onPattern(e, t);
538
+ }
539
+ getContext() {
540
+ return this.context.get();
541
+ }
542
+ updateContext(e) {
543
+ this.context.update(e);
544
+ }
545
+ deepUpdateContext(e) {
546
+ this.context.deepUpdate(e);
547
+ }
548
+ };
549
+ function W(d) {
550
+ return new c(d);
551
+ }
96
552
 
97
553
  // src/constants.ts
98
554
  var ANSI_MODIFIERS = {
@@ -414,17 +870,17 @@ function createProxyPigment(kernel, styles = []) {
414
870
  if (prop === "supportsColor") {
415
871
  return ctx.colorSupport;
416
872
  }
417
- if (MODIFIER_NAMES.includes(prop)) {
873
+ if (MODIFIER_NAMES.some((name) => name === prop)) {
418
874
  const modifierStyle = generateModifierCode(prop);
419
875
  return createProxyPigment(kernel, [...styles, modifierStyle]);
420
876
  }
421
- if (COLOR_NAMES.includes(prop) || BACKGROUND_COLOR_NAMES.includes(prop)) {
877
+ if (COLOR_NAMES.some((name) => name === prop) || BACKGROUND_COLOR_NAMES.some((name) => name === prop)) {
422
878
  const background = prop.startsWith("bg");
423
879
  const colorName = background ? prop.slice(2) : prop;
424
880
  const colorStyle = generateColorCode(colorName, background);
425
881
  return createProxyPigment(kernel, [...styles, colorStyle]);
426
882
  }
427
- if (EXTENDED_COLOR_METHODS.includes(prop)) {
883
+ if (EXTENDED_COLOR_METHODS.some((name) => name === prop)) {
428
884
  if (prop === "ansi256" || prop === "bgAnsi256") {
429
885
  return (code) => {
430
886
  const background = prop === "bgAnsi256";
@@ -452,13 +908,13 @@ function createProxyPigment(kernel, styles = []) {
452
908
  };
453
909
  }
454
910
  if (prop === "hsl" || prop === "bgHsl") {
455
- return (h, s, l) => {
911
+ return (h2, s, l) => {
456
912
  const background = prop === "bgHsl";
457
913
  const hslToRgb2 = ctx.utils?.hslToRgb;
458
914
  if (!hslToRgb2) {
459
915
  throw new Error("hslToRgb utility not available");
460
916
  }
461
- const { r, g, b } = hslToRgb2(h, s, l);
917
+ const { r, g, b } = hslToRgb2(h2, s, l);
462
918
  const rgbStyle = generateRgbCode(r, g, b, background);
463
919
  return createProxyPigment(kernel, [...styles, rgbStyle]);
464
920
  };
@@ -466,9 +922,9 @@ function createProxyPigment(kernel, styles = []) {
466
922
  }
467
923
  if (prop === "visible") {
468
924
  const colorSupport = ctx.colorSupport;
469
- return (text) => colorSupport.level > 0 ? text : "";
925
+ return (text) => colorSupport.level > 0 ? applyStyles(String(text), styles) : "";
470
926
  }
471
- return target[prop];
927
+ return Reflect.get(target, prop);
472
928
  },
473
929
  apply(_target, _thisArg, argArray) {
474
930
  const text = String(argArray[0] ?? "");
@@ -498,7 +954,7 @@ function applyStyles(text, styles) {
498
954
  function hexToRgb(hex) {
499
955
  const hexString = hex.trim().replace(/^#/, "");
500
956
  if (hexString.length === 3) {
501
- const expanded = hexString.split("").map((c) => c + c).join("");
957
+ const expanded = hexString.split("").map((c2) => c2 + c2).join("");
502
958
  return parseExpandedHex(expanded);
503
959
  }
504
960
  if (hexString.length === 6) {
@@ -525,8 +981,8 @@ function validateHex(hex) {
525
981
  }
526
982
 
527
983
  // src/utils/hsl-to-rgb.ts
528
- function hslToRgb(h, s, l) {
529
- const hNormalized = h / 360;
984
+ function hslToRgb(h2, s, l) {
985
+ const hNormalized = h2 / 360;
530
986
  const sNormalized = s / 100;
531
987
  const lNormalized = l / 100;
532
988
  let r;
@@ -769,13 +1225,13 @@ var BuilderPigment = class {
769
1225
  }
770
1226
  return this;
771
1227
  }
772
- hsl(h, s, l) {
773
- const { r, g, b } = hslToRgb(h, s, l);
1228
+ hsl(h2, s, l) {
1229
+ const { r, g, b } = hslToRgb(h2, s, l);
774
1230
  this.styles.push(generateRgbCode(r, g, b, false));
775
1231
  return this;
776
1232
  }
777
- bgHsl(h, s, l) {
778
- const { r, g, b } = hslToRgb(h, s, l);
1233
+ bgHsl(h2, s, l) {
1234
+ const { r, g, b } = hslToRgb(h2, s, l);
779
1235
  this.styles.push(generateRgbCode(r, g, b, true));
780
1236
  return this;
781
1237
  }
@@ -859,69 +1315,31 @@ function detectColorSupport(overrideLevel) {
859
1315
  };
860
1316
  return cachedColorSupport;
861
1317
  }
862
- if (process.env.NO_COLOR) {
863
- cachedColorSupport = {
864
- level: 0,
865
- hasBasic: false,
866
- has256: false,
867
- has16m: false
868
- };
1318
+ const env = process.env;
1319
+ const forced = parseForceColor(env.FORCE_COLOR);
1320
+ if (forced !== void 0) {
1321
+ cachedColorSupport = toColorSupport(forced);
869
1322
  return cachedColorSupport;
870
1323
  }
871
- if (process.env.FORCE_COLOR) {
872
- const level = parseInt(process.env.FORCE_COLOR, 10);
873
- const clampedLevel = Math.max(0, Math.min(3, level));
874
- cachedColorSupport = {
875
- level: clampedLevel,
876
- hasBasic: clampedLevel >= 1,
877
- has256: clampedLevel >= 2,
878
- has16m: clampedLevel >= 3
879
- };
1324
+ if (env.NO_COLOR) {
1325
+ cachedColorSupport = toColorSupport(0);
880
1326
  return cachedColorSupport;
881
1327
  }
882
- if (!hasTTY() && !process.env.CI) {
883
- cachedColorSupport = {
884
- level: 0,
885
- hasBasic: false,
886
- has256: false,
887
- has16m: false
888
- };
1328
+ if (!hasTTY() && !env.CI || env.TERM === "dumb") {
1329
+ cachedColorSupport = toColorSupport(0);
889
1330
  return cachedColorSupport;
890
1331
  }
891
- const term = process.env.TERM ?? "";
892
- if (term.includes("truecolor") || term.includes("24bit")) {
893
- cachedColorSupport = {
894
- level: 3,
895
- hasBasic: true,
896
- has256: true,
897
- has16m: true
898
- };
1332
+ const term = env.TERM ?? "";
1333
+ const colorTerm = (env.COLORTERM ?? "").toLowerCase();
1334
+ if (colorTerm === "truecolor" || colorTerm === "24bit" || term.includes("truecolor") || term.includes("24bit")) {
1335
+ cachedColorSupport = toColorSupport(3);
899
1336
  return cachedColorSupport;
900
1337
  }
901
1338
  if (term.includes("256color")) {
902
- cachedColorSupport = {
903
- level: 2,
904
- hasBasic: true,
905
- has256: true,
906
- has16m: false
907
- };
1339
+ cachedColorSupport = toColorSupport(2);
908
1340
  return cachedColorSupport;
909
1341
  }
910
- if (process.env.CI) {
911
- cachedColorSupport = {
912
- level: 1,
913
- hasBasic: true,
914
- has256: false,
915
- has16m: false
916
- };
917
- return cachedColorSupport;
918
- }
919
- cachedColorSupport = {
920
- level: 1,
921
- hasBasic: true,
922
- has256: false,
923
- has16m: false
924
- };
1342
+ cachedColorSupport = toColorSupport(1);
925
1343
  return cachedColorSupport;
926
1344
  }
927
1345
  function supportsColor() {
@@ -930,6 +1348,18 @@ function supportsColor() {
930
1348
  function resetColorSupportCache() {
931
1349
  cachedColorSupport = void 0;
932
1350
  }
1351
+ function parseForceColor(value) {
1352
+ if (value === void 0) return void 0;
1353
+ const normalized = value.trim().toLowerCase();
1354
+ if (normalized === "" || normalized === "true") return 1;
1355
+ if (normalized === "false") return 0;
1356
+ const level = Number.parseInt(normalized, 10);
1357
+ if (Number.isNaN(level)) return 1;
1358
+ return Math.max(0, Math.min(3, level));
1359
+ }
1360
+ function toColorSupport(level) {
1361
+ return { level, hasBasic: level >= 1, has256: level >= 2, has16m: level >= 3 };
1362
+ }
933
1363
 
934
1364
  // src/utils/rgb-to-ansi256.ts
935
1365
  function rgbToAnsi256(r, g, b) {
@@ -1057,11 +1487,11 @@ function trueColorPlugin() {
1057
1487
  k.emit("color:rgb", { ...rgb, background });
1058
1488
  });
1059
1489
  k.on("color:hsl", (data) => {
1060
- const { h, s, l, background } = data;
1490
+ const { h: h2, s, l, background } = data;
1061
1491
  if (!utils?.hslToRgb) {
1062
1492
  throw new Error("hslToRgb utility not available");
1063
1493
  }
1064
- const rgb = utils.hslToRgb(h, s, l);
1494
+ const rgb = utils.hslToRgb(h2, s, l);
1065
1495
  k.emit("color:rgb", { ...rgb, background });
1066
1496
  });
1067
1497
  }
@@ -1097,7 +1527,8 @@ function environmentPlugin() {
1097
1527
  k.updateContext({
1098
1528
  environment: {
1099
1529
  isCI: ci,
1100
- noColor: process.env.NO_COLOR !== void 0,
1530
+ // NO_COLOR only counts when non-empty (no-color.org)
1531
+ noColor: Boolean(process.env.NO_COLOR),
1101
1532
  forceColor: process.env.FORCE_COLOR !== void 0,
1102
1533
  term: process.env.TERM ?? ""
1103
1534
  }
@@ -1106,13 +1537,13 @@ function environmentPlugin() {
1106
1537
  k.on("environment:check", () => {
1107
1538
  const ctx = k.getContext();
1108
1539
  const env = ctx.environment;
1540
+ if (env?.forceColor) {
1541
+ const level = parseForceColor(process.env.FORCE_COLOR) ?? 1;
1542
+ return { level, enabled: level > 0 };
1543
+ }
1109
1544
  if (env?.noColor) {
1110
1545
  return { level: 0, enabled: false };
1111
1546
  }
1112
- if (env?.forceColor) {
1113
- const level = parseInt(process.env.FORCE_COLOR ?? "0", 10);
1114
- return { level: Math.max(0, Math.min(3, level)), enabled: true };
1115
- }
1116
1547
  if (ci) {
1117
1548
  return { level: 1, enabled: colorSupport.hasBasic };
1118
1549
  }
@@ -1139,7 +1570,7 @@ function createPigment(options) {
1139
1570
  const noColor = options?.noColor ?? false;
1140
1571
  const forceColor = options?.forceColor ?? false;
1141
1572
  const level = noColor ? 0 : forceColor ? options?.level ?? 3 : colorSupport.level;
1142
- const kernel = (0, import_plugin.createKernel)({
1573
+ const kernel = W({
1143
1574
  context: {
1144
1575
  colorSupport: { ...colorSupport, level },
1145
1576
  level,
@@ -1165,7 +1596,7 @@ function createPigment(options) {
1165
1596
  kernel.use(plugin);
1166
1597
  }
1167
1598
  }
1168
- kernel.init();
1599
+ void kernel.init();
1169
1600
  const pigment2 = createProxyPigment(kernel);
1170
1601
  const builder = new BuilderPigment(kernel);
1171
1602
  Object.defineProperty(pigment2, "builder", { value: builder, enumerable: false });
@@ -1311,8 +1742,9 @@ var Chalk = class {
1311
1742
  reset(text) {
1312
1743
  return this.pigment.reset(text);
1313
1744
  }
1745
+ /** Like chalk: returns the text only when colors are supported, otherwise ''. */
1314
1746
  visible(text) {
1315
- return this.supportsColor.level > 0 ? text : text;
1747
+ return this.supportsColor.level > 0 ? text : "";
1316
1748
  }
1317
1749
  rgb(r, g, b) {
1318
1750
  const coloredPigment = this.pigment.rgb(r, g, b);
@@ -1404,9 +1836,6 @@ function compose(...stylers) {
1404
1836
  };
1405
1837
  }
1406
1838
 
1407
- // src/index.ts
1408
- var import_plugin2 = require("@oxog/plugin");
1409
-
1410
1839
  // src/plugins/index.ts
1411
1840
  var plugins_exports = {};
1412
1841
  __export(plugins_exports, {
@@ -1713,7 +2142,8 @@ function parseStyleExpression(expression, text, kernel) {
1713
2142
  }
1714
2143
  }
1715
2144
  if (typeof current === "function") {
1716
- return current(text);
2145
+ const style = current;
2146
+ return style(text);
1717
2147
  }
1718
2148
  return text;
1719
2149
  }
@@ -1729,7 +2159,7 @@ function pigmentPlugin(options) {
1729
2159
  const k = kernel;
1730
2160
  const themeColors = THEME_PRESETS[theme] ?? THEME_PRESETS.monokai;
1731
2161
  const pigment2 = createPigment({ level });
1732
- k.pigment = pigment2;
2162
+ Object.assign(k, { pigment: pigment2 });
1733
2163
  k.updateContext({
1734
2164
  ecosystem: {
1735
2165
  theme,