@oxog/pigment 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1 @@
1
- export { y as ansi256Plugin, w as baseColorsPlugin, J as boxPlugin, D as environmentPlugin, F as gradientPlugin, x as modifiersPlugin, A as nestingPlugin, M as pigmentPlugin, I as semanticPlugin, L as templatePlugin, H as themePlugin, z as trueColorPlugin } from '../index-C_LwyWae.cjs';
2
- import '@oxog/types';
3
- import '@oxog/plugin';
1
+ export { x as ansi256Plugin, y as baseColorsPlugin, z as boxPlugin, A as environmentPlugin, D as gradientPlugin, F as modifiersPlugin, H as nestingPlugin, I as pigmentPlugin, J as semanticPlugin, L as templatePlugin, N as themePlugin, O as trueColorPlugin } from '../index-DsggPsSl.cjs';
@@ -1,3 +1 @@
1
- export { y as ansi256Plugin, w as baseColorsPlugin, J as boxPlugin, D as environmentPlugin, F as gradientPlugin, x as modifiersPlugin, A as nestingPlugin, M as pigmentPlugin, I as semanticPlugin, L as templatePlugin, H as themePlugin, z as trueColorPlugin } from '../index-C_LwyWae.js';
2
- import '@oxog/types';
3
- import '@oxog/plugin';
1
+ export { x as ansi256Plugin, y as baseColorsPlugin, z as boxPlugin, A as environmentPlugin, D as gradientPlugin, F as modifiersPlugin, H as nestingPlugin, I as pigmentPlugin, J as semanticPlugin, L as templatePlugin, N as themePlugin, O as trueColorPlugin } from '../index-DsggPsSl.js';
@@ -352,11 +352,11 @@ function trueColorPlugin() {
352
352
  k.emit("color:rgb", { ...rgb, background });
353
353
  });
354
354
  k.on("color:hsl", (data) => {
355
- const { h: h2, s, l, background } = data;
355
+ const { h: h2, s, l: l2, background } = data;
356
356
  if (!utils?.hslToRgb) {
357
357
  throw new Error("hslToRgb utility not available");
358
358
  }
359
- const rgb = utils.hslToRgb(h2, s, l);
359
+ const rgb = utils.hslToRgb(h2, s, l2);
360
360
  k.emit("color:rgb", { ...rgb, background });
361
361
  });
362
362
  }
@@ -547,10 +547,10 @@ function parseExpandedHex(hex) {
547
547
  }
548
548
 
549
549
  // src/utils/hsl-to-rgb.ts
