@styleframe/core 1.0.0 → 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 +12 -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,149 +0,0 @@
1
- import type {
2
- DeclarationsBlock,
3
- DeclarationsCallback,
4
- DeclarationsCallbackContext,
5
- } from "./declarations";
6
-
7
- export type Variable<Name extends string = string> = {
8
- type: "variable";
9
- name: Name;
10
- value: TokenValue;
11
- };
12
-
13
- export type Reference<Name extends string = string> = {
14
- type: "reference";
15
- name: Name;
16
- fallback?: TokenValue;
17
- };
18
-
19
- export type Selector = {
20
- type: "selector";
21
- query: string;
22
- declarations: DeclarationsBlock;
23
- variables: Variable[];
24
- children: ContainerChild[];
25
- };
26
-
27
- export type AtRule = {
28
- type: "at-rule";
29
- identifier: string;
30
- rule: string;
31
- declarations: DeclarationsBlock;
32
- variables: Variable[];
33
- children: ContainerChild[];
34
- };
35
-
36
- export type CSS = {
37
- type: "css";
38
- value: TokenValue[];
39
- };
40
-
41
- export type UtilityFactory<Name extends string = string> = {
42
- type: "utility";
43
- name: Name;
44
- factory: UtilityCallbackFn;
45
- };
46
-
47
- export type Utility<Name extends string = string> = {
48
- type: "utility";
49
- name: Name;
50
- value: string;
51
- declarations: DeclarationsBlock;
52
- variables: Variable[];
53
- children: ContainerChild[];
54
- modifiers: string[];
55
- };
56
-
57
- export type UtilityCallbackFn = DeclarationsCallback<
58
- DeclarationsCallbackContext & {
59
- value: TokenValue;
60
- }
61
- >;
62
-
63
- export type UtilityCreatorFn = (
64
- values: Record<string, TokenValue>,
65
- modifiers?: ModifierFactory[],
66
- ) => void;
67
-
68
- export type ModifierCallbackFn = DeclarationsCallback<
69
- DeclarationsCallbackContext &
70
- Pick<Utility, "declarations" | "variables" | "children">
71
- >;
72
-
73
- export type ModifierFactory = {
74
- type: "modifier";
75
- key: string[];
76
- factory: ModifierCallbackFn;
77
- };
78
-
79
- export type VariantDeclarationsBlock = Record<string, string | true>;
80
-
81
- export type Recipe<
82
- Name extends string = string,
83
- Variants extends Record<
84
- string,
85
- Record<string, VariantDeclarationsBlock>
86
- > = Record<string, Record<string, VariantDeclarationsBlock>>,
87
- > = {
88
- type: "recipe";
89
- name: Name;
90
- defaults: VariantDeclarationsBlock;
91
- variants: Variants;
92
- defaultVariants?: {
93
- [K in keyof Variants]?: keyof Variants[K] & string;
94
- };
95
- compoundVariants?: Array<
96
- {
97
- [K in keyof Variants]?: keyof Variants[K] & string;
98
- } & {
99
- declarations: VariantDeclarationsBlock;
100
- }
101
- >;
102
- };
103
-
104
- export type PrimitiveTokenValue = number | string | boolean | null | undefined;
105
-
106
- export type TokenValue =
107
- | PrimitiveTokenValue
108
- | Reference
109
- | CSS
110
- | Array<PrimitiveTokenValue | Reference | CSS>;
111
-
112
- export type TokenType =
113
- | Variable["type"]
114
- | Reference["type"]
115
- | Selector["type"]
116
- | AtRule["type"]
117
- | CSS["type"]
118
- | Utility["type"]
119
- | ModifierFactory["type"]
120
- | Recipe["type"]
121
- | Theme["type"]
122
- | Root["type"];
123
-
124
- export type Container = {
125
- children: ContainerChild[];
126
- variables: Variable[];
127
- declarations: DeclarationsBlock;
128
- };
129
-
130
- export type ContainerChild = Variable | Selector | AtRule | Utility;
131
-
132
- export type Theme = {
133
- type: "theme";
134
- name: string;
135
- declarations: DeclarationsBlock;
136
- variables: Variable[];
137
- children: ContainerChild[];
138
- };
139
-
140
- export type Root = {
141
- type: "root";
142
- declarations: DeclarationsBlock;
143
- utilities: UtilityFactory[];
144
- modifiers: ModifierFactory[];
145
- recipes: Recipe[];
146
- variables: Variable[];
147
- children: ContainerChild[];
148
- themes: Theme[];
149
- };
@@ -1,9 +0,0 @@
1
- export type CapitalizeFirst<T extends string> =
2
- T extends `${infer First}${infer Rest}` ? `${Uppercase<First>}${Rest}` : T;
3
-
4
- /**
5
- * Capitalizes the first letter of a string
6
- */
7
- export function capitalizeFirst(str: string): string {
8
- return str.charAt(0).toUpperCase() + str.slice(1);
9
- }
@@ -1,317 +0,0 @@
1
- /**
2
- * Deep clone a value.
3
- *
4
- * We're using rfdc for this, but maintaining our own implementation
5
- * to avoid production dependencies on external libraries.
6
- *
7
- * @source https://github.com/davidmarkclements/rfdc
8
- */
9
-
10
- // biome-ignore-all lint/suspicious/noAssignInExpressions: required in rfdc
11
- // biome-ignore-all lint/suspicious/noExplicitAny: required in rfdc
12
- // biome-ignore-all lint/suspicious/noPrototypeBuiltins: required in rfdc
13
-
14
- type CloneFunction<T = any> = (obj: T) => T;
15
- type ConstructorHandler<T = any> = (obj: T, fn: CloneFunction) => T;
16
- type ConstructorHandlerTuple<T = any> = [
17
- new (...args: any[]) => T,
18
- ConstructorHandler<T>,
19
- ];
20
-
21
- interface RfdcOptions {
22
- circular?: boolean;
23
- proto?: boolean;
24
- constructorHandlers?: ConstructorHandlerTuple[];
25
- }
26
-
27
- function copyBuffer(cur: ArrayBufferView): ArrayBufferView {
28
- if (cur instanceof Buffer) {
29
- return Buffer.from(cur);
30
- }
31
-
32
- const TypedArrayConstructor = cur.constructor as new (
33
- buffer: ArrayBuffer,
34
- byteOffset: number,
35
- length: number,
36
- ) => ArrayBufferView;
37
-
38
- return new TypedArrayConstructor(
39
- (cur.buffer as ArrayBuffer).slice(0),
40
- cur.byteOffset,
41
- cur.byteLength / (cur as any).BYTES_PER_ELEMENT || 1,
42
- );
43
- }
44
-
45
- export function rfdc<T = any>(opts?: RfdcOptions): CloneFunction<T> {
46
- opts = opts || {};
47
-
48
- if (opts.circular) {
49
- return rfdcCircular<T>(opts);
50
- }
51
-
52
- const constructorHandlers = new Map<
53
- new (
54
- ...args: any[]
55
- ) => any,
56
- ConstructorHandler
57
- >();
58
- constructorHandlers.set(Date, (o: Date) => new Date(o));
59
- constructorHandlers.set(
60
- Map,
61
- (o: Map<any, any>, fn: CloneFunction) =>
62
- new Map(cloneArray(Array.from(o), fn)),
63
- );
64
- constructorHandlers.set(
65
- Set,
66
- (o: Set<any>, fn: CloneFunction) => new Set(cloneArray(Array.from(o), fn)),
67
- );
68
-
69
- if (opts.constructorHandlers) {
70
- for (const handler of opts.constructorHandlers) {
71
- constructorHandlers.set(handler[0], handler[1]);
72
- }
73
- }
74
-
75
- let handler: ConstructorHandler | undefined;
76
-
77
- return (opts.proto ? cloneProto : clone) as CloneFunction<T>;
78
-
79
- function cloneArray(a: any[], fn: CloneFunction): any[] {
80
- const keys = Object.keys(a);
81
- const a2: any[] = Array.from({ length: keys.length });
82
-
83
- for (let i = 0; i < keys.length; i++) {
84
- const k = keys[i] as any;
85
- const cur = a[k];
86
-
87
- if (typeof cur !== "object" || cur === null) {
88
- a2[k] = cur;
89
- } else if (
90
- cur.constructor !== Object &&
91
- (handler = constructorHandlers.get(cur.constructor))
92
- ) {
93
- a2[k] = handler(cur, fn);
94
- } else if (ArrayBuffer.isView(cur)) {
95
- a2[k] = copyBuffer(cur);
96
- } else {
97
- a2[k] = fn(cur);
98
- }
99
- }
100
- return a2;
101
- }
102
-
103
- function clone(o: any): any {
104
- if (typeof o !== "object" || o === null) return o;
105
- if (Array.isArray(o)) return cloneArray(o, clone);
106
-
107
- if (
108
- o.constructor !== Object &&
109
- (handler = constructorHandlers.get(o.constructor))
110
- ) {
111
- return handler(o, clone);
112
- }
113
-
114
- const o2: Record<string, any> = {};
115
-
116
- for (const k in o) {
117
- if (Object.hasOwnProperty.call(o, k) === false) continue;
118
-
119
- const cur = o[k];
120
-
121
- if (typeof cur !== "object" || cur === null) {
122
- o2[k] = cur;
123
- } else if (
124
- cur.constructor !== Object &&
125
- (handler = constructorHandlers.get(cur.constructor))
126
- ) {
127
- o2[k] = handler(cur, clone);
128
- } else if (ArrayBuffer.isView(cur)) {
129
- o2[k] = copyBuffer(cur);
130
- } else {
131
- o2[k] = clone(cur);
132
- }
133
- }
134
- return o2;
135
- }
136
-
137
- function cloneProto(o: any): any {
138
- if (typeof o !== "object" || o === null) return o;
139
- if (Array.isArray(o)) return cloneArray(o, cloneProto);
140
-
141
- if (
142
- o.constructor !== Object &&
143
- (handler = constructorHandlers.get(o.constructor))
144
- ) {
145
- return handler(o, cloneProto);
146
- }
147
-
148
- const o2: Record<string, any> = {};
149
-
150
- for (const k in o) {
151
- const cur = o[k];
152
-
153
- if (typeof cur !== "object" || cur === null) {
154
- o2[k] = cur;
155
- } else if (
156
- cur.constructor !== Object &&
157
- (handler = constructorHandlers.get(cur.constructor))
158
- ) {
159
- o2[k] = handler(cur, cloneProto);
160
- } else if (ArrayBuffer.isView(cur)) {
161
- o2[k] = copyBuffer(cur);
162
- } else {
163
- o2[k] = cloneProto(cur);
164
- }
165
- }
166
- return o2;
167
- }
168
- }
169
-
170
- function rfdcCircular<T = any>(opts: RfdcOptions): CloneFunction<T> {
171
- const refs: any[] = [];
172
- const refsNew: any[] = [];
173
-
174
- const constructorHandlers = new Map<
175
- new (
176
- ...args: any[]
177
- ) => any,
178
- ConstructorHandler
179
- >();
180
- constructorHandlers.set(Date, (o: Date) => new Date(o));
181
- constructorHandlers.set(
182
- Map,
183
- (o: Map<any, any>, fn: CloneFunction) =>
184
- new Map(cloneArray(Array.from(o), fn)),
185
- );
186
- constructorHandlers.set(
187
- Set,
188
- (o: Set<any>, fn: CloneFunction) => new Set(cloneArray(Array.from(o), fn)),
189
- );
190
-
191
- if (opts.constructorHandlers) {
192
- for (const handler of opts.constructorHandlers) {
193
- constructorHandlers.set(handler[0], handler[1]);
194
- }
195
- }
196
-
197
- let handler: ConstructorHandler | undefined;
198
-
199
- return (opts.proto ? cloneProto : clone) as CloneFunction<T>;
200
-
201
- function cloneArray(a: any[], fn: CloneFunction): any[] {
202
- const keys = Object.keys(a);
203
- const a2: any[] = Array.from({ length: keys.length });
204
-
205
- for (let i = 0; i < keys.length; i++) {
206
- const k = keys[i] as any;
207
- const cur = a[k];
208
-
209
- if (typeof cur !== "object" || cur === null) {
210
- a2[k] = cur;
211
- } else if (
212
- cur.constructor !== Object &&
213
- (handler = constructorHandlers.get(cur.constructor))
214
- ) {
215
- a2[k] = handler(cur, fn);
216
- } else if (ArrayBuffer.isView(cur)) {
217
- a2[k] = copyBuffer(cur);
218
- } else {
219
- const index = refs.indexOf(cur);
220
- if (index !== -1) {
221
- a2[k] = refsNew[index];
222
- } else {
223
- a2[k] = fn(cur);
224
- }
225
- }
226
- }
227
- return a2;
228
- }
229
-
230
- function clone(o: any): any {
231
- if (typeof o !== "object" || o === null) return o;
232
- if (Array.isArray(o)) return cloneArray(o, clone);
233
-
234
- if (
235
- o.constructor !== Object &&
236
- (handler = constructorHandlers.get(o.constructor))
237
- ) {
238
- return handler(o, clone);
239
- }
240
-
241
- const o2: Record<string, any> = {};
242
- refs.push(o);
243
- refsNew.push(o2);
244
-
245
- for (const k in o) {
246
- if (Object.hasOwnProperty.call(o, k) === false) continue;
247
-
248
- const cur = o[k];
249
-
250
- if (typeof cur !== "object" || cur === null) {
251
- o2[k] = cur;
252
- } else if (
253
- cur.constructor !== Object &&
254
- (handler = constructorHandlers.get(cur.constructor))
255
- ) {
256
- o2[k] = handler(cur, clone);
257
- } else if (ArrayBuffer.isView(cur)) {
258
- o2[k] = copyBuffer(cur);
259
- } else {
260
- const i = refs.indexOf(cur);
261
- if (i !== -1) {
262
- o2[k] = refsNew[i];
263
- } else {
264
- o2[k] = clone(cur);
265
- }
266
- }
267
- }
268
-
269
- refs.pop();
270
- refsNew.pop();
271
- return o2;
272
- }
273
-
274
- function cloneProto(o: any): any {
275
- if (typeof o !== "object" || o === null) return o;
276
- if (Array.isArray(o)) return cloneArray(o, cloneProto);
277
-
278
- if (
279
- o.constructor !== Object &&
280
- (handler = constructorHandlers.get(o.constructor))
281
- ) {
282
- return handler(o, cloneProto);
283
- }
284
-
285
- const o2: Record<string, any> = {};
286
- refs.push(o);
287
- refsNew.push(o2);
288
-
289
- for (const k in o) {
290
- const cur = o[k];
291
-
292
- if (typeof cur !== "object" || cur === null) {
293
- o2[k] = cur;
294
- } else if (
295
- cur.constructor !== Object &&
296
- (handler = constructorHandlers.get(cur.constructor))
297
- ) {
298
- o2[k] = handler(cur, cloneProto);
299
- } else if (ArrayBuffer.isView(cur)) {
300
- o2[k] = copyBuffer(cur);
301
- } else {
302
- const i = refs.indexOf(cur);
303
- if (i !== -1) {
304
- o2[k] = refsNew[i];
305
- } else {
306
- o2[k] = cloneProto(cur);
307
- }
308
- }
309
- }
310
-
311
- refs.pop();
312
- refsNew.pop();
313
- return o2;
314
- }
315
- }
316
-
317
- export const deepClone = rfdc();