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

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 (86) hide show
  1. package/README.md +55 -28
  2. package/classes/TokenManager/index.d.ts +19 -4
  3. package/classes/TokenManager/index.d.ts.map +1 -1
  4. package/classes/TokenManager/types/ds.d.ts +23 -12
  5. package/classes/TokenManager/types/ds.d.ts.map +1 -1
  6. package/classes/TokenManager/types/figma.d.ts +11 -3
  7. package/classes/TokenManager/types/figma.d.ts.map +1 -1
  8. package/commands/generate/index.d.ts.map +1 -1
  9. package/common/lodash.d.ts +8 -0
  10. package/common/lodash.d.ts.map +1 -0
  11. package/index.cjs +96 -5
  12. package/index.mjs +1039 -493
  13. package/modules/breakpoints/breakpointsFromTokenManager/index.d.ts +2 -0
  14. package/modules/breakpoints/breakpointsFromTokenManager/index.d.ts.map +1 -0
  15. package/modules/breakpoints/breakpointsFromTokenManager/module.d.ts +13 -0
  16. package/modules/breakpoints/breakpointsFromTokenManager/module.d.ts.map +1 -0
  17. package/modules/breakpoints/breakpointsFromTokenManager/utils.d.ts +8 -0
  18. package/modules/breakpoints/breakpointsFromTokenManager/utils.d.ts.map +1 -0
  19. package/modules/breakpoints/index.d.ts +3 -0
  20. package/modules/breakpoints/index.d.ts.map +1 -0
  21. package/modules/breakpoints/types.d.ts +6 -0
  22. package/modules/breakpoints/types.d.ts.map +1 -0
  23. package/modules/breakpoints/utils.d.ts +16 -0
  24. package/modules/breakpoints/utils.d.ts.map +1 -0
  25. package/modules/colors/colorsFromTokenManager/index.d.ts +2 -0
  26. package/modules/colors/colorsFromTokenManager/index.d.ts.map +1 -0
  27. package/modules/colors/{colorsFromTokenManager.d.ts → colorsFromTokenManager/module.d.ts} +4 -7
  28. package/modules/colors/colorsFromTokenManager/module.d.ts.map +1 -0
  29. package/modules/colors/colorsFromTokenManager/utils.d.ts +3 -0
  30. package/modules/colors/colorsFromTokenManager/utils.d.ts.map +1 -0
  31. package/modules/colors/index.d.ts +0 -2
  32. package/modules/colors/index.d.ts.map +1 -1
  33. package/modules/colors/utils.d.ts +8 -33
  34. package/modules/colors/utils.d.ts.map +1 -1
  35. package/modules/container/containerFromTokenManager/index.d.ts +2 -0
  36. package/modules/container/containerFromTokenManager/index.d.ts.map +1 -0
  37. package/modules/container/containerFromTokenManager/module.d.ts +13 -0
  38. package/modules/container/containerFromTokenManager/module.d.ts.map +1 -0
  39. package/modules/container/index.d.ts +3 -0
  40. package/modules/container/index.d.ts.map +1 -0
  41. package/modules/container/types.d.ts +5 -0
  42. package/modules/container/types.d.ts.map +1 -0
  43. package/modules/container/utils.d.ts +12 -0
  44. package/modules/container/utils.d.ts.map +1 -0
  45. package/modules/index.d.ts +5 -0
  46. package/modules/index.d.ts.map +1 -1
  47. package/modules/shadows/index.d.ts +3 -0
  48. package/modules/shadows/index.d.ts.map +1 -0
  49. package/modules/shadows/shadowsFromTokenManager.d.ts +13 -0
  50. package/modules/shadows/shadowsFromTokenManager.d.ts.map +1 -0
  51. package/modules/shadows/types.d.ts +6 -0
  52. package/modules/shadows/types.d.ts.map +1 -0
  53. package/modules/shadows/utils.d.ts +22 -0
  54. package/modules/shadows/utils.d.ts.map +1 -0
  55. package/modules/typography/index.d.ts +2 -0
  56. package/modules/typography/index.d.ts.map +1 -0
  57. package/modules/typography/types.d.ts +10 -0
  58. package/modules/typography/types.d.ts.map +1 -0
  59. package/modules/typography/typographyFromTokenManager/index.d.ts +2 -0
  60. package/modules/typography/typographyFromTokenManager/index.d.ts.map +1 -0
  61. package/modules/typography/typographyFromTokenManager/module.d.ts +19 -0
  62. package/modules/typography/typographyFromTokenManager/module.d.ts.map +1 -0
  63. package/modules/typography/utils.d.ts +56 -0
  64. package/modules/typography/utils.d.ts.map +1 -0
  65. package/modules/utilities/index.d.ts +4 -0
  66. package/modules/utilities/index.d.ts.map +1 -0
  67. package/modules/utilities/types.d.ts +48 -0
  68. package/modules/utilities/types.d.ts.map +1 -0
  69. package/modules/utilities/utilitiesFromTokenManager/index.d.ts +2 -0
  70. package/modules/utilities/utilitiesFromTokenManager/index.d.ts.map +1 -0
  71. package/modules/utilities/utilitiesFromTokenManager/module.d.ts +4 -0
  72. package/modules/utilities/utilitiesFromTokenManager/module.d.ts.map +1 -0
  73. package/modules/utilities/utils.d.ts +80 -0
  74. package/modules/utilities/utils.d.ts.map +1 -0
  75. package/package.json +1 -2
  76. package/temporarilyUnnecessary/colorsFromStyles.d.ts +1 -0
  77. package/temporarilyUnnecessary/colorsFromStyles.d.ts.map +1 -0
  78. package/temporarilyUnnecessary/colorsFromVariables.d.ts +1 -0
  79. package/temporarilyUnnecessary/colorsFromVariables.d.ts.map +1 -0
  80. package/temporarilyUnnecessary/utils.d.ts +1 -0
  81. package/temporarilyUnnecessary/utils.d.ts.map +1 -0
  82. package/modules/colors/colorsFromStyles.d.ts +0 -16
  83. package/modules/colors/colorsFromStyles.d.ts.map +0 -1
  84. package/modules/colors/colorsFromTokenManager.d.ts.map +0 -1
  85. package/modules/colors/colorsFromVariables.d.ts +0 -16
  86. package/modules/colors/colorsFromVariables.d.ts.map +0 -1
