@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.cjs
CHANGED
|
@@ -15,7 +15,8 @@ var _chunkTGBCBQFVcjs = require('../chunk-TGBCBQFV.cjs');
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
var _chunk3ZBAXET6cjs = require('../chunk-3ZBAXET6.cjs');
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
|
|
@@ -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
|
}
|
|
@@ -612,7 +613,7 @@ function createChartCommands(controller, options = {}) {
|
|
|
612
613
|
readOnly: true,
|
|
613
614
|
keywords: ["chart", "office", "word", "powerpoint", "docx", "pptx", "xml", "export"],
|
|
614
615
|
description: "Returns the chart as a DrawingML chart part (c:chartSpace) and what could not be written.",
|
|
615
|
-
run: () =>
|
|
616
|
+
run: () => _chunk3ZBAXET6cjs.chartToOoxml.call(void 0, controller.toJSON())
|
|
616
617
|
},
|
|
617
618
|
{
|
|
618
619
|
...base,
|
|
@@ -1050,7 +1051,7 @@ function createChartToolProvider(controller, options = {}) {
|
|
|
1050
1051
|
description: "Returns the chart as a DrawingML chart part (c:chartSpace) for Word or PowerPoint files, with what could not be written as sentences.",
|
|
1051
1052
|
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
1052
1053
|
annotations: { title: "Export chart as Office XML", ...READ },
|
|
1053
|
-
handler: () =>
|
|
1054
|
+
handler: () => _chunk3ZBAXET6cjs.chartToOoxml.call(void 0, controller.toJSON())
|
|
1054
1055
|
};
|
|
1055
1056
|
const updateChart = {
|
|
1056
1057
|
name: "update_chart",
|
|
@@ -1244,7 +1245,7 @@ function createChartToolProvider(controller, options = {}) {
|
|
|
1244
1245
|
inputSchema: { type: "object", properties: { xml: { type: "string", description: "The chart part XML, e.g. word/charts/chart1.xml." } }, required: ["xml"], additionalProperties: false },
|
|
1245
1246
|
annotations: { title: "Import an Office chart", ...DESTRUCTIVE },
|
|
1246
1247
|
handler: ({ xml }) => {
|
|
1247
|
-
const read =
|
|
1248
|
+
const read = _chunk3ZBAXET6cjs.chartFromOoxml.call(void 0, xml, { DOMParser: Parser() });
|
|
1248
1249
|
if (read.issues.some((i) => i.path === "" || i.path === "plotArea")) fail2(read.issues.map((i) => i.message).join(" "));
|
|
1249
1250
|
resolve(controller.update({ ...read.spec }, { label: "Import Office chart" }));
|
|
1250
1251
|
return { spec: controller.toJSON(), issues: read.issues.map((i) => i.message), unsupported: read.unsupported, lossless: read.lossless };
|
|
@@ -1804,6 +1805,313 @@ var ChartDirector = (_class3 = class {
|
|
|
1804
1805
|
}
|
|
1805
1806
|
}, _class3);
|
|
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 && (_optionalChain([a, 'access', _107 => _107.namespaceURI, 'optionalAccess', _108 => _108.includes, 'call', _109 => _109("relationships")]) || a.prefix === "r")) return a.value;
|
|
1834
|
+
}
|
|
1835
|
+
return void 0;
|
|
1836
|
+
}
|
|
1837
|
+
var firstChild = (el, localName) => el ? Array.from(_nullishCoalesce(el.children, () => ( el.childNodes))).find((n) => n.nodeType === 1 && n.localName === localName) : void 0;
|
|
1838
|
+
async function readXml(r, path) {
|
|
1839
|
+
const entry = _nullishCoalesce(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 = _nullishCoalesce(rel.getAttribute("Target"), () => ( ""));
|
|
1852
|
+
const external = _optionalChain([rel, 'access', _110 => _110.getAttribute, 'call', _111 => _111("TargetMode"), 'optionalAccess', _112 => _112.toLowerCase, 'call', _113 => _113()]) === "external";
|
|
1853
|
+
rels.set(id, { type: _nullishCoalesce(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 === _chunk3ZBAXET6cjs.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 _optionalChain([nv, 'optionalAccess', _114 => _114.getAttribute, 'call', _115 => _115("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(_nullishCoalesce(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 = _chunk3ZBAXET6cjs.chartFromOoxml.call(void 0, 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(_optionalChain([firstChild, 'call', _116 => _116(marker, "col"), 'optionalAccess', _117 => _117.textContent]));
|
|
1899
|
+
const row = Number(_optionalChain([firstChild, 'call', _118 => _118(marker, "row"), 'optionalAccess', _119 => _119.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(_nullishCoalesce(relId(sheet), () => ( "")));
|
|
1924
|
+
if (!rel || rel.external) continue;
|
|
1925
|
+
const doc = await readXml(r, rel.target);
|
|
1926
|
+
if (!doc) continue;
|
|
1927
|
+
const sheetName = _nullishCoalesce(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(_nullishCoalesce(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(_nullishCoalesce(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 = _nullishCoalesce(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 _chunk3ZBAXET6cjs.readZip.call(void 0, 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: _nullishCoalesce(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 (e6) {
|
|
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: (_nullishCoalesce(_optionalChain([options, 'access', _120 => _120.files, 'optionalCall', _121 => _121()]), () => ( []))).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(_nullishCoalesce(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: _nullishCoalesce(options.id, () => ( "office-charts")),
|
|
2103
|
+
...options.namespace ? { namespace: options.namespace } : {},
|
|
2104
|
+
tools: () => [...options.files ? [listOpenFiles] : [], listCharts, getChart, ...options.controller && !readOnlyReason() ? [loadChart] : []]
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
|
|
1807
2115
|
|
|
1808
2116
|
|
|
1809
2117
|
|
|
@@ -1944,5 +2252,5 @@ var ChartDirector = (_class3 = class {
|
|
|
1944
2252
|
|
|
1945
2253
|
|
|
1946
2254
|
|
|
1947
|
-
exports.CHART_AXIS_KINDS = _chunkJOX6MJW4cjs.CHART_AXIS_KINDS; exports.CHART_COLOR_SCHEMES = _chunkGTZXF4BIcjs.CHART_COLOR_SCHEMES; exports.CHART_CURVES = _chunkJOX6MJW4cjs.CHART_CURVES; exports.CHART_DATE_STEPS = _chunkGTZXF4BIcjs.CHART_DATE_STEPS; exports.CHART_LABEL_POSITIONS = _chunkJOX6MJW4cjs.CHART_LABEL_POSITIONS; exports.CHART_LAYOUT_PRESETS = _chunkGTZXF4BIcjs.CHART_LAYOUT_PRESETS; exports.CHART_LEGEND_POSITIONS = _chunkJOX6MJW4cjs.CHART_LEGEND_POSITIONS; exports.CHART_MARKERS = _chunkJOX6MJW4cjs.CHART_MARKERS; exports.CHART_MERMAID_META_PREFIX = _chunkGTZXF4BIcjs.CHART_MERMAID_META_PREFIX; exports.CHART_NUMBER_STYLES = _chunkJOX6MJW4cjs.CHART_NUMBER_STYLES; exports.CHART_OOXML_CONTENT_TYPE =
|
|
2255
|
+
exports.CHART_AXIS_KINDS = _chunkJOX6MJW4cjs.CHART_AXIS_KINDS; exports.CHART_COLOR_SCHEMES = _chunkGTZXF4BIcjs.CHART_COLOR_SCHEMES; exports.CHART_CURVES = _chunkJOX6MJW4cjs.CHART_CURVES; exports.CHART_DATE_STEPS = _chunkGTZXF4BIcjs.CHART_DATE_STEPS; exports.CHART_LABEL_POSITIONS = _chunkJOX6MJW4cjs.CHART_LABEL_POSITIONS; exports.CHART_LAYOUT_PRESETS = _chunkGTZXF4BIcjs.CHART_LAYOUT_PRESETS; exports.CHART_LEGEND_POSITIONS = _chunkJOX6MJW4cjs.CHART_LEGEND_POSITIONS; exports.CHART_MARKERS = _chunkJOX6MJW4cjs.CHART_MARKERS; exports.CHART_MERMAID_META_PREFIX = _chunkGTZXF4BIcjs.CHART_MERMAID_META_PREFIX; exports.CHART_NUMBER_STYLES = _chunkJOX6MJW4cjs.CHART_NUMBER_STYLES; exports.CHART_OOXML_CONTENT_TYPE = _chunk3ZBAXET6cjs.CHART_OOXML_CONTENT_TYPE; exports.CHART_OOXML_NS = _chunk3ZBAXET6cjs.CHART_OOXML_NS; exports.CHART_OOXML_RELATIONSHIP = _chunk3ZBAXET6cjs.CHART_OOXML_RELATIONSHIP; exports.CHART_ORIENTATIONS = _chunkJOX6MJW4cjs.CHART_ORIENTATIONS; exports.CHART_PALETTE_SHADES = _chunkJOX6MJW4cjs.CHART_PALETTE_SHADES; exports.CHART_PRESENCE_COLORS = CHART_PRESENCE_COLORS; exports.CHART_RASTER_MAX_SIZE = CHART_RASTER_MAX_SIZE; exports.CHART_SERIES_TYPES = _chunkJOX6MJW4cjs.CHART_SERIES_TYPES; exports.CHART_STACKINGS = _chunkJOX6MJW4cjs.CHART_STACKINGS; exports.CHART_TRENDLINE_TYPES = _chunkJOX6MJW4cjs.CHART_TRENDLINE_TYPES; exports.CHART_TYPES = _chunkJOX6MJW4cjs.CHART_TYPES; exports.CHART_TYPE_LABELS = _chunkJOX6MJW4cjs.CHART_TYPE_LABELS; exports.CSS_VARIABLE_CHART_THEME = _chunkJOX6MJW4cjs.CSS_VARIABLE_CHART_THEME; exports.ChartController = _chunkGTZXF4BIcjs.ChartController; exports.ChartDirector = ChartDirector; exports.ChartPresence = ChartPresence; exports.ChartStream = ChartStream; exports.DEFAULT_CHART_PALETTE = _chunkJOX6MJW4cjs.DEFAULT_CHART_PALETTE; exports.DEFAULT_CHART_THEME = _chunkJOX6MJW4cjs.DEFAULT_CHART_THEME; exports.MAX_CHART_DATA_LABELS = _chunkGTZXF4BIcjs.MAX_CHART_DATA_LABELS; exports.MAX_CHART_LINE_POINTS = _chunkGTZXF4BIcjs.MAX_CHART_LINE_POINTS; exports.MAX_CHART_MARKERS = _chunkGTZXF4BIcjs.MAX_CHART_MARKERS; exports.OfficeChartsError = OfficeChartsError; exports.RENDER_CHART_INSTRUCTIONS = RENDER_CHART_INSTRUCTIONS; exports.analyzeChartTable = analyzeChartTable; exports.blendChartScenes = blendChartScenes; exports.canDragChartPoint = canDragChartPoint; exports.chartBoxStats = _chunkGTZXF4BIcjs.chartBoxStats; exports.chartClientToScene = chartClientToScene; exports.chartColorDistance = _chunkJOX6MJW4cjs.chartColorDistance; exports.chartColorInputValue = _chunkJOX6MJW4cjs.chartColorInputValue; exports.chartColorsByCategory = _chunkJOX6MJW4cjs.chartColorsByCategory; exports.chartContrastRatio = _chunkJOX6MJW4cjs.chartContrastRatio; exports.chartDataFromTable = _chunkJOX6MJW4cjs.chartDataFromTable; exports.chartDataToTable = _chunkJOX6MJW4cjs.chartDataToTable; exports.chartDateLabels = _chunkGTZXF4BIcjs.chartDateLabels; exports.chartDateToSerial = _chunkGTZXF4BIcjs.chartDateToSerial; exports.chartFamily = _chunkJOX6MJW4cjs.chartFamily; exports.chartFileName = chartFileName; exports.chartFormatToCode = _chunk3ZBAXET6cjs.chartFormatToCode; exports.chartFromMermaid = _chunkGTZXF4BIcjs.chartFromMermaid; exports.chartFromOoxml = _chunk3ZBAXET6cjs.chartFromOoxml; exports.chartFromTable = chartFromTable; exports.chartHistogram = _chunkGTZXF4BIcjs.chartHistogram; exports.chartHitTest = chartHitTest; exports.chartLuminance = _chunkJOX6MJW4cjs.chartLuminance; exports.chartMermaidFamily = _chunkGTZXF4BIcjs.chartMermaidFamily; exports.chartMovingAverage = _chunkGTZXF4BIcjs.chartMovingAverage; exports.chartPointAnchor = chartPointAnchor; exports.chartPointColor = _chunkJOX6MJW4cjs.chartPointColor; exports.chartPresetPatch = _chunkGTZXF4BIcjs.chartPresetPatch; exports.chartQuantile = _chunkGTZXF4BIcjs.chartQuantile; exports.chartRasterSize = chartRasterSize; exports.chartRgbToHex = _chunkJOX6MJW4cjs.chartRgbToHex; exports.chartRgbToOklab = _chunkJOX6MJW4cjs.chartRgbToOklab; exports.chartSceneToDomSpec = _chunkGTZXF4BIcjs.chartSceneToDomSpec; exports.chartSceneToSvg = _chunkGTZXF4BIcjs.chartSceneToSvg; exports.chartSerialToDate = _chunkGTZXF4BIcjs.chartSerialToDate; exports.chartSeriesColor = _chunkJOX6MJW4cjs.chartSeriesColor; exports.chartSeriesType = _chunkJOX6MJW4cjs.chartSeriesType; exports.chartSliceColor = _chunkJOX6MJW4cjs.chartSliceColor; exports.chartSquarify = _chunkGTZXF4BIcjs.chartSquarify; exports.chartSupportsTrendlines = _chunkGTZXF4BIcjs.chartSupportsTrendlines; exports.chartTextBaseline = _chunkGTZXF4BIcjs.chartTextBaseline; exports.chartTextOn = _chunkJOX6MJW4cjs.chartTextOn; exports.chartTextTransform = _chunkGTZXF4BIcjs.chartTextTransform; exports.chartToMermaid = _chunkGTZXF4BIcjs.chartToMermaid; exports.chartToOoxml = _chunk3ZBAXET6cjs.chartToOoxml; exports.chartToSvg = _chunkGTZXF4BIcjs.chartToSvg; exports.chartTrendlineName = _chunkGTZXF4BIcjs.chartTrendlineName; exports.chartValueAtPoint = _chunkGTZXF4BIcjs.chartValueAtPoint; exports.chartXAtPoint = _chunkGTZXF4BIcjs.chartXAtPoint; exports.checkChartColors = _chunkJOX6MJW4cjs.checkChartColors; exports.cloneChartSeries = _chunkJOX6MJW4cjs.cloneChartSeries; exports.cloneChartSpec = _chunkJOX6MJW4cjs.cloneChartSpec; exports.compileChartFormatCode = _chunkGTZXF4BIcjs.compileChartFormatCode; exports.contrastingTextColor = _chunkGTZXF4BIcjs.contrastingTextColor; exports.createChartCommands = createChartCommands; exports.createChartController = _chunkGTZXF4BIcjs.createChartController; exports.createChartRasterizer = createChartRasterizer; exports.createChartSpec = _chunkJOX6MJW4cjs.createChartSpec; exports.createChartToolProvider = createChartToolProvider; exports.createInstantChartClock = createInstantChartClock; exports.createOfficeChartToolProvider = createOfficeChartToolProvider; exports.cyclePaletteColor = _chunkJOX6MJW4cjs.cyclePaletteColor; exports.decimateChartPoints = _chunkGTZXF4BIcjs.decimateChartPoints; exports.defaultChartAxis = _chunkJOX6MJW4cjs.defaultChartAxis; exports.describeChart = _chunkGTZXF4BIcjs.describeChart; exports.describeChartSelection = describeChartSelection; exports.describeOfficeChartPlace = describeOfficeChartPlace; exports.downloadChartPng = downloadChartPng; exports.easeChartTween = easeChartTween; exports.estimateChartTextWidth = _chunkGTZXF4BIcjs.estimateChartTextWidth; exports.extractDocxCharts = extractDocxCharts; exports.extractOfficeCharts = extractOfficeCharts; exports.extractPptxCharts = extractPptxCharts; exports.extractXlsxCharts = extractXlsxCharts; exports.findMermaidCharts = _chunkGTZXF4BIcjs.findMermaidCharts; exports.fitChartTrendline = _chunkGTZXF4BIcjs.fitChartTrendline; exports.formatChartDate = _chunkGTZXF4BIcjs.formatChartDate; exports.formatChartNumber = _chunkGTZXF4BIcjs.formatChartNumber; exports.formatChartValueWithCode = _chunkGTZXF4BIcjs.formatChartValueWithCode; exports.handleChartKey = handleChartKey; exports.isCartesianChart = _chunkJOX6MJW4cjs.isCartesianChart; exports.isXyChart = _chunkJOX6MJW4cjs.isXyChart; exports.layoutChart = _chunkGTZXF4BIcjs.layoutChart; exports.layoutSparkline = _chunkGTZXF4BIcjs.layoutSparkline; exports.linearMap = _chunkGTZXF4BIcjs.linearMap; exports.monochromeChartPalette = _chunkGTZXF4BIcjs.monochromeChartPalette; exports.niceScale = _chunkGTZXF4BIcjs.niceScale; exports.niceStep = _chunkGTZXF4BIcjs.niceStep; exports.normalizeChartAxis = _chunkJOX6MJW4cjs.normalizeChartAxis; exports.normalizeChartSpec = _chunkJOX6MJW4cjs.normalizeChartSpec; exports.normalizeChartTrendline = _chunkJOX6MJW4cjs.normalizeChartTrendline; exports.normalizeChartValues = _chunkJOX6MJW4cjs.normalizeChartValues; exports.parseChartColor = _chunkJOX6MJW4cjs.parseChartColor; exports.parseChartDate = _chunkGTZXF4BIcjs.parseChartDate; exports.parseChartValue = _chunkJOX6MJW4cjs.parseChartValue; exports.parsePartialChartJson = parsePartialChartJson; exports.planChartCommand = planChartCommand; exports.rasterizeChartSvg = rasterizeChartSvg; exports.realChartClock = realChartClock; exports.recommendChartTypes = recommendChartTypes; exports.recommendForShape = recommendForShape; exports.resolveChartSvgPaints = resolveChartSvgPaints; exports.sameChartSelection = _chunkGTZXF4BIcjs.sameChartSelection; exports.shadeChartColor = _chunkJOX6MJW4cjs.shadeChartColor; exports.simulateChartVision = _chunkJOX6MJW4cjs.simulateChartVision; exports.snapChartDragValue = snapChartDragValue; exports.snapChartValue = _chunkGTZXF4BIcjs.snapChartValue; exports.sparklineToSvg = _chunkGTZXF4BIcjs.sparklineToSvg; exports.startChartPointDrag = startChartPointDrag; exports.stepDecimals = _chunkGTZXF4BIcjs.stepDecimals; exports.summarizeChart = _chunkGTZXF4BIcjs.summarizeChart; exports.summarizeChartSeries = _chunkGTZXF4BIcjs.summarizeChartSeries; exports.trendNumberText = _chunkGTZXF4BIcjs.trendNumberText; exports.uniqueChartSeriesId = _chunkJOX6MJW4cjs.uniqueChartSeriesId;
|
|
1948
2256
|
//# sourceMappingURL=index.cjs.map
|