@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.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/dist/styleframe.d.ts +301 -0
- package/dist/styleframe.js +528 -0
- package/dist/styleframe.umd.cjs +1 -0
- package/package.json +13 -3
- package/.tsbuildinfo +0 -1
- package/src/index.ts +0 -5
- package/src/styleframe.ts +0 -64
- package/src/tokens/atRule.test.ts +0 -1013
- package/src/tokens/atRule.ts +0 -67
- package/src/tokens/css.test.ts +0 -404
- package/src/tokens/css.ts +0 -23
- package/src/tokens/declarations.test.ts +0 -584
- package/src/tokens/declarations.ts +0 -71
- package/src/tokens/index.ts +0 -11
- package/src/tokens/modifier.test.ts +0 -90
- package/src/tokens/modifier.ts +0 -86
- package/src/tokens/recipe.test.ts +0 -105
- package/src/tokens/recipe.ts +0 -32
- package/src/tokens/ref.test.ts +0 -430
- package/src/tokens/ref.ts +0 -24
- package/src/tokens/root.test.ts +0 -70
- package/src/tokens/root.ts +0 -14
- package/src/tokens/selector.test.ts +0 -440
- package/src/tokens/selector.ts +0 -47
- package/src/tokens/theme.test.ts +0 -338
- package/src/tokens/theme.ts +0 -26
- package/src/tokens/utility.test.ts +0 -1456
- package/src/tokens/utility.ts +0 -92
- package/src/tokens/variable.test.ts +0 -235
- package/src/tokens/variable.ts +0 -42
- package/src/typeGuards.test.ts +0 -33
- package/src/typeGuards.ts +0 -98
- package/src/types/declarations.ts +0 -42
- package/src/types/index.ts +0 -3
- package/src/types/options.ts +0 -22
- package/src/types/tokens.ts +0 -149
- package/src/utils/capitalizeFirst.ts +0 -9
- package/src/utils/deepClone.ts +0 -317
- package/src/utils/getters.test.ts +0 -399
- package/src/utils/getters.ts +0 -36
- package/src/utils/index.ts +0 -4
- package/src/utils/merge.test.ts +0 -978
- package/src/utils/merge.ts +0 -73
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -7
- package/vite.config.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @styleframe/core
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#35](https://github.com/styleframe-dev/styleframe/pull/35) [`5d53569`](https://github.com/styleframe-dev/styleframe/commit/5d5356960af687884703f3de5d3d1638d8ee9d8a) Thanks [@alexgrozav](https://github.com/alexgrozav)! - fix: Update published files references in package.json
|
|
8
|
+
|
|
9
|
+
## 1.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Update README.md
|
|
14
|
+
|
|
3
15
|
## 1.0.0
|
|
4
16
|
|
|
5
17
|
### Major Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alex Grozav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { Properties } from 'csstype';
|
|
2
|
+
|
|
3
|
+
export declare function applyModifiers<InstanceType extends Container>(baseInstance: InstanceType, root: Root, modifiers: Map<string, ModifierFactory>): InstanceType;
|
|
4
|
+
|
|
5
|
+
export declare type AtRule = {
|
|
6
|
+
type: "at-rule";
|
|
7
|
+
identifier: string;
|
|
8
|
+
rule: string;
|
|
9
|
+
declarations: DeclarationsBlock;
|
|
10
|
+
variables: Variable[];
|
|
11
|
+
children: ContainerChild[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export declare type CapitalizeFirst<T extends string> = T extends `${infer First}${infer Rest}` ? `${Uppercase<First>}${Rest}` : T;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Capitalizes the first letter of a string
|
|
18
|
+
*/
|
|
19
|
+
export declare function capitalizeFirst(str: string): string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Deep clone a value.
|
|
23
|
+
*
|
|
24
|
+
* We're using rfdc for this, but maintaining our own implementation
|
|
25
|
+
* to avoid production dependencies on external libraries.
|
|
26
|
+
*
|
|
27
|
+
* @source https://github.com/davidmarkclements/rfdc
|
|
28
|
+
*/
|
|
29
|
+
declare type CloneFunction<T = any> = (obj: T) => T;
|
|
30
|
+
|
|
31
|
+
export declare function combineKeys(groups: string[][]): string[][];
|
|
32
|
+
|
|
33
|
+
declare type ConstructorHandler<T = any> = (obj: T, fn: CloneFunction) => T;
|
|
34
|
+
|
|
35
|
+
declare type ConstructorHandlerTuple<T = any> = [
|
|
36
|
+
new (...args: any[]) => T,
|
|
37
|
+
ConstructorHandler<T>
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
export declare type Container = {
|
|
41
|
+
children: ContainerChild[];
|
|
42
|
+
variables: Variable[];
|
|
43
|
+
declarations: DeclarationsBlock;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export declare type ContainerChild = Variable | Selector | AtRule | Utility;
|
|
47
|
+
|
|
48
|
+
export declare function createAtRuleFunction(parent: Container, root: Root): (identifier: string, rule: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
|
|
49
|
+
|
|
50
|
+
export declare function createCssFunction(_parent: Container, _root: Root): (strings: TemplateStringsArray, ...interpolations: TokenValue[]) => CSS_2;
|
|
51
|
+
|
|
52
|
+
export declare function createDeclarationsCallbackContext(parent: Container, root: Root): DeclarationsCallbackContext;
|
|
53
|
+
|
|
54
|
+
export declare function createKeyframesFunction(parent: Container, root: Root): (name: string, declarations: Record<string, DeclarationsBlock>) => AtRule;
|
|
55
|
+
|
|
56
|
+
export declare function createMediaFunction(parent: Container, root: Root): (query: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
|
|
57
|
+
|
|
58
|
+
export declare function createModifiedUtilityInstances(baseInstance: Utility, availableModifiers: ModifierFactory[], root: Root): Utility[];
|
|
59
|
+
|
|
60
|
+
export declare function createModifierFunction(_parent: Container, root: Root): <Key extends string>(key: Key | Key[], factory: ModifierFactory["factory"]) => ModifierFactory;
|
|
61
|
+
|
|
62
|
+
export declare function createRecipeFunction(_parent: Container, root: Root): <Name extends string, Variants extends Record<string, Record<string, VariantDeclarationsBlock>>>(name: Name, defaults: Recipe<Name, Variants>["defaults"], variants: Recipe<Name, Variants>["variants"], options?: {
|
|
63
|
+
defaultVariants?: Recipe<Name, Variants>["defaultVariants"];
|
|
64
|
+
compoundVariants?: Recipe<Name, Variants>["compoundVariants"];
|
|
65
|
+
}) => Recipe<Name, Variants>;
|
|
66
|
+
|
|
67
|
+
export declare function createRefFunction(_parent: Container, _root: Root): <Name extends string>(variable: Variable<Name> | Name, fallback?: string) => Reference<Name>;
|
|
68
|
+
|
|
69
|
+
export declare function createRoot(): Root;
|
|
70
|
+
|
|
71
|
+
export declare function createSelectorFunction(parent: Container, root: Root): (query: string, declarationsOrCallback: DeclarationsBlock | Container | DeclarationsCallback) => Selector;
|
|
72
|
+
|
|
73
|
+
export declare function createThemeFunction(_parent: Container, root: Root): (name: string, callback: DeclarationsCallback) => Theme;
|
|
74
|
+
|
|
75
|
+
export declare function createUtilityFunction(parent: Container, root: Root): <Name extends string>(name: Name, factory: UtilityCallbackFn) => UtilityCreatorFn;
|
|
76
|
+
|
|
77
|
+
export declare function createVariableFunction(parent: Container, _root: Root): <Name extends string>(nameOrInstance: Name | Variable<Name>, value: TokenValue, options?: {
|
|
78
|
+
default: boolean;
|
|
79
|
+
}) => Variable<Name>;
|
|
80
|
+
|
|
81
|
+
declare type CSS_2 = {
|
|
82
|
+
type: "css";
|
|
83
|
+
value: TokenValue[];
|
|
84
|
+
};
|
|
85
|
+
export { CSS_2 as CSS }
|
|
86
|
+
|
|
87
|
+
declare type CSSValueWithReference<T> = T extends string | number | undefined ? T | TokenValue : T extends object ? CSSValueWithReference<T> : T | TokenValue;
|
|
88
|
+
|
|
89
|
+
export declare type DeclarationsBlock = {
|
|
90
|
+
[K in keyof Properties]: CSSValueWithReference<Properties[K]>;
|
|
91
|
+
} & {
|
|
92
|
+
[key: string]: CSSValueWithReference<Properties[keyof Properties]> | DeclarationsBlock;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export declare type DeclarationsCallback<Context extends DeclarationsCallbackContext = DeclarationsCallbackContext> = (context: Context) => DeclarationsBlock | void;
|
|
96
|
+
|
|
97
|
+
export declare type DeclarationsCallbackContext = {
|
|
98
|
+
variable: ReturnType<typeof createVariableFunction>;
|
|
99
|
+
selector: ReturnType<typeof createSelectorFunction>;
|
|
100
|
+
atRule: ReturnType<typeof createAtRuleFunction>;
|
|
101
|
+
keyframes: ReturnType<typeof createKeyframesFunction>;
|
|
102
|
+
media: ReturnType<typeof createMediaFunction>;
|
|
103
|
+
ref: ReturnType<typeof createRefFunction>;
|
|
104
|
+
css: ReturnType<typeof createCssFunction>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export declare const deepClone: CloneFunction<any>;
|
|
108
|
+
|
|
109
|
+
export declare function getModifier(root: Root, name: string): ModifierFactory;
|
|
110
|
+
|
|
111
|
+
export declare function getUtility(root: Root, name: string): UtilityFactory;
|
|
112
|
+
|
|
113
|
+
export declare function getVariable(root: Container, name: string): Variable;
|
|
114
|
+
|
|
115
|
+
export declare function isAtRule(value: unknown): value is AtRule;
|
|
116
|
+
|
|
117
|
+
export declare function isContainer(value: unknown): value is Container;
|
|
118
|
+
|
|
119
|
+
export declare function isCSS(value: unknown): value is CSS_2;
|
|
120
|
+
|
|
121
|
+
export declare function isModifier(value: unknown): value is ModifierFactory;
|
|
122
|
+
|
|
123
|
+
export declare function isObject(value: unknown): value is object;
|
|
124
|
+
|
|
125
|
+
export declare function isPrimitiveTokenValue(value: unknown): value is PrimitiveTokenValue;
|
|
126
|
+
|
|
127
|
+
export declare function isRef<Name extends string = string>(value: unknown): value is Reference<Name>;
|
|
128
|
+
|
|
129
|
+
export declare function isRoot(value: unknown): value is Root;
|
|
130
|
+
|
|
131
|
+
export declare function isSelector(value: unknown): value is Selector;
|
|
132
|
+
|
|
133
|
+
export declare function isTheme(value: unknown): value is Theme;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Tokens
|
|
137
|
+
*/
|
|
138
|
+
export declare function isToken<T>(value: unknown, type: TokenType): value is T;
|
|
139
|
+
|
|
140
|
+
export declare function isTokenValue(value: unknown): value is TokenValue;
|
|
141
|
+
|
|
142
|
+
export declare function isUtility<Name extends string = string>(value: unknown): value is Utility<Name>;
|
|
143
|
+
|
|
144
|
+
export declare function isVariable<Name extends string = string>(value: unknown): value is Variable<Name>;
|
|
145
|
+
|
|
146
|
+
export declare function merge(base: Styleframe, ...instances: Styleframe[]): Styleframe;
|
|
147
|
+
|
|
148
|
+
export declare function mergeContainers<T extends Container>(a: T, b: T): T;
|
|
149
|
+
|
|
150
|
+
export declare function mergeThemesArray(a: Theme[], b: Theme[]): Theme[];
|
|
151
|
+
|
|
152
|
+
export declare function mergeVariablesArray(a: Variable[], b: Variable[]): Variable[];
|
|
153
|
+
|
|
154
|
+
export declare type ModifierCallbackFn = DeclarationsCallback<DeclarationsCallbackContext & Pick<Utility, "declarations" | "variables" | "children">>;
|
|
155
|
+
|
|
156
|
+
export declare type ModifierFactory = {
|
|
157
|
+
type: "modifier";
|
|
158
|
+
key: string[];
|
|
159
|
+
factory: ModifierCallbackFn;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export declare function parseDeclarationsBlock(declarations: DeclarationsBlock, context: DeclarationsCallbackContext): DeclarationsBlock;
|
|
163
|
+
|
|
164
|
+
export declare type PrimitiveTokenValue = number | string | boolean | null | undefined;
|
|
165
|
+
|
|
166
|
+
export declare type Recipe<Name extends string = string, Variants extends Record<string, Record<string, VariantDeclarationsBlock>> = Record<string, Record<string, VariantDeclarationsBlock>>> = {
|
|
167
|
+
type: "recipe";
|
|
168
|
+
name: Name;
|
|
169
|
+
defaults: VariantDeclarationsBlock;
|
|
170
|
+
variants: Variants;
|
|
171
|
+
defaultVariants?: {
|
|
172
|
+
[K in keyof Variants]?: keyof Variants[K] & string;
|
|
173
|
+
};
|
|
174
|
+
compoundVariants?: Array<{
|
|
175
|
+
[K in keyof Variants]?: keyof Variants[K] & string;
|
|
176
|
+
} & {
|
|
177
|
+
declarations: VariantDeclarationsBlock;
|
|
178
|
+
}>;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export declare type Reference<Name extends string = string> = {
|
|
182
|
+
type: "reference";
|
|
183
|
+
name: Name;
|
|
184
|
+
fallback?: TokenValue;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export declare function rfdc<T = any>(opts?: RfdcOptions): CloneFunction<T>;
|
|
188
|
+
|
|
189
|
+
declare interface RfdcOptions {
|
|
190
|
+
circular?: boolean;
|
|
191
|
+
proto?: boolean;
|
|
192
|
+
constructorHandlers?: ConstructorHandlerTuple[];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export declare type Root = {
|
|
196
|
+
type: "root";
|
|
197
|
+
declarations: DeclarationsBlock;
|
|
198
|
+
utilities: UtilityFactory[];
|
|
199
|
+
modifiers: ModifierFactory[];
|
|
200
|
+
recipes: Recipe[];
|
|
201
|
+
variables: Variable[];
|
|
202
|
+
children: ContainerChild[];
|
|
203
|
+
themes: Theme[];
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export declare type Selector = {
|
|
207
|
+
type: "selector";
|
|
208
|
+
query: string;
|
|
209
|
+
declarations: DeclarationsBlock;
|
|
210
|
+
variables: Variable[];
|
|
211
|
+
children: ContainerChild[];
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export declare interface Styleframe {
|
|
215
|
+
root: Root;
|
|
216
|
+
variable: ReturnType<typeof createVariableFunction>;
|
|
217
|
+
selector: ReturnType<typeof createSelectorFunction>;
|
|
218
|
+
utility: ReturnType<typeof createUtilityFunction>;
|
|
219
|
+
modifier: ReturnType<typeof createModifierFunction>;
|
|
220
|
+
recipe: ReturnType<typeof createRecipeFunction>;
|
|
221
|
+
theme: ReturnType<typeof createThemeFunction>;
|
|
222
|
+
atRule: ReturnType<typeof createAtRuleFunction>;
|
|
223
|
+
keyframes: ReturnType<typeof createKeyframesFunction>;
|
|
224
|
+
media: ReturnType<typeof createMediaFunction>;
|
|
225
|
+
ref: ReturnType<typeof createRefFunction>;
|
|
226
|
+
css: ReturnType<typeof createCssFunction>;
|
|
227
|
+
options: StyleframeOptions;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export declare function styleframe(userOptions?: StyleframeOptions): Styleframe;
|
|
231
|
+
|
|
232
|
+
export declare type StyleframeOptions = {
|
|
233
|
+
indent?: string;
|
|
234
|
+
variables?: {
|
|
235
|
+
name?: VariableNameFn;
|
|
236
|
+
};
|
|
237
|
+
utilities?: {
|
|
238
|
+
selector?: UtilitySelectorFn;
|
|
239
|
+
};
|
|
240
|
+
theme?: {
|
|
241
|
+
selector?: ThemeSelectorFn;
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export declare type Theme = {
|
|
246
|
+
type: "theme";
|
|
247
|
+
name: string;
|
|
248
|
+
declarations: DeclarationsBlock;
|
|
249
|
+
variables: Variable[];
|
|
250
|
+
children: ContainerChild[];
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export declare type ThemeSelectorFn = (options: {
|
|
254
|
+
name: string;
|
|
255
|
+
}) => string;
|
|
256
|
+
|
|
257
|
+
export declare type TokenType = Variable["type"] | Reference["type"] | Selector["type"] | AtRule["type"] | CSS_2["type"] | Utility["type"] | ModifierFactory["type"] | Recipe["type"] | Theme["type"] | Root["type"];
|
|
258
|
+
|
|
259
|
+
export declare type TokenValue = PrimitiveTokenValue | Reference | CSS_2 | Array<PrimitiveTokenValue | Reference | CSS_2>;
|
|
260
|
+
|
|
261
|
+
export declare type Utility<Name extends string = string> = {
|
|
262
|
+
type: "utility";
|
|
263
|
+
name: Name;
|
|
264
|
+
value: string;
|
|
265
|
+
declarations: DeclarationsBlock;
|
|
266
|
+
variables: Variable[];
|
|
267
|
+
children: ContainerChild[];
|
|
268
|
+
modifiers: string[];
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export declare type UtilityCallbackFn = DeclarationsCallback<DeclarationsCallbackContext & {
|
|
272
|
+
value: TokenValue;
|
|
273
|
+
}>;
|
|
274
|
+
|
|
275
|
+
export declare type UtilityCreatorFn = (values: Record<string, TokenValue>, modifiers?: ModifierFactory[]) => void;
|
|
276
|
+
|
|
277
|
+
export declare type UtilityFactory<Name extends string = string> = {
|
|
278
|
+
type: "utility";
|
|
279
|
+
name: Name;
|
|
280
|
+
factory: UtilityCallbackFn;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export declare type UtilitySelectorFn = (options: {
|
|
284
|
+
name: string;
|
|
285
|
+
value: string;
|
|
286
|
+
modifiers: string[];
|
|
287
|
+
}) => string;
|
|
288
|
+
|
|
289
|
+
export declare type Variable<Name extends string = string> = {
|
|
290
|
+
type: "variable";
|
|
291
|
+
name: Name;
|
|
292
|
+
value: TokenValue;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export declare type VariableNameFn = (options: {
|
|
296
|
+
name: string;
|
|
297
|
+
}) => string;
|
|
298
|
+
|
|
299
|
+
export declare type VariantDeclarationsBlock = Record<string, string | true>;
|
|
300
|
+
|
|
301
|
+
export { }
|