@greensight/gts 1.0.0-beta.1 → 1.0.0-beta.11

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/index.mjs CHANGED
@@ -1,22 +1,22 @@
1
- var ce = Object.defineProperty;
2
- var ue = (t, e, o) => e in t ? ce(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
3
- var m = (t, e, o) => ue(t, typeof e != "symbol" ? e + "" : e, o);
1
+ var ue = Object.defineProperty;
2
+ var de = (r, e, o) => e in r ? ue(r, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : r[e] = o;
3
+ var w = (r, e, o) => de(r, typeof e != "symbol" ? e + "" : e, o);
4
4
  import k from "path";
5
- import { tsImport as de } from "ts-import";
6
- import { existsSync as C } from "node:fs";
7
- import { readFile as V, mkdir as fe, writeFile as ye, rm as ge } from "node:fs/promises";
8
- import { resolve as F } from "node:path";
9
- const h = class h {
5
+ import { tsImport as ye } from "ts-import";
6
+ import { existsSync as M } from "node:fs";
7
+ import { readFile as V, mkdir as fe, writeFile as ge, rm as pe } from "node:fs/promises";
8
+ import { resolve as C } from "node:path";
9
+ const p = class p {
10
10
  static resolveReadPath(e) {
11
11
  if (!e || !e.trim())
12
12
  throw new Error("File path must be a non-empty string");
13
- return F(h.baseDir, e);
13
+ return C(p.baseDir, e);
14
14
  }
15
15
  static resolveWritePath(e, o) {
16
- const r = F(h.baseDir, o ?? "");
16
+ const t = C(p.baseDir, o ?? "");
17
17
  return {
18
- targetDir: r,
19
- targetPath: F(r, e)
18
+ targetDir: t,
19
+ targetPath: C(t, e)
20
20
  };
21
21
  }
22
22
  static handleReadError(e, o) {
@@ -25,91 +25,92 @@ const h = class h {
25
25
  );
26
26
  }
27
27
  static async read(e, o = "utf8") {
28
- const r = h.resolveReadPath(e);
28
+ const t = p.resolveReadPath(e);
29
29
  try {
30
- return await V(r, { encoding: o });
30
+ return await V(t, { encoding: o });
31
31
  } catch (n) {
32
- h.handleReadError(n, r);
32
+ p.handleReadError(n, t);
33
33
  }
34
34
  }
35
35
  static async readBuffer(e) {
36
- const o = h.resolveReadPath(e);
36
+ const o = p.resolveReadPath(e);
37
37
  try {
38
38
  return await V(o);
39
- } catch (r) {
40
- h.handleReadError(r, o);
39
+ } catch (t) {
40
+ p.handleReadError(t, o);
41
41
  }
42
42
  }
43
43
  static async readJson(e) {
44
- const o = h.resolveReadPath(e);
44
+ const o = p.resolveReadPath(e);
45
45
  try {
46
- const r = await V(o, { encoding: "utf8" });
46
+ const t = await V(o, { encoding: "utf8" });
47
47
  try {
48
- return JSON.parse(r);
48
+ return JSON.parse(t);
49
49
  } catch (n) {
50
50
  throw new Error(`Failed to parse JSON from "${o}": ${n.message}`);
51
51
  }
52
- } catch (r) {
53
- h.handleReadError(r, o);
52
+ } catch (t) {
53
+ p.handleReadError(t, o);
54
54
  }
55
55
  }
56
- static async write(e, o = "", r = {}) {
57
- const { directory: n, overwrite: s = !0 } = r, { targetDir: a, targetPath: l } = h.resolveWritePath(e, n);
58
- if (!s && C(l))
59
- throw new Error(`File ${l} already exists`);
60
- return await fe(a, { recursive: !0 }), await ye(l, o, { encoding: "utf8" }), l;
56
+ static async write(e, o = "", t = {}) {
57
+ const { directory: n, overwrite: s = !0 } = t, { targetDir: a, targetPath: i } = p.resolveWritePath(e, n);
58
+ if (!s && M(i))
59
+ throw new Error(`File ${i} already exists`);
60
+ return await fe(a, { recursive: !0 }), await ge(i, o, { encoding: "utf8" }), i;
61
61
  }
62
- static async writeWithExtension(e, o, r = "", n) {
62
+ static async writeWithExtension(e, o, t = "", n) {
63
63
  const s = o.startsWith(".") ? o : `.${o}`, a = `${e}${s}`;
64
- return h.write(a, r, n);
64
+ return p.write(a, t, n);
65
65
  }
66
66
  static exists(e) {
67
- const o = h.resolveReadPath(e);
68
- return C(o);
67
+ const o = p.resolveReadPath(e);
68
+ return M(o);
69
69
  }
70
70
  static async delete(e, o) {
71
- const { targetPath: r } = h.resolveWritePath(e, o);
72
- C(r) && await ge(r, { recursive: !0, force: !0 });
71
+ const { targetPath: t } = p.resolveWritePath(e, o);
72
+ M(t) && await pe(t, { recursive: !0, force: !0 });
73
73
  }
74
74
  };
75
- m(h, "baseDir", process.cwd());
76
- let d = h;
75
+ w(p, "baseDir", process.cwd());
76
+ let y = p;
77
77
  const $ = class $ {
78
78
  static async create() {
79
- if (d.exists($.configFileName))
79
+ if (y.exists($.configFileName))
80
80
  throw new Error("The file already exists");
81
- await d.write($.configFileName, "", { overwrite: !1 });
81
+ await y.write($.configFileName, "", { overwrite: !1 });
82
82
  }
83
83
  async load() {
84
84
  try {
85
- const e = await de.compile(
85
+ const e = await ye.compile(
86
86
  `${k.resolve(process.cwd(), $.configFileName)}`
87
87
  );
88
- if (!e) throw new Error();
88
+ if (!e)
89
+ throw new Error("gts.config.ts must default-export a configuration object");
89
90
  return e.default;
90
91
  } catch (e) {
91
92
  console.error("Cannot find module gts.config.ts", e);
92
93
  }
93
94
  }
94
95
  };
95
- m($, "configFileName", "gts.config.ts");
96
- let j = $;
97
- const pe = (t) => {
96
+ w($, "configFileName", "gts.config.ts");
97
+ let v = $;
98
+ const he = (r) => {
98
99
  const e = new URLSearchParams();
99
- return Object.keys(t).forEach((o) => {
100
- Array.isArray(t[o]) ? t[o].forEach((r) => e.append(`${o}[]`, r)) : e.append(o, t[o]);
100
+ return Object.keys(r).forEach((o) => {
101
+ Array.isArray(r[o]) ? r[o].forEach((t) => e.append(`${o}[]`, t)) : e.append(o, r[o]);
101
102
  }), e;
102
- }, he = (t, e = 50) => {
103
+ }, me = (r, e = 50) => {
103
104
  const o = [];
104
- for (let r = 0; r < t.length; r += e)
105
- o.push(t.slice(r, r + e));
105
+ for (let t = 0; t < r.length; t += e)
106
+ o.push(r.slice(t, t + e));
106
107
  return o;
107
108
  };
108
- class P {
109
+ class O {
109
110
  constructor(e, o) {
110
- m(this, "figmaToken");
111
- m(this, "fileId");
112
- m(this, "onTimeMeasureHandler");
111
+ w(this, "figmaToken");
112
+ w(this, "fileId");
113
+ w(this, "onTimeMeasureHandler");
113
114
  this.figmaToken = e, this.fileId = o;
114
115
  }
115
116
  setOnTimeMeasureHandler(e) {
@@ -118,35 +119,35 @@ class P {
118
119
  static async returnJSON(e) {
119
120
  const o = await e.json();
120
121
  if (!e.ok) {
121
- let r = "Request failed";
122
- throw new Error(r);
122
+ let t = "Request failed";
123
+ throw new Error(t);
123
124
  }
124
125
  return o;
125
126
  }
126
- async performControlledRequest(e, { params: o = {}, timeout: r = 3e4, abortController: n = new AbortController() } = {}) {
127
- var g;
127
+ async performControlledRequest(e, { params: o = {}, timeout: t = 3e4, abortController: n = new AbortController() } = {}) {
128
+ var m;
128
129
  if (!this.figmaToken || !this.fileId)
129
- throw new Error("Добавьте figmaToken и figmaId");
130
- const s = Object.entries(o).reduce((p, [b, w]) => typeof w < "u" ? { ...p, [b]: w } : p, {}), a = `https://api.figma.com/v1${e}${s && Object.keys(s).length ? `?${pe(s)}` : ""}`;
130
+ throw new Error("figmaToken and fileId are required in gts.config.ts");
131
+ const s = Object.entries(o).reduce((g, [h, b]) => typeof b < "u" ? { ...g, [h]: b } : g, {}), a = `https://api.figma.com/v1${e}${s && Object.keys(s).length ? `?${he(s)}` : ""}`;
131
132
  console.log("endpoinWithParams=", a);
132
- const l = setTimeout(() => n.abort(), r), i = {
133
+ const i = setTimeout(() => n.abort(), t), l = {
133
134
  "Content-Type": "application/json",
134
135
  ...this.figmaToken && { "X-Figma-Token": this.figmaToken }
135
136
  }, c = {
136
137
  method: "GET",
137
- headers: i,
138
+ headers: l,
138
139
  signal: n.signal
139
- }, u = performance.now(), f = await fetch(`${a}`, c);
140
- clearTimeout(l);
141
- const y = performance.now() - u;
142
- return (g = this.onTimeMeasureHandler) == null || g.call(this, a, i, y), f;
140
+ }, u = performance.now(), d = await fetch(`${a}`, c);
141
+ clearTimeout(i);
142
+ const f = performance.now() - u;
143
+ return (m = this.onTimeMeasureHandler) == null || m.call(this, a, l, f), d;
143
144
  }
144
145
  async request(e, o) {
145
146
  var n;
146
- const r = await this.performControlledRequest(e, {
147
+ const t = await this.performControlledRequest(e, {
147
148
  ...o
148
149
  });
149
- return (n = r.headers.get("content-type")) != null && n.includes("application/json") ? P.returnJSON(r) : r;
150
+ return (n = t.headers.get("content-type")) != null && n.includes("application/json") ? O.returnJSON(t) : t;
150
151
  }
151
152
  async getComponents() {
152
153
  return this.request(`/files/${this.fileId}/components`);
@@ -155,62 +156,62 @@ class P {
155
156
  return this.request(`/files/${this.fileId}/styles`);
156
157
  }
157
158
  async getNodes(e) {
158
- const o = he(e).map(
159
+ const o = me(e).map(
159
160
  (s) => this.request(`/files/${this.fileId}/nodes`, { params: { ids: s.join(",") } })
160
- ), r = await Promise.all(o);
161
+ ), t = await Promise.all(o);
161
162
  return {
162
- ...r[0],
163
- nodes: r.reduce((s, a) => ({ ...s, ...a.nodes }), {})
163
+ ...t[0],
164
+ nodes: t.reduce((s, a) => ({ ...s, ...a.nodes }), {})
164
165
  };
165
166
  }
166
167
  }
167
- const q = (t, e) => {
168
+ const q = (r, e) => {
168
169
  const o = Array.isArray(e) ? e : e.split(".");
169
- let r = t;
170
+ let t = r;
170
171
  for (const n of o) {
171
- if (r == null || typeof r != "object") return;
172
- r = r[n];
172
+ if (t == null || typeof t != "object") return;
173
+ t = t[n];
173
174
  }
174
- return r;
175
- }, H = (t, e) => {
176
- if (!e || typeof e != "object") return t;
177
- if (!t || typeof t != "object") return e;
178
- const o = { ...t };
179
- for (const r in e)
180
- e.hasOwnProperty(r) && (typeof e[r] == "object" && e[r] !== null && typeof o[r] == "object" && o[r] !== null ? o[r] = H(o[r], e[r]) : o[r] = e[r]);
175
+ return t;
176
+ }, H = (r, e) => {
177
+ if (!e || typeof e != "object") return r;
178
+ if (!r || typeof r != "object") return e;
179
+ const o = { ...r };
180
+ for (const t in e)
181
+ e.hasOwnProperty(t) && (typeof e[t] == "object" && e[t] !== null && typeof o[t] == "object" && o[t] !== null ? o[t] = H(o[t], e[t]) : o[t] = e[t]);
181
182
  return o;
182
183
  };
183
- function x(t, e) {
184
- if (t === e)
184
+ function x(r, e) {
185
+ if (r === e)
185
186
  return !0;
186
- if (t == null || e == null)
187
- return t === e;
188
- if (typeof t != typeof e)
187
+ if (r == null || e == null)
188
+ return r === e;
189
+ if (typeof r != typeof e)
189
190
  return !1;
190
- if (t instanceof Date && e instanceof Date)
191
- return t.getTime() === e.getTime();
192
- if (t instanceof RegExp && e instanceof RegExp)
193
- return t.toString() === e.toString();
194
- if (Array.isArray(t) && Array.isArray(e)) {
195
- if (t.length !== e.length)
191
+ if (r instanceof Date && e instanceof Date)
192
+ return r.getTime() === e.getTime();
193
+ if (r instanceof RegExp && e instanceof RegExp)
194
+ return r.toString() === e.toString();
195
+ if (Array.isArray(r) && Array.isArray(e)) {
196
+ if (r.length !== e.length)
196
197
  return !1;
197
- for (let o = 0; o < t.length; o++)
198
- if (!x(t[o], e[o]))
198
+ for (let o = 0; o < r.length; o++)
199
+ if (!x(r[o], e[o]))
199
200
  return !1;
200
201
  return !0;
201
202
  }
202
- if (typeof t == "object" && typeof e == "object") {
203
- const o = Object.keys(t), r = Object.keys(e);
204
- if (o.length !== r.length)
203
+ if (typeof r == "object" && typeof e == "object") {
204
+ const o = Object.keys(r), t = Object.keys(e);
205
+ if (o.length !== t.length)
205
206
  return !1;
206
207
  for (const n of o)
207
- if (!r.includes(n) || !x(t[n], e[n]))
208
+ if (!t.includes(n) || !x(r[n], e[n]))
208
209
  return !1;
209
210
  return !0;
210
211
  }
211
212
  return !1;
212
213
  }
213
- const R = {
214
+ const K = {
214
215
  color: {},
215
216
  effect: {},
216
217
  text: {},
@@ -219,13 +220,13 @@ const R = {
219
220
  class be {
220
221
  constructor(e) {
221
222
  // files
222
- m(this, "tokensDir");
223
- m(this, "manifestPath");
223
+ w(this, "tokensDir");
224
+ w(this, "manifestPath");
224
225
  // result data
225
- m(this, "variables");
226
- m(this, "styles");
226
+ w(this, "variables");
227
+ w(this, "styles");
227
228
  // flags
228
- m(this, "loaded", !1);
229
+ w(this, "loaded", !1);
229
230
  this.tokensDir = e || "", this.manifestPath = k.join(this.tokensDir, "manifest.json");
230
231
  }
231
232
  isLoaded() {
@@ -234,9 +235,9 @@ class be {
234
235
  /** to camelCase */
235
236
  normalizeKey(e) {
236
237
  const o = e.trim();
237
- return o && o.replace(/[-_\s]+/g, " ").split(" ").filter((r) => r.length).map((r, n) => {
238
- const s = r.charAt(0), a = r.slice(1);
239
- return n === 0 ? r.toLowerCase() : s.toUpperCase() + a;
238
+ return o && o.replace(/[-_\s]+/g, " ").split(" ").filter((t) => t.length).map((t, n) => {
239
+ const s = t.charAt(0), a = t.slice(1);
240
+ return n === 0 ? t : s.toUpperCase() + a;
240
241
  }).join("");
241
242
  }
242
243
  /**
@@ -244,9 +245,9 @@ class be {
244
245
  */
245
246
  parseVariableString(e) {
246
247
  if (typeof e != "string") return e;
247
- const o = /^\{(.+)\}$/, r = e.match(o);
248
- if (r) {
249
- const n = r[1].trim();
248
+ const o = /^\{(.+)\}$/, t = e.match(o);
249
+ if (t) {
250
+ const n = t[1].trim();
250
251
  return `{${this.normalizeKey(n)}}`;
251
252
  }
252
253
  return e;
@@ -256,7 +257,7 @@ class be {
256
257
  */
257
258
  createVariableFileList(e) {
258
259
  return Object.entries(e).flatMap(
259
- ([o, r]) => Object.entries(r.modes).flatMap(
260
+ ([o, t]) => Object.entries(t.modes).flatMap(
260
261
  ([n, s]) => s.map((a) => ({
261
262
  fileName: a,
262
263
  modeName: this.normalizeKey(n.trim()),
@@ -266,20 +267,20 @@ class be {
266
267
  );
267
268
  }
268
269
  parseValue(e) {
269
- return e && (typeof e == "string" ? this.parseVariableString(e) : typeof e != "object" ? e : Array.isArray(e) ? e.map((o) => this.parseValue(o)) : Object.entries(e).reduce((o, [r, n]) => ({ ...o, [r]: this.parseValue(n) }), {}));
270
+ return e && (typeof e == "string" ? this.parseVariableString(e) : typeof e != "object" ? e : Array.isArray(e) ? e.map((o) => this.parseValue(o)) : Object.entries(e).reduce((o, [t, n]) => ({ ...o, [t]: this.parseValue(n) }), {}));
270
271
  }
271
272
  getTokensFromFile(e, o) {
272
- return Object.entries(e).reduce((r, [n, s]) => "$type" in s && "$value" in s ? {
273
- ...r,
273
+ return Object.entries(e).reduce((t, [n, s]) => "$type" in s && "$value" in s ? {
274
+ ...t,
274
275
  [this.normalizeKey(n)]: {
275
276
  type: s.$type,
276
277
  description: s.$description,
277
278
  value: o ? { [this.normalizeKey(o)]: this.parseValue(s.$value) } : this.parseValue(s.$value)
278
279
  }
279
- } : { ...r, [this.normalizeKey(n)]: this.getTokensFromFile(s, o) }, {});
280
+ } : { ...t, [this.normalizeKey(n)]: this.getTokensFromFile(s, o) }, {});
280
281
  }
281
- processTokensFile(e, o, r) {
282
- const n = this.normalizeKey(r), s = this.getTokensFromFile(e, o);
282
+ processTokensFile(e, o, t) {
283
+ const n = this.normalizeKey(t), s = this.getTokensFromFile(e, o);
283
284
  return { [n]: s };
284
285
  }
285
286
  /**
@@ -287,10 +288,10 @@ class be {
287
288
  */
288
289
  async loadVariableFiles(e) {
289
290
  return Promise.all(
290
- e.map(async ({ fileName: o, modeName: r, collectionName: n }) => {
291
+ e.map(async ({ fileName: o, modeName: t, collectionName: n }) => {
291
292
  try {
292
- const s = k.join(this.tokensDir, o), a = await d.readJson(s);
293
- return this.processTokensFile(a, r, n);
293
+ const s = k.join(this.tokensDir, o), a = await y.readJson(s);
294
+ return this.processTokensFile(a, t, n);
294
295
  } catch (s) {
295
296
  return console.warn(`Failed to load variable file: ${k.join(this.tokensDir, o)}`, s), {};
296
297
  }
@@ -298,15 +299,15 @@ class be {
298
299
  );
299
300
  }
300
301
  mergeVariables(e) {
301
- return e.reduce((o, r) => H(o, r), {});
302
+ return e.reduce((o, t) => H(o, t), {});
302
303
  }
303
304
  /**
304
305
  * Loads and processes all token variables from manifest collections
305
306
  */
306
307
  async loadTokenVariables(e) {
307
308
  try {
308
- const o = this.createVariableFileList(e), r = await this.loadVariableFiles(o);
309
- return this.mergeVariables(r);
309
+ const o = this.createVariableFileList(e), t = await this.loadVariableFiles(o);
310
+ return this.mergeVariables(t);
310
311
  } catch (o) {
311
312
  throw new Error(`Failed to load token variables from ${this.tokensDir}: ${o}`);
312
313
  }
@@ -316,7 +317,7 @@ class be {
316
317
  */
317
318
  createStyleFileList(e) {
318
319
  return Object.entries(e).flatMap(
319
- ([o, r]) => (r == null ? void 0 : r.map((n) => ({
320
+ ([o, t]) => (t == null ? void 0 : t.map((n) => ({
320
321
  styleType: o,
321
322
  fileName: n
322
323
  }))) || []
@@ -327,18 +328,18 @@ class be {
327
328
  */
328
329
  async loadStyleFiles(e) {
329
330
  return (await Promise.all(
330
- e.map(async ({ styleType: r, fileName: n }) => {
331
+ e.map(async ({ styleType: t, fileName: n }) => {
331
332
  try {
332
- const s = k.join(this.tokensDir, n), a = await d.readJson(s);
333
- return { styleType: r, styleTokens: a };
333
+ const s = k.join(this.tokensDir, n), a = await y.readJson(s);
334
+ return { styleType: t, styleTokens: a };
334
335
  } catch (s) {
335
- return console.warn(`Failed to load style file: ${k.join(this.tokensDir, n)}`, s), { styleType: r, styleTokens: {} };
336
+ return console.warn(`Failed to load style file: ${k.join(this.tokensDir, n)}`, s), { styleType: t, styleTokens: {} };
336
337
  }
337
338
  })
338
339
  )).reduce(
339
- (r, n) => ({ ...r, [n.styleType]: this.getTokensFromFile(n.styleTokens, "") }),
340
+ (t, n) => ({ ...t, [n.styleType]: this.getTokensFromFile(n.styleTokens, "") }),
340
341
  {
341
- ...R
342
+ ...K
342
343
  }
343
344
  );
344
345
  }
@@ -346,13 +347,13 @@ class be {
346
347
  * Loads and processes all style tokens from manifest
347
348
  */
348
349
  async loadStyles(e) {
349
- if (!e) return { ...R };
350
+ if (!e) return { ...K };
350
351
  const o = this.createStyleFileList(e);
351
352
  return await this.loadStyleFiles(o);
352
353
  }
353
354
  async load() {
354
355
  if (this.loaded) return;
355
- const e = await d.readJson(this.manifestPath);
356
+ const e = await y.readJson(this.manifestPath);
356
357
  if (!e)
357
358
  throw new Error(`Failed to load manifest file from: ${this.manifestPath}`);
358
359
  this.variables = await this.loadTokenVariables(e.collections), this.styles = await this.loadStyles(e.styles), this.loaded = !0;
@@ -397,9 +398,9 @@ class be {
397
398
  */
398
399
  resolveVariableValue(e) {
399
400
  if (typeof e == "object")
400
- return Object.keys(e).reduce((o, r) => {
401
- const n = e[r], s = this.resolveVariableValueString(n, r);
402
- return s && (o[r] = s), o;
401
+ return Object.keys(e).reduce((o, t) => {
402
+ const n = e[t], s = this.resolveVariableValueString(n, t);
403
+ return s && (o[t] = s), o;
403
404
  }, {});
404
405
  }
405
406
  /**
@@ -410,7 +411,7 @@ class be {
410
411
  */
411
412
  resolveVariableValueString(e, o) {
412
413
  if (!this.isVariableReference(e)) return e;
413
- const r = this.getVariablePath(e), n = this.getToken(r, o);
414
+ const t = this.getVariablePath(e), n = this.getToken(t, o);
414
415
  if (n)
415
416
  return this.resolveVariableValueString(n, o);
416
417
  }
@@ -422,8 +423,8 @@ class be {
422
423
  getToken(e, o) {
423
424
  if (!this.loaded || !this.variables)
424
425
  throw new Error("Tokens not loaded. Call load() first.");
425
- for (const r of Object.values(this.variables)) {
426
- const n = q(r, e);
426
+ for (const t of Object.values(this.variables)) {
427
+ const n = q(t, e);
427
428
  if (n != null && n.value && typeof n.value == "object") {
428
429
  if (o) return n.value[o];
429
430
  {
@@ -434,36 +435,38 @@ class be {
434
435
  }
435
436
  }
436
437
  }
437
- const Kt = async () => {
438
- const e = await new j().load();
438
+ const It = async () => {
439
+ const e = await new v().load();
439
440
  if (!e)
440
- throw new Error("Заполнить ошибку через нейронку");
441
- const { figmaToken: o, fileId: r, modules: n, manifest: s } = e, a = new P(o, r), l = new be(s);
442
- s && d.exists(s) && await l.load(), await Promise.all(n.map((i) => i.executor({ figmaApiClient: a, tokenManagerClient: l })));
443
- }, Lt = async () => {
444
- await j.create(), console.log("\x1B[32m%s\x1B[0m", "✔️ Configuration file created gts.config.ts");
445
- }, me = ["xxxl", "xxl", "xl", "lg", "md", "sm", "xs", "xxs", "xxxs"], we = (t) => parseInt(t.value, 10), ke = (t) => t.reduce(
441
+ throw new Error(
442
+ 'Failed to load gts.config.ts. Run "npx gts-init" to create it, or ensure the file exists and default-exports a valid configuration.'
443
+ );
444
+ const { figmaToken: o, fileId: t, modules: n, manifest: s } = e, a = new O(o, t), i = new be(s);
445
+ s && y.exists(s) && await i.load(), await Promise.all(n.map((l) => l.executor({ figmaApiClient: a, tokenManagerClient: i })));
446
+ }, zt = async () => {
447
+ await v.create(), console.log("\x1B[32m%s\x1B[0m", "✔️ Configuration file created gts.config.ts");
448
+ }, we = ["xxxl", "xxl", "xl", "lg", "md", "sm", "xs", "xxs", "xxxs"], ke = (r) => parseInt(r.value, 10), $e = (r) => r.reduce(
446
449
  (e, o) => ({
447
450
  ...e,
448
- [o.name]: we(o)
451
+ [o.name]: ke(o)
449
452
  }),
450
453
  {}
451
- ), $e = async (t, e) => {
452
- await d.delete(t, e);
453
- }, Se = async (t, e, o) => {
454
- await d.write(t, e, { directory: o });
455
- }, N = async (t, e, o) => {
456
- await $e(t, o), await Se(t, e, o);
457
- }, Te = (t) => {
458
- const e = t.map(({ name: o, value: r }) => ` --${o}: ${r};`);
454
+ ), Se = async (r, e) => {
455
+ await y.delete(r, e);
456
+ }, Te = async (r, e, o) => {
457
+ await y.write(r, e, { directory: o });
458
+ }, F = async (r, e, o) => {
459
+ await Se(r, o), await Te(r, e, o);
460
+ }, je = (r) => {
461
+ const e = r.map(({ name: o, value: t }) => ` --${o}: ${t};`);
459
462
  return e.length ? `.breakpoint-variables {
460
463
  ${e.join(`
461
464
  `)}
462
465
  }
463
466
  ` : "";
464
- }, je = (t) => {
465
- var r;
466
- const e = t.map(({ name: n, value: s }) => ` ${n}: ${s}`), o = (r = t.at(-1)) == null ? void 0 : r.name;
467
+ }, ve = (r) => {
468
+ var t;
469
+ const e = r.map(({ name: n, value: s }) => ` ${n}: ${s}`), o = (t = r.at(-1)) == null ? void 0 : t.name;
467
470
  return !e.length || !o ? "" : `$breakpointList: (
468
471
  ${e.join(`,
469
472
  `)}
@@ -471,8 +474,8 @@ ${e.join(`,
471
474
 
472
475
  $defaultBreakpoint: '${o}';
473
476
  `;
474
- }, ve = (t) => [
475
- `const breakpoints = ${JSON.stringify(t, null, 4)} as const;`,
477
+ }, Ne = (r) => [
478
+ `const breakpoints = ${JSON.stringify(r, null, 4)} as const;`,
476
479
  "",
477
480
  "const BREAKPOINTS_NAMES = Object.keys(breakpoints);",
478
481
  "",
@@ -483,20 +486,20 @@ $defaultBreakpoint: '${o}';
483
486
  "export type { BreakpointsKeysType, AllowMedia };",
484
487
  ""
485
488
  ].join(`
486
- `), Me = async ({ breakpointTokens: t, dir: e }) => {
487
- const o = ke(t), r = Te(t), n = je(t), s = ve(o);
489
+ `), Me = async ({ breakpointTokens: r, dir: e }) => {
490
+ const o = $e(r), t = je(r), n = ve(r), s = Ne(o);
488
491
  await Promise.all([
489
- N("styles.css", r, e),
490
- N("styles.scss", n, e),
491
- N("index.ts", s, e)
492
+ F("styles.css", t, e),
493
+ F("styles.scss", n, e),
494
+ F("index.ts", s, e)
492
495
  ]);
493
- }, Ce = (t, e) => {
494
- const o = Object.keys(t).filter((s) => !isNaN(Number(s))).sort((s, a) => Number(s) - Number(a));
496
+ }, Ve = (r, e) => {
497
+ const o = Object.keys(r).filter((s) => !isNaN(Number(s))).sort((s, a) => Number(s) - Number(a));
495
498
  if (o.length > e.length)
496
499
  throw new Error(
497
500
  `Not enough breakpoint names provided. Found ${o.length} breakpoints in data, but only ${e.length} names specified: ${e.join(", ")}`
498
501
  );
499
- const n = Object.keys(t).filter((s) => isNaN(Number(s)));
502
+ const n = Object.keys(r).filter((s) => isNaN(Number(s)));
500
503
  if (n.length > 0)
501
504
  throw new Error(
502
505
  `Found non-numeric breakpoint keys in grid data: ${n.join(", ")}. All breakpoint keys must be numeric values.`
@@ -505,22 +508,22 @@ $defaultBreakpoint: '${o}';
505
508
  name: e[e.length - 1 - a] || `bp-${s}`,
506
509
  value: s
507
510
  }));
508
- }, Ut = ({
509
- input: t = {},
511
+ }, Gt = ({
512
+ input: r = {},
510
513
  output: { dir: e }
511
514
  }) => ({
512
515
  name: "breakpoints/tokenManager",
513
516
  executor: async ({ tokenManagerClient: o }) => {
514
517
  try {
515
518
  console.log("[breakpoints/tokenManager] Generating breakpoints from TokenManager...");
516
- const { names: r = me } = t;
519
+ const { names: t = we } = r;
517
520
  if (!o.isLoaded())
518
521
  throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
519
522
  const n = o.getStyles();
520
523
  if (!n.grid)
521
524
  throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
522
525
  console.log("[breakpoints/tokenManager] Extracting breakpoints from grid styles...");
523
- const s = Ce(n.grid, r);
526
+ const s = Ve(n.grid, t);
524
527
  if (!s.length) {
525
528
  console.warn("[breakpoints/tokenManager] No breakpoints found in grid styles.");
526
529
  return;
@@ -531,171 +534,171 @@ $defaultBreakpoint: '${o}';
531
534
  breakpointTokens: s,
532
535
  dir: e
533
536
  }), console.log("[breakpoints/tokenManager] ✅ Successfully generated breakpoint files");
534
- } catch (r) {
535
- const n = r instanceof Error ? r.message : String(r);
536
- throw console.error("[breakpoints/tokenManager] ❌ Failed to generate breakpoints:", n), r instanceof Error && r.stack && console.error("[breakpoints/tokenManager] Stack trace:", r.stack), r;
537
+ } catch (t) {
538
+ const n = t instanceof Error ? t.message : String(t);
539
+ throw console.error("[breakpoints/tokenManager] ❌ Failed to generate breakpoints:", n), t instanceof Error && t.stack && console.error("[breakpoints/tokenManager] Stack trace:", t.stack), t;
537
540
  }
538
541
  }
539
- }), Ve = "styles.css", Fe = "index.ts", A = (t, e) => {
542
+ }), Ce = "styles.css", Fe = "index.ts", A = (r, e) => {
540
543
  if (!e.length) return "";
541
- const o = e.map((r) => ` ${r}`).join(`
544
+ const o = e.map((t) => ` ${t}`).join(`
542
545
  `);
543
- return `${t} {
546
+ return `${r} {
544
547
  ${o}
545
548
  }`;
546
- }, Ne = (t) => `.${t.replace(/\s+/g, "-").toLowerCase()}`, Q = (t) => `--cl-${t}`, xe = (t) => t.reduce(
549
+ }, xe = (r) => `.${r.replace(/\s+/g, "-").toLowerCase()}`, Z = (r) => `--cl-${r}`, Pe = (r) => r.reduce(
547
550
  (e, o) => {
548
- const r = Q(o.name);
551
+ const t = Z(o.name);
549
552
  return typeof o.value == "object" ? Object.entries(o.value).forEach(([n, s]) => {
550
- e[n] || (e[n] = []), e[n].push(`${r}: ${s};`);
551
- }) : e.root.push(`${r}: ${o.value};`), e;
553
+ e[n] || (e[n] = []), e[n].push(`${t}: ${s};`);
554
+ }) : e.root.push(`${t}: ${o.value};`), e;
552
555
  },
553
556
  { root: [] }
554
- ), Oe = (t) => {
555
- const e = A(".color-variables", t.root), o = Object.entries(t).reduce((r, [n, s]) => {
556
- if (n === "root" || !s.length) return r;
557
- const a = A(Ne(`${n}-color-variables`), s);
558
- return a && r.push(a), r;
557
+ ), Oe = (r) => {
558
+ const e = A(".color-variables", r.root), o = Object.entries(r).reduce((t, [n, s]) => {
559
+ if (n === "root" || !s.length) return t;
560
+ const a = A(xe(`${n}-color-variables`), s);
561
+ return a && t.push(a), t;
559
562
  }, []).join(`
560
563
 
561
564
  `);
562
565
  return [e, o].filter(Boolean).join(`
563
566
 
564
567
  `);
565
- }, Pe = (t) => `${`const colors = {
566
- ${t.map((r) => ` '${r.name}': 'var(${Q(r.name)})'`).join(`,
568
+ }, Ee = (r) => `${`const colors = {
569
+ ${r.map((t) => ` '${t.name}': 'var(${Z(t.name)})'`).join(`,
567
570
  `)}
568
571
  } as const;`}
569
572
 
570
573
  type ColorsKeysType = keyof typeof colors;
571
574
 
572
575
  export { colors, type ColorsKeysType };
573
- `, Ee = async ({
574
- tsContent: t,
576
+ `, Be = async ({
577
+ tsContent: r,
575
578
  cssContent: e,
576
579
  dir: o
577
580
  }) => {
578
- await d.delete(o);
579
- const r = d.write(Fe, t, { directory: o }), n = d.write(Ve, e, { directory: o });
580
- await Promise.all([r, n]);
581
- }, Be = async ({ colorTokens: t, dir: e }) => {
582
- const o = xe(t), r = Oe(o), n = Pe(t);
583
- await Ee({ tsContent: n, cssContent: r, dir: e });
584
- }, v = (t) => t.reduce((e, o) => {
585
- const r = Number((o.position * 100).toFixed(1));
586
- return [...e, `${o.color}${r > 0 && r < 100 ? ` ${r}%` : ""}`];
587
- }, []).join(", "), Re = (t) => {
588
- const e = v(t.stops);
589
- return `linear-gradient(${t.angle}deg, ${e})`;
590
- }, Ae = (t) => `radial-gradient(circle, ${v(t.stops)})`, De = (t) => {
591
- const e = v(t.stops);
592
- return `conic-gradient(from ${t.angle}deg, ${e})`;
593
- }, Ke = (t) => {
594
- const e = v(t.stops);
595
- return `linear-gradient(${t.angle}deg, ${e})`;
596
- }, D = (t) => typeof t == "string" ? t : t.type === "linear" ? Re(t) : t.type === "radial" ? Ae(t) : t.type === "conic" ? De(t) : t.type === "diamond" ? Ke(t) : "", Z = (t, e) => Object.keys(t).reduce(
597
- (o, r) => {
598
- const n = t[r], s = e ? `${e}-${r}` : r;
581
+ await y.delete(o);
582
+ const t = y.write(Fe, r, { directory: o }), n = y.write(Ce, e, { directory: o });
583
+ await Promise.all([t, n]);
584
+ }, Ke = async ({ colorTokens: r, dir: e }) => {
585
+ const o = Pe(r), t = Oe(o), n = Ee(r);
586
+ await Be({ tsContent: n, cssContent: t, dir: e });
587
+ }, N = (r) => r.reduce((e, o) => {
588
+ const t = Number((o.position * 100).toFixed(1));
589
+ return [...e, `${o.color}${t > 0 && t < 100 ? ` ${t}%` : ""}`];
590
+ }, []).join(", "), Ae = (r) => {
591
+ const e = N(r.stops);
592
+ return `linear-gradient(${r.angle}deg, ${e})`;
593
+ }, Re = (r) => `radial-gradient(circle, ${N(r.stops)})`, De = (r) => {
594
+ const e = N(r.stops);
595
+ return `conic-gradient(from ${r.angle}deg, ${e})`;
596
+ }, Ue = (r) => {
597
+ const e = N(r.stops);
598
+ return `linear-gradient(${r.angle}deg, ${e})`;
599
+ }, R = (r) => typeof r == "string" ? r : r.type === "linear" ? Ae(r) : r.type === "radial" ? Re(r) : r.type === "conic" ? De(r) : r.type === "diamond" ? Ue(r) : "", Q = (r, e) => Object.keys(r).reduce(
600
+ (o, t) => {
601
+ const n = r[t], s = e ? `${e}-${t}` : t;
599
602
  if (n && typeof n == "object" && "type" in n && "value" in n) {
600
- const l = Object.keys(n.value), i = l.length > 1 ? n.value : n.value[l[0]], c = typeof i == "object" ? Object.keys(i).reduce(
601
- (f, y) => ({
602
- ...f,
603
- [y]: D(i[y])
603
+ const i = Object.keys(n.value), l = i.length > 1 ? n.value : n.value[i[0]], c = typeof l == "object" ? Object.keys(l).reduce(
604
+ (d, f) => ({
605
+ ...d,
606
+ [f]: R(l[f])
604
607
  }),
605
608
  {}
606
- ) : D(i), u = { [s]: c };
609
+ ) : R(l), u = { [s]: c };
607
610
  return { ...o, ...u };
608
611
  }
609
- const a = Z(n, s);
612
+ const a = Q(n, s);
610
613
  return { ...o, ...a };
611
614
  },
612
615
  {}
613
- ), X = (t, e) => Object.keys(t).reduce((o, r) => {
614
- const n = t[r];
616
+ ), X = (r, e) => Object.keys(r).reduce((o, t) => {
617
+ const n = r[t];
615
618
  if (n.type && n.type !== "color") return o;
616
619
  if (n.type && n.value) {
617
- const a = typeof n.value == "string" ? e.resolveVariableValueString(n.value, r) : e.resolveVariableValue(n.value);
618
- return a ? { ...o, [r]: { ...n, value: a } } : o;
620
+ const a = typeof n.value == "string" ? e.resolveVariableValueString(n.value, t) : e.resolveVariableValue(n.value);
621
+ return a ? { ...o, [t]: { ...n, value: a } } : o;
619
622
  }
620
623
  const s = X(n, e);
621
- return s ? { ...o, [r]: s } : o;
622
- }, {}), Wt = ({ input: t = {}, output: { dir: e } }) => ({
624
+ return s ? { ...o, [t]: s } : o;
625
+ }, {}), Jt = ({ input: r = {}, output: { dir: e } }) => ({
623
626
  name: "colors/tokenManager",
624
627
  executor: async ({ tokenManagerClient: o }) => {
625
628
  try {
626
629
  console.log("[colors/tokenManager] Generating colors from TokenManager...");
627
- const { includeVariables: r, includeStyles: n = !0 } = t;
628
- if (!(r != null && r.length) && !n)
630
+ const { includeVariables: t, includeStyles: n = !0 } = r;
631
+ if (!(t != null && t.length) && !n)
629
632
  throw new Error("Either includeVariables or includeStyles must be enabled");
630
633
  if (!o.isLoaded())
631
634
  throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
632
635
  const s = [], a = o.getVariables();
633
636
  if (n) {
634
- const i = o.getStyles();
635
- console.log("[colors/tokenManager] Processing styles for colors..."), i.color && s.push(i.color);
637
+ const l = o.getStyles();
638
+ console.log("[colors/tokenManager] Processing styles for colors..."), l.color && s.push(l.color);
636
639
  }
637
- if (r != null && r.length) {
638
- console.log(`[colors/tokenManager] Processing ${r.length} variable groups...`);
639
- const i = r.map((c) => a[c]).filter(Boolean);
640
- s.push(...i);
640
+ if (t != null && t.length) {
641
+ console.log(`[colors/tokenManager] Processing ${t.length} variable groups...`);
642
+ const l = t.map((c) => a[c]).filter(Boolean);
643
+ s.push(...l);
641
644
  }
642
- const l = s.map((i) => X(i, o)).flatMap(
643
- (i) => Object.entries(Z(i, "")).reduce(
644
- (c, [u, f]) => [...c, { name: u, value: f }],
645
+ const i = s.map((l) => X(l, o)).flatMap(
646
+ (l) => Object.entries(Q(l, "")).reduce(
647
+ (c, [u, d]) => [...c, { name: u, value: d }],
645
648
  []
646
649
  )
647
650
  );
648
- if (l.length === 0) {
651
+ if (i.length === 0) {
649
652
  console.warn("[colors/tokenManager] No color tokens generated");
650
653
  return;
651
654
  }
652
- console.log(`[colors/tokenManager] Generated ${l.length} color tokens`), console.log(`[colors/tokenManager] Writing files to ${e}...`), await Be({
653
- colorTokens: l,
655
+ console.log(`[colors/tokenManager] Generated ${i.length} color tokens`), console.log(`[colors/tokenManager] Writing files to ${e}...`), await Ke({
656
+ colorTokens: i,
654
657
  dir: e
655
658
  }), console.log("[colors/tokenManager] ✅ Successfully generated color files");
656
- } catch (r) {
657
- const n = r instanceof Error ? r.message : String(r);
658
- throw console.error("[colors/tokenManager] ❌ Failed to generate colors:", n), r instanceof Error && r.stack && console.error("[colors/tokenManager] Stack trace:", r.stack), r;
659
+ } catch (t) {
660
+ const n = t instanceof Error ? t.message : String(t);
661
+ throw console.error("[colors/tokenManager] ❌ Failed to generate colors:", n), t instanceof Error && t.stack && console.error("[colors/tokenManager] Stack trace:", t.stack), t;
659
662
  }
660
663
  }
661
- }), Le = (t) => ` @media (width <= ${t.breakpoint}px) {
664
+ }), Le = (r) => ` @media (width <= ${r.breakpoint}px) {
662
665
  .container {
663
- padding-left: ${t.offset};
664
- padding-right: ${t.offset};
666
+ padding-left: ${r.offset};
667
+ padding-right: ${r.offset};
665
668
  }
666
669
 
667
670
  .containerTablet {
668
- padding-left: ${t.offset};
669
- padding-right: ${t.offset};
671
+ padding-left: ${r.offset};
672
+ padding-right: ${r.offset};
670
673
  }
671
- }`, Ue = (t, e) => {
672
- const o = e || "components", r = t.map((n) => Le(n)).join(`
674
+ }`, We = (r, e) => {
675
+ const o = e || "components", t = r.map((n) => Le(n)).join(`
673
676
 
674
677
  `);
675
678
  return `@layer ${o} {
676
- ${r}
679
+ ${t}
677
680
  }`;
678
- }, We = () => `import styles from './styles.module.css';
681
+ }, Ie = () => `import styles from './styles.module.css';
679
682
 
680
- export const conatinerClassName = styles.container;
681
- export const conatinerTabletClassName = styles.containerTablet;
682
- `, K = async (t, e, o) => {
683
- await d.delete(t, o), await d.write(t, e, { directory: o });
684
- }, ze = async ({ containerTokens: t, dir: e, layer: o }) => {
685
- const r = Ue(t, o), n = We();
686
- await K("styles.module.css", r, e), await K("index.ts", n, e);
687
- }, Ie = (t) => {
688
- const e = t.trim().toLowerCase();
683
+ export const containerClassName = styles.container;
684
+ export const containerTabletClassName = styles.containerTablet;
685
+ `, D = async (r, e, o) => {
686
+ await y.delete(r, o), await y.write(r, e, { directory: o });
687
+ }, ze = async ({ containerTokens: r, dir: e, layer: o }) => {
688
+ const t = We(r, o), n = Ie();
689
+ await D("styles.module.css", t, e), await D("index.ts", n, e);
690
+ }, Ge = (r) => {
691
+ const e = r.trim().toLowerCase();
689
692
  return e === "0" || e === "0px";
690
- }, Ge = (t, e) => Object.keys(t).filter((s) => !isNaN(Number(s))).sort((s, a) => Number(a) - Number(s)).reduce((s, a) => {
691
- const l = t[a];
692
- if (!l || !("value" in l) || !Array.isArray(l.value))
693
+ }, Je = (r, e) => Object.keys(r).filter((s) => !isNaN(Number(s))).sort((s, a) => Number(a) - Number(s)).reduce((s, a) => {
694
+ const i = r[a];
695
+ if (!i || !("value" in i) || !Array.isArray(i.value))
693
696
  return s;
694
- const i = l.value.find((u) => u.pattern === "columns");
695
- if (!(i != null && i.offset))
697
+ const l = i.value.find((u) => u.pattern === "columns");
698
+ if (!(l != null && l.offset))
696
699
  return s;
697
- const c = e.resolveVariableValueString(i.offset);
698
- return !c || typeof c != "string" || Ie(c) ? s : [
700
+ const c = e.resolveVariableValueString(l.offset);
701
+ return !c || typeof c != "string" || Ge(c) ? s : [
699
702
  ...s,
700
703
  {
701
704
  breakpoint: Number(a),
@@ -703,24 +706,24 @@ export const conatinerTabletClassName = styles.containerTablet;
703
706
  }
704
707
  ];
705
708
  }, []).reduce((s, a) => {
706
- const l = s[s.length - 1];
707
- return l && x(l.offset, a.offset) || s.push(a), s;
708
- }, []), zt = ({
709
- input: t = {},
709
+ const i = s[s.length - 1];
710
+ return i && x(i.offset, a.offset) || s.push(a), s;
711
+ }, []), qt = ({
712
+ input: r = {},
710
713
  output: { dir: e }
711
714
  }) => ({
712
715
  name: "container/tokenManager",
713
716
  executor: async ({ tokenManagerClient: o }) => {
714
717
  try {
715
718
  console.log("[container/tokenManager] Generating container styles...");
716
- const { layer: r } = t;
719
+ const { layer: t } = r;
717
720
  if (!o.isLoaded())
718
721
  throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
719
722
  console.log("[container/tokenManager] Extracting container tokens...");
720
723
  const n = o.getStyles();
721
724
  if (!n.grid)
722
725
  throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
723
- const s = Ge(n.grid, o);
726
+ const s = Je(n.grid, o);
724
727
  if (!s.length) {
725
728
  console.warn("[container/tokenManager] No container tokens found.");
726
729
  return;
@@ -730,90 +733,90 @@ export const conatinerTabletClassName = styles.containerTablet;
730
733
  ), console.log(`[container/tokenManager] Writing files to ${e}...`), await ze({
731
734
  containerTokens: s,
732
735
  dir: e,
733
- layer: r
736
+ layer: t
734
737
  }), console.log("[container/tokenManager] ✅ Successfully generated container files");
735
- } catch (r) {
736
- const n = r instanceof Error ? r.message : String(r);
737
- throw console.error("[container/tokenManager] ❌ Failed to generate container:", n), r instanceof Error && r.stack && console.error("[container/tokenManager] Stack trace:", r.stack), r;
738
+ } catch (t) {
739
+ const n = t instanceof Error ? t.message : String(t);
740
+ throw console.error("[container/tokenManager] ❌ Failed to generate container:", n), t instanceof Error && t.stack && console.error("[container/tokenManager] Stack trace:", t.stack), t;
738
741
  }
739
742
  }
740
- }), Je = "styles.css", qe = "index.ts", L = (t, e) => {
743
+ }), qe = "styles.css", He = "index.ts", U = (r, e) => {
741
744
  if (!e.length) return "";
742
- const o = e.map((r) => ` ${r}`).join(`
745
+ const o = e.map((t) => ` ${t}`).join(`
743
746
  `);
744
- return `${t} {
747
+ return `${r} {
745
748
  ${o}
746
749
  }`;
747
- }, He = (t) => `.${t.replace(/\s+/g, "-").toLowerCase()}`, Y = (t) => `--${t}`, Qe = ({ offsetX: t, offsetY: e, blur: o, spread: r, color: n }) => `${t} ${e} ${o} ${r} ${n}`, Ze = (t) => t.reduce(
750
+ }, Ze = (r) => `.${r.replace(/\s+/g, "-").toLowerCase()}`, Y = (r) => `--${r}`, Qe = ({ offsetX: r, offsetY: e, blur: o, spread: t, color: n }) => `${r} ${e} ${o} ${t} ${n}`, Xe = (r) => r.reduce(
748
751
  (e, o) => {
749
- const r = Y(o.name);
750
- return typeof o.value != "object" ? (e.root.push(`${r}: ${o.value};`), e) : Object.entries(o.value).reduce((n, [s, a]) => {
751
- const l = n[s] ?? [];
752
- return { ...n, [s]: [...l, `${r}: ${a};`] };
752
+ const t = Y(o.name);
753
+ return typeof o.value != "object" ? (e.root.push(`${t}: ${o.value};`), e) : Object.entries(o.value).reduce((n, [s, a]) => {
754
+ const i = n[s] ?? [];
755
+ return { ...n, [s]: [...i, `${t}: ${a};`] };
753
756
  }, e);
754
757
  },
755
758
  { root: [] }
756
- ), Xe = (t) => {
757
- const e = L(".shadow-variables", t.root), o = Object.entries(t).reduce((r, [n, s]) => {
758
- if (n === "root" || !s.length) return r;
759
- const a = L(He(`${n}-shadow-variables`), s);
760
- return a && r.push(a), r;
759
+ ), Ye = (r) => {
760
+ const e = U(".shadow-variables", r.root), o = Object.entries(r).reduce((t, [n, s]) => {
761
+ if (n === "root" || !s.length) return t;
762
+ const a = U(Ze(`${n}-shadow-variables`), s);
763
+ return a && t.push(a), t;
761
764
  }, []).join(`
762
765
 
763
766
  `);
764
767
  return [e, o].filter(Boolean).join(`
765
768
 
766
769
  `);
767
- }, Ye = (t) => `${`const shadows = {
768
- ${t.map((r) => ` '${r.name}': 'var(${Y(r.name)})'`).join(`,
770
+ }, _e = (r) => `${`const shadows = {
771
+ ${r.map((t) => ` '${t.name}': 'var(${Y(t.name)})'`).join(`,
769
772
  `)}
770
773
  } as const;`}
771
774
 
772
775
  type ShadowsKeysType = keyof typeof shadows;
773
776
 
774
777
  export { shadows, type ShadowsKeysType };
775
- `, _e = async ({
776
- tsContent: t,
778
+ `, et = async ({
779
+ tsContent: r,
777
780
  cssContent: e,
778
781
  dir: o
779
782
  }) => {
780
- await d.delete(o);
781
- const r = d.write(qe, t, { directory: o }), n = d.write(Je, e, { directory: o });
782
- await Promise.all([r, n]);
783
- }, et = async ({ shadowTokens: t, dir: e }) => {
784
- const o = Ze(t), r = Xe(o), n = Ye(t);
785
- await _e({ tsContent: n, cssContent: r, dir: e });
786
- }, _ = (t, e) => Object.keys(t).reduce(
787
- (o, r) => {
788
- const n = t[r], s = e ? `${e}-${r}` : r;
783
+ await y.delete(o);
784
+ const t = y.write(He, r, { directory: o }), n = y.write(qe, e, { directory: o });
785
+ await Promise.all([t, n]);
786
+ }, tt = async ({ shadowTokens: r, dir: e }) => {
787
+ const o = Xe(r), t = Ye(o), n = _e(r);
788
+ await et({ tsContent: n, cssContent: t, dir: e });
789
+ }, _ = (r, e) => Object.keys(r).reduce(
790
+ (o, t) => {
791
+ const n = r[t], s = e ? `${e}-${t}` : t;
789
792
  if (n && typeof n == "object" && "type" in n && "value" in n) {
790
- const l = {
793
+ const i = {
791
794
  [s]: n.value.map(Qe).join(", ")
792
795
  };
793
- return { ...o, ...l };
796
+ return { ...o, ...i };
794
797
  }
795
798
  const a = _(n, s);
796
799
  return { ...o, ...a };
797
800
  },
798
801
  {}
799
- ), It = ({ input: t = {}, output: { dir: e } }) => ({
802
+ ), Ht = ({ input: r = {}, output: { dir: e } }) => ({
800
803
  name: "shadows/tokenManager",
801
804
  executor: async ({ tokenManagerClient: o }) => {
802
805
  try {
803
806
  console.log("[shadows/tokenManager] Generating shadows from TokenManager...");
804
- const { includeStyles: r = !0 } = t;
805
- if (!r)
807
+ const { includeStyles: t = !0 } = r;
808
+ if (!t)
806
809
  throw new Error("includeStyles must be enabled for shadows generation");
807
810
  if (!o.isLoaded())
808
811
  throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
809
812
  const n = [];
810
- if (r) {
813
+ if (t) {
811
814
  const a = o.getStyles();
812
815
  console.log("[shadows/tokenManager] Processing styles for shadows..."), a.effect && n.push(a.effect);
813
816
  }
814
817
  const s = n.flatMap(
815
818
  (a) => Object.entries(_(a, "")).reduce(
816
- (l, [i, c]) => [...l, { name: i, value: c }],
819
+ (i, [l, c]) => [...i, { name: l, value: c }],
817
820
  []
818
821
  )
819
822
  );
@@ -821,46 +824,46 @@ export { shadows, type ShadowsKeysType };
821
824
  console.warn("[shadows/tokenManager] No shadow tokens generated");
822
825
  return;
823
826
  }
824
- console.log(`[shadows/tokenManager] Generated ${s.length} shadow tokens`), console.log(`[shadows/tokenManager] Writing files to ${e}...`), await et({
827
+ console.log(`[shadows/tokenManager] Generated ${s.length} shadow tokens`), console.log(`[shadows/tokenManager] Writing files to ${e}...`), await tt({
825
828
  shadowTokens: s,
826
829
  dir: e
827
830
  }), console.log("[shadows/tokenManager] ✅ Successfully generated shadow files");
828
- } catch (r) {
829
- const n = r instanceof Error ? r.message : String(r);
830
- throw console.error("[shadows/tokenManager] ❌ Failed to generate shadows:", n), r instanceof Error && r.stack && console.error("[shadows/tokenManager] Stack trace:", r.stack), r;
831
+ } catch (t) {
832
+ const n = t instanceof Error ? t.message : String(t);
833
+ throw console.error("[shadows/tokenManager] ❌ Failed to generate shadows:", n), t instanceof Error && t.stack && console.error("[shadows/tokenManager] Stack trace:", t.stack), t;
831
834
  }
832
835
  }
833
- }), tt = "styles.module.css", rt = "index.ts", ot = "typography.ts", U = "sans-serif", W = (t, e) => {
836
+ }), rt = "styles.module.css", ot = "index.ts", nt = "typography.ts", L = "sans-serif", W = (r, e) => {
834
837
  if (!e.length) return "";
835
- const o = e.map((r) => ` ${r}`).join(`
838
+ const o = e.map((t) => ` ${t}`).join(`
836
839
  `);
837
- return `${t} {
840
+ return `${r} {
838
841
  ${o}
839
842
  }`;
840
- }, ee = (t, e) => {
841
- if (typeof t != "string") return t;
842
- const o = e[t] ?? t;
843
- return o.trim().toLowerCase().endsWith(U) ? o : `${o}, ${U}`;
844
- }, z = (t, e) => typeof t.fontFamily != "string" ? t : {
845
- ...t,
846
- fontFamily: ee(t.fontFamily, e)
847
- }, S = (t, e) => {
843
+ }, ee = (r, e) => {
844
+ if (typeof r != "string") return r;
845
+ const o = e[r] ?? r;
846
+ return o.trim().toLowerCase().endsWith(L) ? o : `${o}, ${L}`;
847
+ }, I = (r, e) => typeof r.fontFamily != "string" ? r : {
848
+ ...r,
849
+ fontFamily: ee(r.fontFamily, e)
850
+ }, T = (r, e) => {
848
851
  const o = {};
849
- return Object.entries(t).forEach(([r, n]) => {
850
- const s = r === "fontFamily" ? ee(n, e) : n, a = r.replace(/([A-Z])/g, "-$1").toLowerCase();
852
+ return Object.entries(r).forEach(([t, n]) => {
853
+ const s = t === "fontFamily" ? ee(n, e) : n, a = t.replace(/([A-Z])/g, "-$1");
851
854
  o[a] = s;
852
855
  }), o;
853
- }, nt = (t, e, o) => {
854
- const r = Object.keys(t.breakpoints), n = S(t.base, o);
855
- return r.reduce(
856
- (s, a, l) => {
857
- const i = S(t.breakpoints[a], o);
858
- return l ? [...s, { breakpoint: Number(e[a]), css: i }] : [
856
+ }, st = (r, e, o) => {
857
+ const t = Object.keys(r.breakpoints), n = T(r.base, o);
858
+ return t.reduce(
859
+ (s, a, i) => {
860
+ const l = T(r.breakpoints[a], o);
861
+ return i ? [...s, { breakpoint: Number(e[a]), css: l }] : [
859
862
  {
860
863
  breakpoint: null,
861
864
  css: {
862
865
  ...n,
863
- ...i
866
+ ...l
864
867
  }
865
868
  }
866
869
  ];
@@ -875,86 +878,86 @@ ${o}
875
878
  }, te = () => ({
876
879
  base: {},
877
880
  breakpoints: {}
878
- }), O = (t, e, o, r) => {
879
- Object.keys(r).length && (t.breakpoints[e] || (t.breakpoints[e] = {}), t.breakpoints[e][o] = {
880
- ...t.breakpoints[e][o],
881
- ...r
881
+ }), P = (r, e, o, t) => {
882
+ Object.keys(t).length && (r.breakpoints[e] || (r.breakpoints[e] = {}), r.breakpoints[e][o] = {
883
+ ...r.breakpoints[e][o],
884
+ ...t
882
885
  });
883
- }, T = (t, e, o, r) => {
884
- nt(e.value, o, r).forEach(({ breakpoint: s, css: a }) => {
886
+ }, j = (r, e, o, t) => {
887
+ st(e.value, o, t).forEach(({ breakpoint: s, css: a }) => {
885
888
  if (s === null) {
886
- t.base[e.name] = a;
889
+ r.base[e.name] = a;
887
890
  return;
888
891
  }
889
- O(t, s, e.name, a);
892
+ P(r, s, e.name, a);
890
893
  });
891
- }, re = (t) => {
892
- const e = I(t.base), o = Object.keys(t.breakpoints).map(Number).sort((r, n) => n - r).reduce((r, n) => {
893
- const s = t.breakpoints[n];
894
- return r + `@media (max-width: ${n}px) { ${I(s)} }`;
894
+ }, re = (r) => {
895
+ const e = z(r.base), o = Object.keys(r.breakpoints).map(Number).sort((t, n) => n - t).reduce((t, n) => {
896
+ const s = r.breakpoints[n];
897
+ return t + `@media (max-width: ${n}px) { ${z(s)} }`;
895
898
  }, "");
896
899
  return e + o;
897
- }, st = (t, e, o) => {
898
- const r = t.reduce((n, s) => (T(n, s, e, o), n), te());
899
- return re(r);
900
- }, I = (t) => Object.keys(t).reduce((e, o) => {
901
- const r = t[o], n = Object.keys(r).map((s) => `${s}: ${r[s]}`).join(";");
900
+ }, at = (r, e, o) => {
901
+ const t = r.reduce((n, s) => (j(n, s, e, o), n), te());
902
+ return re(t);
903
+ }, z = (r) => Object.keys(r).reduce((e, o) => {
904
+ const t = r[o], n = Object.keys(t).map((s) => `${s}: ${t[s]}`).join(";");
902
905
  return e + `.typo-${o} { ${n} }`;
903
- }, ""), G = (t) => {
904
- if (typeof t == "number") return Number.isFinite(t) ? t : null;
905
- const e = Number.parseFloat(t);
906
+ }, ""), G = (r) => {
907
+ if (typeof r == "number") return Number.isFinite(r) ? r : null;
908
+ const e = Number.parseFloat(r);
906
909
  return Number.isFinite(e) ? e : null;
907
- }, J = (t) => {
908
- if (typeof t == "number") return t / 16;
909
- const e = t.trim().toLowerCase();
910
+ }, J = (r) => {
911
+ if (typeof r == "number") return r / 16;
912
+ const e = r.trim().toLowerCase();
910
913
  if (e.endsWith("rem")) return G(e);
911
914
  if (e.endsWith("px")) {
912
915
  const o = G(e);
913
916
  return o === null ? null : o / 16;
914
917
  }
915
918
  return null;
916
- }, at = (t) => {
917
- const { minValueRem: e, maxValueRem: o, minVwRem: r, maxVwRem: n } = t, s = o - e;
918
- return `calc(${e}rem + ((100vw - ${r}rem) / (${n}rem - ${r}rem)) * ${s}rem)`;
919
- }, it = (t, e, o, r) => {
920
- const n = ["font-size", "line-height"], s = Object.entries(e.value.breakpoints).map(([p, b]) => {
921
- const w = Number.parseInt(o[p], 10);
922
- return { breakpointName: p, width: w, typography: b };
923
- }).filter((p) => Number.isFinite(p.width)).sort((p, b) => b.width - p.width);
919
+ }, it = (r) => {
920
+ const { minValueRem: e, maxValueRem: o, minVwRem: t, maxVwRem: n } = r, s = o - e;
921
+ return `calc(${e}rem + ((100vw - ${t}rem) / (${n}rem - ${t}rem)) * ${s}rem)`;
922
+ }, lt = (r, e, o, t) => {
923
+ const n = ["font-size", "line-height"], s = Object.entries(e.value.breakpoints).map(([g, h]) => {
924
+ const b = Number.parseInt(o[g], 10);
925
+ return { breakpointName: g, width: b, typography: h };
926
+ }).filter((g) => Number.isFinite(g.width)).sort((g, h) => h.width - g.width);
924
927
  if (s.length < 2) {
925
- T(t, e, o, r);
928
+ j(r, e, o, t);
926
929
  return;
927
930
  }
928
- const a = s[0], l = s[s.length - 1];
929
- if (a.width <= l.width) {
930
- T(t, e, o, r);
931
+ const a = s[0], i = s[s.length - 1];
932
+ if (a.width <= i.width) {
933
+ j(r, e, o, t);
931
934
  return;
932
935
  }
933
- const i = S(e.value.base, r), c = S(a.typography, r), u = S(l.typography, r), f = a.width / 16, y = l.width / 16;
934
- if (f === y) {
935
- T(t, e, o, r);
936
+ const l = T(e.value.base, t), c = T(a.typography, t), u = T(i.typography, t), d = a.width / 16, f = i.width / 16;
937
+ if (d === f) {
938
+ j(r, e, o, t);
936
939
  return;
937
940
  }
938
- t.base[e.name] = {
939
- ...i,
941
+ r.base[e.name] = {
942
+ ...l,
940
943
  ...c
941
944
  };
942
- const g = n.reduce((p, b) => {
943
- const w = c[b], M = u[b];
944
- if (w === void 0 || M === void 0 || w === M)
945
- return p;
946
- const E = J(w), B = J(M);
947
- return E === null || B === null ? p : {
948
- ...p,
949
- [b]: at({ minValueRem: B, maxValueRem: E, minVwRem: y, maxVwRem: f })
945
+ const m = n.reduce((g, h) => {
946
+ const b = c[h], S = u[h];
947
+ if (b === void 0 || S === void 0 || b === S)
948
+ return g;
949
+ const E = J(b), B = J(S);
950
+ return E === null || B === null ? g : {
951
+ ...g,
952
+ [h]: it({ minValueRem: B, maxValueRem: E, minVwRem: f, maxVwRem: d })
950
953
  };
951
954
  }, {});
952
- O(t, a.width, e.name, g), O(t, l.width, e.name, u);
953
- }, lt = (t, e, o, r) => {
954
- if (!r) return st(t, e, o);
955
- const n = t.reduce((s, a) => (it(s, a, e, o), s), te());
955
+ P(r, a.width, e.name, m), P(r, i.width, e.name, u);
956
+ }, ct = (r, e, o, t) => {
957
+ if (!t) return at(r, e, o);
958
+ const n = r.reduce((s, a) => (lt(s, a, e, o), s), te());
956
959
  return re(n);
957
- }, ct = (t) => t.length ? `import styles from './styles.module.css';
960
+ }, ut = (r) => r.length ? `import styles from './styles.module.css';
958
961
  import { typography } from './typography';
959
962
 
960
963
  type TypographyKeysType = keyof typeof typography;
@@ -962,16 +965,16 @@ type TypographyKeysType = keyof typeof typography;
962
965
  const getTypographyClass = (typographyKey: TypographyKeysType) => styles[\`typo-\${typographyKey}\`];
963
966
 
964
967
  export { typography, getTypographyClass, type TypographyKeysType };
965
- ` : "", ut = (t, e) => t.length ? `const typography = {
966
- ${t.map((r) => {
967
- const n = z(r.value.base, e), s = Object.entries(r.value.breakpoints).reduce(
968
- (a, [l, i]) => ({
968
+ ` : "", dt = (r, e) => r.length ? `const typography = {
969
+ ${r.map((t) => {
970
+ const n = I(t.value.base, e), s = Object.entries(t.value.breakpoints).reduce(
971
+ (a, [i, l]) => ({
969
972
  ...a,
970
- [l]: z(i, e)
973
+ [i]: I(l, e)
971
974
  }),
972
975
  {}
973
976
  );
974
- return ` '${r.name}': {
977
+ return ` '${t.name}': {
975
978
  base: ${JSON.stringify(n, null, 8).replace(/\n/g, `
976
979
  `)},
977
980
  breakpoints: ${JSON.stringify(s, null, 8).replace(/\n/g, `
@@ -982,71 +985,71 @@ ${t.map((r) => {
982
985
  } as const;
983
986
 
984
987
  export { typography };
985
- ` : "", dt = async ({
986
- indexTSContent: t,
988
+ ` : "", yt = async ({
989
+ indexTSContent: r,
987
990
  typographyTSContent: e,
988
991
  cssContent: o,
989
- dir: r
992
+ dir: t
990
993
  }) => {
991
- await d.delete(r);
992
- const n = d.write(rt, t, { directory: r }), s = d.write(ot, e, { directory: r }), a = d.write(tt, o, { directory: r });
994
+ await y.delete(t);
995
+ const n = y.write(ot, r, { directory: t }), s = y.write(nt, e, { directory: t }), a = y.write(rt, o, { directory: t });
993
996
  await Promise.all([n, s, a]);
994
997
  }, ft = async ({
995
- typographyTokens: t,
998
+ typographyTokens: r,
996
999
  dir: e,
997
1000
  breakpoints: o,
998
- fontFamily: r,
1001
+ fontFamily: t,
999
1002
  fluid: n
1000
1003
  }) => {
1001
- const s = lt(t, o, r, n), a = ut(t, r), l = ct(t);
1002
- await dt({ indexTSContent: l, typographyTSContent: a, cssContent: s, dir: e });
1003
- }, oe = (t, e, o) => Object.keys(t).reduce((r, n) => {
1004
- const s = t[n];
1005
- if (typeof s != "object" || Array.isArray(s)) return r;
1004
+ const s = ct(r, o, t, n), a = dt(r, t), i = ut(r);
1005
+ await yt({ indexTSContent: i, typographyTSContent: a, cssContent: s, dir: e });
1006
+ }, oe = (r, e, o) => Object.keys(r).reduce((t, n) => {
1007
+ const s = r[n];
1008
+ if (typeof s != "object" || Array.isArray(s)) return t;
1006
1009
  if (!("type" in s) || !("value" in s))
1007
- return { ...r, [n]: oe(s, e, o) };
1008
- if (s.type !== "typography") return r;
1009
- const a = s.value, l = Object.entries(a).reduce(
1010
- (i, [c, u]) => {
1011
- const f = Object.keys(o.breakpoints);
1012
- if (f.length)
1013
- f.forEach((y) => {
1014
- const g = e.resolveVariableValueString(u, y);
1015
- g && (g === u ? i.base = { ...i.base, [c]: g } : i.breakpoints[y] = { ...i.breakpoints[y], [c]: g });
1010
+ return { ...t, [n]: oe(s, e, o) };
1011
+ if (s.type !== "typography") return t;
1012
+ const a = s.value, i = Object.entries(a).reduce(
1013
+ (l, [c, u]) => {
1014
+ const d = Object.keys(o.breakpoints);
1015
+ if (d.length)
1016
+ d.forEach((f) => {
1017
+ const m = e.resolveVariableValueString(u, f);
1018
+ m && (m === u ? l.base = { ...l.base, [c]: m } : l.breakpoints[f] = { ...l.breakpoints[f], [c]: m });
1016
1019
  });
1017
1020
  else {
1018
- const y = e.resolveVariableValueString(u);
1019
- y && (i.base = { ...i.base, [c]: y });
1021
+ const f = e.resolveVariableValueString(u);
1022
+ f && (l.base = { ...l.base, [c]: f });
1020
1023
  }
1021
- return i;
1024
+ return l;
1022
1025
  },
1023
1026
  { base: {}, breakpoints: {} }
1024
1027
  );
1025
- return { ...r, [n]: { type: "typography", value: l } };
1026
- }, {}), ne = (t, e) => Object.keys(t).reduce((o, r) => {
1027
- const n = e ? `${e}-${r}` : r, s = t[r];
1028
+ return { ...t, [n]: { type: "typography", value: i } };
1029
+ }, {}), ne = (r, e) => Object.keys(r).reduce((o, t) => {
1030
+ const n = e ? `${e}-${t}` : t, s = r[t];
1028
1031
  if (!("type" in s) || !("value" in s))
1029
1032
  return { ...o, ...ne(s, n) };
1030
1033
  const a = s.value;
1031
1034
  return { ...o, [n]: a };
1032
- }, {}), Gt = ({ input: t, output: { dir: e } }) => ({
1035
+ }, {}), Zt = ({ input: r, output: { dir: e } }) => ({
1033
1036
  name: "typography/tokenManager",
1034
1037
  executor: async ({ tokenManagerClient: o }) => {
1035
1038
  try {
1036
1039
  console.log("[typography/tokenManager] Generating typography from TokenManager...");
1037
- const { breakpoints: r, fontFamily: n } = t, s = t.fluid ?? !0;
1040
+ const { breakpoints: t, fontFamily: n } = r, s = r.fluid ?? !0;
1038
1041
  if (!o.isLoaded())
1039
1042
  throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
1040
- const a = [], l = o.getStyles();
1041
- console.log("[typography/tokenManager] Processing styles for typography..."), l.text && a.push(l.text);
1042
- const i = a.reduce(
1043
- (u, f) => ({
1043
+ const a = [], i = o.getStyles();
1044
+ console.log("[typography/tokenManager] Processing styles for typography..."), i.text && a.push(i.text);
1045
+ const l = a.reduce(
1046
+ (u, d) => ({
1044
1047
  ...u,
1045
- ...oe(f, o, { breakpoints: t.breakpoints })
1048
+ ...oe(d, o, { breakpoints: r.breakpoints })
1046
1049
  }),
1047
1050
  {}
1048
- ), c = Object.entries(ne(i)).map(
1049
- ([u, f]) => ({ name: u, value: f })
1051
+ ), c = Object.entries(ne(l)).map(
1052
+ ([u, d]) => ({ name: u, value: d })
1050
1053
  );
1051
1054
  if (c.length === 0) {
1052
1055
  console.warn("[typography/tokenManager] No typography tokens generated");
@@ -1055,41 +1058,41 @@ export { typography };
1055
1058
  console.log(`[typography/tokenManager] Generated ${c.length} typography tokens`), console.log(`[typography/tokenManager] Writing files to ${e}...`), await ft({
1056
1059
  typographyTokens: c,
1057
1060
  dir: e,
1058
- breakpoints: r,
1061
+ breakpoints: t,
1059
1062
  fontFamily: n || {},
1060
1063
  fluid: s
1061
1064
  }), console.log("[typography/tokenManager] ✅ Successfully generated typography files");
1062
- } catch (r) {
1063
- const n = r instanceof Error ? r.message : String(r);
1064
- throw console.error("[typography/tokenManager] ❌ Failed to generate typography:", n), r instanceof Error && r.stack && console.error("[typography/tokenManager] Stack trace:", r.stack), r;
1065
+ } catch (t) {
1066
+ const n = t instanceof Error ? t.message : String(t);
1067
+ throw console.error("[typography/tokenManager] ❌ Failed to generate typography:", n), t instanceof Error && t.stack && console.error("[typography/tokenManager] Stack trace:", t.stack), t;
1065
1068
  }
1066
1069
  }
1067
- }), yt = (t) => typeof t == "object" && t !== null && "type" in t && "value" in t, gt = (t) => typeof t == "object" && t !== null && !Array.isArray(t), se = (t) => t.trim().split(".").map((e) => e.trim()).filter(Boolean), pt = (t, e) => {
1070
+ }), gt = (r) => typeof r == "object" && r !== null && "type" in r && "value" in r, pt = (r) => typeof r == "object" && r !== null && !Array.isArray(r), se = (r) => r.trim().split(".").map((e) => e.trim()).filter(Boolean), ht = (r, e) => {
1068
1071
  const o = se(e);
1069
1072
  if (!o.length)
1070
1073
  throw new Error("variablePath must contain at least one segment");
1071
- const r = q(t, o);
1072
- if (r === void 0)
1074
+ const t = q(r, o);
1075
+ if (t === void 0)
1073
1076
  throw new Error(`Variables subtree not found at path: ${o.join(".")}`);
1074
- return r;
1075
- }, ae = (t, e, o) => {
1076
- if (!t) return [];
1077
- if (yt(t)) {
1078
- if (t.type !== "dimension") return [];
1079
- const r = t.value, n = Object.keys(r).reduce((s, a) => {
1080
- const l = r[a], i = o.resolveVariableValueString(l, a);
1081
- return { ...s, [a]: i ?? l };
1077
+ return t;
1078
+ }, ae = (r, e, o) => {
1079
+ if (!r) return [];
1080
+ if (gt(r)) {
1081
+ if (r.type !== "dimension") return [];
1082
+ const t = r.value, n = Object.keys(t).reduce((s, a) => {
1083
+ const i = t[a], l = o.resolveVariableValueString(i, a);
1084
+ return { ...s, [a]: l ?? i };
1082
1085
  }, {});
1083
1086
  return [{ flatName: e, resolvedByMode: n }];
1084
1087
  }
1085
- return gt(t) ? Object.keys(t).flatMap((r) => {
1086
- const n = t[r], s = e ? `${e}-${r}` : r;
1088
+ return pt(r) ? Object.keys(r).flatMap((t) => {
1089
+ const n = r[t], s = e ? `${e}-${t}` : t;
1087
1090
  return ae(n, s, o);
1088
1091
  }) : [];
1089
- }, ht = (t, e) => ae(t, "", e), bt = (t, e) => typeof e == "string" ? t === e : e.test(t), mt = (t, e) => e != null && e.length ? t.filter(
1090
- (o) => e.some((r) => bt(o.flatName, r))
1091
- ) : t, ie = (t) => Object.keys(t).map((e) => ({ mode: e, widthPx: Number.parseInt(t[e], 10) })).filter((e) => Number.isFinite(e.widthPx)).sort((e, o) => o.widthPx - e.widthPx), wt = (t) => {
1092
- const e = se(t);
1092
+ }, mt = (r, e) => ae(r, "", e), bt = (r, e) => typeof e == "string" ? r === e : e.test(r), wt = (r, e) => e != null && e.length ? r.filter(
1093
+ (o) => e.some((t) => bt(o.flatName, t))
1094
+ ) : r, kt = (r) => Object.keys(r).map((e) => ({ mode: e, widthPx: Number.parseInt(r[e], 10) })).filter((e) => Number.isFinite(e.widthPx)).sort((e, o) => o.widthPx - e.widthPx), ie = (r) => {
1095
+ const e = se(r);
1093
1096
  if (!e.length)
1094
1097
  throw new Error("variablePath must contain at least one segment");
1095
1098
  const o = e[e.length - 1];
@@ -1097,152 +1100,162 @@ export { typography };
1097
1100
  variablesClassName: `${o}-variables`,
1098
1101
  variableNamePrefix: o
1099
1102
  };
1100
- }, le = (t) => {
1101
- const e = wt(t.variablePath), o = t.variableNamePrefix ?? e.variableNamePrefix, r = t.variablesClassName ?? `${o}-variables`;
1103
+ }, $t = (r, e) => {
1104
+ const t = ie(r.variablePath).variableNamePrefix, n = e.variablesClassName ?? `${t}-variables`;
1102
1105
  return {
1103
- variableNamePrefix: o,
1104
- variablesClassName: r
1106
+ variableNamePrefix: t,
1107
+ variablesClassName: n
1105
1108
  };
1106
- }, kt = (t, e) => t ? `--${t}-${e}` : `--${e}`, $t = (t, e) => Object.keys(e).reduce(
1107
- (o, r) => {
1108
- const n = Number(r);
1109
+ }, le = (r, e) => `${ie(r).variableNamePrefix}-${e}`, Qt = (r, e) => `--${le(r, e)}`, St = (r) => `--${r}`, ce = (r, e, o) => {
1110
+ const t = le(r.variablePath, o);
1111
+ if (!e.parseCssVariableName)
1112
+ return t;
1113
+ const n = e.parseCssVariableName({
1114
+ variablePath: r.variablePath,
1115
+ flatName: o,
1116
+ defaultName: t
1117
+ });
1118
+ return n.trim() ? n : t;
1119
+ }, Tt = (r, e) => Object.keys(e).reduce(
1120
+ (o, t) => {
1121
+ const n = Number(t);
1109
1122
  return { ...o, [n]: { ...o[n], ...e[n] } };
1110
1123
  },
1111
- { ...t }
1112
- ), St = (t, e, o) => {
1113
- const r = kt(o, t.flatName), n = ie(e);
1114
- if (Object.keys(e).length === 0 || n.length === 0) {
1115
- const i = Object.values(t.resolvedByMode)[0] ?? "";
1116
- return { base: { [r]: i }, byBreakpoint: {} };
1124
+ { ...r }
1125
+ ), jt = (r, e, o) => {
1126
+ const { breakpoints: t } = e, n = ce(e, o, r.flatName), s = St(n), a = kt(t);
1127
+ if (Object.keys(t).length === 0 || a.length === 0) {
1128
+ const u = Object.values(r.resolvedByMode)[0] ?? "";
1129
+ return { base: { [s]: u }, byBreakpoint: {} };
1117
1130
  }
1118
- const s = n.filter((i) => i.mode in t.resolvedByMode);
1119
- if (s.length === 0) {
1120
- const i = Object.values(t.resolvedByMode)[0] ?? "";
1121
- return { base: { [r]: i }, byBreakpoint: {} };
1131
+ const i = a.filter((u) => u.mode in r.resolvedByMode);
1132
+ if (i.length === 0) {
1133
+ const u = Object.values(r.resolvedByMode)[0] ?? "";
1134
+ return { base: { [s]: u }, byBreakpoint: {} };
1122
1135
  }
1123
- if (s.length === 1) {
1124
- const i = s[0], c = t.resolvedByMode[i.mode] ?? "";
1125
- return { base: { [r]: c }, byBreakpoint: {} };
1136
+ if (i.length === 1) {
1137
+ const u = i[0], d = r.resolvedByMode[u.mode] ?? "";
1138
+ return { base: { [s]: d }, byBreakpoint: {} };
1126
1139
  }
1127
- const a = t.resolvedByMode[s[0].mode] ?? "", l = s.slice(1).reduce((i, c, u) => {
1128
- const f = s[u].mode, y = t.resolvedByMode[f], g = t.resolvedByMode[c.mode];
1129
- if (g === void 0 || g === y) return i;
1130
- const p = c.widthPx, b = i[p] ?? {};
1131
- return { ...i, [p]: { ...b, [r]: g } };
1140
+ const l = r.resolvedByMode[i[0].mode] ?? "", c = i.slice(1).reduce((u, d, f) => {
1141
+ const m = i[f].mode, g = r.resolvedByMode[m], h = r.resolvedByMode[d.mode];
1142
+ if (h === void 0 || h === g) return u;
1143
+ const b = d.widthPx, S = u[b] ?? {};
1144
+ return { ...u, [b]: { ...S, [s]: h } };
1132
1145
  }, {});
1133
- return { base: { [r]: a }, byBreakpoint: l };
1134
- }, Tt = (t, e, o) => t.reduce(
1135
- (r, n) => {
1136
- const { base: s, byBreakpoint: a } = St(n, e, o);
1146
+ return { base: { [s]: l }, byBreakpoint: c };
1147
+ }, vt = (r, e, o) => r.reduce(
1148
+ (t, n) => {
1149
+ const { base: s, byBreakpoint: a } = jt(n, e, o);
1137
1150
  return {
1138
- base: { ...r.base, ...s },
1139
- breakpoints: $t(r.breakpoints, a)
1151
+ base: { ...t.base, ...s },
1152
+ breakpoints: Tt(t.breakpoints, a)
1140
1153
  };
1141
1154
  },
1142
1155
  { base: {}, breakpoints: {} }
1143
- ), jt = (t, e) => {
1144
- if (!t.length) return "";
1145
- const { breakpoints: o } = e, { variablesClassName: r, variableNamePrefix: n } = le(e), s = Tt(t, o, n), a = Object.keys(s.base).map((c) => ` ${c}: ${s.base[c]};`), l = W(`.${r}`, a), i = Object.keys(s.breakpoints).map(Number).sort((c, u) => u - c).map((c) => {
1146
- const u = s.breakpoints[c], f = Object.keys(u).map((g) => ` ${g}: ${u[g]};`), y = W(`.${r}`, f);
1147
- return `@media (max-width: ${c}px) {
1148
- ${y}
1156
+ ), Nt = (r, e, o) => {
1157
+ if (!r.length) return "";
1158
+ const { variablesClassName: t } = $t(e, o), n = vt(r, e, o), s = Object.keys(n.base).map((l) => ` ${l}: ${n.base[l]};`), a = W(`.${t}`, s), i = Object.keys(n.breakpoints).map(Number).sort((l, c) => c - l).map((l) => {
1159
+ const c = n.breakpoints[l], u = Object.keys(c).map((f) => ` ${f}: ${c[f]};`), d = W(`.${t}`, u);
1160
+ return `@media (max-width: ${l}px) {
1161
+ ${d}
1149
1162
  }`;
1150
1163
  }).filter(Boolean).join(`
1151
1164
 
1152
1165
  `);
1153
- return i ? `${l}
1154
-
1155
- ${i}` : l;
1156
- }, vt = (t, e) => {
1157
- const o = t.resolvedByMode, r = ie(e), n = Object.keys(e).length > 0 && r.length > 0;
1158
- return { breakpoints: (() => {
1159
- if (!n)
1160
- return Object.keys(o);
1161
- const l = [], i = /* @__PURE__ */ new Set();
1162
- return r.forEach(({ mode: c }) => {
1163
- c in o && (l.push(c), i.add(c));
1164
- }), Object.keys(o).forEach((c) => {
1165
- i.has(c) || (l.push(c), i.add(c));
1166
- }), l;
1167
- })().reduce((l, i) => {
1168
- const c = o[i];
1169
- return c === void 0 ? l : { ...l, [i]: c };
1170
- }, {}) };
1171
- }, Mt = (t, e) => {
1172
- const { breakpoints: o } = e;
1173
- return t.length ? `const utilities = {
1174
- ${t.map((n) => {
1175
- const s = vt(n, o), a = JSON.stringify(s, null, 8);
1176
- return ` '${n.flatName}': ${a.replace(/\n/g, `
1177
- `)}`;
1178
- }).join(`,
1179
- `)}
1180
- } as const;
1181
-
1182
- export { utilities };
1183
- ` : `const utilities = {} as const;
1166
+ return i ? `${a}
1184
1167
 
1185
- export { utilities };
1186
- `;
1187
- }, Ct = (t) => {
1188
- const { variableNamePrefix: e } = le(t);
1168
+ ${i}` : a;
1169
+ }, Mt = (r) => {
1170
+ const e = r.split("-").map((o) => o.trim()).filter(Boolean);
1171
+ return e[e.length - 1] ?? r;
1172
+ }, Vt = (r, e, o) => {
1173
+ const t = Mt(o);
1174
+ if (!e.parseUtilityKey)
1175
+ return t;
1176
+ const n = e.parseUtilityKey({
1177
+ variablePath: r.variablePath,
1178
+ flatName: o,
1179
+ defaultKey: t
1180
+ });
1181
+ return n.trim() ? n : t;
1182
+ }, Ct = /^[A-Za-z_$][A-Za-z0-9_$]*$/, Ft = (r) => {
1183
+ var t;
1184
+ const o = ((t = r.utilityKeysTypeName) == null ? void 0 : t.trim()) || "UtilitiesKeysType";
1185
+ if (!Ct.test(o))
1186
+ throw new Error(
1187
+ `Invalid utilityKeysTypeName: "${o}". Expected a valid TypeScript identifier.`
1188
+ );
1189
+ return o;
1190
+ }, xt = (r, e, o) => r.reduce((t, n) => {
1191
+ const s = Vt(e, o, n.flatName), a = t[s];
1192
+ if (a && a !== n.flatName)
1193
+ throw new Error(
1194
+ `Utility key collision: "${s}" is generated for both "${a}" and "${n.flatName}"`
1195
+ );
1196
+ return {
1197
+ ...t,
1198
+ [s]: n.flatName
1199
+ };
1200
+ }, {}), Pt = (r, e, o) => {
1201
+ var c;
1202
+ const t = xt(r, e, o), n = Object.keys(t).reduce((u, d) => {
1203
+ const f = t[d];
1204
+ return {
1205
+ ...u,
1206
+ [d]: ce(e, o, f)
1207
+ };
1208
+ }, {}), s = JSON.stringify(n, null, 4), i = ((c = o.getUtilityCssVarFunctionName) == null ? void 0 : c.trim()) || "getUtilityCssVar", l = Ft(o);
1189
1209
  return [
1190
- "import { utilities } from './utilities';",
1191
- "",
1192
- "type UtilitiesKeysType = keyof typeof utilities;",
1210
+ `const utilityVariableNameByKey = ${s} as const;`,
1193
1211
  "",
1194
- `const utilityVariableNamePrefix = ${JSON.stringify(e)};`,
1212
+ `type ${l} = keyof typeof utilityVariableNameByKey;`,
1195
1213
  "",
1196
- "const getUtilityCssVariableName = (key: UtilitiesKeysType): string =>",
1197
- " utilityVariableNamePrefix",
1198
- " ? `--${utilityVariableNamePrefix}-${String(key)}`",
1199
- " : `--${String(key)}`;",
1214
+ `const getUtilityCssVariableName = (key: ${l}): string =>`,
1215
+ " `--${utilityVariableNameByKey[key]}`;",
1200
1216
  "",
1201
- "const getUtilityCssVar = (key: UtilitiesKeysType): string =>",
1217
+ `const ${i} = (key: ${l}): string =>`,
1202
1218
  " `var(${getUtilityCssVariableName(key)})`;",
1203
1219
  "",
1204
1220
  "export {",
1205
- " utilities,",
1206
1221
  " getUtilityCssVariableName,",
1207
- " getUtilityCssVar,",
1208
- " type UtilitiesKeysType,",
1222
+ ` ${i},`,
1223
+ ` type ${l},`,
1209
1224
  "};",
1210
1225
  ""
1211
1226
  ].join(`
1212
1227
  `);
1213
- }, Vt = "styles.css", Ft = "utilities.ts", Nt = "index.ts", xt = async ({
1214
- dir: t,
1228
+ }, Ot = "styles.css", Et = "index.ts", Bt = async ({
1229
+ dir: r,
1215
1230
  globalCss: e,
1216
- utilitiesTs: o,
1217
- indexTs: r
1231
+ indexTs: o
1218
1232
  }) => {
1219
- await d.delete(t), await Promise.all([
1220
- d.write(Vt, e, { directory: t }),
1221
- d.write(Ft, o, { directory: t }),
1222
- d.write(Nt, r, { directory: t })
1233
+ await y.delete(r), await Promise.all([
1234
+ y.write(Ot, e, { directory: r }),
1235
+ y.write(Et, o, { directory: r })
1223
1236
  ]);
1224
- }, Ot = async ({
1225
- tokens: t,
1237
+ }, Kt = async ({
1238
+ tokens: r,
1226
1239
  input: e,
1227
1240
  output: o
1228
1241
  }) => {
1229
- const { dir: r } = o, n = jt(t, e), s = Mt(t, e), a = Ct(e);
1230
- await xt({ dir: r, globalCss: n, utilitiesTs: s, indexTs: a });
1231
- }, Jt = ({ input: t, output: e }) => ({
1242
+ const { dir: t } = o, n = Nt(r, e, o), s = Pt(r, e, o);
1243
+ await Bt({ dir: t, globalCss: n, indexTs: s });
1244
+ }, Xt = ({ input: r, output: e }) => ({
1232
1245
  name: "utilities/tokenManager",
1233
1246
  executor: async ({ tokenManagerClient: o }) => {
1234
- var r;
1247
+ var t;
1235
1248
  try {
1236
1249
  if (console.log("[utilities/tokenManager] Generating utility classes from TokenManager..."), !o.isLoaded())
1237
1250
  throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
1238
- const n = o.getVariables(), s = pt(n, t.variablePath), a = ht(s, o), l = mt(a, t.include);
1239
- if (!l.length) {
1240
- a.length && ((r = t.include) != null && r.length) ? console.warn(
1241
- `[utilities/tokenManager] No tokens left after include filter (${a.length} at path "${t.variablePath}")`
1242
- ) : console.warn(`[utilities/tokenManager] No dimension tokens found at path "${t.variablePath}"`);
1251
+ const n = o.getVariables(), s = ht(n, r.variablePath), a = mt(s, o), i = wt(a, r.include);
1252
+ if (!i.length) {
1253
+ a.length && ((t = r.include) != null && t.length) ? console.warn(
1254
+ `[utilities/tokenManager] No tokens left after include filter (${a.length} at path "${r.variablePath}")`
1255
+ ) : console.warn(`[utilities/tokenManager] No dimension tokens found at path "${r.variablePath}"`);
1243
1256
  return;
1244
1257
  }
1245
- console.log(`[utilities/tokenManager] Resolved ${l.length} utility token(s)`), console.log(`[utilities/tokenManager] Writing files to ${e.dir}...`), await Ot({ tokens: l, input: t, output: e }), console.log("[utilities/tokenManager] ✅ Successfully generated utility files");
1258
+ console.log(`[utilities/tokenManager] Resolved ${i.length} utility token(s)`), console.log(`[utilities/tokenManager] Writing files to ${e.dir}...`), await Kt({ tokens: i, input: r, output: e }), console.log("[utilities/tokenManager] ✅ Successfully generated utility files");
1246
1259
  } catch (n) {
1247
1260
  const s = n instanceof Error ? n.message : String(n);
1248
1261
  throw console.error("[utilities/tokenManager] ❌ Failed to generate utilities:", s), n instanceof Error && n.stack && console.error("[utilities/tokenManager] Stack trace:", n.stack), n;
@@ -1250,29 +1263,29 @@ export { utilities };
1250
1263
  }
1251
1264
  });
1252
1265
  export {
1253
- me as BREAKPOINTS_NAMES,
1266
+ we as BREAKPOINTS_NAMES,
1254
1267
  be as TokenManager,
1255
- Ut as breakpointsFromTokenManager,
1256
- Mt as buildUtilitiesDataTSContent,
1257
- jt as buildUtilitiesGlobalStylesCSS,
1258
- Ct as buildUtilitiesIndexTSContent,
1259
- Wt as colorsFromTokenManager,
1260
- zt as containerFromTokenManager,
1261
- wt as deriveUtilityNamingFromVariablePath,
1262
- mt as filterResolvedUtilitiesByInclude,
1263
- Kt as generate,
1264
- Ot as generateUtilitiesFiles,
1265
- ie as getSortedBreakpointModes,
1266
- kt as getUtilityCssVariableName,
1267
- pt as getVariablesSubtree,
1268
- Lt as init,
1269
- ht as resolveUtilitiesSubtree,
1270
- le as resolveUtilityNaming,
1271
- It as shadowsFromTokenManager,
1272
- St as splitUtilityTokenForMedia,
1273
- Gt as typographyFromTokenManager,
1274
- Jt as utilitiesFromTokenManager,
1268
+ Gt as breakpointsFromTokenManager,
1269
+ Nt as buildUtilitiesGlobalStylesCSS,
1270
+ Pt as buildUtilitiesIndexTSContent,
1271
+ Jt as colorsFromTokenManager,
1272
+ qt as containerFromTokenManager,
1273
+ ie as deriveUtilityNamingFromVariablePath,
1274
+ wt as filterResolvedUtilitiesByInclude,
1275
+ It as generate,
1276
+ Kt as generateUtilitiesFiles,
1277
+ kt as getSortedBreakpointModes,
1278
+ Qt as getUtilityCssVariableName,
1279
+ le as getUtilityCssVariableNameWithoutDashes,
1280
+ ht as getVariablesSubtree,
1281
+ zt as init,
1282
+ mt as resolveUtilitiesSubtree,
1283
+ ce as resolveUtilityCssVariableNameWithoutDashes,
1284
+ $t as resolveUtilityNaming,
1285
+ Ht as shadowsFromTokenManager,
1286
+ jt as splitUtilityTokenForMedia,
1287
+ Zt as typographyFromTokenManager,
1288
+ Xt as utilitiesFromTokenManager,
1275
1289
  bt as utilityFlatNameMatchesIncludePattern,
1276
- vt as utilityTokenToSerializableData,
1277
- xt as writeUtilitiesFiles
1290
+ Bt as writeUtilitiesFiles
1278
1291
  };