@paganaye/stylets 0.1.0

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 (70) hide show
  1. package/README.md +13 -0
  2. package/dist/BaseStyles.d.ts +44 -0
  3. package/dist/BaseStyles.js +166 -0
  4. package/dist/Button.d.ts +69 -0
  5. package/dist/Button.js +56 -0
  6. package/dist/CssColor.d.ts +44 -0
  7. package/dist/CssColor.js +196 -0
  8. package/dist/CssColor.test.d.ts +1 -0
  9. package/dist/CssColor.test.js +68 -0
  10. package/dist/CssExpr.d.ts +9 -0
  11. package/dist/CssExpr.js +35 -0
  12. package/dist/CssFilter.d.ts +18 -0
  13. package/dist/CssFilter.js +40 -0
  14. package/dist/CssNum.d.ts +30 -0
  15. package/dist/CssNum.js +106 -0
  16. package/dist/CssNum.test.d.ts +1 -0
  17. package/dist/CssNum.test.js +30 -0
  18. package/dist/CssReset.d.ts +1 -0
  19. package/dist/CssReset.js +15 -0
  20. package/dist/CssShadow.d.ts +19 -0
  21. package/dist/CssShadow.js +42 -0
  22. package/dist/DefaultTheme.d.ts +14 -0
  23. package/dist/DefaultTheme.js +6 -0
  24. package/dist/EmptyTheme.d.ts +14 -0
  25. package/dist/EmptyTheme.js +2 -0
  26. package/dist/HTML.d.ts +9 -0
  27. package/dist/HTML.jsx +7 -0
  28. package/dist/ScopeStyles.d.ts +24 -0
  29. package/dist/ScopeStyles.js +67 -0
  30. package/dist/State.d.ts +36 -0
  31. package/dist/State.js +107 -0
  32. package/dist/State.test.d.ts +1 -0
  33. package/dist/State.test.js +41 -0
  34. package/dist/StyleWriter.d.ts +25 -0
  35. package/dist/StyleWriter.js +156 -0
  36. package/dist/Theme.d.ts +56 -0
  37. package/dist/Theme.js +29 -0
  38. package/dist/Tone.d.ts +1 -0
  39. package/dist/Tone.js +1 -0
  40. package/dist/index.d.ts +1 -0
  41. package/dist/index.js +1 -0
  42. package/dist/index.test.d.ts +1 -0
  43. package/dist/index.test.js +9 -0
  44. package/dist/props.d.ts +7 -0
  45. package/dist/props.js +104 -0
  46. package/dist/types.d.ts +239 -0
  47. package/dist/types.js +1 -0
  48. package/package.json +36 -0
  49. package/src/BaseStyles.ts +192 -0
  50. package/src/Button.ts +68 -0
  51. package/src/CssColor.test.ts +82 -0
  52. package/src/CssColor.ts +175 -0
  53. package/src/CssExpr.ts +25 -0
  54. package/src/CssFilter.ts +44 -0
  55. package/src/CssNum.test.ts +37 -0
  56. package/src/CssNum.ts +93 -0
  57. package/src/CssReset.ts +17 -0
  58. package/src/CssShadow.ts +46 -0
  59. package/src/DefaultTheme.ts +8 -0
  60. package/src/HTML.tsx +17 -0
  61. package/src/ScopeStyles.ts +100 -0
  62. package/src/State.test.ts +47 -0
  63. package/src/State.ts +164 -0
  64. package/src/StyleWriter.ts +163 -0
  65. package/src/Theme.ts +95 -0
  66. package/src/Tone.ts +1 -0
  67. package/src/index.test.ts +10 -0
  68. package/src/index.ts +1 -0
  69. package/src/props.ts +118 -0
  70. package/src/types.ts +311 -0
