@jsb188/css 1.1.8 → 1.1.10

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/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
2
  "name": "@jsb188/css",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Re-usable, base CSS styles for any app (NOTE: Bring your own variables).",
5
5
  "license": "ISC",
6
6
  "author": "jsb188",
7
7
  "type": "module",
8
8
  "exports": {
9
9
  "./_global.css": "./css/_global.css",
10
+ "./_colors.generated.css": "./css/_colors.generated.css",
10
11
  "./alert.css": "./css/alert.css",
11
12
  "./animate.css": "./css/animate.css",
12
13
  "./form.css": "./css/form.css",
13
14
  "./layout.css": "./css/layout.css",
14
- "./list.css": "./css/list.css",
15
15
  "./loading.css": "./css/loading.css",
16
16
  "./misc.css": "./css/misc.css",
17
17
  "./modal.css": "./css/modal.css",
18
18
  "./popover.css": "./css/popover.css"
19
19
  },
20
20
  "scripts": {
21
+ "gen:responsive-css": "node ./scripts/generateResponsiveCss.js",
21
22
  "test": "echo \"Error: no test specified\" && exit 1"
22
23
  }
23
24
  }
@@ -0,0 +1,188 @@
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ const cssDir = path.resolve(__dirname, '../css');
8
+ const responsiveSourcePath = path.join(cssDir, '_responsive.css');
9
+ const responsiveOutputPath = path.join(cssDir, '_responsive.generated.css');
10
+ const colorsOutputPath = path.join(cssDir, '_colors.generated.css');
11
+
12
+ const responsiveBreakpoints = [
13
+ ['landscape', '--responsive-mobile-landscape'],
14
+ ['portrait', '--responsive-mobile-portrait'],
15
+ ['phone', '--responsive-phone-wide'],
16
+ ['narrow', '--responsive-phone-narrow'],
17
+ ['tiny', '--responsive-phone-tiny'],
18
+ ];
19
+
20
+ const colorPalettes = [
21
+ 'red',
22
+ 'orange',
23
+ 'brown',
24
+ 'amber',
25
+ 'yellow',
26
+ 'lime',
27
+ 'green',
28
+ 'emerald',
29
+ 'teal',
30
+ 'cyan',
31
+ 'sky',
32
+ 'blue',
33
+ 'indigo',
34
+ 'violet',
35
+ 'purple',
36
+ 'fuchsia',
37
+ 'pink',
38
+ 'rose',
39
+ 'slate',
40
+ 'zinc',
41
+ 'stone',
42
+ ];
43
+
44
+ const colorShades = [
45
+ ['fd', 'fade'],
46
+ ['lt', 'light'],
47
+ ['md', 'medium'],
48
+ ['bd', 'bold'],
49
+ ['', 'default'],
50
+ ];
51
+
52
+ const colorRuleGroups = [
53
+ ['cl', 'color'],
54
+ ['bg', 'background-color'],
55
+ ['bd', 'border-color'],
56
+ ];
57
+
58
+ /*
59
+ Reads the source responsive utility CSS file that will be expanded into
60
+ breakpoint-scoped utility classes.
61
+ */
62
+ async function readSourceCSS() {
63
+ return readFile(responsiveSourcePath, 'utf8');
64
+ }
65
+
66
+ /*
67
+ Extracts simple single-selector utility rules from the source CSS file so each
68
+ selector can be cloned with responsive prefixes.
69
+ */
70
+ function parseUtilityRules(sourceCSS) {
71
+ const utilityRulePattern = /(^|\n)\s*(\.[A-Za-z0-9_-][A-Za-z0-9_-]*)\s*\{([^}]*)\}/g;
72
+
73
+ return Array.from(
74
+ sourceCSS.matchAll(utilityRulePattern),
75
+ ([, , selector, declarations]) => ({
76
+ selector,
77
+ declarations: declarations.trim(),
78
+ })
79
+ );
80
+ }
81
+
82
+ /*
83
+ Builds the generated CSS file contents by wrapping cloned utility selectors in
84
+ their corresponding custom-media breakpoints.
85
+ */
86
+ function buildGeneratedResponsiveCSS(rules) {
87
+ const sections = responsiveBreakpoints.map(([prefix, mediaName]) => {
88
+ const clonedRules = rules.map(({ selector, declarations }) => {
89
+ const className = selector.slice(1);
90
+
91
+ return ` .${prefix}\\:${className} { ${declarations} }`;
92
+ });
93
+
94
+ return `@media (${mediaName}) {\n${clonedRules.join('\n')}\n}`;
95
+ });
96
+
97
+ return [
98
+ '/* This file is auto-generated by scripts/generateResponsiveCss.js. */',
99
+ '/* Do not edit this file directly. Edit _responsive.css and regenerate. */',
100
+ '',
101
+ ...sections,
102
+ '',
103
+ ].join('\n');
104
+ }
105
+
106
+ /*
107
+ Builds one palette utility rule for a color, shade, and CSS property group.
108
+ Default background rules also set a readable foreground color.
109
+ */
110
+ function buildColorRule(rulePrefix, propertyName, palette, classSuffix, tokenSuffix) {
111
+ const shadeClassSuffix = classSuffix ? `_${classSuffix}` : '';
112
+ const className = `${rulePrefix}_${palette}${shadeClassSuffix}`;
113
+ const selectors = [
114
+ `.${className}`,
115
+ `.${className}_hv:hover`,
116
+ ];
117
+ const declarations = [
118
+ `${propertyName}: var(--color-${palette}-${tokenSuffix}) !important;`,
119
+ ];
120
+
121
+ if (rulePrefix === 'bg' && tokenSuffix === 'default') {
122
+ declarations.push('color: var(--color-solid) !important;');
123
+ }
124
+
125
+ return `${selectors.join(', ')} { ${declarations.join(' ')} }`;
126
+ }
127
+
128
+ /*
129
+ Builds the generated color utility CSS file contents from palette, shade, and
130
+ property rule definitions.
131
+ */
132
+ function buildGeneratedColorsCSS() {
133
+ const sections = colorRuleGroups.map(([rulePrefix, propertyName]) => {
134
+ const rules = colorPalettes.flatMap((palette) => {
135
+ return colorShades.map(([classSuffix, tokenSuffix]) => {
136
+ return buildColorRule(
137
+ rulePrefix,
138
+ propertyName,
139
+ palette,
140
+ classSuffix,
141
+ tokenSuffix
142
+ );
143
+ });
144
+ });
145
+
146
+ return rules.join('\n');
147
+ });
148
+
149
+ return [
150
+ '/* This file is auto-generated by scripts/generateResponsiveCss.js. */',
151
+ '/* Do not edit this file directly. Update the color generator definitions and regenerate. */',
152
+ '',
153
+ '/* Colors - Palette */',
154
+ '',
155
+ ...sections,
156
+ '',
157
+ ].join('\n');
158
+ }
159
+
160
+ /*
161
+ Writes a generated CSS file to the shared CSS package so apps can import it
162
+ through the existing global stylesheet.
163
+ */
164
+ async function writeGeneratedCSS(outputPath, outputCSS) {
165
+ await mkdir(cssDir, { recursive: true });
166
+ await writeFile(outputPath, outputCSS, 'utf8');
167
+ }
168
+
169
+ /*
170
+ Generates the shared CSS files that can be derived from compact utility
171
+ definitions.
172
+ */
173
+ async function main() {
174
+ const sourceCSS = await readSourceCSS();
175
+ const rules = parseUtilityRules(sourceCSS);
176
+ const responsiveOutputCSS = buildGeneratedResponsiveCSS(rules);
177
+ const colorsOutputCSS = buildGeneratedColorsCSS();
178
+
179
+ await Promise.all([
180
+ writeGeneratedCSS(responsiveOutputPath, responsiveOutputCSS),
181
+ writeGeneratedCSS(colorsOutputPath, colorsOutputCSS),
182
+ ]);
183
+
184
+ console.log(`Generated ${path.relative(process.cwd(), responsiveOutputPath)} from ${path.relative(process.cwd(), responsiveSourcePath)}.`);
185
+ console.log(`Generated ${path.relative(process.cwd(), colorsOutputPath)} from color generator definitions.`);
186
+ }
187
+
188
+ await main();
package/css/list.css DELETED
@@ -1,282 +0,0 @@
1
-
2
- /* List container */
3
-
4
- .li_cnt .li_item:last-child, /* Used for stand alone list */
5
- .li_body:last-child .li_item:last-child, .li_body.end .li_item:last-child { /* Used for virtualized lists */
6
- border-bottom: none;
7
- }
8
-
9
- /* List item */
10
-
11
- .p_li {
12
- padding: .55rem var(--rem-default);
13
- }
14
-
15
- .p_li.subtitle {
16
- padding-top: .25rem;
17
- padding-bottom: .25rem;
18
- }
19
-
20
- .li_item {
21
- position: relative;
22
- border-bottom: solid 1px rgb(var(--color-bg-alt));
23
- }
24
-
25
- .li_item .content {
26
- box-sizing: border-box;
27
- }
28
-
29
- .li_item a.content:hover,
30
- .li_item button.content:hover,
31
- .li_item div[role='button'].content:hover {
32
- z-index: 11;
33
- background-color: rgb(var(--color-bg-alt));
34
- /* background-color: var(--opaque-default); */
35
- }
36
-
37
- .li_item.selected a.content {
38
- z-index: 11;
39
- background-color: rgb(var(--color-bg-alt));
40
- box-shadow: inset 0 0 0 1px rgb(var(--color-primary));
41
- }
42
-
43
- /* List item; options button */
44
-
45
- .li_opts_btn {
46
- position: relative; z-index: 2;
47
- display: none;
48
- background-color: rgb(var(--color-bg));
49
- }
50
-
51
- .li_opts_btn:hover {
52
- background-color: rgb(var(--color-bg-alt));
53
- }
54
-
55
- .li_opts_btn:active {
56
- background-color: rgb(var(--color-bg-active));
57
- transform: translateY(1px);
58
- }
59
-
60
- .li_item:hover .li_opts_btn, .li_opts_btn.active {
61
- display: flex;
62
- margin: 0 -4px 0 4px;
63
- }
64
-
65
- /* Unread dot & right icon */
66
-
67
- .li_right {
68
- position: absolute; z-index: 1;
69
- }
70
-
71
- .li_item.default .li_right {
72
- top: 50%;
73
- right: .75rem;
74
- transform: translateY(-50%);
75
- background-color: rgb(var(--color-bg));
76
- box-shadow: 0 0 10px 5px rgb(var(--color-bg));
77
- }
78
-
79
- .li_item.em .li_right {
80
- top: -9px;
81
- right: -10px;
82
- }
83
-
84
- .li_item.default:hover .li_right,
85
- .li_item.default.selected .li_right {
86
- background-color: rgb(var(--color-bg-alt));
87
- box-shadow: 0 0 10px 5px rgb(var(--color-bg-alt));
88
- }
89
-
90
- .unread_dot {
91
- width: .5rem;
92
- height: .5rem;
93
- border-radius: 50%;
94
- margin: 0 4px;
95
- }
96
-
97
- /* List group with an outline */
98
-
99
- .li_group {
100
- position: relative;
101
- margin: 10px 0;
102
- }
103
-
104
- .li_group .li_item {
105
- border-bottom: none;
106
- }
107
-
108
- .li_group .li_item a.content:hover,
109
- .li_group .li_item.selected a.content {
110
- background-color: rgb(var(--color-bg-active));
111
- }
112
-
113
- .li_group .li_item a.content:hover:before {
114
- content: '';
115
- position: absolute;
116
- top: 0; bottom: 0; right: 0;
117
- width: 1px;
118
- background-color: rgb(var(--color-bg-medium));
119
- }
120
-
121
- .li_group .li_item:first-child a.content:hover:after {
122
- content: '';
123
- position: absolute;
124
- top: 0; left: 0; right: 0;
125
- height: 1px;
126
- background-color: rgb(var(--color-bg-medium));
127
- }
128
-
129
- .li_group .li_item:last-child a.content:hover:after {
130
- content: '';
131
- position: absolute;
132
- bottom: 0; left: 0; right: 0;
133
- height: 1px;
134
- background-color: rgb(var(--color-bg-medium));
135
- }
136
-
137
- .li_group .li_item.selected a.content:hover:before,
138
- .li_group .li_item.selected:first-child a.content:hover:after,
139
- .li_group .li_item.selected:last-child a.content:hover:after {
140
- background-color: rgb(var(--color-primary));
141
- }
142
-
143
- .li_group:first-child {
144
- margin-top: 0;
145
- }
146
-
147
- .li_group:before {
148
- content: ' ';
149
- position: absolute;
150
- top: 0;
151
- left: 0;
152
- right: 0;
153
- bottom: 0;
154
- box-shadow: inset 0 0 0 1px rgb(var(--color-bg-medium));
155
- }
156
-
157
- .li_group_line {
158
- position: absolute;
159
- bottom: -11px;
160
- /* left: 100%; right: -74px; */
161
- left: 334px; right: -63px;
162
- height: 10px;
163
- background-color: rgb(var(--color-bg-alt));
164
- }
165
-
166
- /* Preset: em */
167
-
168
- .li_item.em {
169
- display: flex;
170
- flex-direction: column;
171
- margin: 0 var(--rem-default) 2px;
172
- border: none;
173
- }
174
-
175
- .li_item.em:first-child .content, .li_item.em.first .content,
176
- .ln_item.em:first-child, .ln_item.em.first {
177
- margin-top: var(--rem-small);
178
- border-top-left-radius: var(--radius-small);
179
- border-top-right-radius: var(--radius-small);
180
- }
181
-
182
- .li_item.em:last-child .content, .li_item.em.last .content,
183
- .ln_item.em:last-child, .ln_item.em.last {
184
- margin-bottom: var(--rem-small);
185
- border-bottom-left-radius: var(--radius-small);
186
- border-bottom-right-radius: var(--radius-small);
187
- }
188
-
189
- .li_item.em .content {
190
- padding: var(--rem-small) var(--rem-default) var(--rem-small) var(--rem-small);
191
- }
192
-
193
- .li_item.em .content,
194
- .ln_item.em {
195
- background-color: rgb(var(--color-bg-alt));
196
- }
197
-
198
- .li_item.em .content .mock_av, .li_item.em .content .mock:before {
199
- background-color: var(--color-darker-light);
200
- }
201
-
202
- .li_item.em a.content:hover,
203
- .li_item.em button.content:hover,
204
- .li_item.em [role='button'].content:hover,
205
- .ln_item.em.link:hover {
206
- background-color: rgb(var(--color-bg-active));
207
- }
208
-
209
- /* Line list item */
210
-
211
- .ln_item.normal:not(.mb_xs):not(.mb_sm) {
212
- margin-bottom: .4rem;
213
- }
214
-
215
- .ln_item.normal:last-child {
216
- margin-bottom: 0;
217
- }
218
-
219
- /* Line list item: .em preset */
220
-
221
- .ln_item.em {
222
- padding: .5rem 0;
223
- margin: 0 var(--rem-default) 2px;
224
- }
225
-
226
- .ln_item.em .av_w_df {
227
- margin: 0 var(--rem-small) 0 var(--rem-default);
228
- }
229
-
230
- /* Line item; subtitle */
231
-
232
- .ln_item.subtitle {
233
- min-height: 32px;
234
- }
235
-
236
- /* Thumbnail item */
237
-
238
- .th_item {
239
- position: relative;
240
- padding: 100% 0 0;
241
- }
242
-
243
- /* Subtitle */
244
-
245
- .subtitle.p_li .icon_cnt {
246
- width: 2.3rem;
247
- margin-right: .2rem;
248
- }
249
-
250
- /* Preset: small & tiny */
251
-
252
- .li_item.small, .li_item.tiny, .li_item.xtiny {
253
- border-bottom: none;
254
- }
255
-
256
- .li_item.small .p_li, .li_item.tiny .p_li, .li_item.xtiny .p_li {
257
- padding: .25rem 7px;
258
- margin: 0 7px;
259
- border-radius: var(--radius-small);
260
- }
261
-
262
- .li_faded .li_item .li_item_body, .li_faded .li_item .av.main {
263
- opacity: .5;
264
- }
265
-
266
- /* Sticky footer */
267
-
268
- .btn_area {
269
- padding: 1rem 0 0;
270
- }
271
-
272
- .btn_area.sticky {
273
- position: sticky;
274
- /* Need the -1px for DOM scroll behavior cover */
275
- top: 0; left: 0; right: 0;
276
- bottom: -1px;
277
-
278
- padding: 1rem 10px 0;
279
- margin-left: -10px;
280
- margin-right: -10px;
281
- background: transparent linear-gradient(180deg, transparent 0%, rgb(var(--color-bg)) 50%, rgb(var(--color-bg)) 100%);
282
- }