@greensight/gts 1.0.0-alpha.9 → 1.0.0-beta.10

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.
Files changed (87) hide show
  1. package/README.md +55 -28
  2. package/classes/Config/index.d.ts.map +1 -1
  3. package/classes/TokenManager/index.d.ts +19 -4
  4. package/classes/TokenManager/index.d.ts.map +1 -1
  5. package/classes/TokenManager/types/ds.d.ts +23 -12
  6. package/classes/TokenManager/types/ds.d.ts.map +1 -1
  7. package/classes/TokenManager/types/figma.d.ts +11 -3
  8. package/classes/TokenManager/types/figma.d.ts.map +1 -1
  9. package/commands/generate/index.d.ts.map +1 -1
  10. package/common/lodash.d.ts +8 -0
  11. package/common/lodash.d.ts.map +1 -0
  12. package/index.cjs +87 -6
  13. package/index.mjs +1038 -479
  14. package/modules/breakpoints/breakpointsFromTokenManager/index.d.ts +2 -0
  15. package/modules/breakpoints/breakpointsFromTokenManager/index.d.ts.map +1 -0
  16. package/modules/breakpoints/breakpointsFromTokenManager/module.d.ts +13 -0
  17. package/modules/breakpoints/breakpointsFromTokenManager/module.d.ts.map +1 -0
  18. package/modules/breakpoints/breakpointsFromTokenManager/utils.d.ts +8 -0
  19. package/modules/breakpoints/breakpointsFromTokenManager/utils.d.ts.map +1 -0
  20. package/modules/breakpoints/index.d.ts +3 -0
  21. package/modules/breakpoints/index.d.ts.map +1 -0
  22. package/modules/breakpoints/types.d.ts +6 -0
  23. package/modules/breakpoints/types.d.ts.map +1 -0
  24. package/modules/breakpoints/utils.d.ts +16 -0
  25. package/modules/breakpoints/utils.d.ts.map +1 -0
  26. package/modules/colors/colorsFromTokenManager/index.d.ts +2 -0
  27. package/modules/colors/colorsFromTokenManager/index.d.ts.map +1 -0
  28. package/modules/colors/{colorsFromTokenManager.d.ts → colorsFromTokenManager/module.d.ts} +4 -7
  29. package/modules/colors/colorsFromTokenManager/module.d.ts.map +1 -0
  30. package/modules/colors/colorsFromTokenManager/utils.d.ts +3 -0
  31. package/modules/colors/colorsFromTokenManager/utils.d.ts.map +1 -0
  32. package/modules/colors/index.d.ts +0 -2
  33. package/modules/colors/index.d.ts.map +1 -1
  34. package/modules/colors/utils.d.ts +8 -33
  35. package/modules/colors/utils.d.ts.map +1 -1
  36. package/modules/container/containerFromTokenManager/index.d.ts +2 -0
  37. package/modules/container/containerFromTokenManager/index.d.ts.map +1 -0
  38. package/modules/container/containerFromTokenManager/module.d.ts +13 -0
  39. package/modules/container/containerFromTokenManager/module.d.ts.map +1 -0
  40. package/modules/container/index.d.ts +3 -0
  41. package/modules/container/index.d.ts.map +1 -0
  42. package/modules/container/types.d.ts +5 -0
  43. package/modules/container/types.d.ts.map +1 -0
  44. package/modules/container/utils.d.ts +12 -0
  45. package/modules/container/utils.d.ts.map +1 -0
  46. package/modules/index.d.ts +5 -0
  47. package/modules/index.d.ts.map +1 -1
  48. package/modules/shadows/index.d.ts +3 -0
  49. package/modules/shadows/index.d.ts.map +1 -0
  50. package/modules/shadows/shadowsFromTokenManager.d.ts +13 -0
  51. package/modules/shadows/shadowsFromTokenManager.d.ts.map +1 -0
  52. package/modules/shadows/types.d.ts +6 -0
  53. package/modules/shadows/types.d.ts.map +1 -0
  54. package/modules/shadows/utils.d.ts +22 -0
  55. package/modules/shadows/utils.d.ts.map +1 -0
  56. package/modules/typography/index.d.ts +2 -0
  57. package/modules/typography/index.d.ts.map +1 -0
  58. package/modules/typography/types.d.ts +10 -0
  59. package/modules/typography/types.d.ts.map +1 -0
  60. package/modules/typography/typographyFromTokenManager/index.d.ts +2 -0
  61. package/modules/typography/typographyFromTokenManager/index.d.ts.map +1 -0
  62. package/modules/typography/typographyFromTokenManager/module.d.ts +19 -0
  63. package/modules/typography/typographyFromTokenManager/module.d.ts.map +1 -0
  64. package/modules/typography/utils.d.ts +56 -0
  65. package/modules/typography/utils.d.ts.map +1 -0
  66. package/modules/utilities/index.d.ts +4 -0
  67. package/modules/utilities/index.d.ts.map +1 -0
  68. package/modules/utilities/types.d.ts +75 -0
  69. package/modules/utilities/types.d.ts.map +1 -0
  70. package/modules/utilities/utilitiesFromTokenManager/index.d.ts +2 -0
  71. package/modules/utilities/utilitiesFromTokenManager/index.d.ts.map +1 -0
  72. package/modules/utilities/utilitiesFromTokenManager/module.d.ts +4 -0
  73. package/modules/utilities/utilitiesFromTokenManager/module.d.ts.map +1 -0
  74. package/modules/utilities/utils.d.ts +70 -0
  75. package/modules/utilities/utils.d.ts.map +1 -0
  76. package/package.json +1 -2
  77. package/temporarilyUnnecessary/colorsFromStyles.d.ts +1 -0
  78. package/temporarilyUnnecessary/colorsFromStyles.d.ts.map +1 -0
  79. package/temporarilyUnnecessary/colorsFromVariables.d.ts +1 -0
  80. package/temporarilyUnnecessary/colorsFromVariables.d.ts.map +1 -0
  81. package/temporarilyUnnecessary/utils.d.ts +1 -0
  82. package/temporarilyUnnecessary/utils.d.ts.map +1 -0
  83. package/modules/colors/colorsFromStyles.d.ts +0 -16
  84. package/modules/colors/colorsFromStyles.d.ts.map +0 -1
  85. package/modules/colors/colorsFromTokenManager.d.ts.map +0 -1
  86. package/modules/colors/colorsFromVariables.d.ts +0 -16
  87. package/modules/colors/colorsFromVariables.d.ts.map +0 -1
