Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(playground): retain query marker paint in PNG exports (#2092, from #2074)

xerj-org8a89a0bc379e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2ad34569e..115a98d95 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
denied or the legacy copy command fails, and retain their original label
after repeated clicks. A failed copy can be retried.
+- Playground PNG exports preserve computed SVG paint and text styles, including
+ the embedding query crosshair whose CSS-variable stroke disappeared when
+ rasterized outside the page stylesheet. The live chart is left unchanged.
+
- `xerj search` and a plain-string `xerj_search` rank a file that contains
the query as an exact phrase (a pasted error message or log line) at the
top. The bag-of-words leg alone let a short `defs` list sharing two of the
diff --git a/landing/playground/app.bundle.js b/landing/playground/app.bundle.js
index ea2ce788d..e8277e786 100644
--- a/landing/playground/app.bundle.js
+++ b/landing/playground/app.bundle.js
@@ -5048,6 +5048,31 @@ borrows the accent color.`
clone.setAttribute("height", String(h));
const cs = getComputedStyle(svgEl);
clone.setAttribute("color", cs.color);
+ const properties = [
+ "color",
+ "fill",
+ "fill-opacity",
+ "stroke",
+ "stroke-width",
+ "stroke-opacity",
+ "stroke-dasharray",
+ "opacity",
+ "font-family",
+ "font-size",
+ "font-weight",
+ "letter-spacing",
+ "text-anchor",
+ "dominant-baseline"
+ ];
+ const originals = [svgEl, ...svgEl.querySelectorAll("*")];
+ const copies = [clone, ...clone.querySelectorAll("*")];
+ originals.forEach((element, index) => {
+ const computed = getComputedStyle(element);
+ for (const property of properties) {
+ const value = computed.getPropertyValue(property);
+ if (value) copies[index].style.setProperty(property, value);
+ }
+ });
if (!clone.getAttribute("xmlns")) {
clone.setAttribute("xmlns", "http://www.w3.org/2000/svg");
}
diff --git a/landing/playground/src/data/export.js b/landing/playground/src/data/export.js
index 73ca7f9fb..2ac17a102 100644
--- a/landing/playground/src/data/export.js
+++ b/landing/playground/src/data/export.js
@@ -78,6 +78,21 @@ export async function svgToPng(svgEl, { scale = 2, filename = 'chart.png' } = {}
// Inline computed color so currentColor resolves
const cs = getComputedStyle(svgEl);
clone.setAttribute('color', cs.color);
+ // A detached SVG image cannot inherit the page stylesheet or custom
+ // properties. Snapshot computed paint on every node so query markers,
+ // highlighted series and labels survive rasterization.
+ const properties = ['color', 'fill', 'fill-opacity', 'stroke', 'stroke-width',
+ 'stroke-opacity', 'stroke-dasharray', 'opacity', 'font-family', 'font-size',
+ 'font-weight', 'letter-spacing', 'text-anchor', 'dominant-baseline'];
+ const originals = [svgEl, ...svgEl.querySelectorAll('*')];
+ const copies = [clone, ...clone.querySelectorAll('*')];
+ originals.forEach((element, index) => {
+ const computed = getComputedStyle(element);
+ for (const property of properties) {
+ const value = computed.getPropertyValue(property);
+ if (value) copies[index].style.setProperty(property, value);
+ }
+ });
// Add namespace
if (!clone.getAttribute('xmlns')) {
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
diff --git a/scripts/landing/png_export_fixture.html b/scripts/landing/png_export_fixture.html
new file mode 100644
index 000000000..fe4dc958d
--- /dev/null
+++ b/scripts/landing/png_export_fixture.html
@@ -0,0 +1,16 @@
+<!doctype html><meta charset="utf-8"><title>XERJ SVG export regression fixture</title>
+<style>:root{--z-accent:#ffcc00;--z-paper:#ffffff;--font-data:monospace;--font-prose:sans-serif;color:#222}body{font:16px sans-serif;margin:24px}svg,img{width:600px;height:180px;border:1px solid #ccc;display:block}.series-legend{display:none}pre{white-space:pre-wrap}</style>
+<h1>Embedding query marker export</h1><p>Live production chart: yellow crosshair identifies the query location.</p><div id="chart"></div><button id="export">Export with production svgToPng</button><p>Exported PNG:</p><img id="png"><pre id="result">Ready</pre>
+<script type="module">
+import {EmbedSpace} from '/landing/playground/src/ux/charts-ai.js';
+import {svgToPng} from '/landing/playground/src/data/export.js';
+chart.innerHTML=EmbedSpace({clusters:[{label:'CLUSTER',points:[[0,0],[1,1],[0,1],[1,0]],centroid:[0.2,0.2]}],highlight:[0.5,0.5]});
+document.querySelector('button').onclick=async()=>{
+ try {
+ const svg=document.querySelector('svg');const liveStroke=getComputedStyle(svg.querySelector('line[stroke="var(--z-accent)"]')).stroke;
+ const blob=await svgToPng(svg,{scale:1,filename:'xerj-query-marker-fixture.png'});const url=URL.createObjectURL(blob);png.src=url;await png.decode();
+ const canvas=document.createElement('canvas');canvas.width=png.naturalWidth;canvas.height=png.naturalHeight;const ctx=canvas.getContext('2d');ctx.drawImage(png,0,0);const pixels=ctx.getImageData(0,0,canvas.width,canvas.height).data;let yellow=0;for(let i=0;i<pixels.length;i+=4)if(pixels[i]>200&&pixels[i+1]>130&&pixels[i+2]<100)yellow++;
+ result.textContent=JSON.stringify({liveQueryStroke:liveStroke,pngWidth:canvas.width,pngHeight:canvas.height,exportedYellowPixels:yellow,pngQueryCrosshairPixel:[...ctx.getImageData(Math.floor(canvas.width/2),20,1,1).data],pngBackgroundPixel:[...ctx.getImageData(0,0,1,1).data]},null,2);
+ }catch(e){result.textContent=e.stack;}
+};
+</script>
diff --git a/scripts/landing/test_png_export.cjs b/scripts/landing/test_png_export.cjs
new file mode 100644
index 000000000..d9825a995
--- /dev/null
+++ b/scripts/landing/test_png_export.cjs
@@ -0,0 +1,34 @@
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const path = require('node:path');
+const vm = require('node:vm');
+const {test} = require('node:test');
+
+// Run the actual export pipeline, replacing only browser primitives.
+async function exportFixture() {
+ const child = {name:'query', original:true};
+ const source = {name:'root', original:true, cloneNode:()=>clone,
+ getBoundingClientRect:()=>({width:600,height:180}),querySelectorAll:()=>[child]};
+ const copied=[];
+ const makeClone = name => ({name,attrs:{},style:{setProperty:(key,value)=>copied.push([name,key,value])},setAttribute(key,value){this.attrs[key]=value;},getAttribute(key){return this.attrs[key];},innerHTML:'<line stroke="var(--z-accent)"/>'});
+ const clone=makeClone('root');const clonedChild=makeClone('query');clone.querySelectorAll=()=>[clonedChild];
+ let downloaded=false;
+ const body=[];
+ const document={documentElement:{name:'page'},body:{appendChild:el=>body.push(el),removeChild:el=>body.splice(body.indexOf(el),1)},createElement:type=>type==='canvas'?{getContext:()=>({scale(){},drawImage(){}}),toBlob:cb=>cb({png:true})}:{click(){downloaded=true;}}};
+ const styles={root:{color:'rgb(34, 34, 34)',fill:'rgb(34, 34, 34)',stroke:'none'},query:{color:'rgb(34, 34, 34)',stroke:'rgb(255, 204, 0)',fill:'none','stroke-opacity':'0.5'},page:{'--z-paper':'#ffffff'}};
+ const getComputedStyle=el=>({color:styles[el.name].color,getPropertyValue:key=>styles[el.name][key]||''});
+ const context={document,getComputedStyle,URL:{createObjectURL:()=> 'blob:fixture',revokeObjectURL(){}},setTimeout(){},XMLSerializer:class{serializeToString(){return '<svg/>';}},Image:class{set src(value){this.onload();}}};
+ vm.createContext(context);
+ const sourceCode=fs.readFileSync(path.join(__dirname,'../../landing/playground/src/data/export.js'),'utf8');
+ vm.runInContext(sourceCode.replace(/export /g,''),context);
+ await context.svgToPng(source,{scale:1});
+ return {copied,clone,source,body,downloaded};
+}
+test('PNG snapshot resolves inherited query-marker paint styles before detaching the SVG',async()=>{
+ const p=await exportFixture();
+ assert.ok(p.copied.some(([name,key,value])=>name==='query'&&key==='stroke'&&value==='rgb(255, 204, 0)'));
+ assert.ok(p.copied.some(([name,key,value])=>name==='query'&&key==='stroke-opacity'&&value==='0.5'));
+});
+test('export leaves the live SVG untouched and preserves download and cleanup',async()=>{
+ const p=await exportFixture();assert.equal(p.source.original,true);assert.equal(p.source.style,undefined);assert.equal(p.downloaded,true);assert.equal(p.body.length,0);assert.equal(p.clone.attrs.width,'600');assert.equal(p.clone.attrs.height,'180');
+});
diff --git a/scripts/seo/README.md b/scripts/seo/README.md
index 38025ac82..440d8ed08 100644
--- a/scripts/seo/README.md
+++ b/scripts/seo/README.md
@@ -29,6 +29,20 @@ The temporary feedback restores the original button label. Run the interaction
regressions with `node --test scripts/landing/test_interact.cjs` (Node 18+; no
packages are required).
+Dependency-free landing interaction tests run with
+`node --test scripts/landing/test_*.cjs` (Node 22) in the SEO job. Playground
+PNG export snapshots computed SVG paint styles before rasterization, since a
+detached SVG image cannot inherit the page stylesheet or its custom properties.
+For the real-browser pixel check, serve the repository root with
+`python3 -m http.server 8857 --bind 127.0.0.1`, open
+`http://127.0.0.1:8857/scripts/landing/png_export_fixture.html`, and click the
+export button. The live query stroke and exported PNG must retain the yellow
+crosshair (nonzero yellow pixels and a crosshair pixel distinct from the white
+background). The click downloads one PNG for inspection. This is a static
+fixture; it does not run XERJ or contact external services.
+Regenerate its committed bundle from `landing/` using
+`esbuild playground/src/app.js --bundle --outfile=playground/app.bundle.js`.
+
## 1. Architecture
```