@thi.ng/hiccup 5.2.0 → 5.2.1
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/attribs.js +3 -6
- package/css.js +2 -4
- package/deref.js +2 -4
- package/package.json +11 -11
- package/serialize.js +4 -8
package/CHANGELOG.md
CHANGED
package/attribs.js
CHANGED
|
@@ -3,12 +3,9 @@ import { isArray } from "@thi.ng/checks/is-array";
|
|
|
3
3
|
import { isString } from "@thi.ng/checks/is-string";
|
|
4
4
|
const mergeClasses = (existing, val) => {
|
|
5
5
|
val = deref(val);
|
|
6
|
-
if (val == null)
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
val = val.join(" ");
|
|
10
|
-
if (isString(val))
|
|
11
|
-
return existing ? existing + " " + val : val;
|
|
6
|
+
if (val == null) return existing;
|
|
7
|
+
if (isArray(val)) val = val.join(" ");
|
|
8
|
+
if (isString(val)) return existing ? existing + " " + val : val;
|
|
12
9
|
const classes = new Set(existing ? existing.split(" ") : void 0);
|
|
13
10
|
for (let id in val) {
|
|
14
11
|
deref(val[id]) ? classes.add(id) : classes.delete(id);
|
package/css.js
CHANGED
|
@@ -5,10 +5,8 @@ const css = (rules) => {
|
|
|
5
5
|
let v;
|
|
6
6
|
for (let r in rules) {
|
|
7
7
|
v = deref(rules[r]);
|
|
8
|
-
if (isFunction(v))
|
|
9
|
-
|
|
10
|
-
if (v != null)
|
|
11
|
-
css2 += `${r}:${v};`;
|
|
8
|
+
if (isFunction(v)) v = v(rules);
|
|
9
|
+
if (v != null) css2 += `${r}:${v};`;
|
|
12
10
|
}
|
|
13
11
|
return css2;
|
|
14
12
|
};
|
package/deref.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { implementsFunction } from "@thi.ng/checks/implements-function";
|
|
2
2
|
const derefContext = (ctx, keys) => {
|
|
3
|
-
if (ctx == null || !keys || !keys.length)
|
|
4
|
-
return ctx;
|
|
3
|
+
if (ctx == null || !keys || !keys.length) return ctx;
|
|
5
4
|
const res = { ...ctx };
|
|
6
5
|
for (let k of keys) {
|
|
7
6
|
const v = res[k];
|
|
8
|
-
if (implementsFunction(v, "deref"))
|
|
9
|
-
res[k] = v.deref();
|
|
7
|
+
if (implementsFunction(v, "deref")) res[k] = v.deref();
|
|
10
8
|
}
|
|
11
9
|
return res;
|
|
12
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "HTML/SVG/XML serialization of nested data structures, iterables & closures",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -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.2",
|
|
40
|
+
"@thi.ng/checks": "^3.6.4",
|
|
41
|
+
"@thi.ng/errors": "^2.5.7",
|
|
42
|
+
"@thi.ng/strings": "^3.7.33"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.43.
|
|
46
|
-
"@thi.ng/atom": "^5.
|
|
47
|
-
"esbuild": "^0.
|
|
48
|
-
"typedoc": "^0.25.
|
|
49
|
-
"typescript": "^5.4.
|
|
45
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
46
|
+
"@thi.ng/atom": "^5.3.0",
|
|
47
|
+
"esbuild": "^0.21.1",
|
|
48
|
+
"typedoc": "^0.25.13",
|
|
49
|
+
"typescript": "^5.4.5"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|
|
52
52
|
"array",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
],
|
|
129
129
|
"year": 2016
|
|
130
130
|
},
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
132
132
|
}
|
package/serialize.js
CHANGED
|
@@ -28,8 +28,7 @@ const serialize = (tree, opts, path = [0]) => {
|
|
|
28
28
|
xml: false,
|
|
29
29
|
...opts
|
|
30
30
|
};
|
|
31
|
-
if (opts?.keys == null && $opts.span)
|
|
32
|
-
$opts.keys = true;
|
|
31
|
+
if (opts?.keys == null && $opts.span) $opts.keys = true;
|
|
33
32
|
return _serialize(tree, $opts, path);
|
|
34
33
|
};
|
|
35
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;
|
|
@@ -44,8 +43,7 @@ const serializeElement = (tree, opts, path) => {
|
|
|
44
43
|
const serializeTag = (tree, opts, path) => {
|
|
45
44
|
tree = normalize(tree);
|
|
46
45
|
const attribs = tree[1];
|
|
47
|
-
if (attribs.__skip || attribs.__serialize === false)
|
|
48
|
-
return "";
|
|
46
|
+
if (attribs.__skip || attribs.__serialize === false) return "";
|
|
49
47
|
opts.keys && attribs.key === void 0 && (attribs.key = path.join("-"));
|
|
50
48
|
const tag = tree[0];
|
|
51
49
|
const body = tree[2] ? serializeBody(tag, tree[2], opts, path) : !VOID_TAGS[tag] && !NO_CLOSE_EMPTY[tag] ? `></${tag}>` : PROC_TAGS[tag] || "/>";
|
|
@@ -54,8 +52,7 @@ const serializeTag = (tree, opts, path) => {
|
|
|
54
52
|
const serializeAttribs = (attribs, opts) => {
|
|
55
53
|
let res = "";
|
|
56
54
|
for (let a in attribs) {
|
|
57
|
-
if (a.startsWith("__"))
|
|
58
|
-
continue;
|
|
55
|
+
if (a.startsWith("__")) continue;
|
|
59
56
|
const v = serializeAttrib(attribs, a, deref(attribs[a]), opts);
|
|
60
57
|
v != null && (res += v);
|
|
61
58
|
}
|
|
@@ -83,8 +80,7 @@ const serializeBody = (tag, body, opts, path) => {
|
|
|
83
80
|
}
|
|
84
81
|
const proc = PROC_TAGS[tag];
|
|
85
82
|
let res = proc ? " " : ">";
|
|
86
|
-
if (opts.span && !proc && !NO_SPANS[tag])
|
|
87
|
-
opts = { ...opts, span: true };
|
|
83
|
+
if (opts.span && !proc && !NO_SPANS[tag]) opts = { ...opts, span: true };
|
|
88
84
|
for (let i = 0, n = body.length; i < n; i++) {
|
|
89
85
|
res += _serialize(body[i], opts, [...path, i]);
|
|
90
86
|
}
|