@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-ChElNHaA.d.cts → index-CLqJXFfX.d.cts} +8 -0
- package/dist/{index-ChElNHaA.d.ts → index-CLqJXFfX.d.ts} +8 -0
- package/dist/index.cjs +514 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +514 -84
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +511 -79
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +511 -79
- package/dist/plugins/index.js.map +1 -1
- package/package.json +37 -21
package/dist/plugins/index.cjs
CHANGED
|
@@ -382,11 +382,11 @@ function trueColorPlugin() {
|
|
|
382
382
|
k.emit("color:rgb", { ...rgb, background });
|
|
383
383
|
});
|
|
384
384
|
k.on("color:hsl", (data) => {
|
|
385
|
-
const { h, s, l, background } = data;
|
|
385
|
+
const { h: h2, s, l, background } = data;
|
|
386
386
|
if (!utils?.hslToRgb) {
|
|
387
387
|
throw new Error("hslToRgb utility not available");
|
|
388
388
|
}
|
|
389
|
-
const rgb = utils.hslToRgb(
|
|
389
|
+
const rgb = utils.hslToRgb(h2, s, l);
|
|
390
390
|
k.emit("color:rgb", { ...rgb, background });
|
|
391
391
|
});
|
|
392
392
|
}
|
|
@@ -464,71 +464,45 @@ function detectColorSupport(overrideLevel) {
|
|
|
464
464
|
};
|
|
465
465
|
return cachedColorSupport;
|
|
466
466
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
has256: false,
|
|
472
|
-
has16m: false
|
|
473
|
-
};
|
|
467
|
+
const env = process.env;
|
|
468
|
+
const forced = parseForceColor(env.FORCE_COLOR);
|
|
469
|
+
if (forced !== void 0) {
|
|
470
|
+
cachedColorSupport = toColorSupport(forced);
|
|
474
471
|
return cachedColorSupport;
|
|
475
472
|
}
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
const clampedLevel = Math.max(0, Math.min(3, level));
|
|
479
|
-
cachedColorSupport = {
|
|
480
|
-
level: clampedLevel,
|
|
481
|
-
hasBasic: clampedLevel >= 1,
|
|
482
|
-
has256: clampedLevel >= 2,
|
|
483
|
-
has16m: clampedLevel >= 3
|
|
484
|
-
};
|
|
473
|
+
if (env.NO_COLOR) {
|
|
474
|
+
cachedColorSupport = toColorSupport(0);
|
|
485
475
|
return cachedColorSupport;
|
|
486
476
|
}
|
|
487
|
-
if (!hasTTY() && !
|
|
488
|
-
cachedColorSupport =
|
|
489
|
-
level: 0,
|
|
490
|
-
hasBasic: false,
|
|
491
|
-
has256: false,
|
|
492
|
-
has16m: false
|
|
493
|
-
};
|
|
477
|
+
if (!hasTTY() && !env.CI || env.TERM === "dumb") {
|
|
478
|
+
cachedColorSupport = toColorSupport(0);
|
|
494
479
|
return cachedColorSupport;
|
|
495
480
|
}
|
|
496
|
-
const term =
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
hasBasic: true,
|
|
501
|
-
has256: true,
|
|
502
|
-
has16m: true
|
|
503
|
-
};
|
|
481
|
+
const term = env.TERM ?? "";
|
|
482
|
+
const colorTerm = (env.COLORTERM ?? "").toLowerCase();
|
|
483
|
+
if (colorTerm === "truecolor" || colorTerm === "24bit" || term.includes("truecolor") || term.includes("24bit")) {
|
|
484
|
+
cachedColorSupport = toColorSupport(3);
|
|
504
485
|
return cachedColorSupport;
|
|
505
486
|
}
|
|
506
487
|
if (term.includes("256color")) {
|
|
507
|
-
cachedColorSupport =
|
|
508
|
-
level: 2,
|
|
509
|
-
hasBasic: true,
|
|
510
|
-
has256: true,
|
|
511
|
-
has16m: false
|
|
512
|
-
};
|
|
488
|
+
cachedColorSupport = toColorSupport(2);
|
|
513
489
|
return cachedColorSupport;
|
|
514
490
|
}
|
|
515
|
-
|
|
516
|
-
cachedColorSupport = {
|
|
517
|
-
level: 1,
|
|
518
|
-
hasBasic: true,
|
|
519
|
-
has256: false,
|
|
520
|
-
has16m: false
|
|
521
|
-
};
|
|
522
|
-
return cachedColorSupport;
|
|
523
|
-
}
|
|
524
|
-
cachedColorSupport = {
|
|
525
|
-
level: 1,
|
|
526
|
-
hasBasic: true,
|
|
527
|
-
has256: false,
|
|
528
|
-
has16m: false
|
|
529
|
-
};
|
|
491
|
+
cachedColorSupport = toColorSupport(1);
|
|
530
492
|
return cachedColorSupport;
|
|
531
493
|
}
|
|
494
|
+
function parseForceColor(value) {
|
|
495
|
+
if (value === void 0) return void 0;
|
|
496
|
+
const normalized = value.trim().toLowerCase();
|
|
497
|
+
if (normalized === "" || normalized === "true") return 1;
|
|
498
|
+
if (normalized === "false") return 0;
|
|
499
|
+
const level = Number.parseInt(normalized, 10);
|
|
500
|
+
if (Number.isNaN(level)) return 1;
|
|
501
|
+
return Math.max(0, Math.min(3, level));
|
|
502
|
+
}
|
|
503
|
+
function toColorSupport(level) {
|
|
504
|
+
return { level, hasBasic: level >= 1, has256: level >= 2, has16m: level >= 3 };
|
|
505
|
+
}
|
|
532
506
|
|
|
533
507
|
// src/plugins/core/environment.ts
|
|
534
508
|
function environmentPlugin() {
|
|
@@ -543,7 +517,8 @@ function environmentPlugin() {
|
|
|
543
517
|
k.updateContext({
|
|
544
518
|
environment: {
|
|
545
519
|
isCI: ci,
|
|
546
|
-
|
|
520
|
+
// NO_COLOR only counts when non-empty (no-color.org)
|
|
521
|
+
noColor: Boolean(process.env.NO_COLOR),
|
|
547
522
|
forceColor: process.env.FORCE_COLOR !== void 0,
|
|
548
523
|
term: process.env.TERM ?? ""
|
|
549
524
|
}
|
|
@@ -552,13 +527,13 @@ function environmentPlugin() {
|
|
|
552
527
|
k.on("environment:check", () => {
|
|
553
528
|
const ctx = k.getContext();
|
|
554
529
|
const env = ctx.environment;
|
|
530
|
+
if (env?.forceColor) {
|
|
531
|
+
const level = parseForceColor(process.env.FORCE_COLOR) ?? 1;
|
|
532
|
+
return { level, enabled: level > 0 };
|
|
533
|
+
}
|
|
555
534
|
if (env?.noColor) {
|
|
556
535
|
return { level: 0, enabled: false };
|
|
557
536
|
}
|
|
558
|
-
if (env?.forceColor) {
|
|
559
|
-
const level = parseInt(process.env.FORCE_COLOR ?? "0", 10);
|
|
560
|
-
return { level: Math.max(0, Math.min(3, level)), enabled: true };
|
|
561
|
-
}
|
|
562
537
|
if (ci) {
|
|
563
538
|
return { level: 1, enabled: colorSupport.hasBasic };
|
|
564
539
|
}
|
|
@@ -583,7 +558,7 @@ function environmentPlugin() {
|
|
|
583
558
|
function hexToRgb(hex) {
|
|
584
559
|
const hexString = hex.trim().replace(/^#/, "");
|
|
585
560
|
if (hexString.length === 3) {
|
|
586
|
-
const expanded = hexString.split("").map((
|
|
561
|
+
const expanded = hexString.split("").map((c2) => c2 + c2).join("");
|
|
587
562
|
return parseExpandedHex(expanded);
|
|
588
563
|
}
|
|
589
564
|
if (hexString.length === 6) {
|
|
@@ -602,8 +577,8 @@ function parseExpandedHex(hex) {
|
|
|
602
577
|
}
|
|
603
578
|
|
|
604
579
|
// src/utils/hsl-to-rgb.ts
|
|
605
|
-
function hslToRgb(
|
|
606
|
-
const hNormalized =
|
|
580
|
+
function hslToRgb(h2, s, l) {
|
|
581
|
+
const hNormalized = h2 / 360;
|
|
607
582
|
const sNormalized = s / 100;
|
|
608
583
|
const lNormalized = l / 100;
|
|
609
584
|
let r;
|
|
@@ -922,13 +897,470 @@ function parseStyleExpression(expression, text, kernel) {
|
|
|
922
897
|
}
|
|
923
898
|
}
|
|
924
899
|
if (typeof current === "function") {
|
|
925
|
-
|
|
900
|
+
const style = current;
|
|
901
|
+
return style(text);
|
|
926
902
|
}
|
|
927
903
|
return text;
|
|
928
904
|
}
|
|
929
905
|
|
|
930
|
-
//
|
|
931
|
-
var
|
|
906
|
+
// node_modules/@oxog/plugin/dist/index.js
|
|
907
|
+
var import_types = require("@oxog/types");
|
|
908
|
+
var import_types2 = require("@oxog/types");
|
|
909
|
+
var x = ((i) => (i.Created = "created", i.Initializing = "initializing", i.Ready = "ready", i.Destroying = "destroying", i.Destroyed = "destroyed", i))(x || {});
|
|
910
|
+
var h = class {
|
|
911
|
+
context;
|
|
912
|
+
constructor(e) {
|
|
913
|
+
this.context = e;
|
|
914
|
+
}
|
|
915
|
+
get() {
|
|
916
|
+
return this.context;
|
|
917
|
+
}
|
|
918
|
+
update(e) {
|
|
919
|
+
this.context = Object.assign(this.context, e);
|
|
920
|
+
}
|
|
921
|
+
deepUpdate(e) {
|
|
922
|
+
let t = this.deepMerge(this.context, e);
|
|
923
|
+
this.context = Object.assign(this.context, t);
|
|
924
|
+
}
|
|
925
|
+
deepMerge(e, t) {
|
|
926
|
+
if (t === null || typeof t != "object") return t;
|
|
927
|
+
if (Array.isArray(t)) return [...t];
|
|
928
|
+
if (e === null || typeof e != "object" || Array.isArray(e)) return { ...t };
|
|
929
|
+
let n = { ...e };
|
|
930
|
+
for (let r of Object.keys(t)) {
|
|
931
|
+
let i = t[r], a = n[r];
|
|
932
|
+
n[r] = this.deepMerge(a, i);
|
|
933
|
+
}
|
|
934
|
+
return n;
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
var u = class {
|
|
938
|
+
handlers = /* @__PURE__ */ new Map();
|
|
939
|
+
wildcardHandlers = new Array();
|
|
940
|
+
patternHandlers = /* @__PURE__ */ new Map();
|
|
941
|
+
onceWrappers = /* @__PURE__ */ new Map();
|
|
942
|
+
on(e, t) {
|
|
943
|
+
let n = String(e);
|
|
944
|
+
this.handlers.has(n) || this.handlers.set(n, []);
|
|
945
|
+
let r = this.handlers.get(n), i = t;
|
|
946
|
+
return r.includes(i) || r.push(i), () => {
|
|
947
|
+
let a = this.handlers.get(n);
|
|
948
|
+
if (a) {
|
|
949
|
+
let s = a.indexOf(i);
|
|
950
|
+
s !== -1 && a.splice(s, 1);
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
once(e, t) {
|
|
955
|
+
let n = t, r = String(e), i = this.onceWrappers.get(r);
|
|
956
|
+
i || (i = /* @__PURE__ */ new Map(), this.onceWrappers.set(r, i));
|
|
957
|
+
let a = (s) => {
|
|
958
|
+
i.delete(n), this.off(e, a), t(s);
|
|
959
|
+
};
|
|
960
|
+
return i.set(n, a), this.on(e, a);
|
|
961
|
+
}
|
|
962
|
+
off(e, t) {
|
|
963
|
+
let n = String(e), r = this.handlers.get(n);
|
|
964
|
+
if (r) {
|
|
965
|
+
let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l = r.indexOf(o);
|
|
966
|
+
l !== -1 && (r.splice(l, 1), s && a.delete(i));
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
emit(e, t) {
|
|
970
|
+
let n = String(e), r = this.handlers.get(n);
|
|
971
|
+
if (r) for (let i of [...r]) try {
|
|
972
|
+
i(t);
|
|
973
|
+
} catch {
|
|
974
|
+
}
|
|
975
|
+
for (let i of [...this.wildcardHandlers]) try {
|
|
976
|
+
i(n, t);
|
|
977
|
+
} catch {
|
|
978
|
+
}
|
|
979
|
+
for (let [i, a] of this.patternHandlers) if (this.matchPattern(i, n)) for (let s of [...a]) try {
|
|
980
|
+
s(n, t);
|
|
981
|
+
} catch {
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
onWildcard(e) {
|
|
985
|
+
return this.wildcardHandlers.includes(e) || this.wildcardHandlers.push(e), () => {
|
|
986
|
+
let t = this.wildcardHandlers.indexOf(e);
|
|
987
|
+
t !== -1 && this.wildcardHandlers.splice(t, 1);
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
onPattern(e, t) {
|
|
991
|
+
this.patternHandlers.has(e) || this.patternHandlers.set(e, []);
|
|
992
|
+
let n = this.patternHandlers.get(e);
|
|
993
|
+
return n.includes(t) || n.push(t), () => {
|
|
994
|
+
let r = this.patternHandlers.get(e);
|
|
995
|
+
if (r) {
|
|
996
|
+
let i = r.indexOf(t);
|
|
997
|
+
i !== -1 && r.splice(i, 1);
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
clear() {
|
|
1002
|
+
this.handlers.clear(), this.wildcardHandlers.length = 0, this.patternHandlers.clear(), this.onceWrappers.clear();
|
|
1003
|
+
}
|
|
1004
|
+
matchPattern(e, t) {
|
|
1005
|
+
if (e === "*") return true;
|
|
1006
|
+
if (e.endsWith(":*")) {
|
|
1007
|
+
let n = e.slice(0, -2);
|
|
1008
|
+
return t.startsWith(n + ":");
|
|
1009
|
+
}
|
|
1010
|
+
return e === t;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
var f = class {
|
|
1014
|
+
graph = /* @__PURE__ */ new Map();
|
|
1015
|
+
addPlugin(e, t = []) {
|
|
1016
|
+
this.graph.set(e, [...t]);
|
|
1017
|
+
}
|
|
1018
|
+
removePlugin(e) {
|
|
1019
|
+
this.graph.delete(e);
|
|
1020
|
+
for (let t of this.graph.values()) {
|
|
1021
|
+
let n = t.indexOf(e);
|
|
1022
|
+
n !== -1 && t.splice(n, 1);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
validateSinglePlugin(e) {
|
|
1026
|
+
let t = this.graph.get(e);
|
|
1027
|
+
if (!t) return;
|
|
1028
|
+
for (let r of t) if (!this.graph.has(r)) throw new import_types.PluginError(`Missing dependency: '${r}' required by '${e}'`, e);
|
|
1029
|
+
let n = this.detectCycle();
|
|
1030
|
+
if (n && n.includes(e)) throw new import_types.PluginError(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
|
|
1031
|
+
}
|
|
1032
|
+
resolve() {
|
|
1033
|
+
let e = /* @__PURE__ */ new Map(), t = [], n = [], r = /* @__PURE__ */ new Map();
|
|
1034
|
+
for (let [s, o] of this.graph) {
|
|
1035
|
+
let l = o.filter((p) => this.graph.has(p));
|
|
1036
|
+
r.set(s, l);
|
|
1037
|
+
}
|
|
1038
|
+
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);
|
|
1039
|
+
for (let [s, o] of r) e.set(s, o.length), o.length === 0 && t.push(s);
|
|
1040
|
+
let i = /* @__PURE__ */ new Map();
|
|
1041
|
+
for (let [s, o] of r) for (let l of o) {
|
|
1042
|
+
let p = i.get(l);
|
|
1043
|
+
p ? p.push(s) : i.set(l, [s]);
|
|
1044
|
+
}
|
|
1045
|
+
let a = 0;
|
|
1046
|
+
for (; a < t.length; ) {
|
|
1047
|
+
let s = t[a++];
|
|
1048
|
+
n.push(s);
|
|
1049
|
+
for (let o of i.get(s) ?? []) e.set(o, e.get(o) - 1), e.get(o) === 0 && t.push(o);
|
|
1050
|
+
}
|
|
1051
|
+
if (n.length !== r.size) {
|
|
1052
|
+
let s = this.detectCycle();
|
|
1053
|
+
throw new import_types.PluginError(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
|
|
1054
|
+
}
|
|
1055
|
+
return n;
|
|
1056
|
+
}
|
|
1057
|
+
detectCycle() {
|
|
1058
|
+
let r = /* @__PURE__ */ new Map();
|
|
1059
|
+
for (let a of this.graph.keys()) r.set(a, 0);
|
|
1060
|
+
let i = (a, s) => {
|
|
1061
|
+
r.set(a, 1), s.push(a);
|
|
1062
|
+
for (let o of this.graph.get(a)) if (this.graph.has(o)) {
|
|
1063
|
+
if (r.get(o) === 1) {
|
|
1064
|
+
let l = s.indexOf(o);
|
|
1065
|
+
return [...s.slice(l), o];
|
|
1066
|
+
}
|
|
1067
|
+
if (r.get(o) === 0) {
|
|
1068
|
+
let l = i(o, s);
|
|
1069
|
+
if (l) return l;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
return s.pop(), r.set(a, 2), null;
|
|
1073
|
+
};
|
|
1074
|
+
for (let a of this.graph.keys()) if (r.get(a) === 0) {
|
|
1075
|
+
let s = i(a, []);
|
|
1076
|
+
if (s) return s;
|
|
1077
|
+
}
|
|
1078
|
+
return null;
|
|
1079
|
+
}
|
|
1080
|
+
getGraph() {
|
|
1081
|
+
let e = {};
|
|
1082
|
+
for (let [t, n] of this.graph) e[t] = [...n];
|
|
1083
|
+
return e;
|
|
1084
|
+
}
|
|
1085
|
+
clear() {
|
|
1086
|
+
this.graph.clear();
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
var v = class {
|
|
1090
|
+
strategy;
|
|
1091
|
+
globalHandler;
|
|
1092
|
+
errors = [];
|
|
1093
|
+
constructor(e, t) {
|
|
1094
|
+
this.strategy = e, this.globalHandler = t;
|
|
1095
|
+
}
|
|
1096
|
+
getStrategy() {
|
|
1097
|
+
return this.strategy;
|
|
1098
|
+
}
|
|
1099
|
+
async withBoundary(e, t, n) {
|
|
1100
|
+
try {
|
|
1101
|
+
return await n();
|
|
1102
|
+
} catch (r) {
|
|
1103
|
+
let i = r instanceof Error ? r : new Error(String(r));
|
|
1104
|
+
throw await this.handleError(e, t, i), i;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
async handleError(e, t, n) {
|
|
1108
|
+
if (t.onError) try {
|
|
1109
|
+
t.onError(n);
|
|
1110
|
+
} catch {
|
|
1111
|
+
}
|
|
1112
|
+
if (this.globalHandler) try {
|
|
1113
|
+
this.globalHandler(n, e);
|
|
1114
|
+
} catch {
|
|
1115
|
+
}
|
|
1116
|
+
this.strategy === "collect" && this.errors.push(n);
|
|
1117
|
+
}
|
|
1118
|
+
throwIfErrors() {
|
|
1119
|
+
if (this.strategy === "collect" && this.errors.length > 0) {
|
|
1120
|
+
let e = new AggregateError(this.errors, `${this.errors.length} plugin error(s) occurred`);
|
|
1121
|
+
throw this.clearErrors(), e;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
clearErrors() {
|
|
1125
|
+
this.errors = [];
|
|
1126
|
+
}
|
|
1127
|
+
getErrors() {
|
|
1128
|
+
return Object.freeze([...this.errors]);
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
var m = class {
|
|
1132
|
+
async initialize(e, t, n, r, i) {
|
|
1133
|
+
let a = r.getStrategy();
|
|
1134
|
+
for (let s of t) {
|
|
1135
|
+
let o = e.get(s);
|
|
1136
|
+
if (o && o.state !== "ready") {
|
|
1137
|
+
o.state = "initializing";
|
|
1138
|
+
try {
|
|
1139
|
+
await r.withBoundary(s, o.plugin, async () => {
|
|
1140
|
+
o.plugin.onInit && await o.plugin.onInit(n);
|
|
1141
|
+
}), o.state = "ready", o.initializedAt = Date.now(), i?.(s);
|
|
1142
|
+
} catch (l) {
|
|
1143
|
+
if (a === "fail-fast") throw l;
|
|
1144
|
+
o.state = "failed";
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
async destroy(e, t, n, r) {
|
|
1150
|
+
let i = n.getStrategy(), a = [...t].reverse();
|
|
1151
|
+
for (let s of a) {
|
|
1152
|
+
let o = e.get(s);
|
|
1153
|
+
if (o) {
|
|
1154
|
+
o.state = "destroying";
|
|
1155
|
+
try {
|
|
1156
|
+
await n.withBoundary(s, o.plugin, async () => {
|
|
1157
|
+
o.plugin.onDestroy && await o.plugin.onDestroy();
|
|
1158
|
+
});
|
|
1159
|
+
} catch (l) {
|
|
1160
|
+
if (i === "fail-fast") throw l;
|
|
1161
|
+
}
|
|
1162
|
+
o.state = "destroyed", r?.(s);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
var c = class {
|
|
1168
|
+
state = "created";
|
|
1169
|
+
plugins = /* @__PURE__ */ new Map();
|
|
1170
|
+
context;
|
|
1171
|
+
events;
|
|
1172
|
+
resolver;
|
|
1173
|
+
errorBoundary;
|
|
1174
|
+
lifecycle;
|
|
1175
|
+
config;
|
|
1176
|
+
pendingInits = /* @__PURE__ */ new Map();
|
|
1177
|
+
emitInternal(e, t) {
|
|
1178
|
+
this.events.emit(e, t);
|
|
1179
|
+
}
|
|
1180
|
+
constructor(e) {
|
|
1181
|
+
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();
|
|
1182
|
+
}
|
|
1183
|
+
use(e) {
|
|
1184
|
+
if (this.state === "destroyed") throw new import_types.PluginError("Cannot add plugins to destroyed kernel", "kernel");
|
|
1185
|
+
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");
|
|
1186
|
+
if (this.plugins.has(e.name)) throw new import_types.PluginError(`Plugin '${e.name}' is already registered`, "kernel");
|
|
1187
|
+
let t = { plugin: e, state: "registered" };
|
|
1188
|
+
this.plugins.set(e.name, t), this.resolver.addPlugin(e.name, [...e.dependencies || []]);
|
|
1189
|
+
try {
|
|
1190
|
+
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") {
|
|
1191
|
+
let n = this.initializeWithDependencies(e.name);
|
|
1192
|
+
this.pendingInits.set(e.name, n), n.finally(() => {
|
|
1193
|
+
this.pendingInits.delete(e.name);
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
} catch (n) {
|
|
1197
|
+
throw this.pendingInits.delete(e.name), this.plugins.delete(e.name), this.resolver.removePlugin(e.name), n;
|
|
1198
|
+
}
|
|
1199
|
+
return this;
|
|
1200
|
+
}
|
|
1201
|
+
async waitForPlugin(e) {
|
|
1202
|
+
let t = this.pendingInits.get(e);
|
|
1203
|
+
t && await t;
|
|
1204
|
+
}
|
|
1205
|
+
async waitForAll() {
|
|
1206
|
+
await Promise.all(this.pendingInits.values());
|
|
1207
|
+
}
|
|
1208
|
+
async initializeWithDependencies(e) {
|
|
1209
|
+
let t = this.plugins.get(e);
|
|
1210
|
+
if (!t) return;
|
|
1211
|
+
let n = t.plugin.dependencies || [];
|
|
1212
|
+
for (let r of n) {
|
|
1213
|
+
let i = this.pendingInits.get(r);
|
|
1214
|
+
i && await i;
|
|
1215
|
+
}
|
|
1216
|
+
for (let r of n) {
|
|
1217
|
+
let i = this.plugins.get(r);
|
|
1218
|
+
if (!i || i.state !== "ready") {
|
|
1219
|
+
t.state = "failed";
|
|
1220
|
+
let a = new import_types.PluginError(`Dependency '${r}' is not ready for plugin '${e}'`, e);
|
|
1221
|
+
this.emitInternal("plugin:error", { name: e, error: a });
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
await this.initializePlugin(e);
|
|
1226
|
+
}
|
|
1227
|
+
async initializePlugin(e) {
|
|
1228
|
+
let t = this.plugins.get(e);
|
|
1229
|
+
if (!(!t || t.state !== "registered")) try {
|
|
1230
|
+
t.state = "initializing", await this.errorBoundary.withBoundary(e, t.plugin, async () => {
|
|
1231
|
+
t.plugin.onInit && await t.plugin.onInit(this.context.get());
|
|
1232
|
+
}), t.state = "ready", t.initializedAt = Date.now(), this.emitInternal("plugin:init", { name: e });
|
|
1233
|
+
} catch (n) {
|
|
1234
|
+
t.state = "failed", this.emitInternal("plugin:error", { name: e, error: n });
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
useAll(e) {
|
|
1238
|
+
for (let t of e) this.use(t);
|
|
1239
|
+
return this;
|
|
1240
|
+
}
|
|
1241
|
+
unregister(e) {
|
|
1242
|
+
let t = this.plugins.get(e);
|
|
1243
|
+
if (!t) return false;
|
|
1244
|
+
let n = this.pendingInits.get(e);
|
|
1245
|
+
return t.state === "initializing" && n ? (n.finally(() => {
|
|
1246
|
+
if (t.plugin.onDestroy) return t.plugin.onDestroy();
|
|
1247
|
+
}).then(() => this.emitInternal("plugin:destroy", { name: e })).catch(() => {
|
|
1248
|
+
}), this.pendingInits.delete(e)) : t.state === "ready" && t.plugin.onDestroy && Promise.resolve().then(() => t.plugin.onDestroy()).then(() => this.emitInternal("plugin:destroy", { name: e })).catch(() => {
|
|
1249
|
+
}), this.plugins.delete(e), this.resolver.removePlugin(e), true;
|
|
1250
|
+
}
|
|
1251
|
+
async unregisterAsync(e) {
|
|
1252
|
+
let t = this.plugins.get(e);
|
|
1253
|
+
if (!t) return false;
|
|
1254
|
+
let n = this.pendingInits.get(e);
|
|
1255
|
+
if (t.state === "initializing" && n) {
|
|
1256
|
+
try {
|
|
1257
|
+
await n;
|
|
1258
|
+
} catch {
|
|
1259
|
+
}
|
|
1260
|
+
this.pendingInits.delete(e);
|
|
1261
|
+
}
|
|
1262
|
+
if ((t.state === "ready" || t.state === "failed") && t.plugin.onDestroy) try {
|
|
1263
|
+
await t.plugin.onDestroy(), this.emitInternal("plugin:destroy", { name: e });
|
|
1264
|
+
} catch {
|
|
1265
|
+
}
|
|
1266
|
+
return this.plugins.delete(e), this.resolver.removePlugin(e), true;
|
|
1267
|
+
}
|
|
1268
|
+
async replace(e) {
|
|
1269
|
+
await this.unregisterAsync(e.name), this.use(e), this.state === "ready" && await this.waitForPlugin(e.name);
|
|
1270
|
+
}
|
|
1271
|
+
async reload(e) {
|
|
1272
|
+
let t = this.plugins.get(e);
|
|
1273
|
+
if (!t) return;
|
|
1274
|
+
let n = this.errorBoundary.getStrategy();
|
|
1275
|
+
if (t.state === "ready") {
|
|
1276
|
+
try {
|
|
1277
|
+
t.plugin.onDestroy && await this.errorBoundary.withBoundary(e, t.plugin, async () => t.plugin.onDestroy()), this.emitInternal("plugin:destroy", { name: e });
|
|
1278
|
+
} catch (r) {
|
|
1279
|
+
if (n === "fail-fast") throw r;
|
|
1280
|
+
}
|
|
1281
|
+
t.state = "registered";
|
|
1282
|
+
try {
|
|
1283
|
+
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 });
|
|
1284
|
+
} catch (r) {
|
|
1285
|
+
if (n === "fail-fast") throw r;
|
|
1286
|
+
t.state = "failed";
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
async init() {
|
|
1291
|
+
if (this.state !== "created") throw new import_types.PluginError("Kernel already initialized", "kernel");
|
|
1292
|
+
this.state = "initializing";
|
|
1293
|
+
try {
|
|
1294
|
+
this.config.onBeforeInit && await this.config.onBeforeInit();
|
|
1295
|
+
let e = this.resolver.resolve();
|
|
1296
|
+
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();
|
|
1297
|
+
} catch (e) {
|
|
1298
|
+
throw this.state = "created", e;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
async destroy() {
|
|
1302
|
+
if (this.state === "destroyed") return;
|
|
1303
|
+
this.state = "destroying", this.config.onBeforeDestroy && await this.config.onBeforeDestroy(), this.emitInternal("kernel:destroy", { timestamp: Date.now() }), await Promise.allSettled(this.pendingInits.values());
|
|
1304
|
+
let e;
|
|
1305
|
+
try {
|
|
1306
|
+
e = this.resolver.resolve();
|
|
1307
|
+
} catch {
|
|
1308
|
+
e = Array.from(this.plugins.keys());
|
|
1309
|
+
}
|
|
1310
|
+
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();
|
|
1311
|
+
}
|
|
1312
|
+
isInitialized() {
|
|
1313
|
+
return this.state === "ready";
|
|
1314
|
+
}
|
|
1315
|
+
isDestroyed() {
|
|
1316
|
+
return this.state === "destroyed";
|
|
1317
|
+
}
|
|
1318
|
+
getPlugin(e) {
|
|
1319
|
+
return this.plugins.get(e)?.plugin;
|
|
1320
|
+
}
|
|
1321
|
+
hasPlugin(e) {
|
|
1322
|
+
return this.plugins.has(e);
|
|
1323
|
+
}
|
|
1324
|
+
listPlugins() {
|
|
1325
|
+
return Array.from(this.plugins.values()).map((e) => e.plugin);
|
|
1326
|
+
}
|
|
1327
|
+
getPluginNames() {
|
|
1328
|
+
return Array.from(this.plugins.keys());
|
|
1329
|
+
}
|
|
1330
|
+
getDependencyGraph() {
|
|
1331
|
+
return this.resolver.getGraph();
|
|
1332
|
+
}
|
|
1333
|
+
on(e, t) {
|
|
1334
|
+
return this.events.on(e, t);
|
|
1335
|
+
}
|
|
1336
|
+
once(e, t) {
|
|
1337
|
+
return this.events.once(e, t);
|
|
1338
|
+
}
|
|
1339
|
+
off(e, t) {
|
|
1340
|
+
this.events.off(e, t);
|
|
1341
|
+
}
|
|
1342
|
+
emit(e, t) {
|
|
1343
|
+
this.events.emit(e, t);
|
|
1344
|
+
}
|
|
1345
|
+
onWildcard(e) {
|
|
1346
|
+
return this.events.onWildcard(e);
|
|
1347
|
+
}
|
|
1348
|
+
onPattern(e, t) {
|
|
1349
|
+
return this.events.onPattern(e, t);
|
|
1350
|
+
}
|
|
1351
|
+
getContext() {
|
|
1352
|
+
return this.context.get();
|
|
1353
|
+
}
|
|
1354
|
+
updateContext(e) {
|
|
1355
|
+
this.context.update(e);
|
|
1356
|
+
}
|
|
1357
|
+
deepUpdateContext(e) {
|
|
1358
|
+
this.context.deepUpdate(e);
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
function W(d) {
|
|
1362
|
+
return new c(d);
|
|
1363
|
+
}
|
|
932
1364
|
|
|
933
1365
|
// src/core/ansi.ts
|
|
934
1366
|
function generateModifierCode(name) {
|
|
@@ -1016,17 +1448,17 @@ function createProxyPigment(kernel, styles = []) {
|
|
|
1016
1448
|
if (prop === "supportsColor") {
|
|
1017
1449
|
return ctx.colorSupport;
|
|
1018
1450
|
}
|
|
1019
|
-
if (MODIFIER_NAMES.
|
|
1451
|
+
if (MODIFIER_NAMES.some((name) => name === prop)) {
|
|
1020
1452
|
const modifierStyle = generateModifierCode(prop);
|
|
1021
1453
|
return createProxyPigment(kernel, [...styles, modifierStyle]);
|
|
1022
1454
|
}
|
|
1023
|
-
if (COLOR_NAMES.
|
|
1455
|
+
if (COLOR_NAMES.some((name) => name === prop) || BACKGROUND_COLOR_NAMES.some((name) => name === prop)) {
|
|
1024
1456
|
const background = prop.startsWith("bg");
|
|
1025
1457
|
const colorName = background ? prop.slice(2) : prop;
|
|
1026
1458
|
const colorStyle = generateColorCode(colorName, background);
|
|
1027
1459
|
return createProxyPigment(kernel, [...styles, colorStyle]);
|
|
1028
1460
|
}
|
|
1029
|
-
if (EXTENDED_COLOR_METHODS.
|
|
1461
|
+
if (EXTENDED_COLOR_METHODS.some((name) => name === prop)) {
|
|
1030
1462
|
if (prop === "ansi256" || prop === "bgAnsi256") {
|
|
1031
1463
|
return (code) => {
|
|
1032
1464
|
const background = prop === "bgAnsi256";
|
|
@@ -1054,13 +1486,13 @@ function createProxyPigment(kernel, styles = []) {
|
|
|
1054
1486
|
};
|
|
1055
1487
|
}
|
|
1056
1488
|
if (prop === "hsl" || prop === "bgHsl") {
|
|
1057
|
-
return (
|
|
1489
|
+
return (h2, s, l) => {
|
|
1058
1490
|
const background = prop === "bgHsl";
|
|
1059
1491
|
const hslToRgb2 = ctx.utils?.hslToRgb;
|
|
1060
1492
|
if (!hslToRgb2) {
|
|
1061
1493
|
throw new Error("hslToRgb utility not available");
|
|
1062
1494
|
}
|
|
1063
|
-
const { r, g, b } = hslToRgb2(
|
|
1495
|
+
const { r, g, b } = hslToRgb2(h2, s, l);
|
|
1064
1496
|
const rgbStyle = generateRgbCode(r, g, b, background);
|
|
1065
1497
|
return createProxyPigment(kernel, [...styles, rgbStyle]);
|
|
1066
1498
|
};
|
|
@@ -1068,9 +1500,9 @@ function createProxyPigment(kernel, styles = []) {
|
|
|
1068
1500
|
}
|
|
1069
1501
|
if (prop === "visible") {
|
|
1070
1502
|
const colorSupport = ctx.colorSupport;
|
|
1071
|
-
return (text) => colorSupport.level > 0 ? text : "";
|
|
1503
|
+
return (text) => colorSupport.level > 0 ? applyStyles(String(text), styles) : "";
|
|
1072
1504
|
}
|
|
1073
|
-
return target
|
|
1505
|
+
return Reflect.get(target, prop);
|
|
1074
1506
|
},
|
|
1075
1507
|
apply(_target, _thisArg, argArray) {
|
|
1076
1508
|
const text = String(argArray[0] ?? "");
|
|
@@ -1309,13 +1741,13 @@ var BuilderPigment = class {
|
|
|
1309
1741
|
}
|
|
1310
1742
|
return this;
|
|
1311
1743
|
}
|
|
1312
|
-
hsl(
|
|
1313
|
-
const { r, g, b } = hslToRgb(
|
|
1744
|
+
hsl(h2, s, l) {
|
|
1745
|
+
const { r, g, b } = hslToRgb(h2, s, l);
|
|
1314
1746
|
this.styles.push(generateRgbCode(r, g, b, false));
|
|
1315
1747
|
return this;
|
|
1316
1748
|
}
|
|
1317
|
-
bgHsl(
|
|
1318
|
-
const { r, g, b } = hslToRgb(
|
|
1749
|
+
bgHsl(h2, s, l) {
|
|
1750
|
+
const { r, g, b } = hslToRgb(h2, s, l);
|
|
1319
1751
|
this.styles.push(generateRgbCode(r, g, b, true));
|
|
1320
1752
|
return this;
|
|
1321
1753
|
}
|
|
@@ -1358,7 +1790,7 @@ function createPigment(options) {
|
|
|
1358
1790
|
const noColor = options?.noColor ?? false;
|
|
1359
1791
|
const forceColor = options?.forceColor ?? false;
|
|
1360
1792
|
const level = noColor ? 0 : forceColor ? options?.level ?? 3 : colorSupport.level;
|
|
1361
|
-
const kernel = (
|
|
1793
|
+
const kernel = W({
|
|
1362
1794
|
context: {
|
|
1363
1795
|
colorSupport: { ...colorSupport, level },
|
|
1364
1796
|
level,
|
|
@@ -1384,7 +1816,7 @@ function createPigment(options) {
|
|
|
1384
1816
|
kernel.use(plugin);
|
|
1385
1817
|
}
|
|
1386
1818
|
}
|
|
1387
|
-
kernel.init();
|
|
1819
|
+
void kernel.init();
|
|
1388
1820
|
const pigment = createProxyPigment(kernel);
|
|
1389
1821
|
const builder = new BuilderPigment(kernel);
|
|
1390
1822
|
Object.defineProperty(pigment, "builder", { value: builder, enumerable: false });
|
|
@@ -1404,7 +1836,7 @@ function pigmentPlugin(options) {
|
|
|
1404
1836
|
const k = kernel;
|
|
1405
1837
|
const themeColors = THEME_PRESETS[theme] ?? THEME_PRESETS.monokai;
|
|
1406
1838
|
const pigment = createPigment({ level });
|
|
1407
|
-
k
|
|
1839
|
+
Object.assign(k, { pigment });
|
|
1408
1840
|
k.updateContext({
|
|
1409
1841
|
ecosystem: {
|
|
1410
1842
|
theme,
|