@pixerate/editor 0.44.0 → 0.46.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.
- package/README.md +29 -3
- package/dist/agent/index.cjs +548 -45
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +47 -17
- package/dist/agent/index.d.ts +47 -17
- package/dist/agent/index.js +536 -33
- package/dist/agent/index.js.map +1 -1
- package/dist/{builtins-BLud97fC.d.cts → builtins-CZW-aYKS.d.cts} +1 -1
- package/dist/{builtins-D0BDyAgw.d.ts → builtins-DghNQbT-.d.ts} +1 -1
- package/dist/chart/index.cjs +1984 -0
- package/dist/chart/index.cjs.map +1 -0
- package/dist/chart/index.d.cts +646 -0
- package/dist/chart/index.d.ts +646 -0
- package/dist/chart/index.js +1984 -0
- package/dist/chart/index.js.map +1 -0
- package/dist/{chunk-I6BZB5ZH.cjs → chunk-EFDCLENW.cjs} +73 -6
- package/dist/chunk-EFDCLENW.cjs.map +1 -0
- package/dist/chunk-HHQ4XJWT.js +826 -0
- package/dist/chunk-HHQ4XJWT.js.map +1 -0
- package/dist/chunk-J3R2OWOE.cjs +1465 -0
- package/dist/chunk-J3R2OWOE.cjs.map +1 -0
- package/dist/chunk-K2LVZ4FA.cjs +826 -0
- package/dist/chunk-K2LVZ4FA.cjs.map +1 -0
- package/dist/{chunk-6MDQKHRH.cjs → chunk-N4MLNJPO.cjs} +21 -899
- package/dist/chunk-N4MLNJPO.cjs.map +1 -0
- package/dist/chunk-PQM5W7ZN.js +168 -0
- package/dist/chunk-PQM5W7ZN.js.map +1 -0
- package/dist/{chunk-DDADOHJW.js → chunk-Q25ZS4F7.js} +5 -883
- package/dist/chunk-Q25ZS4F7.js.map +1 -0
- package/dist/chunk-TK2XZK6Z.js +1465 -0
- package/dist/chunk-TK2XZK6Z.js.map +1 -0
- package/dist/commands/index.cjs +3 -2
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +5 -5
- package/dist/commands/index.d.ts +5 -5
- package/dist/commands/index.js +2 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/extensions/index.cjs +4 -4
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +3 -3
- package/dist/extensions/index.d.ts +3 -3
- package/dist/extensions/index.js +12 -12
- package/dist/generation/index.cjs +2 -2
- package/dist/generation/index.d.cts +4 -4
- package/dist/generation/index.d.ts +4 -4
- package/dist/generation/index.js +1 -1
- package/dist/image-editor/index.cjs +24 -24
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +2 -2
- package/dist/image-editor/index.d.ts +2 -2
- package/dist/image-editor/index.js +24 -24
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{index-C6gaQRH0.d.cts → index-CfOQf70b.d.cts} +1 -1
- package/dist/{index-DXAv_R08.d.ts → index-jwJ_onWf.d.ts} +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/parameters/index.d.cts +2 -2
- package/dist/parameters/index.d.ts +2 -2
- package/dist/{registry-DnzpgY27.d.cts → registry-B4l-lYts.d.cts} +1 -1
- package/dist/{registry-DhVUZioj.d.ts → registry-BfVD-vVg.d.ts} +1 -1
- package/dist/{registry-BDe-vlv3.d.ts → registry-CSlH4iUn.d.ts} +1 -1
- package/dist/{registry-D0GADKc7.d.cts → registry-vz6HOiiy.d.cts} +1 -1
- package/dist/{schema-DYDGdYL9.d.cts → schema-Di0CS6Pe.d.cts} +26 -2
- package/dist/{schema-DYDGdYL9.d.ts → schema-Di0CS6Pe.d.ts} +26 -2
- package/dist/tools/index.cjs +37 -3
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +871 -11
- package/dist/tools/index.d.ts +871 -11
- package/dist/tools/index.js +36 -2
- package/dist/vector/index.d.cts +2 -2
- package/dist/vector/index.d.ts +2 -2
- package/package.json +6 -1
- package/dist/chunk-36BLROHV.js +0 -438
- package/dist/chunk-36BLROHV.js.map +0 -1
- package/dist/chunk-5H2OPMXZ.js +0 -586
- package/dist/chunk-5H2OPMXZ.js.map +0 -1
- package/dist/chunk-6MDQKHRH.cjs.map +0 -1
- package/dist/chunk-D6S5M7HV.js +0 -101
- package/dist/chunk-D6S5M7HV.js.map +0 -1
- package/dist/chunk-DDADOHJW.js.map +0 -1
- package/dist/chunk-I6BZB5ZH.cjs.map +0 -1
- package/dist/chunk-MC2LQN5S.cjs +0 -586
- package/dist/chunk-MC2LQN5S.cjs.map +0 -1
- package/dist/chunk-V7CC7RZ6.cjs +0 -438
- package/dist/chunk-V7CC7RZ6.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/chart/spec.ts","../../src/chart/scale.ts","../../src/chart/layout.ts","../../src/chart/svg.ts","../../src/chart/controller.ts","../../src/chart/commands.ts","../../src/chart/interaction.ts"],"sourcesContent":["import type {\n\tChartAxis,\n\tChartCurve,\n\tChartIssue,\n\tChartLegend,\n\tChartLegendPosition,\n\tChartNumberFormat,\n\tChartOrientation,\n\tChartSeries,\n\tChartSeriesType,\n\tChartSpec,\n\tChartStacking,\n\tChartTheme,\n\tChartType,\n\tChartValue\n} from './types.js';\n\nexport const CHART_TYPES: readonly ChartType[] = ['bar', 'line', 'area', 'scatter', 'pie', 'donut'];\nexport const CHART_SERIES_TYPES: readonly ChartSeriesType[] = ['bar', 'line', 'area', 'scatter'];\nexport const CHART_STACKINGS: readonly ChartStacking[] = ['none', 'stacked', 'percent'];\nexport const CHART_CURVES: readonly ChartCurve[] = ['linear', 'smooth', 'step'];\nexport const CHART_ORIENTATIONS: readonly ChartOrientation[] = ['vertical', 'horizontal'];\nexport const CHART_LEGEND_POSITIONS: readonly ChartLegendPosition[] = ['top', 'bottom', 'left', 'right'];\nexport const CHART_NUMBER_STYLES: readonly NonNullable<ChartNumberFormat['style']>[] = ['number', 'percent', 'currency', 'compact'];\n\n/** Labels for pickers, shared by the React and Svelte components. */\nexport const CHART_TYPE_LABELS: Readonly<Record<ChartType, string>> = {\n\tbar: 'Bar',\n\tline: 'Line',\n\tarea: 'Area',\n\tscatter: 'Scatter',\n\tpie: 'Pie',\n\tdonut: 'Donut'\n};\n\n/** A colour-blind-friendly categorical palette (Okabe–Ito order, tuned for light and dark backgrounds). */\nexport const DEFAULT_CHART_PALETTE: readonly string[] = ['#4269d0', '#efb118', '#ff725c', '#6cc5b0', '#3ca951', '#ff8ab7', '#a463f2', '#97bbf5', '#9c6b4e', '#9498a0'];\n\nexport const DEFAULT_CHART_THEME: ChartTheme = {\n\tbackground: '#ffffff',\n\tsurface: '#ffffff',\n\ttext: '#0f172a',\n\tmutedText: '#64748b',\n\tgrid: '#e2e8f0',\n\taxis: '#94a3b8',\n\tselection: '#2563eb',\n\tfontFamily: 'system-ui, -apple-system, \"Segoe UI\", sans-serif',\n\tfontSize: 11,\n\ttitleSize: 15\n};\n\n/**\n * A theme that reads the page's `--background`, `--foreground`, `--muted-foreground`,\n * `--border` and `--primary` colour variables (full colours, as the other components'\n * inline styles use them), with light fallbacks. The React and Svelte canvases use it.\n */\nexport const CSS_VARIABLE_CHART_THEME: ChartTheme = {\n\t...DEFAULT_CHART_THEME,\n\tbackground: 'transparent',\n\tsurface: 'var(--background, #ffffff)',\n\ttext: 'var(--foreground, #0f172a)',\n\tmutedText: 'var(--muted-foreground, #64748b)',\n\tgrid: 'var(--border, #e2e8f0)',\n\taxis: 'var(--muted-foreground, #94a3b8)',\n\tselection: 'var(--primary, #2563eb)',\n\tfontFamily: 'inherit'\n};\n\nexport function isCartesianChart(type: ChartType): boolean {\n\treturn type !== 'pie' && type !== 'donut';\n}\n\nexport function defaultChartAxis(value: boolean): ChartAxis {\n\treturn { show: true, title: '', min: null, max: null, gridlines: value, format: {} };\n}\n\n/** A complete spec with every default filled in. */\nexport function createChartSpec(partial: Partial<ChartSpec> = {}): ChartSpec {\n\treturn normalizeChartSpec(partial).spec;\n}\n\n/** The colour a series is drawn with. */\nexport function chartSeriesColor(spec: Pick<ChartSpec, 'palette' | 'series'>, seriesIndex: number): string {\n\tconst series = spec.series[seriesIndex];\n\tif (series?.color) return series.color;\n\tconst palette = spec.palette.length ? spec.palette : DEFAULT_CHART_PALETTE;\n\treturn palette[seriesIndex % palette.length];\n}\n\n/** The colour a pie slice is drawn with (by category). */\nexport function chartSliceColor(spec: Pick<ChartSpec, 'palette'>, index: number): string {\n\tconst palette = spec.palette.length ? spec.palette : DEFAULT_CHART_PALETTE;\n\treturn palette[index % palette.length];\n}\n\n/** How a series is drawn in a cartesian chart. */\nexport function chartSeriesType(spec: Pick<ChartSpec, 'type'>, series: ChartSeries): ChartSeriesType {\n\tif (series.type) return series.type;\n\treturn isCartesianChart(spec.type) ? (spec.type as ChartSeriesType) : 'bar';\n}\n\n/** An id not used by any series (`series-1`, `series-2`, …). */\nexport function uniqueChartSeriesId(series: readonly Pick<ChartSeries, 'id'>[], base = 'series'): string {\n\tconst used = new Set(series.map((s) => s.id));\n\tfor (let i = series.length + 1; ; i++) {\n\t\tconst id = `${base}-${i}`;\n\t\tif (!used.has(id)) return id;\n\t}\n}\n\n/**\n * Reads a number the way people type it in a data grid: `1,234.5`, `12%` (→ 0.12),\n * `$40`, `(3)` (→ -3). Blank → `null`. Returns `undefined` when it is not a number.\n */\nexport function parseChartValue(input: unknown): ChartValue | undefined {\n\tif (input === null || input === undefined) return null;\n\tif (typeof input === 'number') return Number.isFinite(input) ? input : undefined;\n\tif (typeof input !== 'string') return undefined;\n\tlet text = input.trim();\n\tif (!text || text === '-' || text === '—') return null;\n\tlet negative = false;\n\tif (/^\\(.*\\)$/.test(text)) {\n\t\tnegative = true;\n\t\ttext = text.slice(1, -1).trim();\n\t}\n\tconst percent = text.endsWith('%');\n\tif (percent) text = text.slice(0, -1).trim();\n\ttext = text.replace(/^[$€£¥]/, '').replace(/,/g, '').replace(/\\s+/g, '');\n\tif (!/^[-+]?(\\d+\\.?\\d*|\\.\\d+)(e[-+]?\\d+)?$/i.test(text)) return undefined;\n\tlet value = Number(text);\n\tif (percent) value /= 100;\n\tif (negative) value = -value;\n\treturn Number.isFinite(value) ? value : undefined;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value);\n\nfunction pick<T extends string>(value: unknown, options: readonly T[], fallback: T, path: string, issues: ChartIssue[]): T {\n\tif (value === undefined) return fallback;\n\tif (typeof value === 'string' && (options as readonly string[]).includes(value)) return value as T;\n\tissues.push({ path, message: `${path} must be one of ${options.map((o) => `\"${o}\"`).join(', ')}; got ${JSON.stringify(value)}.` });\n\treturn fallback;\n}\n\nfunction text(value: unknown, fallback: string, path: string, issues: ChartIssue[]): string {\n\tif (value === undefined || value === null) return fallback;\n\tif (typeof value === 'string') return value;\n\tif (typeof value === 'number' || typeof value === 'boolean') return String(value);\n\tissues.push({ path, message: `${path} must be text.` });\n\treturn fallback;\n}\n\nfunction flag(value: unknown, fallback: boolean, path: string, issues: ChartIssue[]): boolean {\n\tif (value === undefined) return fallback;\n\tif (typeof value === 'boolean') return value;\n\tissues.push({ path, message: `${path} must be true or false.` });\n\treturn fallback;\n}\n\nfunction bound(value: unknown, path: string, issues: ChartIssue[]): number | null {\n\tif (value === undefined || value === null || value === '') return null;\n\tconst n = typeof value === 'string' ? Number(value) : value;\n\tif (typeof n === 'number' && Number.isFinite(n)) return n;\n\tissues.push({ path, message: `${path} must be a number or null.` });\n\treturn null;\n}\n\nfunction normalizeFormat(value: unknown, path: string, issues: ChartIssue[]): ChartNumberFormat {\n\tif (value === undefined || value === null) return {};\n\tif (!isRecord(value)) {\n\t\tissues.push({ path, message: `${path} must be an object.` });\n\t\treturn {};\n\t}\n\tconst out: ChartNumberFormat = {};\n\tif (value.style !== undefined) out.style = pick(value.style, CHART_NUMBER_STYLES, 'number', `${path}.style`, issues);\n\tif (value.decimals !== undefined) {\n\t\tconst d = Number(value.decimals);\n\t\tif (Number.isInteger(d) && d >= 0 && d <= 10) out.decimals = d;\n\t\telse issues.push({ path: `${path}.decimals`, message: `${path}.decimals must be a whole number from 0 to 10.` });\n\t}\n\tfor (const key of ['currency', 'prefix', 'suffix'] as const) {\n\t\tif (value[key] !== undefined) out[key] = text(value[key], '', `${path}.${key}`, issues);\n\t}\n\treturn out;\n}\n\nexport function normalizeChartAxis(value: unknown, fallback: ChartAxis, path: string, issues: ChartIssue[] = []): ChartAxis {\n\tif (value === undefined) return { ...fallback, format: { ...fallback.format } };\n\tif (!isRecord(value)) {\n\t\tissues.push({ path, message: `${path} must be an object.` });\n\t\treturn { ...fallback, format: { ...fallback.format } };\n\t}\n\tlet min = 'min' in value ? bound(value.min, `${path}.min`, issues) : fallback.min;\n\tlet max = 'max' in value ? bound(value.max, `${path}.max`, issues) : fallback.max;\n\tif (min !== null && max !== null && min >= max) {\n\t\tissues.push({ path: `${path}.max`, message: `${path}.max (${max}) must be greater than ${path}.min (${min}).` });\n\t\tmin = fallback.min;\n\t\tmax = fallback.max;\n\t}\n\treturn {\n\t\tshow: flag(value.show, fallback.show, `${path}.show`, issues),\n\t\ttitle: text(value.title, fallback.title, `${path}.title`, issues),\n\t\tmin,\n\t\tmax,\n\t\tgridlines: flag(value.gridlines, fallback.gridlines, `${path}.gridlines`, issues),\n\t\tformat: 'format' in value ? normalizeFormat(value.format, `${path}.format`, issues) : { ...fallback.format }\n\t};\n}\n\nfunction normalizeLegend(value: unknown, issues: ChartIssue[]): ChartLegend {\n\tconst fallback: ChartLegend = { show: true, position: 'bottom' };\n\tif (value === undefined) return fallback;\n\tif (!isRecord(value)) {\n\t\tissues.push({ path: 'legend', message: 'legend must be an object.' });\n\t\treturn fallback;\n\t}\n\treturn {\n\t\tshow: flag(value.show, fallback.show, 'legend.show', issues),\n\t\tposition: pick(value.position, CHART_LEGEND_POSITIONS, fallback.position, 'legend.position', issues)\n\t};\n}\n\n/** Values as numbers or nulls; bad entries become null and are reported. */\nexport function normalizeChartValues(value: unknown, length: number | undefined, path: string, issues: ChartIssue[] = []): ChartValue[] {\n\tif (value === undefined) return length ? Array(length).fill(null) : [];\n\tif (!Array.isArray(value)) {\n\t\tissues.push({ path, message: `${path} must be an array of numbers.` });\n\t\treturn length ? Array(length).fill(null) : [];\n\t}\n\tconst out = value.map((v, i) => {\n\t\tconst parsed = parseChartValue(v);\n\t\tif (parsed === undefined) {\n\t\t\tissues.push({ path: `${path}[${i}]`, message: `${path}[${i}] is not a number: ${JSON.stringify(v)}.` });\n\t\t\treturn null;\n\t\t}\n\t\treturn parsed;\n\t});\n\tif (length === undefined) return out;\n\tif (out.length > length) return out.slice(0, length);\n\twhile (out.length < length) out.push(null);\n\treturn out;\n}\n\nfunction normalizeSeries(value: unknown, length: number, used: Set<string>, index: number, issues: ChartIssue[]): ChartSeries | null {\n\tconst path = `series[${index}]`;\n\tif (!isRecord(value)) {\n\t\tissues.push({ path, message: `${path} must be an object with a name and values.` });\n\t\treturn null;\n\t}\n\tlet id = typeof value.id === 'string' && value.id.trim() ? value.id.trim() : '';\n\tif (!id || used.has(id)) {\n\t\tif (id) issues.push({ path: `${path}.id`, message: `Series id \"${id}\" is used twice; the second was renamed.` });\n\t\tfor (let n = index + 1; ; n++) {\n\t\t\tid = `series-${n}`;\n\t\t\tif (!used.has(id)) break;\n\t\t}\n\t}\n\tused.add(id);\n\tconst series: ChartSeries = {\n\t\tid,\n\t\tname: text(value.name, `Series ${index + 1}`, `${path}.name`, issues),\n\t\tvalues: normalizeChartValues(value.values, length, `${path}.values`, issues)\n\t};\n\tif (typeof value.color === 'string' && value.color.trim()) series.color = value.color.trim();\n\tif (value.type !== undefined && value.type !== null) series.type = pick(value.type, CHART_SERIES_TYPES, 'bar', `${path}.type`, issues);\n\tif (value.hidden === true) series.hidden = true;\n\treturn series;\n}\n\n/**\n * Turns any input (a partial spec, saved JSON, an agent's arguments) into a complete,\n * valid `ChartSpec`. Every value is checked; problems are reported as sentences in\n * `issues` and replaced by defaults, so the result is always drawable. Series values are\n * padded or trimmed to the number of categories.\n */\nexport function normalizeChartSpec(input: unknown): { spec: ChartSpec; issues: ChartIssue[] } {\n\tconst issues: ChartIssue[] = [];\n\tconst value = isRecord(input) ? input : {};\n\tif (input !== undefined && !isRecord(input)) issues.push({ path: '', message: 'A chart must be an object.' });\n\tconst type = pick(value.type, CHART_TYPES, 'bar', 'type', issues);\n\tconst rawSeries = Array.isArray(value.series) ? value.series : [];\n\tif (value.series !== undefined && !Array.isArray(value.series)) issues.push({ path: 'series', message: 'series must be an array.' });\n\n\tlet categories: string[];\n\tif (Array.isArray(value.categories)) categories = value.categories.map((c, i) => text(c, '', `categories[${i}]`, issues));\n\telse {\n\t\tif (value.categories !== undefined) issues.push({ path: 'categories', message: 'categories must be an array of labels.' });\n\t\tconst longest = rawSeries.reduce<number>((n, s) => Math.max(n, isRecord(s) && Array.isArray(s.values) ? s.values.length : 0), 0);\n\t\tcategories = Array.from({ length: longest }, (_, i) => `${i + 1}`);\n\t}\n\n\tconst used = new Set<string>();\n\tconst series = rawSeries.map((s, i) => normalizeSeries(s, categories.length, used, i, issues)).filter((s): s is ChartSeries => s !== null);\n\n\tlet palette = [...DEFAULT_CHART_PALETTE];\n\tif (Array.isArray(value.palette)) {\n\t\tconst colors = value.palette.filter((c): c is string => typeof c === 'string' && c.trim() !== '');\n\t\tif (colors.length) palette = colors;\n\t\telse issues.push({ path: 'palette', message: 'palette must list at least one colour.' });\n\t} else if (value.palette !== undefined) issues.push({ path: 'palette', message: 'palette must be an array of colours.' });\n\n\tlet innerRadius = 0.55;\n\tif (value.innerRadius !== undefined) {\n\t\tconst r = Number(value.innerRadius);\n\t\tif (Number.isFinite(r) && r >= 0 && r <= 0.9) innerRadius = r;\n\t\telse issues.push({ path: 'innerRadius', message: 'innerRadius must be a number from 0 to 0.9.' });\n\t}\n\n\tconst spec: ChartSpec = {\n\t\tversion: 1,\n\t\ttype,\n\t\ttitle: text(value.title, '', 'title', issues),\n\t\tsubtitle: text(value.subtitle, '', 'subtitle', issues),\n\t\tcategories,\n\t\tseries,\n\t\txAxis: normalizeChartAxis(value.xAxis, defaultChartAxis(false), 'xAxis', issues),\n\t\tyAxis: normalizeChartAxis(value.yAxis, defaultChartAxis(true), 'yAxis', issues),\n\t\tlegend: normalizeLegend(value.legend, issues),\n\t\tstacking: pick(value.stacking, CHART_STACKINGS, 'none', 'stacking', issues),\n\t\torientation: pick(value.orientation, CHART_ORIENTATIONS, 'vertical', 'orientation', issues),\n\t\tcurve: pick(value.curve, CHART_CURVES, 'linear', 'curve', issues),\n\t\tpoints: flag(value.points, true, 'points', issues),\n\t\tdataLabels: flag(value.dataLabels, false, 'dataLabels', issues),\n\t\tpalette,\n\t\tinnerRadius\n\t};\n\treturn { spec, issues };\n}\n\n/** A deep copy (specs are plain JSON). */\nexport function cloneChartSpec(spec: ChartSpec): ChartSpec {\n\treturn {\n\t\t...spec,\n\t\tcategories: [...spec.categories],\n\t\tseries: spec.series.map(cloneChartSeries),\n\t\txAxis: { ...spec.xAxis, format: { ...spec.xAxis.format } },\n\t\tyAxis: { ...spec.yAxis, format: { ...spec.yAxis.format } },\n\t\tlegend: { ...spec.legend },\n\t\tpalette: [...spec.palette]\n\t};\n}\n\nexport function cloneChartSeries(series: ChartSeries): ChartSeries {\n\treturn { ...series, values: [...series.values] };\n}\n\nexport interface ChartTableOptions {\n\t/**\n\t * `columns` (default): the first column holds categories and each other column is a\n\t * series. `rows`: the first row holds categories and each other row is a series.\n\t */\n\tseriesIn?: 'columns' | 'rows';\n\t/** The first row (or column for `rows`) holds series names (default `true`). */\n\theader?: boolean;\n}\n\nexport interface ChartTableData {\n\tcategories: string[];\n\tseries: ChartSeries[];\n\tissues: ChartIssue[];\n}\n\n/**\n * Reads a grid of cells (from CSV, a spreadsheet range or the clipboard) as categories and\n * series. Cells that are not numbers become gaps and are reported.\n */\nexport function chartDataFromTable(rows: ReadonlyArray<ReadonlyArray<unknown>>, options: ChartTableOptions = {}): ChartTableData {\n\tconst header = options.header ?? true;\n\tlet grid = rows.map((r) => [...r]).filter((r) => r.some((c) => c !== null && c !== undefined && String(c).trim() !== ''));\n\tif (options.seriesIn === 'rows') {\n\t\tconst width = Math.max(0, ...grid.map((r) => r.length));\n\t\tgrid = Array.from({ length: width }, (_, c) => grid.map((r) => r[c]));\n\t}\n\tconst issues: ChartIssue[] = [];\n\tif (!grid.length) return { categories: [], series: [], issues };\n\tconst width = Math.max(...grid.map((r) => r.length));\n\tconst names = header ? grid[0] : [];\n\tconst body = header ? grid.slice(1) : grid;\n\tconst categories = body.map((r, i) => {\n\t\tconst c = r[0];\n\t\treturn c === null || c === undefined || String(c).trim() === '' ? `${i + 1}` : String(c).trim();\n\t});\n\tconst series: ChartSeries[] = [];\n\tfor (let col = 1; col < width; col++) {\n\t\tconst name = names[col] !== undefined && String(names[col]).trim() ? String(names[col]).trim() : `Series ${col}`;\n\t\tconst values = body.map((r, i) => {\n\t\t\tconst parsed = parseChartValue(r[col] ?? null);\n\t\t\tif (parsed === undefined) {\n\t\t\t\tissues.push({ path: `${name}[${i}]`, message: `\"${String(r[col])}\" in ${name} (${categories[i]}) is not a number; it was left blank.` });\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn parsed;\n\t\t});\n\t\tseries.push({ id: `series-${col}`, name, values });\n\t}\n\treturn { categories, series, issues };\n}\n\n/** The chart's data as a grid: a header row of series names, then one row per category. */\nexport function chartDataToTable(spec: Pick<ChartSpec, 'categories' | 'series'>, options: { categoryHeader?: string } = {}): (string | number | null)[][] {\n\treturn [\n\t\t[options.categoryHeader ?? '', ...spec.series.map((s) => s.name)],\n\t\t...spec.categories.map((category, i) => [category, ...spec.series.map((s) => s.values[i] ?? null)])\n\t];\n}\n\n/** A colour input value (`#rrggbb`) for a CSS colour: `#abc` expands, non-hex colours show as black. */\nexport function chartColorInputValue(color: string): string {\n\tif (/^#[0-9a-f]{6}$/i.test(color)) return color.toLowerCase();\n\tif (/^#[0-9a-f]{3}$/i.test(color)) return `#${[...color.slice(1)].map((c) => c + c).join('')}`.toLowerCase();\n\treturn '#000000';\n}\n","import type { ChartNumberFormat } from './types.js';\n\n/** A \"nice\" step (1, 2, 2.5 or 5 × 10ⁿ) for about `count` intervals over `span`. */\nexport function niceStep(span: number, count: number): number {\n\tif (!(span > 0) || !(count > 0)) return 1;\n\tconst raw = span / count;\n\tconst power = Math.pow(10, Math.floor(Math.log10(raw)));\n\tconst fraction = raw / power;\n\tconst nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;\n\treturn nice * power;\n}\n\n/** Removes float noise such as 0.30000000000000004. */\nconst clean = (n: number) => (Math.abs(n) < 1e-12 ? 0 : Number(n.toPrecision(12)));\n\nexport interface NiceScale {\n\tmin: number;\n\tmax: number;\n\tstep: number;\n\tticks: number[];\n}\n\n/**\n * Extends `[min, max]` to round numbers and lists the ticks between them. Fixed ends\n * (`fixedMin` / `fixedMax`) are kept exactly; ticks then start at the first nice value\n * inside them.\n */\nexport function niceScale(min: number, max: number, count = 5, fixedMin: number | null = null, fixedMax: number | null = null): NiceScale {\n\tlet lo = fixedMin ?? min;\n\tlet hi = fixedMax ?? max;\n\tif (!Number.isFinite(lo) || !Number.isFinite(hi)) {\n\t\tlo = 0;\n\t\thi = 1;\n\t}\n\tif (lo > hi) [lo, hi] = [hi, lo];\n\tif (lo === hi) {\n\t\tconst pad = lo === 0 ? 1 : Math.abs(lo) * 0.1;\n\t\t// A flat series at 0 grows upwards; anything else gets room on both free sides.\n\t\tif (fixedMin === null && lo !== 0) lo -= pad;\n\t\tif (fixedMax === null || lo === hi) hi += pad;\n\t}\n\tconst step = niceStep(hi - lo, count);\n\tconst niceMin = fixedMin ?? clean(Math.floor(lo / step + 1e-9) * step);\n\tconst niceMax = fixedMax ?? clean(Math.ceil(hi / step - 1e-9) * step);\n\tconst ticks: number[] = [];\n\tconst first = Math.ceil(niceMin / step - 1e-9) * step;\n\tfor (let t = first, i = 0; t <= niceMax + step * 1e-9 && i < 1000; t += step, i++) ticks.push(clean(t));\n\treturn { min: niceMin, max: niceMax, step, ticks };\n}\n\n/** Decimals needed to tell ticks `step` apart (at most 6). */\nexport function stepDecimals(step: number): number {\n\tif (!(step > 0) || step >= 1) return 0;\n\treturn Math.min(6, Math.max(0, Math.ceil(-Math.log10(step) - 1e-9)));\n}\n\nconst COMPACT = [\n\t{ value: 1e12, suffix: 'T' },\n\t{ value: 1e9, suffix: 'B' },\n\t{ value: 1e6, suffix: 'M' },\n\t{ value: 1e3, suffix: 'K' }\n];\n\nfunction grouped(value: number, decimals: number): string {\n\tconst fixed = Math.abs(value).toFixed(decimals);\n\tconst [int, frac] = fixed.split('.');\n\tconst withCommas = int.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\n\treturn `${value < 0 && Number(fixed) !== 0 ? '-' : ''}${withCommas}${frac ? `.${frac}` : ''}`;\n}\n\nconst CURRENCY_SYMBOLS: Record<string, string> = { USD: '$', EUR: '€', GBP: '£', JPY: '¥', CNY: '¥', INR: '₹', AUD: 'A$', CAD: 'C$' };\n\n/**\n * Writes a number for a chart label. Locale-independent (so labels and tests are the same\n * everywhere): `,` thousands, `.` decimals. `decimals` defaults to `fallbackDecimals`\n * (e.g. from the tick step), else up to 2 trimmed.\n */\nexport function formatChartNumber(value: number | null | undefined, format: ChartNumberFormat = {}, fallbackDecimals?: number): string {\n\tif (value === null || value === undefined || !Number.isFinite(value)) return '';\n\tconst style = format.style ?? 'number';\n\tlet body: string;\n\tconst decimalsFor = (v: number) => {\n\t\tif (format.decimals !== undefined) return format.decimals;\n\t\tif (fallbackDecimals !== undefined) return fallbackDecimals;\n\t\treturn Number.isInteger(v) ? 0 : Math.abs(v) < 1 ? Math.min(4, Math.max(2, stepDecimals(Math.abs(v)) + 1)) : 2;\n\t};\n\tconst trim = (s: string) => (format.decimals === undefined && fallbackDecimals === undefined && s.includes('.') ? s.replace(/\\.?0+$/, '') : s);\n\tif (style === 'percent') {\n\t\tconst v = value * 100;\n\t\tconst d = format.decimals ?? (fallbackDecimals !== undefined ? Math.max(0, fallbackDecimals - 2) : Number.isInteger(clean(v)) ? 0 : 1);\n\t\tbody = `${grouped(clean(v), d)}%`;\n\t} else if (style === 'compact') {\n\t\tconst unit = COMPACT.find((u) => Math.abs(value) >= u.value);\n\t\tif (unit) {\n\t\t\tconst v = value / unit.value;\n\t\t\tconst d = format.decimals ?? (Math.abs(v) >= 100 || Number.isInteger(clean(v)) ? 0 : 1);\n\t\t\tbody = `${trim(grouped(v, d))}${unit.suffix}`;\n\t\t} else body = trim(grouped(value, decimalsFor(value)));\n\t} else if (style === 'currency') {\n\t\tconst code = (format.currency || 'USD').toUpperCase();\n\t\tconst symbol = CURRENCY_SYMBOLS[code] ?? `${code} `;\n\t\tconst d = format.decimals ?? (fallbackDecimals !== undefined ? fallbackDecimals : Number.isInteger(value) ? 0 : 2);\n\t\tconst s = grouped(Math.abs(value), d);\n\t\tbody = `${value < 0 ? '-' : ''}${symbol}${s}`;\n\t} else body = trim(grouped(value, decimalsFor(value)));\n\treturn `${format.prefix ?? ''}${body}${format.suffix ?? ''}`;\n}\n\n/** Linear map from `domain` to `range`. */\nexport function linearMap(value: number, domain: readonly [number, number], range: readonly [number, number]): number {\n\tconst [d0, d1] = domain;\n\tconst [r0, r1] = range;\n\tif (d1 === d0) return (r0 + r1) / 2;\n\treturn r0 + ((value - d0) / (d1 - d0)) * (r1 - r0);\n}\n","import { formatChartNumber, linearMap, niceScale, stepDecimals } from './scale.js';\nimport { chartSeriesColor, chartSeriesType, chartSliceColor, DEFAULT_CHART_THEME, isCartesianChart } from './spec.js';\nimport type {\n\tChartMark,\n\tChartNumberFormat,\n\tChartRect,\n\tChartScene,\n\tChartSelection,\n\tChartSeries,\n\tChartSeriesType,\n\tChartSpec,\n\tChartTheme,\n\tChartValueScale\n} from './types.js';\n\nexport type ChartTextMeasure = (text: string, size: number, weight?: number) => number;\n\nexport interface ChartLayoutOptions {\n\twidth: number;\n\theight: number;\n\ttheme?: Partial<ChartTheme>;\n\t/** Highlighted in the scene (selection outlines, `selected` flags). */\n\tselection?: ChartSelection | null;\n\t/** Text width in pixels (default: an estimate from the character count). */\n\tmeasureText?: ChartTextMeasure;\n\t/** Shown when there is nothing to draw (default \"No data\"). */\n\temptyMessage?: string;\n}\n\n/** A DOM-free text width estimate (average glyph ≈ 0.56 em, bold ≈ 0.6 em). */\nexport const estimateChartTextWidth: ChartTextMeasure = (text, size, weight = 400) => text.length * size * (weight >= 600 ? 0.6 : 0.56);\n\n/** Whether two selections point at the same thing. */\nexport function sameChartSelection(a: ChartSelection | null | undefined, b: ChartSelection | null | undefined): boolean {\n\tif (!a || !b || a.kind !== b.kind) return false;\n\tswitch (a.kind) {\n\t\tcase 'axis':\n\t\t\treturn a.axis === (b as typeof a).axis;\n\t\tcase 'series':\n\t\t\treturn a.seriesId === (b as typeof a).seriesId;\n\t\tcase 'point':\n\t\t\treturn a.seriesId === (b as typeof a).seriesId && a.index === (b as typeof a).index;\n\t\tcase 'category':\n\t\t\treturn a.index === (b as typeof a).index;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\nconst r2 = (n: number) => Math.round(n * 100) / 100;\n\ninterface Pt {\n\tc: number;\n\tv: number;\n}\n\n/** Path through points (in category/value pixel space) with the chosen curve; `map` turns them into x/y. */\nfunction curvePath(points: Pt[], curve: ChartSpec['curve'], map: (p: Pt) => [number, number], moveFirst = true): string {\n\tif (!points.length) return '';\n\tconst xy = points.map(map);\n\tlet d = `${moveFirst ? 'M' : 'L'}${r2(xy[0][0])},${r2(xy[0][1])}`;\n\tif (points.length === 1) return d;\n\tif (curve === 'step') {\n\t\tfor (let i = 1; i < points.length; i++) {\n\t\t\tconst mid = (points[i - 1].c + points[i].c) / 2;\n\t\t\tconst a = map({ c: mid, v: points[i - 1].v });\n\t\t\tconst b = map({ c: mid, v: points[i].v });\n\t\t\td += `L${r2(a[0])},${r2(a[1])}L${r2(b[0])},${r2(b[1])}L${r2(xy[i][0])},${r2(xy[i][1])}`;\n\t\t}\n\t\treturn d;\n\t}\n\tif (curve === 'smooth' && points.length > 2) {\n\t\t// Monotone cubic (Fritsch–Carlson): smooth, never overshoots the data.\n\t\tconst n = points.length;\n\t\tconst dc = points.slice(1).map((p, i) => p.c - points[i].c);\n\t\tconst slope = points.slice(1).map((p, i) => (dc[i] === 0 ? 0 : (p.v - points[i].v) / dc[i]));\n\t\tconst tangent = points.map((_, i) => {\n\t\t\tif (i === 0) return slope[0];\n\t\t\tif (i === n - 1) return slope[n - 2];\n\t\t\tconst a = slope[i - 1];\n\t\t\tconst b = slope[i];\n\t\t\tif (a * b <= 0) return 0;\n\t\t\tconst wa = 2 * dc[i] + dc[i - 1];\n\t\t\tconst wb = dc[i] + 2 * dc[i - 1];\n\t\t\treturn (wa + wb) / (wa / a + wb / b);\n\t\t});\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tconst h = dc[i - 1] / 3;\n\t\t\tconst p0 = points[i - 1];\n\t\t\tconst p1 = points[i];\n\t\t\tconst a = map({ c: p0.c + h, v: p0.v + tangent[i - 1] * h });\n\t\t\tconst b = map({ c: p1.c - h, v: p1.v - tangent[i] * h });\n\t\t\td += `C${r2(a[0])},${r2(a[1])} ${r2(b[0])},${r2(b[1])} ${r2(xy[i][0])},${r2(xy[i][1])}`;\n\t\t}\n\t\treturn d;\n\t}\n\tfor (let i = 1; i < xy.length; i++) d += `L${r2(xy[i][0])},${r2(xy[i][1])}`;\n\treturn d;\n}\n\nfunction arcPath(cx: number, cy: number, outer: number, inner: number, start: number, end: number): string {\n\tconst full = end - start >= Math.PI * 2 - 1e-9;\n\tif (full) end = start + Math.PI * 2 - 1e-4;\n\tconst p = (r: number, a: number) => `${r2(cx + r * Math.sin(a))},${r2(cy - r * Math.cos(a))}`;\n\tconst large = end - start > Math.PI ? 1 : 0;\n\tlet d = `M${p(outer, start)}A${r2(outer)},${r2(outer)} 0 ${large} 1 ${p(outer, end)}`;\n\tif (inner > 0) d += `L${p(inner, end)}A${r2(inner)},${r2(inner)} 0 ${large} 0 ${p(inner, start)}Z`;\n\telse d += `L${r2(cx)},${r2(cy)}Z`;\n\treturn d;\n}\n\ninterface LegendItem {\n\tlabel: string;\n\tcolor: string;\n\ttarget: ChartSelection;\n\tfaded: boolean;\n\tselected: boolean;\n\tshape: 'square' | 'line';\n}\n\ninterface Stack {\n\t/** Per category: [bottom, top] of this series' segment, or null for a gap. */\n\tsegments: ([number, number] | null)[];\n}\n\n/**\n * Lays a chart out as drawing primitives (rects, paths, circles, lines and text) in a\n * `width × height` box. Pure and DOM-free: the React and Svelte canvases render the marks\n * as SVG, `chartSceneToSvg` writes them as a string, and anything else (canvas, PDF) can\n * draw them too. Clickable marks carry the `target` they select.\n */\nexport function layoutChart(spec: ChartSpec, options: ChartLayoutOptions): ChartScene {\n\tconst width = Math.max(1, options.width);\n\tconst height = Math.max(1, options.height);\n\tconst theme: ChartTheme = { ...DEFAULT_CHART_THEME, ...options.theme };\n\tconst measure = options.measureText ?? estimateChartTextWidth;\n\tconst selection = options.selection ?? null;\n\tconst fs = theme.fontSize;\n\tconst marks: ChartMark[] = [];\n\tconst isSelected = (target: ChartSelection) => sameChartSelection(selection, target);\n\tconst seriesSelected = (id: string) => selection?.kind === 'series' && selection.seriesId === id;\n\tconst pad = 12;\n\n\tmarks.push({ kind: 'rect', key: 'background', role: 'background', x: 0, y: 0, width, height, fill: theme.background, target: { kind: 'chart' } });\n\n\t// Titles ----------------------------------------------------------------\n\tlet top = pad;\n\tconst outline = (key: string, box: ChartRect) =>\n\t\tmarks.push({ kind: 'rect', key, role: 'selection', ...box, fill: 'none', stroke: theme.selection, strokeWidth: 1, radius: 3 });\n\tconst titleMark = (kind: 'title' | 'subtitle', label: string, size: number, weight: number, fill: string) => {\n\t\tconst target: ChartSelection = { kind };\n\t\tconst selected = isSelected(target);\n\t\tmarks.push({ kind: 'text', key: kind, role: kind, x: width / 2, y: top, text: label, anchor: 'middle', baseline: 'top', size, weight, fill, target, selected });\n\t\tif (selected) {\n\t\t\tconst w = measure(label, size, weight);\n\t\t\toutline(`${kind}-selection`, { x: width / 2 - w / 2 - 4, y: top - 3, width: w + 8, height: size * 1.25 + 6 });\n\t\t}\n\t\ttop += size * 1.35;\n\t};\n\tif (spec.title) titleMark('title', spec.title, theme.titleSize, 600, theme.text);\n\tif (spec.subtitle) titleMark('subtitle', spec.subtitle, fs + 1, 400, theme.mutedText);\n\tif (spec.title || spec.subtitle) top += 6;\n\n\tconst cartesian = isCartesianChart(spec.type);\n\tconst visible = spec.series.filter((s) => !s.hidden);\n\n\t// Legend ----------------------------------------------------------------\n\tconst legendItems: LegendItem[] = cartesian\n\t\t? spec.series.map((s, i) => ({\n\t\t\t\tlabel: s.name,\n\t\t\t\tcolor: chartSeriesColor(spec, i),\n\t\t\t\ttarget: { kind: 'series', seriesId: s.id },\n\t\t\t\tfaded: !!s.hidden,\n\t\t\t\tselected: seriesSelected(s.id),\n\t\t\t\tshape: chartSeriesType(spec, s) === 'line' ? 'line' : 'square'\n\t\t\t}))\n\t\t: spec.categories.map((c, i) => ({\n\t\t\t\tlabel: c,\n\t\t\t\tcolor: chartSliceColor(spec, i),\n\t\t\t\ttarget: { kind: 'category', index: i },\n\t\t\t\tfaded: false,\n\t\t\t\tselected: isSelected({ kind: 'category', index: i }),\n\t\t\t\tshape: 'square'\n\t\t\t}));\n\tlet area: ChartRect = { x: pad, y: top, width: width - pad * 2, height: height - top - pad };\n\tconst showLegend = spec.legend.show && legendItems.length > 0 && (!cartesian || spec.series.length > 1 || spec.series.some((s) => s.hidden));\n\tif (showLegend) area = layoutLegend(legendItems, spec.legend.position, area, theme, measure, marks, isSelected({ kind: 'legend' }));\n\n\tconst empty = (message: string) => {\n\t\tmarks.push({ kind: 'text', key: 'empty', role: 'empty', x: area.x + area.width / 2, y: area.y + area.height / 2, text: message, anchor: 'middle', baseline: 'middle', size: fs + 1, fill: theme.mutedText });\n\t\treturn { width, height, plot: { x: area.x, y: area.y, width: 0, height: 0 }, marks, percent: false, theme };\n\t};\n\tconst hasData = visible.some((s) => s.values.some((v) => v !== null));\n\tif (!spec.categories.length || !visible.length || !hasData) return empty(options.emptyMessage ?? 'No data');\n\n\tif (!cartesian) return layoutPie(spec, visible[0], area, theme, marks, selection, width, height);\n\n\t// Cartesian -------------------------------------------------------------\n\tconst horizontal = spec.orientation === 'horizontal';\n\tconst n = spec.categories.length;\n\tconst types = new Map<string, ChartSeriesType>(visible.map((s) => [s.id, chartSeriesType(spec, s)]));\n\tconst stacked = spec.stacking !== 'none';\n\tconst percent = spec.stacking === 'percent';\n\n\t// Stack bars together and areas together (lines and scatter are never stacked).\n\tconst stacks = new Map<string, Stack>();\n\tif (stacked) {\n\t\tfor (const kind of ['bar', 'area'] as const) {\n\t\t\tconst group = visible.filter((s) => types.get(s.id) === kind);\n\t\t\tif (!group.length) continue;\n\t\t\tconst totals = Array.from({ length: n }, (_, i) => group.reduce((t, s) => t + Math.abs(s.values[i] ?? 0), 0));\n\t\t\tconst pos = Array(n).fill(0);\n\t\t\tconst neg = Array(n).fill(0);\n\t\t\tfor (const s of group) {\n\t\t\t\tconst segments = s.values.map((raw, i) => {\n\t\t\t\t\tif (raw === null && kind === 'bar') return null;\n\t\t\t\t\tlet v = raw ?? 0;\n\t\t\t\t\tif (percent) v = totals[i] ? v / totals[i] : 0;\n\t\t\t\t\tconst base = v >= 0 ? pos[i] : neg[i];\n\t\t\t\t\tconst seg: [number, number] = [base, base + v];\n\t\t\t\t\tif (v >= 0) pos[i] += v;\n\t\t\t\t\telse neg[i] += v;\n\t\t\t\t\treturn seg;\n\t\t\t\t});\n\t\t\t\tstacks.set(s.id, { segments });\n\t\t\t}\n\t\t}\n\t}\n\n\tlet lo = Infinity;\n\tlet hi = -Infinity;\n\tconst see = (v: number) => {\n\t\tlo = Math.min(lo, v);\n\t\thi = Math.max(hi, v);\n\t};\n\tfor (const s of visible) {\n\t\tconst stack = stacks.get(s.id);\n\t\tif (stack) stack.segments.forEach((seg) => seg && (see(seg[0]), see(seg[1])));\n\t\telse s.values.forEach((v) => v !== null && see(v));\n\t}\n\tif (!Number.isFinite(lo)) {\n\t\tlo = 0;\n\t\thi = 1;\n\t}\n\tif ([...types.values()].some((t) => t === 'bar' || t === 'area')) {\n\t\tlo = Math.min(lo, 0);\n\t\thi = Math.max(hi, 0);\n\t}\n\tconst valueFormat: ChartNumberFormat = percent && !spec.yAxis.format.style ? { ...spec.yAxis.format, style: 'percent' } : spec.yAxis.format;\n\n\t// Margins depend on label sizes, and the tick count on the plot length: estimate, then lay out.\n\tconst xAxis = spec.xAxis;\n\tconst yAxis = spec.yAxis;\n\tconst titleBand = fs * 1.3 + 6;\n\tconst valueLen0 = horizontal ? area.width : area.height;\n\tlet scale = niceScale(lo, hi, Math.max(2, Math.min(10, Math.round(valueLen0 / 56))), yAxis.min, yAxis.max);\n\tconst tickText = (t: number) => formatChartNumber(t, valueFormat, valueFormat.decimals ?? stepDecimals(scale.step));\n\tconst valueLabelWidth = Math.max(0, ...scale.ticks.map((t) => measure(tickText(t), fs)));\n\tconst catLabelWidth = Math.max(0, ...spec.categories.map((c) => measure(c, fs)));\n\n\tlet left: number;\n\tlet bottom: number;\n\tlet rotate = 0;\n\tif (horizontal) {\n\t\tleft = (xAxis.show ? Math.min(catLabelWidth, area.width * 0.35) + 8 : 2) + (xAxis.title ? titleBand : 0);\n\t\tbottom = (yAxis.show ? fs * 1.6 : 2) + (yAxis.title ? titleBand : 0);\n\t} else {\n\t\tleft = (yAxis.show ? valueLabelWidth + 8 : 2) + (yAxis.title ? titleBand : 0);\n\t\tconst band = (area.width - left - 8) / n;\n\t\tif (xAxis.show && catLabelWidth > band * 0.92) rotate = -40;\n\t\tconst catHeight = rotate ? Math.min(catLabelWidth * Math.sin(Math.PI / 4.5) + fs, area.height * 0.4) : fs * 1.6;\n\t\tbottom = (xAxis.show ? catHeight : 2) + (xAxis.title ? titleBand : 0);\n\t}\n\tconst rightPad = horizontal ? Math.max(8, valueLabelWidth / 2) : 8;\n\tconst plot: ChartRect = {\n\t\tx: area.x + left,\n\t\ty: area.y + (horizontal ? 4 : fs / 2 + 2),\n\t\twidth: Math.max(1, area.width - left - rightPad),\n\t\theight: Math.max(1, area.height - bottom - (horizontal ? 4 : fs / 2 + 2))\n\t};\n\tscale = niceScale(lo, hi, Math.max(2, Math.min(10, Math.round((horizontal ? plot.width : plot.height) / 56))), yAxis.min, yAxis.max);\n\n\tconst domain: [number, number] = [scale.min, scale.max];\n\tconst valueRange: [number, number] = horizontal ? [plot.x, plot.x + plot.width] : [plot.y + plot.height, plot.y];\n\tconst valuePx = (v: number) => linearMap(Math.min(scale.max, Math.max(scale.min, v)), domain, valueRange);\n\tconst catStart = horizontal ? plot.y : plot.x;\n\tconst catLen = horizontal ? plot.height : plot.width;\n\tconst band = catLen / n;\n\tconst catCenter = (i: number) => catStart + band * (i + 0.5);\n\tconst map = (p: Pt): [number, number] => (horizontal ? [p.v, p.c] : [p.c, p.v]);\n\tconst zero = valuePx(Math.min(scale.max, Math.max(scale.min, 0)));\n\n\t// Grid and axes\n\tconst axisSelected = (axis: 'x' | 'y') => isSelected({ kind: 'axis', axis });\n\tif (yAxis.gridlines) {\n\t\tscale.ticks.forEach((t, i) => {\n\t\t\tconst p = valuePx(t);\n\t\t\tconst [x1, y1] = map({ c: catStart, v: p });\n\t\t\tconst [x2, y2] = map({ c: catStart + catLen, v: p });\n\t\t\tmarks.push({ kind: 'line', key: `grid-y-${i}`, role: 'grid', x1, y1, x2, y2, stroke: theme.grid, strokeWidth: 1 });\n\t\t});\n\t}\n\tif (xAxis.gridlines) {\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tconst c = catStart + band * i;\n\t\t\tconst [x1, y1] = map({ c, v: valueRange[0] });\n\t\t\tconst [x2, y2] = map({ c, v: valueRange[1] });\n\t\t\tmarks.push({ kind: 'line', key: `grid-x-${i}`, role: 'grid', x1, y1, x2, y2, stroke: theme.grid, strokeWidth: 1 });\n\t\t}\n\t}\n\n\tconst yTarget: ChartSelection = { kind: 'axis', axis: 'y' };\n\tconst xTarget: ChartSelection = { kind: 'axis', axis: 'x' };\n\tif (yAxis.show) {\n\t\tscale.ticks.forEach((t, i) => {\n\t\t\tconst p = valuePx(t);\n\t\t\tconst label = tickText(t);\n\t\t\tif (horizontal)\n\t\t\t\tmarks.push({ kind: 'text', key: `tick-y-${i}`, role: 'tick-label', x: p, y: plot.y + plot.height + 6, text: label, anchor: 'middle', baseline: 'top', size: fs, fill: theme.mutedText, target: yTarget });\n\t\t\telse marks.push({ kind: 'text', key: `tick-y-${i}`, role: 'tick-label', x: plot.x - 8, y: p, text: label, anchor: 'end', baseline: 'middle', size: fs, fill: theme.mutedText, target: yTarget });\n\t\t});\n\t}\n\tif (xAxis.show) {\n\t\tconst [x1, y1] = map({ c: catStart, v: zero });\n\t\tconst [x2, y2] = map({ c: catStart + catLen, v: zero });\n\t\tmarks.push({ kind: 'line', key: 'axis-x', role: 'axis', x1, y1, x2, y2, stroke: theme.axis, strokeWidth: 1, target: xTarget });\n\t\tconst every = horizontal ? Math.max(1, Math.ceil((fs * 1.3) / band)) : rotate ? Math.max(1, Math.ceil((fs * 1.4) / band)) : 1;\n\t\tspec.categories.forEach((c, i) => {\n\t\t\tif (i % every) return;\n\t\t\tconst target: ChartSelection = { kind: 'category', index: i };\n\t\t\tconst selected = isSelected(target);\n\t\t\tconst fill = selected ? theme.selection : theme.mutedText;\n\t\t\tif (horizontal) {\n\t\t\t\tconst maxW = left - (xAxis.title ? titleBand : 0) - 8;\n\t\t\t\tmarks.push({ kind: 'text', key: `tick-x-${i}`, role: 'tick-label', x: plot.x - 8, y: catCenter(i), text: truncate(c, maxW, fs, measure), anchor: 'end', baseline: 'middle', size: fs, fill, target, selected });\n\t\t\t} else if (rotate)\n\t\t\t\tmarks.push({ kind: 'text', key: `tick-x-${i}`, role: 'tick-label', x: catCenter(i), y: plot.y + plot.height + 8, text: c, anchor: 'end', baseline: 'middle', size: fs, fill, rotate, target, selected });\n\t\t\telse marks.push({ kind: 'text', key: `tick-x-${i}`, role: 'tick-label', x: catCenter(i), y: plot.y + plot.height + 6, text: c, anchor: 'middle', baseline: 'top', size: fs, fill, target, selected });\n\t\t});\n\t}\n\t// Axis titles: category axis title beside the category labels, value axis title beside the ticks.\n\tconst bottomTitle = horizontal ? yAxis.title : xAxis.title;\n\tconst leftTitle = horizontal ? xAxis.title : yAxis.title;\n\tif (bottomTitle)\n\t\tmarks.push({ kind: 'text', key: `axis-title-${horizontal ? 'y' : 'x'}`, role: 'axis-title', x: plot.x + plot.width / 2, y: area.y + area.height, text: bottomTitle, anchor: 'middle', baseline: 'bottom', size: fs + 1, weight: 500, fill: theme.text, target: horizontal ? yTarget : xTarget });\n\tif (leftTitle)\n\t\tmarks.push({ kind: 'text', key: `axis-title-${horizontal ? 'x' : 'y'}`, role: 'axis-title', x: area.x, y: plot.y + plot.height / 2, text: leftTitle, anchor: 'middle', baseline: 'top', size: fs + 1, weight: 500, fill: theme.text, rotate: -90, target: horizontal ? xTarget : yTarget });\n\t// The selected axis gets an outline around its labels.\n\tfor (const axis of ['x', 'y'] as const) {\n\t\tif (!axisSelected(axis)) continue;\n\t\tconst onLeft = (axis === 'y') !== horizontal;\n\t\tconst box: ChartRect = onLeft\n\t\t\t? { x: area.x, y: plot.y - fs / 2, width: left - 2, height: plot.height + fs }\n\t\t\t: { x: plot.x - 4, y: plot.y + plot.height + 2, width: plot.width + 8, height: area.y + area.height - plot.y - plot.height - 2 };\n\t\toutline(`axis-${axis}-selection`, box);\n\t}\n\n\t// Series ----------------------------------------------------------------\n\tconst bars = visible.filter((s) => types.get(s.id) === 'bar');\n\tconst slots = stacked ? 1 : bars.length;\n\tconst groupWidth = band * (bars.length ? 0.72 : 0);\n\tconst barWidth = slots ? groupWidth / slots : 0;\n\tconst labelMarks: ChartMark[] = [];\n\tconst decimals = valueFormat.decimals ?? undefined;\n\tconst dataLabel = (v: number) => formatChartNumber(v, valueFormat, decimals);\n\n\tconst drawOrder = [...visible].sort((a, b) => order(types.get(a.id)!) - order(types.get(b.id)!));\n\tfor (const s of drawOrder) {\n\t\tconst si = spec.series.indexOf(s);\n\t\tconst color = chartSeriesColor(spec, si);\n\t\tconst type = types.get(s.id)!;\n\t\tconst stack = stacks.get(s.id);\n\t\tconst selSeries = seriesSelected(s.id);\n\t\tconst seriesTarget: ChartSelection = { kind: 'series', seriesId: s.id };\n\n\t\tif (type === 'bar') {\n\t\t\tconst slot = stacked ? 0 : bars.indexOf(s);\n\t\t\ts.values.forEach((raw, i) => {\n\t\t\t\tconst seg = stack ? stack.segments[i] : raw === null ? null : ([0, raw] as [number, number]);\n\t\t\t\tif (!seg || raw === null) return;\n\t\t\t\tconst a = valuePx(seg[0]);\n\t\t\t\tconst b = valuePx(seg[1]);\n\t\t\t\tconst c0 = catCenter(i) - groupWidth / 2 + slot * barWidth + barWidth * 0.06;\n\t\t\t\tconst cw = barWidth * 0.88;\n\t\t\t\tconst target: ChartSelection = { kind: 'point', seriesId: s.id, index: i };\n\t\t\t\tconst selected = isSelected(target);\n\t\t\t\tconst [x, y] = map({ c: c0, v: Math.min(a, b) });\n\t\t\t\tconst rect = horizontal ? { x: Math.min(a, b), y: c0, width: Math.abs(b - a), height: cw } : { x, y, width: cw, height: Math.abs(b - a) };\n\t\t\t\tmarks.push({\n\t\t\t\t\tkind: 'rect',\n\t\t\t\t\tkey: `bar-${s.id}-${i}`,\n\t\t\t\t\trole: 'bar',\n\t\t\t\t\t...rect,\n\t\t\t\t\tfill: color,\n\t\t\t\t\tradius: Math.min(2, cw / 4),\n\t\t\t\t\ttarget,\n\t\t\t\t\tselected: selected || selSeries,\n\t\t\t\t\t...(selSeries ? { stroke: theme.selection, strokeWidth: 1.5 } : {})\n\t\t\t\t});\n\t\t\t\tif (selected) outline(`bar-${s.id}-${i}-selection`, { x: rect.x - 2, y: rect.y - 2, width: rect.width + 4, height: rect.height + 4 });\n\t\t\t\tif (spec.dataLabels) {\n\t\t\t\t\tconst v = percent ? seg[1] - seg[0] : raw;\n\t\t\t\t\tconst end = valuePx(seg[1]);\n\t\t\t\t\tconst outward = (seg[1] >= seg[0] ? 1 : -1) * (horizontal ? 1 : -1);\n\t\t\t\t\tconst [lx, ly] = map({ c: c0 + cw / 2, v: stacked ? (a + b) / 2 : end + outward * 4 });\n\t\t\t\t\tlabelMarks.push({\n\t\t\t\t\t\tkind: 'text',\n\t\t\t\t\t\tkey: `label-${s.id}-${i}`,\n\t\t\t\t\t\trole: 'data-label',\n\t\t\t\t\t\tx: lx,\n\t\t\t\t\t\ty: ly,\n\t\t\t\t\t\ttext: dataLabel(v),\n\t\t\t\t\t\tanchor: horizontal && !stacked ? (outward > 0 ? 'start' : 'end') : 'middle',\n\t\t\t\t\t\tbaseline: horizontal || stacked ? 'middle' : outward < 0 ? 'bottom' : 'top',\n\t\t\t\t\t\tsize: fs - 1,\n\t\t\t\t\t\tfill: stacked ? '#ffffff' : theme.text,\n\t\t\t\t\t\ttarget\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Line, area and scatter share the point positions.\n\t\tconst pointValue = (i: number): number | null => (stack ? (stack.segments[i]?.[1] ?? null) : s.values[i]);\n\t\tconst runs: Pt[][] = [];\n\t\tlet run: Pt[] = [];\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst v = pointValue(i);\n\t\t\tif (v === null) {\n\t\t\t\tif (run.length) runs.push(run);\n\t\t\t\trun = [];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\trun.push({ c: catCenter(i), v: valuePx(v) });\n\t\t}\n\t\tif (run.length) runs.push(run);\n\n\t\tif (type === 'area') {\n\t\t\t// Stacked areas fill down to the series below; others down to zero.\n\t\t\tconst parts = runs.map((r) => {\n\t\t\t\tconst baseline = stack\n\t\t\t\t\t? r.map((p) => ({ c: p.c, v: valuePx(stack.segments[Math.round((p.c - catStart) / band - 0.5)]?.[0] ?? 0) })).reverse()\n\t\t\t\t\t: [\n\t\t\t\t\t\t\t{ c: r[r.length - 1].c, v: zero },\n\t\t\t\t\t\t\t{ c: r[0].c, v: zero }\n\t\t\t\t\t\t];\n\t\t\t\treturn `${curvePath(r, spec.curve, map)}${stack ? curvePath(baseline, spec.curve, map, false) : baseline.map((p) => `L${map(p).map(r2).join(',')}`).join('')}Z`;\n\t\t\t});\n\t\t\tmarks.push({ kind: 'path', key: `area-${s.id}`, role: 'area', d: parts.join(''), fill: color, opacity: 0.22, target: seriesTarget, selected: selSeries });\n\t\t}\n\t\tif (type === 'line' || type === 'area') {\n\t\t\tmarks.push({\n\t\t\t\tkind: 'path',\n\t\t\t\tkey: `line-${s.id}`,\n\t\t\t\trole: 'line',\n\t\t\t\td: runs.map((r) => curvePath(r, spec.curve, map)).join(''),\n\t\t\t\tfill: 'none',\n\t\t\t\tstroke: color,\n\t\t\t\tstrokeWidth: selSeries ? 3.5 : 2,\n\t\t\t\ttarget: seriesTarget,\n\t\t\t\tselected: selSeries\n\t\t\t});\n\t\t}\n\t\tconst showDots = type === 'scatter' || spec.points;\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst v = pointValue(i);\n\t\t\tif (v === null || s.values[i] === null) continue;\n\t\t\tconst [cx, cy] = map({ c: catCenter(i), v: valuePx(v) });\n\t\t\tconst target: ChartSelection = { kind: 'point', seriesId: s.id, index: i };\n\t\t\tconst selected = isSelected(target);\n\t\t\tconst r = type === 'scatter' ? 4.5 : 3.5;\n\t\t\t// Without dots the point still gets a transparent target so it can be picked and dragged.\n\t\t\tmarks.push({\n\t\t\t\tkind: 'circle',\n\t\t\t\tkey: `point-${s.id}-${i}`,\n\t\t\t\trole: 'point',\n\t\t\t\tcx,\n\t\t\t\tcy,\n\t\t\t\tr: showDots ? r : 6,\n\t\t\t\tfill: showDots ? (type === 'scatter' ? color : theme.surface) : 'transparent',\n\t\t\t\t...(showDots ? { stroke: color, strokeWidth: 2 } : {}),\n\t\t\t\topacity: type === 'scatter' ? 0.85 : undefined,\n\t\t\t\ttarget,\n\t\t\t\tselected: selected || selSeries\n\t\t\t});\n\t\t\tif (selected) marks.push({ kind: 'circle', key: `point-${s.id}-${i}-selection`, role: 'selection', cx, cy, r: r + 3.5, fill: 'none', stroke: theme.selection, strokeWidth: 1.5 });\n\t\t\tif (spec.dataLabels) {\n\t\t\t\tconst raw = s.values[i]!;\n\t\t\t\tconst shown = percent && stack ? stack.segments[i]![1] - stack.segments[i]![0] : raw;\n\t\t\t\tlabelMarks.push({\n\t\t\t\t\tkind: 'text',\n\t\t\t\t\tkey: `label-${s.id}-${i}`,\n\t\t\t\t\trole: 'data-label',\n\t\t\t\t\tx: horizontal ? cx + 8 : cx,\n\t\t\t\t\ty: horizontal ? cy : cy - 8,\n\t\t\t\t\ttext: dataLabel(shown),\n\t\t\t\t\tanchor: horizontal ? 'start' : 'middle',\n\t\t\t\t\tbaseline: horizontal ? 'middle' : 'bottom',\n\t\t\t\t\tsize: fs - 1,\n\t\t\t\t\tfill: theme.text,\n\t\t\t\t\ttarget\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\tmarks.push(...labelMarks);\n\n\tconst valueScale: ChartValueScale = { axis: horizontal ? 'x' : 'y', domain, range: valueRange, ticks: scale.ticks };\n\treturn { width, height, plot, marks, valueScale, percent, theme };\n}\n\nconst order = (t: ChartSeriesType) => (t === 'area' ? 0 : t === 'bar' ? 1 : t === 'line' ? 2 : 3);\n\nfunction truncate(text: string, maxWidth: number, size: number, measure: ChartTextMeasure): string {\n\tif (measure(text, size) <= maxWidth) return text;\n\tlet out = text;\n\twhile (out.length > 1 && measure(`${out}…`, size) > maxWidth) out = out.slice(0, -1);\n\treturn `${out}…`;\n}\n\nfunction layoutLegend(\n\titems: LegendItem[],\n\tposition: ChartSpec['legend']['position'],\n\tarea: ChartRect,\n\ttheme: ChartTheme,\n\tmeasure: ChartTextMeasure,\n\tmarks: ChartMark[],\n\tlegendSelected: boolean\n): ChartRect {\n\tconst fs = theme.fontSize;\n\tconst swatch = 10;\n\tconst rowH = fs * 1.7;\n\tconst itemW = (item: LegendItem) => swatch + 6 + measure(item.label, fs) + 14;\n\tconst placed: { item: LegendItem; x: number; y: number }[] = [];\n\tlet box: ChartRect;\n\tlet rest: ChartRect;\n\tif (position === 'left' || position === 'right') {\n\t\tconst w = Math.min(area.width * 0.35, Math.max(...items.map(itemW)));\n\t\tconst h = Math.min(items.length * rowH, area.height);\n\t\tconst x = position === 'left' ? area.x : area.x + area.width - w;\n\t\tconst y = area.y + (area.height - h) / 2;\n\t\titems.forEach((item, i) => {\n\t\t\tif ((i + 1) * rowH <= area.height + 0.5) placed.push({ item, x, y: y + i * rowH + rowH / 2 });\n\t\t});\n\t\tbox = { x, y, width: w, height: h };\n\t\trest = position === 'left' ? { ...area, x: area.x + w + 8, width: area.width - w - 8 } : { ...area, width: area.width - w - 8 };\n\t} else {\n\t\t// Wrap into rows, each centred.\n\t\tconst rows: LegendItem[][] = [[]];\n\t\tlet used = 0;\n\t\tfor (const item of items) {\n\t\t\tconst w = itemW(item);\n\t\t\tif (used + w > area.width && rows[rows.length - 1].length) {\n\t\t\t\trows.push([]);\n\t\t\t\tused = 0;\n\t\t\t}\n\t\t\trows[rows.length - 1].push(item);\n\t\t\tused += w;\n\t\t}\n\t\tconst shown = rows.slice(0, 3);\n\t\tconst h = shown.length * rowH;\n\t\tconst y0 = position === 'top' ? area.y : area.y + area.height - h;\n\t\tshown.forEach((row, r) => {\n\t\t\tconst total = row.reduce((t, item) => t + itemW(item), 0) - 14;\n\t\t\tlet x = area.x + (area.width - total) / 2;\n\t\t\tfor (const item of row) {\n\t\t\t\tplaced.push({ item, x, y: y0 + r * rowH + rowH / 2 });\n\t\t\t\tx += itemW(item);\n\t\t\t}\n\t\t});\n\t\tbox = { x: area.x, y: y0, width: area.width, height: h };\n\t\trest = position === 'top' ? { ...area, y: area.y + h + 6, height: area.height - h - 6 } : { ...area, height: area.height - h - 6 };\n\t}\n\tplaced.forEach(({ item, x, y }, i) => {\n\t\tconst opacity = item.faded ? 0.4 : undefined;\n\t\tif (item.shape === 'line')\n\t\t\tmarks.push({ kind: 'line', key: `legend-swatch-${i}`, role: 'legend-swatch', x1: x, y1: y, x2: x + swatch, y2: y, stroke: item.color, strokeWidth: 2.5, opacity, target: item.target, selected: item.selected });\n\t\telse\n\t\t\tmarks.push({ kind: 'rect', key: `legend-swatch-${i}`, role: 'legend-swatch', x, y: y - swatch / 2, width: swatch, height: swatch, radius: 2, fill: item.color, opacity, target: item.target, selected: item.selected });\n\t\tmarks.push({\n\t\t\tkind: 'text',\n\t\t\tkey: `legend-label-${i}`,\n\t\t\trole: 'legend-label',\n\t\t\tx: x + swatch + 6,\n\t\t\ty,\n\t\t\ttext: item.label,\n\t\t\tanchor: 'start',\n\t\t\tbaseline: 'middle',\n\t\t\tsize: fs,\n\t\t\tfill: item.selected ? theme.selection : theme.text,\n\t\t\tweight: item.selected ? 600 : undefined,\n\t\t\topacity,\n\t\t\ttarget: item.target,\n\t\t\tselected: item.selected\n\t\t});\n\t});\n\tif (legendSelected) marks.push({ kind: 'rect', key: 'legend-selection', role: 'selection', x: box.x - 4, y: box.y - 2, width: box.width + 8, height: box.height + 4, fill: 'none', stroke: theme.selection, strokeWidth: 1, radius: 3 });\n\treturn rest;\n}\n\nfunction layoutPie(\n\tspec: ChartSpec,\n\tseries: ChartSeries,\n\tarea: ChartRect,\n\ttheme: ChartTheme,\n\tmarks: ChartMark[],\n\tselection: ChartSelection | null,\n\twidth: number,\n\theight: number\n): ChartScene {\n\tconst fs = theme.fontSize;\n\tconst values = spec.categories.map((_, i) => Math.max(0, series.values[i] ?? 0));\n\tconst total = values.reduce((a, b) => a + b, 0);\n\tconst labelRoom = spec.dataLabels ? fs * 2.2 : 4;\n\tconst outer = Math.max(4, Math.min(area.width, area.height) / 2 - labelRoom);\n\tconst inner = spec.type === 'donut' ? outer * spec.innerRadius : 0;\n\tconst cx = area.x + area.width / 2;\n\tconst cy = area.y + area.height / 2;\n\tconst plot = { x: cx - outer, y: cy - outer, width: outer * 2, height: outer * 2 };\n\tif (total <= 0) {\n\t\tmarks.push({ kind: 'text', key: 'empty', role: 'empty', x: cx, y: cy, text: 'No positive values', anchor: 'middle', baseline: 'middle', size: fs + 1, fill: theme.mutedText });\n\t\treturn { width, height, plot, marks, percent: false, theme };\n\t}\n\tlet angle = 0;\n\tconst format = spec.yAxis.format;\n\tvalues.forEach((v, i) => {\n\t\tif (v <= 0) return;\n\t\tconst sweep = (v / total) * Math.PI * 2;\n\t\tconst start = angle;\n\t\tconst end = angle + sweep;\n\t\tangle = end;\n\t\tconst target: ChartSelection = { kind: 'point', seriesId: series.id, index: i };\n\t\tconst selected = sameChartSelection(selection, target) || sameChartSelection(selection, { kind: 'category', index: i });\n\t\tconst seriesSel = selection?.kind === 'series' && selection.seriesId === series.id;\n\t\t// The selected slice pops out a little.\n\t\tconst mid = (start + end) / 2;\n\t\tconst off = selected ? 6 : 0;\n\t\tconst ox = cx + off * Math.sin(mid);\n\t\tconst oy = cy - off * Math.cos(mid);\n\t\tmarks.push({\n\t\t\tkind: 'path',\n\t\t\tkey: `slice-${i}`,\n\t\t\trole: 'slice',\n\t\t\td: arcPath(ox, oy, outer, inner, start, end),\n\t\t\tfill: chartSliceColor(spec, i),\n\t\t\tstroke: selected || seriesSel ? theme.selection : theme.surface,\n\t\t\tstrokeWidth: selected || seriesSel ? 2 : 1,\n\t\t\ttarget,\n\t\t\tselected: selected || seriesSel\n\t\t});\n\t\tif (spec.dataLabels && sweep > 0.12) {\n\t\t\tconst share = v / total;\n\t\t\tconst text = format.style ? formatChartNumber(v, format) : `${Math.round(share * 100)}%`;\n\t\t\tconst lr = outer + fs * 1.1;\n\t\t\tconst lx = ox + lr * Math.sin(mid);\n\t\t\tconst ly = oy - lr * Math.cos(mid);\n\t\t\tconst anchor = Math.abs(Math.sin(mid)) < 0.2 ? 'middle' : Math.sin(mid) > 0 ? 'start' : 'end';\n\t\t\tmarks.push({ kind: 'text', key: `label-slice-${i}`, role: 'data-label', x: lx, y: ly, text, anchor, baseline: 'middle', size: fs, fill: theme.text, target });\n\t\t}\n\t});\n\tif (spec.type === 'donut' && inner > fs * 2) {\n\t\tmarks.push({ kind: 'text', key: 'donut-total', role: 'data-label', x: cx, y: cy, text: formatChartNumber(total, format), anchor: 'middle', baseline: 'middle', size: Math.min(theme.titleSize + 4, inner / 2), weight: 600, fill: theme.text, target: { kind: 'series', seriesId: series.id } });\n\t}\n\treturn { width, height, plot, marks, percent: false, theme };\n}\n\n/**\n * The data value at a scene point along the value axis (for dragging a bar or point), or\n * `undefined` when the scene has no value scale or is percent-stacked.\n */\nexport function chartValueAtPoint(scene: ChartScene, point: { x: number; y: number }): number | undefined {\n\tconst scale = scene.valueScale;\n\tif (!scale || scene.percent) return undefined;\n\tconst px = scale.axis === 'y' ? point.y : point.x;\n\treturn linearMap(px, scale.range, scale.domain);\n}\n\n/** The value a drag should store: snapped to a tenth of the tick step (or `step`) and kept finite. */\nexport function snapChartValue(scene: ChartScene, value: number, step?: number): number {\n\tconst ticks = scene.valueScale?.ticks ?? [];\n\tconst unit = step ?? (ticks.length > 1 ? (ticks[1] - ticks[0]) / 10 : 1);\n\tif (!(unit > 0)) return value;\n\tconst snapped = Math.round(value / unit) * unit;\n\treturn Number(snapped.toPrecision(12));\n}\n","import { layoutChart, type ChartLayoutOptions } from './layout.js';\nimport type { ChartMark, ChartScene, ChartSpec, ChartTextMark } from './types.js';\n\n/** SVG `dominant-baseline` for a text mark's baseline (shared by every renderer). */\nexport function chartTextBaseline(baseline: ChartTextMark['baseline']): 'hanging' | 'central' | 'text-after-edge' {\n\treturn baseline === 'top' ? 'hanging' : baseline === 'middle' ? 'central' : 'text-after-edge';\n}\n\n/** SVG `transform` for a rotated text mark, if any. */\nexport function chartTextTransform(mark: ChartTextMark): string | undefined {\n\treturn mark.rotate ? `rotate(${mark.rotate} ${mark.x} ${mark.y})` : undefined;\n}\n\nconst escape = (text: string) => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"');\n\nfunction attrs(values: Record<string, string | number | undefined>): string {\n\treturn Object.entries(values)\n\t\t.filter(([, v]) => v !== undefined && v !== '')\n\t\t.map(([k, v]) => ` ${k}=\"${escape(String(v))}\"`)\n\t\t.join('');\n}\n\nfunction markToSvg(mark: ChartMark, fontFamily: string): string {\n\tconst common = { opacity: mark.opacity, 'data-role': mark.role };\n\tswitch (mark.kind) {\n\t\tcase 'rect':\n\t\t\treturn `<rect${attrs({ x: mark.x, y: mark.y, width: mark.width, height: mark.height, rx: mark.radius, fill: mark.fill, stroke: mark.stroke, 'stroke-width': mark.strokeWidth, ...common })}/>`;\n\t\tcase 'path':\n\t\t\treturn `<path${attrs({ d: mark.d, fill: mark.fill ?? 'none', stroke: mark.stroke, 'stroke-width': mark.strokeWidth, 'stroke-dasharray': mark.dash, 'stroke-linejoin': 'round', 'stroke-linecap': 'round', ...common })}/>`;\n\t\tcase 'circle':\n\t\t\treturn `<circle${attrs({ cx: mark.cx, cy: mark.cy, r: mark.r, fill: mark.fill, stroke: mark.stroke, 'stroke-width': mark.strokeWidth, ...common })}/>`;\n\t\tcase 'line':\n\t\t\treturn `<line${attrs({ x1: mark.x1, y1: mark.y1, x2: mark.x2, y2: mark.y2, stroke: mark.stroke, 'stroke-width': mark.strokeWidth, 'stroke-dasharray': mark.dash, ...common })}/>`;\n\t\tcase 'text':\n\t\t\treturn `<text${attrs({\n\t\t\t\tx: mark.x,\n\t\t\t\ty: mark.y,\n\t\t\t\t'text-anchor': mark.anchor,\n\t\t\t\t'dominant-baseline': chartTextBaseline(mark.baseline),\n\t\t\t\t'font-size': mark.size,\n\t\t\t\t'font-weight': mark.weight,\n\t\t\t\t'font-family': fontFamily,\n\t\t\t\tfill: mark.fill,\n\t\t\t\ttransform: chartTextTransform(mark),\n\t\t\t\t...common\n\t\t\t})}>${escape(mark.text)}</text>`;\n\t}\n}\n\nexport interface ChartSvgOptions {\n\t/** Leave out selection outlines (default `true`: exports show the chart only). */\n\thideSelection?: boolean;\n\t/** Accessible title (default: the chart title). */\n\tariaLabel?: string;\n}\n\n/** Writes a laid-out scene as a standalone SVG document string. */\nexport function chartSceneToSvg(scene: ChartScene, options: ChartSvgOptions = {}): string {\n\tconst hide = options.hideSelection ?? true;\n\tconst font = scene.theme.fontFamily;\n\tconst body = scene.marks\n\t\t.filter((m) => !(hide && m.role === 'selection'))\n\t\t.map((m) => markToSvg(m, font))\n\t\t.join('');\n\tconst label = options.ariaLabel;\n\treturn `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${scene.width}\" height=\"${scene.height}\" viewBox=\"0 0 ${scene.width} ${scene.height}\" role=\"img\"${label ? ` aria-label=\"${escape(label)}\"` : ''}>${body}</svg>`;\n}\n\n/** Lays out and writes a chart as SVG, e.g. for export or server rendering. */\nexport function chartToSvg(spec: ChartSpec, options: Omit<ChartLayoutOptions, 'selection'> & ChartSvgOptions): string {\n\tconst scene = layoutChart(spec, { ...options, selection: null });\n\treturn chartSceneToSvg(scene, { ...options, ariaLabel: options.ariaLabel ?? (spec.title || undefined) });\n}\n","import { HistoryManager } from '../history/HistoryManager.js';\nimport type { Command } from '../history/types.js';\nimport { parseCsv, parseTsv } from '../spreadsheet/csv.js';\nimport { sameChartSelection } from './layout.js';\nimport {\n\tchartDataFromTable,\n\tcloneChartSeries,\n\tcloneChartSpec,\n\tnormalizeChartSpec,\n\tparseChartValue,\n\tuniqueChartSeriesId,\n\ttype ChartTableOptions\n} from './spec.js';\nimport type {\n\tChartAxis,\n\tChartIssue,\n\tChartLegend,\n\tChartSelection,\n\tChartSeries,\n\tChartSeriesType,\n\tChartSpec,\n\tChartType,\n\tChartValue\n} from './types.js';\n\nexport interface ChartControllerOptions {\n\t/** Starting chart (any partial or saved spec; problems are reported in `state.issues`). */\n\tspec?: Partial<ChartSpec> | unknown;\n\t/** History to record into, e.g. one shared with the rest of the app (default: a new one). */\n\thistory?: HistoryManager;\n\t/** Called after the spec changes (edit, undo, redo, load). */\n\tonChange?: (spec: Readonly<ChartSpec>) => void;\n}\n\n/** A snapshot of the controller. The same object is returned until something changes. */\nexport interface ChartState {\n\tspec: Readonly<ChartSpec>;\n\tselection: ChartSelection | null;\n\t/** The series the selection belongs to (a series or one of its points). */\n\tselectedSeries: ChartSeries | null;\n\t/** The category the selection belongs to (a category or a point). */\n\tselectedIndex: number | null;\n\t/** Problems from the last load or rejected edit, as sentences. */\n\tissues: readonly ChartIssue[];\n\t/** The gesture in progress (e.g. a bar drag), if any. */\n\tgesture: string | null;\n\tcanUndo: boolean;\n\tcanRedo: boolean;\n\tundoLabel: string;\n\tredoLabel: string;\n\t/** Bumped on every change. */\n\trevision: number;\n}\n\nexport type ChartActionResult = { ok: true } | { ok: false; message: string; issues?: ChartIssue[] };\n\n/** Top-level fields with partial axes and legend. */\nexport type ChartSpecPatch = Partial<Omit<ChartSpec, 'version' | 'xAxis' | 'yAxis' | 'legend'>> & {\n\txAxis?: Partial<ChartAxis>;\n\tyAxis?: Partial<ChartAxis>;\n\tlegend?: Partial<ChartLegend>;\n};\n\nexport interface ChartSeriesInput {\n\tid?: string;\n\tname?: string;\n\tvalues?: readonly unknown[];\n\tcolor?: string;\n\ttype?: ChartSeriesType;\n\thidden?: boolean;\n}\n\nexport interface ChartSeriesPatch {\n\tname?: string;\n\t/** `null` goes back to the palette colour. */\n\tcolor?: string | null;\n\t/** `null` follows the chart type. */\n\ttype?: ChartSeriesType | null;\n\thidden?: boolean;\n}\n\nexport interface ChartEditOptions {\n\t/** Undo step label. */\n\tlabel?: string;\n}\n\nconst fail = (message: string, issues?: ChartIssue[]): ChartActionResult => ({ ok: false, message, ...(issues ? { issues } : {}) });\n\n/**\n * Headless state for a chart editor: a validated `ChartSpec`, a selection, and undoable\n * edits to data (values, series, categories, pasted grids, CSV) and presentation (type,\n * titles, axes, legend, stacking, …). Drags merge into one undo step (`beginGesture`).\n * `getState()` returns the same object until something changes, so it works with\n * `useSyncExternalStore` and Svelte runes alike.\n */\nexport class ChartController {\n\treadonly history: HistoryManager;\n\tprivate spec: ChartSpec;\n\tprivate selection: ChartSelection | null = null;\n\tprivate issues: ChartIssue[] = [];\n\tprivate gestureKey: string | null = null;\n\tprivate gestureCount = 0;\n\tprivate revision = 0;\n\tprivate applying = false;\n\tprivate readonly onChange?: ChartControllerOptions['onChange'];\n\tprivate readonly listeners = new Set<(state: ChartState) => void>();\n\tprivate unsubscribeHistory?: () => void;\n\tprivate state!: ChartState;\n\n\tconstructor(options: ChartControllerOptions = {}) {\n\t\tthis.history = options.history ?? new HistoryManager();\n\t\tthis.onChange = options.onChange;\n\t\tconst { spec, issues } = normalizeChartSpec(options.spec ?? {});\n\t\tthis.spec = spec;\n\t\tthis.issues = issues;\n\t\tthis.state = this.computeState();\n\t\tthis.connect();\n\t}\n\n\tprivate connect() {\n\t\tthis.unsubscribeHistory?.();\n\t\tthis.unsubscribeHistory = this.history.subscribe((h) => {\n\t\t\t// Edits notify as they apply; only re-notify when the undo/redo state moved on.\n\t\t\tconst s = this.state;\n\t\t\tif (this.applying || (s.canUndo === h.canUndo && s.canRedo === h.canRedo && s.undoLabel === h.undoName && s.redoLabel === h.redoName)) return;\n\t\t\tthis.notify(false);\n\t\t});\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// State\n\t// -------------------------------------------------------------------------\n\n\t/** The current snapshot (stable until the next change). */\n\tgetState = (): ChartState => this.state;\n\n\t/** Calls `listener` after every change. Returns an unsubscribe function. */\n\tsubscribe = (listener: (state: ChartState) => void): (() => void) => {\n\t\t// Reconnect after `destroy()` so a remount (React StrictMode) keeps undo working.\n\t\tif (!this.unsubscribeHistory) this.connect();\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t};\n\n\t/** The current spec (do not mutate; edit through the controller). */\n\tgetSpec(): Readonly<ChartSpec> {\n\t\treturn this.spec;\n\t}\n\n\tgetSeries(id: string): ChartSeries | undefined {\n\t\treturn this.spec.series.find((s) => s.id === id);\n\t}\n\n\tprivate computeState(): ChartState {\n\t\tconst h = this.history.getState();\n\t\tconst sel = this.selection;\n\t\tconst seriesId = sel?.kind === 'series' || sel?.kind === 'point' ? sel.seriesId : null;\n\t\treturn {\n\t\t\tspec: this.spec,\n\t\t\tselection: sel,\n\t\t\tselectedSeries: seriesId ? (this.spec.series.find((s) => s.id === seriesId) ?? null) : null,\n\t\t\tselectedIndex: sel?.kind === 'point' || sel?.kind === 'category' ? sel.index : null,\n\t\t\tissues: this.issues,\n\t\t\tgesture: this.gestureKey,\n\t\t\tcanUndo: h.canUndo,\n\t\t\tcanRedo: h.canRedo,\n\t\t\tundoLabel: h.undoName,\n\t\t\tredoLabel: h.redoName,\n\t\t\trevision: this.revision\n\t\t};\n\t}\n\n\tprivate notify(specChanged: boolean) {\n\t\tthis.revision++;\n\t\tthis.state = this.computeState();\n\t\tif (specChanged) this.onChange?.(this.spec);\n\t\tconst state = this.state;\n\t\tthis.listeners.forEach((listener) => {\n\t\t\ttry {\n\t\t\t\tlistener(state);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('[ChartController] Error in state listener:', error);\n\t\t\t}\n\t\t});\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// Changes: every edit records a before / after snapshot of the spec\n\t// -------------------------------------------------------------------------\n\n\t/** Drops a selection that no longer points at anything. */\n\tprivate validSelection(sel: ChartSelection | null, spec: ChartSpec): ChartSelection | null {\n\t\tif (!sel) return null;\n\t\tswitch (sel.kind) {\n\t\t\tcase 'series':\n\t\t\t\treturn spec.series.some((s) => s.id === sel.seriesId) ? sel : null;\n\t\t\tcase 'point':\n\t\t\t\treturn spec.series.some((s) => s.id === sel.seriesId) && sel.index < spec.categories.length ? sel : null;\n\t\t\tcase 'category':\n\t\t\t\treturn sel.index < spec.categories.length ? sel : null;\n\t\t\tcase 'title':\n\t\t\t\treturn spec.title ? sel : null;\n\t\t\tcase 'subtitle':\n\t\t\t\treturn spec.subtitle ? sel : null;\n\t\t\tdefault:\n\t\t\t\treturn sel;\n\t\t}\n\t}\n\n\tprivate applySpec(spec: ChartSpec) {\n\t\tthis.applying = true;\n\t\ttry {\n\t\t\tthis.spec = spec;\n\t\t\tthis.selection = this.validSelection(this.selection, spec);\n\t\t} finally {\n\t\t\tthis.applying = false;\n\t\t}\n\t\tthis.notify(true);\n\t}\n\n\tprivate commit(label: string, next: ChartSpec, select?: ChartSelection | null) {\n\t\tconst before = this.spec;\n\t\tthis.issues = [];\n\t\tconst command: Command = {\n\t\t\tname: label,\n\t\t\ttag: 'chart',\n\t\t\texecute: () => this.applySpec(next),\n\t\t\tundo: () => this.applySpec(before),\n\t\t\tredo: () => this.applySpec(next)\n\t\t};\n\t\tif (select !== undefined) this.selection = select;\n\t\tif (this.gestureKey !== null) this.history.executeMerged(command, { key: `chart.gesture:${this.gestureKey}:${this.gestureCount}` });\n\t\telse this.history.execute(command);\n\t}\n\n\tprivate reject(message: string, issues: ChartIssue[] = []): ChartActionResult {\n\t\tthis.issues = issues.length ? issues : [{ path: '', message }];\n\t\tthis.notify(false);\n\t\treturn fail(message, issues.length ? issues : undefined);\n\t}\n\n\t/** A copy of the spec with `edit` applied (series and categories copied as needed). */\n\tprivate edited(edit: (draft: ChartSpec) => void): ChartSpec {\n\t\tconst draft = cloneChartSpec(this.spec);\n\t\tedit(draft);\n\t\treturn draft;\n\t}\n\n\tprivate unknownSeries(id: string): ChartActionResult {\n\t\tconst ids = this.spec.series.map((s) => `\"${s.id}\"`);\n\t\treturn fail(`There is no series \"${id}\"; ${ids.length ? `expected one of ${ids.join(', ')}` : 'the chart has no series yet'}.`);\n\t}\n\n\tprivate badIndex(index: number): ChartActionResult {\n\t\tconst n = this.spec.categories.length;\n\t\treturn fail(n ? `Category index ${index} is out of range; expected 0 to ${n - 1}.` : 'The chart has no categories yet.');\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// Presentation\n\t// -------------------------------------------------------------------------\n\n\t/**\n\t * Changes any presentation or data fields as one undo step. All-or-nothing: if anything\n\t * is invalid, nothing changes and every problem is returned (and shown in `state.issues`).\n\t */\n\tupdate(patch: ChartSpecPatch, options: ChartEditOptions = {}): ChartActionResult {\n\t\tconst s = this.spec;\n\t\tconst merged = {\n\t\t\t...s,\n\t\t\t...patch,\n\t\t\txAxis: patch.xAxis ? { ...s.xAxis, ...patch.xAxis } : s.xAxis,\n\t\t\tyAxis: patch.yAxis ? { ...s.yAxis, ...patch.yAxis } : s.yAxis,\n\t\t\tlegend: patch.legend ? { ...s.legend, ...patch.legend } : s.legend,\n\t\t\tversion: 1\n\t\t};\n\t\tconst { spec, issues } = normalizeChartSpec(merged);\n\t\tif (issues.length) return this.reject(issues.map((i) => i.message).join(' '), issues);\n\t\tif (JSON.stringify(spec) === JSON.stringify(s)) return { ok: true };\n\t\tthis.commit(options.label ?? updateLabel(patch), spec);\n\t\treturn { ok: true };\n\t}\n\n\tsetType(type: ChartType): ChartActionResult {\n\t\treturn this.update({ type }, { label: `Change chart type` });\n\t}\n\n\tsetTitle(title: string): ChartActionResult {\n\t\treturn this.update({ title }, { label: 'Edit title' });\n\t}\n\n\tsetSubtitle(subtitle: string): ChartActionResult {\n\t\treturn this.update({ subtitle }, { label: 'Edit subtitle' });\n\t}\n\n\t/** Changes the category (`x`) or value (`y`) axis. */\n\tsetAxis(axis: 'x' | 'y', patch: Partial<ChartAxis>): ChartActionResult {\n\t\treturn this.update(axis === 'x' ? { xAxis: patch } : { yAxis: patch }, { label: `Change ${axis === 'x' ? 'category' : 'value'} axis` });\n\t}\n\n\tsetLegend(patch: Partial<ChartLegend>): ChartActionResult {\n\t\treturn this.update({ legend: patch }, { label: 'Change legend' });\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// Data\n\t// -------------------------------------------------------------------------\n\n\t/**\n\t * Replaces categories and / or series as one undo step. Values are validated and padded\n\t * to the categories; all-or-nothing like `update`.\n\t */\n\tsetData(data: { categories?: readonly unknown[]; series?: readonly ChartSeriesInput[] }, options: ChartEditOptions = {}): ChartActionResult {\n\t\treturn this.update({ ...(data.categories ? { categories: data.categories as string[] } : {}), ...(data.series ? { series: data.series as ChartSeries[] } : {}) }, { label: options.label ?? 'Edit chart data' });\n\t}\n\n\t/**\n\t * Sets one value (numbers, numeric text such as `1,200` or `12%`, or blank for a gap).\n\t * One undo step, or part of the current gesture.\n\t */\n\tsetValue(seriesId: string, index: number, value: unknown, options: ChartEditOptions = {}): ChartActionResult {\n\t\tconst series = this.getSeries(seriesId);\n\t\tif (!series) return this.unknownSeries(seriesId);\n\t\tif (!Number.isInteger(index) || index < 0 || index >= this.spec.categories.length) return this.badIndex(index);\n\t\tconst parsed = parseChartValue(value);\n\t\tif (parsed === undefined) return this.reject(`\"${String(value)}\" is not a number; enter a number or leave the cell blank.`, [{ path: `${seriesId}[${index}]`, message: `\"${String(value)}\" is not a number.` }]);\n\t\tif (series.values[index] === parsed) {\n\t\t\tif (this.issues.length) {\n\t\t\t\tthis.issues = [];\n\t\t\t\tthis.notify(false);\n\t\t\t}\n\t\t\treturn { ok: true };\n\t\t}\n\t\tconst next = this.edited((d) => {\n\t\t\td.series.find((s) => s.id === seriesId)!.values[index] = parsed;\n\t\t});\n\t\tthis.commit(options.label ?? `Edit ${series.name} · ${this.spec.categories[index]}`, next);\n\t\treturn { ok: true };\n\t}\n\n\t/** Several values as one undo step (all-or-nothing). */\n\tsetValues(cells: readonly { seriesId: string; index: number; value: unknown }[], options: ChartEditOptions = {}): ChartActionResult {\n\t\tconst issues: ChartIssue[] = [];\n\t\tconst parsed: { seriesId: string; index: number; value: ChartValue }[] = [];\n\t\tfor (const cell of cells) {\n\t\t\tif (!this.getSeries(cell.seriesId)) issues.push({ path: cell.seriesId, message: (this.unknownSeries(cell.seriesId) as { message: string }).message });\n\t\t\telse if (!Number.isInteger(cell.index) || cell.index < 0 || cell.index >= this.spec.categories.length) issues.push({ path: `${cell.seriesId}[${cell.index}]`, message: (this.badIndex(cell.index) as { message: string }).message });\n\t\t\telse {\n\t\t\t\tconst value = parseChartValue(cell.value);\n\t\t\t\tif (value === undefined) issues.push({ path: `${cell.seriesId}[${cell.index}]`, message: `\"${String(cell.value)}\" is not a number.` });\n\t\t\t\telse parsed.push({ seriesId: cell.seriesId, index: cell.index, value });\n\t\t\t}\n\t\t}\n\t\tif (issues.length) return this.reject(issues.map((i) => i.message).join(' '), issues);\n\t\tconst next = this.edited((d) => {\n\t\t\tfor (const cell of parsed) d.series.find((s) => s.id === cell.seriesId)!.values[cell.index] = cell.value;\n\t\t});\n\t\tif (JSON.stringify(next.series) !== JSON.stringify(this.spec.series)) this.commit(options.label ?? 'Edit values', next);\n\t\treturn { ok: true };\n\t}\n\n\t/** Adds a series (values padded to the categories) and selects it. Returns its id. */\n\taddSeries(input: ChartSeriesInput = {}, options: { at?: number } = {}): { ok: true; id: string } | { ok: false; message: string; issues?: ChartIssue[] } {\n\t\tconst id = input.id && !this.getSeries(input.id) ? input.id : uniqueChartSeriesId(this.spec.series);\n\t\tconst name = input.name ?? `Series ${this.spec.series.length + 1}`;\n\t\tconst at = Math.max(0, Math.min(this.spec.series.length, options.at ?? this.spec.series.length));\n\t\tconst series = [...this.spec.series];\n\t\tseries.splice(at, 0, { ...input, id, name, values: (input.values ?? []) as ChartValue[] });\n\t\tconst { spec, issues } = normalizeChartSpec({ ...this.spec, series });\n\t\tif (issues.length) return this.reject(issues.map((i) => i.message).join(' '), issues) as { ok: false; message: string };\n\t\tthis.commit(`Add series \"${name}\"`, spec, { kind: 'series', seriesId: id });\n\t\treturn { ok: true, id };\n\t}\n\n\tremoveSeries(id: string): ChartActionResult {\n\t\tconst series = this.getSeries(id);\n\t\tif (!series) return this.unknownSeries(id);\n\t\tthis.commit(\n\t\t\t`Delete series \"${series.name}\"`,\n\t\t\tthis.edited((d) => {\n\t\t\t\td.series = d.series.filter((s) => s.id !== id);\n\t\t\t})\n\t\t);\n\t\treturn { ok: true };\n\t}\n\n\tupdateSeries(id: string, patch: ChartSeriesPatch): ChartActionResult {\n\t\tconst series = this.getSeries(id);\n\t\tif (!series) return this.unknownSeries(id);\n\t\tconst next = cloneChartSeries(series);\n\t\tif (patch.name !== undefined) next.name = String(patch.name);\n\t\tif (patch.color === null || patch.color === '') delete next.color;\n\t\telse if (patch.color !== undefined) next.color = patch.color;\n\t\tif (patch.type === null) delete next.type;\n\t\telse if (patch.type !== undefined) next.type = patch.type;\n\t\tif (patch.hidden !== undefined) {\n\t\t\tif (patch.hidden) next.hidden = true;\n\t\t\telse delete next.hidden;\n\t\t}\n\t\tconst series2 = this.spec.series.map((s) => (s.id === id ? next : s));\n\t\tconst { spec, issues } = normalizeChartSpec({ ...this.spec, series: series2 });\n\t\tif (issues.length) return this.reject(issues.map((i) => i.message).join(' '), issues);\n\t\tif (JSON.stringify(spec.series) === JSON.stringify(this.spec.series)) return { ok: true };\n\t\tconst label =\n\t\t\tpatch.hidden !== undefined && Object.keys(patch).length === 1\n\t\t\t\t? `${patch.hidden ? 'Hide' : 'Show'} \"${series.name}\"`\n\t\t\t\t: patch.name !== undefined && Object.keys(patch).length === 1\n\t\t\t\t\t? 'Rename series'\n\t\t\t\t\t: `Change series \"${series.name}\"`;\n\t\tthis.commit(label, spec);\n\t\treturn { ok: true };\n\t}\n\n\ttoggleSeries(id: string): ChartActionResult {\n\t\tconst series = this.getSeries(id);\n\t\tif (!series) return this.unknownSeries(id);\n\t\treturn this.updateSeries(id, { hidden: !series.hidden });\n\t}\n\n\t/** Moves a series to position `to` (drawing and legend order). */\n\tmoveSeries(id: string, to: number): ChartActionResult {\n\t\tconst from = this.spec.series.findIndex((s) => s.id === id);\n\t\tif (from < 0) return this.unknownSeries(id);\n\t\tconst target = Math.max(0, Math.min(this.spec.series.length - 1, to));\n\t\tif (target === from) return { ok: true };\n\t\tthis.commit(\n\t\t\t'Reorder series',\n\t\t\tthis.edited((d) => {\n\t\t\t\tconst [s] = d.series.splice(from, 1);\n\t\t\t\td.series.splice(target, 0, s);\n\t\t\t})\n\t\t);\n\t\treturn { ok: true };\n\t}\n\n\t/** Inserts a category (with gaps in every series) at `at` (default: the end). Returns its index. */\n\taddCategory(label?: string, options: { at?: number } = {}): { ok: true; index: number } {\n\t\tconst at = Math.max(0, Math.min(this.spec.categories.length, options.at ?? this.spec.categories.length));\n\t\tconst name = label ?? `${this.spec.categories.length + 1}`;\n\t\tthis.commit(\n\t\t\t`Add category \"${name}\"`,\n\t\t\tthis.edited((d) => {\n\t\t\t\td.categories.splice(at, 0, name);\n\t\t\t\tfor (const s of d.series) s.values.splice(at, 0, null);\n\t\t\t}),\n\t\t\t{ kind: 'category', index: at }\n\t\t);\n\t\treturn { ok: true, index: at };\n\t}\n\n\tremoveCategory(index: number): ChartActionResult {\n\t\tif (!Number.isInteger(index) || index < 0 || index >= this.spec.categories.length) return this.badIndex(index);\n\t\tthis.commit(\n\t\t\t`Delete category \"${this.spec.categories[index]}\"`,\n\t\t\tthis.edited((d) => {\n\t\t\t\td.categories.splice(index, 1);\n\t\t\t\tfor (const s of d.series) s.values.splice(index, 1);\n\t\t\t})\n\t\t);\n\t\treturn { ok: true };\n\t}\n\n\trenameCategory(index: number, label: string): ChartActionResult {\n\t\tif (!Number.isInteger(index) || index < 0 || index >= this.spec.categories.length) return this.badIndex(index);\n\t\tif (this.spec.categories[index] === label) return { ok: true };\n\t\tthis.commit(\n\t\t\t'Rename category',\n\t\t\tthis.edited((d) => {\n\t\t\t\td.categories[index] = String(label);\n\t\t\t})\n\t\t);\n\t\treturn { ok: true };\n\t}\n\n\tmoveCategory(from: number, to: number): ChartActionResult {\n\t\tif (!Number.isInteger(from) || from < 0 || from >= this.spec.categories.length) return this.badIndex(from);\n\t\tconst target = Math.max(0, Math.min(this.spec.categories.length - 1, to));\n\t\tif (target === from) return { ok: true };\n\t\tconst move = <T>(list: T[]) => {\n\t\t\tconst [item] = list.splice(from, 1);\n\t\t\tlist.splice(target, 0, item);\n\t\t};\n\t\tthis.commit(\n\t\t\t'Reorder categories',\n\t\t\tthis.edited((d) => {\n\t\t\t\tmove(d.categories);\n\t\t\t\tfor (const s of d.series) move(s.values);\n\t\t\t})\n\t\t);\n\t\treturn { ok: true };\n\t}\n\n\t/**\n\t * Pastes a block of cells (TSV / CSV text or rows) into the data grid with its top-left at\n\t * `row` (category index) and `column` (series index; `-1` is the category column). The\n\t * grid grows to fit. Non-numeric value cells become gaps and are reported in `issues`.\n\t */\n\tpasteCells(row: number, column: number, cells: string | ReadonlyArray<ReadonlyArray<unknown>>): ChartActionResult & { issues?: ChartIssue[] } {\n\t\tconst rows: unknown[][] = typeof cells === 'string' ? (cells.includes('\\t') ? parseTsv(cells) : parseCsv(cells)) : cells.map((r) => [...r]);\n\t\tif (!rows.length) return { ok: true };\n\t\tconst issues: ChartIssue[] = [];\n\t\tconst next = this.edited((d) => {\n\t\t\tconst width = Math.max(...rows.map((r) => r.length));\n\t\t\tconst lastSeries = column + width - 1;\n\t\t\twhile (d.series.length <= lastSeries) {\n\t\t\t\tconst id = uniqueChartSeriesId(d.series);\n\t\t\t\td.series.push({ id, name: `Series ${d.series.length + 1}`, values: d.categories.map(() => null) });\n\t\t\t}\n\t\t\tconst lastRow = row + rows.length - 1;\n\t\t\twhile (d.categories.length <= lastRow) {\n\t\t\t\td.categories.push(`${d.categories.length + 1}`);\n\t\t\t\tfor (const s of d.series) s.values.push(null);\n\t\t\t}\n\t\t\trows.forEach((cellsInRow, r) => {\n\t\t\t\tcellsInRow.forEach((cell, c) => {\n\t\t\t\t\tconst col = column + c;\n\t\t\t\t\tconst index = row + r;\n\t\t\t\t\tif (col < 0) d.categories[index] = cell === null || cell === undefined ? '' : String(cell).trim();\n\t\t\t\t\telse {\n\t\t\t\t\t\tconst parsed = parseChartValue(cell);\n\t\t\t\t\t\tif (parsed === undefined) issues.push({ path: `${d.series[col].id}[${index}]`, message: `\"${String(cell)}\" is not a number; it was left blank.` });\n\t\t\t\t\t\td.series[col].values[index] = parsed ?? null;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t\tthis.commit('Paste cells', next);\n\t\tif (issues.length) {\n\t\t\tthis.issues = issues;\n\t\t\tthis.notify(false);\n\t\t}\n\t\treturn issues.length ? { ok: true, issues } : { ok: true };\n\t}\n\n\t/**\n\t * Replaces the data with a grid of cells (see `chartDataFromTable`): one undo step. Series\n\t * colours and types are kept by name.\n\t */\n\timportTable(rows: ReadonlyArray<ReadonlyArray<unknown>>, options: ChartTableOptions = {}): ChartActionResult & { issues?: ChartIssue[] } {\n\t\tconst data = chartDataFromTable(rows, options);\n\t\tif (!data.categories.length || !data.series.length) return this.reject('There is no data to import: expected a header row and at least one row of values.');\n\t\tconst byName = new Map(this.spec.series.map((s) => [s.name, s]));\n\t\tconst series = data.series.map((s) => {\n\t\t\tconst old = byName.get(s.name);\n\t\t\treturn { ...s, ...(old?.color ? { color: old.color } : {}), ...(old?.type ? { type: old.type } : {}), ...(old ? { id: old.id } : {}) };\n\t\t});\n\t\tconst { spec } = normalizeChartSpec({ ...this.spec, categories: data.categories, series });\n\t\tthis.commit('Import data', spec);\n\t\tif (data.issues.length) {\n\t\t\tthis.issues = data.issues;\n\t\t\tthis.notify(false);\n\t\t\treturn { ok: true, issues: data.issues };\n\t\t}\n\t\treturn { ok: true };\n\t}\n\n\t/** Imports CSV (or TSV, detected by tabs) text; see `importTable`. */\n\timportCsv(text: string, options: ChartTableOptions & { delimiter?: string } = {}): ChartActionResult & { issues?: ChartIssue[] } {\n\t\tconst delimiter = options.delimiter ?? (text.includes('\\t') ? '\\t' : ',');\n\t\treturn this.importTable(parseCsv(text, { delimiter }), options);\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// Selection and gestures\n\t// -------------------------------------------------------------------------\n\n\t/** Selects a chart element (view state; not an undo step). */\n\tselect(selection: ChartSelection | null): void {\n\t\tconst next = this.validSelection(selection, this.spec);\n\t\tif (sameChartSelection(next, this.selection) || (next === null && this.selection === null)) return;\n\t\tthis.selection = next;\n\t\tthis.notify(false);\n\t}\n\n\t/**\n\t * Deletes what is selected: a series or category is removed, a point becomes a gap, a\n\t * title is cleared, the legend or an axis is hidden.\n\t */\n\tdeleteSelection(): ChartActionResult {\n\t\tconst sel = this.selection;\n\t\tif (!sel) return fail('Nothing is selected.');\n\t\tswitch (sel.kind) {\n\t\t\tcase 'series':\n\t\t\t\treturn this.removeSeries(sel.seriesId);\n\t\t\tcase 'category':\n\t\t\t\treturn this.removeCategory(sel.index);\n\t\t\tcase 'point':\n\t\t\t\treturn this.setValue(sel.seriesId, sel.index, null, { label: 'Clear value' });\n\t\t\tcase 'title':\n\t\t\t\treturn this.setTitle('');\n\t\t\tcase 'subtitle':\n\t\t\t\treturn this.setSubtitle('');\n\t\t\tcase 'legend':\n\t\t\t\treturn this.setLegend({ show: false });\n\t\t\tcase 'axis':\n\t\t\t\treturn this.setAxis(sel.axis, { show: false });\n\t\t\tdefault:\n\t\t\t\treturn fail('The chart itself cannot be deleted.');\n\t\t}\n\t}\n\n\t/** Adds `delta` to a value (a gap counts as 0). */\n\tnudgeValue(seriesId: string, index: number, delta: number): ChartActionResult {\n\t\tconst series = this.getSeries(seriesId);\n\t\tif (!series) return this.unknownSeries(seriesId);\n\t\tconst current = series.values[index] ?? 0;\n\t\treturn this.setValue(seriesId, index, Number((current + delta).toPrecision(12)), { label: `Edit ${series.name} · ${this.spec.categories[index] ?? index}` });\n\t}\n\n\t/** Starts a continuous edit (a drag): every change until `endGesture()` is one undo step. */\n\tbeginGesture(key: string): void {\n\t\tif (this.gestureKey === key) return;\n\t\tthis.history.endGesture();\n\t\tthis.gestureKey = key;\n\t\tthis.gestureCount++;\n\t\tthis.notify(false);\n\t}\n\n\tendGesture(): void {\n\t\tif (this.gestureKey === null) return;\n\t\tthis.gestureKey = null;\n\t\tthis.history.endGesture();\n\t\tthis.notify(false);\n\t}\n\n\t// -------------------------------------------------------------------------\n\t// Persistence and history\n\t// -------------------------------------------------------------------------\n\n\t/** The spec, for saving (a copy). */\n\ttoJSON(): ChartSpec {\n\t\treturn cloneChartSpec(this.spec);\n\t}\n\n\t/**\n\t * Replaces the chart without an undo step (e.g. when opening a document). Problems are\n\t * fixed with defaults and reported in `state.issues` (and returned).\n\t */\n\tload(input: unknown, options: { clearHistory?: boolean } = {}): ChartIssue[] {\n\t\tconst { spec, issues } = normalizeChartSpec(input);\n\t\tthis.spec = spec;\n\t\tthis.issues = issues;\n\t\tthis.selection = this.validSelection(this.selection, spec);\n\t\tif (options.clearHistory) {\n\t\t\tthis.applying = true;\n\t\t\ttry {\n\t\t\t\tthis.history.clear();\n\t\t\t} finally {\n\t\t\t\tthis.applying = false;\n\t\t\t}\n\t\t}\n\t\tthis.notify(true);\n\t\treturn issues;\n\t}\n\n\tundo(): boolean {\n\t\tthis.endGesture();\n\t\treturn this.history.undo();\n\t}\n\n\tredo(): boolean {\n\t\tthis.endGesture();\n\t\treturn this.history.redo();\n\t}\n\n\t/** Stops listening to the history (reconnected by the next `subscribe`). */\n\tdestroy(): void {\n\t\tthis.unsubscribeHistory?.();\n\t\tthis.unsubscribeHistory = undefined;\n\t\tthis.listeners.clear();\n\t}\n}\n\nexport function createChartController(options: ChartControllerOptions = {}): ChartController {\n\treturn new ChartController(options);\n}\n\nfunction updateLabel(patch: ChartSpecPatch): string {\n\tconst keys = Object.keys(patch);\n\tif (keys.length !== 1) return 'Change chart';\n\tconst labels: Record<string, string> = {\n\t\ttype: 'Change chart type',\n\t\ttitle: 'Edit title',\n\t\tsubtitle: 'Edit subtitle',\n\t\tcategories: 'Edit categories',\n\t\tseries: 'Edit series',\n\t\txAxis: 'Change category axis',\n\t\tyAxis: 'Change value axis',\n\t\tlegend: 'Change legend',\n\t\tstacking: 'Change stacking',\n\t\torientation: 'Change orientation',\n\t\tcurve: 'Change line style',\n\t\tpoints: 'Toggle points',\n\t\tdataLabels: 'Toggle data labels',\n\t\tpalette: 'Change colours',\n\t\tinnerRadius: 'Change donut hole'\n\t};\n\treturn labels[keys[0]] ?? 'Change chart';\n}\n","import type { CommandSpec } from '../commands/registry.js';\nimport type { ChartController, ChartSpecPatch } from './controller.js';\nimport { CHART_CURVES, CHART_LEGEND_POSITIONS, CHART_NUMBER_STYLES, CHART_ORIENTATIONS, CHART_SERIES_TYPES, CHART_STACKINGS, CHART_TYPES, chartDataToTable } from './spec.js';\nimport { chartToSvg } from './svg.js';\n\nexport interface ChartCommandOptions {\n\t/** Id prefix (default `chart.`); use one per chart when several are registered. */\n\tprefix?: string;\n\t/** Palette group (default `Chart`). */\n\tgroup?: string;\n\t/** Command scope. Omit for global commands. */\n\tscope?: string;\n}\n\nconst fail = (message: string): never => {\n\tthrow new Error(message);\n};\n\nconst check = (result: { ok: boolean; message?: string }) => {\n\tif (!result.ok) fail(result.message ?? 'The change was rejected.');\n};\n\nconst VALUE = { type: ['number', 'string', 'null'], description: 'A number, numeric text (\"1,200\", \"12%\") or null for a gap.' } as const;\n\nconst FORMAT = {\n\ttype: 'object',\n\tproperties: {\n\t\tstyle: { type: 'string', enum: [...CHART_NUMBER_STYLES] },\n\t\tdecimals: { type: 'integer', minimum: 0, maximum: 10 },\n\t\tcurrency: { type: 'string', description: 'ISO code for style \"currency\", e.g. \"EUR\".' },\n\t\tprefix: { type: 'string' },\n\t\tsuffix: { type: 'string' }\n\t},\n\tadditionalProperties: false\n} as const;\n\nconst AXIS = {\n\ttype: 'object',\n\tproperties: {\n\t\tshow: { type: 'boolean' },\n\t\ttitle: { type: 'string' },\n\t\tmin: { type: ['number', 'null'], description: 'Fixed lower bound, or null for automatic.' },\n\t\tmax: { type: ['number', 'null'], description: 'Fixed upper bound, or null for automatic.' },\n\t\tgridlines: { type: 'boolean' },\n\t\tformat: FORMAT\n\t},\n\tadditionalProperties: false\n} as const;\n\nconst SERIES = {\n\ttype: 'object',\n\tproperties: {\n\t\tid: { type: 'string' },\n\t\tname: { type: 'string' },\n\t\tvalues: { type: 'array', items: VALUE, description: 'One value per category.' },\n\t\tcolor: { type: 'string', description: 'CSS colour.' },\n\t\ttype: { type: 'string', enum: [...CHART_SERIES_TYPES], description: 'Draw this series differently (combo charts).' },\n\t\thidden: { type: 'boolean' }\n\t},\n\trequired: ['name', 'values'],\n\tadditionalProperties: false\n} as const;\n\n/**\n * Palette and agent commands for a chart: describe, update presentation, replace data, set\n * values, add / remove series and categories, import CSV and export SVG. Register them in a\n * `CommandRegistry` and agents get them through `createCommandToolProvider`. Failures throw\n * sentences, which the registry returns as `{ ok: false, code: 'failed', message }`.\n */\nexport function createChartCommands(controller: ChartController, options: ChartCommandOptions = {}): CommandSpec[] {\n\tconst prefix = options.prefix ?? 'chart.';\n\tconst base = { group: options.group ?? 'Chart', ...(options.scope ? { scope: options.scope } : {}) };\n\tconst seriesIds = () => controller.getSpec().series.map((s) => s.id);\n\tconst resolveSeries = (ref: string) => {\n\t\tconst spec = controller.getSpec();\n\t\tconst series = spec.series.find((s) => s.id === ref) ?? spec.series.find((s) => s.name === ref);\n\t\tif (!series) fail(`There is no series \"${ref}\"; expected one of ${seriesIds().map((id) => `\"${id}\"`).join(', ') || '(none yet)'}.`);\n\t\treturn series!;\n\t};\n\tconst resolveCategory = (ref: string | number) => {\n\t\tconst categories = controller.getSpec().categories;\n\t\tconst index = typeof ref === 'number' ? ref : categories.indexOf(ref);\n\t\tif (index < 0 || index >= categories.length || !Number.isInteger(index)) fail(`There is no category ${JSON.stringify(ref)}; expected an index from 0 to ${categories.length - 1} or one of the labels.`);\n\t\treturn index;\n\t};\n\n\treturn [\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}describe`,\n\t\t\tlabel: 'Describe Chart',\n\t\t\treadOnly: true,\n\t\t\tkeywords: ['chart', 'data', 'spec', 'get'],\n\t\t\tdescription: 'Returns the chart spec (type, titles, axes, legend, options) and its data as a table with series names in the header row.',\n\t\t\trun: () => {\n\t\t\t\tconst spec = controller.getSpec();\n\t\t\t\treturn { spec: controller.toJSON(), table: chartDataToTable(spec), issues: controller.getState().issues };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}update`,\n\t\t\tlabel: 'Change Chart…',\n\t\t\tkeywords: ['chart', 'title', 'axis', 'legend', 'stack', 'style', 'format'],\n\t\t\tdescription: 'Changes chart presentation as one undo step: type, titles, axes (x = categories, y = values), legend, stacking, orientation, curve, points, data labels, palette or donut hole. Invalid values change nothing and return why.',\n\t\t\tparams: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\ttype: { type: 'string', enum: [...CHART_TYPES] },\n\t\t\t\t\ttitle: { type: 'string' },\n\t\t\t\t\tsubtitle: { type: 'string' },\n\t\t\t\t\txAxis: AXIS,\n\t\t\t\t\tyAxis: AXIS,\n\t\t\t\t\tlegend: { type: 'object', properties: { show: { type: 'boolean' }, position: { type: 'string', enum: [...CHART_LEGEND_POSITIONS] } }, additionalProperties: false },\n\t\t\t\t\tstacking: { type: 'string', enum: [...CHART_STACKINGS] },\n\t\t\t\t\torientation: { type: 'string', enum: [...CHART_ORIENTATIONS] },\n\t\t\t\t\tcurve: { type: 'string', enum: [...CHART_CURVES] },\n\t\t\t\t\tpoints: { type: 'boolean' },\n\t\t\t\t\tdataLabels: { type: 'boolean' },\n\t\t\t\t\tpalette: { type: 'array', items: { type: 'string' }, minItems: 1 },\n\t\t\t\t\tinnerRadius: { type: 'number', minimum: 0, maximum: 0.9 }\n\t\t\t\t},\n\t\t\t\tadditionalProperties: false\n\t\t\t},\n\t\t\trun: (_ctx: unknown, params: ChartSpecPatch) => {\n\t\t\t\tcheck(controller.update(params));\n\t\t\t\treturn { spec: controller.toJSON() };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}setData`,\n\t\t\tlabel: 'Replace Chart Data…',\n\t\t\tkeywords: ['chart', 'data', 'series', 'categories'],\n\t\t\tdescription: 'Replaces the categories and series as one undo step. Each series has one value per category (padded with gaps).',\n\t\t\tparams: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\tcategories: { type: 'array', items: { type: 'string' } },\n\t\t\t\t\tseries: { type: 'array', items: SERIES }\n\t\t\t\t},\n\t\t\t\tadditionalProperties: false\n\t\t\t},\n\t\t\trun: (_ctx: unknown, params: { categories?: string[]; series?: any[] }) => {\n\t\t\t\tcheck(controller.setData(params));\n\t\t\t\treturn { table: chartDataToTable(controller.getSpec()) };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}setValues`,\n\t\t\tlabel: 'Set Chart Values…',\n\t\t\tkeywords: ['chart', 'value', 'cell', 'edit'],\n\t\t\tdescription: 'Sets individual values as one undo step. Series by id or name; category by index or label.',\n\t\t\tparams: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\tcells: {\n\t\t\t\t\t\ttype: 'array',\n\t\t\t\t\t\tminItems: 1,\n\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\ttype: 'object',\n\t\t\t\t\t\t\tproperties: { series: { type: 'string' }, category: { type: ['string', 'integer'] }, value: VALUE },\n\t\t\t\t\t\t\trequired: ['series', 'category', 'value'],\n\t\t\t\t\t\t\tadditionalProperties: false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\trequired: ['cells']\n\t\t\t},\n\t\t\trun: (_ctx: unknown, params: { cells: { series: string; category: string | number; value: unknown }[] }) => {\n\t\t\t\tcheck(controller.setValues(params.cells.map((c) => ({ seriesId: resolveSeries(c.series).id, index: resolveCategory(c.category), value: c.value }))));\n\t\t\t\treturn { table: chartDataToTable(controller.getSpec()) };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}addSeries`,\n\t\t\tlabel: 'Add Series',\n\t\t\tkeywords: ['chart', 'series', 'new'],\n\t\t\tdescription: 'Adds a series (default: an empty one at the end). Returns its id.',\n\t\t\tparams: { type: 'object', properties: { ...SERIES.properties, at: { type: 'integer', minimum: 0 } }, additionalProperties: false },\n\t\t\trun: (_ctx: unknown, params: { at?: number; name?: string; values?: unknown[] } = {}) => {\n\t\t\t\tconst { at, ...input } = params ?? {};\n\t\t\t\tconst result = controller.addSeries(input as any, { at });\n\t\t\t\tcheck(result);\n\t\t\t\treturn { id: (result as { id: string }).id };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}updateSeries`,\n\t\t\tlabel: 'Change Series…',\n\t\t\tkeywords: ['chart', 'series', 'rename', 'colour', 'color', 'hide'],\n\t\t\tdescription: 'Renames, recolours, hides or changes how a series is drawn (null colour / type resets it).',\n\t\t\tparams: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\tseries: { type: 'string', description: 'Series id or name.' },\n\t\t\t\t\tname: { type: 'string' },\n\t\t\t\t\tcolor: { type: ['string', 'null'] },\n\t\t\t\t\ttype: { type: ['string', 'null'], enum: [...CHART_SERIES_TYPES, null] },\n\t\t\t\t\thidden: { type: 'boolean' }\n\t\t\t\t},\n\t\t\t\trequired: ['series'],\n\t\t\t\tadditionalProperties: false\n\t\t\t},\n\t\t\trun: (_ctx: unknown, params: { series: string; name?: string; color?: string | null; type?: any; hidden?: boolean }) => {\n\t\t\t\tconst { series, ...patch } = params;\n\t\t\t\tconst id = resolveSeries(series).id;\n\t\t\t\tcheck(controller.updateSeries(id, patch));\n\t\t\t\treturn { series: controller.getSeries(id) };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}removeSeries`,\n\t\t\tlabel: 'Delete Series',\n\t\t\tkeywords: ['chart', 'series', 'remove'],\n\t\t\tdescription: 'Deletes a series by id or name.',\n\t\t\tparams: { type: 'object', properties: { series: { type: 'string' } }, required: ['series'], additionalProperties: false },\n\t\t\trun: (_ctx: unknown, params: { series: string }) => {\n\t\t\t\tcheck(controller.removeSeries(resolveSeries(params.series).id));\n\t\t\t\treturn { series: seriesIds() };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}addCategory`,\n\t\t\tlabel: 'Add Category',\n\t\t\tkeywords: ['chart', 'category', 'row', 'label'],\n\t\t\tdescription: 'Inserts a category (gaps in every series) at `at` (default: the end).',\n\t\t\tparams: { type: 'object', properties: { label: { type: 'string' }, at: { type: 'integer', minimum: 0 } }, additionalProperties: false },\n\t\t\trun: (_ctx: unknown, params: { label?: string; at?: number } = {}) => controller.addCategory(params?.label, { at: params?.at })\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}removeCategory`,\n\t\t\tlabel: 'Delete Category',\n\t\t\tkeywords: ['chart', 'category', 'row', 'remove'],\n\t\t\tdescription: 'Deletes a category (and its values) by index or label.',\n\t\t\tparams: { type: 'object', properties: { category: { type: ['string', 'integer'] } }, required: ['category'], additionalProperties: false },\n\t\t\trun: (_ctx: unknown, params: { category: string | number }) => {\n\t\t\t\tcheck(controller.removeCategory(resolveCategory(params.category)));\n\t\t\t\treturn { categories: controller.getSpec().categories };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}importCsv`,\n\t\t\tlabel: 'Import Chart Data from CSV…',\n\t\t\tkeywords: ['chart', 'csv', 'tsv', 'paste', 'import'],\n\t\t\tdescription: 'Replaces the data with CSV / TSV text: by default the first column holds categories and the first row series names.',\n\t\t\tparams: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\tcsv: { type: 'string' },\n\t\t\t\t\tseriesIn: { type: 'string', enum: ['columns', 'rows'] },\n\t\t\t\t\theader: { type: 'boolean' }\n\t\t\t\t},\n\t\t\t\trequired: ['csv'],\n\t\t\t\tadditionalProperties: false\n\t\t\t},\n\t\t\trun: (_ctx: unknown, params: { csv: string; seriesIn?: 'columns' | 'rows'; header?: boolean }) => {\n\t\t\t\tconst result = controller.importCsv(params.csv, { seriesIn: params.seriesIn, header: params.header });\n\t\t\t\tcheck(result);\n\t\t\t\treturn { table: chartDataToTable(controller.getSpec()), issues: result.issues ?? [] };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}exportSvg`,\n\t\t\tlabel: 'Export Chart as SVG',\n\t\t\treadOnly: true,\n\t\t\tkeywords: ['chart', 'svg', 'export', 'image'],\n\t\t\tdescription: 'Returns the chart drawn as a standalone SVG string.',\n\t\t\tparams: { type: 'object', properties: { width: { type: 'number', minimum: 50 }, height: { type: 'number', minimum: 50 } }, additionalProperties: false },\n\t\t\trun: (_ctx: unknown, params: { width?: number; height?: number } = {}) => ({\n\t\t\t\tsvg: chartToSvg(controller.getSpec() as any, { width: params?.width ?? 640, height: params?.height ?? 400 })\n\t\t\t})\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}undo`,\n\t\t\tlabel: 'Undo Chart Edit',\n\t\t\tkeywords: ['chart', 'undo'],\n\t\t\tenabled: () => controller.getState().canUndo || 'Nothing to undo',\n\t\t\trun: () => ({ undone: controller.undo() })\n\t\t},\n\t\t{\n\t\t\t...base,\n\t\t\tid: `${prefix}redo`,\n\t\t\tlabel: 'Redo Chart Edit',\n\t\t\tkeywords: ['chart', 'redo'],\n\t\t\tenabled: () => controller.getState().canRedo || 'Nothing to redo',\n\t\t\trun: () => ({ redone: controller.redo() })\n\t\t}\n\t];\n}\n","import type { ChartController } from './controller.js';\nimport { chartValueAtPoint, snapChartValue } from './layout.js';\nimport { isCartesianChart } from './spec.js';\nimport type { ChartScene, ChartSelection } from './types.js';\n\n/** Scene coordinates of a pointer, given the rendered element's box (the scene is scaled to fit it). */\nexport function chartClientToScene(scene: Pick<ChartScene, 'width' | 'height'>, box: { left: number; top: number; width: number; height: number }, clientX: number, clientY: number): { x: number; y: number } {\n\tconst sx = box.width ? scene.width / box.width : 1;\n\tconst sy = box.height ? scene.height / box.height : 1;\n\treturn { x: (clientX - box.left) * sx, y: (clientY - box.top) * sy };\n}\n\n/** Whether a point can be dragged to a new value in this scene (cartesian, not percent-stacked, not hidden). */\nexport function canDragChartPoint(controller: ChartController, scene: ChartScene, target: ChartSelection | undefined): target is Extract<ChartSelection, { kind: 'point' }> {\n\tif (target?.kind !== 'point' || !scene.valueScale || scene.percent) return false;\n\tconst spec = controller.getSpec();\n\tif (!isCartesianChart(spec.type)) return false;\n\tconst series = controller.getSeries(target.seriesId);\n\treturn !!series && !series.hidden && series.values[target.index] !== null;\n}\n\nexport interface ChartPointDrag {\n\t/** Moves the value with the pointer (scene coordinates). */\n\tmove(point: { x: number; y: number }): void;\n\t/** Ends the drag (one undo step for the whole drag). */\n\tend(): void;\n}\n\n/**\n * Starts dragging a bar or point: the value follows the pointer along the value axis,\n * snapped to a tenth of the tick step (`step` overrides), and the whole drag is one undo\n * step. Works for stacked bars too (the drag changes the segment by the distance moved).\n * Returns `null` when the target cannot be dragged.\n */\nexport function startChartPointDrag(controller: ChartController, scene: ChartScene, target: ChartSelection | undefined, start: { x: number; y: number }, options: { step?: number } = {}): ChartPointDrag | null {\n\tif (!canDragChartPoint(controller, scene, target)) return null;\n\tconst { seriesId, index } = target;\n\tconst startValue = controller.getSeries(seriesId)!.values[index] ?? 0;\n\tconst startAt = chartValueAtPoint(scene, start);\n\tif (startAt === undefined) return null;\n\tcontroller.beginGesture(`drag:${seriesId}:${index}`);\n\tlet ended = false;\n\treturn {\n\t\tmove(point) {\n\t\t\tif (ended) return;\n\t\t\tconst at = chartValueAtPoint(scene, point);\n\t\t\tif (at === undefined) return;\n\t\t\tcontroller.setValue(seriesId, index, snapChartValue(scene, startValue + (at - startAt), options.step), { label: `Drag ${controller.getSeries(seriesId)?.name ?? 'value'}` });\n\t\t},\n\t\tend() {\n\t\t\tif (ended) return;\n\t\t\tended = true;\n\t\t\tcontroller.endGesture();\n\t\t}\n\t};\n}\n\nexport interface ChartKeyInput {\n\tkey: string;\n\tshiftKey?: boolean;\n\taltKey?: boolean;\n\tmetaKey?: boolean;\n\tctrlKey?: boolean;\n}\n\n/**\n * Keyboard editing on a focused chart: arrows move a point selection between categories\n * (← →) and change its value (↑ ↓, a tenth of the tick step; Shift: a whole step), Delete /\n * Backspace deletes the selection, Escape clears it. Returns `true` when the key was used\n * (call `preventDefault`).\n */\nexport function handleChartKey(controller: ChartController, scene: ChartScene | null, event: ChartKeyInput): boolean {\n\tif (event.metaKey || event.ctrlKey || event.altKey) return false;\n\tconst { selection, spec } = controller.getState();\n\tswitch (event.key) {\n\t\tcase 'Escape':\n\t\t\tif (!selection) return false;\n\t\t\tcontroller.select(null);\n\t\t\treturn true;\n\t\tcase 'Delete':\n\t\tcase 'Backspace':\n\t\t\tif (!selection || selection.kind === 'chart') return false;\n\t\t\tcontroller.deleteSelection();\n\t\t\treturn true;\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight': {\n\t\t\tif (selection?.kind !== 'point' && selection?.kind !== 'category') return false;\n\t\t\tconst n = spec.categories.length;\n\t\t\tconst index = Math.max(0, Math.min(n - 1, selection.index + (event.key === 'ArrowRight' ? 1 : -1)));\n\t\t\tcontroller.select({ ...selection, index });\n\t\t\treturn true;\n\t\t}\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown': {\n\t\t\tif (selection?.kind !== 'point' || scene?.percent) return false;\n\t\t\tconst ticks = scene?.valueScale?.ticks ?? [];\n\t\t\tconst step = ticks.length > 1 ? ticks[1] - ticks[0] : 1;\n\t\t\tconst delta = (event.shiftKey ? step : step / 10) * (event.key === 'ArrowUp' ? 1 : -1);\n\t\t\tcontroller.nudgeValue(selection.seriesId, selection.index, delta);\n\t\t\treturn true;\n\t\t}\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/** A short description of the selection for an inspector heading or a screen reader. */\nexport function describeChartSelection(controller: ChartController, selection: ChartSelection | null = controller.getState().selection): string {\n\tif (!selection) return 'Nothing selected';\n\tconst spec = controller.getSpec();\n\tswitch (selection.kind) {\n\t\tcase 'chart':\n\t\t\treturn 'Chart';\n\t\tcase 'title':\n\t\t\treturn 'Title';\n\t\tcase 'subtitle':\n\t\t\treturn 'Subtitle';\n\t\tcase 'legend':\n\t\t\treturn 'Legend';\n\t\tcase 'axis':\n\t\t\treturn selection.axis === 'x' ? 'Category axis' : 'Value axis';\n\t\tcase 'series':\n\t\t\treturn `Series \"${controller.getSeries(selection.seriesId)?.name ?? selection.seriesId}\"`;\n\t\tcase 'category':\n\t\t\treturn `Category \"${spec.categories[selection.index] ?? selection.index}\"`;\n\t\tcase 'point': {\n\t\t\tconst series = controller.getSeries(selection.seriesId);\n\t\t\tconst value = series?.values[selection.index];\n\t\t\treturn `${series?.name ?? selection.seriesId} · ${spec.categories[selection.index] ?? selection.index}: ${value ?? 'blank'}`;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;AAiBO,IAAM,cAAoC,CAAC,OAAO,QAAQ,QAAQ,WAAW,OAAO,OAAO;AAC3F,IAAM,qBAAiD,CAAC,OAAO,QAAQ,QAAQ,SAAS;AACxF,IAAM,kBAA4C,CAAC,QAAQ,WAAW,SAAS;AAC/E,IAAM,eAAsC,CAAC,UAAU,UAAU,MAAM;AACvE,IAAM,qBAAkD,CAAC,YAAY,YAAY;AACjF,IAAM,yBAAyD,CAAC,OAAO,UAAU,QAAQ,OAAO;AAChG,IAAM,sBAA0E,CAAC,UAAU,WAAW,YAAY,SAAS;AAG3H,IAAM,oBAAyD;AAAA,EACrE,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,KAAK;AAAA,EACL,OAAO;AACR;AAGO,IAAM,wBAA2C,CAAC,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,SAAS;AAE9J,IAAM,sBAAkC;AAAA,EAC9C,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,WAAW;AAAA,EACX,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,WAAW;AACZ;AAOO,IAAM,2BAAuC;AAAA,EACnD,GAAG;AAAA,EACH,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,WAAW;AAAA,EACX,MAAM;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,CAAC,UAAW,QAAO;AACvB,QAAM,OAAO,WAAW,QAAQ;AAChC,UAAQ,UAAU,MAAM;AAAA,IACvB,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO,UAAU,SAAS,MAAM,kBAAkB;AAAA,IACnD,KAAK;AACJ,aAAO,WAAW,WAAW,UAAU,UAAU,QAAQ,GAAG,QAAQ,UAAU,QAAQ;AAAA,IACvF,KAAK;AACJ,aAAO,aAAa,KAAK,WAAW,UAAU,KAAK,KAAK,UAAU,KAAK;AAAA,IACxE,KAAK,SAAS;AACb,YAAM,SAAS,WAAW,UAAU,UAAU,QAAQ;AACtD,YAAM,QAAQ,QAAQ,OAAO,UAAU,KAAK;AAC5C,aAAO,GAAG,QAAQ,QAAQ,UAAU,QAAQ,SAAM,KAAK,WAAW,UAAU,KAAK,KAAK,UAAU,KAAK,KAAK,SAAS,OAAO;AAAA,IAC3H;AAAA,EACD;AACD;","names":["text","width","text","band","text","text","fail"]}
|
|
@@ -14,10 +14,53 @@ function matchesType(value, type) {
|
|
|
14
14
|
return actual === type;
|
|
15
15
|
}
|
|
16
16
|
var isEqual = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
|
|
17
|
-
function
|
|
17
|
+
function resolveRef(ref, root) {
|
|
18
|
+
if (ref === "#") return root;
|
|
19
|
+
if (!ref.startsWith("#/")) return void 0;
|
|
20
|
+
let node = root;
|
|
21
|
+
for (const raw of ref.slice(2).split("/")) {
|
|
22
|
+
const key = decodeURIComponent(raw).replace(/~1/g, "/").replace(/~0/g, "~");
|
|
23
|
+
if (!node || typeof node !== "object") return void 0;
|
|
24
|
+
node = node[key];
|
|
25
|
+
}
|
|
26
|
+
return node && typeof node === "object" ? node : void 0;
|
|
27
|
+
}
|
|
28
|
+
var MAX_REF_DEPTH = 32;
|
|
29
|
+
function validateJsonSchema(value, schema, path = "", root = schema, refDepth = 0) {
|
|
18
30
|
if (!schema || typeof schema !== "object") return [];
|
|
19
31
|
const errors = [];
|
|
20
32
|
const at = path || "/";
|
|
33
|
+
const recurse = (child, childSchema, childPath) => validateJsonSchema(child, childSchema, childPath, root, refDepth);
|
|
34
|
+
if (typeof schema.$ref === "string") {
|
|
35
|
+
const target = root ? resolveRef(schema.$ref, root) : void 0;
|
|
36
|
+
if (!target) {
|
|
37
|
+
errors.push({ path: at, message: `Unresolvable schema reference ${schema.$ref}.` });
|
|
38
|
+
} else if (refDepth >= MAX_REF_DEPTH) {
|
|
39
|
+
errors.push({ path: at, message: `Schema reference ${schema.$ref} is nested too deeply.` });
|
|
40
|
+
} else {
|
|
41
|
+
errors.push(...validateJsonSchema(value, target, path, root, refDepth + 1));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (schema.allOf) {
|
|
45
|
+
for (const branch of schema.allOf) errors.push(...recurse(value, branch, path));
|
|
46
|
+
}
|
|
47
|
+
if (schema.anyOf || schema.oneOf) {
|
|
48
|
+
const branches = _nullishCoalesce(schema.anyOf, () => ( schema.oneOf));
|
|
49
|
+
const results = branches.map((branch) => recurse(value, branch, path));
|
|
50
|
+
const matching = results.filter((r) => r.length === 0).length;
|
|
51
|
+
if (matching === 0 && results.length > 0) {
|
|
52
|
+
const closest = results.reduce((best, r) => r.length < best.length ? r : best);
|
|
53
|
+
errors.push(
|
|
54
|
+
{ path: at, message: `Does not match any allowed shape (${branches.length} options); closest match failed with:` },
|
|
55
|
+
...closest
|
|
56
|
+
);
|
|
57
|
+
} else if (schema.oneOf && !schema.anyOf && matching > 1) {
|
|
58
|
+
errors.push({ path: at, message: `Matches ${matching} shapes; exactly one is allowed.` });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (schema.not && recurse(value, schema.not, path).length === 0) {
|
|
62
|
+
errors.push({ path: at, message: "Matches a disallowed shape." });
|
|
63
|
+
}
|
|
21
64
|
if (schema.type !== void 0) {
|
|
22
65
|
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
23
66
|
if (!types.some((t) => matchesType(value, t))) {
|
|
@@ -59,6 +102,18 @@ function validateJsonSchema(value, schema, path = "") {
|
|
|
59
102
|
if (schema.maximum !== void 0 && value > schema.maximum) {
|
|
60
103
|
errors.push({ path: at, message: `Must be <= ${schema.maximum}.` });
|
|
61
104
|
}
|
|
105
|
+
if (typeof schema.exclusiveMinimum === "number" && value <= schema.exclusiveMinimum) {
|
|
106
|
+
errors.push({ path: at, message: `Must be > ${schema.exclusiveMinimum}.` });
|
|
107
|
+
}
|
|
108
|
+
if (typeof schema.exclusiveMaximum === "number" && value >= schema.exclusiveMaximum) {
|
|
109
|
+
errors.push({ path: at, message: `Must be < ${schema.exclusiveMaximum}.` });
|
|
110
|
+
}
|
|
111
|
+
if (schema.multipleOf !== void 0 && schema.multipleOf > 0) {
|
|
112
|
+
const quotient = value / schema.multipleOf;
|
|
113
|
+
if (Math.abs(quotient - Math.round(quotient)) > 1e-9) {
|
|
114
|
+
errors.push({ path: at, message: `Must be a multiple of ${schema.multipleOf}.` });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
62
117
|
}
|
|
63
118
|
if (Array.isArray(value)) {
|
|
64
119
|
if (schema.minItems !== void 0 && value.length < schema.minItems) {
|
|
@@ -67,9 +122,17 @@ function validateJsonSchema(value, schema, path = "") {
|
|
|
67
122
|
if (schema.maxItems !== void 0 && value.length > schema.maxItems) {
|
|
68
123
|
errors.push({ path: at, message: `Must have at most ${schema.maxItems} items.` });
|
|
69
124
|
}
|
|
125
|
+
if (schema.uniqueItems) {
|
|
126
|
+
const seen = /* @__PURE__ */ new Set();
|
|
127
|
+
value.forEach((item, index) => {
|
|
128
|
+
const key = JSON.stringify(item);
|
|
129
|
+
if (seen.has(key)) errors.push({ path: `${path}/${index}`, message: "Duplicate item; items must be unique." });
|
|
130
|
+
seen.add(key);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
70
133
|
if (schema.items) {
|
|
71
134
|
value.forEach((item, index) => {
|
|
72
|
-
errors.push(...
|
|
135
|
+
errors.push(...recurse(item, schema.items, `${path}/${index}`));
|
|
73
136
|
});
|
|
74
137
|
}
|
|
75
138
|
}
|
|
@@ -84,11 +147,15 @@ function validateJsonSchema(value, schema, path = "") {
|
|
|
84
147
|
for (const [key, child] of Object.entries(obj)) {
|
|
85
148
|
if (child === void 0) continue;
|
|
86
149
|
if (key in properties) {
|
|
87
|
-
errors.push(...
|
|
150
|
+
errors.push(...recurse(child, properties[key], `${path}/${key}`));
|
|
88
151
|
} else if (schema.additionalProperties === false) {
|
|
89
|
-
|
|
152
|
+
const known = Object.keys(properties);
|
|
153
|
+
errors.push({
|
|
154
|
+
path: `${path}/${key}`,
|
|
155
|
+
message: `Unknown property "${key}".${known.length ? ` Allowed: ${known.join(", ")}.` : ""}`
|
|
156
|
+
});
|
|
90
157
|
} else if (typeof schema.additionalProperties === "object") {
|
|
91
|
-
errors.push(...
|
|
158
|
+
errors.push(...recurse(child, schema.additionalProperties, `${path}/${key}`));
|
|
92
159
|
}
|
|
93
160
|
}
|
|
94
161
|
}
|
|
@@ -98,4 +165,4 @@ function validateJsonSchema(value, schema, path = "") {
|
|
|
98
165
|
|
|
99
166
|
|
|
100
167
|
exports.validateJsonSchema = validateJsonSchema;
|
|
101
|
-
//# sourceMappingURL=chunk-
|
|
168
|
+
//# sourceMappingURL=chunk-EFDCLENW.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-EFDCLENW.cjs","../src/tools/schema.ts"],"names":[],"mappings":"AAAA;AC6CA,SAAS,MAAA,CAAO,KAAA,EAA8C;AAC7D,EAAA,GAAA,CAAI,MAAA,IAAU,IAAA,EAAM,OAAO,MAAA;AAC3B,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,OAAA;AACjC,EAAA,GAAA,CAAI,OAA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CAAO,QAAQ,CAAA,OAAA,EAAU,CAAC,CAAA;AAAA,IAClF;AACA,IAAA,GAAA,CAAI,MAAA,CAAO,SAAA,IAAa,KAAA,EAAA,GAAa,KAAA,CAAM,OAAA,EAAS,MAAA,CAAO,QAAA,EAAU;AACpE,MAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,EAAA,EAAI,OAAA,EAAS,CAAA,kBAAA,EAAqB,MAAA,CAAO,QAAQ,CAAA,OAAA,EAAU,CAAC,CAAA;AAAA,IACjF;AACA,IAAA,GAAA,CAAI,MAAA,CAAO,WAAA,EAAa;AACvB,MAAA,MAAM,KAAA,kBAAO,IAAI,GAAA,CAAY,CAAA;AAC7B,MAAA,KAAA,CAAM,OAAA,CAAQ,CAAC,IAAA,EAAM,KAAA,EAAA,GAAU;AAC9B,QAAA,MAAM,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA;AAC/B,QAAA,GAAA,CAAI,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA,EAAG,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,CAAA,EAAA;AAC3B,QAAA;AACZ,MAAA;AACF,IAAA;AACkB,IAAA;AACc,MAAA;AACM,QAAA;AACpC,MAAA;AACF,IAAA;AACD,EAAA;AAEgC,EAAA;AACnB,IAAA;AAC6B,IAAA;AACZ,MAAA;AACW,QAAA;AACvC,MAAA;AACD,IAAA;AACyC,IAAA;AACC,IAAA;AAChB,MAAA;AACF,MAAA;AACQ,QAAA;AACb,MAAA;AACmB,QAAA;AACxB,QAAA;AACS,UAAA;AACkB,UAAA;AACtC,QAAA;AACuB,MAAA;AACa,QAAA;AACtC,MAAA;AACD,IAAA;AACD,EAAA;AAEO,EAAA;AACR;ADjFgD;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-EFDCLENW.cjs","sourcesContent":[null,"/**\n * JSON-Schema-lite: the subset of JSON Schema used by MCP tool `inputSchema`s,\n * plus a small validator for tool-call arguments. Unknown keywords are ignored.\n */\nexport type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';\n\nexport interface JsonSchema {\n\ttype?: JsonSchemaType | readonly JsonSchemaType[];\n\tdescription?: string;\n\ttitle?: string;\n\tenum?: readonly unknown[];\n\tconst?: unknown;\n\tdefault?: unknown;\n\tproperties?: { readonly [key: string]: JsonSchema };\n\trequired?: readonly string[];\n\tadditionalProperties?: boolean | JsonSchema;\n\titems?: JsonSchema;\n\tminItems?: number;\n\tmaxItems?: number;\n\tminimum?: number;\n\tmaximum?: number;\n\texclusiveMinimum?: number;\n\texclusiveMaximum?: number;\n\tmultipleOf?: number;\n\tuniqueItems?: boolean;\n\tanyOf?: readonly JsonSchema[];\n\toneOf?: readonly JsonSchema[];\n\tallOf?: readonly JsonSchema[];\n\tnot?: JsonSchema;\n\t/** Local reference only: `#`, `#/$defs/<name>` or `#/definitions/<name>`. */\n\t$ref?: string;\n\t$defs?: { readonly [key: string]: JsonSchema };\n\tdefinitions?: { readonly [key: string]: JsonSchema };\n\tminLength?: number;\n\tmaxLength?: number;\n\tpattern?: string;\n\t[keyword: string]: unknown;\n}\n\nexport interface SchemaValidationError {\n\t/** JSON-pointer-like path to the offending value, e.g. `/node/id` (`\"\"` is the root). */\n\tpath: string;\n\tmessage: string;\n}\n\nfunction typeOf(value: unknown): JsonSchemaType | 'undefined' {\n\tif (value === null) return 'null';\n\tif (Array.isArray(value)) return 'array';\n\tif (typeof value === 'number') return Number.isInteger(value) ? 'integer' : 'number';\n\tif (typeof value === 'string' || typeof value === 'boolean' || typeof value === 'object') {\n\t\treturn typeof value as JsonSchemaType;\n\t}\n\treturn 'undefined';\n}\n\nfunction matchesType(value: unknown, type: JsonSchemaType): boolean {\n\tconst actual = typeOf(value);\n\tif (type === 'number') return actual === 'number' || actual === 'integer';\n\treturn actual === type;\n}\n\nconst isEqual = (a: unknown, b: unknown) => a === b || JSON.stringify(a) === JSON.stringify(b);\n\n/** Resolves a local `$ref` (`#`, `#/$defs/a`, `#/definitions/a/properties/b`, ...) against `root`. */\nfunction resolveRef(ref: string, root: JsonSchema): JsonSchema | undefined {\n\tif (ref === '#') return root;\n\tif (!ref.startsWith('#/')) return undefined;\n\tlet node: unknown = root;\n\tfor (const raw of ref.slice(2).split('/')) {\n\t\tconst key = decodeURIComponent(raw).replace(/~1/g, '/').replace(/~0/g, '~');\n\t\tif (!node || typeof node !== 'object') return undefined;\n\t\tnode = (node as Record<string, unknown>)[key];\n\t}\n\treturn node && typeof node === 'object' ? (node as JsonSchema) : undefined;\n}\n\n/** Most `$ref` hops followed before a reference cycle is reported. */\nconst MAX_REF_DEPTH = 32;\n\n/**\n * Validates `value` against `schema` and returns every error found (an empty\n * array means valid). Supports `type` (incl. arrays of types), `enum`, `const`,\n * `properties`, `required`, `additionalProperties`, `items`, `minItems`,\n * `maxItems`, `uniqueItems`, `minimum`, `maximum`, `exclusiveMinimum`,\n * `exclusiveMaximum`, `multipleOf`, `minLength`, `maxLength`, `pattern`,\n * `anyOf`, `oneOf`, `allOf`, `not` and local `$ref`s (`#/$defs/...`).\n * Other keywords (`format`, `if`/`then`, `patternProperties`, remote refs...)\n * are ignored.\n *\n * When no `anyOf` / `oneOf` branch matches, the errors of the closest branch\n * (the one with the fewest errors) are reported, so a caller sees what to fix\n * rather than only \"no branch matched\".\n */\nexport function validateJsonSchema(\n\tvalue: unknown,\n\tschema: JsonSchema | undefined,\n\tpath = '',\n\troot: JsonSchema | undefined = schema,\n\trefDepth = 0\n): SchemaValidationError[] {\n\tif (!schema || typeof schema !== 'object') return [];\n\tconst errors: SchemaValidationError[] = [];\n\tconst at = path || '/';\n\tconst recurse = (child: unknown, childSchema: JsonSchema | undefined, childPath: string) =>\n\t\tvalidateJsonSchema(child, childSchema, childPath, root, refDepth);\n\n\tif (typeof schema.$ref === 'string') {\n\t\tconst target = root ? resolveRef(schema.$ref, root) : undefined;\n\t\tif (!target) {\n\t\t\terrors.push({ path: at, message: `Unresolvable schema reference ${schema.$ref}.` });\n\t\t} else if (refDepth >= MAX_REF_DEPTH) {\n\t\t\terrors.push({ path: at, message: `Schema reference ${schema.$ref} is nested too deeply.` });\n\t\t} else {\n\t\t\terrors.push(...validateJsonSchema(value, target, path, root, refDepth + 1));\n\t\t}\n\t\t// Sibling keywords still apply (2019-09+ semantics).\n\t}\n\n\tif (schema.allOf) {\n\t\tfor (const branch of schema.allOf) errors.push(...recurse(value, branch, path));\n\t}\n\tif (schema.anyOf || schema.oneOf) {\n\t\tconst branches = (schema.anyOf ?? schema.oneOf)!;\n\t\tconst results = branches.map((branch) => recurse(value, branch, path));\n\t\tconst matching = results.filter((r) => r.length === 0).length;\n\t\tif (matching === 0 && results.length > 0) {\n\t\t\tconst closest = results.reduce((best, r) => (r.length < best.length ? r : best));\n\t\t\terrors.push(\n\t\t\t\t{ path: at, message: `Does not match any allowed shape (${branches.length} options); closest match failed with:` },\n\t\t\t\t...closest\n\t\t\t);\n\t\t} else if (schema.oneOf && !schema.anyOf && matching > 1) {\n\t\t\terrors.push({ path: at, message: `Matches ${matching} shapes; exactly one is allowed.` });\n\t\t}\n\t}\n\tif (schema.not && recurse(value, schema.not, path).length === 0) {\n\t\terrors.push({ path: at, message: 'Matches a disallowed shape.' });\n\t}\n\n\tif (schema.type !== undefined) {\n\t\tconst types = (Array.isArray(schema.type) ? schema.type : [schema.type]) as JsonSchemaType[];\n\t\tif (!types.some((t) => matchesType(value, t))) {\n\t\t\terrors.push({ path: at, message: `Expected ${types.join(' | ')}, got ${typeOf(value)}.` });\n\t\t\treturn errors;\n\t\t}\n\t}\n\tif (schema.const !== undefined && !isEqual(value, schema.const)) {\n\t\terrors.push({ path: at, message: `Expected ${JSON.stringify(schema.const)}.` });\n\t}\n\tif (schema.enum && !schema.enum.some((option) => isEqual(value, option))) {\n\t\terrors.push({\n\t\t\tpath: at,\n\t\t\tmessage: `Expected one of ${schema.enum.map((o) => JSON.stringify(o)).join(', ')}, got ${JSON.stringify(value)}.`\n\t\t});\n\t}\n\n\tif (typeof value === 'string') {\n\t\tif (schema.minLength !== undefined && value.length < schema.minLength) {\n\t\t\terrors.push({ path: at, message: `Must be at least ${schema.minLength} characters.` });\n\t\t}\n\t\tif (schema.maxLength !== undefined && value.length > schema.maxLength) {\n\t\t\terrors.push({ path: at, message: `Must be at most ${schema.maxLength} characters.` });\n\t\t}\n\t\tif (schema.pattern !== undefined) {\n\t\t\tlet regex: RegExp | null = null;\n\t\t\ttry {\n\t\t\t\tregex = new RegExp(schema.pattern, 'u');\n\t\t\t} catch {\n\t\t\t\t// An invalid pattern in the schema is not the caller's fault.\n\t\t\t}\n\t\t\tif (regex && !regex.test(value)) {\n\t\t\t\terrors.push({ path: at, message: `Must match pattern ${schema.pattern}.` });\n\t\t\t}\n\t\t}\n\t}\n\n\tif (typeof value === 'number') {\n\t\tif (schema.minimum !== undefined && value < schema.minimum) {\n\t\t\terrors.push({ path: at, message: `Must be >= ${schema.minimum}.` });\n\t\t}\n\t\tif (schema.maximum !== undefined && value > schema.maximum) {\n\t\t\terrors.push({ path: at, message: `Must be <= ${schema.maximum}.` });\n\t\t}\n\t\tif (typeof schema.exclusiveMinimum === 'number' && value <= schema.exclusiveMinimum) {\n\t\t\terrors.push({ path: at, message: `Must be > ${schema.exclusiveMinimum}.` });\n\t\t}\n\t\tif (typeof schema.exclusiveMaximum === 'number' && value >= schema.exclusiveMaximum) {\n\t\t\terrors.push({ path: at, message: `Must be < ${schema.exclusiveMaximum}.` });\n\t\t}\n\t\tif (schema.multipleOf !== undefined && schema.multipleOf > 0) {\n\t\t\tconst quotient = value / schema.multipleOf;\n\t\t\tif (Math.abs(quotient - Math.round(quotient)) > 1e-9) {\n\t\t\t\terrors.push({ path: at, message: `Must be a multiple of ${schema.multipleOf}.` });\n\t\t\t}\n\t\t}\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tif (schema.minItems !== undefined && value.length < schema.minItems) {\n\t\t\terrors.push({ path: at, message: `Must have at least ${schema.minItems} items.` });\n\t\t}\n\t\tif (schema.maxItems !== undefined && value.length > schema.maxItems) {\n\t\t\terrors.push({ path: at, message: `Must have at most ${schema.maxItems} items.` });\n\t\t}\n\t\tif (schema.uniqueItems) {\n\t\t\tconst seen = new Set<string>();\n\t\t\tvalue.forEach((item, index) => {\n\t\t\t\tconst key = JSON.stringify(item);\n\t\t\t\tif (seen.has(key)) errors.push({ path: `${path}/${index}`, message: 'Duplicate item; items must be unique.' });\n\t\t\t\tseen.add(key);\n\t\t\t});\n\t\t}\n\t\tif (schema.items) {\n\t\t\tvalue.forEach((item, index) => {\n\t\t\t\terrors.push(...recurse(item, schema.items, `${path}/${index}`));\n\t\t\t});\n\t\t}\n\t}\n\n\tif (typeOf(value) === 'object') {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tfor (const key of schema.required ?? []) {\n\t\t\tif (obj[key] === undefined) {\n\t\t\t\terrors.push({ path: `${path}/${key}`, message: `Missing required property \"${key}\".` });\n\t\t\t}\n\t\t}\n\t\tconst properties = schema.properties ?? {};\n\t\tfor (const [key, child] of Object.entries(obj)) {\n\t\t\tif (child === undefined) continue;\n\t\t\tif (key in properties) {\n\t\t\t\terrors.push(...recurse(child, properties[key], `${path}/${key}`));\n\t\t\t} else if (schema.additionalProperties === false) {\n\t\t\t\tconst known = Object.keys(properties);\n\t\t\t\terrors.push({\n\t\t\t\t\tpath: `${path}/${key}`,\n\t\t\t\t\tmessage: `Unknown property \"${key}\".${known.length ? ` Allowed: ${known.join(', ')}.` : ''}`\n\t\t\t\t});\n\t\t\t} else if (typeof schema.additionalProperties === 'object') {\n\t\t\t\terrors.push(...recurse(child, schema.additionalProperties, `${path}/${key}`));\n\t\t\t}\n\t\t}\n\t}\n\n\treturn errors;\n}\n"]}
|