@digigov/css 2.0.0-36b707c1 → 2.0.0-44e7106a
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/dist/base/index.css +1 -1
- package/dist/base.js +1 -1
- package/dist/components.js +1 -1
- package/dist/digigov.css +3 -3
- package/dist/utilities/index.css +1 -1
- package/dist/utilities.js +1 -1
- package/index.js +99 -69
- package/package.json +13 -13
- package/postcss.config.js +4 -4
- package/src/base/index.css +1 -0
- package/src/base/index.native.css +0 -0
- package/src/base/postcss.config.js +11 -10
- package/src/base/tailwind.config.js +4 -11
- package/src/components/accordion.common.css +29 -0
- package/src/components/accordion.css +9 -7
- package/src/components/accordion.native.css +27 -0
- package/src/components/autocomplete.css +1 -3
- package/src/components/blockquote.common.css +11 -11
- package/src/components/blockquote.css +6 -6
- package/src/components/blockquote.native.css +4 -1
- package/src/components/breadcrumbs.css +1 -1
- package/src/components/button.css +1 -1
- package/src/components/button.native.css +6 -7
- package/src/components/card.common.css +30 -30
- package/src/components/card.css +1 -1
- package/src/components/checkboxes.common.css +13 -13
- package/src/components/checkboxes.native.css +2 -3
- package/src/components/chip.common.css +19 -0
- package/src/components/chip.css +5 -4
- package/src/components/chip.native.css +15 -0
- package/src/components/code.css +7 -7
- package/src/components/copy-to-clipboard.css +1 -1
- package/src/components/copy-to-clipboard.native.css +2 -4
- package/src/components/details.common.css +23 -23
- package/src/components/details.native.css +8 -0
- package/src/components/drawer.css +20 -3
- package/src/components/dropdown.common.css +19 -19
- package/src/components/dropdown.native.css +10 -11
- package/src/components/filter.css +71 -22
- package/src/components/footer.css +8 -7
- package/src/components/form.common.css +75 -76
- package/src/components/form.css +8 -4
- package/src/components/form.native.css +102 -53
- package/src/components/header.common.css +32 -33
- package/src/components/header.css +9 -13
- package/src/components/header.native.css +5 -10
- package/src/components/kitchensink.css +2 -2
- package/src/components/layout.common.css +2 -2
- package/src/components/layout.css +1 -1
- package/src/components/layout.native.css +1 -0
- package/src/components/loader.common.css +7 -0
- package/src/components/loader.css +3 -1
- package/src/components/loader.native.css +5 -0
- package/src/components/modal.common.css +3 -4
- package/src/components/modal.css +14 -10
- package/src/components/modal.native.css +5 -5
- package/src/components/nav.common.css +18 -18
- package/src/components/nav.native.css +4 -6
- package/src/components/notification-banner.common.css +2 -2
- package/src/components/notification-banner.css +20 -2
- package/src/components/pagination.css +19 -3
- package/src/components/panel.common.css +26 -26
- package/src/components/panel.native.css +8 -2
- package/src/components/phase-banner.native.css +0 -1
- package/src/components/postcss.config.js +7 -6
- package/src/components/radios.common.css +1 -1
- package/src/components/radios.native.css +2 -3
- package/src/components/skeleton.common.css +20 -0
- package/src/components/skeleton.css +7 -10
- package/src/components/skeleton.native.css +53 -0
- package/src/components/stack.common.css +67 -0
- package/src/components/stack.css +23 -21
- package/src/components/stack.native.css +68 -0
- package/src/components/summary-list.common.css +5 -2
- package/src/components/summary-list.css +10 -7
- package/src/components/summary-list.native.css +5 -1
- package/src/components/svg-icons.common.css +1 -1
- package/src/components/svg-icons.native.css +2 -3
- package/src/components/table.css +44 -11
- package/src/components/test.css +2 -2
- package/src/components/typography.common.css +2 -7
- package/src/components/typography.css +20 -18
- package/src/components/typography.native.css +31 -0
- package/src/components/warning-text.common.css +1 -1
- package/src/components/warning-text.css +8 -6
- package/src/index.native.css +5 -0
- package/src/utilities/gap.css +1 -1
- package/src/utilities/index.css +6 -6
- package/src/utilities/index.native.css +6 -6
- package/src/utilities/layout.css +1 -1
- package/src/utilities/layout.native.css +1 -1
- package/src/utilities/margin.css +35 -35
- package/src/utilities/padding.css +1 -1
- package/src/utilities/postcss.config.js +7 -6
- package/src/utilities/print.css +1 -1
- package/src/utilities/utilities.css +3 -4
- package/tailwind.config.js +102 -106
- package/theming.js +121 -0
- package/defaultTheme/accordion.json +0 -16
- package/defaultTheme/back-to-top.json +0 -27
- package/defaultTheme/brandConfig.json +0 -147
- package/defaultTheme/breadcrumbs.json +0 -8
- package/defaultTheme/button.json +0 -94
- package/defaultTheme/card.json +0 -23
- package/defaultTheme/form.json +0 -132
- package/defaultTheme/globals.json +0 -81
- package/defaultTheme/index.js +0 -27
- package/defaultTheme/layout.json +0 -55
- package/defaultTheme/misc.json +0 -68
- package/defaultTheme/panel.json +0 -48
- package/defaultTheme/phase-banner.json +0 -8
- package/defaultTheme/radios.json +0 -8
- package/defaultTheme/summary-list.json +0 -8
- package/defaultTheme/typography.json +0 -295
- package/themes.plugin.js +0 -148
package/src/utilities/margin.css
CHANGED
|
@@ -758,7 +758,7 @@
|
|
|
758
758
|
@apply m-5;
|
|
759
759
|
}
|
|
760
760
|
.ds-m-xs-6 {
|
|
761
|
-
@apply m-6
|
|
761
|
+
@apply m-6;
|
|
762
762
|
}
|
|
763
763
|
.ds-m-xs-7 {
|
|
764
764
|
@apply m-7;
|
|
@@ -3278,106 +3278,106 @@
|
|
|
3278
3278
|
@apply xl:ml-96 !important;
|
|
3279
3279
|
}
|
|
3280
3280
|
.ds-mx-xs-0 {
|
|
3281
|
-
@apply mx-0
|
|
3281
|
+
@apply mx-0;
|
|
3282
3282
|
}
|
|
3283
3283
|
.ds-mx-xs-0\.5 {
|
|
3284
|
-
@apply mx-0.5
|
|
3284
|
+
@apply mx-0.5;
|
|
3285
3285
|
}
|
|
3286
3286
|
.ds-mx-xs-1 {
|
|
3287
|
-
@apply mx-1
|
|
3287
|
+
@apply mx-1;
|
|
3288
3288
|
}
|
|
3289
3289
|
.ds-mx-xs-1\.5 {
|
|
3290
|
-
@apply mx-1.5
|
|
3290
|
+
@apply mx-1.5;
|
|
3291
3291
|
}
|
|
3292
3292
|
.ds-mx-xs-2 {
|
|
3293
|
-
@apply mx-2
|
|
3293
|
+
@apply mx-2;
|
|
3294
3294
|
}
|
|
3295
3295
|
.ds-mx-xs-2\.5 {
|
|
3296
|
-
@apply mx-2.5
|
|
3296
|
+
@apply mx-2.5;
|
|
3297
3297
|
}
|
|
3298
3298
|
.ds-mx-xs-3 {
|
|
3299
|
-
@apply mx-3
|
|
3299
|
+
@apply mx-3;
|
|
3300
3300
|
}
|
|
3301
3301
|
.ds-mx-xs-3\.5 {
|
|
3302
|
-
@apply mx-3.5
|
|
3302
|
+
@apply mx-3.5;
|
|
3303
3303
|
}
|
|
3304
3304
|
.ds-mx-xs-4 {
|
|
3305
|
-
@apply mx-4
|
|
3305
|
+
@apply mx-4;
|
|
3306
3306
|
}
|
|
3307
3307
|
.ds-mx-xs-5 {
|
|
3308
|
-
@apply mx-5
|
|
3308
|
+
@apply mx-5;
|
|
3309
3309
|
}
|
|
3310
3310
|
.ds-mx-xs-6 {
|
|
3311
|
-
@apply mx-6
|
|
3311
|
+
@apply mx-6;
|
|
3312
3312
|
}
|
|
3313
3313
|
.ds-mx-xs-7 {
|
|
3314
|
-
@apply mx-7
|
|
3314
|
+
@apply mx-7;
|
|
3315
3315
|
}
|
|
3316
3316
|
.ds-mx-xs-8 {
|
|
3317
|
-
@apply mx-8
|
|
3317
|
+
@apply mx-8;
|
|
3318
3318
|
}
|
|
3319
3319
|
.ds-mx-xs-9 {
|
|
3320
|
-
@apply mx-9
|
|
3320
|
+
@apply mx-9;
|
|
3321
3321
|
}
|
|
3322
3322
|
.ds-mx-xs-10 {
|
|
3323
|
-
@apply mx-10
|
|
3323
|
+
@apply mx-10;
|
|
3324
3324
|
}
|
|
3325
3325
|
.ds-mx-xs-11 {
|
|
3326
|
-
@apply mx-11
|
|
3326
|
+
@apply mx-11;
|
|
3327
3327
|
}
|
|
3328
3328
|
.ds-mx-xs-12 {
|
|
3329
|
-
@apply mx-12
|
|
3329
|
+
@apply mx-12;
|
|
3330
3330
|
}
|
|
3331
3331
|
.ds-mx-xs-14 {
|
|
3332
|
-
@apply mx-14
|
|
3332
|
+
@apply mx-14;
|
|
3333
3333
|
}
|
|
3334
3334
|
.ds-mx-xs-16 {
|
|
3335
|
-
@apply mx-16
|
|
3335
|
+
@apply mx-16;
|
|
3336
3336
|
}
|
|
3337
3337
|
.ds-mx-xs-20 {
|
|
3338
|
-
@apply mx-20
|
|
3338
|
+
@apply mx-20;
|
|
3339
3339
|
}
|
|
3340
3340
|
.ds-mx-xs-24 {
|
|
3341
|
-
@apply mx-24
|
|
3341
|
+
@apply mx-24;
|
|
3342
3342
|
}
|
|
3343
3343
|
.ds-mx-xs-28 {
|
|
3344
|
-
@apply mx-28
|
|
3344
|
+
@apply mx-28;
|
|
3345
3345
|
}
|
|
3346
3346
|
.ds-mx-xs-32 {
|
|
3347
|
-
@apply mx-32
|
|
3347
|
+
@apply mx-32;
|
|
3348
3348
|
}
|
|
3349
3349
|
.ds-mx-xs-36 {
|
|
3350
|
-
@apply mx-36
|
|
3350
|
+
@apply mx-36;
|
|
3351
3351
|
}
|
|
3352
3352
|
.ds-mx-xs-40 {
|
|
3353
|
-
@apply mx-40
|
|
3353
|
+
@apply mx-40;
|
|
3354
3354
|
}
|
|
3355
3355
|
.ds-mx-xs-44 {
|
|
3356
|
-
@apply mx-44
|
|
3356
|
+
@apply mx-44;
|
|
3357
3357
|
}
|
|
3358
3358
|
.ds-mx-xs-48 {
|
|
3359
|
-
@apply mx-48
|
|
3359
|
+
@apply mx-48;
|
|
3360
3360
|
}
|
|
3361
3361
|
.ds-mx-xs-52 {
|
|
3362
|
-
@apply mx-52
|
|
3362
|
+
@apply mx-52;
|
|
3363
3363
|
}
|
|
3364
3364
|
.ds-mx-xs-56 {
|
|
3365
|
-
@apply mx-56
|
|
3365
|
+
@apply mx-56;
|
|
3366
3366
|
}
|
|
3367
3367
|
.ds-mx-xs-60 {
|
|
3368
|
-
@apply mx-60
|
|
3368
|
+
@apply mx-60;
|
|
3369
3369
|
}
|
|
3370
3370
|
.ds-mx-xs-64 {
|
|
3371
|
-
@apply mx-64
|
|
3371
|
+
@apply mx-64;
|
|
3372
3372
|
}
|
|
3373
3373
|
.ds-mx-xs-72 {
|
|
3374
|
-
@apply mx-72
|
|
3374
|
+
@apply mx-72;
|
|
3375
3375
|
}
|
|
3376
3376
|
.ds-mx-xs-80 {
|
|
3377
|
-
@apply mx-80
|
|
3377
|
+
@apply mx-80;
|
|
3378
3378
|
}
|
|
3379
3379
|
.ds-mx-xs-96 {
|
|
3380
|
-
@apply mx-96
|
|
3380
|
+
@apply mx-96;
|
|
3381
3381
|
}
|
|
3382
3382
|
.ds-mx-sm-0 {
|
|
3383
3383
|
@apply sm:mx-0 !important;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/** @type {import('postcss-load-config').Config} */
|
|
2
2
|
const config = {
|
|
3
3
|
plugins: [
|
|
4
|
-
require(
|
|
5
|
-
require(
|
|
6
|
-
require(
|
|
7
|
-
require(
|
|
8
|
-
require(
|
|
4
|
+
require('postcss-import'),
|
|
5
|
+
require('tailwindcss/nesting'),
|
|
6
|
+
require('tailwindcss')('./src/utilities/tailwind.config.js'),
|
|
7
|
+
require('autoprefixer'),
|
|
8
|
+
require('postcss-sort-media-queries'),
|
|
9
|
+
require('cssnano')({
|
|
9
10
|
preset: [
|
|
10
|
-
|
|
11
|
+
'default',
|
|
11
12
|
{
|
|
12
13
|
mergeRules: false,
|
|
13
14
|
},
|
package/src/utilities/print.css
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
@import
|
|
2
|
-
@import
|
|
3
|
-
@import
|
|
4
|
-
|
|
1
|
+
@import './gap.css';
|
|
2
|
+
@import './margin.css';
|
|
3
|
+
@import './padding.css';
|
package/tailwind.config.js
CHANGED
|
@@ -1,72 +1,70 @@
|
|
|
1
|
-
const
|
|
2
|
-
const defaultTheme = require("tailwindcss/defaultTheme");
|
|
3
|
-
const themesPlugin = require("./themes.plugin");
|
|
1
|
+
const defaultTheme = require('tailwindcss/defaultTheme');
|
|
4
2
|
|
|
5
3
|
const allColors = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
4
|
+
'transparent',
|
|
5
|
+
'current',
|
|
6
|
+
'primary',
|
|
7
|
+
'primary-100',
|
|
8
|
+
'primary-200',
|
|
9
|
+
'primary-300',
|
|
10
|
+
'secondary',
|
|
11
|
+
'secondary-100',
|
|
12
|
+
'secondary-200',
|
|
13
|
+
'secondary-300',
|
|
14
|
+
'tertiary',
|
|
15
|
+
'tertiary-100',
|
|
16
|
+
'tertiary-200',
|
|
17
|
+
'tertiary-300',
|
|
18
|
+
'accent',
|
|
19
|
+
'accent-focus',
|
|
20
|
+
'accent-content',
|
|
21
|
+
'base-100',
|
|
22
|
+
'base-200',
|
|
23
|
+
'base-300',
|
|
24
|
+
'base-400',
|
|
25
|
+
'base-500',
|
|
26
|
+
'base-600',
|
|
27
|
+
'base-700',
|
|
28
|
+
'base-800',
|
|
29
|
+
'base-900',
|
|
30
|
+
'base-1000',
|
|
31
|
+
'base-11000',
|
|
32
|
+
'base-content',
|
|
33
|
+
'base-content-secondary',
|
|
34
|
+
'base-content-invert',
|
|
35
|
+
'info',
|
|
36
|
+
'info-hover',
|
|
37
|
+
'success',
|
|
38
|
+
'success-hover',
|
|
39
|
+
'warning',
|
|
40
|
+
'error',
|
|
41
|
+
'error-hover',
|
|
42
|
+
'error-text',
|
|
43
|
+
'focus',
|
|
44
|
+
'link',
|
|
45
|
+
'link-hover',
|
|
46
|
+
'link-visited',
|
|
47
|
+
'link-active',
|
|
48
|
+
'white',
|
|
49
|
+
'gray-100',
|
|
50
|
+
'gray-200',
|
|
51
|
+
'gray-300',
|
|
52
|
+
'gray-400',
|
|
53
|
+
'gray-500',
|
|
54
|
+
'gray-600',
|
|
55
|
+
'gray-700',
|
|
56
|
+
'gray-800',
|
|
57
|
+
'gray-900',
|
|
58
|
+
'gray-1000',
|
|
59
|
+
'gray-1100',
|
|
60
|
+
'gray-1200',
|
|
61
|
+
'black',
|
|
62
|
+
'shadow200',
|
|
63
|
+
'shadow600',
|
|
66
64
|
];
|
|
67
65
|
|
|
68
66
|
const colorVariables = allColors.reduce((colorVars, color) => {
|
|
69
|
-
if ([
|
|
67
|
+
if (['transparent', 'currentColor'].includes(color)) {
|
|
70
68
|
colorVars[color] = color;
|
|
71
69
|
} else {
|
|
72
70
|
colorVars[color] = ({ opacityVariable, opacityValue }) => {
|
|
@@ -81,94 +79,92 @@ const colorVariables = allColors.reduce((colorVars, color) => {
|
|
|
81
79
|
}
|
|
82
80
|
return colorVars;
|
|
83
81
|
}, {});
|
|
82
|
+
|
|
84
83
|
const screens = require('./screens.json');
|
|
85
84
|
const screensWithPixels = Object.keys(screens).reduce((screenVars, screen) => {
|
|
86
85
|
screenVars[screen] = `${screens[screen]}px`;
|
|
87
86
|
return screenVars;
|
|
88
|
-
},{})
|
|
87
|
+
}, {});
|
|
88
|
+
|
|
89
89
|
/** @type {import('tailwindcss').Config} */
|
|
90
90
|
module.exports = {
|
|
91
|
-
darkMode:
|
|
91
|
+
darkMode: 'class',
|
|
92
92
|
content: {
|
|
93
|
-
files: [
|
|
93
|
+
files: ['./src/*.css'],
|
|
94
94
|
relative: true,
|
|
95
95
|
},
|
|
96
|
-
themes: {
|
|
97
|
-
light: require.resolve("./defaultTheme"),
|
|
98
|
-
},
|
|
99
|
-
defaultTheme: "light",
|
|
100
96
|
theme: {
|
|
101
97
|
colors: colorVariables,
|
|
98
|
+
screens: {
|
|
99
|
+
...screensWithPixels,
|
|
100
|
+
print: { raw: 'print' },
|
|
101
|
+
xsOnly: { min: '0px', max: '639.98px' },
|
|
102
|
+
smOnly: { min: '640px', max: '767.98px' },
|
|
103
|
+
mdOnly: { min: '768px', max: '1023.98px' },
|
|
104
|
+
lgOnly: { min: '1024px', max: '1279.98px' },
|
|
105
|
+
xlOnly: { min: '1280px', max: '1535.98px' },
|
|
106
|
+
},
|
|
102
107
|
container: {
|
|
103
108
|
center: true,
|
|
104
109
|
},
|
|
105
110
|
fontSize: {
|
|
106
111
|
...defaultTheme.fontSize,
|
|
107
|
-
lg:
|
|
108
|
-
},
|
|
109
|
-
screens: {
|
|
110
|
-
...screensWithPixels,
|
|
111
|
-
print: { raw: "print" },
|
|
112
|
-
xsOnly: { min: "0px", max: "639.98px" },
|
|
113
|
-
smOnly: { min: "640px", max: "767.98px" },
|
|
114
|
-
mdOnly: { min: "768px", max: "1023.98px" },
|
|
115
|
-
lgOnly: { min: "1024px", max: "1279.98px" },
|
|
116
|
-
xlOnly: { min: "1280px", max: "1535.98px" },
|
|
112
|
+
lg: '1.1875rem',
|
|
117
113
|
},
|
|
118
114
|
fontFamily: {
|
|
119
|
-
sans: [
|
|
115
|
+
sans: ['Roboto', ...defaultTheme.fontFamily.sans],
|
|
120
116
|
},
|
|
121
117
|
extend: {
|
|
122
118
|
height: {
|
|
123
|
-
fit:
|
|
119
|
+
fit: 'fit-content',
|
|
124
120
|
},
|
|
125
121
|
width: {
|
|
126
|
-
fit:
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
fit: 'fit-content',
|
|
123
|
+
'2xl': '42rem',
|
|
124
|
+
'4xl': '56rem',
|
|
129
125
|
},
|
|
130
126
|
maxWidth: {
|
|
131
|
-
fit:
|
|
127
|
+
fit: 'fit-content',
|
|
132
128
|
},
|
|
133
129
|
minWidth: {
|
|
134
|
-
4:
|
|
135
|
-
10:
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
4: '1rem',
|
|
131
|
+
10: '2.5rem',
|
|
132
|
+
12: '3rem',
|
|
133
|
+
32: '8rem',
|
|
134
|
+
52: '13rem',
|
|
138
135
|
},
|
|
139
136
|
minHeight: {
|
|
140
|
-
4:
|
|
141
|
-
6:
|
|
142
|
-
8:
|
|
143
|
-
10:
|
|
144
|
-
12:
|
|
145
|
-
14:
|
|
137
|
+
4: '1rem',
|
|
138
|
+
6: '1.5rem',
|
|
139
|
+
8: '2rem',
|
|
140
|
+
10: '2.5rem',
|
|
141
|
+
12: '3rem',
|
|
142
|
+
14: '3.5rem',
|
|
146
143
|
},
|
|
147
144
|
borderWidth: {
|
|
148
|
-
3:
|
|
149
|
-
5:
|
|
150
|
-
6:
|
|
145
|
+
3: '3px',
|
|
146
|
+
5: '5px',
|
|
147
|
+
6: '6px',
|
|
151
148
|
},
|
|
152
149
|
flexGrow: {
|
|
153
|
-
2:
|
|
150
|
+
2: '2',
|
|
154
151
|
},
|
|
155
152
|
zIndex: {
|
|
156
|
-
|
|
153
|
+
'/1': -1,
|
|
157
154
|
1: 1,
|
|
158
155
|
2: 2,
|
|
159
156
|
3: 3,
|
|
160
157
|
5: 5,
|
|
161
158
|
},
|
|
162
159
|
opacity: {
|
|
163
|
-
85:
|
|
160
|
+
85: '0.85',
|
|
164
161
|
},
|
|
165
162
|
margin: {
|
|
166
|
-
15:
|
|
163
|
+
15: '3.75rem',
|
|
167
164
|
},
|
|
168
165
|
boxShadow: {
|
|
169
|
-
thick:
|
|
166
|
+
thick: '0 0 30px rgba(0, 0, 0, 0.6)',
|
|
170
167
|
},
|
|
171
168
|
},
|
|
172
169
|
},
|
|
173
|
-
plugins: [plugin(themesPlugin)],
|
|
174
170
|
};
|
package/theming.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const postcss = require('postcss');
|
|
4
|
+
const postcssrc = require('postcss-load-config');
|
|
5
|
+
const postcssJs = require('postcss-js');
|
|
6
|
+
|
|
7
|
+
const DEFAULT_THEME = '@digigov/theme-default';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Load custom theme CSS as base styles.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} [options={}]
|
|
13
|
+
* @param {string} [options.theme] - Custom theme package name or file path.
|
|
14
|
+
* @param {boolean} [options.eject] - Whether to ignore the default Digigov CSS base styles.
|
|
15
|
+
* @param {boolean} [options.debug] - Whether to log debug information.
|
|
16
|
+
* @returns {object} - The base styles as CSS-in-JS object.
|
|
17
|
+
*/
|
|
18
|
+
function getThemeBaseStyle(options = {}) {
|
|
19
|
+
const { theme: userTheme, eject, debug } = options;
|
|
20
|
+
|
|
21
|
+
if (!userTheme) {
|
|
22
|
+
// do not load any theme
|
|
23
|
+
if (eject) return;
|
|
24
|
+
// load default theme
|
|
25
|
+
const css = loadCss(debug, DEFAULT_THEME);
|
|
26
|
+
return processCss(css);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// only load user theme
|
|
30
|
+
if (eject) {
|
|
31
|
+
const css = loadCss(debug, userTheme);
|
|
32
|
+
return processCss(css);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// load both default and user theme
|
|
36
|
+
const css = loadCss(debug, DEFAULT_THEME, userTheme);
|
|
37
|
+
return processCss(css);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if the given theme is a local file or package.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} userTheme - File path or package name.
|
|
44
|
+
* @returns {boolean} - Whether the theme is a local file.
|
|
45
|
+
*/
|
|
46
|
+
function isLocalTheme(userTheme) {
|
|
47
|
+
return (
|
|
48
|
+
userTheme.startsWith('./') ||
|
|
49
|
+
userTheme.startsWith('../') ||
|
|
50
|
+
path.isAbsolute(userTheme)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Load CSS from given package or file path.
|
|
56
|
+
*
|
|
57
|
+
* @param {boolean} debug - Whether to log debug information.
|
|
58
|
+
* @param {...string} pkgOrPathList - Package name or file path.
|
|
59
|
+
*
|
|
60
|
+
* @returns {string} - The CSS content.
|
|
61
|
+
*/
|
|
62
|
+
function loadCss(debug, ...pkgOrPathList) {
|
|
63
|
+
const includedThemes = [...pkgOrPathList];
|
|
64
|
+
const css = pkgOrPathList
|
|
65
|
+
.map((pkgOrPath) => {
|
|
66
|
+
try {
|
|
67
|
+
let cssFilePath = isLocalTheme(pkgOrPath)
|
|
68
|
+
? path.resolve(pkgOrPath)
|
|
69
|
+
: require.resolve(pkgOrPath);
|
|
70
|
+
|
|
71
|
+
if (!fs.existsSync(cssFilePath)) {
|
|
72
|
+
throw new Error(`File not found: ${cssFilePath}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (path.extname(cssFilePath) === '.js') {
|
|
76
|
+
const dir = path.dirname(cssFilePath);
|
|
77
|
+
const indexCssFile = path.join(dir, 'index.css');
|
|
78
|
+
if (fs.existsSync(indexCssFile)) {
|
|
79
|
+
cssFilePath = indexCssFile;
|
|
80
|
+
} else {
|
|
81
|
+
throw new Error('No CSS index file found');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return fs.readFileSync(cssFilePath).toString();
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error(`Failed to load CSS from ${pkgOrPath}.`, error);
|
|
88
|
+
delete includedThemes[includedThemes.indexOf(pkgOrPath)];
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.join('\n');
|
|
93
|
+
|
|
94
|
+
if (debug && includedThemes.length > 0)
|
|
95
|
+
console.log(
|
|
96
|
+
'\x1b[32m%s\x1b[0m',
|
|
97
|
+
`🎨 Including theme${includedThemes.length > 1 ? 's' : ''}:`,
|
|
98
|
+
'\x1b[0m',
|
|
99
|
+
'' + includedThemes.join(', ')
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return css;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Process CSS into a CSS-in-JS object.
|
|
107
|
+
* @param {string} css - The CSS content to process.
|
|
108
|
+
* @returns {object} - The merged CSS-in-JS object.
|
|
109
|
+
*/
|
|
110
|
+
function processCss(css) {
|
|
111
|
+
try {
|
|
112
|
+
const { plugins, options } = postcssrc.sync({}, __dirname);
|
|
113
|
+
const processedCss = postcss(plugins).process(css, options).result.root;
|
|
114
|
+
return postcssJs.objectify(processedCss);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error('Failed to process CSS.', error);
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
module.exports = getThemeBaseStyle;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"accordion__section-heading": {
|
|
3
|
-
"font-size": {
|
|
4
|
-
"xs": "var(--text-lg)",
|
|
5
|
-
"md": "var(--text-xl)"
|
|
6
|
-
}
|
|
7
|
-
},
|
|
8
|
-
"accordion__section-summary": {
|
|
9
|
-
"background": {
|
|
10
|
-
"xs": "var(--color-base-100)"
|
|
11
|
-
},
|
|
12
|
-
"background-hover": {
|
|
13
|
-
"xs": "var(--color-base-200)"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"back-to-top-link": {
|
|
3
|
-
"color": {
|
|
4
|
-
"xs": "var(--color-link)"
|
|
5
|
-
},
|
|
6
|
-
"color-active": {
|
|
7
|
-
"xs": "var(--color-link-active)"
|
|
8
|
-
},
|
|
9
|
-
"color-hover": {
|
|
10
|
-
"xs": "var(--color-link-hover)"
|
|
11
|
-
},
|
|
12
|
-
"padding": {
|
|
13
|
-
"xs": "0px"
|
|
14
|
-
},
|
|
15
|
-
"font-size": {
|
|
16
|
-
"xs": "var(--text-base)",
|
|
17
|
-
"md": "var(--text-lg)"
|
|
18
|
-
},
|
|
19
|
-
"line-height": {
|
|
20
|
-
"xs": "var(--line-h-base)",
|
|
21
|
-
"md": "var(--line-h-lg)"
|
|
22
|
-
},
|
|
23
|
-
"letter-spacing": {
|
|
24
|
-
"xs": "var(--letter-spacing-normal)"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|