Skip to content

An agent skill for creating detailed, interactive isometric illustrations of real-world machines and complex systems. Generates polished SVGs with optional WebGL shaders and 3D effects.

fix(react): retain authored dot opacity

Rudy Celekli260d4836cf73
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..1a7ef03 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -57,6 +57,11 @@ jobs:
node examples/raptor-engine/build.mjs
node examples/raptor-engine/build.mjs --light
+ - name: React faded dot regressions
+ run: |
+ npm install --prefix "$RUNNER_TEMP/anatomy-react-tests" --no-package-lock --no-save [email protected] [email protected] [email protected]
+ NODE_PATH="$RUNNER_TEMP/anatomy-react-tests/node_modules" node --test scripts/react-dots-opacity.test.mjs
+
- name: Committed pages are unchanged
run: |
git status --short
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..558da1f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha
### Fixed
+- React `Dots` retains the kit's optional per-point opacity, including fading bolt circles and pulsing dots, while ordinary points remain opaque.
+
- `examples/test-rig/` drew its glass button dark in the light theme. `stretch.css` now has light values for its own colours.
### Changed
diff --git a/kit/react/draw.tsx b/kit/react/draw.tsx
index 235f5a5..5fb365b 100644
--- a/kit/react/draw.tsx
+++ b/kit/react/draw.tsx
@@ -79,15 +79,16 @@ export function Wire({ from, to, via = [], tone = "lo", dotted = false, dashed =
);
}
-export function Dots({ points, size = 0.5, tone = "mid", pulse = false }: { points: Flat[]; size?: number; tone?: Tone; pulse?: boolean }) {
+export function Dots({ points, size = 0.5, tone = "mid", pulse = false }: { points: Array<Flat | [number, number, number]>; size?: number; tone?: Tone; pulse?: boolean }) {
return (
<g className="iso-dots" data-tone={tone}>
- {points.map(([x, y], index) => (
+ {points.map(([x, y, alpha], index) => (
<circle
key={index}
cx={tenth(x)}
cy={tenth(y)}
r={size}
+ fillOpacity={alpha !== undefined && alpha < 1 ? Math.max(0, alpha) : undefined}
data-pulse={pulse ? "" : undefined}
style={pulse ? ({ "--pulse-at": `${(index * 137) % 1600}ms` } as React.CSSProperties) : undefined}
/>
diff --git a/references/kit.md b/references/kit.md
index b60decf..fee710a 100644
--- a/references/kit.md
+++ b/references/kit.md
@@ -132,7 +132,7 @@ From `kit/react/draw.tsx`, which is server-safe:
- `<Solid paths tone crease halo lit flat className inner />` (`inner` is line markup placed under the outline, as for `solidSvg`)
- `<Line d tone dotted dashed flow free />`
- `<Wire from to via tone dotted dashed flow ends size />`
-- `<Dots points size tone pulse />`
+- `<Dots points size tone pulse />` (a point may carry opacity as `[x, y, alpha]`, as for `dotsSvg`)
- `<FaceText transform size tone anchor>text</FaceText>`
- `<IsoFigure width height label>` …svg children… `</IsoFigure>`
- `<Plate fig title hint readout keys caption>` …figure… `</Plate>`
diff --git a/scripts/react-dots-opacity.test.mjs b/scripts/react-dots-opacity.test.mjs
new file mode 100644
index 0000000..2761a6b
--- /dev/null
+++ b/scripts/react-dots-opacity.test.mjs
@@ -0,0 +1,51 @@
+import assert from "node:assert/strict";
+import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { createRequire } from "node:module";
+import { tmpdir } from "node:os";
+import { dirname, join, resolve } from "node:path";
+import test from "node:test";
+import * as G from "../kit/lathe.mjs";
+const require = createRequire(import.meta.url);
+const ts = require("typescript");
+const React = require("react");
+const { renderToStaticMarkup } = require("react-dom/server");
+const directory = mkdtempSync(join(tmpdir(), "anatomy-react-solid-"));
+try {
+ for (const file of ["kit/iso-kit.ts", "kit/react/live.tsx", "kit/react/draw.tsx"]) {
+ const output = join(directory, file.replace(/\.tsx?$/, ".js"));
+ mkdirSync(dirname(output), { recursive: true });
+ const result = ts.transpileModule(readFileSync(resolve(file), "utf8"), { fileName: file, compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.React } });
+ writeFileSync(output, result.outputText);
+ }
+ const { Dots } = require(join(directory, "kit/react/draw.js"));
+ const P = { origin: [0, 0], scale: 1, azimuth: 45, elevation: 30 };
+ test("actual React renderer preserves the kit's faded bolt circle", () => {
+ const points = G.dotsOf(G.frameAlong([0, 0, 0], [0, 0, 1]), 2, 4, 32, P, { fade: [0.04, 0.42] });
+ assert.ok(points.some((point) => point.length === 3));
+ const html = renderToStaticMarkup(React.createElement(Dots, { points }));
+ const circles = [...html.matchAll(/<circle[^>]*>/g)].map(([circle]) => circle);
+ assert.equal(circles.length, points.length);
+ points.forEach((point, index) => {
+ if (point[2] === undefined) assert.doesNotMatch(circles[index], /fill-opacity/);
+ else assert.equal(Number(circles[index].match(/fill-opacity="([^"]+)"/)[1]), point[2]);
+ });
+ });
+ test("actual React renderer preserves opacity while dots pulse", () => {
+ const html = renderToStaticMarkup(React.createElement(Dots, { points: [[2, 3, 0.25]], pulse: true }));
+ assert.match(html, /fill-opacity="0.25"/);
+ assert.match(html, /data-pulse=""/);
+ assert.match(html, /--pulse-at:0ms/);
+ });
+ test("actual React renderer clamps negative opacity to zero", () => {
+ const html = renderToStaticMarkup(React.createElement(Dots, { points: [[0, 0, -0.5]] }));
+ assert.match(html, /fill-opacity="0"/);
+ });
+ test("actual React renderer preserves ordinary opaque points", () => {
+ const html = renderToStaticMarkup(React.createElement(Dots, { points: [[2.22, 3.33], [4, 5, 1]], size: 0.75, tone: "lo" }));
+ assert.doesNotMatch(html, /fill-opacity/);
+ assert.match(html, /cx="2.2" cy="3.3" r="0.75"/);
+ assert.match(html, /data-tone="lo"/);
+ });
+} finally {
+ rmSync(directory, { recursive: true, force: true });
+}
diff --git a/tests/fixtures/react-dots-dark.png b/tests/fixtures/react-dots-dark.png
new file mode 100644
index 0000000..0533c3d
Binary files /dev/null and b/tests/fixtures/react-dots-dark.png differ
diff --git a/tests/fixtures/react-dots-light.png b/tests/fixtures/react-dots-light.png
new file mode 100644
index 0000000..429f9c2
Binary files /dev/null and b/tests/fixtures/react-dots-light.png differ