@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 +7 -1
- package/README.md +1 -1
- package/api.js +4 -4
- package/attribs.d.ts +10 -4
- package/package.json +11 -11
- package/prefix.d.ts +4 -2
- package/serialize.js +20 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
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
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
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
|
|
24
|
-
const SVG_TAGS =
|
|
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 =
|
|
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 =
|
|
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
|
-
*
|
|
20
|
+
* console.log(
|
|
21
|
+
* mergeClasses("foo bar", { foo: false, baz: true })
|
|
22
|
+
* );
|
|
21
23
|
* // "bar baz"
|
|
22
24
|
*
|
|
23
|
-
*
|
|
25
|
+
* console.log(
|
|
26
|
+
* mergeClasses("foo", ["bar", "baz"])
|
|
27
|
+
* );
|
|
24
28
|
* // "foo bar baz"
|
|
25
29
|
*
|
|
26
|
-
*
|
|
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.
|
|
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://
|
|
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.
|
|
40
|
-
"@thi.ng/checks": "^3.6.
|
|
41
|
-
"@thi.ng/errors": "^2.5.
|
|
42
|
-
"@thi.ng/strings": "^3.7.
|
|
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.
|
|
46
|
-
"@thi.ng/atom": "^5.3.
|
|
47
|
-
"esbuild": "^0.21.
|
|
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.
|
|
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": "
|
|
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
|
-
*
|
|
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
|
|
32
|
+
return __serialize(tree, $opts, path);
|
|
33
33
|
};
|
|
34
|
-
const
|
|
35
|
-
const
|
|
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) ?
|
|
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 ?
|
|
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
|
|
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] ?
|
|
50
|
-
return `<${tag}${
|
|
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
|
|
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 =
|
|
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
|
|
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" ?
|
|
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
|
|
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
|
|
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
|
|
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 +=
|
|
85
|
+
res += __serialize(body[i], opts, [...path, i]);
|
|
86
86
|
}
|
|
87
87
|
return res + (proc || `</${tag}>`);
|
|
88
88
|
};
|
|
89
|
-
const
|
|
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
|
|
96
|
+
const __serializeCData = (tree) => `<![CDATA[
|
|
97
97
|
${tree.slice(1).join("\n")}
|
|
98
98
|
]]>`;
|
|
99
|
-
const
|
|
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(
|
|
104
|
+
res.push(__serialize(i, opts, [...p, k++]));
|
|
105
105
|
}
|
|
106
106
|
return res.join("");
|
|
107
107
|
};
|