@greensight/gts 1.0.0-alpha.13 → 1.0.0-alpha.15

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