@pixerate/editor 0.51.0 → 0.52.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/dist/chart/index.cjs +315 -7
- package/dist/chart/index.cjs.map +1 -1
- package/dist/chart/index.d.cts +107 -5
- package/dist/chart/index.d.ts +107 -5
- package/dist/chart/index.js +312 -4
- package/dist/chart/index.js.map +1 -1
- package/dist/{chunk-2Q46FKZK.cjs → chunk-2DEBI6KU.cjs} +23 -23
- package/dist/{chunk-2Q46FKZK.cjs.map → chunk-2DEBI6KU.cjs.map} +1 -1
- package/dist/{chunk-3JNRQVTS.cjs → chunk-3ZBAXET6.cjs} +323 -3
- package/dist/chunk-3ZBAXET6.cjs.map +1 -0
- package/dist/{chunk-T6XU4B54.js → chunk-5N6AQCVB.js} +6 -6
- package/dist/{chunk-MR2764X2.js → chunk-AGGUNWT6.js} +2 -322
- package/dist/chunk-AGGUNWT6.js.map +1 -0
- package/dist/{chunk-LNKZPIQD.cjs → chunk-M5Z77GFH.cjs} +21 -21
- package/dist/{chunk-LNKZPIQD.cjs.map → chunk-M5Z77GFH.cjs.map} +1 -1
- package/dist/{chunk-3CC7OPUQ.cjs → chunk-O6FO6VI3.cjs} +3 -323
- package/dist/chunk-O6FO6VI3.cjs.map +1 -0
- package/dist/{chunk-GJBIVWB2.js → chunk-UAW5FEMD.js} +322 -2
- package/dist/chunk-UAW5FEMD.js.map +1 -0
- package/dist/{chunk-DQPBQXKG.js → chunk-YMKPMXZ4.js} +6 -6
- package/dist/export/index.cjs +4 -4
- package/dist/export/index.js +3 -3
- package/dist/extensions/index.cjs +4 -4
- package/dist/extensions/index.js +3 -3
- package/dist/index.cjs +12 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -110
- package/dist/index.d.ts +3 -110
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/zip-4nG0YAH7.d.cts +110 -0
- package/dist/zip-4nG0YAH7.d.ts +110 -0
- package/package.json +1 -1
- package/dist/chunk-3CC7OPUQ.cjs.map +0 -1
- package/dist/chunk-3JNRQVTS.cjs.map +0 -1
- package/dist/chunk-GJBIVWB2.js.map +0 -1
- package/dist/chunk-MR2764X2.js.map +0 -1
- /package/dist/{chunk-T6XU4B54.js.map → chunk-5N6AQCVB.js.map} +0 -0
- /package/dist/{chunk-DQPBQXKG.js.map → chunk-YMKPMXZ4.js.map} +0 -0
package/dist/chart/index.js
CHANGED
|
@@ -14,8 +14,9 @@ import {
|
|
|
14
14
|
CHART_OOXML_RELATIONSHIP,
|
|
15
15
|
chartFormatToCode,
|
|
16
16
|
chartFromOoxml,
|
|
17
|
-
chartToOoxml
|
|
18
|
-
|
|
17
|
+
chartToOoxml,
|
|
18
|
+
readZip
|
|
19
|
+
} from "../chunk-UAW5FEMD.js";
|
|
19
20
|
import {
|
|
20
21
|
CHART_COLOR_SCHEMES,
|
|
21
22
|
CHART_DATE_STEPS,
|
|
@@ -135,9 +136,9 @@ function chartRasterSize(width, height, scale = 2, maxSize = CHART_RASTER_MAX_SI
|
|
|
135
136
|
const factor = Math.min(scale > 0 ? scale : 1, maxSize / Math.max(width, height));
|
|
136
137
|
return { width: Math.max(1, Math.round(width * factor)), height: Math.max(1, Math.round(height * factor)), scale: factor };
|
|
137
138
|
}
|
|
138
|
-
function closingParen(text,
|
|
139
|
+
function closingParen(text, open2) {
|
|
139
140
|
let depth = 0;
|
|
140
|
-
for (let i =
|
|
141
|
+
for (let i = open2; i < text.length; i++) {
|
|
141
142
|
if (text[i] === "(") depth++;
|
|
142
143
|
else if (text[i] === ")" && --depth === 0) return i + 1;
|
|
143
144
|
}
|
|
@@ -1803,6 +1804,306 @@ var ChartDirector = class {
|
|
|
1803
1804
|
}
|
|
1804
1805
|
}
|
|
1805
1806
|
};
|
|
1807
|
+
|
|
1808
|
+
// src/chart/office-files.ts
|
|
1809
|
+
var OfficeChartsError = class extends Error {
|
|
1810
|
+
constructor(message, options) {
|
|
1811
|
+
super(message, options);
|
|
1812
|
+
this.name = "OfficeChartsError";
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
var CHARTEX_NS = "http://schemas.microsoft.com/office/drawing/2014/chartex";
|
|
1816
|
+
var STRICT_CHART_NS = "http://purl.oclc.org/ooxml/drawingml/chart";
|
|
1817
|
+
var dirname = (path) => path.slice(0, path.lastIndexOf("/") + 1);
|
|
1818
|
+
function resolvePartPath(baseDir, target) {
|
|
1819
|
+
const out = [];
|
|
1820
|
+
for (const segment of (target.startsWith("/") ? target.slice(1) : baseDir + target).split("/")) {
|
|
1821
|
+
if (segment === "" || segment === ".") continue;
|
|
1822
|
+
if (segment === "..") out.pop();
|
|
1823
|
+
else out.push(segment);
|
|
1824
|
+
}
|
|
1825
|
+
return out.join("/");
|
|
1826
|
+
}
|
|
1827
|
+
var relsPathFor = (partPath) => `${dirname(partPath)}_rels/${partPath.slice(dirname(partPath).length)}.rels`;
|
|
1828
|
+
function elements(root, localName) {
|
|
1829
|
+
return Array.from(root.getElementsByTagNameNS("*", localName));
|
|
1830
|
+
}
|
|
1831
|
+
function relId(el, localName = "id") {
|
|
1832
|
+
for (const a of Array.from(el.attributes)) {
|
|
1833
|
+
if (a.localName === localName && (a.namespaceURI?.includes("relationships") || a.prefix === "r")) return a.value;
|
|
1834
|
+
}
|
|
1835
|
+
return void 0;
|
|
1836
|
+
}
|
|
1837
|
+
var firstChild = (el, localName) => el ? Array.from(el.children ?? el.childNodes).find((n) => n.nodeType === 1 && n.localName === localName) : void 0;
|
|
1838
|
+
async function readXml(r, path) {
|
|
1839
|
+
const entry = r.zip.get(path) ?? r.zip.entries.find((e) => e.name.toLowerCase() === path.toLowerCase());
|
|
1840
|
+
if (!entry) return null;
|
|
1841
|
+
const doc = new r.Parser().parseFromString(await r.zip.readText(entry), "application/xml");
|
|
1842
|
+
return doc.getElementsByTagName("parsererror").length ? null : doc;
|
|
1843
|
+
}
|
|
1844
|
+
async function readRels(r, partPath) {
|
|
1845
|
+
const rels = /* @__PURE__ */ new Map();
|
|
1846
|
+
const doc = await readXml(r, relsPathFor(partPath));
|
|
1847
|
+
if (!doc) return rels;
|
|
1848
|
+
for (const rel of elements(doc, "Relationship")) {
|
|
1849
|
+
const id = rel.getAttribute("Id");
|
|
1850
|
+
if (!id) continue;
|
|
1851
|
+
const target = rel.getAttribute("Target") ?? "";
|
|
1852
|
+
const external = rel.getAttribute("TargetMode")?.toLowerCase() === "external";
|
|
1853
|
+
rels.set(id, { type: rel.getAttribute("Type") ?? "", target: external ? target : resolvePartPath(dirname(partPath), target), external });
|
|
1854
|
+
}
|
|
1855
|
+
return rels;
|
|
1856
|
+
}
|
|
1857
|
+
var isChartRef = (el) => el.localName === "chart" && (el.namespaceURI === CHART_OOXML_NS || el.namespaceURI === STRICT_CHART_NS || el.namespaceURI === CHARTEX_NS);
|
|
1858
|
+
function frameName(ref) {
|
|
1859
|
+
for (let el = ref.parentElement; el; el = el.parentElement) {
|
|
1860
|
+
if (el.localName === "graphicFrame") {
|
|
1861
|
+
const nv = elements(el, "cNvPr")[0];
|
|
1862
|
+
return nv?.getAttribute("name") || void 0;
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
return void 0;
|
|
1866
|
+
}
|
|
1867
|
+
async function chartsInPart(r, root, rels, place) {
|
|
1868
|
+
for (const ref of elements(root, "chart")) {
|
|
1869
|
+
if (r.charts.length >= r.max) return;
|
|
1870
|
+
if (!isChartRef(ref)) continue;
|
|
1871
|
+
const rel = rels.get(relId(ref) ?? "");
|
|
1872
|
+
if (!rel || rel.external || r.seen.has(rel.target)) continue;
|
|
1873
|
+
const entry = r.zip.get(rel.target);
|
|
1874
|
+
if (!entry) continue;
|
|
1875
|
+
r.seen.add(rel.target);
|
|
1876
|
+
const read = chartFromOoxml(await r.zip.readText(entry), { DOMParser: r.Parser });
|
|
1877
|
+
const name = frameName(ref);
|
|
1878
|
+
r.charts.push({
|
|
1879
|
+
id: `chart-${r.charts.length + 1}`,
|
|
1880
|
+
path: rel.target,
|
|
1881
|
+
partKind: ref.namespaceURI === CHARTEX_NS ? "chartex" : "chart",
|
|
1882
|
+
...place(ref),
|
|
1883
|
+
...name ? { name } : {},
|
|
1884
|
+
title: read.spec.title,
|
|
1885
|
+
spec: read.spec,
|
|
1886
|
+
issues: read.issues.map((i) => i.message),
|
|
1887
|
+
unsupported: read.unsupported,
|
|
1888
|
+
lossless: read.lossless
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
function columnName(index) {
|
|
1893
|
+
let name = "";
|
|
1894
|
+
for (let n = index + 1; n > 0; n = Math.floor((n - 1) / 26)) name = String.fromCharCode(65 + (n - 1) % 26) + name;
|
|
1895
|
+
return name;
|
|
1896
|
+
}
|
|
1897
|
+
function anchorCell(marker) {
|
|
1898
|
+
const col = Number(firstChild(marker, "col")?.textContent);
|
|
1899
|
+
const row = Number(firstChild(marker, "row")?.textContent);
|
|
1900
|
+
return Number.isInteger(col) && Number.isInteger(row) && col >= 0 && row >= 0 ? `${columnName(col)}${row + 1}` : void 0;
|
|
1901
|
+
}
|
|
1902
|
+
function drawingPlace(ref) {
|
|
1903
|
+
for (let el = ref.parentElement; el; el = el.parentElement) {
|
|
1904
|
+
if (el.localName === "twoCellAnchor" || el.localName === "oneCellAnchor") {
|
|
1905
|
+
const anchor = anchorCell(firstChild(el, "from"));
|
|
1906
|
+
const to = el.localName === "twoCellAnchor" ? anchorCell(firstChild(el, "to")) : void 0;
|
|
1907
|
+
return { ...anchor ? { anchor } : {}, ...anchor && to ? { range: `${anchor}:${to}` } : {} };
|
|
1908
|
+
}
|
|
1909
|
+
if (el.localName === "absoluteAnchor") return {};
|
|
1910
|
+
}
|
|
1911
|
+
return {};
|
|
1912
|
+
}
|
|
1913
|
+
async function readMainPart(r) {
|
|
1914
|
+
const rootRels = await readRels(r, "");
|
|
1915
|
+
const main = [...rootRels.values()].find((rel) => /\/officeDocument$/.test(rel.type) && !rel.external);
|
|
1916
|
+
const doc = main ? await readXml(r, main.target) : null;
|
|
1917
|
+
if (!main || !doc) throw new OfficeChartsError("This is not an Office file: _rels/.rels names no main part (expected an .xlsx, .pptx or .docx file).");
|
|
1918
|
+
return { path: main.target, doc };
|
|
1919
|
+
}
|
|
1920
|
+
async function readXlsx(r, main) {
|
|
1921
|
+
const rels = await readRels(r, main.path);
|
|
1922
|
+
for (const sheet of elements(main.doc, "sheet")) {
|
|
1923
|
+
const rel = rels.get(relId(sheet) ?? "");
|
|
1924
|
+
if (!rel || rel.external) continue;
|
|
1925
|
+
const doc = await readXml(r, rel.target);
|
|
1926
|
+
if (!doc) continue;
|
|
1927
|
+
const sheetName = sheet.getAttribute("name") ?? rel.target;
|
|
1928
|
+
const sheetRels = await readRels(r, rel.target);
|
|
1929
|
+
for (const drawingRef of elements(doc, "drawing")) {
|
|
1930
|
+
const drawingRel = sheetRels.get(relId(drawingRef) ?? "");
|
|
1931
|
+
if (!drawingRel || drawingRel.external) continue;
|
|
1932
|
+
const drawing = await readXml(r, drawingRel.target);
|
|
1933
|
+
if (!drawing) continue;
|
|
1934
|
+
const drawingRels = await readRels(r, drawingRel.target);
|
|
1935
|
+
await chartsInPart(r, drawing, drawingRels, (ref) => ({ sheet: sheetName, ...drawingPlace(ref) }));
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
async function readPptx(r, main) {
|
|
1940
|
+
const rels = await readRels(r, main.path);
|
|
1941
|
+
const slides = elements(main.doc, "sldId");
|
|
1942
|
+
for (let i = 0; i < slides.length; i++) {
|
|
1943
|
+
const rel = rels.get(relId(slides[i]) ?? "");
|
|
1944
|
+
if (!rel || rel.external) continue;
|
|
1945
|
+
const doc = await readXml(r, rel.target);
|
|
1946
|
+
if (!doc) continue;
|
|
1947
|
+
await chartsInPart(r, doc, await readRels(r, rel.target), () => ({ slide: i + 1 }));
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
async function readDocx(r, main) {
|
|
1951
|
+
await chartsInPart(r, main.doc, await readRels(r, main.path), () => ({}));
|
|
1952
|
+
}
|
|
1953
|
+
async function open(bytes, options) {
|
|
1954
|
+
const Parser = options.DOMParser ?? globalThis.DOMParser;
|
|
1955
|
+
if (!Parser) throw new OfficeChartsError("Reading Office files needs a DOMParser. In Node, pass one (e.g. from jsdom or @xmldom/xmldom) as { DOMParser }.");
|
|
1956
|
+
let zip;
|
|
1957
|
+
try {
|
|
1958
|
+
zip = await readZip(bytes, options);
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
throw new OfficeChartsError(`This is not an Office file: ${error.message}`, { cause: error });
|
|
1961
|
+
}
|
|
1962
|
+
const r = { zip, Parser, max: options.maxCharts ?? 500, charts: [], seen: /* @__PURE__ */ new Set() };
|
|
1963
|
+
const main = await readMainPart(r);
|
|
1964
|
+
const root = main.doc.documentElement.localName;
|
|
1965
|
+
const format = root === "workbook" ? "xlsx" : root === "presentation" ? "pptx" : root === "document" ? "docx" : void 0;
|
|
1966
|
+
if (!format) throw new OfficeChartsError(`The main part ${main.path} is a <${root}>; expected an Excel workbook, PowerPoint presentation or Word document.`);
|
|
1967
|
+
return { r, main, format };
|
|
1968
|
+
}
|
|
1969
|
+
var READERS = { xlsx: readXlsx, pptx: readPptx, docx: readDocx };
|
|
1970
|
+
async function extractOfficeCharts(bytes, options = {}) {
|
|
1971
|
+
const { r, main, format } = await open(bytes, options);
|
|
1972
|
+
await READERS[format](r, main);
|
|
1973
|
+
return { format, charts: r.charts };
|
|
1974
|
+
}
|
|
1975
|
+
async function extractAs(format, bytes, options) {
|
|
1976
|
+
const result = await extractOfficeCharts(bytes, options);
|
|
1977
|
+
if (result.format !== format) throw new OfficeChartsError(`This is a .${result.format} file, not a .${format} file.`);
|
|
1978
|
+
return result.charts;
|
|
1979
|
+
}
|
|
1980
|
+
var extractXlsxCharts = (bytes, options = {}) => extractAs("xlsx", bytes, options);
|
|
1981
|
+
var extractPptxCharts = (bytes, options = {}) => extractAs("pptx", bytes, options);
|
|
1982
|
+
var extractDocxCharts = (bytes, options = {}) => extractAs("docx", bytes, options);
|
|
1983
|
+
function describeOfficeChartPlace(chart) {
|
|
1984
|
+
if (chart.sheet !== void 0) return chart.anchor ? `${chart.sheet}!${chart.anchor}` : chart.sheet;
|
|
1985
|
+
if (chart.slide !== void 0) return `Slide ${chart.slide}`;
|
|
1986
|
+
return "Document";
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
// src/chart/file-tools.ts
|
|
1990
|
+
var READ2 = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
1991
|
+
var DESTRUCTIVE2 = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false };
|
|
1992
|
+
var fail3 = (message) => {
|
|
1993
|
+
throw new Error(message);
|
|
1994
|
+
};
|
|
1995
|
+
function fromBase64(data) {
|
|
1996
|
+
const clean = data.replace(/^data:[^,]*,/, "").replace(/\s+/g, "");
|
|
1997
|
+
let binary;
|
|
1998
|
+
try {
|
|
1999
|
+
binary = atob(clean);
|
|
2000
|
+
} catch {
|
|
2001
|
+
return fail3('"data" is not valid base64. Pass the whole .xlsx, .pptx or .docx file encoded as base64 (a data: URL prefix is fine).');
|
|
2002
|
+
}
|
|
2003
|
+
const out = new Uint8Array(binary.length);
|
|
2004
|
+
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
2005
|
+
return out;
|
|
2006
|
+
}
|
|
2007
|
+
function chartSummary(chart) {
|
|
2008
|
+
return {
|
|
2009
|
+
id: chart.id,
|
|
2010
|
+
place: describeOfficeChartPlace(chart),
|
|
2011
|
+
...chart.sheet !== void 0 ? { sheet: chart.sheet } : {},
|
|
2012
|
+
...chart.slide !== void 0 ? { slide: chart.slide } : {},
|
|
2013
|
+
...chart.anchor ? { anchor: chart.anchor } : {},
|
|
2014
|
+
...chart.range ? { range: chart.range } : {},
|
|
2015
|
+
...chart.name ? { name: chart.name } : {},
|
|
2016
|
+
path: chart.path,
|
|
2017
|
+
partKind: chart.partKind,
|
|
2018
|
+
title: chart.title,
|
|
2019
|
+
type: chart.spec.type,
|
|
2020
|
+
series: chart.spec.series.map((s) => s.name),
|
|
2021
|
+
categories: chart.spec.categories.length,
|
|
2022
|
+
issues: chart.issues,
|
|
2023
|
+
unsupported: chart.unsupported,
|
|
2024
|
+
lossless: chart.lossless
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
function createOfficeChartToolProvider(options = {}) {
|
|
2028
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
2029
|
+
const readOnlyReason = () => {
|
|
2030
|
+
const r = typeof options.readOnly === "function" ? options.readOnly() : options.readOnly;
|
|
2031
|
+
if (!r) return null;
|
|
2032
|
+
return typeof r === "string" ? r : "This chart is read-only.";
|
|
2033
|
+
};
|
|
2034
|
+
const source = options.files ? { file: { type: "string", description: "Name of an open file, as list_open_files returns it." } } : { data: { type: "string", description: "The whole .xlsx, .pptx or .docx file as base64 (a data: URL prefix is allowed)." } };
|
|
2035
|
+
const sourceKey = options.files ? "file" : "data";
|
|
2036
|
+
const read = (args) => {
|
|
2037
|
+
if (!options.files) return extractOfficeCharts(fromBase64(String(args.data)), { DOMParser: options.DOMParser });
|
|
2038
|
+
const files = options.files();
|
|
2039
|
+
const file = files.find((f) => f.name === args.file);
|
|
2040
|
+
if (!file) return fail3(`There is no open file "${String(args.file)}"; expected one of ${files.map((f) => JSON.stringify(f.name)).join(", ") || "(none; ask the user to open an .xlsx, .pptx or .docx file)"}.`);
|
|
2041
|
+
let result = cache.get(file);
|
|
2042
|
+
if (!result) {
|
|
2043
|
+
result = extractOfficeCharts(file.data, { DOMParser: options.DOMParser });
|
|
2044
|
+
cache.set(file, result);
|
|
2045
|
+
result.catch(() => cache.delete(file));
|
|
2046
|
+
}
|
|
2047
|
+
return result;
|
|
2048
|
+
};
|
|
2049
|
+
const chartById = async (args) => {
|
|
2050
|
+
const { charts } = await read(args);
|
|
2051
|
+
const chart = charts.find((c) => c.id === args.chartId);
|
|
2052
|
+
if (!chart) fail3(`There is no chart "${String(args.chartId)}" in this file; expected one of ${charts.map((c) => `"${c.id}" (${describeOfficeChartPlace(c)})`).join(", ") || "(none: the file has no charts)"}.`);
|
|
2053
|
+
return chart;
|
|
2054
|
+
};
|
|
2055
|
+
const CHART_ID = { type: "string", description: 'Chart id from list_file_charts, e.g. "chart-1".' };
|
|
2056
|
+
const listOpenFiles = {
|
|
2057
|
+
name: "list_open_files",
|
|
2058
|
+
title: "List open files",
|
|
2059
|
+
description: "Lists the Office files the user opened that charts can be read from. Returns their names and sizes in bytes.",
|
|
2060
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
2061
|
+
annotations: { title: "List open files", ...READ2 },
|
|
2062
|
+
handler: () => ({ files: (options.files?.() ?? []).map((f) => ({ name: f.name, bytes: f.data.byteLength })) })
|
|
2063
|
+
};
|
|
2064
|
+
const listCharts = {
|
|
2065
|
+
name: "list_file_charts",
|
|
2066
|
+
title: "List the charts in an Office file",
|
|
2067
|
+
description: "Reads an Excel workbook, PowerPoint deck or Word document and lists its charts in file order: id, where it sits (sheet name and anchor cell, or slide number), title, type, series names, number of categories, read problems, features the chart editor cannot hold, and whether it reads losslessly. Pass an id to get_file_chart or load_file_chart.",
|
|
2068
|
+
inputSchema: { type: "object", properties: { ...source }, required: [sourceKey], additionalProperties: false },
|
|
2069
|
+
annotations: { title: "List the charts in an Office file", ...READ2 },
|
|
2070
|
+
handler: async (args) => {
|
|
2071
|
+
const result = await read(args);
|
|
2072
|
+
return { format: result.format, charts: result.charts.map(chartSummary) };
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
const getChart = {
|
|
2076
|
+
name: "get_file_chart",
|
|
2077
|
+
title: "Get a chart from an Office file",
|
|
2078
|
+
description: "Returns one chart of an Office file with its full chart spec (data, axes, series styles), where it sits and its read problems.",
|
|
2079
|
+
inputSchema: { type: "object", properties: { ...source, chartId: CHART_ID }, required: [sourceKey, "chartId"], additionalProperties: false },
|
|
2080
|
+
annotations: { title: "Get a chart from an Office file", ...READ2 },
|
|
2081
|
+
handler: async (args) => {
|
|
2082
|
+
const chart = await chartById(args);
|
|
2083
|
+
return { ...chartSummary(chart), spec: chart.spec };
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
const loadChart = {
|
|
2087
|
+
name: "load_file_chart",
|
|
2088
|
+
title: "Load a chart from an Office file",
|
|
2089
|
+
description: "Replaces the chart in the editor with a chart from an Office file, as one undo step. Returns the new spec, read problems and features the editor could not keep.",
|
|
2090
|
+
inputSchema: { type: "object", properties: { ...source, chartId: CHART_ID }, required: [sourceKey, "chartId"], additionalProperties: false },
|
|
2091
|
+
annotations: { title: "Load a chart from an Office file", ...DESTRUCTIVE2 },
|
|
2092
|
+
handler: async (args) => {
|
|
2093
|
+
const reason = readOnlyReason();
|
|
2094
|
+
if (reason) fail3(reason);
|
|
2095
|
+
const chart = await chartById(args);
|
|
2096
|
+
const result = options.controller.update({ ...chart.spec }, { label: "Load chart from file" });
|
|
2097
|
+
if (!result.ok) fail3(result.message ?? "The chart could not be loaded.");
|
|
2098
|
+
return { id: chart.id, place: describeOfficeChartPlace(chart), spec: options.controller.toJSON(), issues: chart.issues, unsupported: chart.unsupported, lossless: chart.lossless };
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
return {
|
|
2102
|
+
id: options.id ?? "office-charts",
|
|
2103
|
+
...options.namespace ? { namespace: options.namespace } : {},
|
|
2104
|
+
tools: () => [...options.files ? [listOpenFiles] : [], listCharts, getChart, ...options.controller && !readOnlyReason() ? [loadChart] : []]
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
1806
2107
|
export {
|
|
1807
2108
|
CHART_AXIS_KINDS,
|
|
1808
2109
|
CHART_COLOR_SCHEMES,
|
|
@@ -1836,6 +2137,7 @@ export {
|
|
|
1836
2137
|
MAX_CHART_DATA_LABELS,
|
|
1837
2138
|
MAX_CHART_LINE_POINTS,
|
|
1838
2139
|
MAX_CHART_MARKERS,
|
|
2140
|
+
OfficeChartsError,
|
|
1839
2141
|
RENDER_CHART_INSTRUCTIONS,
|
|
1840
2142
|
analyzeChartTable,
|
|
1841
2143
|
blendChartScenes,
|
|
@@ -1896,14 +2198,20 @@ export {
|
|
|
1896
2198
|
createChartSpec,
|
|
1897
2199
|
createChartToolProvider,
|
|
1898
2200
|
createInstantChartClock,
|
|
2201
|
+
createOfficeChartToolProvider,
|
|
1899
2202
|
cyclePaletteColor,
|
|
1900
2203
|
decimateChartPoints,
|
|
1901
2204
|
defaultChartAxis,
|
|
1902
2205
|
describeChart,
|
|
1903
2206
|
describeChartSelection,
|
|
2207
|
+
describeOfficeChartPlace,
|
|
1904
2208
|
downloadChartPng,
|
|
1905
2209
|
easeChartTween,
|
|
1906
2210
|
estimateChartTextWidth,
|
|
2211
|
+
extractDocxCharts,
|
|
2212
|
+
extractOfficeCharts,
|
|
2213
|
+
extractPptxCharts,
|
|
2214
|
+
extractXlsxCharts,
|
|
1907
2215
|
findMermaidCharts,
|
|
1908
2216
|
fitChartTrendline,
|
|
1909
2217
|
formatChartDate,
|