@styleframe/core 1.0.1 → 1.0.2

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 (48) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +21 -0
  3. package/dist/styleframe.d.ts +301 -0
  4. package/dist/styleframe.js +528 -0
  5. package/dist/styleframe.umd.cjs +1 -0
  6. package/package.json +13 -3
  7. package/.tsbuildinfo +0 -1
  8. package/src/index.ts +0 -5
  9. package/src/styleframe.ts +0 -64
  10. package/src/tokens/atRule.test.ts +0 -1013
  11. package/src/tokens/atRule.ts +0 -67
  12. package/src/tokens/css.test.ts +0 -404
  13. package/src/tokens/css.ts +0 -23
  14. package/src/tokens/declarations.test.ts +0 -584
  15. package/src/tokens/declarations.ts +0 -71
  16. package/src/tokens/index.ts +0 -11
  17. package/src/tokens/modifier.test.ts +0 -90
  18. package/src/tokens/modifier.ts +0 -86
  19. package/src/tokens/recipe.test.ts +0 -105
  20. package/src/tokens/recipe.ts +0 -32
  21. package/src/tokens/ref.test.ts +0 -430
  22. package/src/tokens/ref.ts +0 -24
  23. package/src/tokens/root.test.ts +0 -70
  24. package/src/tokens/root.ts +0 -14
  25. package/src/tokens/selector.test.ts +0 -440
  26. package/src/tokens/selector.ts +0 -47
  27. package/src/tokens/theme.test.ts +0 -338
  28. package/src/tokens/theme.ts +0 -26
  29. package/src/tokens/utility.test.ts +0 -1456
  30. package/src/tokens/utility.ts +0 -92
  31. package/src/tokens/variable.test.ts +0 -235
  32. package/src/tokens/variable.ts +0 -42
  33. package/src/typeGuards.test.ts +0 -33
  34. package/src/typeGuards.ts +0 -98
  35. package/src/types/declarations.ts +0 -42
  36. package/src/types/index.ts +0 -3
  37. package/src/types/options.ts +0 -22
  38. package/src/types/tokens.ts +0 -149
  39. package/src/utils/capitalizeFirst.ts +0 -9
  40. package/src/utils/deepClone.ts +0 -317
  41. package/src/utils/getters.test.ts +0 -399
  42. package/src/utils/getters.ts +0 -36
  43. package/src/utils/index.ts +0 -4
  44. package/src/utils/merge.test.ts +0 -978
  45. package/src/utils/merge.ts +0 -73
  46. package/src/vite-env.d.ts +0 -1
  47. package/tsconfig.json +0 -7
  48. package/vite.config.ts +0 -5