package/index.mjs CHANGED
@@ -1,90 +1,89 @@
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";
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);
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";
10
9
  const h = class h {
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 F(h.baseDir, e);
15
14
  }
16
- static resolveWritePath(e, r) {
17
- const t = x(h.baseDir, r ?? "");
15
+ static resolveWritePath(e, o) {
16
+ const r = F(h.baseDir, o ?? "");
18
17
  return {
19
- targetDir: t,
20
- targetPath: x(t, e)
18
+ targetDir: r,
19
+ targetPath: F(r, 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 r = h.resolveReadPath(e);
30
29
  try {
31
- return await P(t, { encoding: r });
32
- } catch (o) {
33
- h.handleReadError(o, t);
30
+ return await V(r, { encoding: o });
31
+ } catch (n) {
32
+ h.handleReadError(n, r);
34
33
  }
35
34
  }
36
35
  static async readBuffer(e) {
37
- const r = h.resolveReadPath(e);
36
+ const o = h.resolveReadPath(e);
38
37
  try {
39
- return await P(r);
40
- } catch (t) {
41
- h.handleReadError(t, r);
38
+ return await V(o);
39
+ } catch (r) {
40
+ h.handleReadError(r, o);
42
41
  }
43
42
  }
44
43
  static async readJson(e) {
45
- const r = h.resolveReadPath(e);
44
+ const o = h.resolveReadPath(e);
46
45
  try {
47
- const t = await P(r, { encoding: "utf8" });
46
+ const r = await V(o, { encoding: "utf8" });
48
47
  try {
49
- return JSON.parse(t);
50
- } catch (o) {
51
- throw new Error(`Failed to parse JSON from "${r}": ${o.message}`);
48
+ return JSON.parse(r);
49
+ } catch (n) {
50
+ throw new Error(`Failed to parse JSON from "${o}": ${n.message}`);
52
51
  }
53
- } catch (t) {
54
- h.handleReadError(t, r);
52
+ } catch (r) {
53
+ h.handleReadError(r, 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))
60
- throw new Error(`File ${i} already exists`);
61
- return await re(a, { recursive: !0 }), await te(i, r, { encoding: "utf8" }), i;
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;
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, r = "", n) {
63
+ const s = o.startsWith(".") ? o : `.${o}`, a = `${e}${s}`;
64
+ return h.write(a, r, n);
66
65
  }
67
66
  static exists(e) {
68
- const r = h.resolveReadPath(e);
69
- return j(r);
67
+ const o = h.resolveReadPath(e);
68
+ return C(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: r } = h.resolveWritePath(e, o);
72
+ C(r) && await ge(r, { recursive: !0, force: !0 });
74
73
  }
75
74
  };
76
- b(h, "baseDir", process.cwd());
77
- let m = h;
78
- const v = class v {
75
+ m(h, "baseDir", process.cwd());
76
+ let d = h;
77
+ const $ = class $ {
79
78
  static async create() {
80
- if (m.exists(v.configFileName))
79
+ if (d.exists($.configFileName))
81
80
  throw new Error("The file already exists");
82
- await m.write(v.configFileName, "", { overwrite: !1 });
81
+ await d.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 de.compile(
86
+ `${k.resolve(process.cwd(), $.configFileName)}`
88
87
  );
89
88
  if (!e) throw new Error();
90
89
  return e.default;
@@ -93,61 +92,61 @@ const v = class v {
93
92
  }
94
93
  }
95
94
  };
96
- b(v, "configFileName", "gts.config.ts");
97
- let E = v;
98
- const ne = (s) => {
95
+ m($, "configFileName", "gts.config.ts");
96
+ let j = $;
97
+ const pe = (t) => {
99
98
  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]);
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]);
102
101
  }), 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;
