ntk 8.23.3 → 8.23.4

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.
@@ -726,6 +726,15 @@ function finiteRect(x, y, w, h) {
726
726
  return Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(w) && Number.isFinite(h);
727
727
  }
728
728
 
729
+ /** A style no context can paint with, named for the message that says so. */
730
+ function describeStyle(value) {
731
+ if (value === null) return "null";
732
+ if (value === undefined) return "undefined";
733
+ if (typeof value !== "object") return `${typeof value} ${JSON.stringify(value)}`;
734
+ const name = value.constructor?.name;
735
+ return name && name !== "Object" ? `a ${name}` : "a plain object";
736
+ }
737
+
729
738
  /**
730
739
  * Canvas-like 2d rendering context backed by the XRender extension: most
731
740
  * operations (composition, gradients, text composition) happen server-side.
@@ -1320,7 +1329,7 @@ class RenderingContext2d {
1320
1329
  : app.solidPicture(r, g, b, a);
1321
1330
  }
1322
1331
 
1323
- _stylePicture(value) {
1332
+ _stylePicture(value, property = "fillStyle") {
1324
1333
  if (typeof value === "string" || Array.isArray(value)) {
1325
1334
  // the app's, which it lets go as colours animate (App#styleSolid) —
1326
1335
  // the style stays here, to ask by again. An app that only answers
@@ -1337,7 +1346,16 @@ class RenderingContext2d {
1337
1346
  ) {
1338
1347
  return value;
1339
1348
  }
1340
- throw new Error("Unknown fill style");
1349
+ throw new Error(
1350
+ `Unknown fill style: ${property} takes a CSS colour string, an ` +
1351
+ "[r, g, b, a] array, a CanvasGradient, a CanvasPattern or a " +
1352
+ `Picture, and was given ${describeStyle(value)}.` +
1353
+ (value == null
1354
+ ? " A null is most often createPattern()'s, which answers null " +
1355
+ "for a source it cannot use — check what it returns before " +
1356
+ "assigning it."
1357
+ : ""),
1358
+ );
1341
1359
  }
1342
1360
 
1343
1361
  set fillStyle(value) {
@@ -1353,7 +1371,7 @@ class RenderingContext2d {
1353
1371
 
1354
1372
  set strokeStyle(value) {
1355
1373
  // the picture first: a value that throws leaves the style as it was
1356
- const picture = this._stylePicture(value);
1374
+ const picture = this._stylePicture(value, "strokeStyle");
1357
1375
  this._strokeStyle = value;
1358
1376
  this._strokeSource = picture;
1359
1377
  }
@@ -1381,7 +1399,10 @@ class RenderingContext2d {
1381
1399
  get _strokePicture() {
1382
1400
  const p = this._strokeSource;
1383
1401
  if (!p?._evicted) return p;
1384
- return (this._strokeSource = this._stylePicture(this._strokeStyle));
1402
+ return (this._strokeSource = this._stylePicture(
1403
+ this._strokeStyle,
1404
+ "strokeStyle",
1405
+ ));
1385
1406
  }
1386
1407
 
1387
1408
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ntk",
3
- "version": "8.23.3",
3
+ "version": "8.23.4",
4
4
  "description": "Desktop UI toolkit for X11 with canvas-like 2d and OpenGL rendering",
5
5
  "author": "Andrey Sidorov <sidorares@yandex.ru>",
6
6
  "license": "MIT",