@thi.ng/geom 4.0.2 → 4.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-12-20T16:33:11Z
3
+ - **Last updated**: 2022-12-22T21:47:07Z
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,14 @@ 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
+ ## [4.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.1.0) (2022-12-22)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add SVG default attribs & setter ([3cb07a6](https://github.com/thi-ng/umbrella/commit/3cb07a6))
17
+ - set defaults to no fill & black stroke
18
+ - add setSvgDefaultAttribs()
19
+
12
20
  # [4.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.0.0) (2022-12-10)
13
21
 
14
22
  #### 🛑 Breaking changes
package/README.md CHANGED
@@ -27,7 +27,7 @@ For the Clojure version, please visit: [thi.ng/geom-clj](https://thi.ng/geom-clj
27
27
 
28
28
  ## About
29
29
 
30
- Functional, polymorphic API for 2D geometry types & SVG generation
30
+ Functional, polymorphic API for 2D geometry types & SVG generation.
31
31
 
32
32
  This project is a partially ported from the [Clojure version of the same
33
33
  name](http://thi.ng/geom-clj). All polymorphic operations built on
@@ -186,7 +186,7 @@ For Node.js REPL:
186
186
  const geom = await import("@thi.ng/geom");
187
187
  ```
188
188
 
189
- Package sizes (brotli'd, pre-treeshake): ESM: 11.98 KB
189
+ Package sizes (brotli'd, pre-treeshake): ESM: 12.03 KB
190
190
 
191
191
  ## Dependencies
192
192
 
package/as-svg.d.ts CHANGED
@@ -1,10 +1,22 @@
1
1
  import type { Attribs, IShape } from "@thi.ng/geom-api";
2
+ /**
3
+ * Sets the SVG root element attribs used by default by {@link svgDoc}.
4
+ *
5
+ * @param attribs
6
+ */
7
+ export declare const setSvgDefaultAttribs: (attribs: Attribs) => void;
8
+ /**
9
+ * Serializes given hiccup tree to an actual SVG source string.
10
+ *
11
+ * @param args
12
+ */
2
13
  export declare const asSvg: (...args: any[]) => string;
3
14
  /**
4
- * Creates a hiccup SVG doc element for given {@link IShape}s and attribs. If
5
- * the attribs do not include a `viewBox`, it will be computed automatically.
6
- * Furthermore (and only for the case a viewbox needs to be computed), a `bleed`
7
- * attrib can be provided to include a bleed/margin for the viewbox.
15
+ * Creates a hiccup SVG doc element for given {@link IShape}s and attribs
16
+ * (merged with default attribs). If the attribs do not include a `viewBox`, it
17
+ * will be computed automatically. Furthermore (and only for the case a viewbox
18
+ * needs to be computed), a `bleed` attrib can be provided to include a
19
+ * bleed/margin for the viewbox.
8
20
  *
9
21
  * @remarks
10
22
  * Use {@link asSvg} to serialize the resulting doc to an SVG string.
package/as-svg.js CHANGED
@@ -5,12 +5,30 @@ import { svg } from "@thi.ng/hiccup-svg/svg";
5
5
  import { serialize } from "@thi.ng/hiccup/serialize";
6
6
  import { bounds } from "./bounds.js";
7
7
  import { __collBounds } from "./internal/bounds.js";
8
+ /**
9
+ * Can be overridden via {@link setSvgDefaultAttribs}.
10
+ */
11
+ let DEFAULT_ATTRIBS = { fill: "none", stroke: "#000" };
12
+ /**
13
+ * Sets the SVG root element attribs used by default by {@link svgDoc}.
14
+ *
15
+ * @param attribs
16
+ */
17
+ export const setSvgDefaultAttribs = (attribs) => {
18
+ DEFAULT_ATTRIBS = attribs;
19
+ };
20
+ /**
21
+ * Serializes given hiccup tree to an actual SVG source string.
22
+ *
23
+ * @param args
24
+ */
8
25
  export const asSvg = (...args) => args.map((x) => serialize(convertTree(x))).join("");
9
26
  /**
10
- * Creates a hiccup SVG doc element for given {@link IShape}s and attribs. If
11
- * the attribs do not include a `viewBox`, it will be computed automatically.
12
- * Furthermore (and only for the case a viewbox needs to be computed), a `bleed`
13
- * attrib can be provided to include a bleed/margin for the viewbox.
27
+ * Creates a hiccup SVG doc element for given {@link IShape}s and attribs
28
+ * (merged with default attribs). If the attribs do not include a `viewBox`, it
29
+ * will be computed automatically. Furthermore (and only for the case a viewbox
30
+ * needs to be computed), a `bleed` attrib can be provided to include a
31
+ * bleed/margin for the viewbox.
14
32
  *
15
33
  * @remarks
16
34
  * Use {@link asSvg} to serialize the resulting doc to an SVG string.
@@ -19,6 +37,7 @@ export const asSvg = (...args) => args.map((x) => serialize(convertTree(x))).joi
19
37
  * @param xs
20
38
  */
21
39
  export const svgDoc = (attribs, ...xs) => {
40
+ attribs = { ...DEFAULT_ATTRIBS, ...attribs };
22
41
  if (xs.length > 0) {
23
42
  if (!attribs.viewBox) {
24
43
  const cbounds = __collBounds(xs, bounds);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/geom",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "description": "Functional, polymorphic API for 2D geometry types & SVG generation",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,37 +35,37 @@
35
35
  "tool:bpatch": "tools:node-esm tools/bpatch.ts"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.6.1",
39
- "@thi.ng/arrays": "^2.4.6",
40
- "@thi.ng/associative": "^6.2.20",
41
- "@thi.ng/checks": "^3.3.5",
42
- "@thi.ng/defmulti": "^2.1.25",
43
- "@thi.ng/equiv": "^2.1.15",
44
- "@thi.ng/errors": "^2.2.6",
45
- "@thi.ng/geom-api": "^3.3.22",
46
- "@thi.ng/geom-arc": "^2.1.40",
47
- "@thi.ng/geom-clip-line": "^2.2.2",
48
- "@thi.ng/geom-clip-poly": "^2.1.39",
49
- "@thi.ng/geom-closest-point": "^2.1.36",
50
- "@thi.ng/geom-hull": "^2.1.36",
51
- "@thi.ng/geom-isec": "^2.1.39",
52
- "@thi.ng/geom-poly-utils": "^2.3.23",
53
- "@thi.ng/geom-resample": "^2.1.40",
54
- "@thi.ng/geom-splines": "^2.2.14",
55
- "@thi.ng/geom-subdiv-curve": "^2.1.39",
56
- "@thi.ng/geom-tessellate": "^2.1.39",
57
- "@thi.ng/hiccup": "^4.2.27",
58
- "@thi.ng/hiccup-svg": "^4.3.25",
59
- "@thi.ng/math": "^5.3.17",
60
- "@thi.ng/matrices": "^2.1.37",
61
- "@thi.ng/random": "^3.3.19",
62
- "@thi.ng/strings": "^3.3.21",
63
- "@thi.ng/transducers": "^8.3.27",
64
- "@thi.ng/vectors": "^7.5.28"
38
+ "@thi.ng/api": "^8.6.2",
39
+ "@thi.ng/arrays": "^2.4.7",
40
+ "@thi.ng/associative": "^6.2.21",
41
+ "@thi.ng/checks": "^3.3.6",
42
+ "@thi.ng/defmulti": "^2.1.26",
43
+ "@thi.ng/equiv": "^2.1.16",
44
+ "@thi.ng/errors": "^2.2.7",
45
+ "@thi.ng/geom-api": "^3.3.23",
46
+ "@thi.ng/geom-arc": "^2.1.41",
47
+ "@thi.ng/geom-clip-line": "^2.2.3",
48
+ "@thi.ng/geom-clip-poly": "^2.1.40",
49
+ "@thi.ng/geom-closest-point": "^2.1.37",
50
+ "@thi.ng/geom-hull": "^2.1.37",
51
+ "@thi.ng/geom-isec": "^2.1.40",
52
+ "@thi.ng/geom-poly-utils": "^2.3.24",
53
+ "@thi.ng/geom-resample": "^2.1.41",
54
+ "@thi.ng/geom-splines": "^2.2.15",
55
+ "@thi.ng/geom-subdiv-curve": "^2.1.40",
56
+ "@thi.ng/geom-tessellate": "^2.1.40",
57
+ "@thi.ng/hiccup": "^4.2.28",
58
+ "@thi.ng/hiccup-svg": "^4.3.26",
59
+ "@thi.ng/math": "^5.3.18",
60
+ "@thi.ng/matrices": "^2.1.38",
61
+ "@thi.ng/random": "^3.3.20",
62
+ "@thi.ng/strings": "^3.3.22",
63
+ "@thi.ng/transducers": "^8.3.28",
64
+ "@thi.ng/vectors": "^7.5.29"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@microsoft/api-extractor": "^7.33.7",
68
- "@thi.ng/testament": "^0.3.7",
68
+ "@thi.ng/testament": "^0.3.8",
69
69
  "rimraf": "^3.0.2",
70
70
  "tools": "^0.0.1",
71
71
  "typedoc": "^0.23.22",
@@ -383,5 +383,5 @@
383
383
  "thi.ng": {
384
384
  "year": 2013
385
385
  },
386
- "gitHead": "7b2af448da8a63fb21704a79cc4cdf1f3d7d7a64\n"
386
+ "gitHead": "bc6f7f5e2765bb96fe64db804eaf4b2443b47fc6\n"
387
387
  }