102
+ }, he = (t, e = 50) => {
103
+ const o = [];
104
+ for (let r = 0; r < t.length; r += e)
105
+ o.push(t.slice(r, r + e));
106
+ return o;
108
107
  };
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;
108
+ class P {
109
+ constructor(e, o) {
110
+ m(this, "figmaToken");
111
+ m(this, "fileId");
112
+ m(this, "onTimeMeasureHandler");
113
+ this.figmaToken = e, this.fileId = o;
115
114
  }
116
115
  setOnTimeMeasureHandler(e) {
117
116
  this.onTimeMeasureHandler = e;
118
117
  }
119
118
  static async returnJSON(e) {
120
- const r = await e.json();
119
+ const o = await e.json();
121
120
  if (!e.ok) {
122
- let t = "Request failed";
123
- throw new Error(t);
121
+ let r = "Request failed";
122
+ throw new Error(r);
124
123
  }
125
- return r;
124
+ return o;
126
125
  }
127
- async performControlledRequest(e, { params: r = {}, timeout: t = 3e4, abortController: o = new AbortController() } = {}) {
128
- var f;
126
+ async performControlledRequest(e, { params: o = {}, timeout: r = 3e4, abortController: n = new AbortController() } = {}) {
127
+ var g;
129
128
  if (!this.figmaToken || !this.fileId)
130
129
  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
+ 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)}` : ""}`;
132
131
  console.log("endpoinWithParams=", a);
133
- const i = setTimeout(() => o.abort(), t), l = {
132
+ const l = setTimeout(() => n.abort(), r), i = {
134
133
  "Content-Type": "application/json",
135
134
  ...this.figmaToken && { "X-Figma-Token": this.figmaToken }
136
135
  }, c = {
137
136
  method: "GET",
138
- headers: l,
139
- signal: o.signal
140
- }, g = performance.now(), d = await fetch(`${a}`, c);
141
- clearTimeout(i);
142
- const y = performance.now() - g;
143
- return (f = this.onTimeMeasureHandler) == null || f.call(this, a, l, y), d;
144
- }
145
- async request(e, r) {
146
- var o;
147
- const t = await this.performControlledRequest(e, {
148
- ...r
137
+ headers: i,
138
+ 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;
143
+ }
144
+ async request(e, o) {
145
+ var n;
146
+ const r = await this.performControlledRequest(e, {
147
+ ...o
149
148
  });
150
- return (o = t.headers.get("content-type")) != null && o.includes("application/json") ? V.returnJSON(t) : t;
149
+ return (n = r.headers.get("content-type")) != null && n.includes("application/json") ? P.returnJSON(r) : r;
151
150
  }
152
151
  async getComponents() {
153
152
  return this.request(`/files/${this.fileId}/components`);
@@ -156,36 +155,88 @@ class V {
156
155
  return this.request(`/files/${this.fileId}/styles`);
157
156
  }
158
157
  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);
158
+ const o = he(e).map(
159
+ (s) => this.request(`/files/${this.fileId}/nodes`, { params: { ids: s.join(",") } })
160
+ ), r = await Promise.all(o);
162
161
  return {
163
- ...t[0],
164
- nodes: t.reduce((n, a) => ({ ...n, ...a.nodes }), {})
162
+ ...r[0],
163
+ nodes: r.reduce((s, a) => ({ ...s, ...a.nodes }), {})
165
164
  };
166
165
  }
167
166
  }
168
- class ie {
167
+ const q = (t, e) => {
168
+ const o = Array.isArray(e) ? e : e.split(".");
169
+ let r = t;
170
+ for (const n of o) {
171
+ if (r == null || typeof r != "object") return;
172
+ r = r[n];
173
+ }
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]);
181
+ return o;
182
+ };
183
+ function x(t, e) {
184
+ if (t === e)
185
+ return !0;
186
+ if (t == null || e == null)
187
+ return t === e;
188
+ if (typeof t != typeof e)
189
+ 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)
196
+ return !1;
197
+ for (let o = 0; o < t.length; o++)
198
+ if (!x(t[o], e[o]))
199
+ return !1;
200
+ return !0;
201
+ }
202
+ if (typeof t == "object" && typeof e == "object") {
203
+ const o = Object.keys(t), r = Object.keys(e);
204
+ if (o.length !== r.length)
205
+ return !1;
206
+ for (const n of o)
207
+ if (!r.includes(n) || !x(t[n], e[n]))
208
+ return !1;
209
+ return !0;
210
+ }
211
+ return !1;
212
+ }
213
+ const R = {
214
+ color: {},
215
+ effect: {},
216
+ text: {},
217
+ grid: {}
218
+ };
219
+ class be {
169
220
  constructor(e) {
170
221
  // files
171
- b(this, "tokensDir");
172
- b(this, "manifestPath");
173
- // figma data
174
- b(this, "variables");
175
- b(this, "styles");
222
+ m(this, "tokensDir");
223
+ m(this, "manifestPath");
224
+ // result data
225
+ m(this, "variables");
226
+ m(this, "styles");
176
227
  // flags
177
- b(this, "loaded", !1);
178
- this.tokensDir = e || "", this.manifestPath = $.join(this.tokensDir, "manifest.json");
228
+ m(this, "loaded", !1);
229
+ this.tokensDir = e || "", this.manifestPath = k.join(this.tokensDir, "manifest.json");
179
230
  }
180
231
  isLoaded() {
181
232
  return this.loaded && !!this.variables && !!this.styles;
182
233
  }
183
234
  /** to camelCase */
184
235
  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;
236
+ 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;
189
240
  }).join("");
190
241
  }
191
242
  /**
@@ -193,10 +244,10 @@ class ie {
193
244
  */
194
245
  parseVariableString(e) {
195
246
  if (typeof e != "string") return e;
196
- const r = /^\{(.+)\}$/, t = e.match(r);
197
- if (t) {
198
- const o = t[1].trim();
199
- return `{${this.normalizeKey(o)}}`;
247
+ const o = /^\{(.+)\}$/, r = e.match(o);
248
+ if (r) {
249
+ const n = r[1].trim();
250
+ return `{${this.normalizeKey(n)}}`;
200
251
  }
201
252
  return e;
202
253
  }
@@ -205,59 +256,59 @@ class ie {
205
256
  */
206
257
  createVariableFileList(e) {
207
258
  return Object.entries(e).flatMap(
208
- ([r, t]) => Object.entries(t.modes).flatMap(
209
- ([o, n]) => n.map((a) => ({
259
+ ([o, r]) => Object.entries(r.modes).flatMap(
260
+ ([n, s]) => s.map((a) => ({
210
261
  fileName: a,
211
- modeName: this.normalizeKey(o.trim()),
212
- collectionName: r
262
+ modeName: this.normalizeKey(n.trim()),
263
+ collectionName: o
213
264
  }))
214
265
  )
215
266
  );
216
267
  }
217
268
  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) }), {})));
219
- }
220
- getTokensFromFile(e, r) {
221
- return Object.entries(e).reduce((t, [o, n]) => "$type" in n && "$value" in n ? {
222
- ...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)
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
+ }
271
+ getTokensFromFile(e, o) {
272
+ return Object.entries(e).reduce((r, [n, s]) => "$type" in s && "$value" in s ? {
273
+ ...r,
274
+ [this.normalizeKey(n)]: {
275
+ type: s.$type,
276
+ description: s.$description,
277
+ value: o ? { [this.normalizeKey(o)]: this.parseValue(s.$value) } : this.parseValue(s.$value)
227
278
  }
228
- } : { ...t, [this.normalizeKey(o)]: this.getTokensFromFile(n, r) }, {});
279
+ } : { ...r, [this.normalizeKey(n)]: this.getTokensFromFile(s, o) }, {});
229
280
  }
