@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.d.cts CHANGED
@@ -1,7 +1,5 @@
1
- import { P as PigmentOptions, a as PigmentInstance, b as Pigment, C as ColorSupport, S as Styler, c as Platform } from './index-C_LwyWae.cjs';
2
- export { k as BoxBorder, q as BoxChars, v as BoxOptions, m as BoxPluginOptions, B as BuilderPigment, t as ColorInput, E as EventHandler, G as GradientPluginOptions, K as Kernel, r as KernelOptions, f as PigmentContext, g as PigmentEvents, e as PigmentKernel, s as PigmentPluginApi, n as PigmentPluginOptions, d as Plugin, o as SemanticPluginOptions, h as Style, j as StyleFunction, u as ThemeColorType, l as ThemePluginOptions, T as ThemePreset, p as ThemePresetColors, i as plugins } from './index-C_LwyWae.cjs';
3
- export { createKernel } from '@oxog/plugin';
4
- export { MaybePromise, Unsubscribe } from '@oxog/types';
1
+ import { P as PigmentOptions, a as PigmentInstance, b as Pigment, C as ColorSupport, S as Styler, c as Platform } from './index-DsggPsSl.cjs';
2
+ export { B as BoxBorder, d as BoxChars, e as BoxOptions, f as BoxPluginOptions, g as BuilderPigment, h as ColorInput, E as EventHandler, G as GradientPluginOptions, K as Kernel, i as KernelOptions, M as MaybePromise, j as PigmentContext, k as PigmentEvents, l as PigmentKernel, m as PigmentPluginApi, n as PigmentPluginOptions, o as Plugin, p as SemanticPluginOptions, q as Style, r as StyleFunction, T as ThemeColorType, s as ThemePluginOptions, t as ThemePreset, u as ThemePresetColors, U as Unsubscribe, v as createKernel, w as plugins } from './index-DsggPsSl.cjs';
5
3
 
6
4
  /**
7
5
  * Creates a new Pigment instance using @oxog/plugin micro-kernel.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { P as PigmentOptions, a as PigmentInstance, b as Pigment, C as ColorSupport, S as Styler, c as Platform } from './index-C_LwyWae.js';
2
- export { k as BoxBorder, q as BoxChars, v as BoxOptions, m as BoxPluginOptions, B as BuilderPigment, t as ColorInput, E as EventHandler, G as GradientPluginOptions, K as Kernel, r as KernelOptions, f as PigmentContext, g as PigmentEvents, e as PigmentKernel, s as PigmentPluginApi, n as PigmentPluginOptions, d as Plugin, o as SemanticPluginOptions, h as Style, j as StyleFunction, u as ThemeColorType, l as ThemePluginOptions, T as ThemePreset, p as ThemePresetColors, i as plugins } from './index-C_LwyWae.js';
3
- export { createKernel } from '@oxog/plugin';
4
- export { MaybePromise, Unsubscribe } from '@oxog/types';
1
+ import { P as PigmentOptions, a as PigmentInstance, b as Pigment, C as ColorSupport, S as Styler, c as Platform } from './index-DsggPsSl.js';
2
+ export { B as BoxBorder, d as BoxChars, e as BoxOptions, f as BoxPluginOptions, g as BuilderPigment, h as ColorInput, E as EventHandler, G as GradientPluginOptions, K as Kernel, i as KernelOptions, M as MaybePromise, j as PigmentContext, k as PigmentEvents, l as PigmentKernel, m as PigmentPluginApi, n as PigmentPluginOptions, o as Plugin, p as SemanticPluginOptions, q as Style, r as StyleFunction, T as ThemeColorType, s as ThemePluginOptions, t as ThemePreset, u as ThemePresetColors, U as Unsubscribe, v as createKernel, w as plugins } from './index-DsggPsSl.js';
5
3
 
6
4
  /**
7
5
  * Creates a new Pigment instance using @oxog/plugin micro-kernel.
package/dist/index.js CHANGED
@@ -8,9 +8,27 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
+ // node_modules/@oxog/types/dist/index.js
12
+ 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 || {});
13
+ var u = class extends Error {
14
+ constructor(t, n, s, p) {
15
+ super(t, p);
16
+ this.code = n;
17
+ this.context = s;
18
+ this.name = "OxogError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
19
+ }
20
+ name;
21
+ };
22
+ var l = class extends u {
23
+ constructor(t, n, s, p) {
24
+ super(t, "PLUGIN_ERROR", { pluginName: n, ...s }, p);
25
+ this.pluginName = n;
26
+ this.name = "PluginError", Object.setPrototypeOf(this, new.target.prototype), Error.captureStackTrace?.(this, new.target);
27
+ }
28
+ name;
29
+ };
30
+
11
31
  // node_modules/@oxog/plugin/dist/index.js
12
- import { PluginError } from "@oxog/types";
13
- import { PluginError as PluginError2 } from "@oxog/types";
14
32
  var x = ((i) => (i.Created = "created", i.Initializing = "initializing", i.Ready = "ready", i.Destroying = "destroying", i.Destroyed = "destroyed", i))(x || {});
15
33
  var h = class {
16
34
  context;
@@ -39,7 +57,7 @@ var h = class {
39
57
  return n;
40
58
  }
41
59
  };
42
- var u = class {
60
+ var u2 = class {
43
61
  handlers = /* @__PURE__ */ new Map();
