@thi.ng/hiccup 5.2.1 → 5.2.2

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**: 2024-05-08T18:24:32Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
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,12 @@ 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
+ ### [5.2.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.2.2) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
17
+
12
18
  ## [5.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.2.0) (2024-04-25)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
package/api.js CHANGED
@@ -20,14 +20,14 @@ const NO_SPANS = {
20
20
  textarea: 1,
21
21
  title: 1
22
22
  };
23
- const tagMap = (tags) => tags.split(" ").reduce((acc, x) => (acc[x] = true, acc), {});
24
- const SVG_TAGS = tagMap(
23
+ const __tagMap = (tags) => tags.split(" ").reduce((acc, x) => (acc[x] = true, acc), {});
24
+ const SVG_TAGS = __tagMap(
25
25
  "animate animateColor animateMotion animateTransform circle clipPath color-profile defs desc discard ellipse feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feDropShadow feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence filter font foreignObject g image line linearGradient marker mask metadata mpath path pattern polygon polyline radialGradient rect set stop style svg switch symbol text textPath title tref tspan use view"
26
26
  );
27
- const VOID_TAGS = tagMap(
27
+ const VOID_TAGS = __tagMap(
28
28
  "area base br col command embed hr img input keygen link meta param source stop track use wbr ?xml"
29
29
  );
30
- const NO_CLOSE_EMPTY = tagMap(
30
+ const NO_CLOSE_EMPTY = __tagMap(
31
31
  "animate circle ellipse line path polygon polyline rect"
32
32
  );
33
33
  const ATTRIB_JOIN_DELIMS = {
package/attribs.d.ts CHANGED
@@ -14,16 +14,22 @@
14
14
  * indicate if the class should be added or removed from the existing set.
15
15
  *
16
16
  * @example
17
- * ```ts
17
+ * ```ts tangle:../export/merge-classes.ts
18
18
  * import { mergeClasses } from "@thi.ng/hiccup";
19
19
  *
20
- * mergeClasses("foo bar", { foo: false, baz: true })
20
+ * console.log(
21
+ * mergeClasses("foo bar", { foo: false, baz: true })
22
+ * );
21
23
  * // "bar baz"
22
24
  *
23
- * mergeClasses("foo", ["bar", "baz"]);
25
+ * console.log(
26
+ * mergeClasses("foo", ["bar", "baz"])
27
+ * );
24
28
  * // "foo bar baz"
25
29
  *
26
- * mergeClasses("foo bar", "baz");
30
+ * console.log(
31
+ * mergeClasses("foo bar", "baz")
32
+ * );
27
33
  * // "foo bar baz"
28
34
  * ```
29
35
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hiccup",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "description": "HTML/SVG/XML serialization of nested data structures, iterables & closures",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/hiccup#readme",
13
+ "homepage": "https://thi.ng/hiccup",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,17 +36,17 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.2",
40
- "@thi.ng/checks": "^3.6.4",
41
- "@thi.ng/errors": "^2.5.7",
42
- "@thi.ng/strings": "^3.7.33"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/checks": "^3.6.5",
41
+ "@thi.ng/errors": "^2.5.8",
42
+ "@thi.ng/strings": "^3.7.34"
43
43
  },
44
44
  "devDependencies": {
45
- "@microsoft/api-extractor": "^7.43.2",
46
- "@thi.ng/atom": "^5.3.0",
47
- "esbuild": "^0.21.1",
45
+ "@microsoft/api-extractor": "^7.47.0",
46
+ "@thi.ng/atom": "^5.3.1",
47
+ "esbuild": "^0.21.5",
48
48
  "typedoc": "^0.25.13",
49
- "typescript": "^5.4.5"
49
+ "typescript": "^5.5.2"
50
50
  },
51
51
  "keywords": [
52
52
  "array",
@@ -128,5 +128,5 @@
128
128
  ],
129
129
  "year": 2016
130
130
  },
131
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
131
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
132
132
  }
package/prefix.d.ts CHANGED
@@ -3,11 +3,13 @@
3
3
  * the RDFa `prefix` attribute.
4
4
  *
5
5
  * @example
6
- * ```ts
6
+ * ```ts tangle:../export/format-prefixes.ts
7
7
  * import { formatPrefixes } from "@thi.ng/hiccup";
8
8
  * import { foaf, xsd } from "@thi.ng/prefixes";
9
9
  *
10
- * formatPrefixes({ foaf, xsd })
10
+ * console.log(
11
+ * formatPrefixes({ foaf, xsd })
12
+ * );
11
13
  * // "foaf: http://xmlns.com/foaf/0.1/ rdf: http://www.w3.org/2001/XMLSchema#"
12
14
  * ```
13
15
  *
package/serialize.js CHANGED
@@ -29,43 +29,43 @@ const serialize = (tree, opts, path = [0]) => {
29
29
  ...opts
30
30
  };
31
31
  if (opts?.keys == null && $opts.span) $opts.keys = true;
32
- return _serialize(tree, $opts, path);
32
+ return __serialize(tree, $opts, path);
33
33
  };
34
- const _serialize = (tree, opts, path) => tree == null ? "" : Array.isArray(tree) ? serializeElement(tree, opts, path) : isFunction(tree) ? _serialize(tree(opts.ctx), opts, path) : implementsFunction(tree, "toHiccup") ? _serialize(tree.toHiccup(opts.ctx), opts, path) : isDeref(tree) ? _serialize(tree.deref(), opts, path) : isNotStringAndIterable(tree) ? serializeIter(tree, opts, path) : (tree = __escape(String(tree), opts), opts.span) ? `<span${opts.keys ? ` key="${path.join("-")}"` : ""}>${tree}</span>` : tree;
35
- const serializeElement = (tree, opts, path) => {
34
+ const __serialize = (tree, opts, path) => tree == null ? "" : Array.isArray(tree) ? __serializeElement(tree, opts, path) : isFunction(tree) ? __serialize(tree(opts.ctx), opts, path) : implementsFunction(tree, "toHiccup") ? __serialize(tree.toHiccup(opts.ctx), opts, path) : isDeref(tree) ? __serialize(tree.deref(), opts, path) : isNotStringAndIterable(tree) ? __serializeIter(tree, opts, path) : (tree = __escape(String(tree), opts), opts.span) ? `<span${opts.keys ? ` key="${path.join("-")}"` : ""}>${tree}</span>` : tree;
35
+ const __serializeElement = (tree, opts, path) => {
36
36
  let tag = tree[0];
37
- return !tree.length ? "" : isFunction(tag) ? _serialize(tag.apply(null, [opts.ctx, ...tree.slice(1)]), opts, path) : implementsFunction(tag, "render") ? _serialize(
37
+ return !tree.length ? "" : isFunction(tag) ? __serialize(tag.apply(null, [opts.ctx, ...tree.slice(1)]), opts, path) : implementsFunction(tag, "render") ? __serialize(
38
38
  tag.render.apply(null, [opts.ctx, ...tree.slice(1)]),
39
39
  opts,
40
40
  path
41
- ) : tag === COMMENT ? serializeComment(tree) : tag == CDATA ? serializeCData(tree) : isString(tag) ? serializeTag(tree, opts, path) : isNotStringAndIterable(tree) ? serializeIter(tree, opts, path) : illegalArgs(`invalid tree node: ${tree}`);
41
+ ) : tag === COMMENT ? __serializeComment(tree) : tag == CDATA ? __serializeCData(tree) : isString(tag) ? __serializeTag(tree, opts, path) : isNotStringAndIterable(tree) ? __serializeIter(tree, opts, path) : illegalArgs(`invalid tree node: ${tree}`);
42
42
  };
43
- const serializeTag = (tree, opts, path) => {
43
+ const __serializeTag = (tree, opts, path) => {
44
44
  tree = normalize(tree);
45
45
  const attribs = tree[1];
46
46
  if (attribs.__skip || attribs.__serialize === false) return "";
47
47
  opts.keys && attribs.key === void 0 && (attribs.key = path.join("-"));
48
48
  const tag = tree[0];
49
- const body = tree[2] ? serializeBody(tag, tree[2], opts, path) : !VOID_TAGS[tag] && !NO_CLOSE_EMPTY[tag] ? `></${tag}>` : PROC_TAGS[tag] || "/>";
50
- return `<${tag}${serializeAttribs(attribs, opts)}${body}`;
49
+ const body = tree[2] ? __serializeBody(tag, tree[2], opts, path) : !VOID_TAGS[tag] && !NO_CLOSE_EMPTY[tag] ? `></${tag}>` : PROC_TAGS[tag] || "/>";
50
+ return `<${tag}${__serializeAttribs(attribs, opts)}${body}`;
51
51
  };
52
- const serializeAttribs = (attribs, opts) => {
52
+ const __serializeAttribs = (attribs, opts) => {
53
53
  let res = "";
54
54
  for (let a in attribs) {
55
55
  if (a.startsWith("__")) continue;
56
- const v = serializeAttrib(attribs, a, deref(attribs[a]), opts);
56
+ const v = __serializeAttrib(attribs, a, deref(attribs[a]), opts);
57
57
  v != null && (res += v);
58
58
  }
59
59
  return res;
60
60
  };
61
- const serializeAttrib = (attribs, a, v, opts) => {
62
- return v == null ? null : isFunction(v) && (/^on\w+/.test(a) || (v = v(attribs)) == null) ? null : v === true ? " " + a + (opts.xml ? `=""` : "") : v === false ? null : a === "data" ? serializeDataAttribs(v, opts) : attribPair(a, v, opts);
61
+ const __serializeAttrib = (attribs, a, v, opts) => {
62
+ return v == null ? null : isFunction(v) && (/^on\w+/.test(a) || (v = v(attribs)) == null) ? null : v === true ? " " + a + (opts.xml ? `=""` : "") : v === false ? null : a === "data" ? __serializeDataAttribs(v, opts) : __attribPair(a, v, opts);
63
63
  };
64
- const attribPair = (a, v, opts) => {
64
+ const __attribPair = (a, v, opts) => {
65
65
  v = a === "style" && isPlainObject(v) ? css(v) : a === "prefix" && isPlainObject(v) ? formatPrefixes(v) : isArray(v) ? v.join(ATTRIB_JOIN_DELIMS[a] || " ") : v.toString();
66
66
  return v.length ? ` ${a}="${__escape(v, opts)}"` : null;
67
67
  };
68
- const serializeDataAttribs = (data, opts) => {
68
+ const __serializeDataAttribs = (data, opts) => {
69
69
  let res = "";
70
70
  for (let id in data) {
71
71
  let v = deref(data[id]);
@@ -74,7 +74,7 @@ const serializeDataAttribs = (data, opts) => {
74
74
  }
75
75
  return res;
76
76
  };
77
- const serializeBody = (tag, body, opts, path) => {
77
+ const __serializeBody = (tag, body, opts, path) => {
78
78
  if (VOID_TAGS[tag]) {
79
79
  illegalArgs(`No body allowed in tag: ${tag}`);
80
80
  }
@@ -82,26 +82,26 @@ const serializeBody = (tag, body, opts, path) => {
82
82
  let res = proc ? " " : ">";
83
83
  if (opts.span && !proc && !NO_SPANS[tag]) opts = { ...opts, span: true };
84
84
  for (let i = 0, n = body.length; i < n; i++) {
85
- res += _serialize(body[i], opts, [...path, i]);
85
+ res += __serialize(body[i], opts, [...path, i]);
86
86
  }
87
87
  return res + (proc || `</${tag}>`);
88
88
  };
89
- const serializeComment = (tree) => tree.length > 2 ? `
89
+ const __serializeComment = (tree) => tree.length > 2 ? `
90
90
  <!--
91
91
  ${tree.slice(1).map((x) => " " + x).join("\n")}
92
92
  -->
93
93
  ` : `
94
94
  <!-- ${tree[1]} -->
95
95
  `;
96
- const serializeCData = (tree) => `<![CDATA[
96
+ const __serializeCData = (tree) => `<![CDATA[
97
97
  ${tree.slice(1).join("\n")}
98
98
  ]]>`;
99
- const serializeIter = (iter, opts, path) => {
99
+ const __serializeIter = (iter, opts, path) => {
100
100
  const res = [];
101
101
  const p = path.slice(0, path.length - 1);
102
102
  let k = 0;
103
103
  for (let i of iter) {
104
- res.push(_serialize(i, opts, [...p, k++]));
104
+ res.push(__serialize(i, opts, [...p, k++]));
105
105
  }
106
106
  return res.join("");
107
107
  };