@jsb188/css 1.1.8 → 1.1.11

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/css/popover.css CHANGED
@@ -1,130 +1,134 @@
1
-
2
1
  /* Pop overs */
3
2
 
4
3
  .popover {
5
- position: fixed;
6
- display: flex;
7
- flex-direction: column;
8
- align-items: flex-start;
4
+ position: fixed;
5
+ display: flex;
6
+ flex-direction: column;
7
+ align-items: flex-start;
9
8
  }
10
9
 
11
10
  .popover .tooltip {
12
- display: inline-block;
13
- /* padding: .58rem .7rem; */
14
- padding: .57rem .68rem;
15
- /* box-shadow: var(--shadow-light); */
16
- box-shadow: var(--shadow);
11
+ display: inline-block;
12
+ padding: 0.58rem 0.64rem;
13
+ /* box-shadow: var(--shadow-light); */
14
+ box-shadow: var(--shadow);
17
15
  }
18
16
 
19
17
  .popover.small .tooltip:not(.w_override) {
20
- max-width: 150px;
18
+ max-width: 150px;
21
19
  }
22
20
 
23
21
  .popover.default .tooltip:not(.w_override) {
24
- max-width: 225px;
22
+ max-width: 225px;
25
23
  }
26
24
 
27
25
  /* Pop over; list */
28
26
 
29
27
  .po_list {
30
- border-radius: var(--radius-small-wrap);
28
+ border-radius: 6px;
31
29
  }
32
30
 
33
31
  .po_list .inside {
34
- padding: 5px;
35
- display: flex; flex-direction: column;
36
- justify-content: flex-start;
37
- align-items: stretch;
32
+ /* padding: 5px; */
33
+ padding: 5px;
34
+ display: flex;
35
+ flex-direction: column;
36
+ justify-content: flex-start;
37
+ align-items: stretch;
38
38
  }
39
39
 
40
40
  .po_list.bg a:hover {
41
- background-color: var(--color-darker-light);
41
+ background-color: var(--color-darker-light);
42
42
  }
43
43
 
44
44
  .po_list .av_item .av.main {
45
- box-shadow: 0 0 10px rgb(var(--color-bg));
45
+ box-shadow: 0 0 10px rgb(var(--color-bg));
46
46
  }
47
47
 
48
48
  /* Pop over; subtitle */
49
49
 
50
50
  .po_subtitle {
51
- position: sticky;
52
- top: 0; left: 0; right: 0;
53
- padding: 5px .4rem 8px;
54
- margin-bottom: .3rem;
51
+ position: sticky;
52
+ top: 0;
53
+ left: 0;
54
+ right: 0;
55
+ padding: 5px 0.4rem 8px;
56
+ margin-bottom: 0.3rem;
55
57
  }
56
58
 
57
59
  .po_subtitle_cover {
58
- position: absolute;
59
- top: -5px; left: 0; right: 0;
60
- height: 5px;
60
+ position: absolute;
61
+ top: -5px;
62
+ left: 0;
63
+ right: 0;
64
+ height: 5px;
61
65
  }
62
66
 
63
67
  /* Pop over; list item */
64
68
 
65
69
  .po_opt .saving_area {
66
- width: 24px;
67
- transform: translateX(-4px);
70
+ width: 24px;
71
+ transform: translateX(-4px);
68
72
  }
69
73
 
70
74
  .po_opt {
71
- padding: 5px 0 5px .5rem;
72
- border-radius: var(--radius-small);
75
+ padding: 5px 0 5px 0.4375rem;
76
+ border-radius: 5px;
73
77
  }
74
78
 
75
79
  .po_opt.default:first-child {
76
- margin-top: 5px;
80
+ margin-top: 5px;
77
81
  }
78
82
 
79
83
  .po_opt.default:last-child {
80
- margin-bottom: 5px;
84
+ margin-bottom: 5px;
81
85
  }
82
86
 
83
87
  /* Pop over; text item */
84
88
 
85
89
  .po_opt.text_item {
86
- padding: 5px .5rem;
87
- margin-bottom: 0;
90
+ padding: 5px 0.4375rem;
91
+ margin-bottom: 0;
88
92
  }
89
93
 
90
94
  /* Pop over; different presets for list item */
91
95
 