package/index.mjs CHANGED
@@ -1,153 +1,153 @@
1
- var Z = Object.defineProperty;
2
- var _ = (s, e, r) => e in s ? Z(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r;
3
- var b = (s, e, r) => _(s, typeof e != "symbol" ? e + "" : e, r);
4
- import $ from "path";
5
- import { tsImport as ee } from "ts-import";
6
- import { existsSync as j } from "node:fs";
7
- import { readFile as P, mkdir as re, writeFile as te, rm as oe } from "node:fs/promises";
8
- import { resolve as x } from "node:path";
9
- import { merge as se, get as q } from "lodash-es";
10
- const h = class h {
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
+ import k from "path";
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 {
11
10
  static resolveReadPath(e) {
12
11
  if (!e || !e.trim())
13
12
  throw new Error("File path must be a non-empty string");
14
- return x(h.baseDir, e);
13
+ return C(p.baseDir, e);
15
14
  }
16
- static resolveWritePath(e, r) {
17
- const t = x(h.baseDir, r ?? "");
15
+ static resolveWritePath(e, o) {
16
+ const t = C(p.baseDir, o ?? "");
18
17
  return {
19
18
  targetDir: t,
20
- targetPath: x(t, e)
19
+ targetPath: C(t, e)
21
20
  };
22
21
  }
23
- static handleReadError(e, r) {
24
- throw e.code === "ENOENT" ? new Error(`File not found: ${r}`) : new Error(
25
- `Failed to read file "${r}": ${e.message ?? String(e)}`
22
+ static handleReadError(e, o) {
23
+ throw e.code === "ENOENT" ? new Error(`File not found: ${o}`) : new Error(
24
+ `Failed to read file "${o}": ${e.message ?? String(e)}`
26
25
  );
27
26
  }
28
- static async read(e, r = "utf8") {
29
- const t = h.resolveReadPath(e);
27
+ static async read(e, o = "utf8") {
28
+ const t = p.resolveReadPath(e);
30
29
  try {
31
- return await P(t, { encoding: r });
32
- } catch (o) {
33
- h.handleReadError(o, t);
30
+ return await V(t, { encoding: o });
31
+ } catch (n) {
32
+ p.handleReadError(n, t);
34
33
  }
35
34
  }
36
35
  static async readBuffer(e) {
37
- const r = h.resolveReadPath(e);
36
+ const o = p.resolveReadPath(e);
38
37
  try {
39
- return await P(r);
38
+ return await V(o);
40
39
  } catch (t) {
41
- h.handleReadError(t, r);
40
+ p.handleReadError(t, o);
42
41
  }
43
42
  }
44
43
  static async readJson(e) {
45
- const r = h.resolveReadPath(e);
44
+ const o = p.resolveReadPath(e);
46
45
  try {
47
- const t = await P(r, { encoding: "utf8" });
46
+ const t = await V(o, { encoding: "utf8" });
48
47
  try {
49
48
  return JSON.parse(t);
50
- } catch (o) {
51
- throw new Error(`Failed to parse JSON from "${r}": ${o.message}`);
49
+ } catch (n) {
50
+ throw new Error(`Failed to parse JSON from "${o}": ${n.message}`);
52
51
  }
53
52
  } catch (t) {
54
- h.handleReadError(t, r);
53
+ p.handleReadError(t, o);
55
54
  }
56
55
  }
57
- static async write(e, r = "", t = {}) {
58
- const { directory: o, overwrite: n = !0 } = t, { targetDir: a, targetPath: i } = h.resolveWritePath(e, o);
59
- if (!n && j(i))
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))
60
59
  throw new Error(`File ${i} already exists`);
61
- return await re(a, { recursive: !0 }), await te(i, r, { encoding: "utf8" }), i;
60
+ return await fe(a, { recursive: !0 }), await ge(i, o, { encoding: "utf8" }), i;
62
61
  }
63
- static async writeWithExtension(e, r, t = "", o) {
64
- const n = r.startsWith(".") ? r : `.${r}`, a = `${e}${n}`;
65
- return h.write(a, t, o);
62
+ static async writeWithExtension(e, o, t = "", n) {
63
+ const s = o.startsWith(".") ? o : `.${o}`, a = `${e}${s}`;
64
+ return p.write(a, t, n);
66
65
  }
67
66
  static exists(e) {
68
- const r = h.resolveReadPath(e);
69
- return j(r);
67
+ const o = p.resolveReadPath(e);
68
+ return M(o);
70
69
  }
71
- static async delete(e, r) {
72
- const { targetPath: t } = h.resolveWritePath(e, r);
73
- j(t) && await oe(t, { force: !0 });
70
+ static async delete(e, o) {
71
+ const { targetPath: t } = p.resolveWritePath(e, o);
72
+ M(t) && await pe(t, { recursive: !0, force: !0 });
74
73
  }
75
74
  };
76
- b(h, "baseDir", process.cwd());
77
- let m = h;
78
- const v = class v {
75
+ w(p, "baseDir", process.cwd());
76
+ let y = p;
77
+ const $ = class $ {
79
78
  static async create() {
80
- if (m.exists(v.configFileName))
79
+ if (y.exists($.configFileName))
81
80
  throw new Error("The file already exists");
82
- await m.write(v.configFileName, "", { overwrite: !1 });
81
+ await y.write($.configFileName, "", { overwrite: !1 });
83
82
  }
84
83
  async load() {
85
84
  try {
86
- const e = await ee.compile(
87
- `${$.resolve(process.cwd(), v.configFileName)}`
85
+ const e = await ye.compile(
86
+ `${k.resolve(process.cwd(), $.configFileName)}`
88
87
  );
89
- if (!e) throw new Error();
88
+ if (!e)
89
+ throw new Error("gts.config.ts must default-export a configuration object");
90
90
  return e.default;
91
91
  } catch (e) {
92
92
  console.error("Cannot find module gts.config.ts", e);
93
93
  }
94
94
  }
95
95
  };
96
- b(v, "configFileName", "gts.config.ts");
97
- let E = v;
98
- const ne = (s) => {
96
+ w($, "configFileName", "gts.config.ts");
97
+ let v = $;
98
+ const he = (r) => {
99
99
  const e = new URLSearchParams();
100
- return Object.keys(s).forEach((r) => {
101
- Array.isArray(s[r]) ? s[r].forEach((t) => e.append(`${r}[]`, t)) : e.append(r, s[r]);
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]);
102
102
  }), e;
103
- }, ae = (s, e = 50) => {
104
- const r = [];
105
- for (let t = 0; t < s.length; t += e)
106
- r.push(s.slice(t, t + e));
107
- return r;
103
+ }, me = (r, e = 50) => {
104
+ const o = [];
105
+ for (let t = 0; t < r.length; t += e)
106
+ o.push(r.slice(t, t + e));
107
+ return o;
108
108
  };
109
- class V {
110
- constructor(e, r) {
111
- b(this, "figmaToken");
112
- b(this, "fileId");
113
- b(this, "onTimeMeasureHandler");
114
- this.figmaToken = e, this.fileId = r;
109
+ class O {
110
+ constructor(e, o) {
111
+ w(this, "figmaToken");
112
+ w(this, "fileId");
113
+ w(this, "onTimeMeasureHandler");
114
+ this.figmaToken = e, this.fileId = o;
115
115
  }
116
116
  setOnTimeMeasureHandler(e) {
117
117
  this.onTimeMeasureHandler = e;
118
118
  }
119
119
  static async returnJSON(e) {
120
- const r = await e.json();
120
+ const o = await e.json();
121
121
  if (!e.ok) {
122
122
  let t = "Request failed";
123
123
  throw new Error(t);
124
124
  }
125
- return r;
125
+ return o;
126
126
  }
127
- async performControlledRequest(e, { params: r = {}, timeout: t = 3e4, abortController: o = new AbortController() } = {}) {
128
- var f;
127
+ async performControlledRequest(e, { params: o = {}, timeout: t = 3e4, abortController: n = new AbortController() } = {}) {
128
+ var m;
129
129
  if (!this.figmaToken || !this.fileId)
130
- throw new Error("Добавьте figmaToken и figmaId");
131
- const n = Object.entries(r).reduce((u, [p, w]) => typeof w < "u" ? { ...u, [p]: w } : u, {}), a = `https://api.figma.com/v1${e}${n && Object.keys(n).length ? `?${ne(n)}` : ""}`;
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)}` : ""}`;
132
132
  console.log("endpoinWithParams=", a);
133
- const i = setTimeout(() => o.abort(), t), l = {
133
+ const i = setTimeout(() => n.abort(), t), l = {
134
134
  "Content-Type": "application/json",
135
135
  ...this.figmaToken && { "X-Figma-Token": this.figmaToken }
136
136
  }, c = {
137
137
  method: "GET",
138
138
  headers: l,
139
- signal: o.signal
140
- }, g = performance.now(), d = await fetch(`${a}`, c);
139
+ signal: n.signal
140
+ }, u = performance.now(), d = await fetch(`${a}`, c);
141
141
  clearTimeout(i);
142
- const y = performance.now() - g;
143
- return (f = this.onTimeMeasureHandler) == null || f.call(this, a, l, y), d;
142
+ const f = performance.now() - u;
143
+ return (m = this.onTimeMeasureHandler) == null || m.call(this, a, l, f), d;
144
144
  }
145
- async request(e, r) {
146
- var o;
145
+ async request(e, o) {
146
+ var n;
147
147
  const t = await this.performControlledRequest(e, {
148
- ...r
148
+ ...o
149
149
  });
150
- return (o = t.headers.get("content-type")) != null && o.includes("application/json") ? V.returnJSON(t) : t;
150
+ return (n = t.headers.get("content-type")) != null && n.includes("application/json") ? O.returnJSON(t) : t;
151
151
  }
152
152
  async getComponents() {
153
153
  return this.request(`/files/${this.fileId}/components`);
@@ -156,36 +156,88 @@ class V {
156
156
  return this.request(`/files/${this.fileId}/styles`);
157
157
  }
158
158
  async getNodes(e) {
159
- const r = ae(e).map(
160
- (n) => this.request(`/files/${this.fileId}/nodes`, { params: { ids: n.join(",") } })
161
- ), t = await Promise.all(r);
159
+ const o = me(e).map(
160
+ (s) => this.request(`/files/${this.fileId}/nodes`, { params: { ids: s.join(",") } })
161
+ ), t = await Promise.all(o);
162
162
  return {
163
163
  ...t[0],
164
- nodes: t.reduce((n, a) => ({ ...n, ...a.nodes }), {})
164
+ nodes: t.reduce((s, a) => ({ ...s, ...a.nodes }), {})
165
165
  };
166
166
  }
167
167
  }
168
- class ie {
168
+ const q = (r, e) => {
169
+ const o = Array.isArray(e) ? e : e.split(".");
170
+ let t = r;
171
+ for (const n of o) {
172
+ if (t == null || typeof t != "object") return;
173
+ t = t[n];
174
+ }
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]);
182
+ return o;
183
+ };
184
+ function x(r, e) {
185
+ if (r === e)
186
+ return !0;
187
+ if (r == null || e == null)
188
+ return r === e;
189
+ if (typeof r != typeof e)
190
+ return !1;
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)
197
+ return !1;
198
+ for (let o = 0; o < r.length; o++)
199
+ if (!x(r[o], e[o]))
200
+ return !1;
201
+ return !0;
202
+ }
203
+ if (typeof r == "object" && typeof e == "object") {
204
+ const o = Object.keys(r), t = Object.keys(e);
205
+ if (o.length !== t.length)
206
+ return !1;
207
+ for (const n of o)
208
+ if (!t.includes(n) || !x(r[n], e[n]))
209
+ return !1;
210
+ return !0;
211
+ }
212
+ return !1;
213
+ }
214
+ const K = {
215
+ color: {},
216
+ effect: {},
217
+ text: {},
218
+ grid: {}
219
+ };
220
+ class be {
169
221
  constructor(e) {
170
222
  // files
171
- b(this, "tokensDir");
172
- b(this, "manifestPath");
173
- // figma data
174
- b(this, "variables");
175
- b(this, "styles");
223
+ w(this, "tokensDir");
224
+ w(this, "manifestPath");
225
+ // result data
226
+ w(this, "variables");
227
+ w(this, "styles");
176
228
  // flags
177
- b(this, "loaded", !1);
178
- this.tokensDir = e || "", this.manifestPath = $.join(this.tokensDir, "manifest.json");
229
+ w(this, "loaded", !1);
230
+ this.tokensDir = e || "", this.manifestPath = k.join(this.tokensDir, "manifest.json");
179
231
  }
180
232
  isLoaded() {
181
233
  return this.loaded && !!this.variables && !!this.styles;
182
234
  }
183
235
  /** to camelCase */
184
236
  normalizeKey(e) {
185
- const r = e.trim();
186
- return r && r.replace(/[-_\s]+/g, " ").split(" ").filter((t) => t.length).map((t, o) => {
187
- const n = t.charAt(0), a = t.slice(1);
188
- return o === 0 ? t : n.toUpperCase() + a;
237
+ const o = e.trim();
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;
189
241
  }).join("");
190
242
  }
191
243
  /**
@@ -193,10 +245,10 @@ class ie {
193
245
  */
194
246
  parseVariableString(e) {
195
247
  if (typeof e != "string") return e;
196
- const r = /^\{(.+)\}$/, t = e.match(r);
248
+ const o = /^\{(.+)\}$/, t = e.match(o);
197
249
  if (t) {
198
- const o = t[1].trim();
199
- return `{${this.normalizeKey(o)}}`;
250
+ const n = t[1].trim();
251
+ return `{${this.normalizeKey(n)}}`;
200
252
  }
201
253
  return e;
202
254
  }
@@ -205,59 +257,59 @@ class ie {
205
257
  */
206
258
  createVariableFileList(e) {
207
259
  return Object.entries(e).flatMap(
208
- ([r, t]) => Object.entries(t.modes).flatMap(
209
- ([o, n]) => n.map((a) => ({
260
+ ([o, t]) => Object.entries(t.modes).flatMap(
261
+ ([n, s]) => s.map((a) => ({
210
262
  fileName: a,
211
- modeName: this.normalizeKey(o.trim()),
212
- collectionName: r
263
+ modeName: this.normalizeKey(n.trim()),
264
+ collectionName: o
213
265
  }))
214
266
  )
215
267
  );
216
268
  }
217
269
  parseValue(e) {
218
- return e && (typeof e == "string" ? this.parseVariableString(e) : typeof e != "object" ? e : (Array.isArray(e) && e.map((r) => this.parseValue(r)), Object.entries(e).reduce((r, [t, o]) => ({ ...r, [t]: this.parseValue(o) }), {})));
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) }), {}));
219
271
  }
220
- getTokensFromFile(e, r) {
221
- return Object.entries(e).reduce((t, [o, n]) => "$type" in n && "$value" in n ? {
272
+ getTokensFromFile(e, o) {
273
+ return Object.entries(e).reduce((t, [n, s]) => "$type" in s && "$value" in s ? {
222
274
  ...t,
223
- [this.normalizeKey(o)]: {
224
- type: n.$type,
225
- description: n.$description,
226
- value: r ? { [this.normalizeKey(r)]: this.parseValue(n.$value) } : this.parseValue(n.$value)
275
+ [this.normalizeKey(n)]: {
276
+ type: s.$type,
277
+ description: s.$description,
278
+ value: o ? { [this.normalizeKey(o)]: this.parseValue(s.$value) } : this.parseValue(s.$value)
227
279
  }
228
- } : { ...t, [this.normalizeKey(o)]: this.getTokensFromFile(n, r) }, {});
280
+ } : { ...t, [this.normalizeKey(n)]: this.getTokensFromFile(s, o) }, {});
229
281
  }
230
- processTokensFile(e, r, t) {
231
- const o = this.normalizeKey(t), n = this.getTokensFromFile(e, r);
232
- return { [o]: n };
282
+ processTokensFile(e, o, t) {
283
+ const n = this.normalizeKey(t), s = this.getTokensFromFile(e, o);
284
+ return { [n]: s };
233
285
  }
234
286
  /**
235
287
  * Loads all variable files in parallel and returns processed results
236
288
  */
237
289
  async loadVariableFiles(e) {
238
290
  return Promise.all(
239
- e.map(async ({ fileName: r, modeName: t, collectionName: o }) => {
291
+ e.map(async ({ fileName: o, modeName: t, collectionName: n }) => {
240
292
  try {
241
- const n = $.join(this.tokensDir, r), a = await m.readJson(n);
242
- return this.processTokensFile(a, t, o);
243
- } catch (n) {
244
- return console.warn(`Failed to load variable file: ${$.join(this.tokensDir, r)}`, n), {};
293
+ const s = k.join(this.tokensDir, o), a = await y.readJson(s);
294
+ return this.processTokensFile(a, t, n);
295
+ } catch (s) {
296
+ return console.warn(`Failed to load variable file: ${k.join(this.tokensDir, o)}`, s), {};
245
297
  }
246
298
  })
247
299
  );
248
300
  }
249
301
  mergeVariables(e) {
250
- return e.reduce((r, t) => se(r, t), {});
302
+ return e.reduce((o, t) => H(o, t), {});
251
303
  }
252
304
  /**
253
305
  * Loads and processes all token variables from manifest collections
254
306
  */
255
307
  async loadTokenVariables(e) {
256
308
  try {
257
- const r = this.createVariableFileList(e), t = await this.loadVariableFiles(r);
309
+ const o = this.createVariableFileList(e), t = await this.loadVariableFiles(o);
258
310
  return this.mergeVariables(t);
259
- } catch (r) {
260
- throw new Error(`Failed to load token variables from ${this.tokensDir}: ${r}`);
311
+ } catch (o) {
312
+ throw new Error(`Failed to load token variables from ${this.tokensDir}: ${o}`);
261
313
  }
262
314
  }
263
315
  /**
@@ -265,9 +317,9 @@ class ie {
265
317
  */
266
318
  createStyleFileList(e) {
267
319
  return Object.entries(e).flatMap(
268
- ([r, t]) => (t == null ? void 0 : t.map((o) => ({
269
- styleType: r,
270
- fileName: o
320
+ ([o, t]) => (t == null ? void 0 : t.map((n) => ({
321
+ styleType: o,
322
+ fileName: n
271
323
  }))) || []
272
324
  );
273
325
  }
@@ -276,30 +328,32 @@ class ie {
276
328
  */
277
329
  async loadStyleFiles(e) {
278
330
  return (await Promise.all(
279
- e.map(async ({ styleType: t, fileName: o }) => {
331
+ e.map(async ({ styleType: t, fileName: n }) => {
280
332
  try {
281
- const n = $.join(this.tokensDir, o), a = await m.readJson(n);
333
+ const s = k.join(this.tokensDir, n), a = await y.readJson(s);
282
334
  return { styleType: t, styleTokens: a };
283
- } catch (n) {
284
- return console.warn(`Failed to load style file: ${$.join(this.tokensDir, o)}`, n), { styleType: t, styleTokens: {} };
335
+ } catch (s) {
336
+ return console.warn(`Failed to load style file: ${k.join(this.tokensDir, n)}`, s), { styleType: t, styleTokens: {} };
285
337
  }
286
338
  })
287
339
  )).reduce(
288
- (t, o) => ({ ...t, [o.styleType]: this.getTokensFromFile(o.styleTokens, "") }),
289
- {}
340
+ (t, n) => ({ ...t, [n.styleType]: this.getTokensFromFile(n.styleTokens, "") }),
341
+ {
342
+ ...K
343
+ }
290
344
  );
291
345
  }
292
346
  /**
293
347
  * Loads and processes all style tokens from manifest
294
348
  */
295
349
  async loadStyles(e) {
296
- if (!e) return {};
297
- const r = this.createStyleFileList(e);
298
- return await this.loadStyleFiles(r);
350
+ if (!e) return { ...K };
351
+ const o = this.createStyleFileList(e);
352
+ return await this.loadStyleFiles(o);
299
353
  }
300
354
  async load() {
301
355
  if (this.loaded) return;
302
- const e = await m.readJson(this.manifestPath);
356
+ const e = await y.readJson(this.manifestPath);
303
357
  if (!e)
304
358
  throw new Error(`Failed to load manifest file from: ${this.manifestPath}`);
305
359
  this.variables = await this.loadTokenVariables(e.collections), this.styles = await this.loadStyles(e.styles), this.loaded = !0;
@@ -336,397 +390,902 @@ class ie {
336
390
  getVariablePath(e) {
337
391
  return e.slice(1, -1);
338
392
  }
393
+ /**
394
+ * Resolves a variable reference by validating, parsing and getting the token
395
+ * @param value - Value to resolve (should be a variable reference like "{variable.path}")
396
+ * @param mode - Mode name to get value for (optional)
397
+ * @returns resolved token variable or undefined if not found or invalid
398
+ */
399
+ resolveVariableValue(e) {
400
+ if (typeof e == "object")
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;
404
+ }, {});
405
+ }
406
+ /**
407
+ * Resolves a variable reference by validating, parsing and getting the token
408
+ * @param value - Value to resolve (should be a variable reference like "{variable.path}")
409
+ * @param mode - Mode name to get value for (optional)
410
+ * @returns resolved token variable or undefined if not found or invalid
411
+ */
412
+ resolveVariableValueString(e, o) {
413
+ if (!this.isVariableReference(e)) return e;
414
+ const t = this.getVariablePath(e), n = this.getToken(t, o);
415
+ if (n)
416
+ return this.resolveVariableValueString(n, o);
417
+ }
339
418
  /**
340
419
  * Gets a nested token value by path, similar to lodash.get
341
420
  * @param variablePath - Dot-separated string path or array of path segments
421
+ * @param mode - Mode name to get value for (optional)
342
422
  */
343
- getToken(e) {
423
+ getToken(e, o) {
344
424
  if (!this.loaded || !this.variables)
345
425
  throw new Error("Tokens not loaded. Call load() first.");
346
- const r = q(this.variables, e);
347
- if (r && typeof r == "object") return r;
348
- for (const [, t] of Object.entries(this.variables)) {
349
- const o = q(t, e);
350
- if (o != null && o.value) return o;
426
+ for (const t of Object.values(this.variables)) {
427
+ const n = q(t, e);
428
+ if (n != null && n.value && typeof n.value == "object") {
429
+ if (o) return n.value[o];
430
+ {
431
+ const s = Object.keys(n.value)[0];
432
+ return n.value[s];
433
+ }
434
+ }
351
435
  }
352
436
  }
353
437
  }
354
- const xe = async () => {
355
- const e = await new E().load();
438
+ const It = async () => {
439
+ const e = await new v().load();
356
440
  if (!e)
357
- throw new Error("Заполнить ошибку через нейронку");
358
- const { figmaToken: r, fileId: t, modules: o, manifest: n } = e, a = new V(r, t), i = new ie(n);
359
- n && m.exists(n) && await i.load(), await Promise.all(
360
- // [
361
- // colorsFromTokenManager({
362
- // input: {
363
- // // includeVariables: ['colors'],
364
- // // includeStyles: false,
365
- // },
366
- // output: {
367
- // jsonDir: './fromVariables',
368
- // stylesDir: './fromVariables',
369
- // },
370
- // }),
371
- // ]
372
- o.map((l) => l.executor({ figmaApiClient: a, tokenManagerClient: i }))
373
- );
374
- }, Oe = async () => {
375
- await E.create(), console.log("\x1B[32m%s\x1B[0m", "✔️ Configuration file created gts.config.ts");
376
- }, le = ({ r: s, g: e, b: r }) => {
377
- const t = (o) => `0${o.toString(16)}`.slice(-2);
378
- return `#${t(s)}${t(e)}${t(r)}`;
379
- }, S = ({ opacity: s, r: e, g: r, b: t }) => {
380
- const o = [e, r, t].map((n) => Math.round(n * 255));
381
- return s < 1 ? `rgba(${o[0]}, ${o[1]}, ${o[2]}, ${s})` : le({ r: o[0], g: o[1], b: o[2] });
382
- }, X = (s, e = 0) => {
383
- const r = Math.atan2(
384
- s[1].y - s[0].y,
385
- s[1].x - s[0].x
386
- );
387
- return Math.round(r * 180 / Math.PI) + e;
388
- }, R = (s) => s.reduce((e, r) => {
389
- const t = Number((r.position * 100).toFixed(1));
390
- return [
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(
449
+ (e, o) => ({
391
450
  ...e,
392
- `${S({
393
- opacity: r.color.a,
394
- r: r.color.r,
395
- g: r.color.g,
396
- b: r.color.b
397
- })}${t > 0 && t < 100 ? ` ${t}%` : ""}`
398
- ];
399
- }, []).join(", "), Y = (s) => {
400
- const e = s[0].x, r = s[0].y, t = (e * 100).toFixed(2), o = (r * 100).toFixed(2);
401
- return { centerX: t, centerY: o };
402
- }, ce = (s) => {
403
- const { gradientHandlePositions: e, gradientStops: r } = s, t = X(e, 90), o = R(r);
404
- return `linear-gradient(${t}deg, ${o})`;
405
- }, de = (s) => {
406
- const e = s[0].x, r = s[0].y, t = s[1].x, o = s[1].y, n = s[2].x, a = s[2].y, i = (Math.sqrt((n - e) ** 2 + (a - r) ** 2) * 100).toFixed(2), l = (Math.sqrt((t - e) ** 2 + (o - r) ** 2) * 100).toFixed(2);
407
- return { radiusX: i, radiusY: l };
408
- }, ue = (s) => {
409
- const { gradientHandlePositions: e, gradientStops: r } = s, { centerX: t, centerY: o } = Y(e), { radiusX: n, radiusY: a } = de(e), i = R(r);
410
- return `radial-gradient(${n}% ${a}% at ${t}% ${o}%, ${i})`;
411
- }, ge = (s) => {
412
- const { gradientHandlePositions: e, gradientStops: r } = s, t = X(e, 30), { centerX: o, centerY: n } = Y(e), a = R(r);
413
- return `conic-gradient(from ${t}deg at ${o}% ${n}%, ${a})`;
414
- }, fe = (s) => {
415
- const e = s.type;
416
- return e === "SOLID" ? S({
417
- opacity: s.color.a,
418
- r: s.color.r,
419
- g: s.color.g,
420
- b: s.color.b
421
- }) : e === "GRADIENT_LINEAR" ? ce(s) : e === "GRADIENT_RADIAL" ? ue(s) : e === "GRADIENT_ANGULAR" ? ge(s) : "";
422
- }, B = (s, e) => {
451
+ [o.name]: ke(o)
452
+ }),
453
+ {}
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};`);
462
+ return e.length ? `.breakpoint-variables {
463
+ ${e.join(`
464
+ `)}
465
+ }
466
+ ` : "";
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;
470
+ return !e.length || !o ? "" : `$breakpointList: (
471
+ ${e.join(`,
472
+ `)}
473
+ );
474
+
475
+ $defaultBreakpoint: '${o}';
476
+ `;
477
+ }, Ne = (r) => [
478
+ `const breakpoints = ${JSON.stringify(r, null, 4)} as const;`,
479
+ "",
480
+ "const BREAKPOINTS_NAMES = Object.keys(breakpoints);",
481
+ "",
482
+ "type BreakpointsKeysType = keyof typeof breakpoints;",
483
+ "type AllowMedia = 'all' | BreakpointsKeysType;",
484
+ "",
485
+ "export { breakpoints, BREAKPOINTS_NAMES };",
486
+ "export type { BreakpointsKeysType, AllowMedia };",
487
+ ""
488
+ ].join(`
489
+ `), Me = async ({ breakpointTokens: r, dir: e }) => {
490
+ const o = $e(r), t = je(r), n = ve(r), s = Ne(o);
491
+ await Promise.all([
492
+ F("styles.css", t, e),
493
+ F("styles.scss", n, e),
494
+ F("index.ts", s, e)
495
+ ]);
496
+ }, Ve = (r, e) => {
497
+ const o = Object.keys(r).filter((s) => !isNaN(Number(s))).sort((s, a) => Number(s) - Number(a));
498
+ if (o.length > e.length)
499
+ throw new Error(
500
+ `Not enough breakpoint names provided. Found ${o.length} breakpoints in data, but only ${e.length} names specified: ${e.join(", ")}`
501
+ );
502
+ const n = Object.keys(r).filter((s) => isNaN(Number(s)));
503
+ if (n.length > 0)
504
+ throw new Error(
505
+ `Found non-numeric breakpoint keys in grid data: ${n.join(", ")}. All breakpoint keys must be numeric values.`
506
+ );
507
+ return o.map((s, a) => ({
508
+ name: e[e.length - 1 - a] || `bp-${s}`,
509
+ value: s
510
+ }));
511
+ }, Gt = ({
512
+ input: r = {},
513
+ output: { dir: e }
514
+ }) => ({
515
+ name: "breakpoints/tokenManager",
516
+ executor: async ({ tokenManagerClient: o }) => {
517
+ try {
518
+ console.log("[breakpoints/tokenManager] Generating breakpoints from TokenManager...");
519
+ const { names: t = we } = r;
520
+ if (!o.isLoaded())
521
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
522
+ const n = o.getStyles();
523
+ if (!n.grid)
524
+ throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
525
+ console.log("[breakpoints/tokenManager] Extracting breakpoints from grid styles...");
526
+ const s = Ve(n.grid, t);
527
+ if (!s.length) {
528
+ console.warn("[breakpoints/tokenManager] No breakpoints found in grid styles.");
529
+ return;
530
+ }
531
+ console.log(
532
+ `[breakpoints/tokenManager] Found ${s.length} breakpoints: ${s.map((a) => a.name).join(", ")}`
533
+ ), console.log(`[breakpoints/tokenManager] Writing files to ${e}...`), await Me({
534
+ breakpointTokens: s,
535
+ dir: e
536
+ }), console.log("[breakpoints/tokenManager] ✅ Successfully generated breakpoint files");
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;
540
+ }
541
+ }
542
+ }), Ce = "styles.css", Fe = "index.ts", A = (r, e) => {
423
543
  if (!e.length) return "";
424
- const r = e.map((t) => ` ${t}`).join(`
544
+ const o = e.map((t) => ` ${t}`).join(`
425
545
  `);
426
- return `${s} {
427
- ${r}
546
+ return `${r} {
547
+ ${o}
428
548
  }`;
429
- }, he = (s) => `.${s.replace(/\s+/g, "-").toLowerCase()}`, me = (s) => s.replaceAll(/ /g, "").split("/").at(-1), ye = (s) => `--${s}`, be = (s) => s.reduce(
430
- (e, r) => {
431
- const t = ye(r.name);
432
- return typeof r.value == "object" ? Object.entries(r.value).forEach(([o, n]) => {
433
- e[o] || (e[o] = []), e[o].push(`${t}: ${n};`);
434
- }) : e.root.push(`${t}: ${r.value};`), e;
549
+ }, xe = (r) => `.${r.replace(/\s+/g, "-").toLowerCase()}`, Z = (r) => `--cl-${r}`, Pe = (r) => r.reduce(
550
+ (e, o) => {
551
+ const t = Z(o.name);
552
+ return typeof o.value == "object" ? Object.entries(o.value).forEach(([n, s]) => {
553
+ e[n] || (e[n] = []), e[n].push(`${t}: ${s};`);
554
+ }) : e.root.push(`${t}: ${o.value};`), e;
435
555
  },
436
556
  { root: [] }
437
- ), pe = (s) => {
438
- const e = B(":root", s.root), r = Object.entries(s).reduce((t, [o, n]) => {
439
- if (o === "root" || !n.length) return t;
440
- const a = B(he(o), n);
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);
441
561
  return a && t.push(a), t;
442
562
  }, []).join(`
443
563
 
444
564
  `);
445
- return [e, r].filter(Boolean).join(`
565
+ return [e, o].filter(Boolean).join(`
446
566
 
447
567
  `);
448
- }, we = (s) => {
449
- const e = s.reduce((r, t) => ({ ...r, [t.name]: t.value }), {});
450
- return JSON.stringify(e);
451
- }, $e = async (s, e, r, t, o, n) => {
452
- await Promise.all([m.delete(o, r), m.delete(n, t)]);
453
- const a = m.write(o, s, { directory: r }), i = m.write(n, e, { directory: t });
454
- await Promise.all([a, i]);
455
- }, M = async ({
456
- colorTokens: s,
457
- jsonDir: e,
458
- stylesDir: r,
459
- jsonFileName: t,
460
- cssFileName: o
568
+ }, Ee = (r) => `${`const colors = {
569
+ ${r.map((t) => ` '${t.name}': 'var(${Z(t.name)})'`).join(`,
570
+ `)}
571
+ } as const;`}
572
+
573
+ type ColorsKeysType = keyof typeof colors;
574
+
575
+ export { colors, type ColorsKeysType };
576
+ `, Be = async ({
577
+ tsContent: r,
578
+ cssContent: e,
579
+ dir: o
461
580
  }) => {
462
- const n = be(s), a = pe(n), i = we(s);
463
- await $e(i, a, e, r, t, o);
464
- }, Ve = ({
465
- input: s,
466
- output: { jsonDir: e, stylesDir: r, jsonFileName: t = "colors.json", cssFileName: o = "colors.css" }
467
- }) => ({
468
- name: "styles/colors",
469
- executor: async ({ figmaApiClient: n }) => {
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;
602
+ if (n && typeof n == "object" && "type" in n && "value" in n) {
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])
607
+ }),
608
+ {}
609
+ ) : R(l), u = { [s]: c };
610
+ return { ...o, ...u };
611
+ }
612
+ const a = Q(n, s);
613
+ return { ...o, ...a };
614
+ },
615
+ {}
616
+ ), X = (r, e) => Object.keys(r).reduce((o, t) => {
617
+ const n = r[t];
618
+ if (n.type && n.type !== "color") return o;
619
+ if (n.type && n.value) {
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;
622
+ }
623
+ const s = X(n, e);
624
+ return s ? { ...o, [t]: s } : o;
625
+ }, {}), Jt = ({ input: r = {}, output: { dir: e } }) => ({
626
+ name: "colors/tokenManager",
627
+ executor: async ({ tokenManagerClient: o }) => {
470
628
  try {
471
- console.log("[styles/colors] Fetching styles from Figma...");
472
- const i = (await n.getStyles()).meta.styles, l = (s == null ? void 0 : s.variablePaths) || [], c = i.filter((u) => u.style_type === "FILL");
473
- if (console.log(`[styles/colors] Found ${c.length} color styles`), c.length === 0) {
474
- console.warn("[styles/colors] No color styles found in Figma file");
475
- return;
629
+ console.log("[colors/tokenManager] Generating colors from TokenManager...");
630
+ const { includeVariables: t, includeStyles: n = !0 } = r;
631
+ if (!(t != null && t.length) && !n)
632
+ throw new Error("Either includeVariables or includeStyles must be enabled");
633
+ if (!o.isLoaded())
634
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
635
+ const s = [], a = o.getVariables();
636
+ if (n) {
637
+ const l = o.getStyles();
638
+ console.log("[colors/tokenManager] Processing styles for colors..."), l.color && s.push(l.color);
476
639
  }
477
- console.log(`[styles/colors] Fetching ${c.length} color nodes from Figma...`);
478
- const g = await n.getNodes(c.map((u) => u.node_id)), d = Object.entries(g.nodes);
479
- let y = [];
480
- if (l.length > 1) {
481
- console.log(`[styles/colors] Reading ${l.length} variable files...`);
482
- try {
483
- y = await Promise.all(
484
- l.map(async (u) => {
485
- try {
486
- return await m.readJson(u);
487
- } catch (p) {
488
- throw console.error(`[styles/colors] Failed to read variable file: ${u}`, p), p;
489
- }
490
- })
491
- );
492
- } catch (u) {
493
- throw console.error("[styles/colors] Error reading variable files:", u), new Error(`Failed to read variable files: ${u.message}`);
494
- }
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);
495
644
  }
496
- console.log(`[styles/colors] Processing ${d.length} color nodes...`);
497
- const f = d.reduce((u, [, p]) => {
498
- var w, N, C;
499
- try {
500
- const { document: k } = p, A = me(k.name);
501
- if (k.type !== "RECTANGLE") return u;
502
- const T = (w = k.fills) == null ? void 0 : w[0];
503
- if (!T) return u;
504
- if (T.type === "SOLID" && y.length > 1) {
505
- const L = (C = (N = T.boundVariables) == null ? void 0 : N.color) == null ? void 0 : C.id;
506
- if (L) {
507
- const D = y.reduce((G, J) => {
508
- var z;
509
- const W = (z = Object.entries(J).find(
510
- ([, F]) => F.$extensions["com.figma.variableId"] === L
511
- )) == null ? void 0 : z[1];
512
- if (W) {
513
- const { components: F, alpha: H } = W.$value, Q = S({
514
- opacity: H,
515
- r: F[0],
516
- g: F[1],
517
- b: F[2]
518
- });
519
- return { ...G, [J.$extensions["com.figma.modeName"]]: Q };
520
- }
521
- return G;
522
- }, {});
523
- if (Object.keys(D).length > 1)
524
- return [
525
- ...u,
526
- {
527
- name: A,
528
- value: D
529
- }
530
- ];
531
- }
532
- }
533
- const I = fe(T);
534
- return I ? [
535
- ...u,
536
- {
537
- name: A,
538
- value: I
539
- }
540
- ] : u;
541
- } catch (k) {
542
- return console.warn("[styles/colors] Error processing color node:", k), u;
543
- }
544
- }, []);
545
- if (console.log(`[styles/colors] Generated ${f.length} color tokens`), f.length === 0) {
546
- console.warn("[styles/colors] No color tokens generated. Check your Figma styles configuration.");
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 }],
648
+ []
649
+ )
650
+ );
651
+ if (i.length === 0) {
652
+ console.warn("[colors/tokenManager] No color tokens generated");
547
653
  return;
548
654
  }
549
- console.log(`[styles/colors] Writing files to ${e} and ${r}...`), await M({
550
- colorTokens: f,
551
- jsonDir: e,
552
- stylesDir: r,
553
- jsonFileName: t,
554
- cssFileName: o
555
- }), console.log("[styles/colors] Successfully generated color files");
556
- } catch (a) {
557
- const i = a instanceof Error ? a.message : String(a);
558
- throw console.error("[styles/colors] ❌ Failed to generate colors from styles:", i), a instanceof Error && a.stack && console.error("[styles/colors] Stack trace:", a.stack), a;
655
+ console.log(`[colors/tokenManager] Generated ${i.length} color tokens`), console.log(`[colors/tokenManager] Writing files to ${e}...`), await Ke({
656
+ colorTokens: i,
657
+ dir: e
658
+ }), console.log("[colors/tokenManager] ✅ Successfully generated color files");
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;
559
662
  }
560
663
  }
561
- }), Re = ({
562
- input: { variablePaths: s },
563
- output: { jsonDir: e, stylesDir: r, jsonFileName: t = "colors.json", cssFileName: o = "colors.css" }
664
+ }), Le = (r) => ` @media (width <= ${r.breakpoint}px) {
665
+ .container {
666
+ padding-left: ${r.offset};
667
+ padding-right: ${r.offset};
668
+ }
669
+
670
+ .containerTablet {
671
+ padding-left: ${r.offset};
672
+ padding-right: ${r.offset};
673
+ }
674
+ }`, We = (r, e) => {
675
+ const o = e || "components", t = r.map((n) => Le(n)).join(`
676
+
677
+ `);
678
+ return `@layer ${o} {
679
+ ${t}
680
+ }`;
681
+ }, Ie = () => `import styles from './styles.module.css';
682
+
683
+ export const conatinerClassName = styles.container;
684
+ export const conatinerTabletClassName = 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();
692
+ return e === "0" || e === "0px";
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))
696
+ return s;
697
+ const l = i.value.find((u) => u.pattern === "columns");
698
+ if (!(l != null && l.offset))
699
+ return s;
700
+ const c = e.resolveVariableValueString(l.offset);
701
+ return !c || typeof c != "string" || Ge(c) ? s : [
702
+ ...s,
703
+ {
704
+ breakpoint: Number(a),
705
+ offset: c
706
+ }
707
+ ];
708
+ }, []).reduce((s, a) => {
709
+ const i = s[s.length - 1];
710
+ return i && x(i.offset, a.offset) || s.push(a), s;
711
+ }, []), qt = ({
712
+ input: r = {},
713
+ output: { dir: e }
564
714
  }) => ({
565
- name: "variables/colors",
566
- executor: async () => {
715
+ name: "container/tokenManager",
716
+ executor: async ({ tokenManagerClient: o }) => {
567
717
  try {
568
- if (!s.length)
569
- throw new Error("At least one variable file path is required");
570
- console.log(`[variables/colors] Reading ${s.length} variable files...`);
571
- const n = await Promise.all(
572
- s.map(async (l) => {
573
- try {
574
- return console.log(`[variables/colors] Reading file: ${l}`), await m.readJson(l);
575
- } catch (c) {
576
- throw console.error(`[variables/colors] Failed to read variable file: ${l}`, c), new Error(`Failed to read variable file "${l}": ${c.message}`);
577
- }
578
- })
579
- );
580
- console.log(`[variables/colors] Processing ${n.length} variable files...`);
581
- const a = /* @__PURE__ */ new Map();
582
- n.forEach((l, c) => {
583
- try {
584
- if (!l.$extensions || !l.$extensions["com.figma.modeName"]) {
585
- console.warn(
586
- `[variables/colors] File ${s[c]} is missing modeName in extensions`
587
- );
588
- return;
589
- }
590
- const g = l.$extensions["com.figma.modeName"];
591
- Object.entries(l).forEach(([d, y]) => {
592
- if (d !== "$extensions")
593
- try {
594
- const f = y;
595
- if (!f || f.$type !== "color") return;
596
- if (!f.$value || !f.$value.components) {
597
- console.warn(
598
- `[variables/colors] Variable "${d}" in mode "${g}" has invalid structure`
599
- );
600
- return;
601
- }
602
- const { components: u, alpha: p } = f.$value, w = S({
603
- opacity: p ?? 1,
604
- r: u[0],
605
- g: u[1],
606
- b: u[2]
607
- });
608
- a.has(d) || a.set(d, {}), a.get(d)[g] = w;
609
- } catch (f) {
610
- console.warn(
611
- `[variables/colors] Error processing variable "${d}" in mode "${g}":`,
612
- f
613
- );
614
- }
615
- });
616
- } catch (g) {
617
- console.error(`[variables/colors] Error processing file ${s[c]}:`, g);
618
- }
619
- });
620
- const i = Array.from(a.entries()).map(([l, c]) => ({
621
- name: l,
622
- value: Object.keys(c).length > 1 ? c : Object.values(c)[0]
623
- }));
624
- if (console.log(`[variables/colors] Generated ${i.length} color tokens`), i.length === 0) {
625
- console.warn(
626
- "[variables/colors] No color tokens generated. Check your variable files structure."
627
- );
718
+ console.log("[container/tokenManager] Generating container styles...");
719
+ const { layer: t } = r;
720
+ if (!o.isLoaded())
721
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
722
+ console.log("[container/tokenManager] Extracting container tokens...");
723
+ const n = o.getStyles();
724
+ if (!n.grid)
725
+ throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
726
+ const s = Je(n.grid, o);
727
+ if (!s.length) {
728
+ console.warn("[container/tokenManager] No container tokens found.");
628
729
  return;
629
730
  }
630
- console.log(`[variables/colors] Writing files to ${e} and ${r}...`), await M({
631
- colorTokens: i,
632
- jsonDir: e,
633
- stylesDir: r,
634
- jsonFileName: t,
635
- cssFileName: o
636
- }), console.log("[variables/colors] ✅ Successfully generated color files");
637
- } catch (n) {
638
- const a = n instanceof Error ? n.message : String(n);
639
- throw console.error("[variables/colors] ❌ Failed to generate colors from variables:", a), n instanceof Error && n.stack && console.error("[variables/colors] Stack trace:", n.stack), n;
731
+ console.log(
732
+ `[container/tokenManager] Found ${s.length} container tokens: ${s.map((a) => a.breakpoint).join(", ")}`
733
+ ), console.log(`[container/tokenManager] Writing files to ${e}...`), await ze({
734
+ containerTokens: s,
735
+ dir: e,
736
+ layer: t
737
+ }), console.log("[container/tokenManager] ✅ Successfully generated container files");
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;
640
741
  }
641
742
  }
642
- }), K = (s, e) => Object.keys(s).reduce(
643
- (r, t) => {
644
- const o = s[t], n = e ? `${e}-${t}` : t;
645
- if (o && typeof o == "object" && "type" in o && "value" in o) {
646
- const i = Object.keys(o.value), l = i.length > 1 ? o.value : o.value[i[0]], c = { [n]: l };
647
- return { ...r, ...c };
743
+ }), qe = "styles.css", He = "index.ts", U = (r, e) => {
744
+ if (!e.length) return "";
745
+ const o = e.map((t) => ` ${t}`).join(`
746
+ `);
747
+ return `${r} {
748
+ ${o}
749
+ }`;
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(
751
+ (e, o) => {
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};`] };
756
+ }, e);
757
+ },
758
+ { root: [] }
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;
764
+ }, []).join(`
765
+
766
+ `);
767
+ return [e, o].filter(Boolean).join(`
768
+
769
+ `);
770
+ }, _e = (r) => `${`const shadows = {
771
+ ${r.map((t) => ` '${t.name}': 'var(${Y(t.name)})'`).join(`,
772
+ `)}
773
+ } as const;`}
774
+
775
+ type ShadowsKeysType = keyof typeof shadows;
776
+
777
+ export { shadows, type ShadowsKeysType };
778
+ `, et = async ({
779
+ tsContent: r,
780
+ cssContent: e,
781
+ dir: o
782
+ }) => {
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;
792
+ if (n && typeof n == "object" && "type" in n && "value" in n) {
793
+ const i = {
794
+ [s]: n.value.map(Qe).join(", ")
795
+ };
796
+ return { ...o, ...i };
648
797
  }
649
- const a = K(o, n);
650
- return { ...r, ...a };
798
+ const a = _(n, s);
799
+ return { ...o, ...a };
651
800
  },
652
801
  {}
653
- ), ve = (s) => `cl-${s}`, O = (s, e, r) => {
654
- const { type: t, value: o } = s;
655
- if (t !== "color") return;
656
- if (typeof o == "string") {
657
- if (!e.isVariableReference(o)) return { ...s, value: o };
658
- const i = e.getToken(e.getVariablePath(o)), l = i ? O(i, e, r) : void 0;
659
- return l != null && l.value ? { ...s, ...i } : void 0;
660
- }
661
- const a = Object.keys(o).reduce((i, l) => {
662
- if (r && l !== r) return i;
663
- const c = o[l];
664
- if (typeof c != "string") return i;
665
- if (!e.isVariableReference(c)) return { ...i, [l]: c };
666
- const g = e.getToken(e.getVariablePath(c)), d = g ? O(g, e, l) : void 0;
667
- return d != null && d.value ? { ...i, ...d.value } : i;
668
- }, {});
669
- if (Object.keys(a).length)
670
- return { ...s, value: a };
671
- }, U = (s, e) => Object.keys(s).reduce((r, t) => {
672
- const o = s[t];
673
- if (o.type && o.value) {
674
- const a = O(o, e);
675
- return a ? { ...r, [t]: a } : r;
676
- }
677
- const n = U(o, e);
678
- return n ? { ...r, [t]: n } : r;
679
- }, {}), Me = ({
680
- input: s = {},
681
- output: { jsonDir: e, stylesDir: r, jsonFileName: t = "colors.json", cssFileName: o = "colors.css" }
682
- }) => ({
683
- name: "colors/tokenManager",
684
- executor: async ({ tokenManagerClient: n }) => {
802
+ ), Ht = ({ input: r = {}, output: { dir: e } }) => ({
803
+ name: "shadows/tokenManager",
804
+ executor: async ({ tokenManagerClient: o }) => {
685
805
  try {
686
- console.log("[colors/tokenManager] Generating colors from TokenManager...");
687
- const { includeVariables: a, includeStyles: i = !0 } = s;
688
- if (!(a != null && a.length) && !i)
689
- throw new Error("Either includeVariables or includeStyles must be enabled");
690
- if (!n.isLoaded())
806
+ console.log("[shadows/tokenManager] Generating shadows from TokenManager...");
807
+ const { includeStyles: t = !0 } = r;
808
+ if (!t)
809
+ throw new Error("includeStyles must be enabled for shadows generation");
810
+ if (!o.isLoaded())
691
811
  throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
692
- const l = [], c = n.getVariables();
693
- if (i) {
694
- const d = n.getStyles();
695
- console.log("[colors/tokenManager] Processing styles for colors..."), d.color && l.push(d.color);
696
- }
697
- if (a != null && a.length) {
698
- console.log(`[colors/tokenManager] Processing ${a.length} variable groups...`);
699
- const d = a.map((y) => c[y]).filter(Boolean);
700
- l.push(...d);
812
+ const n = [];
813
+ if (t) {
814
+ const a = o.getStyles();
815
+ console.log("[shadows/tokenManager] Processing styles for shadows..."), a.effect && n.push(a.effect);
701
816
  }
702
- const g = l.map((d) => U(d, n)).flatMap(
703
- (d) => Object.entries(K(d, "")).reduce(
704
- (y, [f, u]) => [...y, { name: ve(f), value: u }],
817
+ const s = n.flatMap(
818
+ (a) => Object.entries(_(a, "")).reduce(
819
+ (i, [l, c]) => [...i, { name: l, value: c }],
705
820
  []
706
821
  )
707
822
  );
708
- if (g.length === 0) {
709
- console.warn("[colors/tokenManager] No color tokens generated");
823
+ if (s.length === 0) {
824
+ console.warn("[shadows/tokenManager] No shadow tokens generated");
710
825
  return;
711
826
  }
712
- console.log(`[colors/tokenManager] Generated ${g.length} color tokens`), console.log(`[colors/tokenManager] Writing files to ${e} and ${r}...`), await M({
713
- colorTokens: g,
714
- jsonDir: e,
715
- stylesDir: r,
716
- jsonFileName: t,
717
- cssFileName: o
718
- }), console.log("[colors/tokenManager] Successfully generated color files");
719
- } catch (a) {
720
- const i = a instanceof Error ? a.message : String(a);
721
- throw console.error("[colors/tokenManager] Failed to generate colors:", i), a instanceof Error && a.stack && console.error("[colors/tokenManager] Stack trace:", a.stack), a;
827
+ console.log(`[shadows/tokenManager] Generated ${s.length} shadow tokens`), console.log(`[shadows/tokenManager] Writing files to ${e}...`), await tt({
828
+ shadowTokens: s,
829
+ dir: e
830
+ }), console.log("[shadows/tokenManager] ✅ Successfully generated shadow files");
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;
834
+ }
835
+ }
836
+ }), rt = "styles.module.css", ot = "index.ts", nt = "typography.ts", L = "sans-serif", W = (r, e) => {
837
+ if (!e.length) return "";
838
+ const o = e.map((t) => ` ${t}`).join(`
839
+ `);
840
+ return `${r} {
841
+ ${o}
842
+ }`;
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) => {
851
+ const o = {};
852
+ return Object.entries(r).forEach(([t, n]) => {
853
+ const s = t === "fontFamily" ? ee(n, e) : n, a = t.replace(/([A-Z])/g, "-$1");
854
+ o[a] = s;
855
+ }), o;
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 }] : [
862
+ {
863
+ breakpoint: null,
864
+ css: {
865
+ ...n,
866
+ ...l
867
+ }
868
+ }
869
+ ];
870
+ },
871
+ [
872
+ {
873
+ breakpoint: null,
874
+ css: n
875
+ }
876
+ ]
877
+ );
878
+ }, te = () => ({
879
+ base: {},
880
+ breakpoints: {}
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
885
+ });
886
+ }, j = (r, e, o, t) => {
887
+ st(e.value, o, t).forEach(({ breakpoint: s, css: a }) => {
888
+ if (s === null) {
889
+ r.base[e.name] = a;
890
+ return;
891
+ }
892
+ P(r, s, e.name, a);
893
+ });
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)} }`;
898
+ }, "");
899
+ return e + o;
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(";");
905
+ return e + `.typo-${o} { ${n} }`;
906
+ }, ""), G = (r) => {
907
+ if (typeof r == "number") return Number.isFinite(r) ? r : null;
908
+ const e = Number.parseFloat(r);
909
+ return Number.isFinite(e) ? e : null;
910
+ }, J = (r) => {
911
+ if (typeof r == "number") return r / 16;
912
+ const e = r.trim().toLowerCase();
913
+ if (e.endsWith("rem")) return G(e);
914
+ if (e.endsWith("px")) {
915
+ const o = G(e);
916
+ return o === null ? null : o / 16;
917
+ }
918
+ return null;
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);
927
+ if (s.length < 2) {
928
+ j(r, e, o, t);
929
+ return;
930
+ }
931
+ const a = s[0], i = s[s.length - 1];
932
+ if (a.width <= i.width) {
933
+ j(r, e, o, t);
934
+ return;
935
+ }
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);
939
+ return;
940
+ }
941
+ r.base[e.name] = {
942
+ ...l,
943
+ ...c
944
+ };
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 })
953
+ };
954
+ }, {});
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());
959
+ return re(n);
960
+ }, ut = (r) => r.length ? `import styles from './styles.module.css';
961
+ import { typography } from './typography';
962
+
963
+ type TypographyKeysType = keyof typeof typography;
964
+
965
+ const getTypographyClass = (typographyKey: TypographyKeysType) => styles[\`typo-\${typographyKey}\`];
966
+
967
+ export { typography, getTypographyClass, type TypographyKeysType };
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]) => ({
972
+ ...a,
973
+ [i]: I(l, e)
974
+ }),
975
+ {}
976
+ );
977
+ return ` '${t.name}': {
978
+ base: ${JSON.stringify(n, null, 8).replace(/\n/g, `
979
+ `)},
980
+ breakpoints: ${JSON.stringify(s, null, 8).replace(/\n/g, `
981
+ `)}
982
+ }`;
983
+ }).join(`,
984
+ `)}
985
+ } as const;
986
+
987
+ export { typography };
988
+ ` : "", yt = async ({
989
+ indexTSContent: r,
990
+ typographyTSContent: e,
991
+ cssContent: o,
992
+ dir: t
993
+ }) => {
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 });
996
+ await Promise.all([n, s, a]);
997
+ }, ft = async ({
998
+ typographyTokens: r,
999
+ dir: e,
1000
+ breakpoints: o,
1001
+ fontFamily: t,
1002
+ fluid: n
1003
+ }) => {
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;
1009
+ if (!("type" in s) || !("value" in s))
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 });
1019
+ });
1020
+ else {
1021
+ const f = e.resolveVariableValueString(u);
1022
+ f && (l.base = { ...l.base, [c]: f });
1023
+ }
1024
+ return l;
1025
+ },
1026
+ { base: {}, breakpoints: {} }
1027
+ );
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];
1031
+ if (!("type" in s) || !("value" in s))
1032
+ return { ...o, ...ne(s, n) };
1033
+ const a = s.value;
1034
+ return { ...o, [n]: a };
1035
+ }, {}), Zt = ({ input: r, output: { dir: e } }) => ({
1036
+ name: "typography/tokenManager",
1037
+ executor: async ({ tokenManagerClient: o }) => {
1038
+ try {
1039
+ console.log("[typography/tokenManager] Generating typography from TokenManager...");
1040
+ const { breakpoints: t, fontFamily: n } = r, s = r.fluid ?? !0;
1041
+ if (!o.isLoaded())
1042
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
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) => ({
1047
+ ...u,
1048
+ ...oe(d, o, { breakpoints: r.breakpoints })
1049
+ }),
1050
+ {}
1051
+ ), c = Object.entries(ne(l)).map(
1052
+ ([u, d]) => ({ name: u, value: d })
1053
+ );
1054
+ if (c.length === 0) {
1055
+ console.warn("[typography/tokenManager] No typography tokens generated");
1056
+ return;
1057
+ }
1058
+ console.log(`[typography/tokenManager] Generated ${c.length} typography tokens`), console.log(`[typography/tokenManager] Writing files to ${e}...`), await ft({
1059
+ typographyTokens: c,
1060
+ dir: e,
1061
+ breakpoints: t,
1062
+ fontFamily: n || {},
1063
+ fluid: s
1064
+ }), console.log("[typography/tokenManager] ✅ Successfully generated typography files");
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;
1068
+ }
1069
+ }
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) => {
1071
+ const o = se(e);
1072
+ if (!o.length)
1073
+ throw new Error("variablePath must contain at least one segment");
1074
+ const t = q(r, o);
1075
+ if (t === void 0)
1076
+ throw new Error(`Variables subtree not found at path: ${o.join(".")}`);
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 };
1085
+ }, {});
1086
+ return [{ flatName: e, resolvedByMode: n }];
1087
+ }
1088
+ return pt(r) ? Object.keys(r).flatMap((t) => {
1089
+ const n = r[t], s = e ? `${e}-${t}` : t;
1090
+ return ae(n, s, o);
1091
+ }) : [];
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);
1096
+ if (!e.length)
1097
+ throw new Error("variablePath must contain at least one segment");
1098
+ const o = e[e.length - 1];
1099
+ return {
1100
+ variablesClassName: `${o}-variables`,
1101
+ variableNamePrefix: o
1102
+ };
1103
+ }, $t = (r, e) => {
1104
+ const t = ie(r.variablePath).variableNamePrefix, n = e.variablesClassName ?? `${t}-variables`;
1105
+ return {
1106
+ variableNamePrefix: t,
1107
+ variablesClassName: n
1108
+ };
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);
1122
+ return { ...o, [n]: { ...o[n], ...e[n] } };
1123
+ },
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: {} };
1130
+ }
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: {} };
1135
+ }
1136
+ if (i.length === 1) {
1137
+ const u = i[0], d = r.resolvedByMode[u.mode] ?? "";
1138
+ return { base: { [s]: d }, byBreakpoint: {} };
1139
+ }
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 } };
1145
+ }, {});
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);
1150
+ return {
1151
+ base: { ...t.base, ...s },
1152
+ breakpoints: Tt(t.breakpoints, a)
1153
+ };
1154
+ },
1155
+ { base: {}, breakpoints: {} }
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}
1162
+ }`;
1163
+ }).filter(Boolean).join(`
1164
+
1165
+ `);
1166
+ return i ? `${a}
1167
+
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);
1209
+ return [
1210
+ `const utilityVariableNameByKey = ${s} as const;`,
1211
+ "",
1212
+ `type ${l} = keyof typeof utilityVariableNameByKey;`,
1213
+ "",
1214
+ `const getUtilityCssVariableName = (key: ${l}): string =>`,
1215
+ " `--${utilityVariableNameByKey[key]}`;",
1216
+ "",
1217
+ `const ${i} = (key: ${l}): string =>`,
1218
+ " `var(${getUtilityCssVariableName(key)})`;",
1219
+ "",
1220
+ "export {",
1221
+ " getUtilityCssVariableName,",
1222
+ ` ${i},`,
1223
+ ` type ${l},`,
1224
+ "};",
1225
+ ""
1226
+ ].join(`
1227
+ `);
1228
+ }, Ot = "styles.css", Et = "index.ts", Bt = async ({
1229
+ dir: r,
1230
+ globalCss: e,
1231
+ indexTs: o
1232
+ }) => {
1233
+ await y.delete(r), await Promise.all([
1234
+ y.write(Ot, e, { directory: r }),
1235
+ y.write(Et, o, { directory: r })
1236
+ ]);
1237
+ }, Kt = async ({
1238
+ tokens: r,
1239
+ input: e,
1240
+ output: o
1241
+ }) => {
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 }) => ({
1245
+ name: "utilities/tokenManager",
1246
+ executor: async ({ tokenManagerClient: o }) => {
1247
+ var t;
1248
+ try {
1249
+ if (console.log("[utilities/tokenManager] Generating utility classes from TokenManager..."), !o.isLoaded())
1250
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
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}"`);
1256
+ return;
1257
+ }
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");
1259
+ } catch (n) {
1260
+ const s = n instanceof Error ? n.message : String(n);
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;
722
1262
  }
723
1263
  }
724
1264
  });
725
1265
  export {
726
- ie as TokenManager,
727
- Ve as colorsFromStyles,
728
- Me as colorsFromTokenManager,
729
- Re as colorsFromVariables,
730
- xe as generate,
731
- Oe as init
1266
+ we as BREAKPOINTS_NAMES,
1267
+ be as TokenManager,
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,
1289
+ bt as utilityFlatNameMatchesIncludePattern,
1290
+ Bt as writeUtilitiesFiles
732
1291
  };