Skip to content

Diagrams under a strict content policy, onLayout for exports, and multi-line sink reasons - #142

Merged
bmjcoding merged 5 commits into
mainfrom
claude/diagrams-cimip
Nov 24, 2026
Merged

bmjcoding merged 5 commits into
mainfrom
claude/diagrams-cimip

Conversation

@bmjcoding

Copy link
Copy Markdown
Owner

Four diagram faults CIMIP's lead found while adopting main, relayed by the Basalt gaps thread. All four are engineering inside decided designs: they restore documented behaviour, or add a prop that changes no pixel.

  • Strict style-src: line labels (d058e618). Labels were positioned with a style attribute inside HTML Basalt writes; under style-src 'self' each was refused and fell into the figure's corner, on the page and in the viewer.
    • Labels are now placed through the CSSOM (placeLabels) after the ink is written and after every measure, in React and the skill.
    • The audit found the same fault in a text sequence's transcript indents. React now renders the transcript as elements; the skill keeps its nodes.
    • Left: server-rendered and composed pages still write the grid's styles as attributes. The browser refuses them at parse (an error each), and script sets them again, so the figure ends right. A data: card mark is refused under img-src 'self'.
  • Strict img-src: PNG export (d4b17322). diagramToPng tries createImageBitmap on the SVG as a Blob, then a blob: image, then a data: image. When all three are refused, it rejects with an error naming the img-src it needs, and makes no file. The JSDoc, the skill's usage and foundations' export line say so. An app under img-src 'self' most likely needs to allow blob:.
  • onLayout (6e3f31d0). Every diagram component takes onLayout(laid) with the layout on screen (DiagramLayoutInfo, our own type), so an app's draw.io, Visio and Lucid files use the real geometry: exportMeasuredDiagram(laid.spec, laid.geo, format, { extras: readMeasuredExtras(laid.figure) }). It fires only when the layout changes. No pixel changes; about +0.3% a diagram component.
  • check-sinks.mjs (b839fd31). A // sink: reason now continues onto the // lines straight after it, stopping at code or another sink:.

Not here:

  • A single automatic column stretching its cards: the decision is silent, so it went to the decider with three options.
  • The skill's PNG button on failure: today it only logs, and what the reader sees is a design call.
  • A seat for app actions in the figure's foot: a light council round is running.

Checks: lint (5 of 5 steps), both typechecks, npm run build and npm run sizes pass on the tree merged with main. No tests were run (DECISIONS 330, 359). New cases are written, not run, in content-policy.test.mjs, diagram-interop-browser.test.mjs and sinks.test.mjs. No reviewer seat looked at this PR.

🤖 Generated with Claude Code

bmjcoding and others added 5 commits November 24, 2026 13:16
…le-src refuses nothing

The ink wrote each label's left, top and width as a style attribute in its HTML, which a policy without 'unsafe-inline' refuses: every label
landed in the drawing's corner, on the page and in the viewer, with a console error each. inkHtml now writes no place, and placeLabels sets it
through the CSSOM after the ink is written and after every measure (a label can move while the ink's string stays the same), in React and in the
skill.

The audit found the same fault in a text sequence's transcript, whose lines' indents are styles: React drew it as HTML, and the skill read it
back and wrote it again as HTML. React now draws the transcript as the tree's elements (keyed apart from the art's HTML), the skill keeps its
nodes and puts them back, and syncAttributes walks into the transcript, so indents a page's own markup carried (server HTML, a composed page) are
set again through the CSSOM.

A test in content-policy.test.mjs serves two figures under style-src 'self' and under 'unsafe-inline' and compares each label's box on the page
and in the viewer, and the transcript's indents, with nothing refused. Written, not run (DECISIONS 359).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…herwise fails with an error that says so

The PNG was drawn through a data: image, which `img-src 'self'` refuses, so under CIMIP's policy the image never decoded. diagramToPng now tries
createImageBitmap from the SVG as a Blob first (no URL, so no img-src, where the browser decodes SVG that way), then an image from a blob: URL,
then from a data: URL. Where the policy allows none, it rejects with an error naming `img-src 'self' blob:` (or data:) and makes no file. The
JSDoc, the skill's usage text and foundations' export line say the app must allow blob: or data:.

A test in content-policy.test.mjs exports under img-src 'self', 'self' blob: and 'self' data:. Written, not run (DECISIONS 359).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… for its draw.io, Visio and Lucid files

exportMeasuredDiagram takes a figure's measured geometry, but only diagram-core's internals could read it, so an app's files used the headless
approximation. Each diagram component now takes `onLayout(laid)`, called each time the figure is laid out anew and not again for the same
layout: `laid.spec` (under layout="auto", with the placement it is drawn on), `laid.geo`, `laid.layout` ("drawn" or "stacked") and
`laid.figure`, so `exportMeasuredDiagram(laid.spec, laid.geo, "drawio", { extras: readMeasuredExtras(laid.figure) })` writes what the reader
sees. Our own types only (DiagramLayoutInfo, exported); the callback is held in a ref, so a new one each render, or one that sets state, never
lays the figure out again. It changes no pixel. The viewer's figure does not call it.

A test in diagram-interop-browser.test.mjs exports two figures (one automatic) from onLayout, checks it is not called in a loop, and that a
resize calls it again. Written, not run (DECISIONS 359).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
check-sinks read only the one `//` comment that starts `sink:`, so a reason continued on a second `//` line failed as one with no test. A
`sink:` line comment now takes each `//` comment on the lines straight after it, each on a line of its own, until a line that is not one or
another `sink:` (as CIMIP's port does). Block comments were always read whole.

Planted cases in tools/html-skill/test/sinks.test.mjs: a reason over three lines and an indented one pass; a line of code or a second reason
ends it. Written, not run as a test (DECISIONS 359); the lint's sink step passes on the repo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ble regenerated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bmjcoding
bmjcoding merged commit ecd547e into main Nov 24, 2026
1 of 2 checks passed
@bmjcoding
bmjcoding deleted the claude/diagrams-cimip branch November 24, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant