@thi.ng/hiccup-svg 5.2.36 → 5.3.0
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 +12 -1
- package/README.md +3 -2
- package/convert.js +8 -10
- package/format.d.ts +1 -1
- package/format.js +7 -8
- package/gradients.js +4 -8
- package/package.json +11 -11
- package/points.js +5 -5
- package/text.d.ts +1 -1
- package/text.js +2 -2
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,17 @@ 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.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-svg@5.3.0) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add fillRule attrib conversion support ([9277417](https://github.com/thi-ng/umbrella/commit/9277417))
|
|
17
|
+
|
|
18
|
+
#### ♻️ Refactoring
|
|
19
|
+
|
|
20
|
+
- rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
|
|
21
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
22
|
+
|
|
12
23
|
### [5.2.34](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-svg@5.2.34) (2024-04-20)
|
|
13
24
|
|
|
14
25
|
#### ♻️ Refactoring
|
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
|
>
|
|
@@ -179,7 +179,7 @@ For Node.js REPL:
|
|
|
179
179
|
const svg = await import("@thi.ng/hiccup-svg");
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 2.
|
|
182
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 2.47 KB
|
|
183
183
|
|
|
184
184
|
## Dependencies
|
|
185
185
|
|
|
@@ -205,6 +205,7 @@ directory are using this package:
|
|
|
205
205
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/package-stats.png" width="240"/> | CLI util to visualize umbrella pkg stats | | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/package-stats) |
|
|
206
206
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pointfree-svg.png" width="240"/> | Generate SVG using pointfree DSL | | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pointfree-svg) |
|
|
207
207
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/poly-spline.png" width="240"/> | Polygon to cubic curve conversion & visualization | [Demo](https://demo.thi.ng/umbrella/poly-spline/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/poly-spline) |
|
|
208
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-reactive-svg.jpg" width="240"/> | Animated SVG elements with reactive attributes | [Demo](https://demo.thi.ng/umbrella/rdom-reactive-svg/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-reactive-svg) |
|
|
208
209
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-svg-nodes.png" width="240"/> | rdom powered SVG graph with draggable nodes | [Demo](https://demo.thi.ng/umbrella/rdom-svg-nodes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-svg-nodes) |
|
|
209
210
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rstream-grid.jpg" width="240"/> | Interactive grid generator, SVG generation & export, undo/redo support | [Demo](https://demo.thi.ng/umbrella/rstream-grid/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rstream-grid) |
|
|
210
211
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/svg-resample.png" width="240"/> | SVG path parsing & dynamic resampling | [Demo](https://demo.thi.ng/umbrella/svg-resample/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/svg-resample) |
|
package/convert.js
CHANGED
|
@@ -17,6 +17,7 @@ const ATTRIB_ALIASES = {
|
|
|
17
17
|
alpha: "opacity",
|
|
18
18
|
dash: "stroke-dasharray",
|
|
19
19
|
dashOffset: "stroke-dashoffset",
|
|
20
|
+
fillRule: "fill-rule",
|
|
20
21
|
lineCap: "stroke-linecap",
|
|
21
22
|
lineJoin: "stroke-linejoin",
|
|
22
23
|
miterLimit: "stroke-miterlimit",
|
|
@@ -35,8 +36,7 @@ const BASE_LINE = {
|
|
|
35
36
|
};
|
|
36
37
|
const precisionStack = [];
|
|
37
38
|
const convertTree = (tree) => {
|
|
38
|
-
if (tree == null)
|
|
39
|
-
return null;
|
|
39
|
+
if (tree == null) return null;
|
|
40
40
|
if (implementsFunction(tree, "toHiccup")) {
|
|
41
41
|
return convertTree(tree.toHiccup());
|
|
42
42
|
}
|
|
@@ -44,7 +44,7 @@ const convertTree = (tree) => {
|
|
|
44
44
|
if (isArray(type)) {
|
|
45
45
|
return tree.map(convertTree);
|
|
46
46
|
}
|
|
47
|
-
let attribs =
|
|
47
|
+
let attribs = __convertAttribs(tree[1]);
|
|
48
48
|
if (attribs.__prec) {
|
|
49
49
|
precisionStack.push(PRECISION);
|
|
50
50
|
setPrecision(attribs.__prec);
|
|
@@ -56,8 +56,7 @@ const convertTree = (tree) => {
|
|
|
56
56
|
case "a":
|
|
57
57
|
case "g":
|
|
58
58
|
result = [type, fattribs(attribs)];
|
|
59
|
-
if (tree[0] === "g")
|
|
60
|
-
__groupLayerID(result[1]);
|
|
59
|
+
if (tree[0] === "g") __groupLayerID(result[1]);
|
|
61
60
|
for (let i = 2, n = tree.length; i < n; i++) {
|
|
62
61
|
const c = convertTree(tree[i]);
|
|
63
62
|
c != null && result.push(c);
|
|
@@ -164,22 +163,21 @@ const convertTree = (tree) => {
|
|
|
164
163
|
}
|
|
165
164
|
return result;
|
|
166
165
|
};
|
|
167
|
-
const
|
|
166
|
+
const __convertAttribs = (attribs) => {
|
|
168
167
|
const res = {};
|
|
169
|
-
if (!attribs)
|
|
170
|
-
return res;
|
|
168
|
+
if (!attribs) return res;
|
|
171
169
|
for (let id in attribs) {
|
|
172
170
|
const v = attribs[id];
|
|
173
171
|
const aid = ATTRIB_ALIASES[id];
|
|
174
172
|
if (aid) {
|
|
175
173
|
res[aid] = v;
|
|
176
174
|
} else {
|
|
177
|
-
|
|
175
|
+
__convertAttrib(res, id, v);
|
|
178
176
|
}
|
|
179
177
|
}
|
|
180
178
|
return res;
|
|
181
179
|
};
|
|
182
|
-
const
|
|
180
|
+
const __convertAttrib = (res, id, v) => {
|
|
183
181
|
switch (id) {
|
|
184
182
|
case "font": {
|
|
185
183
|
const i = v.indexOf(" ");
|
package/format.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare const fpoints: (pts: Vec2Like[], sep?: string) => string;
|
|
|
42
42
|
*
|
|
43
43
|
* Additional attribute names given (via rest args) will be formatted as numeric
|
|
44
44
|
* values (using configured precision, see {@link setPrecision}). Formatting is
|
|
45
|
-
* done via {@link
|
|
45
|
+
* done via {@link __numericAttribs}.
|
|
46
46
|
*
|
|
47
47
|
* Returns updated attribs or `undefined` if `attribs` itself is null-ish.
|
|
48
48
|
*
|
package/format.js
CHANGED
|
@@ -12,7 +12,7 @@ const DEFAULT_NUMERIC_IDS = [
|
|
|
12
12
|
"stroke-width",
|
|
13
13
|
"stroke-miterlimit"
|
|
14
14
|
];
|
|
15
|
-
const
|
|
15
|
+
const __numericAttribs = (attribs, ids) => {
|
|
16
16
|
let v;
|
|
17
17
|
for (let id of DEFAULT_NUMERIC_IDS.concat(ids)) {
|
|
18
18
|
typeof (v = attribs[id]) === "number" && (attribs[id] = ff(v));
|
|
@@ -20,15 +20,14 @@ const numericAttribs = (attribs, ids) => {
|
|
|
20
20
|
return attribs;
|
|
21
21
|
};
|
|
22
22
|
const fattribs = (attribs, ...numericIDs) => {
|
|
23
|
-
if (!attribs)
|
|
24
|
-
|
|
25
|
-
const res = ftransforms(attribs);
|
|
23
|
+
if (!attribs) return;
|
|
24
|
+
const res = __ftransforms(attribs);
|
|
26
25
|
let v;
|
|
27
26
|
(v = attribs.fill) && (res.fill = fcolor(v));
|
|
28
27
|
(v = attribs.stroke) && (res.stroke = fcolor(v));
|
|
29
|
-
return
|
|
28
|
+
return __numericAttribs(attribs, numericIDs);
|
|
30
29
|
};
|
|
31
|
-
const
|
|
30
|
+
const __ftransforms = (attribs) => {
|
|
32
31
|
let v;
|
|
33
32
|
if ((v = attribs.transform) || attribs.translate || attribs.scale != null || attribs.rotate) {
|
|
34
33
|
if (v) {
|
|
@@ -37,12 +36,12 @@ const ftransforms = (attribs) => {
|
|
|
37
36
|
delete attribs.rotate;
|
|
38
37
|
delete attribs.scale;
|
|
39
38
|
} else {
|
|
40
|
-
attribs.transform =
|
|
39
|
+
attribs.transform = __buildTransform(attribs);
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
return attribs;
|
|
44
43
|
};
|
|
45
|
-
const
|
|
44
|
+
const __buildTransform = (attribs) => {
|
|
46
45
|
const tx = [];
|
|
47
46
|
let v;
|
|
48
47
|
if (v = attribs.translate) {
|
package/gradients.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { fattribs, fcolor, ff } from "./format.js";
|
|
2
2
|
const RE_ALPHA_COLOR = /(rgb|hsl)a\(([a-z0-9.-]+),([0-9.%]+),([0-9.%]+),([0-9.]+)\)/;
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
fattribs(attribs),
|
|
6
|
-
...stops.map(gradientStop)
|
|
7
|
-
];
|
|
8
|
-
const gradientStop = ([offset, col]) => {
|
|
3
|
+
const __gradient = (type, attribs, stops) => [type, fattribs(attribs), ...stops.map(__gradientStop)];
|
|
4
|
+
const __gradientStop = ([offset, col]) => {
|
|
9
5
|
col = fcolor(col);
|
|
10
6
|
let opacity;
|
|
11
7
|
const parts = RE_ALPHA_COLOR.exec(col);
|
|
@@ -15,7 +11,7 @@ const gradientStop = ([offset, col]) => {
|
|
|
15
11
|
}
|
|
16
12
|
return ["stop", { offset, "stop-color": col, "stop-opacity": opacity }];
|
|
17
13
|
};
|
|
18
|
-
const linearGradient = (id, from, to, stops, attribs) =>
|
|
14
|
+
const linearGradient = (id, from, to, stops, attribs) => __gradient(
|
|
19
15
|
"linearGradient",
|
|
20
16
|
{
|
|
21
17
|
...attribs,
|
|
@@ -27,7 +23,7 @@ const linearGradient = (id, from, to, stops, attribs) => gradient(
|
|
|
27
23
|
},
|
|
28
24
|
stops
|
|
29
25
|
);
|
|
30
|
-
const radialGradient = (id, from, to, fr, r, stops, attribs) =>
|
|
26
|
+
const radialGradient = (id, from, to, fr, r, stops, attribs) => __gradient(
|
|
31
27
|
"radialGradient",
|
|
32
28
|
{
|
|
33
29
|
...attribs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup-svg",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "SVG element functions for @thi.ng/hiccup & related tooling",
|
|
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-svg",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,16 +36,16 @@
|
|
|
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/color": "^5.6.
|
|
42
|
-
"@thi.ng/prefixes": "^2.3.
|
|
39
|
+
"@thi.ng/api": "^8.11.3",
|
|
40
|
+
"@thi.ng/checks": "^3.6.5",
|
|
41
|
+
"@thi.ng/color": "^5.6.46",
|
|
42
|
+
"@thi.ng/prefixes": "^2.3.20"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.
|
|
46
|
-
"esbuild": "^0.
|
|
47
|
-
"typedoc": "^0.25.
|
|
48
|
-
"typescript": "^5.
|
|
45
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
46
|
+
"esbuild": "^0.21.5",
|
|
47
|
+
"typedoc": "^0.25.13",
|
|
48
|
+
"typescript": "^5.5.2"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"arc",
|
|
@@ -137,5 +137,5 @@
|
|
|
137
137
|
"parent": "@thi.ng/hiccup",
|
|
138
138
|
"year": 2016
|
|
139
139
|
},
|
|
140
|
-
"gitHead": "
|
|
140
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
141
141
|
}
|
package/points.js
CHANGED
|
@@ -5,7 +5,7 @@ const points = (pts, shape, size = 1, attribs, ...body) => {
|
|
|
5
5
|
fattribs(withoutKeys(attribs, /* @__PURE__ */ new Set(["shape", "size"]))),
|
|
6
6
|
...body
|
|
7
7
|
];
|
|
8
|
-
const href =
|
|
8
|
+
const href = __buildSymbol(group, shape, size);
|
|
9
9
|
for (let p of pts) {
|
|
10
10
|
group.push(["use", { "xlink:href": href, x: ff(p[0]), y: ff(p[1]) }]);
|
|
11
11
|
}
|
|
@@ -30,7 +30,7 @@ const packedPoints = (pts, shape, size = 1, attribs, ...body) => {
|
|
|
30
30
|
),
|
|
31
31
|
...body
|
|
32
32
|
];
|
|
33
|
-
const href =
|
|
33
|
+
const href = __buildSymbol(group, shape, size);
|
|
34
34
|
for (let i = start; num-- > 0; i += estride) {
|
|
35
35
|
group.push([
|
|
36
36
|
"use",
|
|
@@ -39,18 +39,18 @@ const packedPoints = (pts, shape, size = 1, attribs, ...body) => {
|
|
|
39
39
|
}
|
|
40
40
|
return group;
|
|
41
41
|
};
|
|
42
|
-
const
|
|
42
|
+
const __buildSymbol = (group, shape, size) => {
|
|
43
43
|
let href;
|
|
44
44
|
if (!shape || shape[0] !== "#") {
|
|
45
45
|
href = "_" + (Math.random() * 1e6 | 0).toString(36);
|
|
46
|
-
group.push(["g", { opacity: 0 },
|
|
46
|
+
group.push(["g", { opacity: 0 }, __buildShape(shape, href, size)]);
|
|
47
47
|
href = "#" + href;
|
|
48
48
|
} else {
|
|
49
49
|
href = shape;
|
|
50
50
|
}
|
|
51
51
|
return href;
|
|
52
52
|
};
|
|
53
|
-
const
|
|
53
|
+
const __buildShape = (shape, id, r) => {
|
|
54
54
|
const rf = ff(r);
|
|
55
55
|
if (shape === "circle") {
|
|
56
56
|
return ["circle", { id, cx: 0, cy: 0, r: rf }];
|
package/text.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Vec2Like } from "./api.js";
|
|
2
|
-
export declare const text: (p: Vec2Like, body: string, attribs?: any, ...
|
|
2
|
+
export declare const text: (p: Vec2Like, body: string, attribs?: any, ...children: any[]) => any[];
|
|
3
3
|
//# sourceMappingURL=text.d.ts.map
|
package/text.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fattribs, ff } from "./format.js";
|
|
2
|
-
const text = (p, body, attribs, ...
|
|
2
|
+
const text = (p, body, attribs, ...children) => [
|
|
3
3
|
"text",
|
|
4
4
|
fattribs({
|
|
5
5
|
...attribs,
|
|
@@ -7,7 +7,7 @@ const text = (p, body, attribs, ...xs) => [
|
|
|
7
7
|
y: ff(p[1])
|
|
8
8
|
}),
|
|
9
9
|
body,
|
|
10
|
-
...
|
|
10
|
+
...children
|
|
11
11
|
];
|
|
12
12
|
export {
|
|
13
13
|
text
|