@opendata-ai/openchart-vanilla 9.0.0-rc.1 → 9.0.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.
Files changed (41) hide show
  1. package/README.md +10 -0
  2. package/dist/{chunk-T6IPHUN4.js → chunk-42WVDS3V.js} +186 -38
  3. package/dist/chunk-42WVDS3V.js.map +1 -0
  4. package/dist/{chunk-46E3QB6O.js → chunk-6GRMMSQA.js} +2 -2
  5. package/dist/{chunk-A5C4VCUO.js → chunk-7XFFPRQ7.js} +13 -4
  6. package/dist/chunk-7XFFPRQ7.js.map +1 -0
  7. package/dist/chunk-E3ETKTJQ.js +130 -0
  8. package/dist/chunk-E3ETKTJQ.js.map +1 -0
  9. package/dist/{chunk-5ZLSMZRM.js → chunk-HQ5GADZ4.js} +9 -8
  10. package/dist/{chunk-5ZLSMZRM.js.map → chunk-HQ5GADZ4.js.map} +1 -1
  11. package/dist/{chunk-ERPYVYFW.js → chunk-NGNHQOXO.js} +1065 -972
  12. package/dist/chunk-NGNHQOXO.js.map +1 -0
  13. package/dist/{chunk-RBXIZJPE.js → chunk-OEJHSKFZ.js} +2 -2
  14. package/dist/{chunk-CMIJA63X.js → chunk-RWP23N4D.js} +3 -3
  15. package/dist/chunk-SKQAAHHR.js +533 -0
  16. package/dist/chunk-SKQAAHHR.js.map +1 -0
  17. package/dist/{chunk-NLKQ5AOA.js → chunk-XR4B3SPC.js} +70 -30
  18. package/dist/chunk-XR4B3SPC.js.map +1 -0
  19. package/dist/export-gif.js +4 -4
  20. package/dist/graph-3d/index.js +4 -4
  21. package/dist/index.d.ts +41 -51
  22. package/dist/index.js +85 -216
  23. package/dist/index.js.map +1 -1
  24. package/dist/simulation-worker.js +26 -26
  25. package/dist/static.d.ts +10 -21
  26. package/dist/static.js +417 -118
  27. package/dist/static.js.map +1 -1
  28. package/dist/story/index.js +7 -7
  29. package/dist/styles.css.map +1 -1
  30. package/package.json +4 -7
  31. package/dist/chunk-6YPRYQKD.js +0 -297
  32. package/dist/chunk-6YPRYQKD.js.map +0 -1
  33. package/dist/chunk-A5C4VCUO.js.map +0 -1
  34. package/dist/chunk-ERPYVYFW.js.map +0 -1
  35. package/dist/chunk-FFP5GXIP.js +0 -45
  36. package/dist/chunk-FFP5GXIP.js.map +0 -1
  37. package/dist/chunk-NLKQ5AOA.js.map +0 -1
  38. package/dist/chunk-T6IPHUN4.js.map +0 -1
  39. /package/dist/{chunk-46E3QB6O.js.map → chunk-6GRMMSQA.js.map} +0 -0
  40. /package/dist/{chunk-RBXIZJPE.js.map → chunk-OEJHSKFZ.js.map} +0 -0
  41. /package/dist/{chunk-CMIJA63X.js.map → chunk-RWP23N4D.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  cubicInOut,
3
3
  cubicOut
4
- } from "./chunk-NLKQ5AOA.js";
4
+ } from "./chunk-XR4B3SPC.js";
5
5
 
6
6
  // src/resize-observer.ts
7
7
  var DEBOUNCE_MS = 16;
@@ -360,4 +360,4 @@ export {
360
360
  prefersReducedMotion,
361
361
  createTween
362
362
  };
363
- //# sourceMappingURL=chunk-46E3QB6O.js.map
363
+ //# sourceMappingURL=chunk-6GRMMSQA.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  SVG_NS
3
- } from "./chunk-FFP5GXIP.js";
3
+ } from "./chunk-E3ETKTJQ.js";
4
4
 
5
5
  // src/theme-style-block.ts
6
6
  import { adaptForLightLineStroke, CSS_TOKENS, cssTokenDefault } from "@opendata-ai/openchart-core";
