@micha.bigler/ui-core-micha 3.2.1 → 3.3.1

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.
@@ -0,0 +1,195 @@
1
+ # UCM-CHART-17 — The two export buttons make two different promises; make them keep them
2
+
3
+ ## Part A — Envelope
4
+
5
+ *Authored by the Expertenchat. Authoritative WHAT/WHY.*
6
+
7
+ ### Goal
8
+
9
+ **Export SVG** yields the chart as scalable, correctly styled vector art. **Export PNG** yields what
10
+ the user is looking at — legend, size key and footnotes included.
11
+
12
+ ### The defect, from the source
13
+
14
+ `exportChart.js:7-11` clones the first `<svg>` in the container and serialises it raw:
15
+
16
+ ```js
17
+ const svg = findSvg(chartContainer).cloneNode(true);
18
+ svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
19
+ return new Blob([new XMLSerializer().serializeToString(svg)], …)
20
+ ```
21
+
22
+ Three consequences, and they compound:
23
+
24
+ 1. **No styles are carried.** MUI X-Charts styles nearly everything through emotion CSS classes —
25
+ tick fonts and sizes, axis and grid colours, text fill, the theme's typography. The clone keeps
26
+ `class="MuiChartsAxis-tickLabel css-1abc"` and none of the rules behind it, so a standalone
27
+ viewer applies bare SVG defaults. This is the "graphically massively different" the operator
28
+ reported. **The PNG inherits it**, because it rasterises the same blob.
29
+
30
+ 2. **The legend is gone, and that is ours.** `findSvg` takes the *first* `<svg>`, i.e. the chart.
31
+ Since `HRAM-RES-39`/`HRAM-VIS-2`, consuming panels hide MUI's own legend and render a hand-built
32
+ one as **HTML** beside the chart, with the size key as a *second* SVG. Both sit outside the
33
+ exported element. **Before that consolidation, MUI's legend was inside the chart SVG and did get
34
+ exported** — unstyled, but present. Fixing a legend overlap silently degraded the export, and
35
+ nobody noticed because nobody opened an exported file.
36
+
37
+ 3. **"The first SVG" is fragile** regardless — a panel that renders any SVG ahead of the chart
38
+ exports the wrong element. It works today by accident of ordering.
39
+
40
+ ### The decision: two paths, two meanings
41
+
42
+ The operator chose option C on 2026-08-25. The two buttons already promise different things and
43
+ should stop pretending to be one mechanism:
44
+
45
+ - **SVG — the chart, faithfully styled.** Keep the clone-and-serialise path, but **inline computed
46
+ styles onto the cloned nodes** before serialising. Stays true vector: scalable, editable in
47
+ Illustrator/Inkscape, chart only. It does **not** gain the legend, and that is correct for what
48
+ this format is for.
49
+ - **PNG — the container, as seen.** Rasterise the whole `chartRef` node rather than the chart SVG, so
50
+ legend, size key and footnotes are in the file and the output matches the screen by construction.
51
+
52
+ **Make the difference legible to the user, not only to us.** Two buttons that produce visibly
53
+ different content need labels or tooltips saying so; today they read as one thing in two formats.
54
+
55
+ ### Scope
56
+
57
+ **`src/components/charts/exportChart.js`**
58
+
59
+ 1. **Inline computed styles** into the SVG clone before serialisation. Walk the clone against the
60
+ live tree and write the resolved properties as inline style. Keep it to the properties that matter
61
+ for chart rendering rather than dumping every computed property — a full dump produces enormous
62
+ files and is its own defect.
63
+ 2. **Rasterise the container for PNG.** The `chartRef` node ChartFrame already passes
64
+ (`ChartFrame.jsx:138`) is the right root — it holds the chart plus everything the panel renders
65
+ beside it.
66
+ 3. **Stop relying on "the first SVG"** for the SVG path — take the chart deliberately, not
67
+ positionally.
68
+ 4. **Preserve the public signatures.** `exportChartSvg(container, filename)` and
69
+ `exportChartPng(container, filename, backgroundColour)` are consumed by `ChartFrame` and possibly
70
+ directly; the change is what they produce, not how they are called.
71
+
72
+ **`src/components/charts/ChartFrame.jsx`** — labels or tooltips that distinguish the two outputs.
73
+ Translated via the existing `chartsTranslations` path, not hard-coded.
74
+
75
+ ### Non-goals / do not touch
76
+
77
+ - The chart presets, `resolveChartLayout`, the size scale, the axis bands.
78
+ - Consuming apps. hram's six panels with `exportOptions` gain the fix through the pin bump; that is
79
+ a separate row.
80
+ - Adding export to panels that do not have it (`HRAM-RES-43` did that for one panel in hram).
81
+
82
+ ### Risks
83
+
84
+ - **A rasteriser is a new dependency in shared-core**, and this package currently has exactly one
85
+ runtime dependency (`@fontsource/dm-sans`). Adding a second is a real decision — check whether the
86
+ job can be done with the platform's own APIs first, and if a library is warranted, say why in the
87
+ WO's implementation record rather than just installing one.
88
+ - **Canvas tainting.** DOM-to-canvas rasterisation routes through an SVG `foreignObject`; any
89
+ external image or font reference taints the canvas and `toBlob` throws. The existing PNG path
90
+ already has this exposure and may already be failing on it — worth checking before assuming the new
91
+ path introduces it.
92
+ - **Fonts in the SVG.** Inlining computed styles records `font-family: "DM Sans"`, which a machine
93
+ without that font will substitute. Either embed the font or accept the substitution — but decide it
94
+ and write it down, because a silently substituted font is exactly the "looks different" complaint
95
+ this WO is fixing.
96
+ - **Style inlining can bloat.** See scope item 1.
97
+ - **This has no test that can see it.** A unit test can assert that a `style` attribute exists; it
98
+ cannot see that the file looks right. See verification.
99
+
100
+ ### Verification
101
+
102
+ **Open the exported files.** That is the whole gate, and its absence is why this defect shipped: the
103
+ SVG in a viewer and the PNG in an image viewer, both compared against the rendered panel.
104
+
105
+ Do it for **two** panels with different shapes — one with a hand-built legend and size key
106
+ (`AccessGapScatterPanel`), one without — because the legend behaviour is precisely what differs
107
+ between the two export paths.
108
+
109
+ Unit tests: the SVG clone carries inlined styles for tick labels and axis strokes; both entry points
110
+ still resolve with their existing signatures; the PNG path resolves for a container holding more than
111
+ one SVG.
112
+
113
+ ---
114
+
115
+ ## Part B — Implementation map
116
+
117
+ `.claude/models.local.json` has no local override, so the default applies: `implementation.runtime`
118
+ is `claude`/`sonnet` — the Orchestrator implemented directly, no Codex dispatch.
119
+
120
+ **Dependency decision (risk section, and Part C's approval gate):** no library added. Checked
121
+ first, per the WO's own instruction, and it held up: the platform's own `<foreignObject>` → `Image`
122
+ → `<canvas>` pipeline works for arbitrary DOM rasterisation with no dependency at all. The one
123
+ obstacle — **confirmed live, not assumed** — is that Chrome taints the canvas on `toBlob`
124
+ unconditionally the moment the source SVG contains a `<foreignObject>` with HTML content, even with
125
+ zero external references (a minimal repro: a `<foreignObject>` holding one `<div>` with inline
126
+ `color: red` styling and no images/fonts/external refs still throws `SecurityError: Tainted
127
+ canvases may not be exported` when the SVG is loaded via `URL.createObjectURL`). The SAME SVG loaded
128
+ via a `data:` URI instead does **not** taint the canvas — confirmed with an identical minimal repro,
129
+ then re-confirmed end-to-end against the real `exportChartPng`/`ChartFrame` (real Chrome, via the
130
+ dev harness). This is why the approval gate never triggered: the platform-only approach IS viable,
131
+ it just needed the `blob:` → `data:` URI swap in `rasterize` (`exportChart.js`), documented inline
132
+ there.
133
+
134
+ **Canvas tainting on the PRE-FIX path:** checked per the risk section's own instruction ("may
135
+ already be failing on it"). It was not — a plain SVG-only blob (no `foreignObject`) loaded via
136
+ `URL.createObjectURL` does **not** taint the canvas; the exposure is specific to the `foreignObject`
137
+ this WO's PNG path adds, not a pre-existing defect.
138
+
139
+ **Verification (both real-browser, via the dev harness's module graph — `dev/entries.jsx` never
140
+ committed a probe entry, all verification was done by dynamically rendering `ChartFrame` into a
141
+ detached container and calling the real `exportChartSvg`/`exportChartPng`):**
142
+
143
+ - Panel shape WITH a hand-built legend + size key (mirroring `AccessGapScatterPanel`: MUI's own
144
+ legend hidden, a `<div>` HTML legend with a coloured swatch, a second `<svg>` "size key" beside
145
+ the chart): PNG rasterised at 2x scale, no taint, and pixel-sampling the produced PNG at the
146
+ swatch's and size-key's known screen coordinates read back their EXACT source colours
147
+ (`rgb(25,118,210)` / `#1976d2` and `rgb(156,39,176)` / `#9c27b0`) — the legend and size key are
148
+ genuinely present in the raster, not just "no error thrown". SVG export of the same panel:
149
+ contains `MuiChartsSurface-root` (the chart), does NOT contain the legend's own text/markup —
150
+ chart-only as designed.
151
+ - Panel shape WITHOUT a hand-built legend (plain `BarChart` inside `ChartFrame`): both exports
152
+ resolve cleanly, no regression for the common case.
153
+
154
+ Context package used: `exportChart.js` (rewritten in full, was short), `ChartFrame.jsx:42-108`
155
+ (the `runExport`/`exportOptions` wiring) and `:137-151` (`chartRef`, the export root — confirmed
156
+ correct: it wraps `content` only, excluding the meta/export-button footer), `chartsTranslations.ts`
157
+ (new `EXPORT_SVG_TOOLTIP`/`EXPORT_PNG_TOOLTIP` keys, all four locales).
158
+
159
+ ---
160
+
161
+ ## Part C — Orchestrator only
162
+
163
+ > **STOP — everything below addresses the Orchestrator.**
164
+
165
+ **Tier 3 · verification: opened files for two panel shapes, plus the unit tests above**
166
+
167
+ Shared-core, and — depending on scope item 2's answer — a dependency addition, which is its own
168
+ approval surface under Core Behaviour. If a library is needed, **stop and get the operator's
169
+ approval for that specific dependency** before adding it; the approval given on 2026-08-25 was for
170
+ the approach, not for a named package.
171
+
172
+ - `reviewer` — the inlining's completeness and the taint/font questions.
173
+ - `ui_reviewer` — whether the two buttons now read as two different things to a user.
174
+ - `sec_reviewer` — not run; no auth, data or exposure surface.
175
+
176
+ ### Release
177
+
178
+ **Minor → 3.3.0**, per the operator. The PNG's *content* changes (it now includes the legend and
179
+ footnotes), so the CHANGELOG entry must **lead** with that, in the style `UCM-CHART-15` established:
180
+ a consumer who bumps and finds their exported PNGs different should read why in the first line, not
181
+ find it in a bullet.
182
+
183
+ ### Register
184
+
185
+ Row `UCM-CHART-17`, both review notes, the published version, landing SHA(s) in a second commit
186
+ before the push. Record what the opened files actually looked like — that evidence is the point.
187
+
188
+ Consumer adoption (hram's pin bump) is a separate row; a shared-core fix that is published but not
189
+ consumed is not finished.
190
+
191
+ ### Log
192
+
193
+ - **2026-08-25** — Envelope authored after the operator reported exports producing graphically very
194
+ different plots. Diagnosed from source, not reproduced by the Expertenchat: the operator has seen
195
+ the files. Option C chosen — SVG stays vector and chart-only, PNG becomes what the screen shows.
@@ -0,0 +1,200 @@
1
+ # UCM-CHART-18 — The PNG export shows what the chart says, not what the user can click
2
+
3
+ ## Part A — Envelope
4
+
5
+ *Authored by the Expertenchat. Authoritative WHAT/WHY.*
6
+
7
+ ### Goal
8
+
9
+ The whole-container PNG export contains the chart and everything that **explains** it, and none of the
10
+ controls that **operate** it. And a rotated element exports rotated.
11
+
12
+ ### Two defects, one file, a few lines apart
13
+
14
+ Both raised by `HRAM-CHT-7`'s independent `ui_reviewer` on 2026-08-25 and confirmed — partly by
15
+ reading, partly live in the running app.
16
+
17
+ **1. Interactive controls are in the image.** Since 3.3.0 the PNG rasterises `ChartFrame`'s whole
18
+ `chartRef` box, and `chartRef` wraps `children` only — not `toolbar`, `controls` or `meta`. Anything a
19
+ panel renders as children is now in the file. In hram:
20
+
21
+ - `StructuralReachabilityPanel.jsx:468` — the footer "More about these caveats" `IconButton`, always
22
+ visible, so **every** PNG of that panel carries a button.
23
+ - `AllocationPerformancePanel.jsx:536,548` — the drill-down `Button`, and `ResearchDrilldownPanel`
24
+ itself when open, both inside the `<ChartFrame>` children.
25
+ - `OptimizationResultsPanel.jsx:1120,1141` — the same shape on the frontier chart.
26
+
27
+ **2. `transform` is not inlined.** `CHART_STYLE_PROPERTIES` (`:32-36`) and
28
+ `CONTAINER_LAYOUT_STYLE_PROPERTIES` (`:44-52`) do not list it, so
29
+ `OptimizationResultsPanel.jsx:1107`'s rotated legend swatch exports as a **square instead of a
30
+ diamond**.
31
+
32
+ ### Why this is fixed here and not in the consuming app
33
+
34
+ The alternative was moving each panel's controls out of `children` into `ChartFrame`'s `controls` /
35
+ `toolbar` slots, which sit outside `chartRef`. That was rejected, for two reasons:
36
+
37
+ - **It is a property of the element kind, not of each panel.** An exported image should show what the
38
+ chart communicates, not what can be clicked. Solved generically here, it also holds for every
39
+ consumer nobody has looked at.
40
+ - **It would undo a deliberate design decision.** `StructuralReachabilityPanel`'s info affordance sits
41
+ in the **footer**, beside the caveat line, because `HRAM-RES-30` put it there. Hoisting it into the
42
+ toolbar to dodge an export defect would trade a design choice for a workaround.
43
+
44
+ After this, hram needs **only a pin bump** — `HRAM-CHT-8` becomes a consumer row, not a rebuild of
45
+ three panels.
46
+
47
+ ### Scope
48
+
49
+ `src/components/charts/exportChart.js`
50
+
51
+ 1. **Drop interactive controls from the container clone** in `containerSvgBlob` (`:120`) — `button`,
52
+ `input`, `select`, `textarea`, `[role="button"]` at minimum. The SVG path is unaffected: it
53
+ exports the chart surface, which holds no HTML controls.
54
+
55
+ 2. **Do it *after* `inlineComputedStyles`, never before.** That function walks source and clone
56
+ **in lockstep by index** (`:70-77`, `sourceNodes[index]` ↔ `cloneNodes[index]`). Removing nodes
57
+ from the clone first shifts every subsequent index, so elements silently receive their
58
+ neighbours' styles — an export that looks plausible and is wrong everywhere after the first
59
+ removal. **This is the single most likely way to get this WO wrong.**
60
+
61
+ 3. **Add `transform` (and `transform-origin`) to the inlined properties.**
62
+
63
+ ### Non-goals / do not touch
64
+
65
+ - The SVG export path, `findChartSvg`, the `data:`-URI decision, the taint workaround —
66
+ `UCM-CHART-17`, done and verified.
67
+ - `ChartFrame`'s slot structure. `chartRef` wrapping `children` only is correct; the fix is what the
68
+ rasteriser does with them.
69
+ - The consuming panels. hram's adoption is `HRAM-CHT-8`.
70
+
71
+ ### Risks
72
+
73
+ - **The lockstep-index trap.** Scope item 2. Name it in the code comment too, not only here.
74
+ - **What disappears must be operation, not content.** A consumer whose legend items are `<button>`s —
75
+ MUI's own legend can be interactive — would lose its legend to this change. The affected hram panels
76
+ all pass `hideLegend`, so they are not the test case. **Verify against a chart that keeps MUI's own
77
+ legend**, and if it vanishes, that is a finding that changes the approach, not a detail to paper
78
+ over.
79
+ - **`transform` may double-apply on SVG nodes.** An SVG element can carry `transform` as a
80
+ *presentation attribute*, which the clone already keeps, while `getComputedStyle` returns the
81
+ resolved CSS transform. Writing that inline could compose with the attribute and move the element
82
+ twice. Check on a chart with rotated tick labels (`xLabels="angled"`) before assuming it is inert.
83
+ - Removing nodes changes layout if anything sized around them — a flex row that held a button now
84
+ has one fewer item. Expected, but look at it rather than assuming it is invisible.
85
+
86
+ ### Verification
87
+
88
+ **Open the files.** Same gate as `UCM-CHART-17`, and for the same reason — both of these defects were
89
+ invisible to every test and visible immediately in an exported image.
90
+
91
+ 1. A PNG of a panel with a control in `children`: the control is gone, everything else is where it
92
+ was.
93
+ 2. A PNG of a chart that keeps **MUI's own legend**: the legend is still there. This is the
94
+ counter-check for the risk above, and it is not optional.
95
+ 3. A rotated element exports rotated — the diamond is a diamond.
96
+ 4. A chart with `xLabels="angled"`: tick labels are not doubly rotated or displaced.
97
+
98
+ Unit tests: the clone contains no `button` after export; a non-interactive sibling at the same depth
99
+ survives; `transform` appears in the inlined declarations.
100
+
101
+ ---
102
+
103
+ ## Part B — Implementation map
104
+
105
+ `.claude/models.local.json` has no local override, so the default applies: `implementation.runtime`
106
+ is `claude`/`sonnet` — the Orchestrator implemented directly, no Codex dispatch.
107
+
108
+ Implemented exactly per scope: `transform`/`transform-origin` added to `CHART_STYLE_PROPERTIES`
109
+ (shared by both export paths); a new `INTERACTIVE_CONTROL_SELECTOR`
110
+ (`button, input, select, textarea, [role="button"]`) and `stripInteractiveControls` helper, called
111
+ in `containerSvgBlob` strictly **after** `inlineComputedStyles` (the lockstep-index trap named in
112
+ the WO) — verified by temporarily reverting the ordering-safe call and confirming the new tests
113
+ fail, then restoring.
114
+
115
+ **Verification (real Chrome, via the dev harness's module graph — no probe entry committed to
116
+ `dev/entries.jsx`, all four cases rendered via direct script injection into detached containers):**
117
+
118
+ 1. Control in `children` (an `IconButton` beside a `<span>` caveat note, mirroring
119
+ `StructuralReachabilityPanel`'s footer affordance): captured the PNG path's actual intermediate
120
+ SVG (intercepting `Image.src`) and confirmed no `<button` tag and no button text present, while
121
+ the sibling text and the chart itself both survive.
122
+ 2. MUI's own legend (two-series `BarChart`, no `hideLegend`): confirmed live that MUI's legend
123
+ renders as `<ul>/<li>/<div>/<span>` (no `button`/`role="button"` in it), then confirmed both
124
+ series labels ("Opened", "Resolved") and the `MuiChartsLegend-root` class survive the export
125
+ fully intact.
126
+ 3. Rotated element: a 24x24px swatch with `transform: rotate(45deg)`, exported to PNG and
127
+ pixel-sampled on a real `<canvas>` — the swatch's own bounding-box corner reads back as
128
+ background white, its centre as the swatch's own red, i.e. a genuine diamond (clipped corners),
129
+ not an unrotated square.
130
+ 4. `xLabels="angled"` (7 long category labels): the exported tick `<text>` carries BOTH its
131
+ original `transform="rotate(-45, 30, 9)"` XML presentation attribute (kept by `cloneNode`) AND
132
+ the newly-inlined `style="transform: matrix(0.707107, -0.707107, 0.707107, 0.707107, ...)"`.
133
+ The matrix values are exactly `cos(-45°)=0.707107, sin(-45°)=-0.707107` — a SINGLE 45° rotation,
134
+ not a doubled/composed one (which would show different values, e.g. matching -90°) — confirming
135
+ the inline `style` declaration wins over the presentation attribute (SVG2: presentation
136
+ attributes carry the lowest specificity) rather than composing with it. Tick text still renders
137
+ non-blank.
138
+
139
+ Context package used: `exportChart.js` in full (short, already read start to finish),
140
+ `ChartFrame.jsx:137-151` (`chartRef` — re-confirmed it wraps `children` only).
141
+
142
+ **Post-review correction, both reviewers converging independently on the same gap the WO's own
143
+ risk section named:** the initial `stripInteractiveControls` removed EVERY matched element
144
+ outright, including MUI's own chart legend when it is interactive
145
+ (`onItemClick`/`toggleVisibilityOnClick`) — X-Charts renders each legend item as
146
+ `<button role="button" class="...MuiChartsLegend-series...">` wrapping the series swatch and
147
+ label, so a blanket removal deleted the legend's content along with its click handler. This is
148
+ EXACTLY the WO's own risk section, made concrete: "if it vanishes, that is a finding that changes
149
+ the approach, not a detail to paper over." Fixed by UNWRAPPING `MuiChartsLegend-series` matches
150
+ (replace with a plain `<span>` carrying the same class/style/children) instead of removing them —
151
+ content survives, only the (irrelevant, in a static image) clickability is dropped. Re-verified
152
+ live against a REAL interactive legend (`slotProps={{ legend: { toggleVisibilityOnClick: true } }}`,
153
+ confirmed the live legend items render as actual `<BUTTON>` tags): the export contains zero
154
+ `<button` tags, but `MuiChartsLegend-series` and both series labels survive intact. `INTERACTIVE_
155
+ CONTROL_SELECTOR` also broadened to `a[href]`/`[role="link"]` (reviewer finding — a drill-down
156
+ built as a link, not only a `<Button>`, is equally out of place in an export).
157
+
158
+ Also fixed a genuine test-coverage gap the reviewer found: the original ordering test's `<button>`
159
+ was the LAST descendant in its fixture, so a "strip before inline" regression would not have shifted
160
+ any node the test actually asserted on — content-presence checks can't observe a style
161
+ misattribution at all, only a missing/wrong STYLE VALUE can. Rewrote it with a distinctively-styled
162
+ sibling AFTER the button (stylesheet-driven colour, not an inline style `cloneNode` would copy
163
+ regardless) and confirmed, by temporarily reverting the call order, that the new assertion actually
164
+ fails when the order is wrong (the button's own style — `border-style: none`, `text-align: center`
165
+ — leaks onto the trailing sibling).
166
+
167
+ ---
168
+
169
+ ## Part C — Orchestrator only
170
+
171
+ > **STOP — everything below addresses the Orchestrator.**
172
+
173
+ **Tier 3 · verification: opened files for the four cases above, plus the unit tests**
174
+
175
+ Shared-core, by the tiering table regardless of diff size.
176
+
177
+ - `ui_reviewer` — what belongs in an exported image, and the MUI-legend counter-check.
178
+ - `reviewer` — the ordering trap and the `transform` double-apply question.
179
+ - `sec_reviewer` — not run; no auth, data or exposure surface.
180
+
181
+ ### Release
182
+
183
+ **Patch → 3.3.1.** This repairs behaviour 3.3.0 itself introduced — the whole-container PNG was never
184
+ meant to carry buttons — rather than adding capability. `UCM-CHART-16` (a repair) went out as a patch
185
+ on the same reasoning, while `-15` and `-17` were minors because they changed what a consumer gets on
186
+ purpose. The CHANGELOG should still say plainly that exported PNGs no longer contain controls; a
187
+ consumer who liked the button in their image deserves to find out by reading, not by looking.
188
+
189
+ ### Register
190
+
191
+ Row `UCM-CHART-18`, both review notes, the published version, landing SHA(s) in a second commit
192
+ before the push. Record what the opened files looked like, including the MUI-legend counter-check.
193
+
194
+ Consumer adoption is `HRAM-CHT-8`, which this WO reduces to a pin bump.
195
+
196
+ ### Log
197
+
198
+ - **2026-08-25** — Envelope authored. The operator chose the shared-core fix over moving controls in
199
+ three hram panels, so that the rule holds for every consumer and `HRAM-RES-30`'s footer placement
200
+ survives.