@greese/ui 0.0.0-stage → 1.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 (288) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -2
  3. package/bin/greese-utilities.mjs +56 -0
  4. package/dist/_layers.scss +2 -0
  5. package/dist/_maps.scss +1884 -0
  6. package/dist/_tokens-base.scss +174 -0
  7. package/dist/_tokens.scss +2140 -0
  8. package/dist/base.css +67 -0
  9. package/dist/colorScheme.d.ts +16 -0
  10. package/dist/colorScheme.js +13 -0
  11. package/dist/contrast.d.ts +15 -0
  12. package/dist/contrast.js +43 -0
  13. package/dist/css/Accordion.css +9 -0
  14. package/dist/css/ActionSelect.css +6 -0
  15. package/dist/css/Alert.css +84 -0
  16. package/dist/css/AppBar.css +35 -0
  17. package/dist/css/AspectRatio.css +40 -0
  18. package/dist/css/AutoLayout.css +508 -0
  19. package/dist/css/Avatar.css +88 -0
  20. package/dist/css/Badge.css +66 -0
  21. package/dist/css/Box.css +640 -0
  22. package/dist/css/Breadcrumbs.css +57 -0
  23. package/dist/css/Button.css +275 -0
  24. package/dist/css/ButtonGroup.css +40 -0
  25. package/dist/css/Card.css +101 -0
  26. package/dist/css/Carousel.css +170 -0
  27. package/dist/css/Center.css +11 -0
  28. package/dist/css/ChatBubble.css +128 -0
  29. package/dist/css/Checkbox.css +65 -0
  30. package/dist/css/Chip.css +124 -0
  31. package/dist/css/ChoiceGroup.css +57 -0
  32. package/dist/css/Code.css +29 -0
  33. package/dist/css/Collapsible.css +126 -0
  34. package/dist/css/ColorPicker.css +191 -0
  35. package/dist/css/Combobox.css +90 -0
  36. package/dist/css/Container.css +30 -0
  37. package/dist/css/Countdown.css +25 -0
  38. package/dist/css/DateField.css +15 -0
  39. package/dist/css/Dialog.css +640 -0
  40. package/dist/css/Diff.css +103 -0
  41. package/dist/css/Divider.css +19 -0
  42. package/dist/css/Dock.css +91 -0
  43. package/dist/css/Field.css +33 -0
  44. package/dist/css/Fieldset.css +54 -0
  45. package/dist/css/FileInput.css +65 -0
  46. package/dist/css/Footer.css +72 -0
  47. package/dist/css/Grid.css +998 -0
  48. package/dist/css/Header.css +89 -0
  49. package/dist/css/Heading.css +6 -0
  50. package/dist/css/Icon.css +12 -0
  51. package/dist/css/IconButton.css +7 -0
  52. package/dist/css/Image.css +69 -0
  53. package/dist/css/Indicator.css +41 -0
  54. package/dist/css/Input.css +115 -0
  55. package/dist/css/Key.css +42 -0
  56. package/dist/css/Link.css +72 -0
  57. package/dist/css/List.css +52 -0
  58. package/dist/css/Media.css +8 -0
  59. package/dist/css/Menu.css +161 -0
  60. package/dist/css/Motion.css +1356 -0
  61. package/dist/css/NumberField.css +49 -0
  62. package/dist/css/OtpField.css +90 -0
  63. package/dist/css/PageTransition.css +991 -0
  64. package/dist/css/Pagination.css +43 -0
  65. package/dist/css/Popover.css +93 -0
  66. package/dist/css/Progress.css +101 -0
  67. package/dist/css/RadialProgress.css +44 -0
  68. package/dist/css/Radio.css +41 -0
  69. package/dist/css/Rating.css +100 -0
  70. package/dist/css/ScrollSpy.css +6 -0
  71. package/dist/css/SegmentedControl.css +101 -0
  72. package/dist/css/Select.css +115 -0
  73. package/dist/css/Sidebar.css +207 -0
  74. package/dist/css/Skeleton.css +48 -0
  75. package/dist/css/Slider.css +75 -0
  76. package/dist/css/Spacer.css +34 -0
  77. package/dist/css/SpeedDial.css +165 -0
  78. package/dist/css/Spinner.css +44 -0
  79. package/dist/css/Stack.css +528 -0
  80. package/dist/css/Stat.css +107 -0
  81. package/dist/css/Status.css +86 -0
  82. package/dist/css/Steps.css +201 -0
  83. package/dist/css/Swap.css +49 -0
  84. package/dist/css/Switch.css +66 -0
  85. package/dist/css/Table.css +269 -0
  86. package/dist/css/Tabs.css +119 -0
  87. package/dist/css/Text.css +60 -0
  88. package/dist/css/TextRotate.css +147 -0
  89. package/dist/css/Textarea.css +107 -0
  90. package/dist/css/ThemeProvider.css +6 -0
  91. package/dist/css/Tile.css +18 -0
  92. package/dist/css/Toast.css +110 -0
  93. package/dist/css/ToggleButton.css +20 -0
  94. package/dist/css/Tooltip.css +94 -0
  95. package/dist/css/Type.css +211 -0
  96. package/dist/css/Visibility.css +78 -0
  97. package/dist/css/VisuallyHidden.css +15 -0
  98. package/dist/css/core.css +251 -0
  99. package/dist/css.d.ts +29 -0
  100. package/dist/css.js +28 -0
  101. package/dist/effect-classes.d.ts +8 -0
  102. package/dist/effect-classes.js +5 -0
  103. package/dist/effects/css.d.ts +71 -0
  104. package/dist/effects/css.js +184 -0
  105. package/dist/effects/definitions.d.ts +555 -0
  106. package/dist/effects/definitions.js +379 -0
  107. package/dist/effects/frames.d.ts +18 -0
  108. package/dist/effects/frames.js +68 -0
  109. package/dist/effects/sequence.d.ts +33 -0
  110. package/dist/effects/sequence.js +106 -0
  111. package/dist/effects.d.ts +30 -0
  112. package/dist/effects.js +30 -0
  113. package/dist/greese.css +11919 -0
  114. package/dist/index.d.ts +10 -0
  115. package/dist/index.js +10 -0
  116. package/dist/kebab.d.ts +2 -0
  117. package/dist/kebab.js +2 -0
  118. package/dist/palette.css +249 -0
  119. package/dist/palette.d.ts +599 -0
  120. package/dist/palette.js +334 -0
  121. package/dist/shapes.d.ts +193 -0
  122. package/dist/shapes.js +852 -0
  123. package/dist/storage.d.ts +47 -0
  124. package/dist/storage.js +118 -0
  125. package/dist/style-manifest.json +3017 -0
  126. package/dist/theme.d.ts +71 -0
  127. package/dist/theme.js +180 -0
  128. package/dist/tokens.css +253 -0
  129. package/dist/tokens.d.ts +343 -0
  130. package/dist/tokens.js +179 -0
  131. package/dist/typography.d.ts +55 -0
  132. package/dist/typography.js +144 -0
  133. package/dist/utilities.css +6975 -0
  134. package/dist/utilities.d.ts +82 -0
  135. package/dist/utilities.js +636 -0
  136. package/dist/utilitiesFiles.d.ts +18 -0
  137. package/dist/utilitiesFiles.js +26 -0
  138. package/dist/vite.d.ts +40 -0
  139. package/dist/vite.js +43 -0
  140. package/package.json +131 -4
  141. package/src/components/Accordion/Accordion.scss +9 -0
  142. package/src/components/ActionSelect/ActionSelect.scss +6 -0
  143. package/src/components/Alert/Alert.scss +71 -0
  144. package/src/components/AppBar/AppBar.scss +43 -0
  145. package/src/components/AspectRatio/AspectRatio.scss +22 -0
  146. package/src/components/AutoLayout/AutoLayout.scss +90 -0
  147. package/src/components/Avatar/Avatar.scss +91 -0
  148. package/src/components/Badge/Badge.scss +52 -0
  149. package/src/components/Box/Box.scss +63 -0
  150. package/src/components/Breadcrumbs/Breadcrumbs.scss +59 -0
  151. package/src/components/Button/Button.scss +231 -0
  152. package/src/components/ButtonGroup/ButtonGroup.scss +56 -0
  153. package/src/components/Card/Card.scss +99 -0
  154. package/src/components/Carousel/Carousel.scss +161 -0
  155. package/src/components/Center/Center.scss +11 -0
  156. package/src/components/ChatBubble/ChatBubble.scss +119 -0
  157. package/src/components/Checkbox/Checkbox.scss +66 -0
  158. package/src/components/Chip/Chip.scss +119 -0
  159. package/src/components/ChoiceGroup/ChoiceGroup.scss +69 -0
  160. package/src/components/Code/Code.scss +28 -0
  161. package/src/components/Collapsible/Collapsible.scss +136 -0
  162. package/src/components/ColorPicker/ColorPicker.scss +235 -0
  163. package/src/components/Combobox/Combobox.scss +83 -0
  164. package/src/components/Container/Container.scss +28 -0
  165. package/src/components/Countdown/Countdown.scss +28 -0
  166. package/src/components/DateField/DateField.scss +19 -0
  167. package/src/components/Dialog/Dialog.scss +268 -0
  168. package/src/components/Diff/Diff.scss +125 -0
  169. package/src/components/Divider/Divider.scss +22 -0
  170. package/src/components/Dock/Dock.scss +86 -0
  171. package/src/components/Field/Field.scss +38 -0
  172. package/src/components/Fieldset/Fieldset.scss +63 -0
  173. package/src/components/FileInput/FileInput.scss +66 -0
  174. package/src/components/Footer/Footer.scss +79 -0
  175. package/src/components/Grid/Grid.scss +86 -0
  176. package/src/components/Header/Header.scss +111 -0
  177. package/src/components/Heading/Heading.scss +7 -0
  178. package/src/components/Icon/Icon.scss +12 -0
  179. package/src/components/IconButton/IconButton.scss +6 -0
  180. package/src/components/Image/Image.scss +46 -0
  181. package/src/components/Indicator/Indicator.scss +48 -0
  182. package/src/components/Input/Input.scss +58 -0
  183. package/src/components/Key/Key.scss +48 -0
  184. package/src/components/Link/Link.scss +50 -0
  185. package/src/components/List/List.scss +62 -0
  186. package/src/components/Media/Media.scss +7 -0
  187. package/src/components/Menu/Menu.scss +91 -0
  188. package/src/components/Motion/Motion.scss +106 -0
  189. package/src/components/NumberField/NumberField.scss +44 -0
  190. package/src/components/OtpField/OtpField.scss +91 -0
  191. package/src/components/PageTransition/PageTransition.scss +197 -0
  192. package/src/components/Pagination/Pagination.scss +55 -0
  193. package/src/components/Popover/Popover.scss +13 -0
  194. package/src/components/Progress/Progress.scss +126 -0
  195. package/src/components/RadialProgress/RadialProgress.scss +65 -0
  196. package/src/components/Radio/Radio.scss +36 -0
  197. package/src/components/Rating/Rating.scss +121 -0
  198. package/src/components/ScrollSpy/ScrollSpy.scss +6 -0
  199. package/src/components/SegmentedControl/SegmentedControl.scss +107 -0
  200. package/src/components/Select/Select.scss +59 -0
  201. package/src/components/Sidebar/Sidebar.scss +88 -0
  202. package/src/components/Skeleton/Skeleton.scss +60 -0
  203. package/src/components/Slider/Slider.scss +96 -0
  204. package/src/components/Spacer/Spacer.scss +15 -0
  205. package/src/components/SpeedDial/SpeedDial.scss +109 -0
  206. package/src/components/Spinner/Spinner.scss +43 -0
  207. package/src/components/Stack/Stack.scss +57 -0
  208. package/src/components/Stat/Stat.scss +96 -0
  209. package/src/components/Status/Status.scss +60 -0
  210. package/src/components/Steps/Steps.scss +216 -0
  211. package/src/components/Swap/Swap.scss +62 -0
  212. package/src/components/Switch/Switch.scss +63 -0
  213. package/src/components/Table/Table.scss +183 -0
  214. package/src/components/Tabs/Tabs.scss +108 -0
  215. package/src/components/Text/Text.scss +34 -0
  216. package/src/components/TextRotate/TextRotate.scss +51 -0
  217. package/src/components/Textarea/Textarea.scss +56 -0
  218. package/src/components/ThemeProvider/ThemeProvider.scss +7 -0
  219. package/src/components/Tile/Tile.scss +23 -0
  220. package/src/components/Toast/Toast.scss +93 -0
  221. package/src/components/ToggleButton/ToggleButton.scss +23 -0
  222. package/src/components/Tooltip/Tooltip.scss +21 -0
  223. package/src/components/Type/Type.scss +35 -0
  224. package/src/components/Visibility/Visibility.scss +39 -0
  225. package/src/components/VisuallyHidden/VisuallyHidden.scss +17 -0
  226. package/src/styles/_breakpoint-vars.scss +16 -0
  227. package/src/styles/_config.scss +48 -0
  228. package/src/styles/_controls.scss +88 -0
  229. package/src/styles/_core.scss +4 -0
  230. package/src/styles/_effect.scss +51 -0
  231. package/src/styles/_floating.scss +141 -0
  232. package/src/styles/_kit.scss +1548 -0
  233. package/src/styles/_manifest.scss +670 -0
  234. package/src/styles/_mixins.scss +261 -0
  235. package/src/styles/_tones.scss +63 -0
  236. package/src/styles/_type-emit.scss +76 -0
  237. package/src/styles/_typography-vars.scss +8 -0
  238. package/src/styles/base.scss +80 -0
  239. package/src/styles/breakpoints.test.ts +73 -0
  240. package/src/styles/entryPoints.test.ts +68 -0
  241. package/src/styles/index.scss +93 -0
  242. package/src/styles/kit.test.ts +754 -0
  243. package/src/styles/public/_controls.scss +3 -0
  244. package/src/styles/public/_floating.scss +3 -0
  245. package/src/styles/public/_mixins.scss +5 -0
  246. package/src/styles/public/_tones.scss +4 -0
  247. package/themes/bevel.css +1077 -0
  248. package/themes/bevel.scss +1166 -0
  249. package/themes/candy.css +87 -0
  250. package/themes/candy.scss +32 -0
  251. package/themes/depth.css +123 -0
  252. package/themes/depth.scss +46 -0
  253. package/themes/extrude.css +219 -0
  254. package/themes/extrude.scss +255 -0
  255. package/themes/folio.css +986 -0
  256. package/themes/folio.scss +1047 -0
  257. package/themes/forest.css +87 -0
  258. package/themes/forest.scss +32 -0
  259. package/themes/gentle.css +66 -0
  260. package/themes/gentle.scss +39 -0
  261. package/themes/grape.css +87 -0
  262. package/themes/grape.scss +32 -0
  263. package/themes/greese.css +36 -0
  264. package/themes/greese.scss +21 -0
  265. package/themes/mono.css +87 -0
  266. package/themes/mono.scss +32 -0
  267. package/themes/ocean.css +87 -0
  268. package/themes/ocean.scss +32 -0
  269. package/themes/outline.css +127 -0
  270. package/themes/outline.scss +126 -0
  271. package/themes/pebble.css +65 -0
  272. package/themes/pebble.scss +69 -0
  273. package/themes/pocket.css +137 -0
  274. package/themes/pocket.scss +45 -0
  275. package/themes/ridge.css +927 -0
  276. package/themes/ridge.scss +998 -0
  277. package/themes/snappy.css +82 -0
  278. package/themes/snappy.scss +40 -0
  279. package/themes/soft.css +79 -0
  280. package/themes/soft.scss +84 -0
  281. package/themes/sunset.css +87 -0
  282. package/themes/sunset.scss +32 -0
  283. package/themes/ticket.css +960 -0
  284. package/themes/ticket.scss +1031 -0
  285. package/themes/tilt.css +148 -0
  286. package/themes/tilt.scss +169 -0
  287. package/themes/wipe.css +186 -0
  288. package/themes/wipe.scss +46 -0
@@ -0,0 +1,636 @@
1
+ import { LAYER_ORDER } from "./css.js";
2
+ import { kebab } from "./kebab.js";
3
+ import { breakpoints as defaultBreakpoints, color, scalarTokens } from "./tokens.js";
4
+ const keys = (record) => Object.keys(record);
5
+ const fromTokens = (group, names, transform = (name) => name) => Object.fromEntries(names.map((name) => [kebab(name), `var(--greese-${kebab(group)}-${transform(name)})`]));
6
+ const space = fromTokens('space', keys(scalarTokens.space), String);
7
+ const colors = {
8
+ ...Object.fromEntries(keys(color).map((role) => [kebab(role), `var(--greese-color-${kebab(role)})`])),
9
+ transparent: 'transparent',
10
+ inherit: 'inherit',
11
+ current: 'currentcolor',
12
+ };
13
+ const sizes = {
14
+ '0': '0',
15
+ '25': '25%',
16
+ '50': '50%',
17
+ '75': '75%',
18
+ full: '100%',
19
+ auto: 'auto',
20
+ fit: 'fit-content',
21
+ min: 'min-content',
22
+ max: 'max-content',
23
+ };
24
+ const alignment = ['start', 'end', 'center', 'stretch'];
25
+ const spread = {
26
+ between: 'space-between',
27
+ around: 'space-around',
28
+ evenly: 'space-evenly',
29
+ };
30
+ const same = (...names) => Object.fromEntries(names.map((name) => [name, name]));
31
+ const counts = (max, of) => Object.fromEntries(Array.from({ length: max }, (_, i) => [String(i + 1), of(i + 1)]));
32
+ /** `{ '': width style color, '0': none, '2', '4' }` for a border on some side. */
33
+ const borderOn = (side) => {
34
+ const edge = (width) => ({
35
+ [`border${side}-width`]: width,
36
+ [`border${side}-style`]: 'solid',
37
+ [`border${side}-color`]: 'var(--greese-color-border)',
38
+ });
39
+ return {
40
+ '': edge('1px'),
41
+ '0': { [`border${side}-width`]: '0' },
42
+ '2': edge('2px'),
43
+ '4': edge('4px'),
44
+ };
45
+ };
46
+ const SIDES = {
47
+ '': '',
48
+ x: '-inline',
49
+ y: '-block',
50
+ t: '-top',
51
+ b: '-bottom',
52
+ l: '-left',
53
+ r: '-right',
54
+ s: '-inline-start',
55
+ e: '-inline-end',
56
+ };
57
+ const definitions = [
58
+ // Spacing: the scale's tokens, on every side.
59
+ ...Object.entries(SIDES).flatMap(([side, suffix]) => [
60
+ {
61
+ group: 'spacing',
62
+ stem: `m${side}`,
63
+ property: `margin${suffix}`,
64
+ values: { ...space, auto: 'auto' },
65
+ responsive: true,
66
+ },
67
+ {
68
+ group: 'spacing',
69
+ stem: `p${side}`,
70
+ property: `padding${suffix}`,
71
+ values: space,
72
+ responsive: true,
73
+ },
74
+ ]),
75
+ { group: 'spacing', stem: 'gap', property: 'gap', values: space, responsive: true },
76
+ {
77
+ group: 'spacing',
78
+ stem: 'gap-x',
79
+ property: 'column-gap',
80
+ values: space,
81
+ responsive: true,
82
+ },
83
+ {
84
+ group: 'spacing',
85
+ stem: 'gap-y',
86
+ property: 'row-gap',
87
+ values: space,
88
+ responsive: true,
89
+ },
90
+ // Sizing: the logical properties, so they follow the writing direction.
91
+ {
92
+ group: 'sizing',
93
+ stem: 'w',
94
+ property: 'inline-size',
95
+ values: { ...sizes, screen: '100vw' },
96
+ responsive: true,
97
+ },
98
+ {
99
+ group: 'sizing',
100
+ stem: 'h',
101
+ property: 'block-size',
102
+ values: { ...sizes, screen: '100dvh' },
103
+ responsive: true,
104
+ },
105
+ { group: 'sizing', stem: 'min-w', property: 'min-inline-size', values: sizes },
106
+ {
107
+ group: 'sizing',
108
+ stem: 'max-w',
109
+ property: 'max-inline-size',
110
+ values: { ...sizes, none: 'none' },
111
+ },
112
+ {
113
+ group: 'sizing',
114
+ stem: 'min-h',
115
+ property: 'min-block-size',
116
+ values: { ...sizes, screen: '100dvh' },
117
+ },
118
+ {
119
+ group: 'sizing',
120
+ stem: 'max-h',
121
+ property: 'max-block-size',
122
+ values: { ...sizes, none: 'none' },
123
+ },
124
+ {
125
+ group: 'sizing',
126
+ stem: 'size',
127
+ property: ['inline-size', 'block-size'],
128
+ values: { full: '100%', auto: 'auto', fit: 'fit-content' },
129
+ },
130
+ {
131
+ group: 'sizing',
132
+ stem: 'aspect-ratio',
133
+ property: 'aspect-ratio',
134
+ values: { auto: 'auto', square: '1 / 1', video: '16 / 9', photo: '4 / 3' },
135
+ },
136
+ {
137
+ group: 'sizing',
138
+ stem: 'object-fit',
139
+ property: 'object-fit',
140
+ values: same('contain', 'cover', 'fill', 'none', 'scale-down'),
141
+ },
142
+ // Layout.
143
+ {
144
+ group: 'layout',
145
+ stem: 'display',
146
+ property: 'display',
147
+ values: same('block', 'inline', 'inline-block', 'flex', 'inline-flex', 'grid', 'inline-grid', 'flow-root', 'contents', 'none'),
148
+ responsive: true,
149
+ },
150
+ {
151
+ group: 'layout',
152
+ stem: 'pos',
153
+ property: 'position',
154
+ values: same('static', 'relative', 'absolute', 'fixed', 'sticky'),
155
+ responsive: true,
156
+ },
157
+ ...[
158
+ ['inset', 'inset'],
159
+ ['inset-x', 'inset-inline'],
160
+ ['inset-y', 'inset-block'],
161
+ ['top', 'inset-block-start'],
162
+ ['bottom', 'inset-block-end'],
163
+ ['left', 'left'],
164
+ ['right', 'right'],
165
+ ['start', 'inset-inline-start'],
166
+ ['end', 'inset-inline-end'],
167
+ ].map(([stem, property]) => ({
168
+ group: 'layout',
169
+ stem,
170
+ property,
171
+ values: { '0': '0', auto: 'auto', full: '100%', half: '50%' },
172
+ responsive: true,
173
+ })),
174
+ {
175
+ group: 'layout',
176
+ stem: 'z',
177
+ property: 'z-index',
178
+ values: {
179
+ '0': '0',
180
+ '1': '1',
181
+ auto: 'auto',
182
+ ...fromTokens('zIndex', keys(scalarTokens.zIndex)),
183
+ },
184
+ },
185
+ ...['overflow', 'overflow-x', 'overflow-y'].map((stem) => ({
186
+ group: 'layout',
187
+ stem,
188
+ property: stem,
189
+ values: same('auto', 'hidden', 'scroll', 'visible', 'clip'),
190
+ responsive: true,
191
+ })),
192
+ {
193
+ group: 'layout',
194
+ stem: 'vis',
195
+ property: 'visibility',
196
+ values: same('visible', 'hidden', 'collapse'),
197
+ responsive: true,
198
+ },
199
+ {
200
+ group: 'layout',
201
+ stem: 'box-sizing',
202
+ property: 'box-sizing',
203
+ values: same('border-box', 'content-box'),
204
+ },
205
+ {
206
+ group: 'layout',
207
+ stem: 'float',
208
+ property: 'float',
209
+ values: same('start', 'end', 'none'),
210
+ },
211
+ // Flexbox.
212
+ {
213
+ group: 'flex',
214
+ stem: 'flex-dir',
215
+ property: 'flex-direction',
216
+ values: {
217
+ row: 'row',
218
+ 'row-reverse': 'row-reverse',
219
+ col: 'column',
220
+ 'col-reverse': 'column-reverse',
221
+ },
222
+ responsive: true,
223
+ },
224
+ {
225
+ group: 'flex',
226
+ stem: 'flex-wrap',
227
+ property: 'flex-wrap',
228
+ values: same('wrap', 'nowrap', 'wrap-reverse'),
229
+ responsive: true,
230
+ },
231
+ {
232
+ group: 'flex',
233
+ stem: 'flex',
234
+ property: 'flex',
235
+ values: { '1': '1 1 0%', auto: '1 1 auto', initial: '0 1 auto', none: 'none' },
236
+ responsive: true,
237
+ },
238
+ {
239
+ group: 'flex',
240
+ stem: 'flex-grow',
241
+ property: 'flex-grow',
242
+ values: { '0': '0', '1': '1' },
243
+ responsive: true,
244
+ },
245
+ {
246
+ group: 'flex',
247
+ stem: 'flex-shrink',
248
+ property: 'flex-shrink',
249
+ values: { '0': '0', '1': '1' },
250
+ responsive: true,
251
+ },
252
+ {
253
+ group: 'flex',
254
+ stem: 'order',
255
+ property: 'order',
256
+ values: { first: '-9999', last: '9999', '0': '0', ...counts(4, String) },
257
+ responsive: true,
258
+ },
259
+ {
260
+ group: 'flex',
261
+ stem: 'justify-content',
262
+ property: 'justify-content',
263
+ values: { ...same(...alignment), ...spread },
264
+ responsive: true,
265
+ },
266
+ {
267
+ group: 'flex',
268
+ stem: 'justify-items',
269
+ property: 'justify-items',
270
+ values: same(...alignment),
271
+ responsive: true,
272
+ },
273
+ {
274
+ group: 'flex',
275
+ stem: 'justify-self',
276
+ property: 'justify-self',
277
+ values: { ...same(...alignment), auto: 'auto' },
278
+ responsive: true,
279
+ },
280
+ {
281
+ group: 'flex',
282
+ stem: 'align-items',
283
+ property: 'align-items',
284
+ values: { ...same(...alignment), baseline: 'baseline' },
285
+ responsive: true,
286
+ },
287
+ {
288
+ group: 'flex',
289
+ stem: 'align-content',
290
+ property: 'align-content',
291
+ values: { ...same(...alignment), ...spread },
292
+ responsive: true,
293
+ },
294
+ {
295
+ group: 'flex',
296
+ stem: 'align-self',
297
+ property: 'align-self',
298
+ values: { ...same(...alignment), auto: 'auto', baseline: 'baseline' },
299
+ responsive: true,
300
+ },
301
+ // Grid.
302
+ {
303
+ group: 'grid',
304
+ stem: 'grid-template-cols',
305
+ property: 'grid-template-columns',
306
+ values: {
307
+ none: 'none',
308
+ ...counts(6, (n) => `repeat(${n}, minmax(0, 1fr))`),
309
+ '12': 'repeat(12, minmax(0, 1fr))',
310
+ },
311
+ responsive: true,
312
+ },
313
+ {
314
+ group: 'grid',
315
+ stem: 'grid-template-rows',
316
+ property: 'grid-template-rows',
317
+ values: { none: 'none', ...counts(6, (n) => `repeat(${n}, minmax(0, 1fr))`) },
318
+ responsive: true,
319
+ },
320
+ {
321
+ group: 'grid',
322
+ stem: 'grid-col',
323
+ property: 'grid-column',
324
+ values: {
325
+ auto: 'auto',
326
+ full: '1 / -1',
327
+ ...Object.fromEntries(Object.entries(counts(6, (n) => `span ${n}`)).map(([n, v]) => [`span-${n}`, v])),
328
+ },
329
+ responsive: true,
330
+ },
331
+ {
332
+ group: 'grid',
333
+ stem: 'grid-row',
334
+ property: 'grid-row',
335
+ values: {
336
+ auto: 'auto',
337
+ full: '1 / -1',
338
+ ...Object.fromEntries(Object.entries(counts(6, (n) => `span ${n}`)).map(([n, v]) => [`span-${n}`, v])),
339
+ },
340
+ responsive: true,
341
+ },
342
+ {
343
+ group: 'grid',
344
+ stem: 'grid-auto-flow',
345
+ property: 'grid-auto-flow',
346
+ values: {
347
+ row: 'row',
348
+ col: 'column',
349
+ dense: 'dense',
350
+ 'row-dense': 'row dense',
351
+ 'col-dense': 'column dense',
352
+ },
353
+ },
354
+ // Text.
355
+ {
356
+ group: 'typography',
357
+ stem: 'text',
358
+ property: 'text-align',
359
+ values: same('start', 'center', 'end', 'justify', 'left', 'right'),
360
+ responsive: true,
361
+ },
362
+ {
363
+ group: 'typography',
364
+ stem: 'text-transform',
365
+ property: 'text-transform',
366
+ values: {
367
+ upper: 'uppercase',
368
+ lower: 'lowercase',
369
+ capitalize: 'capitalize',
370
+ none: 'none',
371
+ },
372
+ },
373
+ {
374
+ group: 'typography',
375
+ stem: 'text-decoration-line',
376
+ property: 'text-decoration-line',
377
+ values: same('underline', 'line-through', 'none'),
378
+ hover: true,
379
+ },
380
+ {
381
+ group: 'typography',
382
+ stem: 'text-wrap',
383
+ property: 'text-wrap',
384
+ values: same('wrap', 'nowrap', 'balance', 'pretty'),
385
+ },
386
+ {
387
+ group: 'typography',
388
+ stem: 'text-overflow',
389
+ property: 'text-overflow',
390
+ values: same('ellipsis', 'clip'),
391
+ },
392
+ {
393
+ group: 'typography',
394
+ stem: 'white-space',
395
+ property: 'white-space',
396
+ values: same('normal', 'nowrap', 'pre', 'pre-wrap', 'pre-line', 'break-spaces'),
397
+ },
398
+ {
399
+ group: 'typography',
400
+ stem: 'word-break',
401
+ property: 'word-break',
402
+ values: same('normal', 'break-all', 'keep-all'),
403
+ },
404
+ {
405
+ group: 'typography',
406
+ stem: 'overflow-wrap',
407
+ property: 'overflow-wrap',
408
+ values: same('normal', 'break-word', 'anywhere'),
409
+ },
410
+ {
411
+ group: 'typography',
412
+ stem: 'vertical-align',
413
+ property: 'vertical-align',
414
+ values: same('baseline', 'top', 'middle', 'bottom'),
415
+ },
416
+ {
417
+ group: 'typography',
418
+ stem: 'font-weight',
419
+ property: 'font-weight',
420
+ values: fromTokens('fontWeight', keys(scalarTokens.fontWeight)),
421
+ },
422
+ {
423
+ group: 'typography',
424
+ stem: 'font-style',
425
+ property: 'font-style',
426
+ values: same('italic', 'normal'),
427
+ },
428
+ {
429
+ group: 'typography',
430
+ stem: 'font-family',
431
+ property: 'font-family',
432
+ values: fromTokens('font', keys(scalarTokens.font)),
433
+ },
434
+ {
435
+ group: 'typography',
436
+ stem: 'font-variant-numeric',
437
+ property: 'font-variant-numeric',
438
+ values: { tabular: 'tabular-nums', normal: 'normal' },
439
+ },
440
+ {
441
+ group: 'typography',
442
+ stem: 'line-height',
443
+ property: 'line-height',
444
+ values: fromTokens('lineHeight', keys(scalarTokens.lineHeight)),
445
+ },
446
+ {
447
+ group: 'typography',
448
+ stem: 'list-style-type',
449
+ property: 'list-style-type',
450
+ values: same('none', 'disc', 'decimal'),
451
+ },
452
+ {
453
+ group: 'typography',
454
+ stem: 'truncate',
455
+ values: {
456
+ '': { overflow: 'hidden', 'text-overflow': 'ellipsis', 'white-space': 'nowrap' },
457
+ },
458
+ },
459
+ {
460
+ group: 'typography',
461
+ stem: 'line-clamp',
462
+ values: Object.fromEntries(Object.entries(counts(4, (n) => String(n))).map(([n]) => [
463
+ n,
464
+ {
465
+ display: '-webkit-box',
466
+ overflow: 'hidden',
467
+ '-webkit-box-orient': 'vertical',
468
+ '-webkit-line-clamp': n,
469
+ },
470
+ ])),
471
+ },
472
+ // Borders. Colors come after the sides, so a color wins over a side's default.
473
+ { group: 'border', stem: 'border', values: borderOn('') },
474
+ ...['top', 'bottom', 'left', 'right', 'inline-start', 'inline-end'].map((side) => ({
475
+ group: 'border',
476
+ stem: `border-${{ top: 't', bottom: 'b', left: 'l', right: 'r', 'inline-start': 's', 'inline-end': 'e' }[side]}`,
477
+ values: borderOn(`-${side}`),
478
+ })),
479
+ { group: 'border', stem: 'border-x', values: borderOn('-inline') },
480
+ { group: 'border', stem: 'border-y', values: borderOn('-block') },
481
+ {
482
+ group: 'border',
483
+ stem: 'border-style',
484
+ property: 'border-style',
485
+ values: same('solid', 'dashed', 'dotted', 'none'),
486
+ },
487
+ {
488
+ group: 'border',
489
+ stem: 'radius',
490
+ property: 'border-radius',
491
+ values: fromTokens('radius', keys(scalarTokens.radius)),
492
+ },
493
+ {
494
+ group: 'border',
495
+ stem: 'shadow',
496
+ property: 'box-shadow',
497
+ values: { none: 'none', ...fromTokens('shadow', keys(scalarTokens.shadow)) },
498
+ hover: true,
499
+ },
500
+ { group: 'border', stem: 'outline', property: 'outline', values: { none: 'none' } },
501
+ // Color: every color role, by name.
502
+ { group: 'color', stem: 'color', property: 'color', values: colors, hover: true },
503
+ {
504
+ group: 'color',
505
+ stem: 'bg',
506
+ property: 'background-color',
507
+ values: colors,
508
+ hover: true,
509
+ },
510
+ {
511
+ group: 'color',
512
+ stem: 'border-color',
513
+ property: 'border-color',
514
+ values: colors,
515
+ hover: true,
516
+ },
517
+ // Effects and interaction.
518
+ {
519
+ group: 'effects',
520
+ stem: 'opacity',
521
+ property: 'opacity',
522
+ values: { '0': '0', '25': '0.25', '50': '0.5', '75': '0.75', '100': '1' },
523
+ hover: true,
524
+ },
525
+ {
526
+ group: 'effects',
527
+ stem: 'cursor',
528
+ property: 'cursor',
529
+ values: same('pointer', 'default', 'not-allowed', 'grab', 'text', 'wait'),
530
+ },
531
+ {
532
+ group: 'effects',
533
+ stem: 'pointer-events',
534
+ property: 'pointer-events',
535
+ values: same('none', 'auto'),
536
+ },
537
+ {
538
+ group: 'effects',
539
+ stem: 'user-select',
540
+ property: 'user-select',
541
+ values: same('none', 'text', 'all', 'auto'),
542
+ },
543
+ {
544
+ group: 'effects',
545
+ stem: 'transition',
546
+ values: {
547
+ '': {
548
+ 'transition-property': 'color, background-color, border-color, opacity, box-shadow, translate, scale, rotate',
549
+ 'transition-duration': 'var(--greese-duration-normal)',
550
+ 'transition-timing-function': 'var(--greese-easing-standard)',
551
+ },
552
+ none: { 'transition-property': 'none' },
553
+ },
554
+ },
555
+ ];
556
+ const declarationsOf = (definition, value) => {
557
+ if (typeof value !== 'string')
558
+ return value;
559
+ const properties = [definition.property ?? []].flat();
560
+ return Object.fromEntries(properties.map((property) => [property, value]));
561
+ };
562
+ /**
563
+ * Every class in the set, in the order they are written: plain, hover, then
564
+ * each breakpoint smallest first, so a larger screen's class beats a smaller
565
+ * one's at equal specificity (mobile first).
566
+ */
567
+ export const utilityClasses = ({ prefix = '', groups, breakpoints = defaultBreakpoints, } = {}) => {
568
+ const variants = [
569
+ undefined,
570
+ 'hover',
571
+ ...Object.entries(breakpoints)
572
+ .filter(([, width]) => width > 0)
573
+ .sort(([, a], [, b]) => a - b)
574
+ .map(([key]) => key),
575
+ ];
576
+ const wanted = definitions.filter((d) => !groups || groups.includes(d.group));
577
+ return variants.flatMap((variant) => wanted
578
+ .filter((d) => variant === undefined ? true : variant === 'hover' ? d.hover : d.responsive)
579
+ .flatMap((d) => Object.entries(d.values).map(([value, setting]) => ({
580
+ name: [prefix, variant, d.stem, value].filter(Boolean).join('-'),
581
+ group: d.group,
582
+ stem: d.stem,
583
+ value,
584
+ ...(variant && { variant }),
585
+ declarations: declarationsOf(d, setting),
586
+ }))));
587
+ };
588
+ const rule = (selector, declarations, indent) => `${indent}${selector} {\n${Object.entries(declarations)
589
+ .map(([property, value]) => `${indent} ${property}: ${value};`)
590
+ .join('\n')}\n${indent}}`;
591
+ /**
592
+ * The CSS for the utilities: the layer order, then the classes in
593
+ * `@layer greese.utilities`. With `used`, only those classes (see
594
+ * `purgeUtilities`).
595
+ */
596
+ export const generateUtilities = (options = {}) => {
597
+ const { used } = options;
598
+ const breakpoints = options.breakpoints ?? defaultBreakpoints;
599
+ const classes = utilityClasses(options).filter(({ name }) => !used || used.has(name));
600
+ const blocks = [];
601
+ const wrap = (variant, body) => {
602
+ if (!body.length)
603
+ return;
604
+ if (variant === undefined)
605
+ blocks.push(...body);
606
+ else if (variant === 'hover')
607
+ blocks.push(` @media (hover: hover) {\n${body.map((b) => b.replace(/^/gm, ' ')).join('\n')}\n }`);
608
+ else
609
+ blocks.push(` @media (width >= ${breakpoints[variant]}px) {\n${body.map((b) => b.replace(/^/gm, ' ')).join('\n')}\n }`);
610
+ };
611
+ for (const variant of new Set(classes.map((c) => c.variant)))
612
+ wrap(variant, classes
613
+ .filter((c) => c.variant === variant)
614
+ .map((c) => rule(`.${c.name}${variant === 'hover' ? ':hover' : ''}`, c.declarations, ' ')));
615
+ return `/* GENERATED by @greese/ui from src/utilities.ts - do not edit. */\n${LAYER_ORDER}\n${blocks.length ? `@layer greese.utilities {\n${blocks.join('\n')}\n}\n` : ''}`;
616
+ };
617
+ /** Every token in some source text that could be a class name. */
618
+ export const scanContent = (text) => new Set(text.match(/[A-Za-z0-9_-]+/g) ?? []);
619
+ /**
620
+ * Only the utilities a project uses. A class counts as used when its name
621
+ * appears anywhere in the content, as a whole word, so `class="p-4"`,
622
+ * `className={cx('p-4')}` and a name in a data file all count; one built from
623
+ * pieces (`` `p-${n}` ``) does not, and belongs in `safelist`.
624
+ */
625
+ export const purgeUtilities = ({ content, safelist = [], ...options }) => {
626
+ const found = new Set();
627
+ for (const text of content)
628
+ for (const token of scanContent(text))
629
+ found.add(token);
630
+ const names = utilityClasses(options).map((c) => c.name);
631
+ const used = new Set(names.filter((name) => found.has(name)));
632
+ for (const name of names)
633
+ if (safelist.some((s) => (typeof s === 'string' ? s === name : s.test(name))))
634
+ used.add(name);
635
+ return generateUtilities({ ...options, used });
636
+ };
@@ -0,0 +1,18 @@
1
+ import { type PurgeOptions } from './utilities.ts';
2
+ export interface ContentOptions {
3
+ /** Glob patterns of the files that use the classes, relative to `cwd`. */
4
+ content: readonly string[];
5
+ /** Where the patterns start. @default process.cwd() */
6
+ cwd?: string;
7
+ }
8
+ /** The files the patterns match, as absolute paths. */
9
+ export declare const contentFiles: ({ content, cwd }: ContentOptions) => Promise<string[]>;
10
+ /**
11
+ * The utilities a project uses: reads the files the patterns match and keeps
12
+ * only the classes they spell out. Returns the CSS and the files it read (for
13
+ * watching).
14
+ */
15
+ export declare const purgeFiles: ({ content, cwd, ...options }: ContentOptions & Omit<PurgeOptions, "content">) => Promise<{
16
+ css: string;
17
+ files: string[];
18
+ }>;
@@ -0,0 +1,26 @@
1
+ import { glob, readFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ import { purgeUtilities } from "./utilities.js";
4
+ /** Folders never scanned: their text isn't the project's markup. */
5
+ const SKIPPED = new Set(['node_modules', '.git', 'dist', 'build', 'coverage']);
6
+ /** The files the patterns match, as absolute paths. */
7
+ export const contentFiles = async ({ content, cwd = process.cwd() }) => {
8
+ const files = new Set();
9
+ for (const pattern of content)
10
+ for await (const file of glob(pattern, {
11
+ cwd,
12
+ exclude: (entry) => SKIPPED.has(typeof entry === 'string' ? entry : entry.name),
13
+ }))
14
+ files.add(resolve(cwd, file));
15
+ return [...files].sort();
16
+ };
17
+ /**
18
+ * The utilities a project uses: reads the files the patterns match and keeps
19
+ * only the classes they spell out. Returns the CSS and the files it read (for
20
+ * watching).
21
+ */
22
+ export const purgeFiles = async ({ content, cwd, ...options }) => {
23
+ const files = await contentFiles({ content, cwd });
24
+ const texts = await Promise.all(files.map((file) => readFile(file, 'utf8')));
25
+ return { css: purgeUtilities({ ...options, content: texts }), files };
26
+ };