230
- processTokensFile(e, r, t) {
231
- const o = this.normalizeKey(t), n = this.getTokensFromFile(e, r);
232
- return { [o]: n };
281
+ processTokensFile(e, o, r) {
282
+ const n = this.normalizeKey(r), s = this.getTokensFromFile(e, o);
283
+ return { [n]: s };
233
284
  }
234
285
  /**
235
286
  * Loads all variable files in parallel and returns processed results
236
287
  */
237
288
  async loadVariableFiles(e) {
238
289
  return Promise.all(
239
- e.map(async ({ fileName: r, modeName: t, collectionName: o }) => {
290
+ e.map(async ({ fileName: o, modeName: r, collectionName: n }) => {
240
291
  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), {};
292
+ const s = k.join(this.tokensDir, o), a = await d.readJson(s);
293
+ return this.processTokensFile(a, r, n);
294
+ } catch (s) {
295
+ return console.warn(`Failed to load variable file: ${k.join(this.tokensDir, o)}`, s), {};
245
296
  }
246
297
  })
247
298
  );
248
299
  }
249
300
  mergeVariables(e) {
250
- return e.reduce((r, t) => se(r, t), {});
301
+ return e.reduce((o, r) => H(o, r), {});
251
302
  }
252
303
  /**
253
304
  * Loads and processes all token variables from manifest collections
254
305
  */
255
306
  async loadTokenVariables(e) {
256
307
  try {
257
- const r = this.createVariableFileList(e), t = await this.loadVariableFiles(r);
258
- return this.mergeVariables(t);
259
- } catch (r) {
260
- throw new Error(`Failed to load token variables from ${this.tokensDir}: ${r}`);
308
+ const o = this.createVariableFileList(e), r = await this.loadVariableFiles(o);
309
+ return this.mergeVariables(r);
310
+ } catch (o) {
311
+ throw new Error(`Failed to load token variables from ${this.tokensDir}: ${o}`);
261
312
  }
262
313
  }
263
314
  /**
@@ -265,9 +316,9 @@ class ie {
265
316
  */
266
317
  createStyleFileList(e) {
267
318
  return Object.entries(e).flatMap(
268
- ([r, t]) => (t == null ? void 0 : t.map((o) => ({
269
- styleType: r,
270
- fileName: o
319
+ ([o, r]) => (r == null ? void 0 : r.map((n) => ({
320
+ styleType: o,
321
+ fileName: n
271
322
  }))) || []
272
323
  );
273
324
  }
@@ -276,30 +327,32 @@ class ie {
276
327
  */
277
328
  async loadStyleFiles(e) {
278
329
  return (await Promise.all(
279
- e.map(async ({ styleType: t, fileName: o }) => {
330
+ e.map(async ({ styleType: r, fileName: n }) => {
280
331
  try {
281
- const n = $.join(this.tokensDir, o), a = await m.readJson(n);
282
- 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: {} };
332
+ const s = k.join(this.tokensDir, n), a = await d.readJson(s);
333
+ return { styleType: r, styleTokens: a };
334
+ } catch (s) {
335
+ return console.warn(`Failed to load style file: ${k.join(this.tokensDir, n)}`, s), { styleType: r, styleTokens: {} };
285
336
  }
286
337
  })
287
338
  )).reduce(
288
- (t, o) => ({ ...t, [o.styleType]: this.getTokensFromFile(o.styleTokens, "") }),
289
- {}
339
+ (r, n) => ({ ...r, [n.styleType]: this.getTokensFromFile(n.styleTokens, "") }),
340
+ {
341
+ ...R
342
+ }
290
343
  );
291
344
  }
292
345
  /**
293
346
  * Loads and processes all style tokens from manifest
294
347
  */
295
348
  async loadStyles(e) {
296
- if (!e) return {};
297
- const r = this.createStyleFileList(e);
298
- return await this.loadStyleFiles(r);
349
+ if (!e) return { ...R };
350
+ const o = this.createStyleFileList(e);
351
+ return await this.loadStyleFiles(o);
299
352
  }
300
353
  async load() {
301
354
  if (this.loaded) return;
302
- const e = await m.readJson(this.manifestPath);
355
+ const e = await d.readJson(this.manifestPath);
303
356
  if (!e)
304
357
  throw new Error(`Failed to load manifest file from: ${this.manifestPath}`);
305
358
  this.variables = await this.loadTokenVariables(e.collections), this.styles = await this.loadStyles(e.styles), this.loaded = !0;
@@ -336,397 +389,890 @@ class ie {
336
389
  getVariablePath(e) {
337
390
  return e.slice(1, -1);
338
391
  }
392
+ /**
393
+ * Resolves a variable reference by validating, parsing and getting the token
394
+ * @param value - Value to resolve (should be a variable reference like "{variable.path}")
395
+ * @param mode - Mode name to get value for (optional)
396
+ * @returns resolved token variable or undefined if not found or invalid
397
+ */
398
+ resolveVariableValue(e) {
399
+ 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;
403
+ }, {});
404
+ }
405
+ /**
406
+ * Resolves a variable reference by validating, parsing and getting the token
407
+ * @param value - Value to resolve (should be a variable reference like "{variable.path}")
408
+ * @param mode - Mode name to get value for (optional)
409
+ * @returns resolved token variable or undefined if not found or invalid
410
+ */
411
+ resolveVariableValueString(e, o) {
412
+ if (!this.isVariableReference(e)) return e;
413
+ const r = this.getVariablePath(e), n = this.getToken(r, o);
414
+ if (n)
415
+ return this.resolveVariableValueString(n, o);
416
+ }
339
417
  /**
340
418
  * Gets a nested token value by path, similar to lodash.get
341
419
  * @param variablePath - Dot-separated string path or array of path segments
420
+ * @param mode - Mode name to get value for (optional)
342
421
  */
343
- getToken(e) {
422
+ getToken(e, o) {
344
423
  if (!this.loaded || !this.variables)
345
424
  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;
425
+ for (const r of Object.values(this.variables)) {
426
+ const n = q(r, e);
427
+ if (n != null && n.value && typeof n.value == "object") {
428
+ if (o) return n.value[o];
429
+ {
430
+ const s = Object.keys(n.value)[0];
431
+ return n.value[s];
432
+ }
433
+ }
351
434
  }
352
435
  }
353
436
  }
354
- const xe = async () => {
355
- const e = await new E().load();
437
+ const Kt = async () => {
438
+ const e = await new j().load();
356
439
  if (!e)
357
440
  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
+ 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(
446
+ (e, o) => ({
391
447
  ...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) => {
448
+ [o.name]: we(o)
449
+ }),
450
+ {}
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};`);
459
+ return e.length ? `.breakpoint-variables {
460
+ ${e.join(`
461
+ `)}
462
+ }
463
+ ` : "";
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
+ return !e.length || !o ? "" : `$breakpointList: (
468
+ ${e.join(`,
469
+ `)}
470
+ );
471
+
472
+ $defaultBreakpoint: '${o}';
473
+ `;
474
+ }, ve = (t) => [
475
+ `const breakpoints = ${JSON.stringify(t, null, 4)} as const;`,
476
+ "",
477
+ "const BREAKPOINTS_NAMES = Object.keys(breakpoints);",
478
+ "",
479
+ "type BreakpointsKeysType = keyof typeof breakpoints;",
480
+ "type AllowMedia = 'all' | BreakpointsKeysType;",
481
+ "",
482
+ "export { breakpoints, BREAKPOINTS_NAMES };",
483
+ "export type { BreakpointsKeysType, AllowMedia };",
484
+ ""
485
+ ].join(`
486
+ `), Me = async ({ breakpointTokens: t, dir: e }) => {
487
+ const o = ke(t), r = Te(t), n = je(t), s = ve(o);
488
+ await Promise.all([
489
+ N("styles.css", r, e),
490
+ N("styles.scss", n, e),
491
+ N("index.ts", s, e)
492
+ ]);
493
+ }, Ce = (t, e) => {
494
+ const o = Object.keys(t).filter((s) => !isNaN(Number(s))).sort((s, a) => Number(s) - Number(a));
495
+ if (o.length > e.length)
496
+ throw new Error(
497
+ `Not enough breakpoint names provided. Found ${o.length} breakpoints in data, but only ${e.length} names specified: ${e.join(", ")}`
498
+ );
499
+ const n = Object.keys(t).filter((s) => isNaN(Number(s)));
500
+ if (n.length > 0)
501
+ throw new Error(
502
+ `Found non-numeric breakpoint keys in grid data: ${n.join(", ")}. All breakpoint keys must be numeric values.`
503
+ );
504
+ return o.map((s, a) => ({
505
+ name: e[e.length - 1 - a] || `bp-${s}`,
506
+ value: s
507
+ }));
508
+ }, Ut = ({
509
+ input: t = {},
510
+ output: { dir: e }
511
+ }) => ({
512
+ name: "breakpoints/tokenManager",
513
+ executor: async ({ tokenManagerClient: o }) => {
514
+ try {
515
+ console.log("[breakpoints/tokenManager] Generating breakpoints from TokenManager...");
516
+ const { names: r = me } = t;
517
+ if (!o.isLoaded())
518
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
519
+ const n = o.getStyles();
520
+ if (!n.grid)
521
+ throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
522
+ console.log("[breakpoints/tokenManager] Extracting breakpoints from grid styles...");
523
+ const s = Ce(n.grid, r);
524
+ if (!s.length) {
525
+ console.warn("[breakpoints/tokenManager] No breakpoints found in grid styles.");
526
+ return;
527
+ }
528
+ console.log(
529
+ `[breakpoints/tokenManager] Found ${s.length} breakpoints: ${s.map((a) => a.name).join(", ")}`
530
+ ), console.log(`[breakpoints/tokenManager] Writing files to ${e}...`), await Me({
531
+ breakpointTokens: s,
532
+ dir: e
533
+ }), 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
+ }
538
+ }
539
+ }), Ve = "styles.css", Fe = "index.ts", A = (t, e) => {
423
540
  if (!e.length) return "";
424
- const r = e.map((t) => ` ${t}`).join(`
541
+ const o = e.map((r) => ` ${r}`).join(`
425
542
  `);
426
- return `${s} {
427
- ${r}
543
+ return `${t} {
544
+ ${o}
428
545
  }`;
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;
546
+ }, Ne = (t) => `.${t.replace(/\s+/g, "-").toLowerCase()}`, Q = (t) => `--cl-${t}`, xe = (t) => t.reduce(
547
+ (e, o) => {
548
+ const r = Q(o.name);
549
+ 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;
435
552
  },
436
553
  { 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);
441
- return a && t.push(a), t;
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;
442
559
  }, []).join(`
443
560
 
444
561
  `);
445
- return [e, r].filter(Boolean).join(`
562
+ return [e, o].filter(Boolean).join(`
446
563
 
447
564
  `);
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
565
+ }, Pe = (t) => `${`const colors = {
566
+ ${t.map((r) => ` '${r.name}': 'var(${Q(r.name)})'`).join(`,
567
+ `)}
568
+ } as const;`}
569
+
570
+ type ColorsKeysType = keyof typeof colors;
571
+
572
+ export { colors, type ColorsKeysType };
573
+ `, Ee = async ({
574
+ tsContent: t,
575
+ cssContent: e,
576
+ dir: o
461
577
  }) => {
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 }) => {
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;
599
+ 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])
604
+ }),
605
+ {}
606
+ ) : D(i), u = { [s]: c };
607
+ return { ...o, ...u };
608
+ }
609
+ const a = Z(n, s);
610
+ return { ...o, ...a };
611
+ },
612
+ {}
613
+ ), X = (t, e) => Object.keys(t).reduce((o, r) => {
614
+ const n = t[r];
615
+ if (n.type && n.type !== "color") return o;
616
+ 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;
619
+ }
620
+ const s = X(n, e);
621
+ return s ? { ...o, [r]: s } : o;
622
+ }, {}), Wt = ({ input: t = {}, output: { dir: e } }) => ({
623
+ name: "colors/tokenManager",
624
+ executor: async ({ tokenManagerClient: o }) => {
470
625
  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;
626
+ console.log("[colors/tokenManager] Generating colors from TokenManager...");
627
+ const { includeVariables: r, includeStyles: n = !0 } = t;
628
+ if (!(r != null && r.length) && !n)
629
+ throw new Error("Either includeVariables or includeStyles must be enabled");
630
+ if (!o.isLoaded())
631
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
632
+ const s = [], a = o.getVariables();
633
+ if (n) {
634
+ const i = o.getStyles();
635
+ console.log("[colors/tokenManager] Processing styles for colors..."), i.color && s.push(i.color);
476
636
  }
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
- }
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);
495
641
  }
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.");
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
+ []
646
+ )
647
+ );
648
+ if (l.length === 0) {
649
+ console.warn("[colors/tokenManager] No color tokens generated");
547
650
  return;
548
651
  }
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;
652
+ console.log(`[colors/tokenManager] Generated ${l.length} color tokens`), console.log(`[colors/tokenManager] Writing files to ${e}...`), await Be({
653
+ colorTokens: l,
654
+ dir: e
655
+ }), 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;
559
659
  }
