@thi.ng/hiccup 4.2.26 → 4.2.27
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/package.json +5 -5
- package/serialize.d.ts +44 -46
- package/serialize.js +44 -46
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.27",
|
|
4
4
|
"description": "HTML/SVG/XML serialization of nested data structures, iterables & closures",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.6.
|
|
37
|
+
"@thi.ng/api": "^8.6.1",
|
|
38
38
|
"@thi.ng/checks": "^3.3.5",
|
|
39
39
|
"@thi.ng/errors": "^2.2.6",
|
|
40
|
-
"@thi.ng/strings": "^3.3.
|
|
40
|
+
"@thi.ng/strings": "^3.3.21"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@microsoft/api-extractor": "^7.33.7",
|
|
44
|
-
"@thi.ng/atom": "^5.1.
|
|
44
|
+
"@thi.ng/atom": "^5.1.26",
|
|
45
45
|
"@thi.ng/testament": "^0.3.7",
|
|
46
46
|
"rimraf": "^3.0.2",
|
|
47
47
|
"tools": "^0.0.1",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
],
|
|
121
121
|
"year": 2016
|
|
122
122
|
},
|
|
123
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "7b2af448da8a63fb21704a79cc4cdf1f3d7d7a64\n"
|
|
124
124
|
}
|
package/serialize.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Recursively normalizes and serializes given tree as HTML/SVG/XML
|
|
3
|
-
*
|
|
2
|
+
* Recursively normalizes and serializes given tree as HTML/SVG/XML string.
|
|
3
|
+
* Expands any embedded component functions with their results.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
* Each node of the input tree can have one of the following input
|
|
7
|
-
* forms:
|
|
6
|
+
* Each node of the input tree can have one of the following input forms:
|
|
8
7
|
*
|
|
9
8
|
* ```js
|
|
10
9
|
* ["tag", ...]
|
|
@@ -22,14 +21,13 @@
|
|
|
22
21
|
* ["div#foo.bar.baz", "hi"] // <div id="foo" class="bar baz">hi</div>
|
|
23
22
|
* ```
|
|
24
23
|
*
|
|
25
|
-
* The presence of the attributes object (2nd array index) is optional.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* from the output.
|
|
24
|
+
* The presence of the attributes object (2nd array index) is optional. Any
|
|
25
|
+
* attribute values, incl. functions are allowed. If the latter, the function is
|
|
26
|
+
* called with the full attribs object as argument and the return value is used
|
|
27
|
+
* for the attribute. This allows for the dynamic creation of attrib values
|
|
28
|
+
* based on other attribs. The only exception to this are event attributes, i.e.
|
|
29
|
+
* attribute names starting with "on". Function values assigned to event
|
|
30
|
+
* attributes will be omitted from the output.
|
|
33
31
|
*
|
|
34
32
|
* ```js
|
|
35
33
|
* ["div#foo", { bar: (attribs) => attribs.id + "-bar" }]
|
|
@@ -43,23 +41,24 @@
|
|
|
43
41
|
* // <div style="color:red;background:#000;"></div>
|
|
44
42
|
* ```
|
|
45
43
|
*
|
|
46
|
-
* Boolean attribs are serialized in HTML5 syntax (present or not).
|
|
47
|
-
* `
|
|
44
|
+
* Boolean attribs are serialized in HTML5 syntax (present or not). `null`,
|
|
45
|
+
* `undefined` or empty string attrib values are ignored.
|
|
48
46
|
*
|
|
49
|
-
* Any `null` or `undefined` array values (other than in head position)
|
|
50
|
-
*
|
|
47
|
+
* Any `null` or `undefined` array values (other than in head position) will
|
|
48
|
+
* also be removed, unless a function is in head position.
|
|
51
49
|
*
|
|
52
|
-
* A function in head position of a node acts as a mechanism for
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
50
|
+
* A function in head position of a node acts as a mechanism for component
|
|
51
|
+
* composition & delayed execution. The function will only be executed at
|
|
52
|
+
* serialization time. In this case the optional global context object and all
|
|
53
|
+
* other elements of that node / array are passed as arguments when that
|
|
54
|
+
* function is called. The return value the function MUST be a valid new tree
|
|
55
|
+
* (or `undefined`).
|
|
58
56
|
*
|
|
59
57
|
* If the `ctx` object it'll be passed to each embedded component fns.
|
|
60
|
-
* Optionally call {@link derefContext} prior to {@link serialize} to
|
|
61
|
-
*
|
|
62
|
-
*
|
|
58
|
+
* Optionally call {@link derefContext} prior to {@link serialize} to auto-deref
|
|
59
|
+
* context keys with values implementing the
|
|
60
|
+
* [`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html)
|
|
61
|
+
* interface.
|
|
63
62
|
*
|
|
64
63
|
* ```js
|
|
65
64
|
* const foo = (ctx, a, b) => ["div#" + a, ctx.foo, b];
|
|
@@ -68,29 +67,28 @@
|
|
|
68
67
|
* // <div id="id" class="black">body</div>
|
|
69
68
|
* ```
|
|
70
69
|
*
|
|
71
|
-
* Functions located in other positions are called ONLY with the global
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
* Functions located in other positions are called ONLY with the global context
|
|
71
|
+
* arg and can return any (serializable) value (i.e. new trees, strings,
|
|
72
|
+
* numbers, iterables or any type with a suitable `.toString()`, `.toHiccup()`
|
|
73
|
+
* or `.deref()` implementation).
|
|
75
74
|
*
|
|
76
|
-
* If the optional `span` flag is true (default: false), all text
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
75
|
+
* If the optional `span` flag is true (default: false), all text content will
|
|
76
|
+
* be wrapped in <span> elements (this is to ensure DOM compatibility with
|
|
77
|
+
* hdom). The only elements for spans are never created are listed in `NO_SPANS`
|
|
78
|
+
* in `api.ts`.
|
|
80
79
|
*
|
|
81
|
-
* If the optional `keys` flag is true (default: false), all elements
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* {@link @thi.ng/hdom# | @thi.ng/hdom}).
|
|
80
|
+
* If the optional `keys` flag is true (default: false), all elements will have
|
|
81
|
+
* an autogenerated `key` attribute injected. If `span` is enabled, `keys` will
|
|
82
|
+
* be enabled by default too (since in this case we assume the output is meant
|
|
83
|
+
* to be compatible with [`thi.ng/hdom`](https://thi.ng/hdom)).
|
|
86
84
|
*
|
|
87
|
-
* hiccup & hdom control attributes (i.e. attrib names prefixed with
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
85
|
+
* hiccup & hdom control attributes (i.e. attrib names prefixed with `__`) will
|
|
86
|
+
* be omitted from the output. The only control attrib supported by this package
|
|
87
|
+
* is `__serialize`. If set to `false`, the entire tree branch will be excluded
|
|
88
|
+
* from the output.
|
|
91
89
|
*
|
|
92
|
-
* Single or multiline comments can be included using the special
|
|
93
|
-
*
|
|
90
|
+
* Single or multiline comments can be included using the special `COMMENT` tag
|
|
91
|
+
* (`__COMMENT__`) (always WITHOUT attributes!).
|
|
94
92
|
*
|
|
95
93
|
* ```
|
|
96
94
|
* [COMMENT, "Hello world"]
|
|
@@ -111,8 +109,8 @@
|
|
|
111
109
|
* - `!ENTITY`
|
|
112
110
|
* - `!ATTLIST`
|
|
113
111
|
*
|
|
114
|
-
* These are used as follows (attribs are only allowed for `?xml`, all
|
|
115
|
-
*
|
|
112
|
+
* These are used as follows (attribs are only allowed for `?xml`, all others
|
|
113
|
+
* only accept a body string which is taken as is):
|
|
116
114
|
*
|
|
117
115
|
* ```
|
|
118
116
|
* ["?xml", { version: "1.0", standalone: "yes" }]
|
package/serialize.js
CHANGED
|
@@ -12,12 +12,11 @@ import { css } from "./css.js";
|
|
|
12
12
|
import { normalize } from "./normalize.js";
|
|
13
13
|
import { formatPrefixes } from "./prefix.js";
|
|
14
14
|
/**
|
|
15
|
-
* Recursively normalizes and serializes given tree as HTML/SVG/XML
|
|
16
|
-
*
|
|
15
|
+
* Recursively normalizes and serializes given tree as HTML/SVG/XML string.
|
|
16
|
+
* Expands any embedded component functions with their results.
|
|
17
17
|
*
|
|
18
18
|
* @remarks
|
|
19
|
-
* Each node of the input tree can have one of the following input
|
|
20
|
-
* forms:
|
|
19
|
+
* Each node of the input tree can have one of the following input forms:
|
|
21
20
|
*
|
|
22
21
|
* ```js
|
|
23
22
|
* ["tag", ...]
|
|
@@ -35,14 +34,13 @@ import { formatPrefixes } from "./prefix.js";
|
|
|
35
34
|
* ["div#foo.bar.baz", "hi"] // <div id="foo" class="bar baz">hi</div>
|
|
36
35
|
* ```
|
|
37
36
|
*
|
|
38
|
-
* The presence of the attributes object (2nd array index) is optional.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* from the output.
|
|
37
|
+
* The presence of the attributes object (2nd array index) is optional. Any
|
|
38
|
+
* attribute values, incl. functions are allowed. If the latter, the function is
|
|
39
|
+
* called with the full attribs object as argument and the return value is used
|
|
40
|
+
* for the attribute. This allows for the dynamic creation of attrib values
|
|
41
|
+
* based on other attribs. The only exception to this are event attributes, i.e.
|
|
42
|
+
* attribute names starting with "on". Function values assigned to event
|
|
43
|
+
* attributes will be omitted from the output.
|
|
46
44
|
*
|
|
47
45
|
* ```js
|
|
48
46
|
* ["div#foo", { bar: (attribs) => attribs.id + "-bar" }]
|
|
@@ -56,23 +54,24 @@ import { formatPrefixes } from "./prefix.js";
|
|
|
56
54
|
* // <div style="color:red;background:#000;"></div>
|
|
57
55
|
* ```
|
|
58
56
|
*
|
|
59
|
-
* Boolean attribs are serialized in HTML5 syntax (present or not).
|
|
60
|
-
* `
|
|
57
|
+
* Boolean attribs are serialized in HTML5 syntax (present or not). `null`,
|
|
58
|
+
* `undefined` or empty string attrib values are ignored.
|
|
61
59
|
*
|
|
62
|
-
* Any `null` or `undefined` array values (other than in head position)
|
|
63
|
-
*
|
|
60
|
+
* Any `null` or `undefined` array values (other than in head position) will
|
|
61
|
+
* also be removed, unless a function is in head position.
|
|
64
62
|
*
|
|
65
|
-
* A function in head position of a node acts as a mechanism for
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
63
|
+
* A function in head position of a node acts as a mechanism for component
|
|
64
|
+
* composition & delayed execution. The function will only be executed at
|
|
65
|
+
* serialization time. In this case the optional global context object and all
|
|
66
|
+
* other elements of that node / array are passed as arguments when that
|
|
67
|
+
* function is called. The return value the function MUST be a valid new tree
|
|
68
|
+
* (or `undefined`).
|
|
71
69
|
*
|
|
72
70
|
* If the `ctx` object it'll be passed to each embedded component fns.
|
|
73
|
-
* Optionally call {@link derefContext} prior to {@link serialize} to
|
|
74
|
-
*
|
|
75
|
-
*
|
|
71
|
+
* Optionally call {@link derefContext} prior to {@link serialize} to auto-deref
|
|
72
|
+
* context keys with values implementing the
|
|
73
|
+
* [`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html)
|
|
74
|
+
* interface.
|
|
76
75
|
*
|
|
77
76
|
* ```js
|
|
78
77
|
* const foo = (ctx, a, b) => ["div#" + a, ctx.foo, b];
|
|
@@ -81,29 +80,28 @@ import { formatPrefixes } from "./prefix.js";
|
|
|
81
80
|
* // <div id="id" class="black">body</div>
|
|
82
81
|
* ```
|
|
83
82
|
*
|
|
84
|
-
* Functions located in other positions are called ONLY with the global
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
83
|
+
* Functions located in other positions are called ONLY with the global context
|
|
84
|
+
* arg and can return any (serializable) value (i.e. new trees, strings,
|
|
85
|
+
* numbers, iterables or any type with a suitable `.toString()`, `.toHiccup()`
|
|
86
|
+
* or `.deref()` implementation).
|
|
88
87
|
*
|
|
89
|
-
* If the optional `span` flag is true (default: false), all text
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
88
|
+
* If the optional `span` flag is true (default: false), all text content will
|
|
89
|
+
* be wrapped in <span> elements (this is to ensure DOM compatibility with
|
|
90
|
+
* hdom). The only elements for spans are never created are listed in `NO_SPANS`
|
|
91
|
+
* in `api.ts`.
|
|
93
92
|
*
|
|
94
|
-
* If the optional `keys` flag is true (default: false), all elements
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* {@link @thi.ng/hdom# | @thi.ng/hdom}).
|
|
93
|
+
* If the optional `keys` flag is true (default: false), all elements will have
|
|
94
|
+
* an autogenerated `key` attribute injected. If `span` is enabled, `keys` will
|
|
95
|
+
* be enabled by default too (since in this case we assume the output is meant
|
|
96
|
+
* to be compatible with [`thi.ng/hdom`](https://thi.ng/hdom)).
|
|
99
97
|
*
|
|
100
|
-
* hiccup & hdom control attributes (i.e. attrib names prefixed with
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
98
|
+
* hiccup & hdom control attributes (i.e. attrib names prefixed with `__`) will
|
|
99
|
+
* be omitted from the output. The only control attrib supported by this package
|
|
100
|
+
* is `__serialize`. If set to `false`, the entire tree branch will be excluded
|
|
101
|
+
* from the output.
|
|
104
102
|
*
|
|
105
|
-
* Single or multiline comments can be included using the special
|
|
106
|
-
*
|
|
103
|
+
* Single or multiline comments can be included using the special `COMMENT` tag
|
|
104
|
+
* (`__COMMENT__`) (always WITHOUT attributes!).
|
|
107
105
|
*
|
|
108
106
|
* ```
|
|
109
107
|
* [COMMENT, "Hello world"]
|
|
@@ -124,8 +122,8 @@ import { formatPrefixes } from "./prefix.js";
|
|
|
124
122
|
* - `!ENTITY`
|
|
125
123
|
* - `!ATTLIST`
|
|
126
124
|
*
|
|
127
|
-
* These are used as follows (attribs are only allowed for `?xml`, all
|
|
128
|
-
*
|
|
125
|
+
* These are used as follows (attribs are only allowed for `?xml`, all others
|
|
126
|
+
* only accept a body string which is taken as is):
|
|
129
127
|
*
|
|
130
128
|
* ```
|
|
131
129
|
* ["?xml", { version: "1.0", standalone: "yes" }]
|