@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.
package/dist/index.cjs CHANGED
@@ -91,9 +91,27 @@ __export(index_exports, {
91
91
  });
92
92
  module.exports = __toCommonJS(index_exports);
93
93
 
94
+ // node_modules/@oxog/types/dist/index.js
95
+ 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 || {});
96
+ var u = class extends Error {
97
+ constructor(t, n, s, p) {
98
+ super(t, p);
99
+ this.code = n;
100
+ this.context = s;
101
+ this.name = "OxogError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
102
+ }
103
+ name;
104
+ };
105
+ var l = class extends u {
106
+ constructor(t, n, s, p) {
107
+ super(t, "PLUGIN_ERROR", { pluginName: n, ...s }, p);
108
+ this.pluginName = n;
109
+ this.name = "PluginError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
110
+ }
111
+ name;
112
+ };
113
+
94
114
  // node_modules/@oxog/plugin/dist/index.js
95
- var import_types = require("@oxog/types");
96
- var import_types2 = require("@oxog/types");
97
115
  var x = ((i) => (i.Created = "created", i.Initializing = "initializing", i.Ready = "ready", i.Destroying = "destroying", i.Destroyed = "destroyed", i))(x || {});
98
116
  var h = class {
99
117
  context;
@@ -122,7 +140,7 @@ var h = class {
122
140
  return n;
123
141
  }
124
142
  };
