@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.
@@ -388,11 +388,11 @@ function trueColorPlugin() {
388
388
  k.emit("color:rgb", { ...rgb, background });
389
389
  });
390
390
  k.on("color:hsl", (data) => {
391
- const { h: h2, s, l, background } = data;
391
+ const { h: h2, s, l: l2, background } = data;
392
392
  if (!utils?.hslToRgb) {
393
393
  throw new Error("hslToRgb utility not available");
394
394
  }
395
- const rgb = utils.hslToRgb(h2, s, l);
395
+ const rgb = utils.hslToRgb(h2, s, l2);
396
396
  k.emit("color:rgb", { ...rgb, background });
397
397
  });
398
398
  }
@@ -583,10 +583,10 @@ function parseExpandedHex(hex) {
583
583
  }
584
584
 
585
585
  // src/utils/hsl-to-rgb.ts
586
- function hslToRgb(h2, s, l) {
586
+ function hslToRgb(h2, s, l2) {
587
587
  const hNormalized = h2 / 360;
588
588
  const sNormalized = s / 100;
589
- const lNormalized = l / 100;
589
+ const lNormalized = l2 / 100;
590
590
  let r;
591
591
  let g;
592
592
  let b;
@@ -793,6 +793,9 @@ var PLUGIN_API_PROVIDERS = {
793
793
  box: "boxPlugin",
794
794
  template: "templatePlugin"
795
795
  };
796
+ function isPluginApiName(name) {
797
+ return Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, name);
798
+ }
796
799
  function registerPluginApi(kernel, name, value) {
797
800
  let api = apis.get(kernel);
798
801
  if (!api) {
@@ -1112,7 +1115,7 @@ function boxPlugin(options) {
1112
1115
  throw new StyleError(`Unknown box border: ${String(boxBorder)}`);
1113
1116
  }
1114
1117
  const lines = text.split("\n");
1115
- const width = Math.max(...lines.map((l) => l.length)) + boxPadding * 2;
1118
+ const width = Math.max(...lines.map((l2) => l2.length)) + boxPadding * 2;
1116
1119
  const pad = " ".repeat(boxPadding);
1117
1120
  const top = `${chars.tl}${chars.h.repeat(width)}${chars.tr}`;
1118
1121
  const middle = lines.map((line) => {
@@ -1185,13 +1188,13 @@ function createProxyPigment(kernel, styles = []) {
1185
1188
  };
1186
1189
  }
1187
1190
  if (prop === "hsl" || prop === "bgHsl") {
1188
- return (h2, s, l) => {
1191
+ return (h2, s, l2) => {
1189
1192
  const background = prop === "bgHsl";
1190
1193
  const hslToRgb2 = ctx.utils?.hslToRgb;
1191
1194
  if (!hslToRgb2) {
1192
1195
  throw new Error("hslToRgb utility not available");
1193
1196
  }
1194
- const { r, g, b } = hslToRgb2(h2, s, l);
1197
+ const { r, g, b } = hslToRgb2(h2, s, l2);
1195
1198
  const rgbStyle = generateRgbCodeForLevel(r, g, b, background, ctx.level);
1196
1199
  return createProxyPigment(kernel, [...styles, rgbStyle]);
1197
1200
  };
@@ -1207,7 +1210,7 @@ function createProxyPigment(kernel, styles = []) {
1207
1210
  return getRoot(kernel) ?? createProxyPigment(kernel);
1208
1211
  };
1209
1212
  }
1210
- if (Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, prop)) {
1213
+ if (isPluginApiName(prop)) {
1211
1214
  return getPluginApi(kernel, prop) ?? missingPluginApi(prop);
1212
1215
  }
1213
1216
  return Reflect.get(target, prop);
@@ -1243,7 +1246,7 @@ var TOKEN = /\uE000(\d+)\uE001/g;
1243
1246
  function renderTemplate(root, strings, values) {
1244
1247
  const parts = values.map((value) => String(value));
1245
1248
  const token = (index) => `\uE000${index}\uE001`;
1246
- const restore = (text) => text.replace(TOKEN, (_match, index) => parts[Number(index)]);
1249
+ const restore = (text) => text.replace(TOKEN, (_match, index) => String(parts[Number(index)]));
1247
1250
  let source = "";
1248
1251
  for (let i = 0; i < strings.length; i++) {
1249
1252
  source += strings[i];
@@ -1326,9 +1329,27 @@ function parseStyleExpression(expression, text, kernel) {
1326
1329
  return text;
1327
1330
  }
1328
1331
 
1332
+ // node_modules/@oxog/types/dist/index.js
1333
+ 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 || {});
1334
+ var u = class extends Error {
1335
+ constructor(t, n, s, p) {
1336
+ super(t, p);
1337
+ this.code = n;
1338
+ this.context = s;
1339
+ this.name = "OxogError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
1340
+ }
1341
+ name;
1342
+ };
1343
+ var l = class extends u {
1344
+ constructor(t, n, s, p) {
1345
+ super(t, "PLUGIN_ERROR", { pluginName: n, ...s }, p);
1346
+ this.pluginName = n;
1347
+ this.name = "PluginError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
1348
+ }
1349
+ name;
1350
+ };
1351
+
1329
1352
  // node_modules/@oxog/plugin/dist/index.js
1330
- var import_types = require("@oxog/types");
1331
- var import_types2 = require("@oxog/types");
1332
1353
  var x = ((i) => (i.Created = "created", i.Initializing = "initializing", i.Ready = "ready", i.Destroying = "destroying", i.Destroyed = "destroyed", i))(x || {});
1333
1354
  var h = class {
1334
1355
  context;
@@ -1357,7 +1378,7 @@ var h = class {
1357
1378
  return n;
1358
1379
  }
1359
1380
  };
1360
- var u = class {
1381
+ var u2 = class {
1361
1382
  handlers = /* @__PURE__ */ new Map();
1362
1383
  wildcardHandlers = new Array();
1363
1384
  patternHandlers = /* @__PURE__ */ new Map();
@@ -1385,8 +1406,8 @@ var u = class {
1385
1406
  off(e, t) {
1386
1407
  let n = String(e), r = this.handlers.get(n);
1387
1408
  if (r) {
1388
- let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l = r.indexOf(o);
1389
- l !== -1 && (r.splice(l, 1), s && a.delete(i));
1409
+ let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l2 = r.indexOf(o);
1410
+ l2 !== -1 && (r.splice(l2, 1), s && a.delete(i));
1390
1411
  }
1391
1412
  }
1392
1413
  emit(e, t) {
@@ -1448,22 +1469,22 @@ var f = class {
1448
1469
  validateSinglePlugin(e) {
1449
1470
  let t = this.graph.get(e);
1450
1471
  if (!t) return;
1451
- for (let r of t) if (!this.graph.has(r)) throw new import_types.PluginError(`Missing dependency: '${r}' required by '${e}'`, e);
1472
+ for (let r of t) if (!this.graph.has(r)) throw new l(`Missing dependency: '${r}' required by '${e}'`, e);
1452
1473
  let n = this.detectCycle();
1453
- if (n && n.includes(e)) throw new import_types.PluginError(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
1474
+ if (n && n.includes(e)) throw new l(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
1454
1475
  }
1455
1476
  resolve() {
1456
1477
  let e = /* @__PURE__ */ new Map(), t = [], n = [], r = /* @__PURE__ */ new Map();
1457
1478
  for (let [s, o] of this.graph) {
1458
- let l = o.filter((p) => this.graph.has(p));
1459
- r.set(s, l);
1479
+ let l2 = o.filter((p) => this.graph.has(p));
1480
+ r.set(s, l2);
1460
1481
  }
1461
- 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);
1482
+ 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);
1462
1483
  for (let [s, o] of r) e.set(s, o.length), o.length === 0 && t.push(s);
1463
1484
  let i = /* @__PURE__ */ new Map();
1464
- for (let [s, o] of r) for (let l of o) {
1465
- let p = i.get(l);
1466
- p ? p.push(s) : i.set(l, [s]);
1485
+ for (let [s, o] of r) for (let l2 of o) {
1486
+ let p = i.get(l2);
1487
+ p ? p.push(s) : i.set(l2, [s]);
1467
1488
  }
1468
1489
  let a = 0;
1469
1490
  for (; a < t.length; ) {
@@ -1473,7 +1494,7 @@ var f = class {
1473
1494
  }
1474
1495
  if (n.length !== r.size) {
1475
1496
  let s = this.detectCycle();
1476
- throw new import_types.PluginError(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
1497
+ throw new l(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
1477
1498
  }
1478
1499
  return n;
1479
1500
  }
@@ -1484,12 +1505,12 @@ var f = class {
1484
1505
  r.set(a, 1), s.push(a);
1485
1506
  for (let o of this.graph.get(a)) if (this.graph.has(o)) {
1486
1507
  if (r.get(o) === 1) {
1487
- let l = s.indexOf(o);
1488
- return [...s.slice(l), o];
1508
+ let l2 = s.indexOf(o);
1509
+ return [...s.slice(l2), o];
1489
1510
  }
1490
1511
  if (r.get(o) === 0) {
1491
- let l = i(o, s);
1492
- if (l) return l;
1512
+ let l2 = i(o, s);
1513
+ if (l2) return l2;
1493
1514
  }
1494
1515
  }
1495
1516
  return s.pop(), r.set(a, 2), null;
@@ -1562,8 +1583,8 @@ var m = class {
1562
1583
  await r.withBoundary(s, o.plugin, async () => {
1563
1584
  o.plugin.onInit && await o.plugin.onInit(n);
1564
1585
  }), o.state = "ready", o.initializedAt = Date.now(), i?.(s);
1565
- } catch (l) {
1566
- if (a === "fail-fast") throw l;
1586
+ } catch (l2) {
1587
+ if (a === "fail-fast") throw l2;
1567
1588
  o.state = "failed";
1568
1589
  }
1569
1590
  }
@@ -1579,8 +1600,8 @@ var m = class {
1579
1600
  await n.withBoundary(s, o.plugin, async () => {
1580
1601
  o.plugin.onDestroy && await o.plugin.onDestroy();
1581
1602
  });
1582
- } catch (l) {
1583
- if (i === "fail-fast") throw l;
1603
+ } catch (l2) {
1604
+ if (i === "fail-fast") throw l2;
1584
1605
  }
1585
1606
  o.state = "destroyed", r?.(s);
1586
1607
  }
@@ -1601,12 +1622,12 @@ var c = class {
1601
1622
  this.events.emit(e, t);
1602
1623
  }
1603
1624
  constructor(e) {
1604
- 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();
1625
+ 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();
1605
1626
  }
1606
1627
  use(e) {
1607
- if (this.state === "destroyed") throw new import_types.PluginError("Cannot add plugins to destroyed kernel", "kernel");
1608
- 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");
1609
- if (this.plugins.has(e.name)) throw new import_types.PluginError(`Plugin '${e.name}' is already registered`, "kernel");
1628
+ if (this.state === "destroyed") throw new l("Cannot add plugins to destroyed kernel", "kernel");
1629
+ 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");
1630
+ if (this.plugins.has(e.name)) throw new l(`Plugin '${e.name}' is already registered`, "kernel");
1610
1631
  let t = { plugin: e, state: "registered" };
1611
1632
  this.plugins.set(e.name, t), this.resolver.addPlugin(e.name, [...e.dependencies || []]);
1612
1633
  try {
@@ -1640,7 +1661,7 @@ var c = class {
1640
1661
  let i = this.plugins.get(r);
1641
1662
  if (!i || i.state !== "ready") {
1642
1663
  t.state = "failed";
1643
- let a = new import_types.PluginError(`Dependency '${r}' is not ready for plugin '${e}'`, e);
1664
+ let a = new l(`Dependency '${r}' is not ready for plugin '${e}'`, e);
1644
1665
  this.emitInternal("plugin:error", { name: e, error: a });
1645
1666
  return;
1646
1667
  }
@@ -1711,7 +1732,7 @@ var c = class {
1711
1732
  }
1712
1733
  }
1713
1734
  async init() {
1714
- if (this.state !== "created") throw new import_types.PluginError("Kernel already initialized", "kernel");
1735
+ if (this.state !== "created") throw new l("Kernel already initialized", "kernel");
1715
1736
  this.state = "initializing";
1716
1737
  try {
1717
1738
  this.config.onBeforeInit && await this.config.onBeforeInit();
@@ -2004,13 +2025,13 @@ var BuilderPigment = class {
2004
2025
  }
2005
2026
  return this;
2006
2027
  }
2007
- hsl(h2, s, l) {
2008
- const { r, g, b } = hslToRgb(h2, s, l);
2028
+ hsl(h2, s, l2) {
2029
+ const { r, g, b } = hslToRgb(h2, s, l2);
2009
2030
  this.styles.push(generateRgbCodeForLevel(r, g, b, false, this.level));
2010
2031
  return this;
2011
2032
  }
2012
- bgHsl(h2, s, l) {
2013
- const { r, g, b } = hslToRgb(h2, s, l);
2033
+ bgHsl(h2, s, l2) {
2034
+ const { r, g, b } = hslToRgb(h2, s, l2);
2014
2035
  this.styles.push(generateRgbCodeForLevel(r, g, b, true, this.level));
2015
2036
  return this;
2016
2037
  }