560
660
  }
561
- }), Re = ({
562
- input: { variablePaths: s },
563
- output: { jsonDir: e, stylesDir: r, jsonFileName: t = "colors.json", cssFileName: o = "colors.css" }
661
+ }), Le = (t) => ` @media (width <= ${t.breakpoint}px) {
662
+ .container {
663
+ padding-left: ${t.offset};
664
+ padding-right: ${t.offset};
665
+ }
666
+
667
+ .containerTablet {
668
+ padding-left: ${t.offset};
669
+ padding-right: ${t.offset};
670
+ }
671
+ }`, Ue = (t, e) => {
672
+ const o = e || "components", r = t.map((n) => Le(n)).join(`
673
+
674
+ `);
675
+ return `@layer ${o} {
676
+ ${r}
677
+ }`;
678
+ }, We = () => `import styles from './styles.module.css';
679
+
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();
689
+ 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
+ return s;
694
+ const i = l.value.find((u) => u.pattern === "columns");
695
+ if (!(i != null && i.offset))
696
+ return s;
697
+ const c = e.resolveVariableValueString(i.offset);
698
+ return !c || typeof c != "string" || Ie(c) ? s : [
699
+ ...s,
700
+ {
701
+ breakpoint: Number(a),
702
+ offset: c
703
+ }
704
+ ];
705
+ }, []).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 = {},
710
+ output: { dir: e }
564
711
  }) => ({
565
- name: "variables/colors",
566
- executor: async () => {
712
+ name: "container/tokenManager",
713
+ executor: async ({ tokenManagerClient: o }) => {
567
714
  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
- );
715
+ console.log("[container/tokenManager] Generating container styles...");
716
+ const { layer: r } = t;
717
+ if (!o.isLoaded())
718
+ throw new Error("TokenManager is not loaded. Tokens must be loaded before using this module.");
719
+ console.log("[container/tokenManager] Extracting container tokens...");
720
+ const n = o.getStyles();
721
+ if (!n.grid)
722
+ throw new Error("No grid styles found in TokenManager. Grid tokens must be loaded.");
723
+ const s = Ge(n.grid, o);
724
+ if (!s.length) {
725
+ console.warn("[container/tokenManager] No container tokens found.");
628
726
  return;
629
727
  }
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;
728
+ console.log(
729
+ `[container/tokenManager] Found ${s.length} container tokens: ${s.map((a) => a.breakpoint).join(", ")}`
730
+ ), console.log(`[container/tokenManager] Writing files to ${e}...`), await ze({
731
+ containerTokens: s,
732
+ dir: e,
733
+ layer: r
734
+ }), 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;
640
738
  }
641
739
  }
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 };
740
+ }), Je = "styles.css", qe = "index.ts", L = (t, e) => {
741
+ if (!e.length) return "";
742
+ const o = e.map((r) => ` ${r}`).join(`
743
+ `);
744
+ return `${t} {
745
+ ${o}
746
+ }`;
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(
748
+ (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};`] };
753
+ }, e);
754
+ },
755
+ { 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;
761
+ }, []).join(`
762
+
763
+ `);
764
+ return [e, o].filter(Boolean).join(`
765
+
766
+ `);
767
+ }, Ye = (t) => `${`const shadows = {
768
+ ${t.map((r) => ` '${r.name}': 'var(${Y(r.name)})'`).join(`,
769
+ `)}
770
+ } as const;`}
771
+
772
+ type ShadowsKeysType = keyof typeof shadows;
773
+
774
+ export { shadows, type ShadowsKeysType };
775
+ `, _e = async ({
776
+ tsContent: t,
777
+ cssContent: e,
778
+ dir: o
779
+ }) => {
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;
789
+ if (n && typeof n == "object" && "type" in n && "value" in n) {
790
+ const l = {
791
+ [s]: n.value.map(Qe).join(", ")
792
+ };
793
+ return { ...o, ...l };
648
794
  }
649
- const a = K(o, n);
650
- return { ...r, ...a };
795
+ const a = _(n, s);
796
+ return { ...o, ...a };
651
797
  },
