@office-open/core 0.8.0 → 0.9.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 +32 -60
- package/dist/chart/index.d.mts +2 -2
- package/dist/chart/index.mjs +2 -2
- package/dist/chart-DNpai28f.mjs +365 -0
- package/dist/descriptor/index.d.mts +2 -0
- package/dist/descriptor/index.mjs +2 -0
- package/dist/descriptor-DKmR7pw-.mjs +282 -0
- package/dist/drawingml/index.d.mts +2 -2
- package/dist/drawingml/index.mjs +2 -2
- package/dist/index-BI-1SKm5.d.mts +153 -0
- package/dist/{index-Cj2Yf5mk.d.mts → index-DByjp6ug.d.mts} +10 -7
- package/dist/index-DNH2sizc.d.mts +137 -0
- package/dist/{index-C-DvIxek.d.mts → index-RWXzxibP.d.mts} +1420 -1866
- package/dist/{index-D0N5Bw2M.d.mts → index-eu1aFQCm.d.mts} +39 -28
- package/dist/index.d.mts +7 -538
- package/dist/index.mjs +7 -2077
- package/dist/smartart/index.d.mts +2 -2
- package/dist/smartart/index.mjs +2 -2
- package/dist/{smartart-BAhTD2yA.mjs → smartart-DCY-Vdv7.mjs} +120 -204
- package/dist/src-CU2AFKyt.mjs +7413 -0
- package/dist/theme/index.d.mts +2 -2
- package/dist/theme/index.mjs +2 -2
- package/dist/{theme-DmJXjgQs.mjs → theme-CiNzdl-9.mjs} +117 -22
- package/dist/{values.d.mts → util/values.d.mts} +1 -1
- package/dist/{values.mjs → util/values.mjs} +1 -1
- package/dist/{values-zMCu5EoQ.mjs → values-CVIZcTRw.mjs} +2 -2
- package/dist/{values-COjPGYkS.d.mts → values-Dqj8cbcy.d.mts} +1 -1
- package/package.json +12 -7
- package/dist/chart-BtEtdK2K.mjs +0 -1266
- package/dist/drawingml-anlfMLLZ.mjs +0 -7132
- package/dist/index-Bh6s66Up.d.mts +0 -381
- package/dist/index-CoTp4wVf.d.mts +0 -202
- package/dist/xml-components-DEU24Y1T.mjs +0 -322
package/README.md
CHANGED
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|