92
96
  .po_opt.av_item {
93
- padding-top: .5rem;
94
- padding-bottom: .5rem;
97
+ padding-top: 0.5rem;
98
+ padding-bottom: 0.5rem;
95
99
  }
96
100
 
97
101
  .po_opt.preset_small {
98
- padding: .5rem 0 .5rem .5rem;
102
+ padding: 0.5rem 0 0.5rem 0.4375rem;
99
103
  }
100
104
 
101
105
  /* Pop over; list break */
102
106
 
103
107
  .po_list_break {
104
- margin: 3px 0;
105
- border-top: solid 1px var(--color-darker-light);
108
+ margin: 4px 0;
109
+ border-top: solid 1px var(--color-darker-light);
106
110
  }
107
111
 
108
112
  /* Pop over container */
109
113
 
110
114
  .po_container {
111
- /* padding: 4px; */
112
- box-shadow: var(--shadow-light);
115
+ /* padding: 4px; */
116
+ box-shadow: var(--shadow-light);
113
117
  }
114
118
 
115
119
  .po_container .inside {
116
- display: flex;
117
- flex-direction: column;
120
+ display: flex;
121
+ flex-direction: column;
118
122
 
119
- width: 300px;
120
- min-height: 200px;
121
- /* max-height: calc(100vh - 20px); */
122
- max-height: 70vh;
123
+ width: 300px;
124
+ min-height: 150px;
125
+ /* max-height: calc(100vh - 20px); */
126
+ max-height: 70vh;
123
127
  }
124
128
 
125
129
  /* Pop over image */
126
130
 
127
131
  .pu_img {
128
- max-width: 400px;
129
- margin: 10px; /* 10px is also hard coded into the React Component */
132
+ max-width: 400px;
133
+ margin: 10px; /* 10px is also hard coded into the React Component */
130
134
  }
package/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
- "name": "@jsb188/css",
3
- "version": "1.1.8",
4
- "description": "Re-usable, base CSS styles for any app (NOTE: Bring your own variables).",
5
- "license": "ISC",
6
- "author": "jsb188",
7
- "type": "module",
8
- "exports": {
9
- "./_global.css": "./css/_global.css",
10
- "./alert.css": "./css/alert.css",
11
- "./animate.css": "./css/animate.css",
12
- "./form.css": "./css/form.css",
13
- "./layout.css": "./css/layout.css",
14
- "./list.css": "./css/list.css",
15
- "./loading.css": "./css/loading.css",
16
- "./misc.css": "./css/misc.css",
17
- "./modal.css": "./css/modal.css",
18
- "./popover.css": "./css/popover.css"
19
- },
20
- "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1"
22
- }
2
+ "name": "@jsb188/css",
3
+ "version": "1.1.11",
4
+ "description": "Re-usable, base CSS styles for any app (NOTE: Bring your own variables).",
5
+ "license": "ISC",
6
+ "author": "jsb188",
7
+ "type": "module",
8
+ "exports": {
9
+ "./_global.css": "./css/_global.css",
10
+ "./_colors.generated.css": "./css/_colors.generated.css",
11
+ "./alert.css": "./css/alert.css",
12
+ "./animate.css": "./css/animate.css",
13
+ "./form.css": "./css/form.css",
14
+ "./layout.css": "./css/layout.css",
15
+ "./loading.css": "./css/loading.css",
16
+ "./misc.css": "./css/misc.css",
17
+ "./modal.css": "./css/modal.css",
18
+ "./popover.css": "./css/popover.css"
19
+ },
20
+ "scripts": {
21
+ "gen:responsive-css": "node ./scripts/generateResponsiveCss.js",
22
+ "test": "echo \"Error: no test specified\" && exit 1"
23
+ }
23
24
  }