44
62
  wildcardHandlers = new Array();
45
63
  patternHandlers = /* @__PURE__ */ new Map();
@@ -67,8 +85,8 @@ var u = class {
67
85
  off(e, t) {
68
86
  let n = String(e), r = this.handlers.get(n);
69
87
  if (r) {
70
- let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l = r.indexOf(o);
71
- l !== -1 && (r.splice(l, 1), s && a.delete(i));
88
+ let i = t, a = this.onceWrappers.get(n), s = a?.get(i), o = s || i, l2 = r.indexOf(o);
89
+ l2 !== -1 && (r.splice(l2, 1), s && a.delete(i));
72
90
  }
73
91
  }
74
92
  emit(e, t) {
@@ -130,22 +148,22 @@ var f = class {
130
148
  validateSinglePlugin(e) {
131
149
  let t = this.graph.get(e);
132
150
  if (!t) return;
133
- for (let r of t) if (!this.graph.has(r)) throw new PluginError(`Missing dependency: '${r}' required by '${e}'`, e);
151
+ for (let r of t) if (!this.graph.has(r)) throw new l(`Missing dependency: '${r}' required by '${e}'`, e);
134
152
  let n = this.detectCycle();
135
- if (n && n.includes(e)) throw new PluginError(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
153
+ if (n && n.includes(e)) throw new l(`Circular dependency detected: ${n.join(" -> ")}`, "dependency-resolver");
136
154
  }
137
155
  resolve() {
138
156
  let e = /* @__PURE__ */ new Map(), t = [], n = [], r = /* @__PURE__ */ new Map();
139
157
  for (let [s, o] of this.graph) {
140
- let l = o.filter((p) => this.graph.has(p));
141
- r.set(s, l);
158
+ let l2 = o.filter((p) => this.graph.has(p));
159
+ r.set(s, l2);
142
160
  }
143
- for (let [s, o] of this.graph) for (let l of o) if (!this.graph.has(l)) throw new PluginError(`Missing dependency: '${l}' required by '${s}'`, s);
161
+ 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);
144
162
  for (let [s, o] of r) e.set(s, o.length), o.length === 0 && t.push(s);
145
163
  let i = /* @__PURE__ */ new Map();
146
- for (let [s, o] of r) for (let l of o) {
147
- let p = i.get(l);
148
- p ? p.push(s) : i.set(l, [s]);
164
+ for (let [s, o] of r) for (let l2 of o) {
165
+ let p = i.get(l2);
166
+ p ? p.push(s) : i.set(l2, [s]);
149
167
  }
150
168
  let a = 0;
151
169
  for (; a < t.length; ) {
@@ -155,7 +173,7 @@ var f = class {
155
173
  }
156
174
  if (n.length !== r.size) {
157
175
  let s = this.detectCycle();
158
- throw new PluginError(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
176
+ throw new l(`Circular dependency detected: ${s.join(" -> ")}`, "dependency-resolver");
159
177
  }
160
178
  return n;
161
179
  }
@@ -166,12 +184,12 @@ var f = class {
166
184
  r.set(a, 1), s.push(a);
167
185
  for (let o of this.graph.get(a)) if (this.graph.has(o)) {
168
186
  if (r.get(o) === 1) {
169
- let l = s.indexOf(o);
170
- return [...s.slice(l), o];
187
+ let l2 = s.indexOf(o);
188
+ return [...s.slice(l2), o];
171
189
  }
172
190
  if (r.get(o) === 0) {
173
- let l = i(o, s);
174
- if (l) return l;
191
+ let l2 = i(o, s);
192
+ if (l2) return l2;
175
193
  }
176
194
  }
177
195
  return s.pop(), r.set(a, 2), null;
@@ -244,8 +262,8 @@ var m = class {
244
262
  await r.withBoundary(s, o.plugin, async () => {
245
263
  o.plugin.onInit && await o.plugin.onInit(n);
246
264
  }), o.state = "ready", o.initializedAt = Date.now(), i?.(s);
247
- } catch (l) {
248
- if (a === "fail-fast") throw l;
265
+ } catch (l2) {
266
+ if (a === "fail-fast") throw l2;
249
267
  o.state = "failed";
250
268
  }
251
269
  }
@@ -261,8 +279,8 @@ var m = class {
261
279
  await n.withBoundary(s, o.plugin, async () => {
262
280
  o.plugin.onDestroy && await o.plugin.onDestroy();
263
281
  });
264
- } catch (l) {
265
- if (i === "fail-fast") throw l;
282
+ } catch (l2) {
283
+ if (i === "fail-fast") throw l2;
266
284
  }
267
285
  o.state = "destroyed", r?.(s);
268
286
  }
@@ -283,12 +301,12 @@ var c = class {
283
301
  this.events.emit(e, t);
284
302
  }
285
303
  constructor(e) {
286
- 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();
304
+ 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();
287
305
  }
288
306
  use(e) {
289
- if (this.state === "destroyed") throw new PluginError("Cannot add plugins to destroyed kernel", "kernel");
290
- if (this.state === "initializing") throw new PluginError("Cannot add plugins while kernel is initializing. Register all plugins before calling init(), or wait until kernel is ready.", "kernel");
291
- if (this.plugins.has(e.name)) throw new PluginError(`Plugin '${e.name}' is already registered`, "kernel");
307
+ if (this.state === "destroyed") throw new l("Cannot add plugins to destroyed kernel", "kernel");
308
+ 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");
309
+ if (this.plugins.has(e.name)) throw new l(`Plugin '${e.name}' is already registered`, "kernel");
292
310
  let t = { plugin: e, state: "registered" };
293
311
  this.plugins.set(e.name, t), this.resolver.addPlugin(e.name, [...e.dependencies || []]);
294
312
  try {
@@ -322,7 +340,7 @@ var c = class {
322
340
  let i = this.plugins.get(r);
323
341
  if (!i || i.state !== "ready") {
324
342
  t.state = "failed";
325
- let a = new PluginError(`Dependency '${r}' is not ready for plugin '${e}'`, e);
343
+ let a = new l(`Dependency '${r}' is not ready for plugin '${e}'`, e);
326
344
  this.emitInternal("plugin:error", { name: e, error: a });
327
345
  return;
328
346
  }
@@ -393,7 +411,7 @@ var c = class {
393
411
  }
394
412
  }
395
413
  async init() {
396
- if (this.state !== "created") throw new PluginError("Kernel already initialized", "kernel");
414
+ if (this.state !== "created") throw new l("Kernel already initialized", "kernel");
397
415
  this.state = "initializing";
398
416
  try {
399
417
  this.config.onBeforeInit && await this.config.onBeforeInit();
@@ -688,7 +706,7 @@ var PigmentError = class _PigmentError extends Error {
688
706
  Error.captureStackTrace(this, _PigmentError);
689
707
  }
690
708
  };
691
- var PluginError3 = class extends PigmentError {
709
+ var PluginError = class extends PigmentError {
692
710
  constructor(pluginName, message) {
693
711
  super(`[${pluginName}] ${message}`, "PLUGIN_ERROR");
694
712
  this.name = "PluginError";
@@ -886,6 +904,9 @@ var PLUGIN_API_PROVIDERS = {
886
904
  box: "boxPlugin",
887
905
  template: "templatePlugin"
888
906
  };
907
+ function isPluginApiName(name) {
908
+ return Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, name);
909
+ }
889
910
  function registerPluginApi(kernel, name, value) {
890
911
  let api = apis.get(kernel);
891
912
  if (!api) {
@@ -906,7 +927,7 @@ function getRoot(kernel) {
906
927
  function missingPluginApi(name) {
907
928
  const plugin = PLUGIN_API_PROVIDERS[name];
908
929
  const fail = () => {
909
- throw new PluginError3(
930
+ throw new PluginError(
910
931
  plugin,
911
932
  `pigment.${name} needs ${plugin}(): createPigment({ plugins: [${plugin}()] }) or pigment.use(${plugin}())`
912
933
  );
@@ -983,13 +1004,13 @@ function createProxyPigment(kernel, styles = []) {
983
1004
  };
984
1005
  }
985
1006
  if (prop === "hsl" || prop === "bgHsl") {
986
- return (h2, s, l) => {
1007
+ return (h2, s, l2) => {
987
1008
  const background = prop === "bgHsl";
988
1009
  const hslToRgb2 = ctx.utils?.hslToRgb;
989
1010
  if (!hslToRgb2) {
990
1011
  throw new Error("hslToRgb utility not available");
991
1012
  }
992
- const { r, g, b } = hslToRgb2(h2, s, l);
1013
+ const { r, g, b } = hslToRgb2(h2, s, l2);
993
1014
  const rgbStyle = generateRgbCodeForLevel(r, g, b, background, ctx.level);
994
1015
  return createProxyPigment(kernel, [...styles, rgbStyle]);
995
1016
  };
@@ -1005,7 +1026,7 @@ function createProxyPigment(kernel, styles = []) {
1005
1026
  return getRoot(kernel) ?? createProxyPigment(kernel);
1006
1027
  };
1007
1028
  }
1008
- if (Object.prototype.hasOwnProperty.call(PLUGIN_API_PROVIDERS, prop)) {
1029
+ if (isPluginApiName(prop)) {
1009
1030
  return getPluginApi(kernel, prop) ?? missingPluginApi(prop);
1010
1031
  }
1011
1032
  return Reflect.get(target, prop);
@@ -1065,10 +1086,10 @@ function validateHex(hex) {
1065
1086
  }
1066
1087
 
1067
1088
  // src/utils/hsl-to-rgb.ts
1068
- function hslToRgb(h2, s, l) {
1089
+ function hslToRgb(h2, s, l2) {
1069
1090
  const hNormalized = h2 / 360;
1070
1091
  const sNormalized = s / 100;
1071
- const lNormalized = l / 100;
1092
+ const lNormalized = l2 / 100;
1072
1093
  let r;
1073
1094
  let g;
1074
1095
  let b;
@@ -1315,13 +1336,13 @@ var BuilderPigment = class {
1315
1336
  }
1316
1337
  return this;
1317
1338
  }
1318
- hsl(h2, s, l) {
1319
- const { r, g, b } = hslToRgb(h2, s, l);
1339
+ hsl(h2, s, l2) {
1340
+ const { r, g, b } = hslToRgb(h2, s, l2);
1320
1341
  this.styles.push(generateRgbCodeForLevel(r, g, b, false, this.level));
1321
1342
  return this;
1322
1343
  }
1323
- bgHsl(h2, s, l) {
1324
- const { r, g, b } = hslToRgb(h2, s, l);
1344
+ bgHsl(h2, s, l2) {
1345
+ const { r, g, b } = hslToRgb(h2, s, l2);
1325
1346
  this.styles.push(generateRgbCodeForLevel(r, g, b, true, this.level));
1326
1347
  return this;
1327
1348
  }
@@ -1560,11 +1581,11 @@ function trueColorPlugin() {
1560
1581
  k.emit("color:rgb", { ...rgb, background });
1561
1582
  });
1562
1583
  k.on("color:hsl", (data) => {
1563
- const { h: h2, s, l, background } = data;
1584
+ const { h: h2, s, l: l2, background } = data;
1564
1585
  if (!utils?.hslToRgb) {
1565
1586
  throw new Error("hslToRgb utility not available");
1566
1587
  }
1567
- const rgb = utils.hslToRgb(h2, s, l);
1588
+ const rgb = utils.hslToRgb(h2, s, l2);
1568
1589
  k.emit("color:rgb", { ...rgb, background });
1569
1590
  });
1570
1591
  }
@@ -2085,7 +2106,7 @@ function boxPlugin(options) {
2085
2106
  throw new StyleError(`Unknown box border: ${String(boxBorder)}`);
2086
2107
  }
2087
2108
  const lines = text.split("\n");
2088
- const width = Math.max(...lines.map((l) => l.length)) + boxPadding * 2;
2109
+ const width = Math.max(...lines.map((l2) => l2.length)) + boxPadding * 2;
2089
2110
  const pad = " ".repeat(boxPadding);
2090
2111
  const top = `${chars.tl}${chars.h.repeat(width)}${chars.tr}`;
2091
2112
  const middle = lines.map((line) => {
@@ -2115,7 +2136,7 @@ var TOKEN = /\uE000(\d+)\uE001/g;
2115
2136
  function renderTemplate(root, strings, values) {
2116
2137
  const parts = values.map((value) => String(value));
2117
2138
  const token = (index) => `\uE000${index}\uE001`;
2118
- const restore = (text) => text.replace(TOKEN, (_match, index) => parts[Number(index)]);
2139
+ const restore = (text) => text.replace(TOKEN, (_match, index) => String(parts[Number(index)]));
2119
2140
  let source = "";
2120
2141
  for (let i = 0; i < strings.length; i++) {
2121
2142
  source += strings[i];