postcss-enumerates-in-line 0.0.1 → 0.0.9

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/README_EN.md ADDED
@@ -0,0 +1,551 @@
1
+ # PostCSS Enumerates in Line
2
+
3
+ |言語|Language|
4
+ |---|---|
5
+ |[<img width="24" height="24" align="left" src="README.img/1f1ef-1f1f5.png" alt="🇯🇵"> 日本語](README.md)|[<img width="24" height="24" align="left" src="README.img/1f1fa-1f1f8.png" alt="🇺🇸"> English](README_EN.md)|
6
+
7
+
8
+ ## Revision: in v0.0.1
9
+
10
+ - Begin to publish.
11
+
12
+ ---
13
+
14
+ This [PostCSS] plugin extend to multiple CSSes from shrinked it which described in 1 line like `@apply` syntax of [Tailwind CSS].
15
+
16
+ ```scss
17
+ // header
18
+ .c-header {
19
+ @enums my:1.5rem;
20
+
21
+ &--caption {
22
+ @enums ff:"Rammetto^One",sans-serif fs:1.25em;
23
+ }
24
+
25
+ &--description {
26
+ @enums fs:0.85em;
27
+ }
28
+ }
29
+ ```
30
+
31
+ Specific speaking, it takes the syntax like above -- language in [SCSS].
32
+
33
+ > The syntax is a kind of at-rules which begins by `@enums`, writing as same as `@apply` on Tailwind CSS.
34
+ >
35
+ > There are shorthands; `my` means convined `margin-top` and `margin-bottom`, `ff` means `font-family`, and `fs` means `font-size`.
36
+ > What are defining about shorthands, c.f. [Shorthands of property names](#shorthands-of-property-names).
37
+ >
38
+ > You would separate CSS styles by `:` character so, property name appears in before and property value appears in after against `:`.
39
+ > Whitespace characters (like a ` `) treat as separator of CSS styles. If you want to write whitespaces at property values, then may replace these by `^` character.
40
+ >
41
+ > There are syntax descriptions after indexes.
42
+
43
+ There are no imprements about state transition like a hover, media queries, dark mode, etc.; because I am wishing only to aim for enumerating CSS styles.
44
+
45
+ > What do I want to say; this plugin do not have any `hover:`, `md:`, and `dark:` etc. at [Tailwind CSS].
46
+
47
+ I think primary usage is [gulp] and [gulp-postcss]. However it also works on JS-API of the PostCSS.
48
+
49
+ [PostCSS]: https://github.com/postcss/postcss
50
+ [Tailwind CSS]: https://tailwindcss.com/
51
+ [SCSS]: https://sass-lang.com/
52
+ [gulp]: https://gulpjs.com/
53
+ [gulp-postcss]: https://github.com/postcss/gulp-postcss
54
+
55
+ <div class="x--hr"></div>
56
+
57
+
58
+ ## Indexes
59
+
60
+ - [PostCSS Enumerates in Line](#postcss-enumerates-in-line)
61
+ - [Revision: in v0.0.1](#revision-in-v001)
62
+ - [Indexes](#indexes)
63
+ - [Method of writing in CSS files.](#method-of-writing-in-css-files)
64
+ - [Special characters](#special-characters)
65
+ - [COLON Character](#colon-character)
66
+ - [EXCLAMATION character](#exclamation-character)
67
+ - [CIRCUMFLEX character](#circumflex-character)
68
+ - [double SQUARE BRACKET character](#double-square-bracket-character)
69
+ - [Shorthands of property names](#shorthands-of-property-names)
70
+ - [How to use this plugin](#how-to-use-this-plugin)
71
+ - [How to use with gulp](#how-to-use-with-gulp)
72
+ - [package.json](#packagejson)
73
+ - [Javascript module](#javascript-module)
74
+ - [Load packages](#load-packages)
75
+ - [Task: SCSS](#task-scss)
76
+ - [Source files of sample](#source-files-of-sample)
77
+ - [Execute compiling](#execute-compiling)
78
+ - [How to use with JS-API](#how-to-use-with-js-api)
79
+ - [package.json](#packagejson-1)
80
+ - [Javascript module](#javascript-module-1)
81
+ - [Load packages](#load-packages-1)
82
+ - [Task: SCSS](#task-scss-1)
83
+ - [Source files of sample](#source-files-of-sample-1)
84
+ - [Execute compiling](#execute-compiling-1)
85
+ - [Arguments of option settings](#arguments-of-option-settings)
86
+ - [prependDefaultColor](#prependdefaultcolor)
87
+ - [prependDefaultStyle](#prependdefaultstyle)
88
+
89
+ <div class="x--hr"></div>
90
+
91
+
92
+ ## Method of writing in CSS files.
93
+
94
+ It is easilable doing in CSS (or SCSS) files.
95
+
96
+ ```scss
97
+ html {
98
+ @enums background-color:#000 color:#fff;
99
+
100
+ h1 {
101
+ @enums font-size:100%;
102
+ }
103
+ }
104
+ ```
105
+
106
+ You need not to write setting `@import tailwindcss;` as for [Tailwind CSS]. There are no special syntax for import in this plugin.
107
+
108
+ Begin with `@enums`, and end with `;`. That is all.
109
+
110
+ You can enumerates multiple CSS styles with whitespace splitter which are "WHITESPACEs". That means splitting is executed by line breaks also.
111
+
112
+ There are simplification at CSS style declarating too. That made by combination with "`property name`", "`:`", and "`property value`".
113
+
114
+ You will be able to operate designation freely like a "`border:1px^#888^solid`", because property values can have arbitary value.
115
+
116
+
117
+ ### Special characters
118
+
119
+ There are 5 characters which behave especially; `:`, `^`, `!`, `[[`, and `]]`.
120
+
121
+
122
+ #### COLON Character
123
+
124
+ As saying before, COLON (`:`) characters are used for separator against property name and property value.
125
+
126
+ Because of this, you cannot describe as `content:":"`.
127
+
128
+ Please transform to escape the characters by yourself -- `content:"\03A"`.
129
+
130
+
131
+ #### EXCLAMATION character
132
+
133
+ When you postfix EXCLAMATION (`!`) character about property value, this plugin recognize "I ordered this property is declared `!important`". There is `padding-top:1rem`, then will be replaced to `padding-top: 1rem !important`.
134
+
135
+
136
+ #### CIRCUMFLEX character
137
+
138
+ CIRCUMFLEX (`^`) characters will be replaced to half-width space (` `) character automatically.
139
+
140
+ When you occured that need to separate a CSS style by whitespace character. For example using, `border:1px^#888^solid` (this CSS style appears above).
141
+
142
+ There are not only usage at CSS property shorthands, there are used in the case of calculation operators, multiple CSS property values, avoidance `//` character. See no.1, 2, and 3.
143
+
144
+ 1. calculation operators
145
+
146
+ Operators (`+`, `-`, `*`, and `/`) of calculation functions (`calc`, `min`, etc.) need whitespace character at before and behind, it must descripts like `calc(100vw - 1rem)` in regular CSS syntax.
147
+
148
+ But this plugin is not allow whitespaces in property values. So you should replace whitespace character to `^`.
149
+
150
+ 2. multiple CSS property values
151
+
152
+ There is a case of effecting to combine multiple property values like `filter: blur(5px) grayscale(80%)`. As same above, you would describe replacing whitespace characters to `filter:blur(5px)^grayscale(80%)`.
153
+
154
+ 3. avoidance `//` character
155
+
156
+ In the unique case, there are special way to describe using shorthands like `border-image: linear-gradient(#333,#333) fill 0 // 0 100vw`.
157
+
158
+ > This is a one of CSS tricks which used on drawing to max of viewport width over DOM element's left and right.
159
+
160
+ There is included `//` character, this can write on CSS syntax because which only have block comment-out. But SCSS syntax have 1 line comment-out too, it occurs a compile error.
161
+
162
+ > I needed to consider about this probrem -- all user possibly write the both case `/ /` (sepalated by whitespace) and `//` (adjacented SLASH characters) -- that is works too as same CSS syntax meaning.
163
+
164
+ Therefore you might supplement CIRCUMFLEX (`^`) characters against whitespace as `border-image:linear-gradient(#333,#333)^fill^0^/^/^0^100vw`, so have to describe explicitly as `/ /` for evading SCSS syntax error.
165
+
166
+
167
+ #### double SQUARE BRACKET character
168
+
169
+ Additional speaking, this is a experimental function. I provided another method for problem of calculation operators (no. 1; `+`, `-`, `*`, and `/`).
170
+
171
+ You can describe as `width:calc[[100vw-(100%+2rem)*(2)+1rem]]` too to omit `^` characters, by surrounding with `[[` and `]]` characters.
172
+
173
+ Because there ware annoying `^` characters they appear many and many times about `width:calc(100vw^-^(100%^+^2rem)^*^2^+^1rem)`, that is not visibility at good.
174
+
175
+ > Please must you not use `[[` and `]]` characters about non-mathematical functions like `var()`.
176
+ >
177
+ > Cause for example; `var[[--foo-bar]]` will be wrongly replacing to `var(--foo - var)`. That is destructed and meaningless property value of CSS.
178
+
179
+ This is experimental function. I am improving a transform compiler, so you will face at risk that would not insert whitespace characters to both end of calculation operators normally at your wish.
180
+
181
+ It works to replace whitespace to `^` characters as this case too. But I recommend to take a surefire way, it is supplements by `^` characters manually without `[[` and `]]`.
182
+
183
+
184
+ ### Shorthands of property names
185
+
186
+ There are defined shorthands about some property names.
187
+
188
+ For example, `border-top-width:1px` as same as `bw8:1px`.
189
+
190
+ + margin
191
+ - `m`: margin
192
+ - `m8`: margin-top
193
+ - `m6`: margin-right
194
+ - `m2`: margin-bottom
195
+ - `m4`: margin-left
196
+ - `mx`: margin-left & margin-right
197
+ - `my`: margin-top & margin-bottom
198
+ + padding
199
+ - `p`: padding
200
+ - `p8`: padding-top
201
+ - `p6`: padding-right
202
+ - `p2`: padding-bottom
203
+ - `p4`: padding-left
204
+ - `px`: padding-left & padding-right
205
+ - `py`: padding-top & padding-bottom
206
+ + outline
207
+ - `o`: outline
208
+ - `o8`: outline-top
209
+ - `o6`: outline-right
210
+ - `o2`: outline-bottom
211
+ - `o4`: outline-left
212
+ - `ox`: outline-left & outline-right
213
+ - `oy`: outline-top & outline-bottom
214
+ + border-width
215
+ - `bw`: border-width
216
+ - `bw8`: border-top-width
217
+ - `bw6`: border-right-width
218
+ - `bw2`: border-bottom-width
219
+ - `bw4`: border-left-width
220
+ - `bwx`: border-left-width & border-right-width
221
+ - `bwy`: border-top-width & border-bottom-width
222
+ + border-style
223
+ - `bs`: border-style
224
+ - `bs8`: border-top-style
225
+ - `bs6`: border-right-style
226
+ - `bs2`: border-bottom-style
227
+ - `bs4`: border-left-style
228
+ - `bsx`: border-left-style & border-right-style
229
+ - `bsy`: border-top-style & border-bottom-style
230
+ + border-color
231
+ - `bc`: border-color
232
+ - `bc8`: border-top-color
233
+ - `bc6`: border-right-color
234
+ - `bc2`: border-bottom-color
235
+ - `bc4`: border-left-color
236
+ - `bcx`: border-left-color & border-right-color
237
+ - `bcy`: border-top-color & border-bottom-color
238
+ + border-radius
239
+ - `br`: border-radius
240
+ - `br7`: border-top-left-radius
241
+ - `br9`: border-top-right-radius
242
+ - `br3`: border-bottom-right-radius
243
+ - `br1`: border-bottom-left-radius
244
+ + color
245
+ - `ct`: color
246
+ - `cb`: background-color
247
+ + inset
248
+ - `i`: inset
249
+ - `i8`: top
250
+ - `i6`: right
251
+ - `i2`: bottom
252
+ - `i4`: left
253
+ + sizing
254
+ - `w`: width
255
+ - `wmin`: min-width
256
+ - `wmax`: max-width
257
+ - `h`: height
258
+ - `hmin`: min-height
259
+ - `hmax`: max-height
260
+ + grid position
261
+ - `gx`: grid-column
262
+ - `g4`: grid-column-start
263
+ - `g6`: grid-column-end
264
+ - `gy`: grid-row
265
+ - `g8`: grid-row-start
266
+ - `g2`: grid-row-end
267
+ + font
268
+ - `ff`: font-family
269
+ - `fs`: font-size
270
+ - `fw`: font-weight
271
+ - `fh`: line-height
272
+
273
+ `x` character means left & right, `y` means top & bottom.
274
+
275
+ Numeric character (from `1` to `9`) are related to position of Ten-key pad.
276
+
277
+
278
+ ## How to use this plugin
279
+
280
+ ### How to use with gulp
281
+
282
+ I will prepare for workable sample in `test/gulp` folder.
283
+
284
+
285
+ #### package.json
286
+
287
+ ```powershell
288
+ npm init -y
289
+ ```
290
+
291
+ Change defining some properties in a package.json.
292
+
293
+ ```json
294
+ {
295
+ "type": "module",
296
+ "scripts": {
297
+ "clean": "gulp clean",
298
+ "build": "npm run clean && gulp",
299
+ "dev": "gulp dev"
300
+ }
301
+ }
302
+ ```
303
+
304
+ ```powershell
305
+ npm install autoprefixer browser-sync gulp gulp-plumber gulp-postcss gulp-sass postcss-csso postcss-enumerates-in-line sass
306
+ ```
307
+
308
+
309
+ #### Javascript module
310
+
311
+ Create `gulpfile.mjs` file.
312
+
313
+ I only describe functions about this package.
314
+
315
+
316
+ ##### Load packages
317
+
318
+ Load this package with PostCSS and other plugin packages.
319
+
320
+ ```javascript
321
+ // PostCSS
322
+ import postcss from 'gulp-postcss'
323
+ import autoprefixer from 'autoprefixer'
324
+ import csso from 'postcss-csso'
325
+ import { enumSpreader } from 'postcss-enumerates-in-line'
326
+ ```
327
+
328
+
329
+ ##### Task: SCSS
330
+
331
+ ```javascript
332
+ // CSS <- SCSS
333
+ const task_css = done => {
334
+ src('src/css/**/!(_)*.scss', {
335
+ allowEmpty: true,
336
+ })
337
+ .pipe(plumber())
338
+ .pipe(sass())
339
+ .pipe(postcss([
340
+ enumSpreader({}),
341
+ autoprefixer(),
342
+ csso(),
343
+ ]))
344
+ .pipe(dest('dist/css'))
345
+
346
+ done()
347
+ }
348
+ ```
349
+
350
+ Insert a function of `enumSpreader({})` into array of PostCSS execution.
351
+
352
+ > Please set a PostCSS function after Sass (SCSS), and set this package before all other PostCSS plugins.
353
+
354
+ You will designate a blank object at a function of this package, if want to use by default settings.
355
+
356
+ Or not want, might add option settings in the object.
357
+
358
+ The detail of settings to know, refer to [Arguments of option settings](#arguments-of-option-settings).
359
+
360
+
361
+ #### Source files of sample
362
+
363
+ I created to provide these folders -- `src`, `src/css`, `src/js`, and `dist`. And files -- `src/index.html`, `src/css/app.scss`, and `src/js/app.js`.
364
+
365
+ For lively using example about this package, you may mainly see a file `src/css/app.scss`.
366
+
367
+
368
+ #### Execute compiling
369
+
370
+ `npm run dev` runs CLI debug mode, and `npm run build` runs CLI build mode.
371
+
372
+
373
+ ### How to use with JS-API
374
+
375
+ I will prepare for workable sample in `test/postcss` folder.
376
+
377
+
378
+ #### package.json
379
+
380
+ ```powershell
381
+ npm init -y
382
+ ```
383
+
384
+ Change defining some properties in a package.json.
385
+
386
+ ```json
387
+ {
388
+ "type": "module",
389
+ "scripts": {
390
+ "clean": "node build-clean.mjs",
391
+ "common:copy": "node build-copy.mjs",
392
+ "build:css": "node build-css.mjs -- build",
393
+ "dev:css": "node build-css.mjs -- dev",
394
+ "build": "npm run clean && run-s common:* build:*",
395
+ "dev": "run-s common:* dev:*"
396
+ }
397
+ }
398
+ ```
399
+
400
+ ```powershell
401
+ npm install autoprefixer glob npm-run-all2 postcss postcss-csso postcss-enumerates-in-line sass
402
+ ```
403
+
404
+ #### Javascript module
405
+
406
+ Create these files -- `build-clean.mjs`, `build-copy.mjs`, and `build-css.mjs`.
407
+
408
+ Omit to explain about build-clean.mjs and build-copy.mjs, because there are no affects directly with this package.
409
+
410
+
411
+ ##### Load packages
412
+
413
+ Load these packages.
414
+
415
+ ```javascript
416
+ // Files
417
+ import fs from 'node:fs'
418
+ import { glob } from 'glob'
419
+ import path from 'node:path'
420
+
421
+ // SCSS
422
+ import * as dartSass from 'sass'
423
+
424
+ // PostCSS
425
+ import postcss from 'postcss'
426
+ import autoprefixer from 'autoprefixer'
427
+ import csso from 'postcss-csso'
428
+ import { enumSpreader } from 'postcss-enumerates-in-line'
429
+ ```
430
+
431
+ ##### Task: SCSS
432
+
433
+ ```javascript
434
+ const task = async () => {
435
+ const files = await glob('src/css/**/!(_)*.scss', {
436
+ ignore: 'node_modules/**',
437
+ })
438
+
439
+ files.forEach(file => {
440
+ const distPath = path.dirname(file).replace(/^src/, 'dist') + path.sep + path.basename(file).replace(/\.scss$/, '.css')
441
+
442
+ let body = fs.readFileSync(file, {
443
+ encoding: 'utf-8',
444
+ })
445
+
446
+ body = dartSass.compile(file).css.replace(/[\t\r\n\s]+/g, ' ')
447
+
448
+ postcss([
449
+ enumSpreader({}),
450
+ autoprefixer(),
451
+ csso(),
452
+ ])
453
+ .process(body, {from: file, to: distPath})
454
+ .then(res => {
455
+ fs.writeFileSync(res.opts.to, res.css)
456
+ })
457
+ })
458
+ }
459
+
460
+ task()
461
+ ```
462
+
463
+ Insert a function of `enumSpreader({})` into array of PostCSS execution.
464
+
465
+ > Please set this package before all other PostCSS plugins.
466
+
467
+ You will designate a blank object at a function of this package, if want to use by default settings.
468
+
469
+ Or not want, might add option settings in the object.
470
+
471
+ The detail of settings to know, refer to [Arguments of option settings](#arguments-of-option-settings).
472
+
473
+
474
+ #### Source files of sample
475
+
476
+ I created to provide these folders -- `src`, `src/css`, `src/js`, and `dist`. And files -- `src/index.html`, `src/css/app.scss`, and `src/js/app.js`.
477
+
478
+ For lively using example about this package, you may mainly see a file `src/css/app.scss`.
479
+
480
+
481
+ #### Execute compiling
482
+
483
+ `npm run dev` runs CLI debug mode, and `npm run build` runs CLI build mode.
484
+
485
+
486
+ ## Arguments of option settings
487
+
488
+ ### prependDefaultColor
489
+
490
+ How to dealing with CSS about color settings that will add automatically.
491
+
492
+ Default value: true (boolean|string)
493
+
494
+ If you designate to `true` (either nothing to designate, or designate `"hsl"` including `"HSL"`), this package output color settings in HSL type to CSS files like below.
495
+
496
+ ```css
497
+ :root {
498
+ --enums-color-gray-100: hsl(210 5% 10%);
499
+ }
500
+ ```
501
+
502
+ Turn it `false`, this will not output any color settings.
503
+
504
+ You want to output by RGB type (without default HSL type), may designate `"rgb"` or `"RGB"`.
505
+
506
+ ```css
507
+ :root {
508
+ --enums-color-gray-100: #181a1b;
509
+ }
510
+ ```
511
+
512
+ Or want to output by OKLCH type, may designate `"oklch"` or `"OKLCH"`.
513
+
514
+ ```css
515
+ :root {
516
+ --enums-color-gray-100: oklch(0.21 0.01 210);
517
+ }
518
+ ```
519
+
520
+
521
+ ### prependDefaultStyle
522
+
523
+ How to dealing with CSS about reset settings that will add automatically.
524
+
525
+ Default value: true (boolean|string[])
526
+
527
+ If you designate to `true` (or nothing to designate), this package output reset settings to CSS files like below.
528
+
529
+ ```css
530
+ *, ::before, ::after, ::backdrop, ::file-selector-button {
531
+ box-sizing: border-box;
532
+ margin: 0;
533
+ padding: 0;
534
+ border: 0 solid;
535
+ }
536
+ ```
537
+
538
+ Turn it `false`, this will not output any reset settings.
539
+
540
+ ```javascript
541
+ prependDefaultStyle: [
542
+ 'a { color: red }',
543
+ 'a:hover { text-decoration: underline }',
544
+ ]
545
+ ```
546
+
547
+ You want to append your original reset CSS, please designate CSS blocks (string[] type) like above.
548
+
549
+ It only works appending CSS styles, you cannot remove reset CSS styles which defined in this package.
550
+
551
+ In the case of working perfectly original CSS styles, you may designate `false` to this option, and write these in your SCSS files.
package/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ // declare module "postcss-enumerates-in-line"
2
+
3
+ interface EnumsEnumeratesInLineOptions extends object {
4
+ /**
5
+ * @param {boolean|string} prependDefaultColor - Enable to print default CSS colors which explains like a `--enums-color-red-900: #f00;`.
6
+ * If set false, this will not print CSS colors.
7
+ * If set true, this will print CSS colors which is styled in `#f00`.
8
+ * And if set 'RGB' (also available 'rgb'), same as above.
9
+ * But if set 'HSL' (also available 'hsl'), prints which styled in `hsl(0 100% 50%)`.
10
+ * Then if set 'OKLCH' (also available 'oklch'), prints which styled in `oklch(63% 26 29.93)`.
11
+ */
12
+ prependDefaultColor?: true | '',
13
+
14
+ /**
15
+ * @param {boolean|string[]} prependDefaultStyle - Enable to print default CSS styles.
16
+ * If set false, this will not print any CSS styles.
17
+ * If set true, this will print default CSS styles which defined of the package.
18
+ * If set {string[]} (like a ['a {text-decoration: underline}', 'a:hover {text-decoration: none}']), this will print CSS styles both package's default one and designate one.
19
+ */
20
+ prependDefaultStyle?: true | [''],
21
+ }
22
+ export declare function enumSpreader(options?: EnumsEnumeratesInLineOptions): import('postcss').Plugin