@thi.ng/hiccup-css 2.6.7 → 2.6.8
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/CHANGELOG.md +1 -1
- package/README.md +75 -47
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -170,13 +170,15 @@ format preset, see examples further below.
|
|
|
170
170
|
This feature is only intended for setting an element's `.style` attrib:
|
|
171
171
|
|
|
172
172
|
```ts
|
|
173
|
-
css.css
|
|
173
|
+
import { css, percent, px } from "@thi.ng/hiccup-css";
|
|
174
|
+
|
|
175
|
+
css({
|
|
174
176
|
position: "absolute",
|
|
175
177
|
border: 0,
|
|
176
178
|
// function is evaluated during serialization
|
|
177
|
-
top: () =>
|
|
179
|
+
top: () => percent((Math.random() * 100) | 0),
|
|
178
180
|
// the entire properties object is passed to functions
|
|
179
|
-
left: (props) =>
|
|
181
|
+
left: (props) => px(props.border),
|
|
180
182
|
// arrays are joined with `,`
|
|
181
183
|
// nested arrays are joined w/ ` `
|
|
182
184
|
font: [["72px", "ComicSans"], "sans-serif"]
|
|
@@ -188,13 +190,15 @@ css.css({
|
|
|
188
190
|
### Basic selectors
|
|
189
191
|
|
|
190
192
|
```ts
|
|
191
|
-
css.css
|
|
193
|
+
import { css, rem, PRETTY } from "@thi.ng/hiccup-css";
|
|
194
|
+
|
|
195
|
+
css(
|
|
192
196
|
[
|
|
193
197
|
["html", "body", { margin: 0, padding: 0 }],
|
|
194
|
-
["div", { "max-width":
|
|
198
|
+
["div", { "max-width": rem(30)}],
|
|
195
199
|
["div.title", { color: "red" }]
|
|
196
200
|
],
|
|
197
|
-
{ format:
|
|
201
|
+
{ format: PRETTY }
|
|
198
202
|
);
|
|
199
203
|
```
|
|
200
204
|
|
|
@@ -216,16 +220,18 @@ div.title {
|
|
|
216
220
|
### Property object merging & re-use
|
|
217
221
|
|
|
218
222
|
```ts
|
|
223
|
+
import { css, PRETTY } from "@thi.ng/hiccup-css";
|
|
224
|
+
|
|
219
225
|
// re-usable property snippets
|
|
220
226
|
const border = { border: "1px solid black" };
|
|
221
227
|
const red = { color: "red" };
|
|
222
228
|
|
|
223
|
-
css
|
|
229
|
+
css(
|
|
224
230
|
[
|
|
225
231
|
["#foo", { background: "white" }, border, red],
|
|
226
232
|
["#bar", { background: "yellow", color: "black" }, border]
|
|
227
233
|
],
|
|
228
|
-
{ format:
|
|
234
|
+
{ format: PRETTY }
|
|
229
235
|
);
|
|
230
236
|
```
|
|
231
237
|
|
|
@@ -308,13 +314,15 @@ selectors are computed using the cartesian product of any selectors in
|
|
|
308
314
|
the current scope and their previously defined parents:
|
|
309
315
|
|
|
310
316
|
```ts
|
|
311
|
-
css.css
|
|
312
|
-
|
|
317
|
+
import { css, rem, withAttrib, PRETTY } from "@thi.ng/hiccup-css";
|
|
318
|
+
|
|
319
|
+
css(
|
|
320
|
+
["header", "footer", { "font-size": rem(1.25) },
|
|
313
321
|
["nav", { background: "#000", color: "#666" },
|
|
314
322
|
["ul", { "list-style": "none" }],
|
|
315
|
-
["li", { padding:
|
|
316
|
-
[
|
|
317
|
-
{ format:
|
|
323
|
+
["li", { padding: rem(0.5) },
|
|
324
|
+
[withAttrib("selected"), { color: "#0cf" }]]]],
|
|
325
|
+
{ format: PRETTY }
|
|
318
326
|
)
|
|
319
327
|
```
|
|
320
328
|
|
|
@@ -346,9 +354,11 @@ header, footer {
|
|
|
346
354
|
Pseudo-classes follow the same pattern as other nested selectors shown above:
|
|
347
355
|
|
|
348
356
|
```ts
|
|
349
|
-
css.css
|
|
357
|
+
import { css, PRETTY } from "@thi.ng/hiccup-css";
|
|
358
|
+
|
|
359
|
+
css(
|
|
350
360
|
["p", ["a", [":link", {color: "red"}], [":visited", {border: 0}]]],
|
|
351
|
-
{ format:
|
|
361
|
+
{ format: PRETTY }
|
|
352
362
|
);
|
|
353
363
|
```
|
|
354
364
|
|
|
@@ -379,9 +389,11 @@ p a:visited {
|
|
|
379
389
|
on property values is planned, but currently low priority.)
|
|
380
390
|
|
|
381
391
|
```ts
|
|
382
|
-
css.css
|
|
392
|
+
import { css, PRETTY } from "@thi.ng/hiccup-css";
|
|
393
|
+
|
|
394
|
+
css(
|
|
383
395
|
["div", {"border-radius": "4px"}],
|
|
384
|
-
{ autoprefix: ["border-radius"], format:
|
|
396
|
+
{ autoprefix: ["border-radius"], format: PRETTY }
|
|
385
397
|
);
|
|
386
398
|
```
|
|
387
399
|
|
|
@@ -415,20 +427,22 @@ Note: In CSS Level 3, the `not` operator can't be used to negate an individual
|
|
|
415
427
|
media feature expression, only an entire media query.
|
|
416
428
|
|
|
417
429
|
```ts
|
|
418
|
-
css.css
|
|
419
|
-
|
|
420
|
-
|
|
430
|
+
import { css, at_media, percent, rem, PRETTY } from "@thi.ng/hiccup-css";
|
|
431
|
+
|
|
432
|
+
css(
|
|
433
|
+
at_media(
|
|
434
|
+
{ screen: true, "min-width": rem(10) },
|
|
421
435
|
[
|
|
422
|
-
[".col", { width:
|
|
436
|
+
[".col", { width: percent(50)}],
|
|
423
437
|
[
|
|
424
|
-
|
|
438
|
+
at_media(
|
|
425
439
|
{ "min-width": "20rem" },
|
|
426
|
-
[".col", { padding:
|
|
440
|
+
[".col", { padding: rem(1) }]
|
|
427
441
|
)
|
|
428
442
|
]
|
|
429
443
|
]
|
|
430
444
|
),
|
|
431
|
-
{ format:
|
|
445
|
+
{ format: PRETTY }
|
|
432
446
|
);
|
|
433
447
|
```
|
|
434
448
|
|
|
@@ -453,9 +467,11 @@ css.css(
|
|
|
453
467
|
### Keyframes
|
|
454
468
|
|
|
455
469
|
```ts
|
|
456
|
-
css.css
|
|
457
|
-
|
|
458
|
-
|
|
470
|
+
import { css, at_keyframes, PRETTY } from "@thi.ng/hiccup-css";
|
|
471
|
+
|
|
472
|
+
css(
|
|
473
|
+
at_keyframes("fadein", { opacity: 0 }, { opacity: 1 }),
|
|
474
|
+
{ format: PRETTY }
|
|
459
475
|
);
|
|
460
476
|
```
|
|
461
477
|
|
|
@@ -474,8 +490,10 @@ css.css(
|
|
|
474
490
|
```
|
|
475
491
|
|
|
476
492
|
```ts
|
|
477
|
-
css.css
|
|
478
|
-
|
|
493
|
+
import { css, at_keyframes, PRETTY } from "@thi.ng/hiccup-css";
|
|
494
|
+
|
|
495
|
+
css(
|
|
496
|
+
at_keyframes(
|
|
479
497
|
"rgbfade",
|
|
480
498
|
{
|
|
481
499
|
0: {
|
|
@@ -489,7 +507,7 @@ css.css(
|
|
|
489
507
|
}
|
|
490
508
|
}
|
|
491
509
|
),
|
|
492
|
-
{ format:
|
|
510
|
+
{ format: PRETTY }
|
|
493
511
|
);
|
|
494
512
|
```
|
|
495
513
|
|
|
@@ -519,13 +537,15 @@ given animation `opts`. Only the `duration`option is given a default
|
|
|
519
537
|
value (250ms), all others are optional.
|
|
520
538
|
|
|
521
539
|
```ts
|
|
540
|
+
import { css, animation } from "@thi.ng/hiccup-css";
|
|
541
|
+
|
|
522
542
|
css(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
543
|
+
animation(
|
|
544
|
+
"delayed-fade-in",
|
|
545
|
+
{ delay: "0.5s" },
|
|
546
|
+
{ opacity: 0 },
|
|
547
|
+
{ opacity: 1 }
|
|
548
|
+
)
|
|
529
549
|
);
|
|
530
550
|
```
|
|
531
551
|
|
|
@@ -553,8 +573,10 @@ Results in:
|
|
|
553
573
|
CSS strings can be installed into the DOM `<head>` element via `injectStyleSheet()`:
|
|
554
574
|
|
|
555
575
|
```ts
|
|
556
|
-
css.
|
|
557
|
-
|
|
576
|
+
import { css, injectStyleSheet } from "@thi.ng/hiccup-css";
|
|
577
|
+
|
|
578
|
+
injectStyleSheet(
|
|
579
|
+
css([
|
|
558
580
|
"body", { background: "#000", color: "#fff" }
|
|
559
581
|
])
|
|
560
582
|
);
|
|
@@ -575,7 +597,9 @@ the `CSSOpts` object passed to `css()`. This form is mainly used by the
|
|
|
575
597
|
various `at_*()` functions provided (e.g. `at_media()` example above).
|
|
576
598
|
|
|
577
599
|
```ts
|
|
578
|
-
css
|
|
600
|
+
import { css, at_import } from "@thi.ng/hiccup-css";
|
|
601
|
+
|
|
602
|
+
css(at_import("foo.css", "screen"));
|
|
579
603
|
// "@import url(foo.css) screen;"
|
|
580
604
|
```
|
|
581
605
|
|
|
@@ -583,10 +607,12 @@ The following example illustrates the head position placement, using the
|
|
|
583
607
|
`comment()` function to emit CSS comments.
|
|
584
608
|
|
|
585
609
|
```ts
|
|
586
|
-
css.css
|
|
610
|
+
import { css, comment } from "@thi.ng/hiccup-css";
|
|
611
|
+
|
|
612
|
+
css([
|
|
587
613
|
// comments are usually omitted with the default format (css.COMPACT)
|
|
588
614
|
// pass `true` as 2nd arg to force inclusion
|
|
589
|
-
|
|
615
|
+
comment("generated, please don't edit", true),
|
|
590
616
|
["div", { margin: 0 }]
|
|
591
617
|
]);
|
|
592
618
|
// "/*generated, don't edit*/div{margin:0;}"
|
|
@@ -617,6 +643,8 @@ called with all remaining elements in the same array. I.e. `["@import",
|
|
|
617
643
|
of a scope.
|
|
618
644
|
|
|
619
645
|
```ts
|
|
646
|
+
import * as css from "@thi.ng/hiccup-css";
|
|
647
|
+
|
|
620
648
|
const styles = [
|
|
621
649
|
["@comment", " CSS from JSON"],
|
|
622
650
|
["@import", "print.css", "print"],
|
|
@@ -631,12 +659,12 @@ css.css(styles, { format: css.PRETTY, fns: css.QUOTED_FNS });
|
|
|
631
659
|
|
|
632
660
|
// btw. QUOTED_FNS is simply:
|
|
633
661
|
const QUOTED_FNS = {
|
|
634
|
-
"@comment": comment,
|
|
635
|
-
"@import": at_import,
|
|
636
|
-
"@keyframes": at_keyframes,
|
|
637
|
-
"@media": at_media,
|
|
638
|
-
"@namespace": at_namespace,
|
|
639
|
-
"@supports": at_supports,
|
|
662
|
+
"@comment": css.comment,
|
|
663
|
+
"@import": css.at_import,
|
|
664
|
+
"@keyframes": css.at_keyframes,
|
|
665
|
+
"@media": css.at_media,
|
|
666
|
+
"@namespace": css.at_namespace,
|
|
667
|
+
"@supports": css.at_supports,
|
|
640
668
|
}
|
|
641
669
|
```
|
|
642
670
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup-css",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.8",
|
|
4
4
|
"description": "CSS from nested JS data structures",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@thi.ng/api": "^8.9.27",
|
|
39
39
|
"@thi.ng/checks": "^3.5.1",
|
|
40
40
|
"@thi.ng/errors": "^2.4.19",
|
|
41
|
-
"@thi.ng/transducers": "^8.9.
|
|
41
|
+
"@thi.ng/transducers": "^8.9.9"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@microsoft/api-extractor": "^7.40.1",
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
],
|
|
127
127
|
"year": 2016
|
|
128
128
|
},
|
|
129
|
-
"gitHead": "
|
|
129
|
+
"gitHead": "df9e312af741d87e6b450afcfea6a6e381662b1e\n"
|
|
130
130
|
}
|