@vyaz/renderer 0.3.0 → 0.4.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.
@@ -85,7 +85,7 @@ export interface SVGRenderOptions {
85
85
  * Content for inline-box spans, keyed by `span.inlineWidget.id`. Each value is
86
86
  * an SVG fragment already sized to the widget's `width` × `height`; it is
87
87
  * spliced into a `<g>` translated to the box the layout reserved. A span whose
88
- * id has no entry gets a light placeholder `<rect>`. Produced by `@vyaz/html`
88
+ * id has no entry gets a light placeholder `<rect>`. Produced by `@vyaz/converters`
89
89
  * for `<img>` / `<svg>` / `<progress>` / … ; irrelevant without inline boxes.
90
90
  */
91
91
  inlineBoxes?: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"SVGRenderer.d.ts","sourceRoot":"","sources":["../src/SVGRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAQ,qBAAqB,EAAE,qBAAqB,EAAkB,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE9I,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,YAAY,CAAC;AAKlE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAElE,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;AAErC,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9C,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG;IAAE,UAAU,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAC;AAE3E,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,sGAAsG;IACtG,KAAK,CAAC,EAAE,QAAQ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AC;IAC3B;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AA+3BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,IAAI,EAAE,GAAG,qBAAqB,EACrC,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CA2TR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,IAAI,EAAE,EACb,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,CAMR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,qBAAqB,EAC7B,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,CAMR"}
@@ -7,7 +7,7 @@
7
7
  * (from `renderToSVG`), positioned with a `<g transform="translate(…)">` —
8
8
  * the same "paint a self-contained SVG fragment into a box" pattern
9
9
  * `SVGRenderOptions.inlineBoxes` uses for `<img>`/`<svg>` boxes from
10
- * `@vyaz/html`. `before`/`after` (`paintSlot`) paint at the absolute
10
+ * `@vyaz/converters`. `before`/`after` (`paintSlot`) paint at the absolute
11
11
  * position `TableLayoutEngine` already resolved for them — no extra
12
12
  * padding/border math here, unlike main content.
13
13
  *
@@ -177,7 +177,10 @@ function equalStyle(a, b) {
177
177
  }
178
178
  function styleSignature(span) {
179
179
  const s = defaultStyleState(span);
180
- return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}|${s.color}|${s.fontStyle}|${s.decoration}|${s.letterSpacing ?? ""}|${s.backgroundColor ?? ""}`;
180
+ return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}|${s.color}|${s.fontStyle}|${s.decoration}|${s.letterSpacing ?? ""}|${s.backgroundColor ?? ""}|${span.style.data?.href ?? ""}`;
181
+ }
182
+ function hrefOf(span) {
183
+ return span.style.data?.href;
181
184
  }
182
185
  function buildTextAttrs(line, span, opts, runId) {
183
186
  const x = line.x;
@@ -430,6 +433,12 @@ ${debugMarkup}
430
433
  "stroke-dasharray": "2,2"
431
434
  }));
432
435
  }
436
+ openLink(href) {
437
+ this.root.children.push(rawNode(`<a href="${escapeXml(href)}">`));
438
+ }
439
+ closeLink() {
440
+ this.root.children.push(rawNode("</a>"));
441
+ }
433
442
  addDecorationLine(x, width, y, color, thickness) {
434
443
  this.closeText();
435
444
  this.root.children.push(el("line", {
@@ -752,6 +761,9 @@ function renderToSVG(input, options = {}) {
752
761
  const baseSpan = group.spans.find((f) => f.type === "text" && f.text.length > 0) || group.spans[0];
753
762
  if (!baseSpan)
754
763
  continue;
764
+ const href = hrefOf(baseSpan);
765
+ if (href)
766
+ builder.openLink(href);
755
767
  const lineBaseY = Math.round((line.y + line.baseline) * 100) / 100;
756
768
  const needsOffset = group.targetY !== lineBaseY;
757
769
  if (needsOffset) {
@@ -794,6 +806,8 @@ function renderToSVG(input, options = {}) {
794
806
  }
795
807
  }
796
808
  builder.closeText();
809
+ if (href)
810
+ builder.closeLink();
797
811
  }
798
812
  }
799
813
  }
package/dist/index.js CHANGED
@@ -141721,7 +141721,10 @@ function equalStyle(a, b) {
141721
141721
  }
141722
141722
  function styleSignature(span) {
141723
141723
  const s = defaultStyleState(span);
141724
- return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}|${s.color}|${s.fontStyle}|${s.decoration}|${s.letterSpacing ?? ""}|${s.backgroundColor ?? ""}`;
141724
+ return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}|${s.color}|${s.fontStyle}|${s.decoration}|${s.letterSpacing ?? ""}|${s.backgroundColor ?? ""}|${span.style.data?.href ?? ""}`;
141725
+ }
141726
+ function hrefOf(span) {
141727
+ return span.style.data?.href;
141725
141728
  }
141726
141729
  function buildTextAttrs(line, span, opts, runId) {
141727
141730
  const x = line.x;
@@ -141974,6 +141977,12 @@ ${debugMarkup}
141974
141977
  "stroke-dasharray": "2,2"
141975
141978
  }));
141976
141979
  }
141980
+ openLink(href) {
141981
+ this.root.children.push(rawNode(`<a href="${escapeXml(href)}">`));
141982
+ }
141983
+ closeLink() {
141984
+ this.root.children.push(rawNode("</a>"));
141985
+ }
141977
141986
  addDecorationLine(x, width, y, color, thickness) {
141978
141987
  this.closeText();
141979
141988
  this.root.children.push(el("line", {
@@ -142296,6 +142305,9 @@ function renderToSVG(input, options = {}) {
142296
142305
  const baseSpan = group.spans.find((f) => f.type === "text" && f.text.length > 0) || group.spans[0];
142297
142306
  if (!baseSpan)
142298
142307
  continue;
142308
+ const href = hrefOf(baseSpan);
142309
+ if (href)
142310
+ builder.openLink(href);
142299
142311
  const lineBaseY = Math.round((line.y + line.baseline) * 100) / 100;
142300
142312
  const needsOffset = group.targetY !== lineBaseY;
142301
142313
  if (needsOffset) {
@@ -142338,6 +142350,8 @@ function renderToSVG(input, options = {}) {
142338
142350
  }
142339
142351
  }
142340
142352
  builder.closeText();
142353
+ if (href)
142354
+ builder.closeLink();
142341
142355
  }
142342
142356
  }
142343
142357
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyaz/renderer",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "SVG renderer for @vyaz/core layout output — text lines and TableFrame grids, four presets (flat/browser/preserve/glyph), plus registerFont() for keeping engine metrics and document.fonts in sync.",
5
5
  "keywords": ["svg", "renderer", "text-layout", "table-layout", "typography"],
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/sedrew/vyaz.git",
11
- "directory": "packages/renderer"
11
+ "directory": "packages/renderers"
12
12
  },
13
13
  "type": "module",
14
14
  "main": "./dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "prepublishOnly": "bun run build"
34
34
  },
35
35
  "dependencies": {
36
- "@vyaz/core": "^0.3.0"
36
+ "@vyaz/core": "^0.4.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26.1.1",