package/src/types.ts ADDED
@@ -0,0 +1,311 @@
1
+ import { CssColor } from "./CssColor";
2
+ import { CssFilter } from "./CssFilter";
3
+ import { Num } from "./CssNum";
4
+ import { CssShadow } from "./CssShadow";
5
+
6
+ // +-----------------------------+
7
+ // \ Variables and Functions /
8
+ // \-------------------------/
9
+ // \ Global CSS properties /
10
+ // \---------------------/
11
+ // \ Elements /
12
+ // \-----------------/
13
+ // \ Components /
14
+ // +-------------+
15
+ // \ /
16
+ // \Overrides/
17
+ // \_______/
18
+ // OverrideProperties groups the property types where we want stronger
19
+ // typing (e.g. allow `Num`/`number` for spacing, typography, layout, etc.).
20
+ export type OverrideProperties = ShadowProperties & PaddingProperties & MarginProperties & BorderProperties & BackgroundProperties & LayoutProperties & TypographyProperties;
21
+
22
+ export type CssProperties = Omit<Partial<CSSStyleDeclaration>, keyof OverrideProperties> & OverrideProperties & {
23
+ [key: CssVariableName]: string | number | boolean | Num;
24
+ };
25
+
26
+ export type CssVariableName = `--${string}`;
27
+
28
+ export type ThemeArgs = {
29
+ variants: Record<string, Record<string, any>>;
30
+ colors: string;
31
+ vars: string;
32
+ paddings: string;
33
+ margins: string;
34
+ borders: string;
35
+ backgrounds: string;
36
+ typography: string;
37
+ layouts: string;
38
+ shadows: string;
39
+ classes: string;
40
+ };
41
+
42
+ export type ThemeKey = keyof ThemeArgs;
43
+
44
+ export interface IThemeParts<
45
+ A extends ThemeArgs> {
46
+ name?: string;
47
+ variants?: { [K in keyof A['variants']]?: Record<keyof A['variants'][K] & string, CssProperties> };
48
+ colors?: Record<A['colors'], string | CssColor>;
49
+ vars?: Record<A['vars'], string | number>;
50
+ //
51
+ paddings?: Record<A['paddings'], PaddingProperties>;
52
+ margins?: Record<A['margins'], MarginProperties>;
53
+ borders?: Record<A['borders'], BorderProperties>;
54
+ backgrounds?: Record<A['backgrounds'], BackgroundProperties>;
55
+ typography?: Record<A['typography'], TypographyProperties>;
56
+ layouts?: Record<A['layouts'], LayoutProperties>;
57
+ shadows?: Record<A['shadows'], ShadowProperties>;
58
+ classes?: Record<A['classes'], CssProperties>;
59
+ styles?: Record<string, CssProperties>;
60
+ }
61
+
62
+ // The XxxxProperties below are Records<Key,Value>
63
+ // where key is STRICTLY a CSS property name in camelCase
64
+ // and Value is the type of value accepted for that property
65
+
66
+ export type ShadowProperties = {
67
+ boxShadow?: CssShadow | string;
68
+ textShadow?: CssShadow | string;
69
+ filter?: CssFilter | CssFilter[] | string;
70
+ backdropFilter?: CssFilter | string;
71
+ opacity?: Num | string;
72
+ }
73
+
74
+ export type PaddingProperties = {
75
+ padding?: Num;
76
+ paddingTop?: Num;
77
+ paddingRight?: Num;
78
+ paddingBottom?: Num;
79
+ paddingLeft?: Num;
80
+ }
81
+
82
+ export type MarginProperties = {
83
+ margin?: Num;
84
+ marginTop?: Num;
85
+ marginRight?: Num;
86
+ marginBottom?: Num;
87
+ marginLeft?: Num;
88
+ }
89
+
90
+ export type BorderProperties = {
91
+ border?: string;
92
+ borderWidth?: Num;
93
+ borderStyle?: CssBorderStyle;
94
+ borderColor?: CssColor | string;
95
+ borderCollapse?: CssBorderCollapse;
96
+ borderSpacing?: Num;
97
+
98
+ borderTop?: string;
99
+ borderTopWidth?: Num;
100
+ borderTopStyle?: CssBorderStyle;
101
+ borderTopColor?: CssColor | string;
102
+
103
+ borderRight?: string;
104
+ borderRightWidth?: Num;
105
+ borderRightStyle?: CssBorderStyle;
106
+ borderRightColor?: CssColor | string;
107
+
108
+ borderBottom?: string;
109
+ borderBottomWidth?: Num;
110
+ borderBottomStyle?: CssBorderStyle;
111
+ borderBottomColor?: CssColor | string;
112
+
113
+ borderLeft?: string;
114
+ borderLeftWidth?: Num;
115
+ borderLeftStyle?: CssBorderStyle;
116
+ borderLeftColor?: CssColor | string;
117
+
118
+ borderRadius?: Num;
119
+ borderTopLeftRadius?: Num;
120
+ borderTopRightRadius?: Num;
121
+ borderBottomLeftRadius?: Num;
122
+ borderBottomRightRadius?: Num;
123
+
124
+ cornerTopLeftShape?: CssCornerShape;
125
+ cornerTopRightShape?: CssCornerShape;
126
+ cornerBottomLeftShape?: CssCornerShape;
127
+ cornerBottomRightShape?: CssCornerShape;
128
+
129
+ outline?: string;
130
+ outlineWidth?: Num;
131
+ outlineStyle?: CssBorderStyle;
132
+ outlineColor?: CssColor | string;
133
+ outlineOffset?: Num;
134
+ }
135
+
136
+ export type BackgroundProperties = {
137
+ background?: string;
138
+ backgroundColor?: CssColor | string;
139
+ backgroundImage?: string;
140
+ backgroundRepeat?: string;
141
+ backgroundPosition?: string;
142
+ backgroundSize?: string;
143
+ backgroundAttachment?: 'scroll' | 'fixed' | 'local' | string;
144
+ backgroundClip?: string;
145
+ backgroundOrigin?: string;
146
+ }
147
+
148
+ export type LayoutProperties = {
149
+ /* Positioning */
150
+ position?: 'static' | 'relative' | 'absolute' | 'fixed' | 'sticky' | string;
151
+ inset?: string | Num;
152
+ top?: Num | string;
153
+ right?: Num | string;
154
+ bottom?: Num | string;
155
+ left?: Num | string;
156
+ zIndex?: number | string;
157
+
158
+ /* Display & Box */
159
+ display?: string;
160
+ boxSizing?: 'content-box' | 'border-box' | string;
161
+
162
+ /* Sizing */
163
+ width?: Num | string;
164
+ minWidth?: Num | string;
165
+ maxWidth?: Num | string;
166
+ height?: Num | string;
167
+ minHeight?: Num | string;
168
+ maxHeight?: Num | string;
169
+
170
+ /* Flexbox */
171
+ flex?: string | Num;
172
+ flexBasis?: Num | string;
173
+ flexGrow?: number | string;
174
+ flexShrink?: number | string;
175
+ flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse' | string;
176
+ flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse' | string;
177
+ justifyContent?: string;
178
+ alignItems?: string;
179
+ alignContent?: string;
180
+ alignSelf?: string;
181
+ order?: number | string;
182
+ gap?: Num | string;
183
+
184
+ /* Grid */
185
+ gridTemplateColumns?: string;
186
+ gridTemplateRows?: string;
187
+ gridColumn?: string;
188
+ gridRow?: string;
189
+ gridGap?: Num | string;
190
+ gridAutoFlow?: string;
191
+
192
+ /* Columns */
193
+ columnCount?: number | string;
194
+ columnWidth?: Num | string;
195
+ columnGap?: Num | string;
196
+ columnRule?: string;
197
+
198
+ /* Overflow & Scrolling */
199
+ overflow?: 'visible' | 'hidden' | 'scroll' | 'auto' | string;
200
+ overflowX?: 'visible' | 'hidden' | 'scroll' | 'auto' | string;
201
+ overflowY?: 'visible' | 'hidden' | 'scroll' | 'auto' | string;
202
+ scrollBehavior?: 'auto' | 'smooth' | string;
203
+ overscrollBehavior?: string;
204
+ scrollSnapType?: string;
205
+ scrollSnapAlign?: string;
206
+ };
207
+
208
+ export type TypographyProperties = {
209
+ font?: string;
210
+ fontFamily?: string;
211
+ fontSize?: Num;
212
+ fontWeight?: Num;
213
+ fontStyle?: 'normal' | 'italic' | 'oblique' | string;
214
+ lineHeight?: Num;
215
+ letterSpacing?: Num;
216
+ wordSpacing?: Num;
217
+ textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase' | string;
218
+ textDecoration?: string;
219
+ textAlign?: 'left' | 'right' | 'center' | 'justify' | string;
220
+ whiteSpace?: string;
221
+ textOverflow?: 'clip' | 'ellipsis' | string;
222
+ overflowWrap?: 'normal' | 'break-word' | 'anywhere';
223
+ }
224
+
225
+ export type CssBorderStyle = 'none' | 'hidden' | 'dotted' | 'dashed' | 'solid' | 'double' | 'groove' | 'ridge' | 'inset' | 'outset';
226
+ export type CssBorderCollapse = 'collapse' | 'separate' | 'inherit' | 'initial' | 'revert' | 'revert-layer' | 'unset';
227
+
228
+ export type CssCornerShape = 'bevel' | 'notch' | 'round' | 'scoop' | 'square' | 'squircle';
229
+
230
+ export interface IScopeStylesParts<A extends ThemeArgs> extends IThemeParts<A> {
231
+ }
232
+
233
+
234
+ export interface ITheme<A extends ThemeArgs = any> {
235
+ colors: Record<A['colors'], string>;
236
+ paddings: Record<A['paddings'], string>;
237
+ margins: Record<A['margins'], string>;
238
+ borders: Record<A['borders'], string>;
239
+ shadows: Record<A['shadows'], string>;
240
+ backgrounds: Record<A['backgrounds'], string>;
241
+ typography: Record<A['typography'], string>;
242
+ vars: Record<A['vars'], string>;
243
+ classes: Identity<A['classes']>;
244
+ }
245
+
246
+ export type CssClass<TTheme extends ITheme<any>> = Extract<keyof TTheme['classes'], string>
247
+
248
+ export type ClassList<T extends string = any> = T
249
+ | Array<T
250
+ | undefined
251
+ | null
252
+ | Record<T, boolean | undefined | null>
253
+ >
254
+ | Record<T, boolean | undefined | null>;
255
+
256
+ export type ThemeClass<TTheme extends ITheme> = ClassList<CssClass<TTheme>>;
257
+
258
+ export type IThemeFromArgs<Args extends ThemeArgs> = ITheme<Args>;
259
+
260
+ export type ExtractNames<P, K extends ThemeKey> =
261
+ P extends { [Key in K]: Record<infer Names, any> } ? Extract<Names, string> : never;
262
+
263
+ export type MergeNames<K extends ThemeKey, A extends ThemeArgs, P> =
264
+ [A[K]] extends [never]
265
+ ? ExtractNames<P, K>
266
+ : ([ExtractNames<P, K>] extends [never] ? A[K] : A[K] | ExtractNames<P, K>);
267
+
268
+ export type Simplify<T> = { [K in keyof T]: T[K] } & {};
269
+
270
+ export type Identity<T extends string> = { [K in T]: K };
271
+
272
+ export type ExtractVariantRecord<P> = P extends { variants: infer V extends Record<string, any> } ? V : {};
273
+
274
+ export type MergeVariants<A extends ThemeArgs, P> =
275
+ Simplify<A['variants'] & ExtractVariantRecord<P>>;
276
+
277
+ export type ExtractVariants<P> = P extends { variants: infer V } ? V : {};
278
+
279
+ export type HasDefault<T> = "default" extends keyof T ? true : false;
280
+
281
+ export type RemoveIndexSignature<T> = {
282
+ [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K]
283
+ };
284
+
285
+ export type VariantProps<S> = S extends { variants: infer V extends Record<string, any> }
286
+ ? Simplify<{
287
+ [K in keyof RemoveIndexSignature<V> as K extends string ? (HasDefault<V[K]> extends true ? K : never) : never]?: Extract<keyof V[K], string>
288
+ } & {
289
+ [K in keyof RemoveIndexSignature<V> as K extends string ? (HasDefault<V[K]> extends true ? never : K) : never]: Extract<keyof V[K], string>
290
+ }>
291
+ : {};
292
+
293
+ export type ElementPropsRecord = {
294
+ class: string;
295
+ [dataAttr: `data-${string}`]: string | undefined;
296
+ };
297
+
298
+ export type MergeThemeArgs<A extends ThemeArgs, P> = Simplify<{
299
+ colors: MergeNames<'colors', A, P>;
300
+ vars: MergeNames<'vars', A, P>;
301
+ paddings: MergeNames<'paddings', A, P>;
302
+ margins: MergeNames<'margins', A, P>;
303
+ borders: MergeNames<'borders', A, P>;
304
+ backgrounds: MergeNames<'backgrounds', A, P>;
305
+ typography: MergeNames<'typography', A, P>;
306
+ shadows: MergeNames<'shadows', A, P>;
307
+ layouts: MergeNames<'layouts', A, P>;
308
+ classes: MergeNames<'classes', A, P>;
309
+ variants: MergeVariants<A, P>;
310
+ }>;
311
+