cacao-css 6.2.0 → 6.4.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.
package/dist/media.css CHANGED
@@ -51,11 +51,14 @@
51
51
  * - And our own usage in building websites
52
52
  *
53
53
  * Cacao is a mobile-first system.
54
- * We don't use min-width or max-width because we follow Stylelint's media-feature-rante-notation rule.
54
+ * We don't use min-width or max-width because we follow Stylelint's media-feature-range-notation rule.
55
55
  * https://stylelint.io/user-guide/rules/media-feature-range-notation/
56
56
  *
57
57
  * We use pixels instead of ems because that is the convention and it helps prevent a Safari bug with how they calculate ems (i.e. they use font-size + zoom level)
58
58
  * https://cgamesplay.com/post/2023/05/19/stop-using-em-in-media-queries/
59
+ *
60
+ * https://www.joshwcomeau.com/css/surprising-truth-about-pixels-and-accessibility/ is another viewpoint on this and considers users increacing the default
61
+ * font size in their browser settings. Need to explore this more. 10/26/2024
59
62
  */
60
63
 
61
64
  /* 3xs */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cacao-css",
3
3
  "description": "A set of composable CSS utilities that provide a solid foundation for website projects.",
4
- "version": "6.2.0",
4
+ "version": "6.4.0",
5
5
  "author": "Aptuitiv, Inc <hello@aptuitiv.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -13,10 +13,12 @@
13
13
  "email": "support@aptuitiv.com"
14
14
  },
15
15
  "bin": {
16
+ "cacao-convert-v3": "./scripts/v3/index.js",
16
17
  "cacao-convert-v6": "./scripts/v6/index.js"
17
18
  },
18
19
  "files": [
19
20
  "dist",
21
+ "scripts/v3",
20
22
  "scripts/v6"
21
23
  ],
22
24
  "type": "module",
@@ -25,6 +27,7 @@
25
27
  "build-gutters": "node scripts/build gutters",
26
28
  "build-imports": "node scripts/build imports",
27
29
  "build-margins": "node scripts/build margins",
30
+ "build-media-queries": "node scripts/build media",
28
31
  "build-paddings": "node scripts/build paddings",
29
32
  "eslint": "eslint --fix .",
30
33
  "watch": "esw -w --color --fix ."
