@oxog/pigment 1.0.1 → 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/README.md +4 -1
- package/dist/{index-BE-MUtRO.d.cts → index-CLqJXFfX.d.cts} +16 -2
- package/dist/{index-BE-MUtRO.d.ts → index-CLqJXFfX.d.ts} +16 -2
- package/dist/index.cjs +542 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +541 -100
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +534 -95
- 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 +534 -95
- package/dist/plugins/index.js.map +1 -1
- package/package.json +38 -23
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
|
}
|
|
@@ -405,12 +405,6 @@ function nestingPlugin() {
|
|
|
405
405
|
enabled: true
|
|
406
406
|
}
|
|
407
407
|
});
|
|
408
|
-
k.on("style:nest", (data) => {
|
|
409
|
-
const { innerText, outerStyles } = data;
|
|
410
|
-
const open = outerStyles.join("");
|
|
411
|
-
const close = outerStyles.map(() => "\x1B[0m").join("");
|
|
412
|
-
return `${open}${innerText}${close}`;
|
|
413
|
-
});
|
|
414
408
|
}
|
|
415
409
|
};
|
|
416
410
|
}
|
|
@@ -454,23 +448,14 @@ function detectColorSupport(overrideLevel) {
|
|
|
454
448
|
const platform = detectPlatform();
|
|
455
449
|
if (platform.isBrowser) {
|
|
456
450
|
cachedColorSupport = {
|
|
457
|
-
level:
|
|
451
|
+
level: 1,
|
|
458
452
|
hasBasic: true,
|
|
459
|
-
has256: true,
|
|
460
|
-
has16m: true
|
|
461
|
-
};
|
|
462
|
-
return cachedColorSupport;
|
|
463
|
-
}
|
|
464
|
-
if (!platform.isNode) {
|
|
465
|
-
cachedColorSupport = {
|
|
466
|
-
level: 0,
|
|
467
|
-
hasBasic: false,
|
|
468
453
|
has256: false,
|
|
469
454
|
has16m: false
|
|
470
455
|
};
|
|
471
456
|
return cachedColorSupport;
|
|
472
457
|
}
|
|
473
|
-
if (
|
|
458
|
+
if (!platform.isNode) {
|
|
474
459
|
cachedColorSupport = {
|
|
475
460
|
level: 0,
|
|
476
461
|
hasBasic: false,
|
|
@@ -479,62 +464,45 @@ function detectColorSupport(overrideLevel) {
|
|
|
479
464
|
};
|
|
480
465
|
return cachedColorSupport;
|
|
481
466
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
cachedColorSupport =
|
|
486
|
-
level: clampedLevel,
|
|
487
|
-
hasBasic: clampedLevel >= 1,
|
|
488
|
-
has256: clampedLevel >= 2,
|
|
489
|
-
has16m: clampedLevel >= 3
|
|
490
|
-
};
|
|
467
|
+
const env = process.env;
|
|
468
|
+
const forced = parseForceColor(env.FORCE_COLOR);
|
|
469
|
+
if (forced !== void 0) {
|
|
470
|
+
cachedColorSupport = toColorSupport(forced);
|
|
491
471
|
return cachedColorSupport;
|
|
492
472
|
}
|
|
493
|
-
if (
|
|
494
|
-
cachedColorSupport =
|
|
495
|
-
level: 0,
|
|
496
|
-
hasBasic: false,
|
|
497
|
-
has256: false,
|
|
498
|
-
has16m: false
|
|
499
|
-
};
|
|
473
|
+
if (env.NO_COLOR) {
|
|
474
|
+
cachedColorSupport = toColorSupport(0);
|
|
500
475
|
return cachedColorSupport;
|
|
501
476
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
cachedColorSupport = {
|
|
505
|
-
level: 3,
|
|
506
|
-
hasBasic: true,
|
|
507
|
-
has256: true,
|
|
508
|
-
has16m: true
|
|
509
|
-
};
|
|
477
|
+
if (!hasTTY() && !env.CI || env.TERM === "dumb") {
|
|
478
|
+
cachedColorSupport = toColorSupport(0);
|
|
510
479
|
return cachedColorSupport;
|
|
511
480
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
has256: true,
|
|
517
|
-
has16m: false
|
|
518
|
-
};
|
|
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);
|
|
519
485
|
return cachedColorSupport;
|
|
520
486
|
}
|
|
521
|
-
if (
|
|
522
|
-
cachedColorSupport =
|
|
523
|
-
level: 1,
|
|
524
|
-
hasBasic: true,
|
|
525
|
-
has256: false,
|
|
526
|
-
has16m: false
|
|
527
|
-
};
|
|
487
|
+
if (term.includes("256color")) {
|
|
488
|
+
cachedColorSupport = toColorSupport(2);
|
|
528
489
|
return cachedColorSupport;
|
|
529
490
|
}
|
|
530
|
-
cachedColorSupport =
|
|
531
|
-
level: 1,
|
|
532
|
-
hasBasic: true,
|
|
533
|
-
has256: false,
|
|
534
|
-
has16m: false
|
|
535
|
-
};
|
|
491
|
+
cachedColorSupport = toColorSupport(1);
|
|
536
492
|
return cachedColorSupport;
|
|
537
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
|
+
}
|
|
538
506
|
|
|
539
507
|
// src/plugins/core/environment.ts
|
|
540
508
|
function environmentPlugin() {
|
|
@@ -544,26 +512,28 @@ function environmentPlugin() {
|
|
|
544
512
|
install(kernel) {
|
|
545
513
|
const k = kernel;
|
|
546
514
|
const ci = isCI();
|
|
547
|
-
const
|
|
515
|
+
const existingContext = k.getContext();
|
|
516
|
+
const colorSupport = existingContext.colorSupport ?? detectColorSupport();
|
|
548
517
|
k.updateContext({
|
|
549
518
|
environment: {
|
|
550
519
|
isCI: ci,
|
|
551
|
-
|
|
520
|
+
// NO_COLOR only counts when non-empty (no-color.org)
|
|
521
|
+
noColor: Boolean(process.env.NO_COLOR),
|
|
552
522
|
forceColor: process.env.FORCE_COLOR !== void 0,
|
|
553
523
|
term: process.env.TERM ?? ""
|
|
554
|
-
}
|
|
555
|
-
colorSupport
|
|
524
|
+
}
|
|
525
|
+
// Don't overwrite colorSupport - it was already set in factory with the correct level
|
|
556
526
|
});
|
|
557
527
|
k.on("environment:check", () => {
|
|
558
528
|
const ctx = k.getContext();
|
|
559
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
|
+
}
|
|
560
534
|
if (env?.noColor) {
|
|
561
535
|
return { level: 0, enabled: false };
|
|
562
536
|
}
|
|
563
|
-
if (env?.forceColor) {
|
|
564
|
-
const level = parseInt(process.env.FORCE_COLOR ?? "0", 10);
|
|
565
|
-
return { level: Math.max(0, Math.min(3, level)), enabled: true };
|
|
566
|
-
}
|
|
567
537
|
if (ci) {
|
|
568
538
|
return { level: 1, enabled: colorSupport.hasBasic };
|
|
569
539
|
}
|
|
@@ -588,7 +558,7 @@ function environmentPlugin() {
|
|
|
588
558
|
function hexToRgb(hex) {
|
|
589
559
|
const hexString = hex.trim().replace(/^#/, "");
|
|
590
560
|
if (hexString.length === 3) {
|
|
591
|
-
const expanded = hexString.split("").map((
|
|
561
|
+
const expanded = hexString.split("").map((c2) => c2 + c2).join("");
|
|
592
562
|
return parseExpandedHex(expanded);
|
|
593
563
|
}
|
|
594
564
|
if (hexString.length === 6) {
|
|
@@ -607,8 +577,8 @@ function parseExpandedHex(hex) {
|
|
|
607
577
|
}
|
|
608
578
|
|
|
609
579
|
// src/utils/hsl-to-rgb.ts
|
|
610
|
-
function hslToRgb(
|
|
611
|
-
const hNormalized =
|
|
580
|
+
function hslToRgb(h2, s, l) {
|
|
581
|
+
const hNormalized = h2 / 360;
|
|
612
582
|
const sNormalized = s / 100;
|
|
613
583
|
const lNormalized = l / 100;
|
|
614
584
|
let r;
|
|
@@ -927,13 +897,470 @@ function parseStyleExpression(expression, text, kernel) {
|
|
|
927
897
|
}
|
|
928
898
|
}
|
|
929
899
|
if (typeof current === "function") {
|
|
930
|
-
|
|
900
|
+
const style = current;
|
|
901
|
+
return style(text);
|
|
931
902
|
}
|
|
932
903
|
return text;
|
|
933
904
|
}
|
|
934
905
|
|
|
935
|
-
//
|
|
936
|
-
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
|
+
}
|
|
937
1364
|
|
|
938
1365
|
// src/core/ansi.ts
|
|
939
1366
|
function generateModifierCode(name) {
|
|
@@ -1021,17 +1448,17 @@ function createProxyPigment(kernel, styles = []) {
|
|
|
1021
1448
|
if (prop === "supportsColor") {
|
|
1022
1449
|
return ctx.colorSupport;
|
|
1023
1450
|
}
|
|
1024
|
-
if (MODIFIER_NAMES.
|
|
1451
|
+
if (MODIFIER_NAMES.some((name) => name === prop)) {
|
|
1025
1452
|
const modifierStyle = generateModifierCode(prop);
|
|
1026
1453
|
return createProxyPigment(kernel, [...styles, modifierStyle]);
|
|
1027
1454
|
}
|
|
1028
|
-
if (COLOR_NAMES.
|
|
1455
|
+
if (COLOR_NAMES.some((name) => name === prop) || BACKGROUND_COLOR_NAMES.some((name) => name === prop)) {
|
|
1029
1456
|
const background = prop.startsWith("bg");
|
|
1030
1457
|
const colorName = background ? prop.slice(2) : prop;
|
|
1031
1458
|
const colorStyle = generateColorCode(colorName, background);
|
|
1032
1459
|
return createProxyPigment(kernel, [...styles, colorStyle]);
|
|
1033
1460
|
}
|
|
1034
|
-
if (EXTENDED_COLOR_METHODS.
|
|
1461
|
+
if (EXTENDED_COLOR_METHODS.some((name) => name === prop)) {
|
|
1035
1462
|
if (prop === "ansi256" || prop === "bgAnsi256") {
|
|
1036
1463
|
return (code) => {
|
|
1037
1464
|
const background = prop === "bgAnsi256";
|
|
@@ -1059,13 +1486,13 @@ function createProxyPigment(kernel, styles = []) {
|
|
|
1059
1486
|
};
|
|
1060
1487
|
}
|
|
1061
1488
|
if (prop === "hsl" || prop === "bgHsl") {
|
|
1062
|
-
return (
|
|
1489
|
+
return (h2, s, l) => {
|
|
1063
1490
|
const background = prop === "bgHsl";
|
|
1064
1491
|
const hslToRgb2 = ctx.utils?.hslToRgb;
|
|
1065
1492
|
if (!hslToRgb2) {
|
|
1066
1493
|
throw new Error("hslToRgb utility not available");
|
|
1067
1494
|
}
|
|
1068
|
-
const { r, g, b } = hslToRgb2(
|
|
1495
|
+
const { r, g, b } = hslToRgb2(h2, s, l);
|
|
1069
1496
|
const rgbStyle = generateRgbCode(r, g, b, background);
|
|
1070
1497
|
return createProxyPigment(kernel, [...styles, rgbStyle]);
|
|
1071
1498
|
};
|
|
@@ -1073,9 +1500,9 @@ function createProxyPigment(kernel, styles = []) {
|
|
|
1073
1500
|
}
|
|
1074
1501
|
if (prop === "visible") {
|
|
1075
1502
|
const colorSupport = ctx.colorSupport;
|
|
1076
|
-
return (text) => colorSupport.level > 0 ? text :
|
|
1503
|
+
return (text) => colorSupport.level > 0 ? applyStyles(String(text), styles) : "";
|
|
1077
1504
|
}
|
|
1078
|
-
return target
|
|
1505
|
+
return Reflect.get(target, prop);
|
|
1079
1506
|
},
|
|
1080
1507
|
apply(_target, _thisArg, argArray) {
|
|
1081
1508
|
const text = String(argArray[0] ?? "");
|
|
@@ -1087,12 +1514,18 @@ function createProxyPigment(kernel, styles = []) {
|
|
|
1087
1514
|
return pigment;
|
|
1088
1515
|
}
|
|
1089
1516
|
function applyStyles(text, styles) {
|
|
1090
|
-
if (styles.length === 0) {
|
|
1517
|
+
if (styles.length === 0 || text === "") {
|
|
1091
1518
|
return text;
|
|
1092
1519
|
}
|
|
1093
1520
|
const open = styles.map((style) => style.open).join("");
|
|
1094
1521
|
const close = [...styles].reverse().map((style) => style.close).join("");
|
|
1095
|
-
|
|
1522
|
+
let result = text;
|
|
1523
|
+
for (const style of styles) {
|
|
1524
|
+
if (style.close) {
|
|
1525
|
+
result = result.split(style.close).join(style.close + style.open);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return `${open}${result}${close}`;
|
|
1096
1529
|
}
|
|
1097
1530
|
|
|
1098
1531
|
// src/core/builder.ts
|
|
@@ -1308,23 +1741,29 @@ var BuilderPigment = class {
|
|
|
1308
1741
|
}
|
|
1309
1742
|
return this;
|
|
1310
1743
|
}
|
|
1311
|
-
hsl(
|
|
1312
|
-
const { r, g, b } = hslToRgb(
|
|
1744
|
+
hsl(h2, s, l) {
|
|
1745
|
+
const { r, g, b } = hslToRgb(h2, s, l);
|
|
1313
1746
|
this.styles.push(generateRgbCode(r, g, b, false));
|
|
1314
1747
|
return this;
|
|
1315
1748
|
}
|
|
1316
|
-
bgHsl(
|
|
1317
|
-
const { r, g, b } = hslToRgb(
|
|
1749
|
+
bgHsl(h2, s, l) {
|
|
1750
|
+
const { r, g, b } = hslToRgb(h2, s, l);
|
|
1318
1751
|
this.styles.push(generateRgbCode(r, g, b, true));
|
|
1319
1752
|
return this;
|
|
1320
1753
|
}
|
|
1321
1754
|
paint(text) {
|
|
1322
|
-
if (this.styles.length === 0) {
|
|
1755
|
+
if (this.styles.length === 0 || text === "") {
|
|
1323
1756
|
return text;
|
|
1324
1757
|
}
|
|
1325
1758
|
const open = this.styles.map((style) => style.open).join("");
|
|
1326
1759
|
const close = [...this.styles].reverse().map((style) => style.close).join("");
|
|
1327
|
-
|
|
1760
|
+
let result = text;
|
|
1761
|
+
for (const style of this.styles) {
|
|
1762
|
+
if (style.close) {
|
|
1763
|
+
result = result.split(style.close).join(style.close + style.open);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
return `${open}${result}${close}`;
|
|
1328
1767
|
}
|
|
1329
1768
|
};
|
|
1330
1769
|
|
|
@@ -1351,7 +1790,7 @@ function createPigment(options) {
|
|
|
1351
1790
|
const noColor = options?.noColor ?? false;
|
|
1352
1791
|
const forceColor = options?.forceColor ?? false;
|
|
1353
1792
|
const level = noColor ? 0 : forceColor ? options?.level ?? 3 : colorSupport.level;
|
|
1354
|
-
const kernel = (
|
|
1793
|
+
const kernel = W({
|
|
1355
1794
|
context: {
|
|
1356
1795
|
colorSupport: { ...colorSupport, level },
|
|
1357
1796
|
level,
|
|
@@ -1377,7 +1816,7 @@ function createPigment(options) {
|
|
|
1377
1816
|
kernel.use(plugin);
|
|
1378
1817
|
}
|
|
1379
1818
|
}
|
|
1380
|
-
kernel.init();
|
|
1819
|
+
void kernel.init();
|
|
1381
1820
|
const pigment = createProxyPigment(kernel);
|
|
1382
1821
|
const builder = new BuilderPigment(kernel);
|
|
1383
1822
|
Object.defineProperty(pigment, "builder", { value: builder, enumerable: false });
|
|
@@ -1397,7 +1836,7 @@ function pigmentPlugin(options) {
|
|
|
1397
1836
|
const k = kernel;
|
|
1398
1837
|
const themeColors = THEME_PRESETS[theme] ?? THEME_PRESETS.monokai;
|
|
1399
1838
|
const pigment = createPigment({ level });
|
|
1400
|
-
k
|
|
1839
|
+
Object.assign(k, { pigment });
|
|
1401
1840
|
k.updateContext({
|
|
1402
1841
|
ecosystem: {
|
|
1403
1842
|
theme,
|