7
- function buildThemeStyleBlock(theme) {
7
+ function buildThemeStyleBlock(theme, rootId) {
8
8
  const accent = theme.colors.categorical[0] ?? cssTokenDefault("--oc-accent", "light");
9
9
  const bg = theme.colors.neutral.surface;
10
10
  const props = [
@@ -66,7 +66,16 @@ function buildThemeStyleBlock(theme) {
66
66
  `.oc-legend-entry { cursor: default; }`,
67
67
  `.oc-legend text { fill: var(--oc-legend-text); }`
68
68
  ];
69
- return rules.join("\n");
69
+ const css = rules.join("\n");
70
+ if (!rootId) return css;
71
+ const selectorId = rootId.replaceAll(".", "\\.");
72
+ return css.replace(
73
+ /([^{}]+)\{/g,
74
+ (_match, selectors) => `${selectors.split(",").map((selector) => {
75
+ const value = selector.trim();
76
+ return value.startsWith("svg.") ? `${value}#${selectorId}` : `#${selectorId} ${value}`;
77
+ }).join(", ")} {`
78
+ );
70
79
  }
71
80
  function injectThemeStyleBlock(svg, theme) {
72
81
  if (!theme) return;
@@ -104,4 +113,4 @@ export {
104
113
  copyComputedThemeProperties,
105
114
  prepareSettledExportTheme
106
115
  };
107
- //# sourceMappingURL=chunk-A5C4VCUO.js.map
116
+ //# sourceMappingURL=chunk-7XFFPRQ7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/theme-style-block.ts"],"sourcesContent":["/**\n * Theme `<style>` block for self-contained SVG export.\n *\n * Charts render most fills as inline SVG attributes, but a handful of chrome\n * elements (metric cells, the eyebrow dot, legend text, endpoint labels)\n * take their fill from CSS classes in `chrome.css` via `--oc-*` variables. That\n * works on-screen because the live SVG inherits the page stylesheet — but a\n * serialized/rasterized export (PNG/JPG/GIF) is detached from the page, so those\n * class-based fills vanish. This module builds a `<style>` block that resolves\n * every such rule against a concrete `ResolvedTheme`, so injecting it into an\n * export clone makes the SVG fully self-contained.\n *\n * Both the headless renderer (`static.ts`) and the browser export path use this,\n * so class-based styling round-trips identically no matter which path produced\n * the SVG. Browser-safe (no Node imports) so the browser exporters can import it.\n */\n\nimport type { ResolvedTheme } from '@opendata-ai/openchart-core';\nimport { adaptForLightLineStroke, CSS_TOKENS, cssTokenDefault } from '@opendata-ai/openchart-core';\nimport { SVG_NS } from './renderers/svg-dom';\n\n/**\n * Build the theme `<style>` block CSS text for a resolved theme. Sets the\n * `--oc-*` custom properties on each supported SVG root and defines every class-based\n * chrome rule against them.\n */\nexport function buildThemeStyleBlock(theme: ResolvedTheme, rootId?: string): string {\n const accent = theme.colors.categorical[0] ?? cssTokenDefault('--oc-accent', 'light');\n const bg = theme.colors.neutral.surface;\n\n const props = [\n `--oc-font-family: ${theme.fonts.family}`,\n `--oc-font-mono: ${theme.fonts.mono}`,\n `--oc-title-size: ${theme.chrome.title.fontSize}px`,\n `--oc-title-weight: ${theme.chrome.title.fontWeight}`,\n `--oc-title-tracking: ${cssTokenDefault('--oc-title-tracking', 'light')}`,\n `--oc-subtitle-size: ${theme.chrome.subtitle.fontSize}px`,\n `--oc-subtitle-weight: ${theme.chrome.subtitle.fontWeight}`,\n `--oc-source-size: ${theme.chrome.source.fontSize}px`,\n `--oc-source-weight: ${theme.chrome.source.fontWeight}`,\n `--oc-body-size: ${theme.fonts.sizes.body}px`,\n `--oc-eyebrow-size: ${theme.chrome.eyebrow.fontSize}px`,\n `--oc-eyebrow-weight: ${theme.chrome.eyebrow.fontWeight}`,\n `--oc-eyebrow-tracking: ${cssTokenDefault('--oc-eyebrow-tracking', 'light')}`,\n `--oc-bg: ${bg}`,\n `--oc-text: ${theme.colors.text}`,\n `--oc-text-muted: ${theme.colors.axis}`,\n `--oc-text-secondary: ${theme.colors.neutral.secondary}`,\n `--oc-text-faint: ${theme.colors.neutral.faint}`,\n `--oc-border: ${theme.colors.neutral.border}`,\n `--oc-gridline: ${theme.colors.gridline}`,\n // Hairline, not the tick-label ink.\n `--oc-axis: ${theme.colors.hairline}`,\n `--oc-border-radius: ${theme.borderRadius}px`,\n `--oc-accent: ${accent}`,\n `--oc-accent-strong: ${adaptForLightLineStroke(accent)}`,\n `--oc-positive: ${theme.colors.positive}`,\n `--oc-negative: ${theme.colors.negative}`,\n `--oc-legend-text: ${theme.isDark ? cssTokenDefault('--oc-legend-text', 'dark') : cssTokenDefault('--oc-legend-text', 'light')}`,\n `--oc-space-2: ${theme.spacing.chromeGap * 2}px`,\n `--oc-space-4: ${theme.spacing.padding}px`,\n ];\n\n const rules = [\n // Tabular figures everywhere in the chart's own text: axis ticks, value\n // labels and legend entries all line up column-wise.\n `svg.oc-chart, svg.oc-map, svg.oc-tilemap, svg.oc-barlist { ${props.join('; ')}; font-variant-numeric: tabular-nums; }`,\n `.oc-chrome { font-family: var(--oc-font-family); }`,\n `.oc-eyebrow { font-size: var(--oc-eyebrow-size); font-weight: var(--oc-eyebrow-weight); letter-spacing: var(--oc-eyebrow-tracking); text-transform: uppercase; fill: var(--oc-accent); }`,\n `.oc-title { font-size: var(--oc-title-size); font-weight: var(--oc-title-weight); letter-spacing: var(--oc-title-tracking); fill: var(--oc-text); }`,\n `.oc-subtitle { font-size: var(--oc-subtitle-size); font-weight: var(--oc-subtitle-weight); fill: var(--oc-text-muted); }`,\n `.oc-source, .oc-byline, .oc-footer { font-size: var(--oc-source-size); font-weight: var(--oc-source-weight); fill: var(--oc-text-muted); }`,\n `.oc-brand { font-size: 11px; font-weight: 500; letter-spacing: 0.02em; fill: var(--oc-text-faint); }`,\n `.oc-eyebrow-dot { fill: var(--oc-accent); }`,\n `.oc-metrics { font-family: var(--oc-font-family); }`,\n `.oc-metric-label { font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; fill: var(--oc-text-muted); }`,\n `.oc-metric-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; fill: var(--oc-text); font-variant-numeric: tabular-nums; }`,\n `.oc-metric-delta-up { fill: var(--oc-positive); font-size: 12px; font-weight: 500; }`,\n `.oc-metric-delta-down { fill: var(--oc-negative); font-size: 12px; font-weight: 500; }`,\n `.oc-axis-tick-inline { font-size: 11px; font-weight: 400; fill: var(--oc-text-muted); }`,\n `.oc-endpoint-labels { font-family: var(--oc-font-family); }`,\n `.oc-endpoint-label { fill: var(--oc-endpoint-label-color, var(--oc-text)); }`,\n `.oc-endpoint-value { fill: var(--oc-endpoint-value-color, var(--oc-text-muted)); }`,\n `.oc-endpoint-leader { stroke: var(--oc-endpoint-leader-color, currentColor); }`,\n `.oc-annotation-subtitle { fill: var(--oc-annotation-subtitle-color, var(--oc-text-muted)); }`,\n `.oc-metric-secondary { fill: var(--oc-text-muted); font-size: 12px; font-weight: 400; }`,\n `.oc-legend { font-family: var(--oc-font-family); font-size: var(--oc-body-size); }`,\n `.oc-legend-entry { cursor: default; }`,\n `.oc-legend text { fill: var(--oc-legend-text); }`,\n ];\n\n const css = rules.join('\\n');\n if (!rootId) return css;\n const selectorId = rootId.replaceAll('.', '\\\\.');\n return css.replace(\n /([^{}]+)\\{/g,\n (_match, selectors: string) =>\n `${selectors\n .split(',')\n .map((selector) => {\n const value = selector.trim();\n return value.startsWith('svg.') ? `${value}#${selectorId}` : `#${selectorId} ${value}`;\n })\n .join(', ')} {`,\n );\n}\n\n/**\n * Inject the theme style block into an SVG clone's `<defs>` so class-based fills\n * survive serialization. Replaces any prior export theme block, so repeated\n * preparation produces one block. No-op if `theme` is\n * undefined (nothing to resolve against).\n */\nexport function injectThemeStyleBlock(svg: SVGElement, theme: ResolvedTheme | undefined): void {\n if (!theme) return;\n for (const previous of svg.querySelectorAll('style[data-oc-theme]')) previous.remove();\n let defs = svg.querySelector('defs');\n if (!defs) {\n defs = document.createElementNS(SVG_NS, 'defs');\n svg.insertBefore(defs, svg.firstChild);\n }\n const style = document.createElementNS(SVG_NS, 'style');\n style.setAttribute('data-oc-theme', '');\n style.textContent = buildThemeStyleBlock(theme);\n defs.insertBefore(style, defs.firstChild);\n}\n\n/** Preserve the live host CSS tokens when an export leaves its document. */\nexport function copyComputedThemeProperties(source: SVGElement, clone: SVGElement): void {\n if (!source.isConnected) return;\n const computed = getComputedStyle(source);\n for (const { name } of CSS_TOKENS) {\n const value = computed.getPropertyValue(name).trim();\n if (value) clone.style.setProperty(name, value);\n }\n}\n\n/** Prepare detached settled geometry with its live cascade or an export override. */\nexport function prepareSettledExportTheme(\n source: SVGElement,\n settled: SVGElement,\n theme: ResolvedTheme | undefined,\n explicitTheme = false,\n): void {\n if (explicitTheme) {\n // A re-render may stamp authored mount values inline. They would beat the\n // export theme's stylesheet even when copying the live cascade is skipped.\n for (const { name } of CSS_TOKENS) settled.style.removeProperty(name);\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AO,SAAS,gBAAgB,QAAQ,MAAM;AAC9C,QAAI,aAAa,MAAM,IAAI,UAAU;AAAA,EACvC;AACA,QAAM,QAAQ,SAAS,gBAAgB,QAAQ,OAAO;AACtD,QAAM,aAAa,iBAAiB,EAAE;AACtC,QAAM,cAAc,qBAAqB,KAAK;AAC9C,OAAK,aAAa,OAAO,KAAK,UAAU;AAC1C;AAGO,SAAS,4BAA4B,QAAoB,OAAyB;AACvF,MAAI,CAAC,OAAO,YAAa;AACzB,QAAM,WAAW,iBAAiB,MAAM;AACxC,aAAW,EAAE,KAAK,KAAK,YAAY;AACjC,UAAM,QAAQ,SAAS,iBAAiB,IAAI,EAAE,KAAK;AACnD,QAAI,MAAO,OAAM,MAAM,YAAY,MAAM,KAAK;AAAA,EAChD;AACF;AAGO,SAAS,0BACd,QACA,SACA,OACA,gBAAgB,OACV;AACN,MAAI,eAAe;AAGjB,eAAW,EAAE,KAAK,KAAK,WAAY,SAAQ,MAAM,eAAe,IAAI;AAAA,EACtE,OAAO;AACL,gCAA4B,QAAQ,OAAO;AAAA,EAC7C;AACA,wBAAsB,SAAS,KAAK;AACtC;","names":[]}
@@ -0,0 +1,130 @@
1
+ // src/renderers/svg-dom.ts
2
+ import { cssTokenDefault } from "@opendata-ai/openchart-core";
3
+ var SVG_NS = "http://www.w3.org/2000/svg";
4
+ var XLINK_NS = "http://www.w3.org/1999/xlink";
5
+ var defaultElementFactory = {
6
+ svg: (tag) => document.createElementNS(SVG_NS, tag),
7
+ html: (tag) => document.createElement(tag),
8
+ text: (data) => document.createTextNode(data)
9
+ };
10
+ function createSVGElement(tag, factory = defaultElementFactory) {
11
+ return factory.svg(tag);
12
+ }
13
+ function setAttrs(el, attrs) {
14
+ for (const [key, value] of Object.entries(attrs)) {
15
+ el.setAttribute(key, String(value));
16
+ }
17
+ }
18
+ function applyKnockoutHalo(el, color, fontSize) {
19
+ setAttrs(el, {
20
+ stroke: color,
21
+ "stroke-width": Math.round(fontSize * 0.3),
22
+ "stroke-linejoin": "round",
23
+ "paint-order": "stroke"
24
+ });
25
+ }
26
+ function applyTextStyle(el, style) {
27
+ const inline = el.style;
28
+ inline.setProperty("fill", style.fill);
29
+ inline.setProperty("font-size", `${style.fontSize}px`);
30
+ inline.setProperty("font-weight", String(style.fontWeight));
31
+ inline.setProperty("font-family", style.fontFamily);
32
+ if (style.textAnchor) {
33
+ el.setAttribute("text-anchor", style.textAnchor);
34
+ }
35
+ if (style.dominantBaseline) {
36
+ el.setAttribute("dominant-baseline", style.dominantBaseline);
37
+ }
38
+ if (style.fontVariant) {
39
+ el.setAttribute("font-variant", style.fontVariant);
40
+ }
41
+ }
42
+ function roleStyles(theme) {
43
+ const { colors, fonts, chrome } = theme;
44
+ const muted = colors.axis;
45
+ const accent = colors.categorical[0] ?? cssTokenDefault("--oc-accent", "light");
46
+ const roles = {
47
+ "oc-chrome": { "font-family": fonts.family },
48
+ "oc-eyebrow": {
49
+ "font-size": chrome.eyebrow.fontSize,
50
+ "font-weight": chrome.eyebrow.fontWeight,
51
+ "letter-spacing": cssTokenDefault("--oc-eyebrow-tracking", "light"),
52
+ fill: accent,
53
+ "text-transform": "uppercase"
54
+ },
55
+ "oc-title": {
56
+ "font-size": chrome.title.fontSize,
57
+ "font-weight": chrome.title.fontWeight,
58
+ "letter-spacing": cssTokenDefault("--oc-title-tracking", "light"),
59
+ fill: colors.text
60
+ },
61
+ "oc-subtitle": {
62
+ "font-size": chrome.subtitle.fontSize,
63
+ "font-weight": chrome.subtitle.fontWeight,
64
+ fill: muted
65
+ },
66
+ "oc-source": {
67
+ "font-size": chrome.source.fontSize,
68
+ "font-weight": chrome.source.fontWeight,
69
+ fill: muted
70
+ },
71
+ "oc-brand": {
72
+ "font-size": 11,
73
+ "font-weight": 500,
74
+ "letter-spacing": "0.02em",
75
+ fill: colors.neutral.faint
76
+ },
77
+ "oc-eyebrow-dot": { fill: accent },
78
+ "oc-metrics": { "font-family": fonts.family },
79
+ "oc-metric-label": {
80
+ "font-size": 11,
81
+ "font-weight": 500,
82
+ "letter-spacing": "0.06em",
83
+ "text-transform": "uppercase",
84
+ fill: muted
85
+ },
86
+ "oc-metric-value": {
87
+ "font-size": 22,
88
+ "font-weight": 600,
89
+ "letter-spacing": "-0.02em",
90
+ fill: colors.text,
91
+ "font-variant-numeric": "tabular-nums"
92
+ },
93
+ "oc-metric-delta-up": { fill: colors.positive, "font-size": 12, "font-weight": 500 },
94
+ "oc-metric-delta-down": { fill: colors.negative, "font-size": 12, "font-weight": 500 },
95
+ "oc-metric-secondary": { fill: muted, "font-size": 12, "font-weight": 400 },
96
+ "oc-axis-tick-inline": { "font-size": 11, "font-weight": 400, fill: muted },
97
+ "oc-endpoint-labels": { "font-family": fonts.family },
98
+ "oc-endpoint-label": { fill: colors.text },
99
+ "oc-endpoint-value": { fill: muted },
100
+ "oc-endpoint-leader": { stroke: colors.text },
101
+ "oc-annotation-subtitle": { fill: muted },
102
+ "oc-legend": { "font-family": fonts.family, "font-size": fonts.sizes.body },
103
+ "oc-legend-text": {
104
+ fill: cssTokenDefault("--oc-legend-text", theme.isDark ? "dark" : "light")
105
+ }
106
+ };
107
+ roles["oc-byline"] = roles["oc-source"];
108
+ roles["oc-footer"] = roles["oc-source"];
109
+ return roles;
110
+ }
111
+ function applyRoleStyle(ctx, el, role) {
112
+ ctx.roleStyles ??= roleStyles(ctx.theme);
113
+ for (const [name, value] of Object.entries(ctx.roleStyles[role] ?? {})) {
114
+ if (name === "text-transform" || name === "font-variant-numeric") {
115
+ if (!el.style.getPropertyValue(name)) el.style.setProperty(name, String(value));
116
+ } else if (!el.hasAttribute(name)) el.setAttribute(name, String(value));
117
+ }
118
+ }
119
+
120
+ export {
121
+ SVG_NS,
122
+ XLINK_NS,
123
+ defaultElementFactory,
124
+ createSVGElement,
125
+ setAttrs,
126
+ applyKnockoutHalo,
127
+ applyTextStyle,
128
+ applyRoleStyle
129
+ };
130
+ //# sourceMappingURL=chunk-E3ETKTJQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/renderers/svg-dom.ts"],"sourcesContent":["/**\n * Shared SVG DOM helpers used across the per-concern renderers.\n *\n * Pure, stateless utilities. No layout/theme knowledge.\n */\n\nimport type { ResolvedTheme, TextStyle } from '@opendata-ai/openchart-core';\nimport { cssTokenDefault } from '@opendata-ai/openchart-core';\n\nexport const SVG_NS = 'http://www.w3.org/2000/svg';\nexport const XLINK_NS = 'http://www.w3.org/1999/xlink';\n\nexport interface ElementFactory {\n svg(tag: string): SVGElement;\n html(tag: string): HTMLElement;\n text(data: string): Text;\n}\nexport const defaultElementFactory: ElementFactory = {\n svg: (tag) => document.createElementNS(SVG_NS, tag),\n html: (tag) => document.createElement(tag),\n text: (data) => document.createTextNode(data),\n};\nexport function createSVGElement(\n tag: string,\n factory: ElementFactory = defaultElementFactory,\n): SVGElement {\n return factory.svg(tag);\n}\n\nexport function setAttrs(el: SVGElement, attrs: Record<string, string | number>): void {\n for (const [key, value] of Object.entries(attrs)) {\n el.setAttribute(key, String(value));\n }\n}\n\n/**\n * Cut a knockout halo behind text so it stays legible where it crosses\n * gridlines, marks, or a neighbouring series: a surface-colored stroke painted\n * under the glyphs.\n *\n * Presentation attributes, not inline styles, so a stylesheet can still\n * override the halo. The width scales with the font size -- a fixed width rings\n * small glyphs and disappears behind large ones.\n */\nexport function applyKnockoutHalo(el: SVGElement, color: string, fontSize: number): void {\n setAttrs(el, {\n stroke: color,\n 'stroke-width': Math.round(fontSize * 0.3),\n 'stroke-linejoin': 'round',\n 'paint-order': 'stroke',\n });\n}\n\nexport function applyTextStyle(el: SVGElement, style: TextStyle): void {\n // Use inline styles so engine-computed values take priority over CSS class\n // defaults (e.g. .oc-title { font-size: var(--oc-title-size) } would otherwise\n // override the responsive scaling applied by the chrome layout).\n const inline = (el as SVGElement & ElementCSSInlineStyle).style;\n inline.setProperty('fill', style.fill);\n inline.setProperty('font-size', `${style.fontSize}px`);\n inline.setProperty('font-weight', String(style.fontWeight));\n inline.setProperty('font-family', style.fontFamily);\n if (style.textAnchor) {\n el.setAttribute('text-anchor', style.textAnchor);\n }\n if (style.dominantBaseline) {\n el.setAttribute('dominant-baseline', style.dominantBaseline);\n }\n if (style.fontVariant) {\n el.setAttribute('font-variant', style.fontVariant);\n }\n}\n\ntype RoleStyles = Record<string, Record<string, string | number>>;\nfunction roleStyles(theme: ResolvedTheme): RoleStyles {\n const { colors, fonts, chrome } = theme;\n const muted = colors.axis;\n const accent = colors.categorical[0] ?? cssTokenDefault('--oc-accent', 'light');\n const roles: Record<string, Record<string, string | number>> = {\n 'oc-chrome': { 'font-family': fonts.family },\n 'oc-eyebrow': {\n 'font-size': chrome.eyebrow.fontSize,\n 'font-weight': chrome.eyebrow.fontWeight,\n 'letter-spacing': cssTokenDefault('--oc-eyebrow-tracking', 'light'),\n fill: accent,\n 'text-transform': 'uppercase',\n },\n 'oc-title': {\n 'font-size': chrome.title.fontSize,\n 'font-weight': chrome.title.fontWeight,\n 'letter-spacing': cssTokenDefault('--oc-title-tracking', 'light'),\n fill: colors.text,\n },\n 'oc-subtitle': {\n 'font-size': chrome.subtitle.fontSize,\n 'font-weight': chrome.subtitle.fontWeight,\n fill: muted,\n },\n 'oc-source': {\n 'font-size': chrome.source.fontSize,\n 'font-weight': chrome.source.fontWeight,\n fill: muted,\n },\n 'oc-brand': {\n 'font-size': 11,\n 'font-weight': 500,\n 'letter-spacing': '0.02em',\n fill: colors.neutral.faint,\n },\n 'oc-eyebrow-dot': { fill: accent },\n 'oc-metrics': { 'font-family': fonts.family },\n 'oc-metric-label': {\n 'font-size': 11,\n 'font-weight': 500,\n 'letter-spacing': '0.06em',\n 'text-transform': 'uppercase',\n fill: muted,\n },\n 'oc-metric-value': {\n 'font-size': 22,\n 'font-weight': 600,\n 'letter-spacing': '-0.02em',\n fill: colors.text,\n 'font-variant-numeric': 'tabular-nums',\n },\n 'oc-metric-delta-up': { fill: colors.positive, 'font-size': 12, 'font-weight': 500 },\n 'oc-metric-delta-down': { fill: colors.negative, 'font-size': 12, 'font-weight': 500 },\n 'oc-metric-secondary': { fill: muted, 'font-size': 12, 'font-weight': 400 },\n 'oc-axis-tick-inline': { 'font-size': 11, 'font-weight': 400, fill: muted },\n 'oc-endpoint-labels': { 'font-family': fonts.family },\n 'oc-endpoint-label': { fill: colors.text },\n 'oc-endpoint-value': { fill: muted },\n 'oc-endpoint-leader': { stroke: colors.text },\n 'oc-annotation-subtitle': { fill: muted },\n 'oc-legend': { 'font-family': fonts.family, 'font-size': fonts.sizes.body },\n 'oc-legend-text': {\n fill: cssTokenDefault('--oc-legend-text', theme.isDark ? 'dark' : 'light'),\n },\n };\n roles['oc-byline'] = roles['oc-source'];\n roles['oc-footer'] = roles['oc-source'];\n return roles;\n}\n/** Resolve class defaults while keeping engine-authored attributes and inline styles. */\nexport function applyRoleStyle(\n ctx: { theme: ResolvedTheme; roleStyles?: RoleStyles },\n el: SVGElement,\n role: string,\n): void {\n ctx.roleStyles ??= roleStyles(ctx.theme);\n for (const [name, value] of Object.entries(ctx.roleStyles[role] ?? {})) {\n if (name === 'text-transform' || name === 'font-variant-numeric') {\n if (!el.style.getPropertyValue(name)) el.style.setProperty(name, String(value));\n } else if (!el.hasAttribute(name)) el.setAttribute(name, String(value));\n }\n}\n"],"mappings":";AAOA,SAAS,uBAAuB;AAEzB,IAAM,SAAS;AACf,IAAM,WAAW;AAOjB,IAAM,wBAAwC;AAAA,EACnD,KAAK,CAAC,QAAQ,SAAS,gBAAgB,QAAQ,GAAG;AAAA,EAClD,MAAM,CAAC,QAAQ,SAAS,cAAc,GAAG;AAAA,EACzC,MAAM,CAAC,SAAS,SAAS,eAAe,IAAI;AAC9C;AACO,SAAS,iBACd,KACA,UAA0B,uBACd;AACZ,SAAO,QAAQ,IAAI,GAAG;AACxB;AAEO,SAAS,SAAS,IAAgB,OAA8C;AACrF,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,OAAG,aAAa,KAAK,OAAO,KAAK,CAAC;AAAA,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BAAoB,MAAM,SAAS,SAAS,OAAO;AAAA,IAC3E;AAAA,EACF;AACA,QAAM,WAAW,IAAI,MAAM,WAAW;AACtC,QAAM,WAAW,IAAI,MAAM,WAAW;AACtC,SAAO;AACT;AAEO,SAAS,eACd,KACA,IACA,MACM;AACN,MAAI,eAAe,WAAW,IAAI,KAAK;AACvC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,IAAI,WAAW,IAAI,KAAK,CAAC,CAAC,GAAG;AACtE,QAAI,SAAS,oBAAoB,SAAS,wBAAwB;AAChE,UAAI,CAAC,GAAG,MAAM,iBAAiB,IAAI,EAAG,IAAG,MAAM,YAAY,MAAM,OAAO,KAAK,CAAC;AAAA,IAChF,WAAW,CAAC,GAAG,aAAa,IAAI,EAAG,IAAG,aAAa,MAAM,OAAO,KAAK,CAAC;AAAA,EACxE;AACF;","names":[]}
@@ -7,16 +7,17 @@ import {
7
7
  prefersReducedMotion,
8
8
  resolveDarkMode,
9
9
  resolveEase
10
- } from "./chunk-46E3QB6O.js";
10
+ } from "./chunk-6GRMMSQA.js";
11
11
  import {
12
+ createRenderContext,
12
13
  renderAttributionBrand,
13
14
  renderChromeElement,
14
15
  stampThemeProperties
15
- } from "./chunk-NLKQ5AOA.js";
16
+ } from "./chunk-XR4B3SPC.js";
16
17
  import {
17
18
  createSVGElement,
18
19
  setAttrs
19
- } from "./chunk-FFP5GXIP.js";
20
+ } from "./chunk-E3ETKTJQ.js";
20
21
 
21
22
  // src/graph/renderer-registry.ts
22
23
  var registry = /* @__PURE__ */ new Map();
@@ -1922,10 +1923,10 @@ function seedNodePositions(nodes, seed) {
1922
1923
  }
1923
1924
 
1924
1925
  // src/renderers/attribution-footer.ts
1925
- function createAttributionFooter(chrome, width, measureText) {
1926
+ function createAttributionFooter(chrome, width, measureText, ctx = createRenderContext()) {
1926
1927
  if (!chrome.source && !chrome.byline && !chrome.footer && !chrome.brand && !chrome.watermark)
1927
1928
  return null;
1928
- const svg = createSVGElement("svg");
1929
+ const svg = createSVGElement("svg", ctx.factory);
1929
1930
  svg.setAttribute("class", "oc-attribution-footer");
1930
1931
  setAttrs(svg, {
1931
1932
  width: "100%",
@@ -1936,9 +1937,9 @@ function createAttributionFooter(chrome, width, measureText) {
1936
1937
  svg.style.flex = "0 0 auto";
1937
1938
  for (const key of ["source", "byline", "footer"]) {
1938
1939
  const element = chrome[key];
1939
- if (element) renderChromeElement(svg, element, `oc-${key}`, key, measureText);
1940
+ if (element) renderChromeElement(svg, element, `oc-${key}`, key, measureText, void 0, ctx);
1940
1941
  }
1941
- renderAttributionBrand(svg, chrome, 0, measureText);
1942
+ renderAttributionBrand(svg, chrome, 0, measureText, void 0, ctx);
1942
1943
  return svg;
1943
1944
  }
1944
1945
 
@@ -3718,4 +3719,4 @@ export {
3718
3719
  reheatAlpha,
3719
3720
  createGraph
3720
3721
  };
3721
- //# sourceMappingURL=chunk-5ZLSMZRM.js.map
3722
+ //# sourceMappingURL=chunk-HQ5GADZ4.js.map