@thi.ng/hiccup-svg 5.0.0 → 5.0.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 +1 -1
- package/README.md +33 -26
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ This project is part of the
|
|
|
11
11
|
|
|
12
12
|
- [About](#about)
|
|
13
13
|
- [Important](#important)
|
|
14
|
-
- [SVG conversion of @thi.ng/geom & @thi.ng/
|
|
14
|
+
- [SVG conversion of @thi.ng/geom & @thi.ng/hiccup-canvas shape trees](#svg-conversion-of-thinggeom--thinghiccup-canvas-shape-trees)
|
|
15
15
|
- [Automatic attribute conversions](#automatic-attribute-conversions)
|
|
16
16
|
- [Colors](#colors)
|
|
17
17
|
- [Transforms](#transforms)
|
|
@@ -42,33 +42,38 @@ svg.svg({}, svg.circle([0, 0], 100, { fill: "red" }));
|
|
|
42
42
|
[svg.svg, {}, [svg.circle, [0, 0], 100, { fill: "red" }]]
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
### SVG conversion of @thi.ng/geom & @thi.ng/
|
|
45
|
+
### SVG conversion of @thi.ng/geom & @thi.ng/hiccup-canvas shape trees
|
|
46
46
|
|
|
47
|
-
Since v2.0.0 this package provides a conversion utility to translate the
|
|
48
|
-
|
|
47
|
+
Since v2.0.0 this package provides a conversion utility to translate the more
|
|
48
|
+
compact syntax used by
|
|
49
49
|
[@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom)
|
|
50
50
|
and
|
|
51
|
-
[@thi.ng/
|
|
52
|
-
shape trees (designed for more performant realtime / canvas drawing) into
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
The
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
result tree). See
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
[@thi.ng/hiccup-canvas](https://github.com/thi-ng/umbrella/tree/develop/packages/hiccup-canvas)
|
|
52
|
+
shape trees (designed for more performant realtime / canvas drawing) into a SVG
|
|
53
|
+
serializable hiccup format.
|
|
54
|
+
|
|
55
|
+
The
|
|
56
|
+
[`convertTree()`](https://docs.thi.ng/umbrella/hiccup-svg/functions/convertTree.html)
|
|
57
|
+
function takes a pre-normalized hiccup tree of geom/hiccup-canvas shape
|
|
58
|
+
definitions and recursively converts it into an hiccup flavor which is ready for
|
|
59
|
+
SVG serialization (i.e. using stringified geometry attribs). This conversion
|
|
60
|
+
also involves translation & re-organization of various attributes. This function
|
|
61
|
+
returns a new tree. The original remains untouched, as will any unrecognized
|
|
62
|
+
tree / shape nodes (those will be transferred as-is to the result tree). See
|
|
63
|
+
example below.
|
|
64
|
+
|
|
65
|
+
Tree conversion can be implicitly triggered by providing a `__convert: true`
|
|
66
|
+
attribute to the root `svg()` element. This conversion also supports the
|
|
67
|
+
`__prec` control attribute which can be used (on a per-shape basis) to control
|
|
68
|
+
the formatting used for various floating point values (except color
|
|
69
|
+
conversions). Child shapes (of a group) inherit the precision setting of their
|
|
70
|
+
parent.
|
|
66
71
|
|
|
67
72
|
```ts
|
|
68
73
|
// create SVG root element and convert body
|
|
69
74
|
svg(
|
|
70
|
-
{ width: 100, height: 100,
|
|
71
|
-
["rect", { fill: [1, 0, 0] }, [
|
|
75
|
+
{ width: 100, height: 100, __convert: true, __prec: 3 },
|
|
76
|
+
["rect", { fill: [1, 0, 0] }, [1.2345, -1.2345], 100, 100]
|
|
72
77
|
)
|
|
73
78
|
// [
|
|
74
79
|
// 'svg',
|
|
@@ -79,7 +84,7 @@ svg(
|
|
|
79
84
|
// width: 100,
|
|
80
85
|
// height: 100
|
|
81
86
|
// },
|
|
82
|
-
// [
|
|
87
|
+
// ['rect', { fill: '#ff0000', x: '1.234', y: '-1.234', width: '100', height: '100' }]
|
|
83
88
|
// ]
|
|
84
89
|
```
|
|
85
90
|
|
|
@@ -204,7 +209,7 @@ fs.writeFileSync(
|
|
|
204
209
|
"hello.svg",
|
|
205
210
|
serialize(
|
|
206
211
|
svg.svg(
|
|
207
|
-
{width: 100, height: 100},
|
|
212
|
+
{ width: 100, height: 100 },
|
|
208
213
|
svg.defs(svg.linearGradient("grad", [0, 0], [0, 1], [[0, "red"], [1, "blue"]])),
|
|
209
214
|
svg.circle([50, 50], 50, { fill: "url(#grad)" }),
|
|
210
215
|
svg.text([50, 55], "Hello", { fill: "white", "text-anchor": "middle" })
|
|
@@ -212,10 +217,12 @@ fs.writeFileSync(
|
|
|
212
217
|
));
|
|
213
218
|
```
|
|
214
219
|
|
|
215
|
-
Minimal example showing SVG conversion of a
|
|
220
|
+
Minimal example showing SVG conversion of a hiccup-canvas scene (also see
|
|
221
|
+
[@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom)
|
|
222
|
+
for another compatible approach):
|
|
216
223
|
|
|
217
224
|
```ts
|
|
218
|
-
// scene tree defined for
|
|
225
|
+
// scene tree defined for hiccup-canvas
|
|
219
226
|
const scene = [
|
|
220
227
|
["defs", {},
|
|
221
228
|
["radialGradient",
|
|
@@ -232,7 +239,7 @@ const scene = [
|
|
|
232
239
|
fs.writeFileSync(
|
|
233
240
|
"radialgradient.svg",
|
|
234
241
|
serialize(
|
|
235
|
-
svg.svg({ width: 300, height: 300 },
|
|
242
|
+
svg.svg({ width: 300, height: 300, __convert: true }, scene)
|
|
236
243
|
)
|
|
237
244
|
);
|
|
238
245
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup-svg",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "SVG element functions for @thi.ng/hiccup & related tooling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@thi.ng/checks": "^3.3.12",
|
|
38
|
-
"@thi.ng/color": "^5.
|
|
38
|
+
"@thi.ng/color": "^5.5.1",
|
|
39
39
|
"@thi.ng/prefixes": "^2.1.22"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
@@ -135,5 +135,5 @@
|
|
|
135
135
|
"parent": "@thi.ng/hiccup",
|
|
136
136
|
"year": 2016
|
|
137
137
|
},
|
|
138
|
-
"gitHead": "
|
|
138
|
+
"gitHead": "ca22f02a137c0a4e3a38ef81e82e2bc7e3c43849\n"
|
|
139
139
|
}
|