ooxml-core 0.20.0 → 0.21.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 +21 -43
- package/dist/chart/axis-nice.d.ts +97 -0
- package/dist/chart/axis-nice.d.ts.map +1 -0
- package/dist/chart/histogram-binning.d.ts +40 -0
- package/dist/chart/histogram-binning.d.ts.map +1 -0
- package/dist/chart/index.cjs +167 -0
- package/dist/chart/index.d.ts +2 -0
- package/dist/chart/index.d.ts.map +1 -1
- package/dist/chart/index.mjs +162 -1
- package/dist/index.cjs +167 -0
- package/dist/index.mjs +167 -0
- package/dist/pptx/automation/index.cjs +1572 -863
- package/dist/pptx/automation/index.d.ts +4 -3
- package/dist/pptx/automation/index.d.ts.map +1 -1
- package/dist/pptx/automation/index.mjs +1572 -863
- package/dist/pptx/chunks/color-ref-BM66NGFP.d.ts +42 -0
- package/dist/pptx/chunks/color-ref-BM66NGFP.d.ts.map +1 -0
- package/dist/pptx/chunks/{index-D0yGoLyw.d.ts → index-CcQTCBnT.d.ts} +63 -479
- package/dist/pptx/chunks/index-CcQTCBnT.d.ts.map +1 -0
- package/dist/pptx/chunks/{index-BtBj3VG1.d.ts → index-DHoPgFcH.d.ts} +529 -11
- package/dist/pptx/chunks/index-DHoPgFcH.d.ts.map +1 -0
- package/dist/pptx/chunks/{text-operations-GuisjlbR.d.ts → text-operations-BzdehTeY.d.ts} +50 -51
- package/dist/pptx/chunks/text-operations-BzdehTeY.d.ts.map +1 -0
- package/dist/pptx/cli/index.cjs +1204 -489
- package/dist/pptx/cli/index.d.ts +1 -1
- package/dist/pptx/cli/index.mjs +1204 -489
- package/dist/pptx/converter/index.cjs +8 -5
- package/dist/pptx/converter/index.d.ts +1 -1
- package/dist/pptx/converter/index.mjs +8 -5
- package/dist/pptx/index.cjs +1699 -989
- package/dist/pptx/index.d.ts +5 -4
- package/dist/pptx/index.mjs +1698 -990
- package/dist/pptx/ui/index.cjs +510 -0
- package/dist/pptx/ui/index.d.ts +80 -0
- package/dist/pptx/ui/index.d.ts.map +1 -0
- package/dist/pptx/ui/index.mjs +499 -0
- package/package.json +15 -4
- package/dist/pptx/chunks/index-BtBj3VG1.d.ts.map +0 -1
- package/dist/pptx/chunks/index-D0yGoLyw.d.ts.map +0 -1
- package/dist/pptx/chunks/text-operations-GuisjlbR.d.ts.map +0 -1
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
// src/color/color-primitives.ts
|
|
2
|
+
function clampUnitInterval(value) {
|
|
3
|
+
return Math.min(1, Math.max(0, value));
|
|
4
|
+
}
|
|
5
|
+
function normalizeHexColor(value, fallback = "#111827") {
|
|
6
|
+
if (!value || value === "transparent") {
|
|
7
|
+
return fallback;
|
|
8
|
+
}
|
|
9
|
+
const candidate = value.startsWith("#") ? value : `#${value}`;
|
|
10
|
+
return /^#[0-9A-Fa-f]{6}$/.test(candidate) ? candidate : fallback;
|
|
11
|
+
}
|
|
12
|
+
function hexToRgbChannels(color) {
|
|
13
|
+
const normalized = color.replace("#", "");
|
|
14
|
+
if (!/^[0-9a-fA-F]{6}$/.test(normalized)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
r: Number.parseInt(normalized.slice(0, 2), 16),
|
|
19
|
+
g: Number.parseInt(normalized.slice(2, 4), 16),
|
|
20
|
+
b: Number.parseInt(normalized.slice(4, 6), 16)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function percentDivisorFor(text) {
|
|
24
|
+
return text.endsWith("%") ? 100 : 1e5;
|
|
25
|
+
}
|
|
26
|
+
function parseOoxmlPercent(value) {
|
|
27
|
+
const text = String(value ?? "").trim();
|
|
28
|
+
const divisor = percentDivisorFor(text);
|
|
29
|
+
const magnitude = Number.parseFloat(divisor === 100 ? text.slice(0, -1) : text);
|
|
30
|
+
if (!Number.isFinite(magnitude)) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
return magnitude / divisor;
|
|
34
|
+
}
|
|
35
|
+
function parseDrawingPercent(value) {
|
|
36
|
+
const parsed = parseOoxmlPercent(value);
|
|
37
|
+
return parsed === void 0 ? void 0 : clampUnitInterval(parsed);
|
|
38
|
+
}
|
|
39
|
+
function toHex(value) {
|
|
40
|
+
return Math.min(255, Math.max(0, Math.round(value))).toString(16).padStart(2, "0").toUpperCase();
|
|
41
|
+
}
|
|
42
|
+
function rgbToHsl(r, g, b) {
|
|
43
|
+
const rN = r / 255;
|
|
44
|
+
const gN = g / 255;
|
|
45
|
+
const bN = b / 255;
|
|
46
|
+
const cMax = Math.max(rN, gN, bN);
|
|
47
|
+
const cMin = Math.min(rN, gN, bN);
|
|
48
|
+
const delta = cMax - cMin;
|
|
49
|
+
const l = (cMax + cMin) / 2;
|
|
50
|
+
let s = 0;
|
|
51
|
+
if (delta !== 0) {
|
|
52
|
+
s = delta / (1 - Math.abs(2 * l - 1));
|
|
53
|
+
}
|
|
54
|
+
let h = 0;
|
|
55
|
+
if (delta !== 0) {
|
|
56
|
+
if (cMax === rN) {
|
|
57
|
+
h = 60 * ((gN - bN) / delta % 6);
|
|
58
|
+
} else if (cMax === gN) {
|
|
59
|
+
h = 60 * ((bN - rN) / delta + 2);
|
|
60
|
+
} else {
|
|
61
|
+
h = 60 * ((rN - gN) / delta + 4);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (h < 0) {
|
|
65
|
+
h += 360;
|
|
66
|
+
}
|
|
67
|
+
return { h, s: clampUnitInterval(s), l: clampUnitInterval(l) };
|
|
68
|
+
}
|
|
69
|
+
function hslToRgb(h, s, l) {
|
|
70
|
+
const sC = clampUnitInterval(s);
|
|
71
|
+
const lC = clampUnitInterval(l);
|
|
72
|
+
const hN = (h % 360 + 360) % 360;
|
|
73
|
+
const c = (1 - Math.abs(2 * lC - 1)) * sC;
|
|
74
|
+
const x = c * (1 - Math.abs(hN / 60 % 2 - 1));
|
|
75
|
+
const m = lC - c / 2;
|
|
76
|
+
let rP = 0;
|
|
77
|
+
let gP = 0;
|
|
78
|
+
let bP = 0;
|
|
79
|
+
if (hN < 60) {
|
|
80
|
+
rP = c;
|
|
81
|
+
gP = x;
|
|
82
|
+
bP = 0;
|
|
83
|
+
} else if (hN < 120) {
|
|
84
|
+
rP = x;
|
|
85
|
+
gP = c;
|
|
86
|
+
bP = 0;
|
|
87
|
+
} else if (hN < 180) {
|
|
88
|
+
rP = 0;
|
|
89
|
+
gP = c;
|
|
90
|
+
bP = x;
|
|
91
|
+
} else if (hN < 240) {
|
|
92
|
+
rP = 0;
|
|
93
|
+
gP = x;
|
|
94
|
+
bP = c;
|
|
95
|
+
} else if (hN < 300) {
|
|
96
|
+
rP = x;
|
|
97
|
+
gP = 0;
|
|
98
|
+
bP = c;
|
|
99
|
+
} else {
|
|
100
|
+
rP = c;
|
|
101
|
+
gP = 0;
|
|
102
|
+
bP = x;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
r: Math.round((rP + m) * 255),
|
|
106
|
+
g: Math.round((gP + m) * 255),
|
|
107
|
+
b: Math.round((bP + m) * 255)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function parseDrawingFraction(value) {
|
|
111
|
+
return parseOoxmlPercent(value);
|
|
112
|
+
}
|
|
113
|
+
function parseDrawingHueDegrees(value) {
|
|
114
|
+
const parsed = Number.parseFloat(String(value ?? "").trim());
|
|
115
|
+
if (!Number.isFinite(parsed)) {
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
return parsed / 6e4;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/color/color-linear.ts
|
|
122
|
+
function srgb255ToLinear(channel) {
|
|
123
|
+
const c = clampUnitInterval(channel / 255);
|
|
124
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
125
|
+
}
|
|
126
|
+
function linearToSrgb255(linear) {
|
|
127
|
+
const c = clampUnitInterval(linear);
|
|
128
|
+
return 255 * (c <= 31308e-7 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/pptx/core/color/color-transforms.ts
|
|
132
|
+
function applyDrawingColorTransforms(baseColor, colorNode) {
|
|
133
|
+
const rgb = hexToRgbChannels(baseColor);
|
|
134
|
+
if (!rgb) {
|
|
135
|
+
return baseColor;
|
|
136
|
+
}
|
|
137
|
+
let r = rgb.r;
|
|
138
|
+
let g = rgb.g;
|
|
139
|
+
let b = rgb.b;
|
|
140
|
+
const getVal = (key) => colorNode[key]?.["@_val"];
|
|
141
|
+
if (colorNode["a:gamma"] !== void 0) {
|
|
142
|
+
const out = applySrgbGammaEncode(r, g, b);
|
|
143
|
+
r = out.r;
|
|
144
|
+
g = out.g;
|
|
145
|
+
b = out.b;
|
|
146
|
+
}
|
|
147
|
+
if (colorNode["a:invGamma"] !== void 0) {
|
|
148
|
+
const out = applySrgbGammaDecode(r, g, b);
|
|
149
|
+
r = out.r;
|
|
150
|
+
g = out.g;
|
|
151
|
+
b = out.b;
|
|
152
|
+
}
|
|
153
|
+
if (colorNode["a:comp"] !== void 0) {
|
|
154
|
+
const hsl = rgbToHsl(r, g, b);
|
|
155
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
156
|
+
const out = hslToRgb(hsl.h, hsl.s, hsl.l);
|
|
157
|
+
r = out.r;
|
|
158
|
+
g = out.g;
|
|
159
|
+
b = out.b;
|
|
160
|
+
}
|
|
161
|
+
if (colorNode["a:inv"] !== void 0) {
|
|
162
|
+
r = 255 - r;
|
|
163
|
+
g = 255 - g;
|
|
164
|
+
b = 255 - b;
|
|
165
|
+
}
|
|
166
|
+
if (colorNode["a:gray"] !== void 0) {
|
|
167
|
+
const gray = Math.round(0.299 * r + 0.587 * g + 0.114 * b);
|
|
168
|
+
r = gray;
|
|
169
|
+
g = gray;
|
|
170
|
+
b = gray;
|
|
171
|
+
}
|
|
172
|
+
const shade = parseDrawingPercent(getVal("a:shade"));
|
|
173
|
+
if (shade !== void 0) {
|
|
174
|
+
r = linearToSrgb255(srgb255ToLinear(r) * shade);
|
|
175
|
+
g = linearToSrgb255(srgb255ToLinear(g) * shade);
|
|
176
|
+
b = linearToSrgb255(srgb255ToLinear(b) * shade);
|
|
177
|
+
}
|
|
178
|
+
const tint = parseDrawingPercent(getVal("a:tint"));
|
|
179
|
+
if (tint !== void 0) {
|
|
180
|
+
r = linearToSrgb255(1 - (1 - srgb255ToLinear(r)) * tint);
|
|
181
|
+
g = linearToSrgb255(1 - (1 - srgb255ToLinear(g)) * tint);
|
|
182
|
+
b = linearToSrgb255(1 - (1 - srgb255ToLinear(b)) * tint);
|
|
183
|
+
}
|
|
184
|
+
const hslKeys = [
|
|
185
|
+
"a:hue",
|
|
186
|
+
"a:hueMod",
|
|
187
|
+
"a:hueOff",
|
|
188
|
+
"a:sat",
|
|
189
|
+
"a:satMod",
|
|
190
|
+
"a:satOff",
|
|
191
|
+
"a:lum",
|
|
192
|
+
"a:lumMod",
|
|
193
|
+
"a:lumOff"
|
|
194
|
+
];
|
|
195
|
+
const hasHsl = hslKeys.some((k) => colorNode[k] !== void 0);
|
|
196
|
+
if (hasHsl) {
|
|
197
|
+
const hsl = rgbToHsl(r, g, b);
|
|
198
|
+
const hueAbs = parseDrawingHueDegrees(getVal("a:hue"));
|
|
199
|
+
if (hueAbs !== void 0) {
|
|
200
|
+
hsl.h = (hueAbs % 360 + 360) % 360;
|
|
201
|
+
}
|
|
202
|
+
const hueMod = parseDrawingFraction(getVal("a:hueMod"));
|
|
203
|
+
if (hueMod !== void 0) {
|
|
204
|
+
hsl.h = (hsl.h * hueMod % 360 + 360) % 360;
|
|
205
|
+
}
|
|
206
|
+
const hueOff = parseDrawingHueDegrees(getVal("a:hueOff"));
|
|
207
|
+
if (hueOff !== void 0) {
|
|
208
|
+
hsl.h = ((hsl.h + hueOff) % 360 + 360) % 360;
|
|
209
|
+
}
|
|
210
|
+
const satAbs = parseDrawingFraction(getVal("a:sat"));
|
|
211
|
+
if (satAbs !== void 0) {
|
|
212
|
+
hsl.s = clampUnitInterval(satAbs);
|
|
213
|
+
}
|
|
214
|
+
const satMod = parseDrawingFraction(getVal("a:satMod"));
|
|
215
|
+
if (satMod !== void 0) {
|
|
216
|
+
hsl.s = clampUnitInterval(hsl.s * satMod);
|
|
217
|
+
}
|
|
218
|
+
const satOff = parseDrawingFraction(getVal("a:satOff"));
|
|
219
|
+
if (satOff !== void 0) {
|
|
220
|
+
hsl.s = clampUnitInterval(hsl.s + satOff);
|
|
221
|
+
}
|
|
222
|
+
const lumAbs = parseDrawingFraction(getVal("a:lum"));
|
|
223
|
+
if (lumAbs !== void 0) {
|
|
224
|
+
hsl.l = clampUnitInterval(lumAbs);
|
|
225
|
+
}
|
|
226
|
+
const lumMod = parseDrawingFraction(getVal("a:lumMod"));
|
|
227
|
+
if (lumMod !== void 0) {
|
|
228
|
+
hsl.l = clampUnitInterval(hsl.l * lumMod);
|
|
229
|
+
}
|
|
230
|
+
const lumOff = parseDrawingFraction(getVal("a:lumOff"));
|
|
231
|
+
if (lumOff !== void 0) {
|
|
232
|
+
hsl.l = clampUnitInterval(hsl.l + lumOff);
|
|
233
|
+
}
|
|
234
|
+
const out = hslToRgb(hsl.h, hsl.s, hsl.l);
|
|
235
|
+
r = out.r;
|
|
236
|
+
g = out.g;
|
|
237
|
+
b = out.b;
|
|
238
|
+
}
|
|
239
|
+
const redAbs = parseDrawingFraction(getVal("a:red"));
|
|
240
|
+
if (redAbs !== void 0) {
|
|
241
|
+
r = Math.round(clampUnitInterval(redAbs) * 255);
|
|
242
|
+
}
|
|
243
|
+
const redMod = parseDrawingFraction(getVal("a:redMod"));
|
|
244
|
+
if (redMod !== void 0) {
|
|
245
|
+
r = Math.min(255, Math.max(0, Math.round(r * redMod)));
|
|
246
|
+
}
|
|
247
|
+
const redOff = parseDrawingFraction(getVal("a:redOff"));
|
|
248
|
+
if (redOff !== void 0) {
|
|
249
|
+
r = Math.min(255, Math.max(0, Math.round(r + 255 * redOff)));
|
|
250
|
+
}
|
|
251
|
+
const greenAbs = parseDrawingFraction(getVal("a:green"));
|
|
252
|
+
if (greenAbs !== void 0) {
|
|
253
|
+
g = Math.round(clampUnitInterval(greenAbs) * 255);
|
|
254
|
+
}
|
|
255
|
+
const greenMod = parseDrawingFraction(getVal("a:greenMod"));
|
|
256
|
+
if (greenMod !== void 0) {
|
|
257
|
+
g = Math.min(255, Math.max(0, Math.round(g * greenMod)));
|
|
258
|
+
}
|
|
259
|
+
const greenOff = parseDrawingFraction(getVal("a:greenOff"));
|
|
260
|
+
if (greenOff !== void 0) {
|
|
261
|
+
g = Math.min(255, Math.max(0, Math.round(g + 255 * greenOff)));
|
|
262
|
+
}
|
|
263
|
+
const blueAbs = parseDrawingFraction(getVal("a:blue"));
|
|
264
|
+
if (blueAbs !== void 0) {
|
|
265
|
+
b = Math.round(clampUnitInterval(blueAbs) * 255);
|
|
266
|
+
}
|
|
267
|
+
const blueMod = parseDrawingFraction(getVal("a:blueMod"));
|
|
268
|
+
if (blueMod !== void 0) {
|
|
269
|
+
b = Math.min(255, Math.max(0, Math.round(b * blueMod)));
|
|
270
|
+
}
|
|
271
|
+
const blueOff = parseDrawingFraction(getVal("a:blueOff"));
|
|
272
|
+
if (blueOff !== void 0) {
|
|
273
|
+
b = Math.min(255, Math.max(0, Math.round(b + 255 * blueOff)));
|
|
274
|
+
}
|
|
275
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
276
|
+
}
|
|
277
|
+
function srgbEncodeChannel(channel) {
|
|
278
|
+
const linear = Math.min(1, Math.max(0, channel / 255));
|
|
279
|
+
const companded = linear <= 31308e-7 ? 12.92 * linear : 1.055 * linear ** (1 / 2.4) - 0.055;
|
|
280
|
+
return Math.min(255, Math.max(0, Math.round(companded * 255)));
|
|
281
|
+
}
|
|
282
|
+
function srgbDecodeChannel(channel) {
|
|
283
|
+
const companded = Math.min(1, Math.max(0, channel / 255));
|
|
284
|
+
const linear = companded <= 0.04045 ? companded / 12.92 : ((companded + 0.055) / 1.055) ** 2.4;
|
|
285
|
+
return Math.min(255, Math.max(0, Math.round(linear * 255)));
|
|
286
|
+
}
|
|
287
|
+
function applySrgbGammaEncode(r, g, b) {
|
|
288
|
+
return { r: srgbEncodeChannel(r), g: srgbEncodeChannel(g), b: srgbEncodeChannel(b) };
|
|
289
|
+
}
|
|
290
|
+
function applySrgbGammaDecode(r, g, b) {
|
|
291
|
+
return { r: srgbDecodeChannel(r), g: srgbDecodeChannel(g), b: srgbDecodeChannel(b) };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/pptx/core/color/theme-color-ref.ts
|
|
295
|
+
var DEFAULT_ALIASES = {
|
|
296
|
+
bg1: "lt1",
|
|
297
|
+
tx1: "dk1",
|
|
298
|
+
bg2: "lt2",
|
|
299
|
+
tx2: "dk2"
|
|
300
|
+
};
|
|
301
|
+
function percentVal(fraction) {
|
|
302
|
+
return String(Math.round(fraction * 1e5));
|
|
303
|
+
}
|
|
304
|
+
function themeColorRefToXml(ref) {
|
|
305
|
+
const node = { "@_val": ref.scheme };
|
|
306
|
+
if (ref.tint !== void 0) {
|
|
307
|
+
node["a:tint"] = { "@_val": percentVal(ref.tint) };
|
|
308
|
+
}
|
|
309
|
+
if (ref.shade !== void 0) {
|
|
310
|
+
node["a:shade"] = { "@_val": percentVal(ref.shade) };
|
|
311
|
+
}
|
|
312
|
+
if (ref.lumMod !== void 0) {
|
|
313
|
+
node["a:lumMod"] = { "@_val": percentVal(ref.lumMod) };
|
|
314
|
+
}
|
|
315
|
+
if (ref.lumOff !== void 0) {
|
|
316
|
+
node["a:lumOff"] = { "@_val": percentVal(ref.lumOff) };
|
|
317
|
+
}
|
|
318
|
+
if (ref.alpha !== void 0) {
|
|
319
|
+
node["a:alpha"] = { "@_val": percentVal(ref.alpha) };
|
|
320
|
+
}
|
|
321
|
+
return node;
|
|
322
|
+
}
|
|
323
|
+
function resolveThemeColorRef(ref, themeColorMap) {
|
|
324
|
+
if (!themeColorMap) {
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
const base = themeColorMap[ref.scheme] ?? themeColorMap[DEFAULT_ALIASES[ref.scheme] ?? ""];
|
|
328
|
+
if (!base) {
|
|
329
|
+
return void 0;
|
|
330
|
+
}
|
|
331
|
+
const node = themeColorRefToXml(ref);
|
|
332
|
+
delete node["a:alpha"];
|
|
333
|
+
return normalizeHexColor(
|
|
334
|
+
applyDrawingColorTransforms(normalizeHexColor(base), node)
|
|
335
|
+
).toLowerCase();
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/pptx/core/types/color-ref.ts
|
|
339
|
+
var THEME_COLOR_PALETTE_COLUMNS = [
|
|
340
|
+
"bg1",
|
|
341
|
+
"tx1",
|
|
342
|
+
"bg2",
|
|
343
|
+
"tx2",
|
|
344
|
+
"accent1",
|
|
345
|
+
"accent2",
|
|
346
|
+
"accent3",
|
|
347
|
+
"accent4",
|
|
348
|
+
"accent5",
|
|
349
|
+
"accent6"
|
|
350
|
+
];
|
|
351
|
+
|
|
352
|
+
// src/pptx/ui/theme-color-swatches.ts
|
|
353
|
+
var COLUMN_LABELS = {
|
|
354
|
+
bg1: "Background 1",
|
|
355
|
+
tx1: "Text 1",
|
|
356
|
+
bg2: "Background 2",
|
|
357
|
+
tx2: "Text 2",
|
|
358
|
+
accent1: "Accent 1",
|
|
359
|
+
accent2: "Accent 2",
|
|
360
|
+
accent3: "Accent 3",
|
|
361
|
+
accent4: "Accent 4",
|
|
362
|
+
accent5: "Accent 5",
|
|
363
|
+
accent6: "Accent 6",
|
|
364
|
+
dk1: "Text 1",
|
|
365
|
+
lt1: "Background 1",
|
|
366
|
+
dk2: "Text 2",
|
|
367
|
+
lt2: "Background 2",
|
|
368
|
+
hlink: "Hyperlink",
|
|
369
|
+
folHlink: "Followed Hyperlink"
|
|
370
|
+
};
|
|
371
|
+
function lighter(percent) {
|
|
372
|
+
return { kind: "lighter", percent };
|
|
373
|
+
}
|
|
374
|
+
function darker(percent) {
|
|
375
|
+
return { kind: "darker", percent };
|
|
376
|
+
}
|
|
377
|
+
function themeColorVariantsForLuminance(l) {
|
|
378
|
+
if (l < 0.05) {
|
|
379
|
+
return [lighter(50), lighter(35), lighter(25), lighter(15), lighter(5)];
|
|
380
|
+
}
|
|
381
|
+
if (l < 0.25) {
|
|
382
|
+
return [lighter(90), lighter(75), lighter(50), lighter(25), lighter(10)];
|
|
383
|
+
}
|
|
384
|
+
if (l < 0.75) {
|
|
385
|
+
return [lighter(80), lighter(60), lighter(40), darker(25), darker(50)];
|
|
386
|
+
}
|
|
387
|
+
if (l < 0.95) {
|
|
388
|
+
return [darker(10), darker(25), darker(50), darker(75), darker(90)];
|
|
389
|
+
}
|
|
390
|
+
return [darker(5), darker(15), darker(25), darker(35), darker(50)];
|
|
391
|
+
}
|
|
392
|
+
function themeColorVariantToRef(scheme, variant) {
|
|
393
|
+
const fraction = variant.percent / 100;
|
|
394
|
+
const lumMod = Math.round((1 - fraction) * 1e5) / 1e5;
|
|
395
|
+
return variant.kind === "lighter" ? { scheme, lumMod, lumOff: fraction } : { scheme, lumMod };
|
|
396
|
+
}
|
|
397
|
+
function describeThemeColorSwatch(ref, variant) {
|
|
398
|
+
const column = COLUMN_LABELS[ref.scheme] ?? ref.scheme;
|
|
399
|
+
if (!variant) {
|
|
400
|
+
return column;
|
|
401
|
+
}
|
|
402
|
+
const word = variant.kind === "lighter" ? "Lighter" : "Darker";
|
|
403
|
+
return `${column}, ${word} ${variant.percent}%`;
|
|
404
|
+
}
|
|
405
|
+
function themeColorVariantOfRef(ref) {
|
|
406
|
+
if (ref.lumMod === void 0 || ref.tint !== void 0 || ref.shade !== void 0) {
|
|
407
|
+
return void 0;
|
|
408
|
+
}
|
|
409
|
+
const percent = Math.round((1 - ref.lumMod) * 100);
|
|
410
|
+
if (ref.lumOff !== void 0) {
|
|
411
|
+
return Math.round(ref.lumOff * 100) === percent ? lighter(percent) : void 0;
|
|
412
|
+
}
|
|
413
|
+
return darker(percent);
|
|
414
|
+
}
|
|
415
|
+
function buildThemeColorSwatchGrid(themeColorMap) {
|
|
416
|
+
if (!themeColorMap) {
|
|
417
|
+
return [];
|
|
418
|
+
}
|
|
419
|
+
const columns = [];
|
|
420
|
+
for (const scheme of THEME_COLOR_PALETTE_COLUMNS) {
|
|
421
|
+
const baseRef = { scheme };
|
|
422
|
+
const baseHex = resolveThemeColorRef(baseRef, themeColorMap);
|
|
423
|
+
const rgb = baseHex ? hexToRgbChannels(baseHex) : null;
|
|
424
|
+
if (!baseHex || !rgb) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const { l } = rgbToHsl(rgb.r, rgb.g, rgb.b);
|
|
428
|
+
const variants = [];
|
|
429
|
+
for (const variant of themeColorVariantsForLuminance(l)) {
|
|
430
|
+
const ref = themeColorVariantToRef(scheme, variant);
|
|
431
|
+
const hex = resolveThemeColorRef(ref, themeColorMap);
|
|
432
|
+
if (hex) {
|
|
433
|
+
variants.push({ ref, hex, label: describeThemeColorSwatch(ref, variant), variant });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
columns.push({
|
|
437
|
+
scheme,
|
|
438
|
+
base: {
|
|
439
|
+
ref: baseRef,
|
|
440
|
+
hex: baseHex,
|
|
441
|
+
label: describeThemeColorSwatch(baseRef, void 0),
|
|
442
|
+
variant: void 0
|
|
443
|
+
},
|
|
444
|
+
variants
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return columns;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/pptx/ui/theme-color-picker-state.ts
|
|
451
|
+
function themeColorRefsEqual(a, b) {
|
|
452
|
+
if (!a || !b) {
|
|
453
|
+
return a === b;
|
|
454
|
+
}
|
|
455
|
+
return a.scheme === b.scheme && a.lumMod === b.lumMod && a.lumOff === b.lumOff && a.tint === b.tint && a.shade === b.shade;
|
|
456
|
+
}
|
|
457
|
+
function findSelectedThemeSwatch(columns, ref, hex) {
|
|
458
|
+
if (ref) {
|
|
459
|
+
for (const column of columns) {
|
|
460
|
+
const swatches = [column.base, ...column.variants];
|
|
461
|
+
const match = swatches.find((swatch) => themeColorRefsEqual(swatch.ref, ref));
|
|
462
|
+
if (match) {
|
|
463
|
+
return match;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return void 0;
|
|
467
|
+
}
|
|
468
|
+
if (!hex) {
|
|
469
|
+
return void 0;
|
|
470
|
+
}
|
|
471
|
+
const normalized = hex.trim().toLowerCase();
|
|
472
|
+
for (const column of columns) {
|
|
473
|
+
const swatches = [column.base, ...column.variants];
|
|
474
|
+
const match = swatches.find((swatch) => swatch.hex.toLowerCase() === normalized);
|
|
475
|
+
if (match) {
|
|
476
|
+
return match;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return void 0;
|
|
480
|
+
}
|
|
481
|
+
function themeSwatchCommit(swatch) {
|
|
482
|
+
return { hex: swatch.hex, ref: swatch.ref };
|
|
483
|
+
}
|
|
484
|
+
function customColorCommit(hex) {
|
|
485
|
+
return { hex, ref: void 0 };
|
|
486
|
+
}
|
|
487
|
+
function themeColorSwatchRows(columns) {
|
|
488
|
+
if (columns.length === 0) {
|
|
489
|
+
return [];
|
|
490
|
+
}
|
|
491
|
+
const variantRowCount = Math.max(...columns.map((column) => column.variants.length));
|
|
492
|
+
const rows = [columns.map((column) => column.base)];
|
|
493
|
+
for (let i = 0; i < variantRowCount; i++) {
|
|
494
|
+
rows.push(columns.map((column) => column.variants[i]));
|
|
495
|
+
}
|
|
496
|
+
return rows;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export { buildThemeColorSwatchGrid, customColorCommit, describeThemeColorSwatch, findSelectedThemeSwatch, themeColorRefsEqual, themeColorSwatchRows, themeColorVariantOfRef, themeColorVariantToRef, themeColorVariantsForLuminance, themeSwatchCommit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ooxml-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Shared OOXML logic for the Word, PowerPoint and Excel viewers: everything except the UI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"charts",
|
|
@@ -31,7 +31,13 @@
|
|
|
31
31
|
"pptx": "./dist/pptx/cli/index.mjs"
|
|
32
32
|
},
|
|
33
33
|
"workspaces": [
|
|
34
|
-
"packages/*"
|
|
34
|
+
"packages/*",
|
|
35
|
+
"viewers/*",
|
|
36
|
+
"viewers/*/packages/*",
|
|
37
|
+
"viewers/*/mcp",
|
|
38
|
+
"viewers/*/docs",
|
|
39
|
+
"viewers/teams/server",
|
|
40
|
+
"viewers/teams/demos/*"
|
|
35
41
|
],
|
|
36
42
|
"files": [
|
|
37
43
|
"dist",
|
|
@@ -191,6 +197,11 @@
|
|
|
191
197
|
"import": "./dist/pptx/automation/index.mjs",
|
|
192
198
|
"require": "./dist/pptx/automation/index.cjs"
|
|
193
199
|
},
|
|
200
|
+
"./pptx/ui": {
|
|
201
|
+
"types": "./dist/pptx/ui/index.d.ts",
|
|
202
|
+
"import": "./dist/pptx/ui/index.mjs",
|
|
203
|
+
"require": "./dist/pptx/ui/index.cjs"
|
|
204
|
+
},
|
|
194
205
|
"./docx/ui": {
|
|
195
206
|
"types": "./dist/docx/ui/index.d.ts",
|
|
196
207
|
"import": "./dist/docx/ui/index.mjs",
|
|
@@ -224,8 +235,8 @@
|
|
|
224
235
|
"release:publish": "node scripts/publish-released.mjs",
|
|
225
236
|
"changelog:unreleased": "bunx git-cliff --config cliff.toml --tag-pattern \"^ooxml-core@\" --unreleased",
|
|
226
237
|
"test:mcp": "node --test mcp/test/*.test.js",
|
|
227
|
-
"lint": "oxlint",
|
|
228
|
-
"lint:fix": "oxlint --fix"
|
|
238
|
+
"lint": "oxlint --ignore-pattern=viewers/",
|
|
239
|
+
"lint:fix": "oxlint --fix --ignore-pattern=viewers/"
|
|
229
240
|
},
|
|
230
241
|
"dependencies": {
|
|
231
242
|
"@xmldom/xmldom": "^0.9.12",
|