@expofp/renderer 2.0.1 → 2.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.
Files changed (2) hide show
  1. package/dist/index.js +18 -10
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -8,7 +8,8 @@ import { BatchedText as BatchedText$1, Text as Text$1 } from "troika-three-text"
8
8
  import createLog from "debug";
9
9
  import { LineMaterial, LineSegmentsGeometry } from "three/examples/jsm/Addons.js";
10
10
  import { MaxRectsPacker, Rectangle } from "maxrects-packer";
11
- import { converter, parse } from "culori";
11
+ import { extend, colord } from "colord";
12
+ import namesPlugin from "colord/plugins/names";
12
13
  import { RAD2DEG, DEG2RAD as DEG2RAD$1 } from "three/src/math/MathUtils.js";
13
14
  import { EventManager, Rotate, Pan } from "mjolnir.js";
14
15
  const floatsPerMember = 32;
@@ -368,7 +369,8 @@ const dimColorFrag = (
368
369
  }`
369
370
  );
370
371
  function createLogger(namespace) {
371
- const info = createLog(namespace);
372
+ const fullNamespace = namespace ? `renderer:${namespace}` : "renderer";
373
+ const info = createLog(fullNamespace);
372
374
  info.log = console.info.bind(console);
373
375
  const debug = info.extend("debug");
374
376
  debug.log = console.debug.bind(console);
@@ -1721,6 +1723,7 @@ class Polygon {
1721
1723
  }
1722
1724
  }
1723
1725
  const logger$7 = createLogger("mesh");
1726
+ extend([namesPlugin]);
1724
1727
  class MeshSystem extends RenderableSystem {
1725
1728
  /**
1726
1729
  * @param materialSystem {@link MaterialSystem}
@@ -1728,7 +1731,6 @@ class MeshSystem extends RenderableSystem {
1728
1731
  */
1729
1732
  constructor(materialSystem, renderer) {
1730
1733
  super("mesh", renderer, logger$7);
1731
- __publicField(this, "toRgbConverter", converter("rgb"));
1732
1734
  __publicField(this, "meshColor", new Color());
1733
1735
  this.materialSystem = materialSystem;
1734
1736
  }
@@ -1743,10 +1745,10 @@ class MeshSystem extends RenderableSystem {
1743
1745
  shapes,
1744
1746
  (shapeDef) => {
1745
1747
  var _a2;
1746
- return (((_a2 = mapShapeToNormColor.get(shapeDef)) == null ? void 0 : _a2.alpha) ?? 1) === 1;
1748
+ return (((_a2 = mapShapeToNormColor.get(shapeDef)) == null ? void 0 : _a2.a) ?? 1) === 1;
1747
1749
  }
1748
1750
  );
1749
- const transparentShapesGrouped = groupBy(transparentShapes, (shapeDef) => mapShapeToNormColor.get(shapeDef).alpha);
1751
+ const transparentShapesGrouped = groupBy(transparentShapes, (shapeDef) => mapShapeToNormColor.get(shapeDef).a);
1750
1752
  const group = new Group();
1751
1753
  for (const [opacity, shapes2] of transparentShapesGrouped) {
1752
1754
  const transparentMesh = this.buildBatchedMesh(shapes2, opacity);
@@ -1768,9 +1770,12 @@ class MeshSystem extends RenderableSystem {
1768
1770
  }
1769
1771
  updateDefImpl(shapeDef, mesh, instanceIds) {
1770
1772
  const color = this.normalizeColor(shapeDef.color);
1771
- if (color === void 0) return;
1773
+ if (!color) {
1774
+ logger$7.warn(`Invalid color: ${shapeDef.color} %O`, shapeDef);
1775
+ return;
1776
+ }
1772
1777
  for (const instanceId of instanceIds) {
1773
- mesh.setColorAt(instanceId, this.meshColor.setRGB(color.r, color.g, color.b, SRGBColorSpace));
1778
+ mesh.setColorAt(instanceId, this.meshColor.setRGB(color.r / 255, color.g / 255, color.b / 255, SRGBColorSpace));
1774
1779
  }
1775
1780
  }
1776
1781
  buildBatchedMesh(shapes, opacity = 1) {
@@ -1820,8 +1825,11 @@ class MeshSystem extends RenderableSystem {
1820
1825
  }
1821
1826
  return batchedMesh;
1822
1827
  }
1823
- normalizeColor(color) {
1824
- return typeof color === "string" ? this.toRgbConverter(parse(color)) : this.toRgbConverter(parse(`#${color.toString(16).padStart(6, "0")}`));
1828
+ normalizeColor(colorInput) {
1829
+ const colorString = typeof colorInput === "string" ? colorInput : `#${colorInput.toString(16).padStart(6, "0")}`;
1830
+ const color = colord(colorString);
1831
+ if (!color.isValid()) return void 0;
1832
+ return color.toRgb();
1825
1833
  }
1826
1834
  buildPolygonGeometry(polygon) {
1827
1835
  const geometry = new BufferGeometry().setFromPoints(polygon.vertices).setIndex(polygon.indices.flat());
@@ -6212,7 +6220,7 @@ class InteractionsSystem {
6212
6220
  this.canvasListeners = void 0;
6213
6221
  }
6214
6222
  }
6215
- const logger = createLogger("renderer");
6223
+ const logger = createLogger("");
6216
6224
  class Renderer {
6217
6225
  /**
6218
6226
  * @param opts {@link RendererOptions}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expofp/renderer",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -10,19 +10,19 @@
10
10
  },
11
11
  "exports": "./dist/index.js",
12
12
  "devDependencies": {
13
- "@types/culori": "^2.1.1",
14
13
  "@types/debug": "^4.1.12",
15
14
  "@types/object-hash": "^3.0.6",
16
15
  "@types/three": "^0.174.0",
17
16
  "stats-gl": "^3.6.0",
18
17
  "typescript": "^5.2.2",
19
18
  "vite": "^5.2.0",
19
+ "vite-bundle-analyzer": "^1.3.2",
20
20
  "vite-plugin-dts": "^4.5.4",
21
21
  "vite-plugin-externalize-deps": "^0.9.0"
22
22
  },
23
23
  "dependencies": {
24
24
  "camera-controls": "^3.1.1",
25
- "culori": "^4.0.1",
25
+ "colord": "^2.9.3",
26
26
  "debug": "^4.4.3",
27
27
  "maxrects-packer": "^2.7.3",
28
28
  "mjolnir.js": "^3.0.0",