125
- var u = class {
143
+ var u2 = class {
126
144
  handlers = /* @__PURE__ */ new Map();
127
145
  wildcardHandlers = new Array();
128
146
  patternHandlers = /* @__PURE__ */ new Map();
@@ -150,8 +168,8 @@ var u = class {
150
168
  off(e, t) {
151
169
  let n = String(e), r = this.handlers.get(n);
152
170
  if (r) {
153
- let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l = r.indexOf(o);
154
- l !== -1 && (r.splice(l, 1), s && a.delete(i));
171
+ let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l2 = r.indexOf(o);
172
+ l2 !== -1 && (r.splice(l2, 1), s && a.delete(i));
155
173
  }
156
174
  }
157
175
  emit(e, t) {
@@ -213,22 +231,22 @@ var f = class {
213
231
  validateSinglePlugin(e) {
214
232
  let t = this.graph.get(e);
215
233
  if (!t) return;
216
- for (let r of t) if (!this.graph.has(r)) throw new import_types.PluginError(`Missing dependency: '${r}' required by '${e}'`, e);
234
+ for (let r of t) if (!this.graph.has(r)) throw new l(`Missing dependency: '${r}' required by '${e}'`, e);
217
235
  let n = this.detectCycle();
218
- if (n && n.includes(e)) throw new import_types.PluginError(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
236
+ if (n && n.includes(e)) throw new l(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
219
237
  }
220
238
  resolve() {
221
239
  let e = /* @__PURE__ */ new Map(), t = [], n = [], r = /* @__PURE__ */ new Map();
222
240
  for (let [s, o] of this.graph) {
223
- let l = o.filter((p) => this.graph.has(p));
224
- r.set(s, l);
241
+ let l2 = o.filter((p) => this.graph.has(p));
242
+ r.set(s, l2);
225
243
  }
226
- 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);
244
+ 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);
227
245
  for (let [s, o] of r) e.set(s, o.length), o.length === 0 && t.push(s);
228
246
  let i = /* @__PURE__ */ new Map();
229
- for (let [s, o] of r) for (let l of o) {
230
- let p = i.get(l);
231
- p ? p.push(s) : i.set(l, [s]);
247
+ for (let [s, o] of r) for (let l2 of o) {
248
+ let p = i.get(l2);
249
+ p ? p.push(s) : i.set(l2, [s]);
232
250
  }
233
251
  let a = 0;
234
252
  for (; a < t.length; ) {
@@ -238,7 +256,7 @@ var f = class {
238
256
  }
239
257
  if (n.length !== r.size) {
240
258
  let s = this.detectCycle();
241
- throw new import_types.PluginError(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
259
+ throw new l(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
242
260
  }
243
261
  return n;
244
262
  }
@@ -249,12 +267,12 @@ var f = class {
249
267
  r.set(a, 1), s.push(a);
250
268
  for (let o of this.graph.get(a)) if (this.graph.has(o)) {
251
269
  if (r.get(o) === 1) {
252
- let l = s.indexOf(o);
253
- return [...s.slice(l), o];
270
+ let l2 = s.indexOf(o);
271
+ return [...s.slice(l2), o];
254
272
  }
255
273
  if (r.get(o) === 0) {
256
- let l = i(o, s);
257
- if (l) return l;
274
+ let l2 = i(o, s);
275
+ if (l2) return l2;
258
276
  }
259
277
  }
260
278
  return s.pop(), r.set(a, 2), null;
@@ -327,8 +345,8 @@ var m = class {
327
345
  await r.withBoundary(s, o.plugin, async () => {
328
346
  o.plugin.onInit && await o.plugin.onInit(n);
329
347
  }), o.state = "ready", o.initializedAt = Date.now(), i?.(s);
330
- } catch (l) {
331
- if (a === "fail-fast") throw l;
348
+ } catch (l2) {
349
+ if (a === "fail-fast") throw l2;
332
350
  o.state = "failed";
333
351
  }
334
352
  }
@@ -344,8 +362,8 @@ var m = class {
344
362
  await n.withBoundary(s, o.plugin, async () => {
345
363
  o.plugin.onDestroy && await o.plugin.onDestroy();
346
364
  });
347
- } catch (l) {
348
- if (i === "fail-fast") throw l;
365
+ } catch (l2) {
366
+ if (i === "fail-fast") throw l2;
349
367
  }
350
368
  o.state = "destroyed", r?.(s);
351
369
  }
@@ -366,12 +384,12 @@ var c = class {
366
384
  this.events.emit(e, t);
367
385
  }
368
386
  constructor(e) {
369
- 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();
387
+ 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();
370
388
  }
371
389
  use(e) {
372
- if (this.state === "destroyed") throw new import_types.PluginError("Cannot add plugins to destroyed kernel", "kernel");
373
- 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");
374
- if (this.plugins.has(e.name)) throw new import_types.PluginError(`Plugin '${e.name}' is already registered`, "kernel");
390
+ if (this.state === "destroyed") throw new l("Cannot add plugins to destroyed kernel", "kernel");
391
+ 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");
392
+ if (this.plugins.has(e.name)) throw new l(`Plugin '${e.name}' is already registered`, "kernel");
375
393
  let t = { plugin: e, state: "registered" };
376
394
  this.plugins.set(e.name, t), this.resolver.addPlugin(e.name, [...e.dependencies || []]);
377
395
  try {
@@ -405,7 +423,7 @@ var c = class {
405
423
  let i = this.plugins.get(r);
406
424
  if (!i || i.state !== "ready") {
407
425
  t.state = "failed";
408
- let a = new import_types.PluginError(`Dependency '${r}' is not ready for plugin '${e}'`, e);
426
+ let a = new l(`Dependency '${r}' is not ready for plugin '${e}'`, e);
409
427
  this.emitInternal("plugin:error", { name: e, error: a });
410
428
  return;
411
429
  }
@@ -476,7 +494,7 @@ var c = class {
476
494
  }
477
495
  }
478
496
  async init() {
479
- if (this.state !== "created") throw new import_types.PluginError("Kernel already initialized", "kernel");
497
+ if (this.state !== "created") throw new l("Kernel already initialized", "kernel");
480
498
  this.state = "initializing";
481
499
  try {
482
500
  this.config.onBeforeInit && await this.config.onBeforeInit();
@@ -771,7 +789,7 @@ var PigmentError = class _PigmentError extends Error {
771
789
  Error.captureStackTrace(this, _PigmentError);
772
790
  }
773
791
  };
774
- var PluginError3 = class extends PigmentError {
792
+ var PluginError = class extends PigmentError {
775
793
  constructor(pluginName, message) {
776
794
  super(`[${pluginName}] ${message}`, "PLUGIN_ERROR");
777
795
  this.name = "PluginError";
@@ -969,6 +987,9 @@ var PLUGIN_API_PROVIDERS = {
969
987
  box: "boxPlugin",
970
988
  template: "templatePlugin"
971
989
  };
990
+ function isPluginApiName(name) {
991
+ return Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, name);
992
+ }
972
993
  function registerPluginApi(kernel, name, value) {
973
994
  let api = apis.get(kernel);
974
995
  if (!api) {
@@ -989,7 +1010,7 @@ function getRoot(kernel) {
989
1010
  function missingPluginApi(name) {
990
1011
  const plugin = PLUGIN_API_PROVIDERS[name];
991
1012
  const fail = () => {
992
- throw new PluginError3(
1013
+ throw new PluginError(
993
1014
  plugin,
994
1015
  `pigment.${name} needs ${plugin}(): createPigment({ plugins: [${plugin}()] }) or pigment.use(${plugin}())`
995
1016
  );
@@ -1066,13 +1087,13 @@ function createProxyPigment(kernel, styles = []) {
1066
1087
  };
1067
1088
  }
1068
1089
  if (prop === "hsl" || prop === "bgHsl") {
1069
- return (h2, s, l) => {
1090
+ return (h2, s, l2) => {
1070
1091
  const background = prop === "bgHsl";
1071
1092
  const hslToRgb2 = ctx.utils?.hslToRgb;
1072
1093
  if (!hslToRgb2) {
1073
1094
  throw new Error("hslToRgb utility not available");
1074
1095
  }
1075
- const { r, g, b } = hslToRgb2(h2, s, l);
1096
+ const { r, g, b } = hslToRgb2(h2, s, l2);
1076
1097
  const rgbStyle = generateRgbCodeForLevel(r, g, b, background, ctx.level);
1077
1098
  return createProxyPigment(kernel, [...styles, rgbStyle]);
1078
1099
  };
@@ -1088,7 +1109,7 @@ function createProxyPigment(kernel, styles = []) {
1088
1109
  return getRoot(kernel) ?? createProxyPigment(kernel);
1089
1110
  };
1090
1111
  }
1091
- if (Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, prop)) {
1112
+ if (isPluginApiName(prop)) {
1092
1113
  return getPluginApi(kernel, prop) ?? missingPluginApi(prop);
1093
1114
  }
1094
1115
  return Reflect.get(target, prop);
@@ -1148,10 +1169,10 @@ function validateHex(hex) {
1148
1169
  }
1149
1170
 
1150
1171
  // src/utils/hsl-to-rgb.ts
1151
- function hslToRgb(h2, s, l) {
1172
+ function hslToRgb(h2, s, l2) {
1152
1173
  const hNormalized = h2 / 360;
1153
1174
  const sNormalized = s / 100;
1154
- const lNormalized = l / 100;
1175
+ const lNormalized = l2 / 100;
1155
1176
  let r;
1156
1177
  let g;
1157
1178
  let b;
@@ -1398,13 +1419,13 @@ var BuilderPigment = class {
1398
1419
  }
1399
1420
  return this;
1400
1421
  }
1401
- hsl(h2, s, l) {
1402
- const { r, g, b } = hslToRgb(h2, s, l);
1422
+ hsl(h2, s, l2) {
1423
+ const { r, g, b } = hslToRgb(h2, s, l2);
1403
1424
  this.styles.push(generateRgbCodeForLevel(r, g, b, false, this.level));
1404
1425
  return this;
1405
1426
  }
1406
- bgHsl(h2, s, l) {
1407
- const { r, g, b } = hslToRgb(h2, s, l);
1427
+ bgHsl(h2, s, l2) {
1428
+ const { r, g, b } = hslToRgb(h2, s, l2);
1408
1429
  this.styles.push(generateRgbCodeForLevel(r, g, b, true, this.level));
1409
1430
  return this;
1410
1431
  }
@@ -1643,11 +1664,11 @@ function trueColorPlugin() {
1643
1664
  k.emit("color:rgb", { ...rgb, background });
1644
1665
  });
1645
1666
  k.on("color:hsl", (data) => {
1646
- const { h: h2, s, l, background } = data;
1667
+ const { h: h2, s, l: l2, background } = data;
1647
1668
  if (!utils?.hslToRgb) {
1648
1669
  throw new Error("hslToRgb utility not available");
1649
1670
  }
1650
- const rgb = utils.hslToRgb(h2, s, l);
1671
+ const rgb = utils.hslToRgb(h2, s, l2);
1651
1672
  k.emit("color:rgb", { ...rgb, background });
1652
1673
  });
1653
1674
  }
@@ -2168,7 +2189,7 @@ function boxPlugin(options) {
2168
2189
  throw new StyleError(`Unknown box border: ${String(boxBorder)}`);
2169
2190
  }
2170
2191
  const lines = text.split("\n");
2171
- const width = Math.max(...lines.map((l) => l.length)) + boxPadding * 2;
2192
+ const width = Math.max(...lines.map((l2) => l2.length)) + boxPadding * 2;
2172
2193
  const pad = " ".repeat(boxPadding);
2173
2194
  const top = `${chars.tl}${chars.h.repeat(width)}${chars.tr}`;
2174
2195
  const middle = lines.map((line) => {
@@ -2198,7 +2219,7 @@ var TOKEN = /\uE000(\d+)\uE001/g;
2198
2219
  function renderTemplate(root, strings, values) {
2199
2220
  const parts = values.map((value) => String(value));
2200
2221
  const token = (index) => `\uE000${index}\uE001`;
2201
- const restore = (text) => text.replace(TOKEN, (_match, index) => parts[Number(index)]);
2222
+ const restore = (text) => text.replace(TOKEN, (_match, index) => String(parts[Number(index)]));
2202
2223
  let source = "";
2203
2224
  for (let i = 0; i < strings.length; i++) {
2204
2225
  source += strings[i];