|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
> Shared OOXML infrastructure —
|
|
7
|
+
> Shared OOXML infrastructure — descriptors, DrawingML, charts, SmartArt, OPC, validators, and converters.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
11
|
+
- **Descriptor Runtime** — `CustomDescriptor<T>` and `ElementDescriptor<T>` for bidirectional XML stringify/parse
|
|
12
|
+
- **DrawingML** — Fills, outlines, effects, geometry, text body, scene 3D, and more
|
|
13
|
+
- **Chart Components** — Shared chart types (bar, line, pie, area, scatter) and chart collection
|
|
14
|
+
- **SmartArt Components** — Data model, tree-to-model converter, layout/style/color definitions
|
|
15
|
+
- **OPC (Open Packaging)** — Content types, relationships, and ZIP packaging
|
|
16
|
+
- **Value Validators** — Runtime validation for OOXML spec types (ST_HexColor, ST_OnOff, ST_DecimalNumber, etc.)
|
|
17
|
+
- **Unit Converters** — TWIP and EMU conversions (mm/in/pt/px)
|
|
18
|
+
- **ID Generators** — Sequential numeric IDs, nanoid, SHA-1 hash, UUID v4
|
|
19
|
+
- **Template Patching** — Placeholder replacement, XML traverser, and token replacer
|
|
20
|
+
- **OOXML Compliance** — All types verified against ISO/IEC 29500-4 XSD schemas
|
|
18
21
|
|
|
19
22
|
## Installation
|
|
20
23
|
|
|
@@ -36,30 +39,15 @@ bun add @office-open/core
|
|
|
36
39
|
|
|
37
40
|
```typescript
|
|
38
41
|
import {
|
|
39
|
-
OnOffElement,
|
|
40
|
-
StringValueElement,
|
|
41
|
-
BuilderElement,
|
|
42
|
-
StringContainer,
|
|
43
42
|
hexColorValue,
|
|
44
43
|
decimalNumber,
|
|
45
44
|
convertMillimetersToTwip,
|
|
45
|
+
convertPixelsToEmu,
|
|
46
|
+
convertInchesToEmu,
|
|
47
|
+
convertPointsToEmu,
|
|
46
48
|
uniqueNumericIdCreator,
|
|
47
49
|
} from "@office-open/core";
|
|
48
50
|
|
|
49
|
-
// CT_OnOff — dynamic namespace prefix per XSD spec
|
|
50
|
-
new OnOffElement("w:b", false);
|
|
51
|
-
// → { "w:b": { _attr: { "w:val": false } } }
|
|
52
|
-
|
|
53
|
-
new OnOffElement("m:hideBot", false);
|
|
54
|
-
// → { "m:hideBot": { _attr: { "m:val": false } } }
|
|
55
|
-
|
|
56
|
-
// Builder with attributes + children
|
|
57
|
-
new BuilderElement({
|
|
58
|
-
name: "w:r",
|
|
59
|
-
attributes: { lang: { key: "xml:lang", value: "en-US" } },
|
|
60
|
-
children: [new StringContainer("w:t", "Hello")],
|
|
61
|
-
});
|
|
62
|
-
|
|
63
51
|
// Value validators
|
|
64
52
|
hexColorValue("#FF0000"); // → "FF0000"
|
|
65
53
|
hexColorValue("auto"); // → "auto"
|
|
@@ -78,43 +66,27 @@ gen(); // → 1, 2, 3, ...
|
|
|
78
66
|
|
|
79
67
|
## OOXML Schema Compliance
|
|
80
68
|
|
|
81
|
-
| Type
|
|
82
|
-
|
|
|
83
|
-
| `ThemeColor`
|
|
84
|
-
| `ThemeFont`
|
|
85
|
-
| `UniversalMeasure`
|
|
86
|
-
| `Percentage`
|
|
87
|
-
| `hexColorValue`
|
|
88
|
-
| `
|
|
89
|
-
| `HpsMeasureElement` | `CT_HpsMeasure` |
|
|
90
|
-
| `StringValueElement` | `CT_String` |
|
|
69
|
+
| Type | XSD Reference |
|
|
70
|
+
| ------------------ | ---------------------------------------------- |
|
|
71
|
+
| `ThemeColor` | `ST_ThemeColor` (17 values) |
|
|
72
|
+
| `ThemeFont` | `ST_Theme` (8 values) |
|
|
73
|
+
| `UniversalMeasure` | `ST_UniversalMeasure` (mm, cm, in, pt, pc, pi) |
|
|
74
|
+
| `Percentage` | `ST_Percentage` |
|
|
75
|
+
| `hexColorValue` | `ST_HexColor` (auto + 3-byte hexBinary) |
|
|
76
|
+
| `decimalNumber` | `ST_DecimalNumber` |
|
|
91
77
|
|
|
92
78
|
## Exports
|
|
93
79
|
|
|
94
|
-
| Path | Contents
|
|
95
|
-
| ----------------------------- |
|
|
96
|
-
| `@office-open/core` |
|
|
97
|
-
| `@office-open/core/values` | Validators + ThemeColor/ThemeFont only
|
|
98
|
-
| `@office-open/core/chart` | Chart types, series data, chart collection, title
|
|
99
|
-
| `@office-open/core/smartart` | SmartArt data model, tree-to-model, definitions
|
|
100
|
-
| `@office-open/core/drawingml` | DrawingML fills, outlines, effects, geometry, text body
|
|
101
|
-
| `@office-open/core/patch` | Template patching utilities (replacer, traverser, token replacer)
|
|
102
|
-
| `@office-open/core/theme` | Theme definitions and color schemes
|
|
103
|
-
|
|
104
|
-
## Benchmark
|
|
105
|
-
|
|
106
|
-
| Operation | hz |
|
|
107
|
-
| ----------------------------- | ----- |
|
|
108
|
-
| `decimalNumber` | ~21M |
|
|
109
|
-
| `hexColorValue` (6-char hex) | ~13M |
|
|
110
|
-
| `uniqueNumericIdCreator` | ~21M |
|
|
111
|
-
| `uniqueId` (nanoid) | ~3.2M |
|
|
112
|
-
| `uniqueUuid` | ~2.0M |
|
|
113
|
-
| `onOffObj` (true) | ~19M |
|
|
114
|
-
| `onOffObj` (false) | ~3.7M |
|
|
115
|
-
| `BuilderElement` (attributes) | ~3.1M |
|
|
116
|
-
| `BuilderElement` (children) | ~2.6M |
|
|
80
|
+
| Path | Contents |
|
|
81
|
+
| ----------------------------- | ------------------------------------------------------------------------- |
|
|
82
|
+
| `@office-open/core` | Descriptors, validators, converters, ID generators, OPC, password hashing |
|
|
83
|
+
| `@office-open/core/values` | Validators + ThemeColor/ThemeFont only |
|
|
84
|
+
| `@office-open/core/chart` | Chart types, series data, chart collection, title |
|
|
85
|
+
| `@office-open/core/smartart` | SmartArt data model, tree-to-model, definitions |
|
|
86
|
+
| `@office-open/core/drawingml` | DrawingML fills, outlines, effects, geometry, text body |
|
|
87
|
+
| `@office-open/core/patch` | Template patching utilities (replacer, traverser, token replacer) |
|
|
88
|
+
| `@office-open/core/theme` | Theme definitions and color schemes |
|
|
117
89
|
|
|
118
90
|
## License
|
|
119
91
|
|
|
120
|
-
- [MIT](LICENSE) © [Demo Macro](https://
|
|
92
|
+
- [MIT](LICENSE) © [Demo Macro](https://www.demomacro.com/)
|
package/dist/chart/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { _ as ChartCollection, a as ChartSpaceOptions, c as DataLabelsOptions, d as ErrorBarType, f as ErrorValueType, g as View3DOptions, h as TrendlineType, i as ChartSeriesData, l as ErrorBarDirection, m as TrendlineOptions, n as AxisChartType, o as ChartType, p as TimeUnit, r as BubbleSeriesData, s as DataLabelPosition, t as chartSpaceDesc, u as ErrorBarOptions, v as ChartData } from "../index-DNH2sizc.mjs";
|
|
2
|
+
export { AxisChartType, BubbleSeriesData, ChartCollection, ChartData, ChartSeriesData, ChartSpaceOptions, ChartType, DataLabelPosition, DataLabelsOptions, ErrorBarDirection, ErrorBarOptions, ErrorBarType, ErrorValueType, TimeUnit, TrendlineOptions, TrendlineType, View3DOptions, chartSpaceDesc };
|
package/dist/chart/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { a as TimeUnit, c as ChartCollection, i as ErrorValueType, n as ErrorBarDirection, o as TrendlineType, r as ErrorBarType, s as chartSpaceDesc, t as DataLabelPosition } from "../chart-DNpai28f.mjs";
|
|
2
|
+
export { ChartCollection, DataLabelPosition, ErrorBarDirection, ErrorBarType, ErrorValueType, TimeUnit, TrendlineType, chartSpaceDesc };
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { children, escapeXml, findChild } from "@office-open/xml";
|
|
2
|
+
//#region src/chart/chart-collection.ts
|
|
3
|
+
var ChartCollection = class {
|
|
4
|
+
map;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.map = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
addChart(key, chartData) {
|
|
9
|
+
this.map.set(key, chartData);
|
|
10
|
+
}
|
|
11
|
+
get array() {
|
|
12
|
+
return [...this.map.values()];
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/chart/chart-descriptors.ts
|
|
17
|
+
/**
|
|
18
|
+
* Chart descriptors — CustomDescriptor for c:chartSpace serialization.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
const CHART_TYPE_TAGS = {
|
|
23
|
+
column: "c:barChart",
|
|
24
|
+
bar: "c:barChart",
|
|
25
|
+
line: "c:lineChart",
|
|
26
|
+
pie: "c:pieChart",
|
|
27
|
+
area: "c:areaChart",
|
|
28
|
+
scatter: "c:scatterChart",
|
|
29
|
+
bubble: "c:bubbleChart",
|
|
30
|
+
doughnut: "c:doughnutChart",
|
|
31
|
+
radar: "c:radarChart",
|
|
32
|
+
stock: "c:stockChart",
|
|
33
|
+
surface: "c:surfaceChart"
|
|
34
|
+
};
|
|
35
|
+
const CHART_TYPE_TAGS_3D = {
|
|
36
|
+
column: "c:bar3DChart",
|
|
37
|
+
bar: "c:bar3DChart",
|
|
38
|
+
line: "c:line3DChart",
|
|
39
|
+
pie: "c:pie3DChart",
|
|
40
|
+
area: "c:area3DChart"
|
|
41
|
+
};
|
|
42
|
+
const NO_AXES_TYPES = new Set(["pie", "doughnut"]);
|
|
43
|
+
const TAG_TO_CHART_TYPE = {
|
|
44
|
+
"c:barChart": { type: "column" },
|
|
45
|
+
"c:bar3DChart": {
|
|
46
|
+
type: "column",
|
|
47
|
+
threeD: true
|
|
48
|
+
},
|
|
49
|
+
"c:lineChart": { type: "line" },
|
|
50
|
+
"c:line3DChart": {
|
|
51
|
+
type: "line",
|
|
52
|
+
threeD: true
|
|
53
|
+
},
|
|
54
|
+
"c:pieChart": { type: "pie" },
|
|
55
|
+
"c:pie3DChart": {
|
|
56
|
+
type: "pie",
|
|
57
|
+
threeD: true
|
|
58
|
+
},
|
|
59
|
+
"c:areaChart": { type: "area" },
|
|
60
|
+
"c:area3DChart": {
|
|
61
|
+
type: "area",
|
|
62
|
+
threeD: true
|
|
63
|
+
},
|
|
64
|
+
"c:scatterChart": { type: "scatter" },
|
|
65
|
+
"c:bubbleChart": { type: "bubble" },
|
|
66
|
+
"c:doughnutChart": { type: "doughnut" },
|
|
67
|
+
"c:radarChart": { type: "radar" },
|
|
68
|
+
"c:stockChart": { type: "stock" },
|
|
69
|
+
"c:surfaceChart": { type: "surface" },
|
|
70
|
+
"c:surface3DChart": {
|
|
71
|
+
type: "surface",
|
|
72
|
+
threeD: true
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function attrVal(name, value) {
|
|
76
|
+
return `${name}="${escapeXml(String(value))}"`;
|
|
77
|
+
}
|
|
78
|
+
function emptyEl(tag) {
|
|
79
|
+
return `<${tag}/>`;
|
|
80
|
+
}
|
|
81
|
+
function valEl(tag, value) {
|
|
82
|
+
return `<${tag} ${attrVal("val", value)}/>`;
|
|
83
|
+
}
|
|
84
|
+
function stringifyStrRef(values) {
|
|
85
|
+
const pts = values.map((v, i) => `<c:pt idx="${i}"><c:v>${escapeXml(v)}</c:v></c:pt>`).join("");
|
|
86
|
+
return `<c:strRef><c:f/><c:strCache><c:ptCount ${attrVal("val", values.length)}/>${pts}</c:strCache></c:strRef>`;
|
|
87
|
+
}
|
|
88
|
+
function stringifyNumRef(values) {
|
|
89
|
+
const pts = values.map((v, i) => `<c:pt idx="${i}"><c:v>${v}</c:v></c:pt>`).join("");
|
|
90
|
+
return `<c:numRef><c:f/><c:numCache><c:formatCode>General</c:formatCode><c:ptCount ${attrVal("val", values.length)}/>${pts}</c:numCache></c:numRef>`;
|
|
91
|
+
}
|
|
92
|
+
function chartTypeHeader(opts) {
|
|
93
|
+
const tag = opts.threeD ? CHART_TYPE_TAGS_3D[opts.type] : CHART_TYPE_TAGS[opts.type];
|
|
94
|
+
if (!tag) throw new Error(`Unsupported chart type: ${opts.type}`);
|
|
95
|
+
const headerParts = [];
|
|
96
|
+
switch (opts.type) {
|
|
97
|
+
case "column":
|
|
98
|
+
case "bar":
|
|
99
|
+
headerParts.push(valEl("c:barDir", opts.type === "column" ? "col" : "bar"));
|
|
100
|
+
headerParts.push(valEl("c:grouping", "clustered"));
|
|
101
|
+
break;
|
|
102
|
+
case "line":
|
|
103
|
+
case "area":
|
|
104
|
+
headerParts.push(valEl("c:grouping", "standard"));
|
|
105
|
+
break;
|
|
106
|
+
case "scatter":
|
|
107
|
+
headerParts.push(valEl("c:scatterStyle", "line"));
|
|
108
|
+
break;
|
|
109
|
+
case "radar":
|
|
110
|
+
headerParts.push(valEl("c:radarStyle", "standard"));
|
|
111
|
+
break;
|
|
112
|
+
case "pie":
|
|
113
|
+
case "doughnut":
|
|
114
|
+
case "bubble":
|
|
115
|
+
headerParts.push(valEl("c:varyColors", 1));
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
return `<${tag}>${headerParts.join("")}`;
|
|
119
|
+
}
|
|
120
|
+
function chartTypeFooter(opts) {
|
|
121
|
+
const tag = opts.threeD ? CHART_TYPE_TAGS_3D[opts.type] : CHART_TYPE_TAGS[opts.type];
|
|
122
|
+
if (NO_AXES_TYPES.has(opts.type)) return `</${tag}>`;
|
|
123
|
+
const axIds = [valEl("c:axId", 10), valEl("c:axId", 20)];
|
|
124
|
+
if (opts.threeD || opts.type === "surface") axIds.push(valEl("c:axId", 30));
|
|
125
|
+
return `${axIds.join("")}</${tag}>`;
|
|
126
|
+
}
|
|
127
|
+
function stringifySeries(index, series, categories, chartType) {
|
|
128
|
+
const parts = [];
|
|
129
|
+
parts.push(valEl("c:idx", index));
|
|
130
|
+
parts.push(valEl("c:order", index));
|
|
131
|
+
parts.push(`<c:tx>${stringifyStrRef([series.name])}</c:tx>`);
|
|
132
|
+
parts.push(emptyEl("c:spPr"));
|
|
133
|
+
if (chartType === "bubble") {
|
|
134
|
+
const bs = series;
|
|
135
|
+
parts.push(`<c:xVal>${stringifyNumRef(bs.xValues)}</c:xVal>`);
|
|
136
|
+
parts.push(`<c:yVal>${stringifyNumRef(bs.yValues)}</c:yVal>`);
|
|
137
|
+
parts.push(`<c:bubbleSize>${stringifyNumRef(bs.bubbleSize)}</c:bubbleSize>`);
|
|
138
|
+
} else if (chartType === "scatter") {
|
|
139
|
+
const s = series;
|
|
140
|
+
parts.push(`<c:xVal>${stringifyStrRef(categories)}</c:xVal>`);
|
|
141
|
+
parts.push(`<c:yVal>${stringifyNumRef(s.values)}</c:yVal>`);
|
|
142
|
+
} else {
|
|
143
|
+
const s = series;
|
|
144
|
+
parts.push(`<c:cat>${stringifyStrRef(categories)}</c:cat>`);
|
|
145
|
+
parts.push(`<c:val>${stringifyNumRef(s.values)}</c:val>`);
|
|
146
|
+
}
|
|
147
|
+
return `<c:ser>${parts.join("")}</c:ser>`;
|
|
148
|
+
}
|
|
149
|
+
function stringifyTitle(title) {
|
|
150
|
+
return `<c:title><c:tx><c:rich><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>${escapeXml(title)}</a:t></a:r></a:p></c:rich></c:tx><c:overlay val="0"/></c:title>`;
|
|
151
|
+
}
|
|
152
|
+
function stringifyLegend() {
|
|
153
|
+
return `<c:legend><c:legendPos val="b"/><c:layout/><c:overlay val="0"/><c:spPr><a:noFill/><a:ln><a:noFill/></a:ln><a:effectLst/></c:spPr><c:txPr><a:bodyPr rot="0" spcFirstLastPara="1" vertOverflow="ellipsis" vert="horz" wrap="square" anchor="ctr" anchorCtr="1"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr lang="en-US"/></a:p></c:txPr></c:legend>`;
|
|
154
|
+
}
|
|
155
|
+
function noFillSpPr() {
|
|
156
|
+
return `<c:spPr><a:noFill/><a:ln><a:noFill/></a:ln><a:effectLst/></c:spPr>`;
|
|
157
|
+
}
|
|
158
|
+
function chartTxPr() {
|
|
159
|
+
return `<c:txPr><a:bodyPr/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr lang="en-US"/></a:p></c:txPr>`;
|
|
160
|
+
}
|
|
161
|
+
function stringifyAxes(chartType, threeD) {
|
|
162
|
+
if (NO_AXES_TYPES.has(chartType)) return "";
|
|
163
|
+
const parts = [];
|
|
164
|
+
if (chartType === "scatter" || chartType === "bubble") {
|
|
165
|
+
parts.push(valAxXml(10, 20));
|
|
166
|
+
parts.push(valAxXml(20, 10));
|
|
167
|
+
} else if (chartType === "stock" || chartType === "surface") {
|
|
168
|
+
parts.push(catAxXml(10, 20));
|
|
169
|
+
parts.push(valAxXml(20, 10));
|
|
170
|
+
if (chartType === "surface") parts.push(serAxXml(30, 10));
|
|
171
|
+
} else {
|
|
172
|
+
parts.push(catAxXml(10, 20));
|
|
173
|
+
parts.push(valAxXml(20, 10));
|
|
174
|
+
if (threeD) parts.push(catAxXml(30, 10));
|
|
175
|
+
}
|
|
176
|
+
return parts.join("");
|
|
177
|
+
}
|
|
178
|
+
function catAxXml(axId, crossAx) {
|
|
179
|
+
return `<c:catAx><c:axId ${attrVal("val", axId)}/><c:scaling><c:orientation val="minMax"/></c:scaling><c:delete val="0"/><c:axPos val="b"/><c:crossAx ${attrVal("val", crossAx)}/><c:crosses val="autoZero"/><c:auto val="1"/><c:lblOffset val="100"/><c:noMultiLvlLbl val="0"/></c:catAx>`;
|
|
180
|
+
}
|
|
181
|
+
function valAxXml(axId, crossAx) {
|
|
182
|
+
return `<c:valAx><c:axId ${attrVal("val", axId)}/><c:scaling><c:orientation val="minMax"/></c:scaling><c:delete val="0"/><c:axPos val="l"/><c:numFmt formatCode="General" sourceLinked="1"/><c:spPr/><c:crossAx ${attrVal("val", crossAx)}/><c:crosses val="autoZero"/></c:valAx>`;
|
|
183
|
+
}
|
|
184
|
+
function serAxXml(axId, crossAx) {
|
|
185
|
+
return `<c:serAx><c:axId ${attrVal("val", axId)}/><c:scaling><c:orientation val="minMax"/></c:scaling><c:delete val="0"/><c:axPos val="b"/><c:numFmt formatCode="General" sourceLinked="1"/><c:spPr/><c:crossAx ${attrVal("val", crossAx)}/><c:crosses val="autoZero"/><c:tickLblSkip val="1"/></c:serAx>`;
|
|
186
|
+
}
|
|
187
|
+
function readStrCache(el) {
|
|
188
|
+
const strRef = findChild(el, "c:strRef");
|
|
189
|
+
if (!strRef) return [];
|
|
190
|
+
const strCache = findChild(strRef, "c:strCache");
|
|
191
|
+
if (!strCache?.elements) return [];
|
|
192
|
+
const result = [];
|
|
193
|
+
for (const pt of strCache.elements) if (pt.name === "c:pt" && pt.elements) {
|
|
194
|
+
const v = pt.elements.find((c) => c.name === "c:v");
|
|
195
|
+
if (v?.text !== void 0) result.push(String(v.text));
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
function readNumCache(el) {
|
|
200
|
+
const numRef = findChild(el, "c:numRef");
|
|
201
|
+
if (!numRef) return [];
|
|
202
|
+
const numCache = findChild(numRef, "c:numCache");
|
|
203
|
+
if (!numCache?.elements) return [];
|
|
204
|
+
const result = [];
|
|
205
|
+
for (const pt of numCache.elements) if (pt.name === "c:pt" && pt.elements) {
|
|
206
|
+
const v = pt.elements.find((c) => c.name === "c:v");
|
|
207
|
+
if (v?.text !== void 0) result.push(Number(v.text));
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
function readSeriesName(serEl) {
|
|
212
|
+
const tx = findChild(serEl, "c:tx");
|
|
213
|
+
if (!tx) return "";
|
|
214
|
+
return readStrCache(tx)[0] ?? "";
|
|
215
|
+
}
|
|
216
|
+
function readTitleText(titleEl) {
|
|
217
|
+
const tx = findChild(titleEl, "c:tx");
|
|
218
|
+
if (!tx?.elements) return void 0;
|
|
219
|
+
for (const child of tx.elements) if (child.name === "c:rich" && child.elements) {
|
|
220
|
+
for (const sub of child.elements) if (sub.name === "a:p" && sub.elements) {
|
|
221
|
+
for (const r of sub.elements) if (r.name === "a:r" && r.elements) {
|
|
222
|
+
for (const t of r.elements) if (t.name === "a:t" && t.text !== void 0) return String(t.text);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const chartSpaceDesc = {
|
|
228
|
+
kind: "custom",
|
|
229
|
+
stringify(opts, _ctx) {
|
|
230
|
+
const parts = [];
|
|
231
|
+
parts.push(`<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">`);
|
|
232
|
+
parts.push(valEl("c:date1904", 0));
|
|
233
|
+
parts.push(valEl("c:lang", "en-US"));
|
|
234
|
+
parts.push(valEl("c:roundedCorners", 0));
|
|
235
|
+
if (opts.style !== void 0) parts.push(valEl("c:style", opts.style));
|
|
236
|
+
parts.push("<c:chart>");
|
|
237
|
+
if (opts.title) parts.push(stringifyTitle(opts.title));
|
|
238
|
+
parts.push(valEl("c:autoTitleDeleted", 0));
|
|
239
|
+
parts.push("<c:plotArea><c:layout/>");
|
|
240
|
+
parts.push(chartTypeHeader(opts));
|
|
241
|
+
const categories = opts.categories ?? [];
|
|
242
|
+
for (let i = 0; i < opts.series.length; i++) parts.push(stringifySeries(i, opts.series[i], categories, opts.type));
|
|
243
|
+
parts.push(chartTypeFooter(opts));
|
|
244
|
+
parts.push(stringifyAxes(opts.type, opts.threeD));
|
|
245
|
+
parts.push("</c:plotArea>");
|
|
246
|
+
if (opts.showLegend !== false) parts.push(stringifyLegend());
|
|
247
|
+
parts.push("</c:chart>");
|
|
248
|
+
parts.push(noFillSpPr());
|
|
249
|
+
parts.push(chartTxPr());
|
|
250
|
+
parts.push("</c:chartSpace>");
|
|
251
|
+
return parts.join("");
|
|
252
|
+
},
|
|
253
|
+
parse(el, _ctx) {
|
|
254
|
+
const result = {};
|
|
255
|
+
const styleEl = findChild(el, "c:style");
|
|
256
|
+
if (styleEl?.attributes?.["val"] !== void 0) result.style = Number(styleEl.attributes["val"]);
|
|
257
|
+
const chart = findChild(el, "c:chart");
|
|
258
|
+
if (!chart) return result;
|
|
259
|
+
const titleEl = findChild(chart, "c:title");
|
|
260
|
+
if (titleEl) {
|
|
261
|
+
const title = readTitleText(titleEl);
|
|
262
|
+
if (title !== void 0) result.title = title;
|
|
263
|
+
}
|
|
264
|
+
const plotArea = findChild(chart, "c:plotArea");
|
|
265
|
+
if (plotArea?.elements) {
|
|
266
|
+
let detectedType;
|
|
267
|
+
let threeD = false;
|
|
268
|
+
for (const child of plotArea.elements) {
|
|
269
|
+
if (!child.name) continue;
|
|
270
|
+
const mapping = TAG_TO_CHART_TYPE[child.name];
|
|
271
|
+
if (mapping) {
|
|
272
|
+
detectedType = mapping.type;
|
|
273
|
+
threeD = mapping.threeD ?? false;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (detectedType) {
|
|
278
|
+
result.type = detectedType;
|
|
279
|
+
if (threeD) result.threeD = true;
|
|
280
|
+
}
|
|
281
|
+
const seriesEls = children(plotArea, "c:ser");
|
|
282
|
+
if (seriesEls.length > 0) if (detectedType === "bubble") {
|
|
283
|
+
const bubbleSeries = [];
|
|
284
|
+
for (const serEl of seriesEls) {
|
|
285
|
+
const name = readSeriesName(serEl);
|
|
286
|
+
const xVal = findChild(serEl, "c:xVal");
|
|
287
|
+
const yVal = findChild(serEl, "c:yVal");
|
|
288
|
+
const bubbleSize = findChild(serEl, "c:bubbleSize");
|
|
289
|
+
bubbleSeries.push({
|
|
290
|
+
name,
|
|
291
|
+
xValues: xVal ? readNumCache(xVal) : [],
|
|
292
|
+
yValues: yVal ? readNumCache(yVal) : [],
|
|
293
|
+
bubbleSize: bubbleSize ? readNumCache(bubbleSize) : []
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
result.series = bubbleSeries;
|
|
297
|
+
} else {
|
|
298
|
+
const chartSeries = [];
|
|
299
|
+
let categories;
|
|
300
|
+
for (const serEl of seriesEls) {
|
|
301
|
+
const name = readSeriesName(serEl);
|
|
302
|
+
if (!categories) {
|
|
303
|
+
const catEl = findChild(serEl, "c:cat") ?? findChild(serEl, "c:xVal");
|
|
304
|
+
if (catEl) categories = readStrCache(catEl);
|
|
305
|
+
}
|
|
306
|
+
const valEl = findChild(serEl, "c:val") ?? findChild(serEl, "c:yVal");
|
|
307
|
+
const values = valEl ? readNumCache(valEl) : [];
|
|
308
|
+
chartSeries.push({
|
|
309
|
+
name,
|
|
310
|
+
values
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
result.series = chartSeries;
|
|
314
|
+
if (categories?.length) result.categories = categories;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (!findChild(chart, "c:legend")) result.showLegend = false;
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/chart/types.ts
|
|
323
|
+
const TrendlineType = {
|
|
324
|
+
EXP: "exp",
|
|
325
|
+
LINEAR: "linear",
|
|
326
|
+
LOG: "log",
|
|
327
|
+
MOVING_AVG: "movingAvg",
|
|
328
|
+
POLY: "poly",
|
|
329
|
+
POWER: "power"
|
|
330
|
+
};
|
|
331
|
+
const ErrorBarDirection = {
|
|
332
|
+
BOTH: "both",
|
|
333
|
+
X: "x",
|
|
334
|
+
Y: "y"
|
|
335
|
+
};
|
|
336
|
+
const ErrorBarType = {
|
|
337
|
+
BOTH: "both",
|
|
338
|
+
MINUS: "minus",
|
|
339
|
+
PLUS: "plus"
|
|
340
|
+
};
|
|
341
|
+
const ErrorValueType = {
|
|
342
|
+
CUST: "cust",
|
|
343
|
+
FIXED: "fixedVal",
|
|
344
|
+
PERCENTAGE: "percentage",
|
|
345
|
+
STD_DEV: "stdDev",
|
|
346
|
+
STD_ERR: "stdErr"
|
|
347
|
+
};
|
|
348
|
+
const DataLabelPosition = {
|
|
349
|
+
BEST_FIT: "bestFit",
|
|
350
|
+
B: "b",
|
|
351
|
+
CTRL: "ctr",
|
|
352
|
+
IN_BASE: "inBase",
|
|
353
|
+
IN_END: "inEnd",
|
|
354
|
+
L: "l",
|
|
355
|
+
OUT_END: "outEnd",
|
|
356
|
+
R: "r",
|
|
357
|
+
T: "t"
|
|
358
|
+
};
|
|
359
|
+
const TimeUnit = {
|
|
360
|
+
DAYS: "days",
|
|
361
|
+
MONTHS: "months",
|
|
362
|
+
YEARS: "years"
|
|
363
|
+
};
|
|
364
|
+
//#endregion
|
|
365
|
+
export { TimeUnit as a, ChartCollection as c, ErrorValueType as i, ErrorBarDirection as n, TrendlineType as o, ErrorBarType as r, chartSpaceDesc as s, DataLabelPosition as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as TextSpec, a as enumEncode, b as ReadContext, c as DescriptorBuilder, d as ChildSpec, f as ChildrenSpec, g as ElementDescriptor, h as Descriptor, i as enumDecode, l as element, m as CustomDescriptor, n as boolDecode, o as parse, p as ContentSpec, r as boolEncode, s as stringify, t as DescriptorRegistry, u as AttrSpec, v as UnionSpec, x as WriteContext, y as UnionVariant } from "../index-BI-1SKm5.mjs";
|
|
2
|
+
export { type AttrSpec, type ChildSpec, type ChildrenSpec, type ContentSpec, type CustomDescriptor, type Descriptor, DescriptorBuilder, DescriptorRegistry, type ElementDescriptor, type ReadContext, type TextSpec, type UnionSpec, type UnionVariant, type WriteContext, boolDecode, boolEncode, element, enumDecode, enumEncode, parse, stringify };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as enumEncode, c as DescriptorBuilder, i as enumDecode, l as element, n as boolDecode, o as parse, r as boolEncode, s as stringify, t as DescriptorRegistry } from "../descriptor-DKmR7pw-.mjs";
|
|
2
|
+
export { DescriptorBuilder, DescriptorRegistry, boolDecode, boolEncode, element, enumDecode, enumEncode, parse, stringify };
|