@thi.ng/hiccup-canvas 2.1.40 → 2.2.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-22T21:47:07Z
3
+ - **Last updated**: 2023-01-10T15:20:19Z
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
+ ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-canvas@2.2.0) (2023-01-10)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add __background attrib support ([a33a58d](https://github.com/thi-ng/umbrella/commit/a33a58d))
17
+ - update __mergeState() to fill bg if attrib given
18
+ - refactor attrib handling in main draw() fn
19
+
12
20
  ### [2.1.9](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-canvas@2.1.9) (2022-04-07)
13
21
 
14
22
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -47,6 +47,8 @@ This project is part of the
47
47
  - [Translation](#translation)
48
48
  - [Scaling](#scaling)
49
49
  - [Rotation](#rotation)
50
+ - [Special attributes](#special-attributes)
51
+ - [Background fill](#background-fill)
50
52
  - [Authors](#authors)
51
53
  - [License](#license)
52
54
 
@@ -92,7 +94,7 @@ For Node.js REPL:
92
94
  const hiccupCanvas = await import("@thi.ng/hiccup-canvas");
93
95
  ```
94
96
 
95
- Package sizes (brotli'd, pre-treeshake): ESM: 2.36 KB
97
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.40 KB
96
98
 
97
99
  ## Dependencies
98
100
 
@@ -493,6 +495,15 @@ package for creating different kinds of transformation matrices, e.g.
493
495
  { rotate: theta } // in radians
494
496
  ```
495
497
 
498
+ ### Special attributes
499
+
500
+ #### Background fill
501
+
502
+ The special `__background` attribute can be used to fill the entire canvas with
503
+ a given background color. The attribute only makes sense if attached to the root
504
+ group/shape and can take the same values as any other [color
505
+ attribs](#color-attributes).
506
+
496
507
  ## Authors
497
508
 
498
509
  - [Karsten Schmidt](https://thi.ng)
@@ -510,4 +521,4 @@ If this project contributes to an academic publication, please cite it as:
510
521
 
511
522
  ## License
512
523
 
513
- © 2018 - 2022 Karsten Schmidt // Apache License 2.0
524
+ © 2018 - 2023 Karsten Schmidt // Apache License 2.0
package/draw.js CHANGED
@@ -25,26 +25,27 @@ export const draw = (ctx, shape, pstate = { attribs: {}, edits: [] }) => {
25
25
  }
26
26
  return;
27
27
  }
28
- const state = __mergeState(ctx, pstate, shape[1]);
29
- const attribs = state ? state.attribs : pstate.attribs;
30
- if (attribs.__skip)
28
+ const origAttribs = shape[1];
29
+ if (origAttribs.__skip)
31
30
  return;
31
+ const state = __mergeState(ctx, pstate, origAttribs);
32
+ const attribs = state ? state.attribs : pstate.attribs;
32
33
  switch (shape[0]) {
33
34
  case "g":
34
35
  case "defs":
35
36
  defs(ctx, state, pstate, shape);
36
37
  break;
37
38
  case "linearGradient":
38
- __registerGradient(pstate, shape[1].id, defLinearGradient(ctx, shape[1], shape[2]));
39
+ __registerGradient(pstate, origAttribs.id, defLinearGradient(ctx, origAttribs, shape[2]));
39
40
  break;
40
41
  case "radialGradient":
41
- __registerGradient(pstate, shape[1].id, defRadialGradient(ctx, shape[1], shape[2]));
42
+ __registerGradient(pstate, origAttribs.id, defRadialGradient(ctx, origAttribs, shape[2]));
42
43
  break;
43
44
  case "points":
44
- points(ctx, attribs, shape[1], shape[2]);
45
+ points(ctx, attribs, origAttribs, shape[2]);
45
46
  break;
46
47
  case "packedPoints":
47
- packedPoints(ctx, attribs, shape[1], shape[2]);
48
+ packedPoints(ctx, attribs, origAttribs, shape[2]);
48
49
  break;
49
50
  case "line":
50
51
  line(ctx, attribs, shape[2], shape[3]);
@@ -83,7 +84,7 @@ export const draw = (ctx, shape, pstate = { attribs: {}, edits: [] }) => {
83
84
  text(ctx, attribs, shape[2], shape[3], shape[4]);
84
85
  break;
85
86
  case "img":
86
- image(ctx, attribs, shape[1], shape[2], shape[3], shape[4], shape[5]);
87
+ image(ctx, attribs, origAttribs, shape[2], shape[3], shape[4], shape[5]);
87
88
  default:
88
89
  }
89
90
  state && __restoreState(ctx, pstate, state);
package/internal/state.js CHANGED
@@ -71,6 +71,13 @@ export const __mergeState = (ctx, state, attribs) => {
71
71
  setAttrib(ctx, state, id, k, v);
72
72
  }
73
73
  }
74
+ else if (id === "__background") {
75
+ ctx.save();
76
+ ctx.resetTransform();
77
+ ctx.fillStyle = resolveGradientOrColor(state, attribs[id]);
78
+ ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
79
+ ctx.restore();
80
+ }
74
81
  }
75
82
  return res;
76
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hiccup-canvas",
3
- "version": "2.1.40",
3
+ "version": "2.2.0",
4
4
  "description": "Hiccup shape tree renderer for vanilla Canvas 2D contexts",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,16 +34,16 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.6.2",
38
- "@thi.ng/checks": "^3.3.6",
39
- "@thi.ng/color": "^5.2.15",
40
- "@thi.ng/math": "^5.3.18",
41
- "@thi.ng/pixel": "^4.0.13",
42
- "@thi.ng/vectors": "^7.5.29"
37
+ "@thi.ng/api": "^8.6.3",
38
+ "@thi.ng/checks": "^3.3.7",
39
+ "@thi.ng/color": "^5.2.17",
40
+ "@thi.ng/math": "^5.4.0",
41
+ "@thi.ng/pixel": "^4.1.0",
42
+ "@thi.ng/vectors": "^7.5.31"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-extractor": "^7.33.7",
46
- "@thi.ng/testament": "^0.3.8",
46
+ "@thi.ng/testament": "^0.3.9",
47
47
  "rimraf": "^3.0.2",
48
48
  "tools": "^0.0.1",
49
49
  "typedoc": "^0.23.22",
@@ -130,5 +130,5 @@
130
130
  ],
131
131
  "year": 2018
132
132
  },
133
- "gitHead": "bc6f7f5e2765bb96fe64db804eaf4b2443b47fc6\n"
133
+ "gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
134
134
  }