@thi.ng/hiccup-css 2.2.19 → 2.3.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-18T13:41:19Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,17 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-css@2.3.0) (2023-12-18)
13
+
14
+ #### 🚀 Features
15
+
16
+ - update float value formatter, add tests ([00ee4f7](https://github.com/thi-ng/umbrella/commit/00ee4f7))
17
+
18
+ #### 🩹 Bug fixes
19
+
20
+ - update conditional formatting ([f126005](https://github.com/thi-ng/umbrella/commit/f126005))
21
+ - add tests
22
+
12
23
  ### [2.2.14](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-css@2.2.14) (2023-11-09)
13
24
 
14
25
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -117,7 +117,7 @@ For Node.js REPL:
117
117
  const hiccupCss = await import("@thi.ng/hiccup-css");
118
118
  ```
119
119
 
120
- Package sizes (brotli'd, pre-treeshake): ESM: 2.08 KB
120
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.13 KB
121
121
 
122
122
  ## Dependencies
123
123
 
package/animation.js CHANGED
@@ -1,53 +1,21 @@
1
1
  import { at_keyframes } from "./keyframes.js";
2
- /**
3
- * Defines new `@keyframes` with given `id` and creates related class of
4
- * same name to configure given animation `opts`. Only the `duration`
5
- * option is given a default value (250ms), all others are optional.
6
- *
7
- * @example
8
- * ```ts
9
- * css(
10
- * animation(
11
- * "fadein",
12
- * { delay: "0.5s" },
13
- * { opacity: 0 },
14
- * { opacity: 1 }
15
- * )
16
- * );
17
- * ```
18
- *
19
- * ```css
20
- * @keyframes fadein {
21
- * 0% {
22
- * opacity: 0;
23
- * }
24
- * 100% {
25
- * opacity: 1;
26
- * }
27
- * }
28
- *
29
- * .fadein {
30
- * animation-duration: 250ms;
31
- * animation-name: fadein;
32
- * animation-delay: 0.5s;
33
- * }
34
- * ```
35
- *
36
- * @param id - animation name
37
- * @param opts - animation config options
38
- * @param keyframes - keyframes
39
- */
40
- export const animation = (id, opts, ...keyframes) => {
41
- opts = {
42
- duration: "250ms",
43
- name: id,
44
- ...opts,
45
- };
46
- return [
47
- at_keyframes.apply(null, [id, ...keyframes]),
48
- [
49
- `.${id}`,
50
- Object.keys(opts).reduce((acc, k) => ((acc[`animation-${k}`] = opts[k]), acc), {}),
51
- ],
52
- ];
2
+ const animation = (id, opts, ...keyframes) => {
3
+ opts = {
4
+ duration: "250ms",
5
+ name: id,
6
+ ...opts
7
+ };
8
+ return [
9
+ at_keyframes.apply(null, [id, ...keyframes]),
10
+ [
11
+ `.${id}`,
12
+ Object.keys(opts).reduce(
13
+ (acc, k) => (acc[`animation-${k}`] = opts[k], acc),
14
+ {}
15
+ )
16
+ ]
17
+ ];
18
+ };
19
+ export {
20
+ animation
53
21
  };
package/api.js CHANGED
@@ -1,30 +1,26 @@
1
- export const DEFAULT_VENDORS = ["-moz-", "-ms-", "-o-", "-webkit-"];
2
- /**
3
- * Default format config used by {@link css} function.
4
- * Forms "minimized" CSS without obsolete white space
5
- * and omits comments unless they were forced.
6
- */
7
- export const COMPACT = {
8
- rules: "",
9
- ruleSep: ",",
10
- valSep: "",
11
- decls: "",
12
- declStart: "{",
13
- declEnd: "}",
14
- indent: "",
15
- comments: false,
1
+ const DEFAULT_VENDORS = ["-moz-", "-ms-", "-o-", "-webkit-"];
2
+ const COMPACT = {
3
+ rules: "",
4
+ ruleSep: ",",
5
+ valSep: "",
6
+ decls: "",
7
+ declStart: "{",
8
+ declEnd: "}",
9
+ indent: "",
10
+ comments: false
16
11
  };
17
- /**
18
- * Pretty printing format config with line breaks
19
- * and indentation.
20
- */
21
- export const PRETTY = {
22
- rules: "\n",
23
- ruleSep: ", ",
24
- valSep: " ",
25
- decls: "\n",
26
- declStart: " {\n",
27
- declEnd: "}\n",
28
- indent: " ",
29
- comments: true,
12
+ const PRETTY = {
13
+ rules: "\n",
14
+ ruleSep: ", ",
15
+ valSep: " ",
16
+ decls: "\n",
17
+ declStart: " {\n",
18
+ declEnd: "}\n",
19
+ indent: " ",
20
+ comments: true
21
+ };
22
+ export {
23
+ COMPACT,
24
+ DEFAULT_VENDORS,
25
+ PRETTY
30
26
  };
package/attribs.js CHANGED
@@ -1,46 +1,15 @@
1
1
  const $ = (op) => (id, x, caseSensitve = false) => `[${id}${op}="${x}"${caseSensitve ? " i" : ""}]`;
2
- /**
3
- * Returns attrib selector: `[id]`
4
- *
5
- * @param id -
6
- */
7
- export const withAttrib = (id) => `[${id}]`;
8
- /**
9
- * Returns attrib selector `[id=x]`
10
- *
11
- * @param id -
12
- * @param x -
13
- * @param caseSensitive -
14
- */
15
- export const attribEq = $("");
16
- /**
17
- * Returns attrib selector `[id~=x]`
18
- *
19
- * @param id -
20
- * @param x -
21
- * @param caseSensitive -
22
- */
23
- export const attribContains = $("~");
24
- /**
25
- * Returns attrib selector `[id^=x]`
26
- *
27
- * @param id -
28
- * @param x -
29
- * @param caseSensitive -
30
- */
31
- export const attribPrefix = $("^");
32
- /**
33
- * Returns attrib selector `[id$=x]`
34
- *
35
- * @param id -
36
- * @param x -
37
- * @param caseSensitive -
38
- */
39
- export const attribSuffix = $("$");
40
- /**
41
- * Returns attrib selector `[id*=x]`
42
- * @param id -
43
- * @param x -
44
- * @param caseSensitive -
45
- */
46
- export const attribMatches = $("*");
2
+ const withAttrib = (id) => `[${id}]`;
3
+ const attribEq = $("");
4
+ const attribContains = $("~");
5
+ const attribPrefix = $("^");
6
+ const attribSuffix = $("$");
7
+ const attribMatches = $("*");
8
+ export {
9
+ attribContains,
10
+ attribEq,
11
+ attribMatches,
12
+ attribPrefix,
13
+ attribSuffix,
14
+ withAttrib
15
+ };
package/comment.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import { indent } from "./impl.js";
2
- export const comment = (body, force = false) => (acc, opts) => {
3
- const space = indent(opts);
4
- const inner = indent(opts, opts.depth + 1);
5
- if (opts.format.comments || force) {
6
- acc.push(space + "/*", body
7
- .split("\n")
8
- .map((l) => inner + l)
9
- .join("\n"), space + "*/");
10
- }
11
- return acc;
2
+ const comment = (body, force = false) => (acc, opts) => {
3
+ const space = indent(opts);
4
+ const inner = indent(opts, opts.depth + 1);
5
+ if (opts.format.comments || force) {
6
+ acc.push(
7
+ space + "/*",
8
+ body.split("\n").map((l) => inner + l).join("\n"),
9
+ space + "*/"
10
+ );
11
+ }
12
+ return acc;
13
+ };
14
+ export {
15
+ comment
12
16
  };
package/conditional.js CHANGED
@@ -1,36 +1,37 @@
1
1
  import { isString } from "@thi.ng/checks/is-string";
2
2
  import { expand, indent } from "./impl.js";
3
- export const conditional = (type, cond, rules) => (acc, opts) => {
4
- const space = indent(opts);
5
- acc.push(`${space}${type} ${formatCond(cond)}${opts.format.declStart}`);
6
- opts.depth++;
7
- expand(acc, [], rules, opts);
8
- opts.depth--;
9
- acc.push(space + opts.format.declEnd);
10
- return acc;
3
+ const conditional = (type, cond, rules) => (acc, opts) => {
4
+ const space = indent(opts);
5
+ acc.push(`${space}${type} ${formatCond(cond)}${opts.format.declStart}`);
6
+ opts.depth++;
7
+ expand(acc, [], rules, opts);
8
+ opts.depth--;
9
+ acc.push(space + opts.format.declEnd);
10
+ return acc;
11
11
  };
12
12
  const formatCond = (cond) => {
13
- if (isString(cond)) {
14
- return cond;
13
+ if (isString(cond)) {
14
+ return cond;
15
+ }
16
+ const acc = [];
17
+ for (let c in cond) {
18
+ if (cond.hasOwnProperty(c)) {
19
+ let v = cond[c];
20
+ if (v === true) {
21
+ v = MEDIA_TYPES.has(c) ? c : `(${c})`;
22
+ } else if (v === false) {
23
+ v = "not " + (MEDIA_TYPES.has(c) ? c : `(${c})`);
24
+ } else if (v === "only") {
25
+ v += " " + c;
26
+ } else {
27
+ v = `(${c}:${v})`;
28
+ }
29
+ acc.push(v);
15
30
  }
16
- const acc = [];
17
- for (let c in cond) {
18
- if (cond.hasOwnProperty(c)) {
19
- let v = cond[c];
20
- if (v === true) {
21
- v = c;
22
- }
23
- else if (v === false) {
24
- v = "not " + c;
25
- }
26
- else if (v === "only") {
27
- v += " " + c;
28
- }
29
- else {
30
- v = `(${c}:${v})`;
31
- }
32
- acc.push(v);
33
- }
34
- }
35
- return acc.join(" and ");
31
+ }
32
+ return acc.join(" and ");
33
+ };
34
+ const MEDIA_TYPES = /* @__PURE__ */ new Set(["all", "print", "screen"]);
35
+ export {
36
+ conditional
36
37
  };
package/css.js CHANGED
@@ -5,22 +5,22 @@ import { isPlainObject } from "@thi.ng/checks/is-plain-object";
5
5
  import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
6
6
  import { COMPACT, DEFAULT_VENDORS } from "./api.js";
7
7
  import { expand, formatDecls } from "./impl.js";
8
- export const css = (rules, opts) => {
9
- opts = {
10
- format: COMPACT,
11
- vendors: DEFAULT_VENDORS,
12
- fns: {},
13
- depth: 0,
14
- ...opts,
15
- };
16
- isArray(opts.autoprefix) && (opts.autoprefix = new Set(opts.autoprefix));
17
- return isPlainObject(rules)
18
- ? formatDecls(rules, opts)
19
- : isFunction(rules)
20
- ? rules([], opts).join(opts.format.rules)
21
- : expand([], [], isArray(rules)
22
- ? rules
23
- : isNotStringAndIterable(rules)
24
- ? [...rules]
25
- : illegalArgs(`invalid rules`), opts).join(opts.format.rules);
8
+ const css = (rules, opts) => {
9
+ opts = {
10
+ format: COMPACT,
11
+ vendors: DEFAULT_VENDORS,
12
+ fns: {},
13
+ depth: 0,
14
+ ...opts
15
+ };
16
+ isArray(opts.autoprefix) && (opts.autoprefix = new Set(opts.autoprefix));
17
+ return isPlainObject(rules) ? formatDecls(rules, opts) : isFunction(rules) ? rules([], opts).join(opts.format.rules) : expand(
18
+ [],
19
+ [],
20
+ isArray(rules) ? rules : isNotStringAndIterable(rules) ? [...rules] : illegalArgs(`invalid rules`),
21
+ opts
22
+ ).join(opts.format.rules);
23
+ };
24
+ export {
25
+ css
26
26
  };
package/impl.js CHANGED
@@ -11,97 +11,99 @@ import { permutations } from "@thi.ng/transducers/permutations";
11
11
  import { repeat } from "@thi.ng/transducers/repeat";
12
12
  import { str } from "@thi.ng/transducers/str";
13
13
  import { transduce } from "@thi.ng/transducers/transduce";
14
- const EMPTY = new Set();
14
+ const EMPTY = /* @__PURE__ */ new Set();
15
15
  const NO_SPACES = ":[";
16
- const xfSel = comp(flatten(), map((x) => (NO_SPACES.indexOf(x.charAt(0)) >= 0 ? x : " " + x)));
17
- const withScope = (xf, scope) => comp(xf, map((x) => (isString(x) && x.indexOf(" .") == 0 ? x + scope : x)));
18
- /** @internal */
19
- export const expand = (acc, parent, rules, opts) => {
20
- const n = rules.length;
21
- const sel = [];
22
- let curr, isFn;
23
- const process = (i, r) => {
24
- let rfn = null;
25
- if (isArray(r)) {
26
- expand(acc, makeSelector(parent, sel), r, opts);
27
- }
28
- else if (isIterable(r) && !isString(r)) {
29
- expand(acc, makeSelector(parent, sel), [...r], opts);
30
- }
31
- else if ((isFn = isFunction(r)) || (rfn = opts.fns[r])) {
32
- if (!parent.length) {
33
- if (rfn) {
34
- rfn.apply(null, rules.slice(i + 1))(acc, opts);
35
- return true;
36
- }
37
- r(acc, opts);
38
- }
39
- else if (isFn) {
40
- process(i, r());
41
- }
42
- else {
43
- illegalArgs(`quoted fn ('${r}') only allowed at head position`);
44
- }
45
- }
46
- else if (isPlainObject(r)) {
47
- curr = Object.assign(curr || {}, r);
48
- }
49
- else if (r != null) {
50
- sel.push(r);
51
- }
52
- };
53
- for (let i = 0; i < n; i++) {
54
- if (process(i, rules[i])) {
55
- return acc;
16
+ const xfSel = comp(
17
+ flatten(),
18
+ map((x) => NO_SPACES.indexOf(x.charAt(0)) >= 0 ? x : " " + x)
19
+ );
20
+ const withScope = (xf, scope) => comp(
21
+ xf,
22
+ map((x) => isString(x) && x.indexOf(" .") == 0 ? x + scope : x)
23
+ );
24
+ const expand = (acc, parent, rules, opts) => {
25
+ const n = rules.length;
26
+ const sel = [];
27
+ let curr, isFn;
28
+ const process = (i, r) => {
29
+ let rfn = null;
30
+ if (isArray(r)) {
31
+ expand(acc, makeSelector(parent, sel), r, opts);
32
+ } else if (isIterable(r) && !isString(r)) {
33
+ expand(acc, makeSelector(parent, sel), [...r], opts);
34
+ } else if ((isFn = isFunction(r)) || (rfn = opts.fns[r])) {
35
+ if (!parent.length) {
36
+ if (rfn) {
37
+ rfn.apply(null, rules.slice(i + 1))(acc, opts);
38
+ return true;
56
39
  }
40
+ r(acc, opts);
41
+ } else if (isFn) {
42
+ process(i, r());
43
+ } else {
44
+ illegalArgs(`quoted fn ('${r}') only allowed at head position`);
45
+ }
46
+ } else if (isPlainObject(r)) {
47
+ curr = Object.assign(curr || {}, r);
48
+ } else if (r != null) {
49
+ sel.push(r);
50
+ }
51
+ };
52
+ for (let i = 0; i < n; i++) {
53
+ if (process(i, rules[i])) {
54
+ return acc;
57
55
  }
58
- curr && acc.push(formatRule(parent, sel, curr, opts));
59
- return acc;
56
+ }
57
+ curr && acc.push(formatRule(parent, sel, curr, opts));
58
+ return acc;
60
59
  };
61
60
  const makeSelector = (parent, curr) => parent.length ? [...permutations(parent, curr)] : curr;
62
61
  const formatRule = (parent, sel, curr, opts) => {
63
- const f = opts.format;
64
- const space = indent(opts);
65
- const xf = opts.scope ? withScope(xfSel, opts.scope) : xfSel;
66
- return [
67
- space,
68
- transduce(map((sel) => transduce(xf, str(), isArray(sel) ? sel : [sel]).trim()), str(f.ruleSep), makeSelector(parent, sel)),
69
- f.declStart,
70
- formatDecls(curr, opts),
71
- space,
72
- f.declEnd,
73
- ].join("");
62
+ const f = opts.format;
63
+ const space = indent(opts);
64
+ const xf = opts.scope ? withScope(xfSel, opts.scope) : xfSel;
65
+ return [
66
+ space,
67
+ transduce(
68
+ map(
69
+ (sel2) => transduce(xf, str(), isArray(sel2) ? sel2 : [sel2]).trim()
70
+ ),
71
+ str(f.ruleSep),
72
+ makeSelector(parent, sel)
73
+ ),
74
+ f.declStart,
75
+ formatDecls(curr, opts),
76
+ space,
77
+ f.declEnd
78
+ ].join("");
74
79
  };
75
- /** @internal */
76
- export const formatDecls = (rules, opts) => {
77
- const f = opts.format;
78
- const prefixes = (opts.autoprefix || EMPTY);
79
- const space = indent(opts, opts.depth + 1);
80
- const acc = [];
81
- for (let r in rules) {
82
- if (rules.hasOwnProperty(r)) {
83
- let val = rules[r];
84
- if (isFunction(val)) {
85
- val = val(rules);
86
- }
87
- if (isArray(val)) {
88
- val = val
89
- .map((v) => (isArray(v) ? v.join(" ") : v))
90
- .join(f.ruleSep);
91
- }
92
- if (prefixes.has(r)) {
93
- for (let v of opts.vendors) {
94
- acc.push(`${space}${v}${r}:${f.valSep}${val};`);
95
- }
96
- }
97
- acc.push(`${space}${r}:${f.valSep}${val};`);
80
+ const formatDecls = (rules, opts) => {
81
+ const f = opts.format;
82
+ const prefixes = opts.autoprefix || EMPTY;
83
+ const space = indent(opts, opts.depth + 1);
84
+ const acc = [];
85
+ for (let r in rules) {
86
+ if (rules.hasOwnProperty(r)) {
87
+ let val = rules[r];
88
+ if (isFunction(val)) {
89
+ val = val(rules);
90
+ }
91
+ if (isArray(val)) {
92
+ val = val.map((v) => isArray(v) ? v.join(" ") : v).join(f.ruleSep);
93
+ }
94
+ if (prefixes.has(r)) {
95
+ for (let v of opts.vendors) {
96
+ acc.push(`${space}${v}${r}:${f.valSep}${val};`);
98
97
  }
98
+ }
99
+ acc.push(`${space}${r}:${f.valSep}${val};`);
99
100
  }
100
- return acc.join(f.decls) + f.decls;
101
+ }
102
+ return acc.join(f.decls) + f.decls;
103
+ };
104
+ const indent = (opts, d = opts.depth) => d > 1 ? [...repeat(opts.format.indent, d)].join("") : d > 0 ? opts.format.indent : "";
105
+ export {
106
+ expand,
107
+ formatDecls,
108
+ indent
101
109
  };
102
- /** @internal */
103
- export const indent = (opts, d = opts.depth) => d > 1
104
- ? [...repeat(opts.format.indent, d)].join("")
105
- : d > 0
106
- ? opts.format.indent
107
- : "";
package/import.js CHANGED
@@ -1,4 +1,6 @@
1
- export const at_import = (url, ...queries) => (acc, opts) => (acc.push(queries.length
2
- ? `@import url(${url}) ${queries.join(opts.format.ruleSep)};`
3
- : `@import url(${url});`),
4
- acc);
1
+ const at_import = (url, ...queries) => (acc, opts) => (acc.push(
2
+ queries.length ? `@import url(${url}) ${queries.join(opts.format.ruleSep)};` : `@import url(${url});`
3
+ ), acc);
4
+ export {
5
+ at_import
6
+ };
package/inject.js CHANGED
@@ -1,28 +1,19 @@
1
- // https://davidwalsh.name/add-rules-stylesheets
2
- /**
3
- * Injects given CSS string as global stylesheet in DOM head. If `first`
4
- * is true, inserts it as first stylesheet, else (default) appends it.
5
- *
6
- * Returns created style DOM element.
7
- *
8
- * @param css - CSS string
9
- * @param first - true, if prepend to stylesheet list (else append)
10
- */
11
- export const injectStyleSheet = (css, first = false) => {
12
- const head = document.getElementsByTagName("head")[0];
13
- const sheet = document.createElement("style");
14
- sheet.setAttribute("type", "text/css");
15
- if (sheet.styleSheet !== undefined) {
16
- sheet.styleSheet.cssText = css;
17
- }
18
- else {
19
- sheet.textContent = css;
20
- }
21
- if (first) {
22
- head.insertBefore(sheet, head.firstChild);
23
- }
24
- else {
25
- head.appendChild(sheet);
26
- }
27
- return sheet;
1
+ const injectStyleSheet = (css, first = false) => {
2
+ const head = document.getElementsByTagName("head")[0];
3
+ const sheet = document.createElement("style");
4
+ sheet.setAttribute("type", "text/css");
5
+ if (sheet.styleSheet !== void 0) {
6
+ sheet.styleSheet.cssText = css;
7
+ } else {
8
+ sheet.textContent = css;
9
+ }
10
+ if (first) {
11
+ head.insertBefore(sheet, head.firstChild);
12
+ } else {
13
+ head.appendChild(sheet);
14
+ }
15
+ return sheet;
16
+ };
17
+ export {
18
+ injectStyleSheet
28
19
  };
package/keyframes.js CHANGED
@@ -1,25 +1,30 @@
1
1
  import { formatDecls, indent } from "./impl.js";
2
- export function at_keyframes(id, ...args) {
3
- const stops = args.length === 1 ? args[0] : { 0: args[0], 100: args[1] };
4
- return (acc, opts) => {
5
- const outer = indent(opts);
6
- opts.depth++;
7
- const inner = indent(opts);
8
- acc.push(`${outer}@keyframes ${id}${opts.format.declStart}`);
9
- for (let s in stops) {
10
- if (stops.hasOwnProperty(s)) {
11
- acc.push([
12
- inner,
13
- s + "%",
14
- opts.format.declStart,
15
- formatDecls(stops[s], opts),
16
- inner,
17
- opts.format.declEnd,
18
- ].join(""));
19
- }
20
- }
21
- opts.depth--;
22
- acc.push(outer + opts.format.declEnd);
23
- return acc;
24
- };
2
+ function at_keyframes(id, ...args) {
3
+ const stops = args.length === 1 ? args[0] : { 0: args[0], 100: args[1] };
4
+ return (acc, opts) => {
5
+ const outer = indent(opts);
6
+ opts.depth++;
7
+ const inner = indent(opts);
8
+ acc.push(`${outer}@keyframes ${id}${opts.format.declStart}`);
9
+ for (let s in stops) {
10
+ if (stops.hasOwnProperty(s)) {
11
+ acc.push(
12
+ [
13
+ inner,
14
+ s + "%",
15
+ opts.format.declStart,
16
+ formatDecls(stops[s], opts),
17
+ inner,
18
+ opts.format.declEnd
19
+ ].join("")
20
+ );
21
+ }
22
+ }
23
+ opts.depth--;
24
+ acc.push(outer + opts.format.declEnd);
25
+ return acc;
26
+ };
25
27
  }
28
+ export {
29
+ at_keyframes
30
+ };
package/media.js CHANGED
@@ -1,2 +1,5 @@
1
1
  import { conditional } from "./conditional.js";
2
- export const at_media = (cond, rules) => conditional("@media", cond, rules);
2
+ const at_media = (cond, rules) => conditional("@media", cond, rules);
3
+ export {
4
+ at_media
5
+ };
package/namespace.js CHANGED
@@ -1,6 +1,8 @@
1
- export function at_namespace(...args) {
2
- return (acc, _) => (acc.push(args.length > 1
3
- ? `@namespace ${args[0]} url(${args[1]});`
4
- : `@namespace url(${args[0]});`),
5
- acc);
1
+ function at_namespace(...args) {
2
+ return (acc, _) => (acc.push(
3
+ args.length > 1 ? `@namespace ${args[0]} url(${args[1]});` : `@namespace url(${args[0]});`
4
+ ), acc);
6
5
  }
6
+ export {
7
+ at_namespace
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hiccup-css",
3
- "version": "2.2.19",
3
+ "version": "2.3.0",
4
4
  "description": "CSS from nested JS data structures",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,13 +35,14 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/checks": "^3.4.11",
38
- "@thi.ng/errors": "^2.4.5",
39
- "@thi.ng/transducers": "^8.8.14"
38
+ "@thi.ng/api": "^8.9.13",
39
+ "@thi.ng/checks": "^3.4.13",
40
+ "@thi.ng/errors": "^2.4.7",
41
+ "@thi.ng/transducers": "^8.8.16"
40
42
  },
41
43
  "devDependencies": {
42
44
  "@microsoft/api-extractor": "^7.38.3",
45
+ "esbuild": "^0.19.8",
43
46
  "rimraf": "^5.0.5",
44
47
  "tools": "^0.0.1",
45
48
  "typedoc": "^0.25.4",
@@ -55,7 +58,6 @@
55
58
  "export",
56
59
  "fileformat",
57
60
  "hiccup",
58
- "iterator",
59
61
  "json",
60
62
  "typescript",
61
63
  "ui"
@@ -64,7 +66,7 @@
64
66
  "access": "public"
65
67
  },
66
68
  "engines": {
67
- "node": ">=12.7"
69
+ "node": ">=18"
68
70
  },
69
71
  "files": [
70
72
  "./*.js",
@@ -125,5 +127,5 @@
125
127
  ],
126
128
  "year": 2016
127
129
  },
128
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
130
+ "gitHead": "25a42a81fac8603a1e440a7aa8bc343276211ff4\n"
129
131
  }
@@ -4,12 +4,14 @@ import { at_keyframes } from "./keyframes.js";
4
4
  import { at_media } from "./media.js";
5
5
  import { at_namespace } from "./namespace.js";
6
6
  import { at_supports } from "./supports.js";
7
- /** @internal */
8
- export const QUOTED_FNS = {
9
- "@comment": comment,
10
- "@import": at_import,
11
- "@keyframes": at_keyframes,
12
- "@media": at_media,
13
- "@namespace": at_namespace,
14
- "@supports": at_supports,
7
+ const QUOTED_FNS = {
8
+ "@comment": comment,
9
+ "@import": at_import,
10
+ "@keyframes": at_keyframes,
11
+ "@media": at_media,
12
+ "@namespace": at_namespace,
13
+ "@supports": at_supports
14
+ };
15
+ export {
16
+ QUOTED_FNS
15
17
  };
package/supports.js CHANGED
@@ -1,2 +1,5 @@
1
1
  import { conditional } from "./conditional.js";
2
- export const at_supports = (cond, rules) => conditional("@supports", cond, rules);
2
+ const at_supports = (cond, rules) => conditional("@supports", cond, rules);
3
+ export {
4
+ at_supports
5
+ };
package/units.js CHANGED
@@ -1,28 +1,39 @@
1
- export let PRECISION = 4;
2
- /**
3
- * Sets the number of fractional digits used for formatting various floating
4
- * point values in the serialized SVG. The current value can be read via
5
- * {@link PRECISION}.
6
- *
7
- * @param n
8
- */
9
- export const setPrecision = (n) => (PRECISION = n);
10
- /** @internal */
11
- const ff = (x) => (x === (x | 0) ? String(x) : x.toFixed(PRECISION));
12
- export const em = (x) => `${ff(x)}em`;
13
- export const ex = (x) => `${ff(x)}ex`;
14
- export const rem = (x) => `${ff(x)}rem`;
15
- export const percent = (x) => `${ff(x)}%`;
16
- export const px = (x) => `${ff(x)}px`;
17
- export const vh = (x) => `${ff(x)}vh`;
18
- export const vw = (x) => `${ff(x)}vw`;
19
- export const vmin = (x) => `${ff(x)}vmin`;
20
- export const vmax = (x) => `${ff(x)}vmax`;
21
- export const ms = (x) => `${x | 0}ms`;
22
- export const second = (x) => `${ff(x)}s`;
23
- /** @deprecated use {@link second} */
24
- export const sec = second;
25
- export const deg = (x) => `${ff(x)}deg`;
26
- export const rad = (x) => `${ff(x)}rad`;
27
- export const turn = (x) => `${ff(x)}turn`;
28
- export const url = (x) => `url(${x})`;
1
+ let PRECISION = 4;
2
+ const setPrecision = (n) => PRECISION = n;
3
+ const ff = (x) => x === (x | 0) ? String(x) : x.toFixed(PRECISION).replace(/^0./, ".").replace(/0+$/, "");
4
+ const em = (x) => `${ff(x)}em`;
5
+ const ex = (x) => `${ff(x)}ex`;
6
+ const rem = (x) => `${ff(x)}rem`;
7
+ const percent = (x) => `${ff(x)}%`;
8
+ const px = (x) => `${ff(x)}px`;
9
+ const vh = (x) => `${ff(x)}vh`;
10
+ const vw = (x) => `${ff(x)}vw`;
11
+ const vmin = (x) => `${ff(x)}vmin`;
12
+ const vmax = (x) => `${ff(x)}vmax`;
13
+ const ms = (x) => `${x | 0}ms`;
14
+ const second = (x) => `${ff(x)}s`;
15
+ const sec = second;
16
+ const deg = (x) => `${ff(x)}deg`;
17
+ const rad = (x) => `${ff(x)}rad`;
18
+ const turn = (x) => `${ff(x)}turn`;
19
+ const url = (x) => `url(${x})`;
20
+ export {
21
+ PRECISION,
22
+ deg,
23
+ em,
24
+ ex,
25
+ ms,
26
+ percent,
27
+ px,
28
+ rad,
29
+ rem,
30
+ sec,
31
+ second,
32
+ setPrecision,
33
+ turn,
34
+ url,
35
+ vh,
36
+ vmax,
37
+ vmin,
38
+ vw
39
+ };