@@ -0,0 +1,274 @@
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 colorAltShades = [
53
+ ['fd', 'fade'],
54
+ ['lt', 'light'],
55
+ ['md', 'medium'],
56
+ ['df', 'default'],
57
+ ];
58
+
59
+ const colorRuleGroups = [
60
+ ['cl', 'color'],
61
+ ['bg', 'background-color'],
62
+ ['bd', 'border-color'],
63
+ ];
64
+
65
+ /*
66
+ Reads the source responsive utility CSS file that will be expanded into
67
+ breakpoint-scoped utility classes.
68
+ */
69
+ async function readSourceCSS() {
70
+ return readFile(responsiveSourcePath, 'utf8');
71
+ }
72
+
73
+ /*
74
+ Extracts simple single-selector utility rules from the source CSS file so each
75
+ selector can be cloned with responsive prefixes.
76
+ */
77
+ function parseUtilityRules(sourceCSS) {
78
+ const utilityRulePattern =
79
+ /(^|\n)\s*(\.[A-Za-z0-9_-][A-Za-z0-9_-]*)\s*\{([^}]*)\}/g;
80
+
81
+ return Array.from(
82
+ sourceCSS.matchAll(utilityRulePattern),
83
+ ([, , selector, declarations]) => ({
84
+ selector,
85
+ declarations: declarations.trim(),
86
+ }),
87
+ );
88
+ }
89
+
90
+ /*
91
+ Builds the generated CSS file contents by wrapping cloned utility selectors in
92
+ their corresponding custom-media breakpoints.
93
+ */
94
+ function buildGeneratedResponsiveCSS(rules) {
95
+ const sections = responsiveBreakpoints.map(([prefix, mediaName]) => {
96
+ const clonedRules = rules.map(({ selector, declarations }) => {
97
+ const className = selector.slice(1);
98
+
99
+ return ` .${prefix}\\:${className} { ${declarations} }`;
100
+ });
101
+
102
+ return `@media (${mediaName}) {\n${clonedRules.join('\n')}\n}`;
103
+ });
104
+
105
+ return [
106
+ '/* This file is auto-generated by scripts/generateResponsiveCss.js. */',
107
+ '/* Do not edit this file directly. Edit _responsive.css and regenerate. */',
108
+ '',
109
+ ...sections,
110
+ '',
111
+ ].join('\n');
112
+ }
113
+
114
+ /*
115
+ Builds one palette utility rule for a color, shade, and CSS property group.
116
+ Default background rules also set a readable foreground color.
117
+ */
118
+ function buildColorRule(
119
+ rulePrefix,
120
+ propertyName,
121
+ palette,
122
+ classSuffix,
123
+ tokenSuffix,
124
+ ) {
125
+ const shadeClassSuffix = classSuffix ? `_${classSuffix}` : '';
126
+ const className = `${rulePrefix}_${palette}${shadeClassSuffix}`;
127
+ const selectors = [`.${className}`, `.${className}_hv:hover`];
128
+ const declarations = [
129
+ `${propertyName}: var(--color-${palette}-${tokenSuffix}) !important;`,
130
+ ];
131
+
132
+ if (rulePrefix === 'bg' && tokenSuffix === 'default') {
133
+ declarations.push('color: var(--color-solid) !important;');
134
+ }
135
+
136
+ return `${selectors.join(', ')} { ${declarations.join(' ')} }`;
137
+ }
138
+
139
+ /*
140
+ Builds one alt background utility rule for a color and shade.
141
+ */
142
+ function buildAltBackgroundColorRule(palette, classSuffix, tokenSuffix) {
143
+ const className = `bg_${palette}_alt_${classSuffix}`;
144
+ const selectors = [`.${className}`, `.${className}_hv:hover`];
145
+
146
+ return `${selectors.join(', ')} { background-color: var(--color-${palette}-alt-${tokenSuffix}) !important; }`;
147
+ }
148
+
149
+ /*
150
+ Builds one alt foreground/border utility rule for a color, mapping the bare
151
+ "_alt" suffix to the muted-vivid alt-default token.
152
+ */
153
+ function buildAltColorRule(rulePrefix, propertyName, palette) {
154
+ const className = `${rulePrefix}_${palette}_alt`;
155
+ const selectors = [`.${className}`, `.${className}_hv:hover`];
156
+
157
+ return `${selectors.join(', ')} { ${propertyName}: var(--color-${palette}-alt-default) !important; }`;
158
+ }
159
+
160
+ /*
161
+ Builds one outline utility rule for a palette's default or light token,
162
+ including the equivalent alt token when requested.
163
+ */
164
+ function buildOutlineColorRule(
165
+ palette,
166
+ classSuffix,
167
+ tokenSuffix,
168
+ isAlt = false,
169
+ ) {
170
+ const altClassSuffix = isAlt ? '_alt' : '';
171
+ const shadeClassSuffix = classSuffix ? `_${classSuffix}` : '';
172
+ const altTokenSuffix = isAlt ? '-alt' : '';
173
+ const className = `ol_${palette}${altClassSuffix}${shadeClassSuffix}`;
174
+ const selectors = [
175
+ `.${className}`,
176
+ `.${className}_hv:hover`,
177
+ `.${className}_focus:focus`,
178
+ ];
179
+
180
+ return `${selectors.join(', ')} { outline: 3px solid rgb(var(--color-${palette}${altTokenSuffix}-${tokenSuffix})); outline-offset: -1px; }`;
181
+ }
182
+
183
+ /*
184
+ Builds the generated color utility CSS file contents from palette, shade, and
185
+ property rule definitions.
186
+ */
187
+ function buildGeneratedColorsCSS() {
188
+ const sections = colorRuleGroups.map(([rulePrefix, propertyName]) => {
189
+ const rules = colorPalettes.flatMap((palette) => {
190
+ const paletteRules = colorShades.map(([classSuffix, tokenSuffix]) => {
191
+ return buildColorRule(
192
+ rulePrefix,
193
+ propertyName,
194
+ palette,
195
+ classSuffix,
196
+ tokenSuffix,
197
+ );
198
+ });
199
+
200
+ if (rulePrefix === 'bg') {
201
+ return [
202
+ ...paletteRules,
203
+ ...colorAltShades.map(([classSuffix, tokenSuffix]) => {
204
+ return buildAltBackgroundColorRule(
205
+ palette,
206
+ classSuffix,
207
+ tokenSuffix,
208
+ );
209
+ }),
210
+ ];
211
+ }
212
+
213
+ return [
214
+ ...paletteRules,
215
+ buildAltColorRule(rulePrefix, propertyName, palette),
216
+ ];
217
+ });
218
+
219
+ return rules.join('\n');
220
+ });
221
+ const outlineRules = colorPalettes.flatMap((palette) => {
222
+ return [
223
+ buildOutlineColorRule(palette, '', 'default'),
224
+ buildOutlineColorRule(palette, 'lt', 'light'),
225
+ buildOutlineColorRule(palette, '', 'default', true),
226
+ buildOutlineColorRule(palette, 'lt', 'light', true),
227
+ ];
228
+ });
229
+
230
+ return [
231
+ '/* This file is auto-generated by scripts/generateResponsiveCss.js. */',
232
+ '/* Do not edit this file directly. Update the color generator definitions and regenerate. */',
233
+ '',
234
+ '/* Colors - Palette */',
235
+ '',
236
+ ...sections,
237
+ outlineRules.join('\n'),
238
+ '',
239
+ ].join('\n');
240
+ }
241
+
242
+ /*
243
+ Writes a generated CSS file to the shared CSS package so apps can import it
244
+ through the existing global stylesheet.
245
+ */
246
+ async function writeGeneratedCSS(outputPath, outputCSS) {
247
+ await mkdir(cssDir, { recursive: true });
248
+ await writeFile(outputPath, outputCSS, 'utf8');
249
+ }
250
+
251
+ /*
252
+ Generates the shared CSS files that can be derived from compact utility
253
+ definitions.
254
+ */
255
+ async function main() {
256
+ const sourceCSS = await readSourceCSS();
257
+ const rules = parseUtilityRules(sourceCSS);
258
+ const responsiveOutputCSS = buildGeneratedResponsiveCSS(rules);
259
+ const colorsOutputCSS = buildGeneratedColorsCSS();
260
+
261
+ await Promise.all([
262
+ writeGeneratedCSS(responsiveOutputPath, responsiveOutputCSS),
263
+ writeGeneratedCSS(colorsOutputPath, colorsOutputCSS),
264
+ ]);
265
+
266
+ console.log(
267
+ `Generated ${path.relative(process.cwd(), responsiveOutputPath)} from ${path.relative(process.cwd(), responsiveSourcePath)}.`,
268
+ );
269
+ console.log(
270
+ `Generated ${path.relative(process.cwd(), colorsOutputPath)} from color generator definitions.`,
271
+ );
272
+ }
273
+
274
+ await main();