@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.
@@ -346,11 +346,11 @@ function trueColorPlugin() {
346
346
  k.emit("color:rgb", { ...rgb, background });
347
347
  });
348
348
  k.on("color:hsl", (data) => {
349
- const { h, s, l, background } = data;
349
+ const { h: h2, s, l, background } = data;
350
350
  if (!utils?.hslToRgb) {
351
351
  throw new Error("hslToRgb utility not available");
352
352
  }
353
- const rgb = utils.hslToRgb(h, s, l);
353
+ const rgb = utils.hslToRgb(h2, s, l);
354
354
  k.emit("color:rgb", { ...rgb, background });
355
355
  });
356
356
  }
@@ -428,71 +428,45 @@ function detectColorSupport(overrideLevel) {
428
428
  };
429
429
  return cachedColorSupport;
430
430
  }
431
- if (process.env.NO_COLOR) {
432
- cachedColorSupport = {
433
- level: 0,
434
- hasBasic: false,
435
- has256: false,
436
- has16m: false
437
- };
431
+ const env = process.env;
432
+ const forced = parseForceColor(env.FORCE_COLOR);
433
+ if (forced !== void 0) {
434
+ cachedColorSupport = toColorSupport(forced);
438
435
  return cachedColorSupport;
439
436
  }
440
- if (process.env.FORCE_COLOR) {
441
- const level = parseInt(process.env.FORCE_COLOR, 10);
442
- const clampedLevel = Math.max(0, Math.min(3, level));
443
- cachedColorSupport = {
444
- level: clampedLevel,
445
- hasBasic: clampedLevel >= 1,
446
- has256: clampedLevel >= 2,
447
- has16m: clampedLevel >= 3
448
- };
437
+ if (env.NO_COLOR) {
438
+ cachedColorSupport = toColorSupport(0);
449
439
  return cachedColorSupport;
450
440
  }
451
- if (!hasTTY() && !process.env.CI) {
452
- cachedColorSupport = {
453
- level: 0,
454
- hasBasic: false,
455
- has256: false,
456
- has16m: false
457
- };
441
+ if (!hasTTY() && !env.CI || env.TERM === "dumb") {
442
+ cachedColorSupport = toColorSupport(0);
458
443
  return cachedColorSupport;
459
444
  }
460
- const term = process.env.TERM ?? "";
461
- if (term.includes("truecolor") || term.includes("24bit")) {
462
- cachedColorSupport = {
463
- level: 3,
464
- hasBasic: true,
465
- has256: true,
466
- has16m: true
467
- };
445
+ const term = env.TERM ?? "";
446
+ const colorTerm = (env.COLORTERM ?? "").toLowerCase();
447
+ if (colorTerm === "truecolor" || colorTerm === "24bit" || term.includes("truecolor") || term.includes("24bit")) {
448
+ cachedColorSupport = toColorSupport(3);
468
449
  return cachedColorSupport;
469
450
  }
470
451
  if (term.includes("256color")) {
471
- cachedColorSupport = {
472
- level: 2,
473
- hasBasic: true,
474
- has256: true,
475
- has16m: false
476
- };
452
+ cachedColorSupport = toColorSupport(2);
477
453
  return cachedColorSupport;
478
454
  }
479
- if (process.env.CI) {
480
- cachedColorSupport = {
481
- level: 1,
482
- hasBasic: true,
483
- has256: false,
484
- has16m: false
485
- };
486
- return cachedColorSupport;
487
- }
488
- cachedColorSupport = {
489
- level: 1,
490
- hasBasic: true,
491
- has256: false,
492
- has16m: false
493
- };
455
+ cachedColorSupport = toColorSupport(1);
494
456
  return cachedColorSupport;
495
457
  }
458
+ function parseForceColor(value) {
459
+ if (value === void 0) return void 0;
460
+ const normalized = value.trim().toLowerCase();
461
+ if (normalized === "" || normalized === "true") return 1;
462
+ if (normalized === "false") return 0;
463
+ const level = Number.parseInt(normalized, 10);
464
+ if (Number.isNaN(level)) return 1;
465
+ return Math.max(0, Math.min(3, level));
466
+ }
467
+ function toColorSupport(level) {
468
+ return { level, hasBasic: level >= 1, has256: level >= 2, has16m: level >= 3 };
469
+ }
496
470
 
497
471
  // src/plugins/core/environment.ts
498
472
  function environmentPlugin() {
@@ -507,7 +481,8 @@ function environmentPlugin() {
507
481
  k.updateContext({
508
482
  environment: {
509
483
  isCI: ci,
510
- noColor: process.env.NO_COLOR !== void 0,
484
+ // NO_COLOR only counts when non-empty (no-color.org)
485
+ noColor: Boolean(process.env.NO_COLOR),
511
486
  forceColor: process.env.FORCE_COLOR !== void 0,
512
487
  term: process.env.TERM ?? ""
513
488
  }
@@ -516,13 +491,13 @@ function environmentPlugin() {
516
491
  k.on("environment:check", () => {
517
492
  const ctx = k.getContext();
518
493
  const env = ctx.environment;
494
+ if (env?.forceColor) {
495
+ const level = parseForceColor(process.env.FORCE_COLOR) ?? 1;
496
+ return { level, enabled: level > 0 };
497
+ }
519
498
  if (env?.noColor) {
520
499
  return { level: 0, enabled: false };
521
500
  }
522
- if (env?.forceColor) {
523
- const level = parseInt(process.env.FORCE_COLOR ?? "0", 10);
524
- return { level: Math.max(0, Math.min(3, level)), enabled: true };
525
- }
526
501
  if (ci) {
527
502
  return { level: 1, enabled: colorSupport.hasBasic };
528
503
  }
@@ -547,7 +522,7 @@ function environmentPlugin() {
547
522
  function hexToRgb(hex) {
548
523
  const hexString = hex.trim().replace(/^#/, "");
549
524
  if (hexString.length === 3) {
550
- const expanded = hexString.split("").map((c) => c + c).join("");
525
+ const expanded = hexString.split("").map((c2) => c2 + c2).join("");
551
526
  return parseExpandedHex(expanded);
552
527
  }
553
528
  if (hexString.length === 6) {
@@ -566,8 +541,8 @@ function parseExpandedHex(hex) {
566
541
  }
567
542
 
568
543
  // src/utils/hsl-to-rgb.ts
569
- function hslToRgb(h, s, l) {
570
- const hNormalized = h / 360;
544
+ function hslToRgb(h2, s, l) {
545
+ const hNormalized = h2 / 360;
571
546
  const sNormalized = s / 100;
572
547
  const lNormalized = l / 100;
573
548
  let r;
@@ -886,13 +861,470 @@ function parseStyleExpression(expression, text, kernel) {
886
861
  }
887
862
  }
888
863
  if (typeof current === "function") {
889
- return current(text);
864
+ const style = current;
865
+ return style(text);
890
866
  }
891
867
  return text;
892
868
  }
893
869
 
894
- // src/core/factory.ts
895
- import { createKernel } from "@oxog/plugin";
870
+ // node_modules/@oxog/plugin/dist/index.js
871
+ import { PluginError } from "@oxog/types";
872
+ import { PluginError as PluginError2 } from "@oxog/types";
873
+ var x = ((i) => (i.Created = "created", i.Initializing = "initializing", i.Ready = "ready", i.Destroying = "destroying", i.Destroyed = "destroyed", i))(x || {});
874
+ var h = class {
875
+ context;
876
+ constructor(e) {
877
+ this.context = e;
878
+ }
879
+ get() {
880
+ return this.context;
881
+ }
882
+ update(e) {
883
+ this.context = Object.assign(this.context, e);
884
+ }
885
+ deepUpdate(e) {
886
+ let t = this.deepMerge(this.context, e);
887
+ this.context = Object.assign(this.context, t);
888
+ }
889
+ deepMerge(e, t) {
890
+ if (t === null || typeof t != "object") return t;
891
+ if (Array.isArray(t)) return [...t];
892
+ if (e === null || typeof e != "object" || Array.isArray(e)) return { ...t };
893
+ let n = { ...e };
894
+ for (let r of Object.keys(t)) {
895
+ let i = t[r], a = n[r];
896
+ n[r] = this.deepMerge(a, i);
897
+ }
898
+ return n;
899
+ }
900
+ };
901
+ var u = class {
902
+ handlers = /* @__PURE__ */ new Map();
903
+ wildcardHandlers = new Array();
904
+ patternHandlers = /* @__PURE__ */ new Map();
905
+ onceWrappers = /* @__PURE__ */ new Map();
906
+ on(e, t) {
907
+ let n = String(e);
908
+ this.handlers.has(n) || this.handlers.set(n, []);
909
+ let r = this.handlers.get(n), i = t;
910
+ return r.includes(i) || r.push(i), () => {
911
+ let a = this.handlers.get(n);
912
+ if (a) {
913
+ let s = a.indexOf(i);
914
+ s !== -1 && a.splice(s, 1);
915
+ }
916
+ };
917
+ }
918
+ once(e, t) {
919
+ let n = t, r = String(e), i = this.onceWrappers.get(r);
920
+ i || (i = /* @__PURE__ */ new Map(), this.onceWrappers.set(r, i));
921
+ let a = (s) => {
922
+ i.delete(n), this.off(e, a), t(s);
923
+ };
924
+ return i.set(n, a), this.on(e, a);
925
+ }
926
+ off(e, t) {
927
+ let n = String(e), r = this.handlers.get(n);
928
+ if (r) {
929
+ let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l = r.indexOf(o);
930
+ l !== -1 && (r.splice(l, 1), s && a.delete(i));
931
+ }
932
+ }
933
+ emit(e, t) {
934
+ let n = String(e), r = this.handlers.get(n);
935
+ if (r) for (let i of [...r]) try {
936
+ i(t);
937
+ } catch {
938
+ }
939
+ for (let i of [...this.wildcardHandlers]) try {
940
+ i(n, t);
941
+ } catch {
942
+ }
943
+ for (let [i, a] of this.patternHandlers) if (this.matchPattern(i, n)) for (let s of [...a]) try {
944
+ s(n, t);
945
+ } catch {
946
+ }
947
+ }
948
+ onWildcard(e) {
949
+ return this.wildcardHandlers.includes(e) || this.wildcardHandlers.push(e), () => {
950
+ let t = this.wildcardHandlers.indexOf(e);
951
+ t !== -1 && this.wildcardHandlers.splice(t, 1);
952
+ };
953
+ }
954
+ onPattern(e, t) {
955
+ this.patternHandlers.has(e) || this.patternHandlers.set(e, []);
956
+ let n = this.patternHandlers.get(e);
957
+ return n.includes(t) || n.push(t), () => {
958
+ let r = this.patternHandlers.get(e);
959
+ if (r) {
960
+ let i = r.indexOf(t);
961
+ i !== -1 && r.splice(i, 1);
962
+ }
963
+ };
964
+ }
965
+ clear() {
966
+ this.handlers.clear(), this.wildcardHandlers.length = 0, this.patternHandlers.clear(), this.onceWrappers.clear();
967
+ }
968
+ matchPattern(e, t) {
969
+ if (e === "*") return true;
970
+ if (e.endsWith(":*")) {
971
+ let n = e.slice(0, -2);
972
+ return t.startsWith(n + ":");
973
+ }
974
+ return e === t;
975
+ }
976
+ };
977
+ var f = class {
978
+ graph = /* @__PURE__ */ new Map();
979
+ addPlugin(e, t = []) {
980
+ this.graph.set(e, [...t]);
981
+ }
982
+ removePlugin(e) {
983
+ this.graph.delete(e);
984
+ for (let t of this.graph.values()) {
985
+ let n = t.indexOf(e);
986
+ n !== -1 && t.splice(n, 1);
987
+ }
988
+ }
989
+ validateSinglePlugin(e) {
990
+ let t = this.graph.get(e);
991
+ if (!t) return;
992
+ for (let r of t) if (!this.graph.has(r)) throw new PluginError(`Missing dependency: '${r}' required by '${e}'`, e);
993
+ let n = this.detectCycle();
994
+ if (n && n.includes(e)) throw new PluginError(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
995
+ }
996
+ resolve() {
997
+ let e = /* @__PURE__ */ new Map(), t = [], n = [], r = /* @__PURE__ */ new Map();
998
+ for (let [s, o] of this.graph) {
999
+ let l = o.filter((p) => this.graph.has(p));
1000
+ r.set(s, l);
1001
+ }
1002
+ for (let [s, o] of this.graph) for (let l of o) if (!this.graph.has(l)) throw new PluginError(`Missing dependency: '${l}' required by '${s}'`, s);
1003
+ for (let [s, o] of r) e.set(s, o.length), o.length === 0 && t.push(s);
1004
+ let i = /* @__PURE__ */ new Map();
1005
+ for (let [s, o] of r) for (let l of o) {
1006
+ let p = i.get(l);
1007
+ p ? p.push(s) : i.set(l, [s]);
1008
+ }
1009
+ let a = 0;
1010
+ for (; a < t.length; ) {
1011
+ let s = t[a++];
1012
+ n.push(s);
1013
+ for (let o of i.get(s) ?? []) e.set(o, e.get(o) - 1), e.get(o) === 0 && t.push(o);
1014
+ }
1015
+ if (n.length !== r.size) {
1016
+ let s = this.detectCycle();
1017
+ throw new PluginError(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
1018
+ }
1019
+ return n;
1020
+ }
1021
+ detectCycle() {
1022
+ let r = /* @__PURE__ */ new Map();
1023
+ for (let a of this.graph.keys()) r.set(a, 0);
1024
+ let i = (a, s) => {
1025
+ r.set(a, 1), s.push(a);
1026
+ for (let o of this.graph.get(a)) if (this.graph.has(o)) {
1027
+ if (r.get(o) === 1) {
1028
+ let l = s.indexOf(o);
1029
+ return [...s.slice(l), o];
1030
+ }
1031
+ if (r.get(o) === 0) {
1032
+ let l = i(o, s);
1033
+ if (l) return l;
1034
+ }
1035
+ }
1036
+ return s.pop(), r.set(a, 2), null;
1037
+ };
1038
+ for (let a of this.graph.keys()) if (r.get(a) === 0) {
1039
+ let s = i(a, []);
1040
+ if (s) return s;
1041
+ }
1042
+ return null;
1043
+ }
1044
+ getGraph() {
1045
+ let e = {};
1046
+ for (let [t, n] of this.graph) e[t] = [...n];
1047
+ return e;
1048
+ }
1049
+ clear() {
1050
+ this.graph.clear();
1051
+ }
1052
+ };
1053
+ var v = class {
1054
+ strategy;
1055
+ globalHandler;
1056
+ errors = [];
1057
+ constructor(e, t) {
1058
+ this.strategy = e, this.globalHandler = t;
1059
+ }
1060
+ getStrategy() {
1061
+ return this.strategy;
1062
+ }
1063
+ async withBoundary(e, t, n) {
1064
+ try {
1065
+ return await n();
1066
+ } catch (r) {
1067
+ let i = r instanceof Error ? r : new Error(String(r));
1068
+ throw await this.handleError(e, t, i), i;
1069
+ }
1070
+ }
1071
+ async handleError(e, t, n) {
1072
+ if (t.onError) try {
1073
+ t.onError(n);
1074
+ } catch {
1075
+ }
1076
+ if (this.globalHandler) try {
1077
+ this.globalHandler(n, e);
1078
+ } catch {
1079
+ }
1080
+ this.strategy === "collect" && this.errors.push(n);
1081
+ }
1082
+ throwIfErrors() {
1083
+ if (this.strategy === "collect" && this.errors.length > 0) {
1084
+ let e = new AggregateError(this.errors, `${this.errors.length} plugin error(s) occurred`);
1085
+ throw this.clearErrors(), e;
1086
+ }
1087
+ }
1088
+ clearErrors() {
1089
+ this.errors = [];
1090
+ }
1091
+ getErrors() {
1092
+ return Object.freeze([...this.errors]);
1093
+ }
1094
+ };
1095
+ var m = class {
1096
+ async initialize(e, t, n, r, i) {
1097
+ let a = r.getStrategy();
1098
+ for (let s of t) {
1099
+ let o = e.get(s);
1100
+ if (o && o.state !== "ready") {
1101
+ o.state = "initializing";
1102
+ try {
1103
+ await r.withBoundary(s, o.plugin, async () => {
1104
+ o.plugin.onInit && await o.plugin.onInit(n);
1105
+ }), o.state = "ready", o.initializedAt = Date.now(), i?.(s);
1106
+ } catch (l) {
1107
+ if (a === "fail-fast") throw l;
1108
+ o.state = "failed";
1109
+ }
1110
+ }
1111
+ }
1112
+ }
1113
+ async destroy(e, t, n, r) {
1114
+ let i = n.getStrategy(), a = [...t].reverse();
1115
+ for (let s of a) {
1116
+ let o = e.get(s);
1117
+ if (o) {
1118
+ o.state = "destroying";
1119
+ try {
1120
+ await n.withBoundary(s, o.plugin, async () => {
1121
+ o.plugin.onDestroy && await o.plugin.onDestroy();
1122
+ });
1123
+ } catch (l) {
1124
+ if (i === "fail-fast") throw l;
1125
+ }
1126
+ o.state = "destroyed", r?.(s);
1127
+ }
1128
+ }
1129
+ }
1130
+ };
1131
+ var c = class {
1132
+ state = "created";
1133
+ plugins = /* @__PURE__ */ new Map();
1134
+ context;
1135
+ events;
1136
+ resolver;
1137
+ errorBoundary;
1138
+ lifecycle;
1139
+ config;
1140
+ pendingInits = /* @__PURE__ */ new Map();
1141
+ emitInternal(e, t) {
1142
+ this.events.emit(e, t);
1143
+ }
1144
+ constructor(e) {
1145
+ 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();
1146
+ }
1147
+ use(e) {
1148
+ if (this.state === "destroyed") throw new PluginError("Cannot add plugins to destroyed kernel", "kernel");
1149
+ if (this.state === "initializing") throw new PluginError("Cannot add plugins while kernel is initializing. Register all plugins before calling init(), or wait until kernel is ready.", "kernel");
1150
+ if (this.plugins.has(e.name)) throw new PluginError(`Plugin '${e.name}' is already registered`, "kernel");
1151
+ let t = { plugin: e, state: "registered" };
1152
+ this.plugins.set(e.name, t), this.resolver.addPlugin(e.name, [...e.dependencies || []]);
1153
+ try {
1154
+ 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") {
1155
+ let n = this.initializeWithDependencies(e.name);
1156
+ this.pendingInits.set(e.name, n), n.finally(() => {
1157
+ this.pendingInits.delete(e.name);
1158
+ });
1159
+ }
1160
+ } catch (n) {
1161
+ throw this.pendingInits.delete(e.name), this.plugins.delete(e.name), this.resolver.removePlugin(e.name), n;
1162
+ }
1163
+ return this;
1164
+ }
1165
+ async waitForPlugin(e) {
1166
+ let t = this.pendingInits.get(e);
1167
+ t && await t;
1168
+ }
1169
+ async waitForAll() {
1170
+ await Promise.all(this.pendingInits.values());
1171
+ }
1172
+ async initializeWithDependencies(e) {
1173
+ let t = this.plugins.get(e);
1174
+ if (!t) return;
1175
+ let n = t.plugin.dependencies || [];
1176
+ for (let r of n) {
1177
+ let i = this.pendingInits.get(r);
1178
+ i && await i;
1179
+ }
1180
+ for (let r of n) {
1181
+ let i = this.plugins.get(r);
1182
+ if (!i || i.state !== "ready") {
1183
+ t.state = "failed";
1184
+ let a = new PluginError(`Dependency '${r}' is not ready for plugin '${e}'`, e);
1185
+ this.emitInternal("plugin:error", { name: e, error: a });
1186
+ return;
1187
+ }
1188
+ }
1189
+ await this.initializePlugin(e);
1190
+ }
1191
+ async initializePlugin(e) {
1192
+ let t = this.plugins.get(e);
1193
+ if (!(!t || t.state !== "registered")) try {
1194
+ t.state = "initializing", await this.errorBoundary.withBoundary(e, t.plugin, async () => {
1195
+ t.plugin.onInit && await t.plugin.onInit(this.context.get());
1196
+ }), t.state = "ready", t.initializedAt = Date.now(), this.emitInternal("plugin:init", { name: e });
1197
+ } catch (n) {
1198
+ t.state = "failed", this.emitInternal("plugin:error", { name: e, error: n });
1199
+ }
1200
+ }
1201
+ useAll(e) {
1202
+ for (let t of e) this.use(t);
1203
+ return this;
1204
+ }
1205
+ unregister(e) {
1206
+ let t = this.plugins.get(e);
1207
+ if (!t) return false;
1208
+ let n = this.pendingInits.get(e);
1209
+ return t.state === "initializing" && n ? (n.finally(() => {
1210
+ if (t.plugin.onDestroy) return t.plugin.onDestroy();
1211
+ }).then(() => this.emitInternal("plugin:destroy", { name: e })).catch(() => {
1212
+ }), this.pendingInits.delete(e)) : t.state === "ready" && t.plugin.onDestroy && Promise.resolve().then(() => t.plugin.onDestroy()).then(() => this.emitInternal("plugin:destroy", { name: e })).catch(() => {
1213
+ }), this.plugins.delete(e), this.resolver.removePlugin(e), true;
1214
+ }
1215
+ async unregisterAsync(e) {
1216
+ let t = this.plugins.get(e);
1217
+ if (!t) return false;
1218
+ let n = this.pendingInits.get(e);
1219
+ if (t.state === "initializing" && n) {
1220
+ try {
1221
+ await n;
1222
+ } catch {
1223
+ }
1224
+ this.pendingInits.delete(e);
1225
+ }
1226
+ if ((t.state === "ready" || t.state === "failed") && t.plugin.onDestroy) try {
1227
+ await t.plugin.onDestroy(), this.emitInternal("plugin:destroy", { name: e });
1228
+ } catch {
1229
+ }
1230
+ return this.plugins.delete(e), this.resolver.removePlugin(e), true;
1231
+ }
1232
+ async replace(e) {
1233
+ await this.unregisterAsync(e.name), this.use(e), this.state === "ready" && await this.waitForPlugin(e.name);
1234
+ }
1235
+ async reload(e) {
1236
+ let t = this.plugins.get(e);
1237
+ if (!t) return;
1238
+ let n = this.errorBoundary.getStrategy();
1239
+ if (t.state === "ready") {
1240
+ try {
1241
+ t.plugin.onDestroy && await this.errorBoundary.withBoundary(e, t.plugin, async () => t.plugin.onDestroy()), this.emitInternal("plugin:destroy", { name: e });
1242
+ } catch (r) {
1243
+ if (n === "fail-fast") throw r;
1244
+ }
1245
+ t.state = "registered";
1246
+ try {
1247
+ 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 });
1248
+ } catch (r) {
1249
+ if (n === "fail-fast") throw r;
1250
+ t.state = "failed";
1251
+ }
1252
+ }
1253
+ }
1254
+ async init() {
1255
+ if (this.state !== "created") throw new PluginError("Kernel already initialized", "kernel");
1256
+ this.state = "initializing";
1257
+ try {
1258
+ this.config.onBeforeInit && await this.config.onBeforeInit();
1259
+ let e = this.resolver.resolve();
1260
+ 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();
1261
+ } catch (e) {
1262
+ throw this.state = "created", e;
1263
+ }
1264
+ }
1265
+ async destroy() {
1266
+ if (this.state === "destroyed") return;
1267
+ this.state = "destroying", this.config.onBeforeDestroy && await this.config.onBeforeDestroy(), this.emitInternal("kernel:destroy", { timestamp: Date.now() }), await Promise.allSettled(this.pendingInits.values());
1268
+ let e;
1269
+ try {
1270
+ e = this.resolver.resolve();
1271
+ } catch {
1272
+ e = Array.from(this.plugins.keys());
1273
+ }
1274
+ 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();
1275
+ }
1276
+ isInitialized() {
1277
+ return this.state === "ready";
1278
+ }
1279
+ isDestroyed() {
1280
+ return this.state === "destroyed";
1281
+ }
1282
+ getPlugin(e) {
1283
+ return this.plugins.get(e)?.plugin;
1284
+ }
1285
+ hasPlugin(e) {
1286
+ return this.plugins.has(e);
1287
+ }
1288
+ listPlugins() {
1289
+ return Array.from(this.plugins.values()).map((e) => e.plugin);
1290
+ }
1291
+ getPluginNames() {
1292
+ return Array.from(this.plugins.keys());
1293
+ }
1294
+ getDependencyGraph() {
1295
+ return this.resolver.getGraph();
1296
+ }
1297
+ on(e, t) {
1298
+ return this.events.on(e, t);
1299
+ }
1300
+ once(e, t) {
1301
+ return this.events.once(e, t);
1302
+ }
1303
+ off(e, t) {
1304
+ this.events.off(e, t);
1305
+ }
1306
+ emit(e, t) {
1307
+ this.events.emit(e, t);
1308
+ }
1309
+ onWildcard(e) {
1310
+ return this.events.onWildcard(e);
1311
+ }
1312
+ onPattern(e, t) {
1313
+ return this.events.onPattern(e, t);
1314
+ }
1315
+ getContext() {
1316
+ return this.context.get();
1317
+ }
1318
+ updateContext(e) {
1319
+ this.context.update(e);
1320
+ }
1321
+ deepUpdateContext(e) {
1322
+ this.context.deepUpdate(e);
1323
+ }
1324
+ };
1325
+ function W(d) {
1326
+ return new c(d);
1327
+ }
896
1328
 
897
1329
  // src/core/ansi.ts
898
1330
  function generateModifierCode(name) {
@@ -980,17 +1412,17 @@ function createProxyPigment(kernel, styles = []) {
980
1412
  if (prop === "supportsColor") {
981
1413
  return ctx.colorSupport;
982
1414
  }
983
- if (MODIFIER_NAMES.includes(prop)) {
1415
+ if (MODIFIER_NAMES.some((name) => name === prop)) {
984
1416
  const modifierStyle = generateModifierCode(prop);
985
1417
  return createProxyPigment(kernel, [...styles, modifierStyle]);
986
1418
  }
987
- if (COLOR_NAMES.includes(prop) || BACKGROUND_COLOR_NAMES.includes(prop)) {
1419
+ if (COLOR_NAMES.some((name) => name === prop) || BACKGROUND_COLOR_NAMES.some((name) => name === prop)) {
988
1420
  const background = prop.startsWith("bg");
989
1421
  const colorName = background ? prop.slice(2) : prop;
990
1422
  const colorStyle = generateColorCode(colorName, background);
991
1423
  return createProxyPigment(kernel, [...styles, colorStyle]);
992
1424
  }
993
- if (EXTENDED_COLOR_METHODS.includes(prop)) {
1425
+ if (EXTENDED_COLOR_METHODS.some((name) => name === prop)) {
994
1426
  if (prop === "ansi256" || prop === "bgAnsi256") {
995
1427
  return (code) => {
996
1428
  const background = prop === "bgAnsi256";
@@ -1018,13 +1450,13 @@ function createProxyPigment(kernel, styles = []) {
1018
1450
  };
1019
1451
  }
1020
1452
  if (prop === "hsl" || prop === "bgHsl") {
1021
- return (h, s, l) => {
1453
+ return (h2, s, l) => {
1022
1454
  const background = prop === "bgHsl";
1023
1455
  const hslToRgb2 = ctx.utils?.hslToRgb;
1024
1456
  if (!hslToRgb2) {
1025
1457
  throw new Error("hslToRgb utility not available");
1026
1458
  }
1027
- const { r, g, b } = hslToRgb2(h, s, l);
1459
+ const { r, g, b } = hslToRgb2(h2, s, l);
1028
1460
  const rgbStyle = generateRgbCode(r, g, b, background);
1029
1461
  return createProxyPigment(kernel, [...styles, rgbStyle]);
1030
1462
  };
@@ -1032,9 +1464,9 @@ function createProxyPigment(kernel, styles = []) {
1032
1464
  }
1033
1465
  if (prop === "visible") {
1034
1466
  const colorSupport = ctx.colorSupport;
1035
- return (text) => colorSupport.level > 0 ? text : "";
1467
+ return (text) => colorSupport.level > 0 ? applyStyles(String(text), styles) : "";
1036
1468
  }
1037
- return target[prop];
1469
+ return Reflect.get(target, prop);
1038
1470
  },
1039
1471
  apply(_target, _thisArg, argArray) {
1040
1472
  const text = String(argArray[0] ?? "");
@@ -1273,13 +1705,13 @@ var BuilderPigment = class {
1273
1705
  }
1274
1706
  return this;
1275
1707
  }
1276
- hsl(h, s, l) {
1277
- const { r, g, b } = hslToRgb(h, s, l);
1708
+ hsl(h2, s, l) {
1709
+ const { r, g, b } = hslToRgb(h2, s, l);
1278
1710
  this.styles.push(generateRgbCode(r, g, b, false));
1279
1711
  return this;
1280
1712
  }
1281
- bgHsl(h, s, l) {
1282
- const { r, g, b } = hslToRgb(h, s, l);
1713
+ bgHsl(h2, s, l) {
1714
+ const { r, g, b } = hslToRgb(h2, s, l);
1283
1715
  this.styles.push(generateRgbCode(r, g, b, true));
1284
1716
  return this;
1285
1717
  }
@@ -1322,7 +1754,7 @@ function createPigment(options) {
1322
1754
  const noColor = options?.noColor ?? false;
1323
1755
  const forceColor = options?.forceColor ?? false;
1324
1756
  const level = noColor ? 0 : forceColor ? options?.level ?? 3 : colorSupport.level;
1325
- const kernel = createKernel({
1757
+ const kernel = W({
1326
1758
  context: {
1327
1759
  colorSupport: { ...colorSupport, level },
1328
1760
  level,
@@ -1348,7 +1780,7 @@ function createPigment(options) {
1348
1780
  kernel.use(plugin);
1349
1781
  }
1350
1782
  }
1351
- kernel.init();
1783
+ void kernel.init();
1352
1784
  const pigment = createProxyPigment(kernel);
1353
1785
  const builder = new BuilderPigment(kernel);
1354
1786
  Object.defineProperty(pigment, "builder", { value: builder, enumerable: false });
@@ -1368,7 +1800,7 @@ function pigmentPlugin(options) {
1368
1800
  const k = kernel;
1369
1801
  const themeColors = THEME_PRESETS[theme] ?? THEME_PRESETS.monokai;
1370
1802
  const pigment = createPigment({ level });
1371
- k.pigment = pigment;
1803
+ Object.assign(k, { pigment });
1372
1804
  k.updateContext({
1373
1805
  ecosystem: {
1374
1806
  theme,