@@ -1,399 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { Container } from "../types";
3
- import { createRoot } from "../tokens/root";
4
- import { getVariable, getUtility, getModifier } from "./getters";
5
-
6
- describe("getVariable", () => {
7
- describe("basic functionality", () => {
8
- it("should return a variable when it exists", () => {
9
- const container: Container = {
10
- variables: [
11
- {
12
- type: "variable",
13
- name: "primary-color",
14
- value: "#007bff",
15
- },
16
- ],
17
- declarations: {},
18
- children: [],
19
- };
20
-
21
- const result = getVariable(container, "primary-color");
22
-
23
- expect(result).toEqual({
24
- type: "variable",
25
- name: "primary-color",
26
- value: "#007bff",
27
- });
28
- });
29
-
30
- it("should return the correct variable when multiple exist", () => {
31
- const container: Container = {
32
- variables: [
33
- {
34
- type: "variable",
35
- name: "primary-color",
36
- value: "#007bff",
37
- },
38
- {
39
- type: "variable",
40
- name: "secondary-color",
41
- value: "#6c757d",
42
- },
43
- {
44
- type: "variable",
45
- name: "spacing",
46
- value: "1rem",
47
- },
48
- ],
49
- declarations: {},
50
- children: [],
51
- };
52
-
53
- const result = getVariable(container, "secondary-color");
54
-
55
- expect(result).toEqual({
56
- type: "variable",
57
- name: "secondary-color",
58
- value: "#6c757d",
59
- });
60
- });
61
-
62
- it("should throw an error when variable does not exist", () => {
63
- const container: Container = {
64
- variables: [
65
- {
66
- type: "variable",
67
- name: "primary-color",
68
- value: "#007bff",
69
- },
70
- ],
71
- declarations: {},
72
- children: [],
73
- };
74
-
75
- expect(() => getVariable(container, "non-existent")).toThrow(
76
- 'Variable "non-existent" not found',
77
- );
78
- });
79
-
80
- it("should throw an error when variables array is empty", () => {
81
- const container: Container = {
82
- variables: [],
83
- declarations: {},
84
- children: [],
85
- };
86
-
87
- expect(() => getVariable(container, "any-variable")).toThrow(
88
- 'Variable "any-variable" not found',
89
- );
90
- });
91
- });
92
-
93
- describe("edge cases", () => {
94
- it("should handle variables with special characters in names", () => {
95
- const container: Container = {
96
- variables: [
97
- {
98
- type: "variable",
99
- name: "color-primary-500",
100
- value: "#007bff",
101
- },
102
- ],
103
- declarations: {},
104
- children: [],
105
- };
106
-
107
- const result = getVariable(container, "color-primary-500");
108
-
109
- expect(result.name).toBe("color-primary-500");
110
- });
111
-
112
- it("should be case-sensitive", () => {
113
- const container: Container = {
114
- variables: [
115
- {
116
- type: "variable",
117
- name: "primaryColor",
118
- value: "#007bff",
119
- },
120
- ],
121
- declarations: {},
122
- children: [],
123
- };
124
-
125
- expect(() => getVariable(container, "primarycolor")).toThrow(
126
- 'Variable "primarycolor" not found',
127
- );
128
- });
129
- });
130
- });
131
-
132
- describe("getUtility", () => {
133
- describe("basic functionality", () => {
134
- it("should return a utility when it exists", () => {
135
- const mockFactory = () => {};
136
- const root = createRoot();
137
- root.utilities = [
138
- {
139
- type: "utility",
140
- name: "padding",
141
- factory: mockFactory,
142
- },
143
- ];
144
-
145
- const result = getUtility(root, "padding");
146
-
147
- expect(result).toEqual({
148
- type: "utility",
149
- name: "padding",
150
- factory: mockFactory,
151
- });
152
- });
153
-
154
- it("should return the correct utility when multiple exist", () => {
155
- const mockFactory1 = () => {};
156
- const mockFactory2 = () => {};
157
- const mockFactory3 = () => {};
158
- const root = createRoot();
159
- root.utilities = [
160
- {
161
- type: "utility",
162
- name: "padding",
163
- factory: mockFactory1,
164
- },
165
- {
166
- type: "utility",
167
- name: "margin",
168
- factory: mockFactory2,
169
- },
170
- {
171
- type: "utility",
172
- name: "display",
173
- factory: mockFactory3,
174
- },
175
- ];
176
-
177
- const result = getUtility(root, "margin");
178
-
179
- expect(result).toEqual({
180
- type: "utility",
181
- name: "margin",
182
- factory: mockFactory2,
183
- });
184
- });
185
-
186
- it("should throw an error when utility does not exist", () => {
187
- const root = createRoot();
188
- root.utilities = [
189
- {
190
- type: "utility",
191
- name: "padding",
192
- factory: () => {},
193
- },
194
- ];
195
-
196
- expect(() => getUtility(root, "non-existent")).toThrow(
197
- 'Utility "non-existent" not found',
198
- );
199
- });
200
-
201
- it("should throw an error when utilities array is empty", () => {
202
- const root = createRoot();
203
-
204
- expect(() => getUtility(root, "padding")).toThrow(
205
- 'Utility "padding" not found',
206
- );
207
- });
208
- });
209
-
210
- describe("edge cases", () => {
211
- it("should handle utilities with hyphenated names", () => {
212
- const mockFactory = () => {};
213
- const root = createRoot();
214
- root.utilities = [
215
- {
216
- type: "utility",
217
- name: "flex-direction",
218
- factory: mockFactory,
219
- },
220
- ];
221
-
222
- const result = getUtility(root, "flex-direction");
223
-
224
- expect(result.name).toBe("flex-direction");
225
- });
226
-
227
- it("should be case-sensitive", () => {
228
- const root = createRoot();
229
- root.utilities = [
230
- {
231
- type: "utility",
232
- name: "padding",
233
- factory: () => {},
234
- },
235
- ];
236
-
237
- expect(() => getUtility(root, "Padding")).toThrow(
238
- 'Utility "Padding" not found',
239
- );
240
- });
241
- });
242
- });
243
-
244
- describe("getModifier", () => {
245
- describe("basic functionality", () => {
246
- it("should return a modifier when it exists", () => {
247
- const mockFactory = () => {};
248
- const root = createRoot();
249
- root.modifiers = [
250
- {
251
- type: "modifier",
252
- key: ["hover"],
253
- factory: mockFactory,
254
- },
255
- ];
256
-
257
- const result = getModifier(root, "hover");
258
-
259
- expect(result).toEqual({
260
- type: "modifier",
261
- key: ["hover"],
262
- factory: mockFactory,
263
- });
264
- });
265
-
266
- it("should return the correct modifier when multiple exist", () => {
267
- const mockFactory1 = () => {};
268
- const mockFactory2 = () => {};
269
- const mockFactory3 = () => {};
270
- const root = createRoot();
271
- root.modifiers = [
272
- {
273
- type: "modifier",
274
- key: ["hover"],
275
- factory: mockFactory1,
276
- },
277
- {
278
- type: "modifier",
279
- key: ["focus"],
280
- factory: mockFactory2,
281
- },
282
- {
283
- type: "modifier",
284
- key: ["active"],
285
- factory: mockFactory3,
286
- },
287
- ];
288
-
289
- const result = getModifier(root, "focus");
290
-
291
- expect(result).toEqual({
292
- type: "modifier",
293
- key: ["focus"],
294
- factory: mockFactory2,
295
- });
296
- });
297
-
298
- it("should find modifier when name is in key array", () => {
299
- const mockFactory = () => {};
300
- const root = createRoot();
301
- root.modifiers = [
302
- {
303
- type: "modifier",
304
- key: ["sm", "small"],
305
- factory: mockFactory,
306
- },
307
- ];
308
-
309
- const result = getModifier(root, "small");
310
-
311
- expect(result).toEqual({
312
- type: "modifier",
313
- key: ["sm", "small"],
314
- factory: mockFactory,
315
- });
316
- });
317
-
318
- it("should throw an error when modifier does not exist", () => {
319
- const root = createRoot();
320
- root.modifiers = [
321
- {
322
- type: "modifier",
323
- key: ["hover"],
324
- factory: () => {},
325
- },
326
- ];
327
-
328
- expect(() => getModifier(root, "non-existent")).toThrow(
329
- 'Modifier "non-existent" not found',
330
- );
331
- });
332
-
333
- it("should throw an error when modifiers array is empty", () => {
334
- const root = createRoot();
335
-
336
- expect(() => getModifier(root, "hover")).toThrow(
337
- 'Modifier "hover" not found',
338
- );
339
- });
340
- });
341
-
342
- describe("edge cases", () => {
343
- it("should return first matching modifier when multiple keys match", () => {
344
- const mockFactory1 = () => {};
345
- const mockFactory2 = () => {};
346
- const root = createRoot();
347
- root.modifiers = [
348
- {
349
- type: "modifier",
350
- key: ["hover", "h"],
351
- factory: mockFactory1,
352
- },
353
- {
354
- type: "modifier",
355
- key: ["h", "highlight"],
356
- factory: mockFactory2,
357
- },
358
- ];
359
-
360
- const result = getModifier(root, "h");
361
-
362
- expect(result.factory).toBe(mockFactory1);
363
- });
364
-
365
- it("should handle modifiers with multiple keys", () => {
366
- const mockFactory = () => {};
367
- const root = createRoot();
368
- root.modifiers = [
369
- {
370
- type: "modifier",
371
- key: ["sm", "small", "s"],
372
- factory: mockFactory,
373
- },
374
- ];
375
-
376
- const result1 = getModifier(root, "sm");
377
- const result2 = getModifier(root, "small");
378
- const result3 = getModifier(root, "s");
379
-
380
- expect(result1).toBe(result2);
381
- expect(result2).toBe(result3);
382
- });
383
-
384
- it("should be case-sensitive", () => {
385
- const root = createRoot();
386
- root.modifiers = [
387
- {
388
- type: "modifier",
389
- key: ["hover"],
390
- factory: () => {},
391
- },
392
- ];
393
-
394
- expect(() => getModifier(root, "Hover")).toThrow(
395
- 'Modifier "Hover" not found',
396
- );
397
- });
398
- });
399
- });
@@ -1,36 +0,0 @@
1
- import type {
2
- Container,
3
- ModifierFactory,
4
- Root,
5
- UtilityFactory,
6
- Variable,
7
- } from "../types";
8
-
9
- export function getVariable(root: Container, name: string): Variable {
10
- const variable = root.variables.find((variable) => variable.name === name);
11
- if (!variable) {
12
- throw new Error(`Variable "${name}" not found`);
13
- }
14
-
15
- return variable;
16
- }
17
-
18
- export function getUtility(root: Root, name: string): UtilityFactory {
19
- const utility = root.utilities.find((utility) => utility.name === name);
20
- if (!utility) {
21
- throw new Error(`Utility "${name}" not found`);
22
- }
23
-
24
- return utility;
25
- }
26
-
27
- export function getModifier(root: Root, name: string): ModifierFactory {
28
- const modifier = root.modifiers.find((modifier) =>
29
- modifier.key.includes(name),
30
- );
31
- if (!modifier) {
32
- throw new Error(`Modifier "${name}" not found`);
33
- }
34
-
35
- return modifier;
36
- }
@@ -1,4 +0,0 @@
1
- export * from "./capitalizeFirst";
2
- export * from "./deepClone";
3
- export * from "./getters";
4
- export * from "./merge";