652
798
  {}
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 }) => {
799
+ ), It = ({ input: t = {}, output: { dir: e } }) => ({
800
+ name: "shadows/tokenManager",
801
+ executor: async ({ tokenManagerClient: o }) => {
685
802
  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())
803
+ console.log("[shadows/tokenManager] Generating shadows from TokenManager...");
804
+ const { includeStyles: r = !0 } = t;
805
+ if (!r)
806
+ throw new Error("includeStyles must be enabled for shadows generation");
807
+ if (!o.isLoaded())
691
808
  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);
809
+ const n = [];
810
+ if (r) {
811
+ const a = o.getStyles();
812
+ console.log("[shadows/tokenManager] Processing styles for shadows..."), a.effect && n.push(a.effect);
701
813
  }
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 }],
814
+ const s = n.flatMap(
815
+ (a) => Object.entries(_(a, "")).reduce(
816
+ (l, [i, c]) => [...l, { name: i, value: c }],
705
817
  []
706
818
  )
707
819
  );
708
- if (g.length === 0) {
709
- console.warn("[colors/tokenManager] No color tokens generated");
820
+ if (s.length === 0) {
821
+ console.warn("[shadows/tokenManager] No shadow tokens generated");
710
822
  return;
711
823
  }
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;
824
+ console.log(`[shadows/tokenManager] Generated ${s.length} shadow tokens`), console.log(`[shadows/tokenManager] Writing files to ${e}...`), await et({
825
+ shadowTokens: s,
826
+ dir: e
827
+ }), 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
+ }
832
+ }
833
+ }), tt = "styles.module.css", rt = "index.ts", ot = "typography.ts", U = "sans-serif", W = (t, e) => {
834
+ if (!e.length) return "";
835
+ const o = e.map((r) => ` ${r}`).join(`
836
+ `);
837
+ return `${t} {
838
+ ${o}
839
+ }`;
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) => {
848
+ 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();
851
+ o[a] = s;
852
+ }), 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 }] : [
859
+ {
860
+ breakpoint: null,
861
+ css: {
862
+ ...n,
863
+ ...i
864
+ }
865
+ }
866
+ ];
867
+ },
868
+ [
869
+ {
870
+ breakpoint: null,
871
+ css: n
872
+ }
873
+ ]
874
+ );
875
+ }, te = () => ({
876
+ base: {},
877
+ 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
882
+ });
883
+ }, T = (t, e, o, r) => {
884
+ nt(e.value, o, r).forEach(({ breakpoint: s, css: a }) => {
885
+ if (s === null) {
886
+ t.base[e.name] = a;
887
+ return;
888
+ }
889
+ O(t, s, e.name, a);
890
+ });
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)} }`;
895
+ }, "");
896
+ 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(";");
902
+ 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
+ return Number.isFinite(e) ? e : null;
907
+ }, J = (t) => {
908
+ if (typeof t == "number") return t / 16;
909
+ const e = t.trim().toLowerCase();
910
+ if (e.endsWith("rem")) return G(e);
911
+ if (e.endsWith("px")) {
912
+ const o = G(e);
913
+ return o === null ? null : o / 16;
914
+ }
915
+ 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);
924
+ if (s.length < 2) {
925
+ T(t, e, o, r);
926
+ return;
927
+ }
928
+ const a = s[0], l = s[s.length - 1];
929
+ if (a.width <= l.width) {
930
+ T(t, e, o, r);
931
+ return;
932
+ }
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
+ return;
937
+ }
938
+ t.base[e.name] = {
939
+ ...i,
940
+ ...c
941
+ };
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 })
950
+ };
951
+ }, {});
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());
956
+ return re(n);
957
+ }, ct = (t) => t.length ? `import styles from './styles.module.css';
958
+ import { typography } from './typography';
959
+
960
+ type TypographyKeysType = keyof typeof typography;
961
+
962
+ const getTypographyClass = (typographyKey: TypographyKeysType) => styles[\`typo-\${typographyKey}\`];
963
+
964
+ 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]) => ({
969
+ ...a,
970
+ [l]: z(i, e)
971
+ }),
972
+ {}
973
+ );
974
+ return ` '${r.name}': {
975
+ base: ${JSON.stringify(n, null, 8).replace(/\n/g, `
976
+ `)},
977
+ breakpoints: ${JSON.stringify(s, null, 8).replace(/\n/g, `
978
+ `)}
979
+ }`;
980
+ }).join(`,
981
+ `)}
982
+ } as const;
983
+
984
+ export { typography };
985
+ ` : "", dt = async ({
986
+ indexTSContent: t,
987
+ typographyTSContent: e,
988
+ cssContent: o,
989
+ dir: r
990
+ }) => {
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 });
993
+ await Promise.all([n, s, a]);
994
+ }, ft = async ({
995
+ typographyTokens: t,
996
+ dir: e,
997
+ breakpoints: o,
998
+ fontFamily: r,
999
+ fluid: n
1000
+ }) => {
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;
1006
+ 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 });
1016
+ });
1017
+ else {
1018
+ const y = e.resolveVariableValueString(u);
1019
+ y && (i.base = { ...i.base, [c]: y });
1020
+ }
1021
+ return i;
1022
+ },
1023
+ { base: {}, breakpoints: {} }
1024
+ );
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
+ if (!("type" in s) || !("value" in s))
1029
+ return { ...o, ...ne(s, n) };
1030
+ const a = s.value;
1031
+ return { ...o, [n]: a };
1032
+ }, {}), Gt = ({ input: t, output: { dir: e } }) => ({
1033
+ name: "typography/tokenManager",
1034
+ executor: async ({ tokenManagerClient: o }) => {
1035
+ try {
1036
+ console.log("[typography/tokenManager] Generating typography from TokenManager...");
1037
+ const { breakpoints: r, fontFamily: n } = t, s = t.fluid ?? !0;
1038
+ if (!o.isLoaded())
1039
+ 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) => ({
1044
+ ...u,
1045
+ ...oe(f, o, { breakpoints: t.breakpoints })
1046
+ }),
1047
+ {}
1048
+ ), c = Object.entries(ne(i)).map(
1049
+ ([u, f]) => ({ name: u, value: f })
1050
+ );
1051
+ if (c.length === 0) {
1052
+ console.warn("[typography/tokenManager] No typography tokens generated");
1053
+ return;
1054
+ }
1055
+ console.log(`[typography/tokenManager] Generated ${c.length} typography tokens`), console.log(`[typography/tokenManager] Writing files to ${e}...`), await ft({
1056
+ typographyTokens: c,
1057
+ dir: e,
1058
+ breakpoints: r,
1059
+ fontFamily: n || {},
1060
+ fluid: s
1061
+ }), 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
+ }
1066
+ }
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) => {
1068
+ const o = se(e);
1069
+ if (!o.length)
1070
+ throw new Error("variablePath must contain at least one segment");
1071
+ const r = q(t, o);
1072
+ if (r === void 0)
1073
+ 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 };
1082
+ }, {});
1083
+ return [{ flatName: e, resolvedByMode: n }];
1084
+ }
1085
+ return gt(t) ? Object.keys(t).flatMap((r) => {
1086
+ const n = t[r], s = e ? `${e}-${r}` : r;
1087
+ return ae(n, s, o);
1088
+ }) : [];
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);
1093
+ if (!e.length)
1094
+ throw new Error("variablePath must contain at least one segment");
1095
+ const o = e[e.length - 1];
1096
+ return {
1097
+ variablesClassName: `${o}-variables`,
1098
+ variableNamePrefix: o
1099
+ };
1100
+ }, le = (t) => {
1101
+ const e = wt(t.variablePath), o = t.variableNamePrefix ?? e.variableNamePrefix, r = t.variablesClassName ?? `${o}-variables`;
1102
+ return {
1103
+ variableNamePrefix: o,
1104
+ variablesClassName: r
1105
+ };
1106
+ }, kt = (t, e) => t ? `--${t}-${e}` : `--${e}`, $t = (t, e) => Object.keys(e).reduce(
1107
+ (o, r) => {
1108
+ const n = Number(r);
1109
+ return { ...o, [n]: { ...o[n], ...e[n] } };
1110
+ },
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: {} };
1117
+ }
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: {} };
1122
+ }
1123
+ if (s.length === 1) {
1124
+ const i = s[0], c = t.resolvedByMode[i.mode] ?? "";
1125
+ return { base: { [r]: c }, byBreakpoint: {} };
1126
+ }
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 } };
1132
+ }, {});
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);
1137
+ return {
1138
+ base: { ...r.base, ...s },
1139
+ breakpoints: $t(r.breakpoints, a)
1140
+ };
1141
+ },
1142
+ { 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}
1149
+ }`;
1150
+ }).filter(Boolean).join(`
1151
+
1152
+ `);
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;
1184
+
1185
+ export { utilities };
1186
+ `;
1187
+ }, Ct = (t) => {
1188
+ const { variableNamePrefix: e } = le(t);
1189
+ return [
1190
+ "import { utilities } from './utilities';",
1191
+ "",
1192
+ "type UtilitiesKeysType = keyof typeof utilities;",
1193
+ "",
1194
+ `const utilityVariableNamePrefix = ${JSON.stringify(e)};`,
1195
+ "",
1196
+ "const getUtilityCssVariableName = (key: UtilitiesKeysType): string =>",
1197
+ " utilityVariableNamePrefix",
1198
+ " ? `--${utilityVariableNamePrefix}-${String(key)}`",
1199
+ " : `--${String(key)}`;",
1200
+ "",
1201
+ "const getUtilityCssVar = (key: UtilitiesKeysType): string =>",
1202
+ " `var(${getUtilityCssVariableName(key)})`;",
1203
+ "",
1204
+ "export {",
1205
+ " utilities,",
1206
+ " getUtilityCssVariableName,",
1207
+ " getUtilityCssVar,",
1208
+ " type UtilitiesKeysType,",
1209
+ "};",
1210
+ ""
1211
+ ].join(`
1212
+ `);
1213
+ }, Vt = "styles.css", Ft = "utilities.ts", Nt = "index.ts", xt = async ({
1214
+ dir: t,
1215
+ globalCss: e,
1216
+ utilitiesTs: o,
1217
+ indexTs: r
1218
+ }) => {
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 })
1223
+ ]);
1224
+ }, Ot = async ({
1225
+ tokens: t,
1226
+ input: e,
1227
+ output: o
1228
+ }) => {
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 }) => ({
1232
+ name: "utilities/tokenManager",
1233
+ executor: async ({ tokenManagerClient: o }) => {
1234
+ var r;
1235
+ try {
1236
+ if (console.log("[utilities/tokenManager] Generating utility classes from TokenManager..."), !o.isLoaded())
1237
+ 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}"`);
1243
+ return;
1244
+ }
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");
1246
+ } catch (n) {
1247
+ const s = n instanceof Error ? n.message : String(n);
1248
+ 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
1249
  }
723
1250
  }
724
1251
  });
725
1252
  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
1253
+ me as BREAKPOINTS_NAMES,
1254
+ 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,
1275
+ bt as utilityFlatNameMatchesIncludePattern,
1276
+ vt as utilityTokenToSerializableData,
1277
+ xt as writeUtilitiesFiles
732
1278
  };