@@ -0,0 +1,19 @@
1
+ # Cacao V3 conversion scripts
2
+
3
+ This folder contains scripts to convert a website that was running on Cacao version 3 to run on the latest version of Cacao.
4
+
5
+ ## Update the CSS classes in template files
6
+
7
+ This will recursively crawl the root directory for your template files and update any Cacao version 3 classes to the correct version 6 class.
8
+
9
+ For example, if your templates are in `src/templates` you would run:
10
+
11
+ ```bash
12
+ cacao-convert-v3 classes -d src/templates
13
+ ```
14
+
15
+ It may also be good to run this on Javascript in case any utility classes were being set.
16
+
17
+ ```bash
18
+ cacao-convert-v3 classes -d src/js
19
+ ```
@@ -0,0 +1,136 @@
1
+ /* ===========================================================================
2
+ Convert the V3 classes to the Cacao V6 format
3
+ =========================================================================== */
4
+
5
+ import chalk from 'chalk';
6
+ import fancyLog from 'fancy-log';
7
+ import fs from 'fs-extra';
8
+ import logSymbols from 'log-symbols';
9
+ import { basename } from 'path';
10
+ import recursiveReadDir from 'recursive-readdir';
11
+
12
+ /**
13
+ * Update the file with the new classes
14
+ *
15
+ * @param {string} file The path to the file to update
16
+ */
17
+ const updateFile = (file) => {
18
+ // Read the file
19
+ let fileContents = fs.readFileSync(file, 'utf8');
20
+ const originalContents = fileContents;
21
+
22
+ // Breakpoints to convert
23
+ const classes = {
24
+ 'u-cf': 'clearfix',
25
+ 'u-cleanContent': 'last-child-sb-0',
26
+ 'u-block': 'block',
27
+ 'u-flexInline': 'inline-flex',
28
+ 'u-flexRowReverse': 'flex-reverse',
29
+ 'u-flexCol': 'flex-col',
30
+ 'u-flexColReverse': 'flex-col-reverse',
31
+ 'u-flexJustifyStart': 'justify-start',
32
+ 'u-flexJustifyEnd': 'justify-end',
33
+ 'u-flexJustifyCenter': 'justify-center',
34
+ 'u-flexJustifyBetween': 'justify-between',
35
+ 'u-flexJustifyAround': 'justify-around',
36
+ 'u-flexAlignItemsStart': 'align-start',
37
+ 'u-flexAlignItemsEnd': 'align-end',
38
+ 'u-flexAlignItemsCenter': 'align-center',
39
+ 'u-flex': 'flex',
40
+ 'u-heightFull': 'h-1-1',
41
+ 'u-hiddenVisually': 'visually-hidden',
42
+ 'u-hidden': 'hidden',
43
+ 'u-inline': 'inline',
44
+ 'u-linkSubtle': 'link-subtle',
45
+ 'u-posAbsolute': 'absolute',
46
+ 'u-posRelative': 'relative',
47
+ 'u-posStatic': 'static',
48
+ 'u-printHide': 'print-hide',
49
+ 'u-printShow': 'print-show',
50
+ 'u-sizeFull': 'w-1-1',
51
+ 'u-styleEm': 'style-italic',
52
+ 'u-textBreak': 'break-word',
53
+ 'u-textBreakAll': 'break-all',
54
+ 'u-textLeft': 'text-start',
55
+ 'u-textLower': 'text-lower',
56
+ 'u-textNoWrap': 'no-wrap',
57
+ 'u-textUpper': 'text-upper',
58
+ 'u-textCenter': 'text-center',
59
+ 'u-textRight': 'text-end',
60
+ 'u-weightNormal': 'weight-normal',
61
+ 'u-weightBold': 'weight-bold',
62
+ 'u-widthFull': 'w-1-1',
63
+ 'Grid--alignBottom': 'align-end',
64
+ 'Grid--alignMiddle': 'align-center',
65
+ 'Grid--alignCenter': 'justify-center',
66
+ 'Grid--alignRight': 'justify-end',
67
+ 'Grid--withGutterSm': 'g-1',
68
+ 'Grid--withGutterLg': 'g-4',
69
+ 'Grid--withGutterXlg': 'g-6',
70
+ 'Grid--withGutterXxlg': 'g-8',
71
+ 'Grid--withGutter': 'g-2',
72
+ 'FlexEmbed-ratio--': 'aspect-',
73
+ 'FlexEmbed-ratio': '',
74
+ 'FlexEmbed-content': '',
75
+ FlexEmbed: 'embed',
76
+ 'Grid-cell': '',
77
+ 'Image Image--left': 'image-left',
78
+ 'Image--left': 'image-left',
79
+ 'Image Image--right': 'image-right',
80
+ 'Image--right': 'image-right',
81
+
82
+ };
83
+
84
+ // Replace the classes
85
+ Object.keys(classes).forEach((key) => {
86
+ fileContents = fileContents.replaceAll(key, classes[key]);
87
+ });
88
+
89
+ fileContents = fileContents.replace(/u-gutters(\d+)/g, 'px-$1');
90
+ fileContents = fileContents.replace(/u-guttersMarg(\d+)/g, 'mx-$1');
91
+ fileContents = fileContents.replace(/u-margTop(\d+)/g, 'mt-$1');
92
+ fileContents = fileContents.replace(/u-margRight(\d+)/g, 'me-$1');
93
+ fileContents = fileContents.replace(/u-margBottom(\d+)/g, 'mb-$1');
94
+ fileContents = fileContents.replace(/u-margLeft(\d+)/g, 'ms-$1');
95
+ fileContents = fileContents.replace(/u-padTop(\d+)/g, 'pt-$1');
96
+ fileContents = fileContents.replace(/u-padRight(\d+)/g, 'pe-$1');
97
+ fileContents = fileContents.replace(/u-padBottom(\d+)/g, 'pb-$1');
98
+ fileContents = fileContents.replace(/u-padLeft(\d+)/g, 'ps-$1');
99
+ fileContents = fileContents.replace(/u-rowGap(\d+)/g, 'gy-$1');
100
+ fileContents = fileContents.replace(/u-spaced(\d+)/g, 'py-$1');
101
+ fileContents = fileContents.replace(/"Grid"/g, '"grid"');
102
+ fileContents = fileContents.replace(/"Grid(\s+)/g, '"grid$1');
103
+
104
+ // Replace any empty spaces in class attributes
105
+ fileContents = fileContents.replace(/class="\s+/g, 'class="');
106
+
107
+ if (fileContents !== originalContents) {
108
+ // Write the new file
109
+ fs.writeFileSync(file, fileContents);
110
+ fancyLog(logSymbols.success, chalk.green('Updated', chalk.cyan(file)));
111
+ } else {
112
+ fancyLog(logSymbols.info, chalk.blue('Skipped', chalk.cyan(file)));
113
+ }
114
+ };
115
+
116
+ /**
117
+ * Convert the class names in the CSS files to the Cacao V6 format
118
+ *
119
+ * @param {object} args The command line arguments. "dir" is the directory to convert.
120
+ */
121
+ const convertClasses = (args) => {
122
+ fancyLog(chalk.magenta('Converting classes', chalk.cyan(args.dir)));
123
+
124
+ // Recursively read the directory and then update the files
125
+ recursiveReadDir(args.dir).then((files) => {
126
+ files.sort();
127
+ files.forEach((file) => {
128
+ if (basename(file) !== '.DS_Store') {
129
+ updateFile(file);
130
+ }
131
+ });
132
+ fancyLog(logSymbols.success, chalk.green('Finished converting classes'));
133
+ });
134
+ };
135
+
136
+ export default convertClasses;
@@ -0,0 +1,36 @@
1
+ #! /usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import fs from 'fs-extra';
5
+ import { dirname } from 'path';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ import convertClasses from './convert-classes.js';
9
+
10
+ // Get the directory name of the current module
11
+ // eslint-disable-next-line no-underscore-dangle -- The dangle is used to match the __dirname variable in Node.js
12
+ const __dirname = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
13
+
14
+ // Get the current package.json information
15
+ const thisPackageJson = fs.readJsonSync(`${__dirname}/package.json`);
16
+
17
+ // Set up the command line options
18
+ const program = new Command();
19
+ program.description('Convert Cacao CSS versions 3 to the current version');
20
+ program.version(thisPackageJson.version);
21
+
22
+ /**
23
+ * Convert the V3 classes to V6 format
24
+ *
25
+ * cacao-convert-v3 classes -d src/templates
26
+ */
27
+ program
28
+ .command('classes')
29
+ .description('Convert the V3 classes to V6 format')
30
+ .requiredOption('-d, --dir <path>', 'The root path for the templates. The path should be relative to the root of the project.')
31
+ .action(async (args) => {
32
+ convertClasses(args);
33
+ });
34
+
35
+ // Parse the command line arguments
36
+ program.parse();
@@ -21,11 +21,21 @@ const updateFile = (file) => {
21
21
 
22
22
  // Breakpoints to convert
23
23
  const breakpoints = {
24
+ '--c-bp-3xs': '--m-3xs',
25
+ '--c-bp-xxxs': '--m-3xs',
26
+ '--c-bp-2xs': '--m-2xs',
27
+ '--c-bp-xxs': '--m-2xs',
28
+ '--c-bp-xs': '--m-xs',
24
29
  '--c-bp-sm': '--m-sm',
25
30
  '--c-bp-md': '--m-md',
26
31
  '--c-bp-lg': '--m-lg',
27
32
  '--c-bp-xl': '--m-xl',
28
33
  '--c-bp-xxl': '--m-2xl',
34
+ '--c-bp-2xl': '--m-2xl',
35
+ '--c-bp-xxxl': '--m-3xl',
36
+ '--c-bp-3xl': '--m-3xl',
37
+ '--c-bp-4xl': '--m-4xl',
38
+ '--c-bp-5xl': '--m-5xl',
29
39
  };
30
40
 
31
41
  // Replace the breakpoint classes