550
- function hslToRgb(h2, s, l) {
550
+ function hslToRgb(h2, s, l2) {
551
551
  const hNormalized = h2 / 360;
552
552
  const sNormalized = s / 100;
553
- const lNormalized = l / 100;
553
+ const lNormalized = l2 / 100;
554
554
  let r;
555
555
  let g;
556
556
  let b;
@@ -757,6 +757,9 @@ var PLUGIN_API_PROVIDERS = {
757
757
  box: "boxPlugin",
758
758
  template: "templatePlugin"
759
759
  };
760
+ function isPluginApiName(name) {
761
+ return Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, name);
762
+ }
760
763
  function registerPluginApi(kernel, name, value) {
761
764
  let api = apis.get(kernel);
762
765
  if (!api) {
@@ -1076,7 +1079,7 @@ function boxPlugin(options) {
1076
1079
  throw new StyleError(`Unknown box border: ${String(boxBorder)}`);
1077
1080
  }
1078
1081
  const lines = text.split("\n");
1079
- const width = Math.max(...lines.map((l) => l.length)) + boxPadding * 2;
1082
+ const width = Math.max(...lines.map((l2) => l2.length)) + boxPadding * 2;
1080
1083
  const pad = " ".repeat(boxPadding);
1081
1084
  const top = `${chars.tl}${chars.h.repeat(width)}${chars.tr}`;
1082
1085
  const middle = lines.map((line) => {
@@ -1149,13 +1152,13 @@ function createProxyPigment(kernel, styles = []) {
1149
1152
  };
1150
1153
  }
1151
1154
  if (prop === "hsl" || prop === "bgHsl") {
1152
- return (h2, s, l) => {
1155
+ return (h2, s, l2) => {
1153
1156
  const background = prop === "bgHsl";
1154
1157
  const hslToRgb2 = ctx.utils?.hslToRgb;
1155
1158
  if (!hslToRgb2) {
1156
1159
  throw new Error("hslToRgb utility not available");
1157
1160
  }
1158
- const { r, g, b } = hslToRgb2(h2, s, l);
1161
+ const { r, g, b } = hslToRgb2(h2, s, l2);
1159
1162
  const rgbStyle = generateRgbCodeForLevel(r, g, b, background, ctx.level);
1160
1163
  return createProxyPigment(kernel, [...styles, rgbStyle]);
1161
1164
  };
@@ -1171,7 +1174,7 @@ function createProxyPigment(kernel, styles = []) {
1171
1174
  return getRoot(kernel) ?? createProxyPigment(kernel);
1172
1175
  };
1173
1176
  }
1174
- if (Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, prop)) {
1177
+ if (isPluginApiName(prop)) {
1175
1178
  return getPluginApi(kernel, prop) ?? missingPluginApi(prop);
1176
1179
  }
1177
1180
  return Reflect.get(target, prop);
@@ -1207,7 +1210,7 @@ var TOKEN = /\uE000(\d+)\uE001/g;
1207
1210
  function renderTemplate(root, strings, values) {
1208
1211
  const parts = values.map((value) => String(value));
1209
1212
  const token = (index) => `\uE000${index}\uE001`;
1210
- const restore = (text) => text.replace(TOKEN, (_match, index) => parts[Number(index)]);
1213
+ const restore = (text) => text.replace(TOKEN, (_match, index) => String(parts[Number(index)]));
1211
1214
  let source = "";
1212
1215
  for (let i = 0; i < strings.length; i++) {
1213
1216
  source += strings[i];
@@ -1290,9 +1293,27 @@ function parseStyleExpression(expression, text, kernel) {
1290
1293
  return text;
1291
1294
  }
1292
1295
 
1296
+ // node_modules/@oxog/types/dist/index.js
1297
+ var U = ((o) => (o.UNKNOWN = "UNKNOWN", o.VALIDATION_ERROR = "VALIDATION_ERROR", o.PLUGIN_ERROR = "PLUGIN_ERROR", o.NOT_FOUND = "NOT_FOUND", o.TIMEOUT = "TIMEOUT", o.DEPENDENCY_ERROR = "DEPENDENCY_ERROR", o))(U || {});
1298
+ var u = class extends Error {
1299
+ constructor(t, n, s, p) {
1300
+ super(t, p);
1301
+ this.code = n;
1302
+ this.context = s;
1303
+ this.name = "OxogError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
1304
+ }
1305
+ name;
1306
+ };
1307
+ var l = class extends u {
1308
+ constructor(t, n, s, p) {
1309
+ super(t, "PLUGIN_ERROR", { pluginName: n, ...s }, p);
1310
+ this.pluginName = n;
1311
+ this.name = "PluginError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
1312
+ }
1313
+ name;
1314
+ };
1315
+
1293
1316
  // node_modules/@oxog/plugin/dist/index.js
1294
- import { PluginError as PluginError2 } from "@oxog/types";
1295
- import { PluginError as PluginError3 } from "@oxog/types";
1296
1317
  var x = ((i) => (i.Created = "created", i.Initializing = "initializing", i.Ready = "ready", i.Destroying = "destroying", i.Destroyed = "destroyed", i))(x || {});
1297
1318
  var h = class {
1298
1319
  context;
@@ -1321,7 +1342,7 @@ var h = class {
1321
1342
  return n;
1322
1343
  }
1323
1344
  };
1324
- var u = class {
1345
+ var u2 = class {
1325
1346
  handlers = /* @__PURE__ */ new Map();
1326
1347
  wildcardHandlers = new Array();
1327
1348
  patternHandlers = /* @__PURE__ */ new Map();
@@ -1349,8 +1370,8 @@ var u = class {
1349
1370
  off(e, t) {
1350
1371
  let n = String(e), r = this.handlers.get(n);
1351
1372
  if (r) {
1352
- let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l = r.indexOf(o);
1353
- l !== -1 && (r.splice(l, 1), s && a.delete(i));
1373
+ let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l2 = r.indexOf(o);
1374
+ l2 !== -1 && (r.splice(l2, 1), s && a.delete(i));
1354
1375
  }
1355
1376
  }
1356
1377
  emit(e, t) {
@@ -1412,22 +1433,22 @@ var f = class {
1412
1433
  validateSinglePlugin(e) {
1413
1434
  let t = this.graph.get(e);
1414
1435
  if (!t) return;
1415
- for (let r of t) if (!this.graph.has(r)) throw new PluginError2(`Missing dependency: '${r}' required by '${e}'`, e);
1436
+ for (let r of t) if (!this.graph.has(r)) throw new l(`Missing dependency: '${r}' required by '${e}'`, e);
1416
1437
  let n = this.detectCycle();
1417
- if (n && n.includes(e)) throw new PluginError2(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
1438
+ if (n && n.includes(e)) throw new l(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
1418
1439
  }
1419
1440
  resolve() {
1420
1441
  let e = /* @__PURE__ */ new Map(), t = [], n = [], r = /* @__PURE__ */ new Map();
1421
1442
  for (let [s, o] of this.graph) {
1422
- let l = o.filter((p) => this.graph.has(p));
1423
- r.set(s, l);
1443
+ let l2 = o.filter((p) => this.graph.has(p));
1444
+ r.set(s, l2);
1424
1445
  }
1425
- for (let [s, o] of this.graph) for (let l of o) if (!this.graph.has(l)) throw new PluginError2(`Missing dependency: '${l}' required by '${s}'`, s);
1446
+ for (let [s, o] of this.graph) for (let l2 of o) if (!this.graph.has(l2)) throw new l(`Missing dependency: '${l2}' required by '${s}'`, s);
1426
1447
  for (let [s, o] of r) e.set(s, o.length), o.length === 0 && t.push(s);
1427
1448
  let i = /* @__PURE__ */ new Map();
1428
- for (let [s, o] of r) for (let l of o) {
1429
- let p = i.get(l);
1430
- p ? p.push(s) : i.set(l, [s]);
1449
+ for (let [s, o] of r) for (let l2 of o) {
1450
+ let p = i.get(l2);
1451
+ p ? p.push(s) : i.set(l2, [s]);
1431
1452
  }
1432
1453
  let a = 0;
1433
1454
  for (; a < t.length; ) {
@@ -1437,7 +1458,7 @@ var f = class {
1437
1458
  }
1438
1459
  if (n.length !== r.size) {
1439
1460
  let s = this.detectCycle();
1440
- throw new PluginError2(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
1461
+ throw new l(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
1441
1462
  }
1442
1463
  return n;
1443
1464
  }
@@ -1448,12 +1469,12 @@ var f = class {
1448
1469
  r.set(a, 1), s.push(a);
1449
1470
  for (let o of this.graph.get(a)) if (this.graph.has(o)) {
1450
1471
  if (r.get(o) === 1) {
1451
- let l = s.indexOf(o);
1452
- return [...s.slice(l), o];
1472
+ let l2 = s.indexOf(o);
1473
+ return [...s.slice(l2), o];
1453
1474
  }
1454
1475
  if (r.get(o) === 0) {
1455
- let l = i(o, s);
1456
- if (l) return l;
1476
+ let l2 = i(o, s);
1477
+ if (l2) return l2;
1457
1478
  }
1458
1479
  }
1459
1480
  return s.pop(), r.set(a, 2), null;
@@ -1526,8 +1547,8 @@ var m = class {
1526
1547
  await r.withBoundary(s, o.plugin, async () => {
1527
1548
  o.plugin.onInit && await o.plugin.onInit(n);
1528
1549
  }), o.state = "ready", o.initializedAt = Date.now(), i?.(s);
1529
- } catch (l) {
1530
- if (a === "fail-fast") throw l;
1550
+ } catch (l2) {
1551
+ if (a === "fail-fast") throw l2;
1531
1552
  o.state = "failed";
1532
1553
  }
1533
1554
  }
@@ -1543,8 +1564,8 @@ var m = class {
1543
1564
  await n.withBoundary(s, o.plugin, async () => {
1544
1565
  o.plugin.onDestroy && await o.plugin.onDestroy();
1545
1566
  });
1546
- } catch (l) {
1547
- if (i === "fail-fast") throw l;
1567
+ } catch (l2) {
1568
+ if (i === "fail-fast") throw l2;
1548
1569
  }
1549
1570
  o.state = "destroyed", r?.(s);
1550
1571
  }
@@ -1565,12 +1586,12 @@ var c = class {
1565
1586
  this.events.emit(e, t);
1566
1587
  }
1567
1588
  constructor(e) {
1568
- 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();
1589
+ this.config = e || {}, this.context = new h(this.config.context ?? {}), this.events = new u2(), this.resolver = new f(), this.errorBoundary = new v(this.config.errorStrategy || "isolate", this.config.onError), this.lifecycle = new m();
1569
1590
  }
1570
1591
  use(e) {
1571
- if (this.state === "destroyed") throw new PluginError2("Cannot add plugins to destroyed kernel", "kernel");
1572
- if (this.state === "initializing") throw new PluginError2("Cannot add plugins while kernel is initializing. Register all plugins before calling init(), or wait until kernel is ready.", "kernel");
1573
- if (this.plugins.has(e.name)) throw new PluginError2(`Plugin '${e.name}' is already registered`, "kernel");
1592
+ if (this.state === "destroyed") throw new l("Cannot add plugins to destroyed kernel", "kernel");
1593
+ if (this.state === "initializing") throw new l("Cannot add plugins while kernel is initializing. Register all plugins before calling init(), or wait until kernel is ready.", "kernel");
1594
+ if (this.plugins.has(e.name)) throw new l(`Plugin '${e.name}' is already registered`, "kernel");
1574
1595
  let t = { plugin: e, state: "registered" };
1575
1596
  this.plugins.set(e.name, t), this.resolver.addPlugin(e.name, [...e.dependencies || []]);
1576
1597
  try {
@@ -1604,7 +1625,7 @@ var c = class {
1604
1625
  let i = this.plugins.get(r);
1605
1626
  if (!i || i.state !== "ready") {
1606
1627
  t.state = "failed";
1607
- let a = new PluginError2(`Dependency '${r}' is not ready for plugin '${e}'`, e);
1628
+ let a = new l(`Dependency '${r}' is not ready for plugin '${e}'`, e);
1608
1629
  this.emitInternal("plugin:error", { name: e, error: a });
1609
1630
  return;
1610
1631
  }
@@ -1675,7 +1696,7 @@ var c = class {
1675
1696
  }
1676
1697
  }
1677
1698
  async init() {
1678
- if (this.state !== "created") throw new PluginError2("Kernel already initialized", "kernel");
1699
+ if (this.state !== "created") throw new l("Kernel already initialized", "kernel");
1679
1700
  this.state = "initializing";
1680
1701
  try {
1681
1702
  this.config.onBeforeInit && await this.config.onBeforeInit();
@@ -1968,13 +1989,13 @@ var BuilderPigment = class {
1968
1989
  }
1969
1990
  return this;
1970
1991
  }
1971
- hsl(h2, s, l) {
1972
- const { r, g, b } = hslToRgb(h2, s, l);
1992
+ hsl(h2, s, l2) {
1993
+ const { r, g, b } = hslToRgb(h2, s, l2);
1973
1994
  this.styles.push(generateRgbCodeForLevel(r, g, b, false, this.level));
1974
1995
  return this;
1975
1996
  }
1976
- bgHsl(h2, s, l) {
1977
- const { r, g, b } = hslToRgb(h2, s, l);
1997
+ bgHsl(h2, s, l2) {
1998
+ const { r, g, b } = hslToRgb(h2, s, l2);
1978
1999
  this.styles.push(generateRgbCodeForLevel(r, g, b, true, this.level));
1979
2000
  return this;
1980
2001
  }