pptx-glimpse 3.2.0 → 3.2.1
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/browser.cjs +381 -15
- package/dist/browser.js +3 -3
- package/dist/{chunk-KY3SYR3V.js → chunk-OOQWOZHT.js} +1 -1
- package/dist/{chunk-KELC7JQK.js → chunk-Q3ZCUUGG.js} +1 -1
- package/dist/{chunk-CX4ZDTKK.js → chunk-VBQRNQOT.js} +380 -14
- package/dist/cli.js +2 -2
- package/dist/index.js +3 -3
- package/package.json +3 -3
package/dist/browser.cjs
CHANGED
|
@@ -8394,6 +8394,7 @@ var xmlBuilder = new import_fast_xml_parser2.XMLBuilder({
|
|
|
8394
8394
|
suppressEmptyNode: true
|
|
8395
8395
|
});
|
|
8396
8396
|
function buildTextBoxXml(params) {
|
|
8397
|
+
const paragraphs = params.paragraphs ?? [{ runs: [{ text: params.text ?? "" }] }];
|
|
8397
8398
|
return xmlBuilder.build({
|
|
8398
8399
|
"p:sp": {
|
|
8399
8400
|
"p:nvSpPr": {
|
|
@@ -8408,6 +8409,7 @@ function buildTextBoxXml(params) {
|
|
|
8408
8409
|
},
|
|
8409
8410
|
"p:spPr": {
|
|
8410
8411
|
"a:xfrm": {
|
|
8412
|
+
...params.rotation !== void 0 ? { "@_rot": String(params.rotation) } : {},
|
|
8411
8413
|
"a:off": {
|
|
8412
8414
|
"@_x": String(params.offsetX),
|
|
8413
8415
|
"@_y": String(params.offsetY)
|
|
@@ -8427,20 +8429,142 @@ function buildTextBoxXml(params) {
|
|
|
8427
8429
|
}
|
|
8428
8430
|
},
|
|
8429
8431
|
"p:txBody": {
|
|
8430
|
-
"a:bodyPr":
|
|
8431
|
-
"@_wrap": "square"
|
|
8432
|
-
},
|
|
8432
|
+
"a:bodyPr": createTextBodyPropertiesXml(params.body),
|
|
8433
8433
|
"a:lstStyle": {},
|
|
8434
|
-
"a:p":
|
|
8435
|
-
"a:r": {
|
|
8436
|
-
"a:t": textElementValue(params.text)
|
|
8437
|
-
},
|
|
8438
|
-
"a:endParaRPr": {}
|
|
8439
|
-
}
|
|
8434
|
+
"a:p": paragraphs.map(createParagraphXml)
|
|
8440
8435
|
}
|
|
8441
8436
|
}
|
|
8442
8437
|
});
|
|
8443
8438
|
}
|
|
8439
|
+
function createTextBodyPropertiesXml(body) {
|
|
8440
|
+
return {
|
|
8441
|
+
"@_wrap": "square",
|
|
8442
|
+
...body?.anchor !== void 0 ? { "@_anchor": verticalAnchorToken(body.anchor) } : {},
|
|
8443
|
+
...body?.marginLeft !== void 0 ? { "@_lIns": String(body.marginLeft) } : {},
|
|
8444
|
+
...body?.marginRight !== void 0 ? { "@_rIns": String(body.marginRight) } : {},
|
|
8445
|
+
...body?.marginTop !== void 0 ? { "@_tIns": String(body.marginTop) } : {},
|
|
8446
|
+
...body?.marginBottom !== void 0 ? { "@_bIns": String(body.marginBottom) } : {}
|
|
8447
|
+
};
|
|
8448
|
+
}
|
|
8449
|
+
function createParagraphXml(paragraph) {
|
|
8450
|
+
return {
|
|
8451
|
+
...paragraph.properties !== void 0 ? { "a:pPr": createParagraphPropertiesXml(paragraph.properties) } : {},
|
|
8452
|
+
"a:r": paragraph.runs.map(createTextRunXml),
|
|
8453
|
+
"a:endParaRPr": {}
|
|
8454
|
+
};
|
|
8455
|
+
}
|
|
8456
|
+
function createParagraphPropertiesXml(properties) {
|
|
8457
|
+
return {
|
|
8458
|
+
...properties.align !== void 0 ? { "@_algn": textAlignToken(properties.align) } : {},
|
|
8459
|
+
...properties.lineSpacing !== void 0 ? { "a:lnSpc": { "a:spcPts": { "@_val": String(properties.lineSpacing) } } } : {}
|
|
8460
|
+
};
|
|
8461
|
+
}
|
|
8462
|
+
function createTextRunXml(run) {
|
|
8463
|
+
return {
|
|
8464
|
+
...run.properties !== void 0 ? { "a:rPr": createTextRunPropertiesXml(run.properties) } : {},
|
|
8465
|
+
"a:t": textElementValue(run.text)
|
|
8466
|
+
};
|
|
8467
|
+
}
|
|
8468
|
+
function createTextRunPropertiesXml(properties) {
|
|
8469
|
+
return {
|
|
8470
|
+
...properties.bold !== void 0 ? { "@_b": boolToken(properties.bold) } : {},
|
|
8471
|
+
...properties.italic !== void 0 ? { "@_i": boolToken(properties.italic) } : {},
|
|
8472
|
+
...properties.underline !== void 0 ? { "@_u": underlineStyleToken(properties.underline) } : {},
|
|
8473
|
+
...properties.strike !== void 0 ? { "@_strike": properties.strike ? "sngStrike" : "noStrike" } : {},
|
|
8474
|
+
...properties.baseline !== void 0 ? { "@_baseline": String(baselineToken(properties.baseline)) } : {},
|
|
8475
|
+
...properties.fontSize !== void 0 ? { "@_sz": String(Math.round(properties.fontSize * 100)) } : {},
|
|
8476
|
+
...properties.charSpacing !== void 0 ? { "@_spc": textPointToken(properties.charSpacing) } : {},
|
|
8477
|
+
...properties.outline !== void 0 ? { "a:ln": createTextOutlineXml(properties.outline) } : {},
|
|
8478
|
+
...properties.color !== void 0 ? { "a:solidFill": createSolidFillXml(properties.color) } : {},
|
|
8479
|
+
...properties.gradientFill !== void 0 ? { "a:gradFill": createGradientFillXml(properties.gradientFill) } : {},
|
|
8480
|
+
...properties.glow !== void 0 ? { "a:effectLst": { "a:glow": createGlowXml(properties.glow) } } : {},
|
|
8481
|
+
...properties.highlight !== void 0 ? { "a:highlight": createColorXml(properties.highlight) } : {},
|
|
8482
|
+
...properties.underline !== void 0 && typeof properties.underline !== "boolean" && properties.underline.color !== void 0 ? { "a:uFill": { "a:solidFill": createSolidFillXml(properties.underline.color) } } : {},
|
|
8483
|
+
...properties.fontFace !== void 0 ? {
|
|
8484
|
+
"a:latin": { "@_typeface": properties.fontFace },
|
|
8485
|
+
"a:ea": { "@_typeface": properties.fontFace },
|
|
8486
|
+
"a:cs": { "@_typeface": properties.fontFace }
|
|
8487
|
+
} : {}
|
|
8488
|
+
};
|
|
8489
|
+
}
|
|
8490
|
+
function createSolidFillXml(color) {
|
|
8491
|
+
return createColorXml(color);
|
|
8492
|
+
}
|
|
8493
|
+
function createColorXml(color) {
|
|
8494
|
+
if (!/^[0-9A-Fa-f]{6}$/.test(color.hex)) {
|
|
8495
|
+
throw new Error("buildTextBoxXml: color hex must be a 6-digit RGB value");
|
|
8496
|
+
}
|
|
8497
|
+
return {
|
|
8498
|
+
"a:srgbClr": {
|
|
8499
|
+
"@_val": color.hex.toUpperCase()
|
|
8500
|
+
}
|
|
8501
|
+
};
|
|
8502
|
+
}
|
|
8503
|
+
function createGradientFillXml(fill) {
|
|
8504
|
+
return {
|
|
8505
|
+
"a:gsLst": {
|
|
8506
|
+
"a:gs": fill.stops.map((stop) => ({
|
|
8507
|
+
"@_pos": String(stop.position),
|
|
8508
|
+
...createColorXml(stop.color)
|
|
8509
|
+
}))
|
|
8510
|
+
},
|
|
8511
|
+
"a:lin": {
|
|
8512
|
+
"@_ang": String(fill.angle ?? 0),
|
|
8513
|
+
"@_scaled": "1"
|
|
8514
|
+
}
|
|
8515
|
+
};
|
|
8516
|
+
}
|
|
8517
|
+
function createTextOutlineXml(outline) {
|
|
8518
|
+
return {
|
|
8519
|
+
...outline.width !== void 0 ? { "@_w": String(outline.width) } : {},
|
|
8520
|
+
...outline.color !== void 0 ? { "a:solidFill": createSolidFillXml(outline.color) } : {}
|
|
8521
|
+
};
|
|
8522
|
+
}
|
|
8523
|
+
function createGlowXml(glow) {
|
|
8524
|
+
return {
|
|
8525
|
+
"@_rad": String(glow.radius),
|
|
8526
|
+
...createColorXml(glow.color)
|
|
8527
|
+
};
|
|
8528
|
+
}
|
|
8529
|
+
function underlineStyleToken(underline) {
|
|
8530
|
+
if (typeof underline === "boolean") return underline ? "sng" : "none";
|
|
8531
|
+
return underline.style ?? "sng";
|
|
8532
|
+
}
|
|
8533
|
+
function baselineToken(baseline) {
|
|
8534
|
+
if (baseline === "superscript") return 3e4;
|
|
8535
|
+
return -25e3;
|
|
8536
|
+
}
|
|
8537
|
+
function textPointToken(value) {
|
|
8538
|
+
if (!Number.isInteger(value) || value < -4e5 || value > 4e5) {
|
|
8539
|
+
throw new Error("buildTextBoxXml: charSpacing must be an integer between -400000 and 400000");
|
|
8540
|
+
}
|
|
8541
|
+
return String(value);
|
|
8542
|
+
}
|
|
8543
|
+
function boolToken(value) {
|
|
8544
|
+
return value ? "1" : "0";
|
|
8545
|
+
}
|
|
8546
|
+
function textAlignToken(align) {
|
|
8547
|
+
switch (align) {
|
|
8548
|
+
case "left":
|
|
8549
|
+
return "l";
|
|
8550
|
+
case "center":
|
|
8551
|
+
return "ctr";
|
|
8552
|
+
case "right":
|
|
8553
|
+
return "r";
|
|
8554
|
+
case "justify":
|
|
8555
|
+
return "just";
|
|
8556
|
+
}
|
|
8557
|
+
}
|
|
8558
|
+
function verticalAnchorToken(anchor) {
|
|
8559
|
+
switch (anchor) {
|
|
8560
|
+
case "top":
|
|
8561
|
+
return "t";
|
|
8562
|
+
case "middle":
|
|
8563
|
+
return "ctr";
|
|
8564
|
+
case "bottom":
|
|
8565
|
+
return "b";
|
|
8566
|
+
}
|
|
8567
|
+
}
|
|
8444
8568
|
function buildConnectorXml(params) {
|
|
8445
8569
|
return xmlBuilder.build({
|
|
8446
8570
|
"p:cxnSp": {
|
|
@@ -8529,6 +8653,25 @@ var CONNECTOR_PRESETS = /* @__PURE__ */ new Set([
|
|
|
8529
8653
|
]);
|
|
8530
8654
|
var ARROW_TYPES2 = /* @__PURE__ */ new Set(["triangle", "stealth", "diamond", "oval", "arrow"]);
|
|
8531
8655
|
var ARROW_SIZES2 = /* @__PURE__ */ new Set(["sm", "med", "lg"]);
|
|
8656
|
+
var UNDERLINE_STYLES = /* @__PURE__ */ new Set([
|
|
8657
|
+
"sng",
|
|
8658
|
+
"dbl",
|
|
8659
|
+
"heavy",
|
|
8660
|
+
"dotted",
|
|
8661
|
+
"dottedHeavy",
|
|
8662
|
+
"dash",
|
|
8663
|
+
"dashHeavy",
|
|
8664
|
+
"dashLong",
|
|
8665
|
+
"dashLongHeavy",
|
|
8666
|
+
"dotDash",
|
|
8667
|
+
"dotDashHeavy",
|
|
8668
|
+
"dotDotDash",
|
|
8669
|
+
"dotDotDashHeavy",
|
|
8670
|
+
"wavy",
|
|
8671
|
+
"wavyHeavy",
|
|
8672
|
+
"wavyDbl",
|
|
8673
|
+
"none"
|
|
8674
|
+
]);
|
|
8532
8675
|
function findShapeNodeBySourceHandle(source, handle) {
|
|
8533
8676
|
for (const slide of source.slides) {
|
|
8534
8677
|
const shape = findShapeNodeInTree(slide.shapes, handle);
|
|
@@ -8698,7 +8841,9 @@ function addTextBox(source, slideHandle, input) {
|
|
|
8698
8841
|
offsetY: input.offsetY,
|
|
8699
8842
|
width: input.width,
|
|
8700
8843
|
height: input.height,
|
|
8701
|
-
|
|
8844
|
+
...input.rotation !== void 0 ? { rotation: input.rotation } : {},
|
|
8845
|
+
...input.paragraphs !== void 0 ? { paragraphs: input.paragraphs } : { text: input.text },
|
|
8846
|
+
...input.body !== void 0 ? { body: input.body } : {}
|
|
8702
8847
|
});
|
|
8703
8848
|
const shape = parseShapeNodeXml(xml, slide.partPath, orderingSlot);
|
|
8704
8849
|
const slides = source.slides.map(
|
|
@@ -8935,13 +9080,208 @@ function assertTextBoxInput(input) {
|
|
|
8935
9080
|
assertFiniteEmu(input.offsetY, "addTextBox", "offsetY");
|
|
8936
9081
|
assertPositiveFiniteEmu(input.width, "addTextBox", "width");
|
|
8937
9082
|
assertPositiveFiniteEmu(input.height, "addTextBox", "height");
|
|
8938
|
-
if (
|
|
8939
|
-
|
|
9083
|
+
if (input.rotation !== void 0) {
|
|
9084
|
+
assertFiniteIntegerNumber(input.rotation, "addTextBox", "rotation");
|
|
9085
|
+
}
|
|
9086
|
+
if (input.text !== void 0 && input.paragraphs !== void 0) {
|
|
9087
|
+
throw new Error("addTextBox: specify either text or paragraphs, not both");
|
|
9088
|
+
}
|
|
9089
|
+
if (input.text === void 0 && input.paragraphs === void 0) {
|
|
9090
|
+
throw new Error("addTextBox: text or paragraphs must be provided");
|
|
9091
|
+
}
|
|
9092
|
+
if (input.text !== void 0 && typeof input.text !== "string") {
|
|
9093
|
+
throw new Error("addTextBox: text must be a string when provided");
|
|
9094
|
+
}
|
|
9095
|
+
if (input.paragraphs !== void 0) {
|
|
9096
|
+
assertTextBoxParagraphs(input.paragraphs);
|
|
9097
|
+
}
|
|
9098
|
+
if (input.body !== void 0) {
|
|
9099
|
+
assertTextBoxBody(input.body, "body");
|
|
8940
9100
|
}
|
|
8941
9101
|
if (input.name !== void 0 && input.name.trim() === "") {
|
|
8942
9102
|
throw new Error("addTextBox: name must be a non-empty string when provided");
|
|
8943
9103
|
}
|
|
8944
9104
|
}
|
|
9105
|
+
function assertTextBoxParagraphs(paragraphs) {
|
|
9106
|
+
if (!isArrayValue(paragraphs) || paragraphs.length === 0) {
|
|
9107
|
+
throw new Error("addTextBox: paragraphs must contain at least one paragraph");
|
|
9108
|
+
}
|
|
9109
|
+
paragraphs.forEach((paragraph, paragraphIndex) => {
|
|
9110
|
+
if (!isPlainRecord(paragraph)) {
|
|
9111
|
+
throw new Error(`addTextBox: paragraphs[${paragraphIndex}] must be an object`);
|
|
9112
|
+
}
|
|
9113
|
+
const runs = paragraph.runs;
|
|
9114
|
+
if (!isArrayValue(runs) || runs.length === 0) {
|
|
9115
|
+
throw new Error(
|
|
9116
|
+
`addTextBox: paragraphs[${paragraphIndex}].runs must contain at least one run`
|
|
9117
|
+
);
|
|
9118
|
+
}
|
|
9119
|
+
assertTextBoxParagraphProperties(paragraph.properties, paragraphIndex);
|
|
9120
|
+
runs.forEach((run, runIndex) => assertTextBoxRun(run, paragraphIndex, runIndex));
|
|
9121
|
+
});
|
|
9122
|
+
}
|
|
9123
|
+
function assertTextBoxParagraphProperties(properties, paragraphIndex) {
|
|
9124
|
+
if (properties === void 0) return;
|
|
9125
|
+
if (!isPlainRecord(properties)) {
|
|
9126
|
+
throw new Error(`addTextBox: paragraphs[${paragraphIndex}].properties must be an object`);
|
|
9127
|
+
}
|
|
9128
|
+
const align = properties.align;
|
|
9129
|
+
const lineSpacing = properties.lineSpacing;
|
|
9130
|
+
if (align !== void 0 && align !== "left" && align !== "center" && align !== "right" && align !== "justify") {
|
|
9131
|
+
throw new Error(`addTextBox: paragraphs[${paragraphIndex}].properties.align is not supported`);
|
|
9132
|
+
}
|
|
9133
|
+
if (lineSpacing !== void 0) {
|
|
9134
|
+
assertPositiveFiniteIntegerNumber(
|
|
9135
|
+
lineSpacing,
|
|
9136
|
+
"addTextBox",
|
|
9137
|
+
`paragraphs[${paragraphIndex}].properties.lineSpacing`
|
|
9138
|
+
);
|
|
9139
|
+
}
|
|
9140
|
+
}
|
|
9141
|
+
function assertTextBoxRun(run, paragraphIndex, runIndex) {
|
|
9142
|
+
const path = `paragraphs[${paragraphIndex}].runs[${runIndex}]`;
|
|
9143
|
+
if (!isPlainRecord(run)) {
|
|
9144
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
9145
|
+
}
|
|
9146
|
+
if (typeof run.text !== "string") {
|
|
9147
|
+
throw new Error(`addTextBox: ${path}.text must be a string`);
|
|
9148
|
+
}
|
|
9149
|
+
assertTextBoxRunProperties(run.properties, path);
|
|
9150
|
+
}
|
|
9151
|
+
function assertTextBoxRunProperties(properties, path) {
|
|
9152
|
+
if (properties === void 0) return;
|
|
9153
|
+
if (!isPlainRecord(properties)) {
|
|
9154
|
+
throw new Error(`addTextBox: ${path}.properties must be an object`);
|
|
9155
|
+
}
|
|
9156
|
+
const fontFace = properties.fontFace;
|
|
9157
|
+
const fontSize = properties.fontSize;
|
|
9158
|
+
const color = properties.color;
|
|
9159
|
+
const gradientFill = properties.gradientFill;
|
|
9160
|
+
const underline = properties.underline;
|
|
9161
|
+
const baseline = properties.baseline;
|
|
9162
|
+
const highlight = properties.highlight;
|
|
9163
|
+
const glow = properties.glow;
|
|
9164
|
+
const outline = properties.outline;
|
|
9165
|
+
const charSpacing = properties.charSpacing;
|
|
9166
|
+
if (fontFace !== void 0 && (typeof fontFace !== "string" || fontFace.trim() === "")) {
|
|
9167
|
+
throw new Error(`addTextBox: ${path}.properties.fontFace must be a non-empty string`);
|
|
9168
|
+
}
|
|
9169
|
+
if (fontSize !== void 0) {
|
|
9170
|
+
assertPositiveFiniteNumber(fontSize, "addTextBox", `${path}.properties.fontSize`);
|
|
9171
|
+
}
|
|
9172
|
+
assertBooleanOrUndefined(properties.bold, "addTextBox", `${path}.properties.bold`);
|
|
9173
|
+
assertBooleanOrUndefined(properties.italic, "addTextBox", `${path}.properties.italic`);
|
|
9174
|
+
assertBooleanOrUndefined(properties.strike, "addTextBox", `${path}.properties.strike`);
|
|
9175
|
+
if (color !== void 0) assertTextBoxColor(color, `${path}.properties.color`);
|
|
9176
|
+
if (gradientFill !== void 0) {
|
|
9177
|
+
if (color !== void 0) {
|
|
9178
|
+
throw new Error(`addTextBox: ${path}.properties cannot set both color and gradientFill`);
|
|
9179
|
+
}
|
|
9180
|
+
assertTextBoxGradientFill(gradientFill, `${path}.properties.gradientFill`);
|
|
9181
|
+
}
|
|
9182
|
+
if (underline !== void 0) {
|
|
9183
|
+
assertTextBoxUnderline(underline, `${path}.properties.underline`);
|
|
9184
|
+
}
|
|
9185
|
+
if (baseline !== void 0) {
|
|
9186
|
+
assertTextBoxBaseline(baseline, `${path}.properties.baseline`);
|
|
9187
|
+
}
|
|
9188
|
+
if (highlight !== void 0) {
|
|
9189
|
+
assertTextBoxColor(highlight, `${path}.properties.highlight`);
|
|
9190
|
+
}
|
|
9191
|
+
if (glow !== void 0) assertTextBoxGlow(glow, `${path}.properties.glow`);
|
|
9192
|
+
if (outline !== void 0) {
|
|
9193
|
+
assertTextBoxOutline(outline, `${path}.properties.outline`);
|
|
9194
|
+
}
|
|
9195
|
+
if (charSpacing !== void 0) {
|
|
9196
|
+
assertTextPointNumber(charSpacing, "addTextBox", `${path}.properties.charSpacing`);
|
|
9197
|
+
}
|
|
9198
|
+
}
|
|
9199
|
+
function assertTextBoxColor(color, path) {
|
|
9200
|
+
if (!isPlainRecord(color)) {
|
|
9201
|
+
throw new Error(`addTextBox: ${path} must be an srgb 6-digit hex color`);
|
|
9202
|
+
}
|
|
9203
|
+
if (color.kind !== "srgb" || typeof color.hex !== "string" || !/^[0-9A-Fa-f]{6}$/.test(color.hex)) {
|
|
9204
|
+
throw new Error(`addTextBox: ${path} must be an srgb 6-digit hex color`);
|
|
9205
|
+
}
|
|
9206
|
+
}
|
|
9207
|
+
function assertTextBoxGradientFill(fill, path) {
|
|
9208
|
+
if (!isPlainRecord(fill)) {
|
|
9209
|
+
throw new Error(`addTextBox: ${path} must be a gradient fill object`);
|
|
9210
|
+
}
|
|
9211
|
+
const stops = fill.stops;
|
|
9212
|
+
if (!isArrayValue(stops) || stops.length < 2) {
|
|
9213
|
+
throw new Error(`addTextBox: ${path}.stops must contain at least two stops`);
|
|
9214
|
+
}
|
|
9215
|
+
if (fill.angle !== void 0)
|
|
9216
|
+
assertFiniteIntegerNumber(fill.angle, "addTextBox", `${path}.angle`);
|
|
9217
|
+
stops.forEach((stop, index) => {
|
|
9218
|
+
if (!isPlainRecord(stop)) {
|
|
9219
|
+
throw new Error(`addTextBox: ${path}.stops[${index}] must be an object`);
|
|
9220
|
+
}
|
|
9221
|
+
const position = stop.position;
|
|
9222
|
+
assertFiniteIntegerNumber(position, "addTextBox", `${path}.stops[${index}].position`);
|
|
9223
|
+
if (typeof position !== "number" || position < 0 || position > 1e5) {
|
|
9224
|
+
throw new Error(`addTextBox: ${path}.stops[${index}].position must be between 0 and 100000`);
|
|
9225
|
+
}
|
|
9226
|
+
assertTextBoxColor(stop.color, `${path}.stops[${index}].color`);
|
|
9227
|
+
});
|
|
9228
|
+
}
|
|
9229
|
+
function isArrayValue(value) {
|
|
9230
|
+
return Array.isArray(value);
|
|
9231
|
+
}
|
|
9232
|
+
function assertTextBoxUnderline(underline, path) {
|
|
9233
|
+
if (typeof underline === "boolean") return;
|
|
9234
|
+
if (!isPlainRecord(underline)) {
|
|
9235
|
+
throw new Error(`addTextBox: ${path} must be a boolean or underline options object`);
|
|
9236
|
+
}
|
|
9237
|
+
const style = underline.style ?? "sng";
|
|
9238
|
+
if (typeof style !== "string" || !UNDERLINE_STYLES.has(style)) {
|
|
9239
|
+
throw new Error(`addTextBox: ${path}.style is not supported`);
|
|
9240
|
+
}
|
|
9241
|
+
if (underline.color !== void 0) {
|
|
9242
|
+
assertTextBoxColor(underline.color, `${path}.color`);
|
|
9243
|
+
}
|
|
9244
|
+
}
|
|
9245
|
+
function assertTextBoxBaseline(baseline, path) {
|
|
9246
|
+
if (baseline === "subscript" || baseline === "superscript") return;
|
|
9247
|
+
throw new Error(`addTextBox: ${path} must be subscript or superscript`);
|
|
9248
|
+
}
|
|
9249
|
+
function assertTextBoxGlow(glow, path) {
|
|
9250
|
+
if (!isPlainRecord(glow)) {
|
|
9251
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
9252
|
+
}
|
|
9253
|
+
assertPositiveFiniteEmu(glow.radius, "addTextBox", `${path}.radius`);
|
|
9254
|
+
assertTextBoxColor(glow.color, `${path}.color`);
|
|
9255
|
+
}
|
|
9256
|
+
function assertTextBoxOutline(outline, path) {
|
|
9257
|
+
if (!isPlainRecord(outline)) {
|
|
9258
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
9259
|
+
}
|
|
9260
|
+
if (outline.width === void 0 && outline.color === void 0) {
|
|
9261
|
+
throw new Error(`addTextBox: ${path} must set width or color`);
|
|
9262
|
+
}
|
|
9263
|
+
if (outline.width !== void 0) {
|
|
9264
|
+
assertPositiveFiniteEmu(outline.width, "addTextBox", `${path}.width`);
|
|
9265
|
+
}
|
|
9266
|
+
if (outline.color !== void 0) assertTextBoxColor(outline.color, `${path}.color`);
|
|
9267
|
+
}
|
|
9268
|
+
function assertTextBoxBody(body, path) {
|
|
9269
|
+
if (!isPlainRecord(body)) {
|
|
9270
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
9271
|
+
}
|
|
9272
|
+
if (body.anchor !== void 0 && body.anchor !== "top" && body.anchor !== "middle" && body.anchor !== "bottom") {
|
|
9273
|
+
throw new Error("addTextBox: body.anchor is not supported");
|
|
9274
|
+
}
|
|
9275
|
+
if (body.marginLeft !== void 0)
|
|
9276
|
+
assertFiniteEmu(body.marginLeft, "addTextBox", "body.marginLeft");
|
|
9277
|
+
if (body.marginRight !== void 0) {
|
|
9278
|
+
assertFiniteEmu(body.marginRight, "addTextBox", "body.marginRight");
|
|
9279
|
+
}
|
|
9280
|
+
if (body.marginTop !== void 0) assertFiniteEmu(body.marginTop, "addTextBox", "body.marginTop");
|
|
9281
|
+
if (body.marginBottom !== void 0) {
|
|
9282
|
+
assertFiniteEmu(body.marginBottom, "addTextBox", "body.marginBottom");
|
|
9283
|
+
}
|
|
9284
|
+
}
|
|
8945
9285
|
function assertConnectorInput(input) {
|
|
8946
9286
|
assertFiniteEmu(input.offsetX, "addConnector", "offsetX");
|
|
8947
9287
|
assertFiniteEmu(input.offsetY, "addConnector", "offsetY");
|
|
@@ -8980,13 +9320,39 @@ function assertArrowEndpoint(endpoint, fieldName) {
|
|
|
8980
9320
|
throw new Error(`addConnector: outline.${fieldName}.length is not supported`);
|
|
8981
9321
|
}
|
|
8982
9322
|
}
|
|
9323
|
+
function assertBooleanOrUndefined(value, operationName, fieldName) {
|
|
9324
|
+
if (value !== void 0 && typeof value !== "boolean") {
|
|
9325
|
+
throw new Error(`${operationName}: ${fieldName} must be a boolean value`);
|
|
9326
|
+
}
|
|
9327
|
+
}
|
|
9328
|
+
function assertFiniteIntegerNumber(value, operationName, fieldName) {
|
|
9329
|
+
if (!Number.isInteger(value)) {
|
|
9330
|
+
throw new Error(`${operationName}: ${fieldName} must be a finite integer`);
|
|
9331
|
+
}
|
|
9332
|
+
}
|
|
9333
|
+
function assertPositiveFiniteNumber(value, operationName, fieldName) {
|
|
9334
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
9335
|
+
throw new Error(`${operationName}: ${fieldName} must be a finite positive number`);
|
|
9336
|
+
}
|
|
9337
|
+
}
|
|
9338
|
+
function assertPositiveFiniteIntegerNumber(value, operationName, fieldName) {
|
|
9339
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
9340
|
+
throw new Error(`${operationName}: ${fieldName} must be a finite positive integer`);
|
|
9341
|
+
}
|
|
9342
|
+
}
|
|
9343
|
+
function assertTextPointNumber(value, operationName, fieldName) {
|
|
9344
|
+
assertFiniteIntegerNumber(value, operationName, fieldName);
|
|
9345
|
+
if (typeof value !== "number" || value < -4e5 || value > 4e5) {
|
|
9346
|
+
throw new Error(`${operationName}: ${fieldName} must be between -400000 and 400000`);
|
|
9347
|
+
}
|
|
9348
|
+
}
|
|
8983
9349
|
function assertFiniteEmu(value, operationName, fieldName) {
|
|
8984
|
-
if (!Number.isFinite(value)) {
|
|
9350
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
8985
9351
|
throw new Error(`${operationName}: ${fieldName} must be a finite EMU value`);
|
|
8986
9352
|
}
|
|
8987
9353
|
}
|
|
8988
9354
|
function assertPositiveFiniteEmu(value, operationName, fieldName) {
|
|
8989
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
9355
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
8990
9356
|
throw new Error(`${operationName}: ${fieldName} must be a finite positive EMU value`);
|
|
8991
9357
|
}
|
|
8992
9358
|
}
|
|
@@ -16817,7 +17183,7 @@ function addTextBoxCommand(document, command) {
|
|
|
16817
17183
|
requireFiniteEmu(command.offsetY, "addTextBox", "offsetY");
|
|
16818
17184
|
requirePositiveFiniteEmu(command.width, "addTextBox", "width");
|
|
16819
17185
|
requirePositiveFiniteEmu(command.height, "addTextBox", "height");
|
|
16820
|
-
if (typeof command.text !== "string") {
|
|
17186
|
+
if (command.text !== void 0 && typeof command.text !== "string") {
|
|
16821
17187
|
throw new Error("addTextBox: text must be a string");
|
|
16822
17188
|
}
|
|
16823
17189
|
if (command.name !== void 0 && command.name.trim() === "") {
|
package/dist/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectUsedFonts
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OOQWOZHT.js";
|
|
4
4
|
import {
|
|
5
5
|
DEFAULT_OUTPUT_WIDTH,
|
|
6
6
|
addConnector,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
unsafeBrandAssertion,
|
|
31
31
|
updateShapeTransform,
|
|
32
32
|
writePptx
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-VBQRNQOT.js";
|
|
34
34
|
import {
|
|
35
35
|
DEFAULT_FONT_MAPPING,
|
|
36
36
|
clearFontCache,
|
|
@@ -3096,7 +3096,7 @@ function addTextBoxCommand(document, command) {
|
|
|
3096
3096
|
requireFiniteEmu(command.offsetY, "addTextBox", "offsetY");
|
|
3097
3097
|
requirePositiveFiniteEmu(command.width, "addTextBox", "width");
|
|
3098
3098
|
requirePositiveFiniteEmu(command.height, "addTextBox", "height");
|
|
3099
|
-
if (typeof command.text !== "string") {
|
|
3099
|
+
if (command.text !== void 0 && typeof command.text !== "string") {
|
|
3100
3100
|
throw new Error("addTextBox: text must be a string");
|
|
3101
3101
|
}
|
|
3102
3102
|
if (command.name !== void 0 && command.name.trim() === "") {
|
|
@@ -6773,6 +6773,7 @@ var xmlBuilder = new XMLBuilder({
|
|
|
6773
6773
|
suppressEmptyNode: true
|
|
6774
6774
|
});
|
|
6775
6775
|
function buildTextBoxXml(params) {
|
|
6776
|
+
const paragraphs = params.paragraphs ?? [{ runs: [{ text: params.text ?? "" }] }];
|
|
6776
6777
|
return xmlBuilder.build({
|
|
6777
6778
|
"p:sp": {
|
|
6778
6779
|
"p:nvSpPr": {
|
|
@@ -6787,6 +6788,7 @@ function buildTextBoxXml(params) {
|
|
|
6787
6788
|
},
|
|
6788
6789
|
"p:spPr": {
|
|
6789
6790
|
"a:xfrm": {
|
|
6791
|
+
...params.rotation !== void 0 ? { "@_rot": String(params.rotation) } : {},
|
|
6790
6792
|
"a:off": {
|
|
6791
6793
|
"@_x": String(params.offsetX),
|
|
6792
6794
|
"@_y": String(params.offsetY)
|
|
@@ -6806,20 +6808,142 @@ function buildTextBoxXml(params) {
|
|
|
6806
6808
|
}
|
|
6807
6809
|
},
|
|
6808
6810
|
"p:txBody": {
|
|
6809
|
-
"a:bodyPr":
|
|
6810
|
-
"@_wrap": "square"
|
|
6811
|
-
},
|
|
6811
|
+
"a:bodyPr": createTextBodyPropertiesXml(params.body),
|
|
6812
6812
|
"a:lstStyle": {},
|
|
6813
|
-
"a:p":
|
|
6814
|
-
"a:r": {
|
|
6815
|
-
"a:t": textElementValue(params.text)
|
|
6816
|
-
},
|
|
6817
|
-
"a:endParaRPr": {}
|
|
6818
|
-
}
|
|
6813
|
+
"a:p": paragraphs.map(createParagraphXml)
|
|
6819
6814
|
}
|
|
6820
6815
|
}
|
|
6821
6816
|
});
|
|
6822
6817
|
}
|
|
6818
|
+
function createTextBodyPropertiesXml(body) {
|
|
6819
|
+
return {
|
|
6820
|
+
"@_wrap": "square",
|
|
6821
|
+
...body?.anchor !== void 0 ? { "@_anchor": verticalAnchorToken(body.anchor) } : {},
|
|
6822
|
+
...body?.marginLeft !== void 0 ? { "@_lIns": String(body.marginLeft) } : {},
|
|
6823
|
+
...body?.marginRight !== void 0 ? { "@_rIns": String(body.marginRight) } : {},
|
|
6824
|
+
...body?.marginTop !== void 0 ? { "@_tIns": String(body.marginTop) } : {},
|
|
6825
|
+
...body?.marginBottom !== void 0 ? { "@_bIns": String(body.marginBottom) } : {}
|
|
6826
|
+
};
|
|
6827
|
+
}
|
|
6828
|
+
function createParagraphXml(paragraph) {
|
|
6829
|
+
return {
|
|
6830
|
+
...paragraph.properties !== void 0 ? { "a:pPr": createParagraphPropertiesXml(paragraph.properties) } : {},
|
|
6831
|
+
"a:r": paragraph.runs.map(createTextRunXml),
|
|
6832
|
+
"a:endParaRPr": {}
|
|
6833
|
+
};
|
|
6834
|
+
}
|
|
6835
|
+
function createParagraphPropertiesXml(properties) {
|
|
6836
|
+
return {
|
|
6837
|
+
...properties.align !== void 0 ? { "@_algn": textAlignToken(properties.align) } : {},
|
|
6838
|
+
...properties.lineSpacing !== void 0 ? { "a:lnSpc": { "a:spcPts": { "@_val": String(properties.lineSpacing) } } } : {}
|
|
6839
|
+
};
|
|
6840
|
+
}
|
|
6841
|
+
function createTextRunXml(run) {
|
|
6842
|
+
return {
|
|
6843
|
+
...run.properties !== void 0 ? { "a:rPr": createTextRunPropertiesXml(run.properties) } : {},
|
|
6844
|
+
"a:t": textElementValue(run.text)
|
|
6845
|
+
};
|
|
6846
|
+
}
|
|
6847
|
+
function createTextRunPropertiesXml(properties) {
|
|
6848
|
+
return {
|
|
6849
|
+
...properties.bold !== void 0 ? { "@_b": boolToken(properties.bold) } : {},
|
|
6850
|
+
...properties.italic !== void 0 ? { "@_i": boolToken(properties.italic) } : {},
|
|
6851
|
+
...properties.underline !== void 0 ? { "@_u": underlineStyleToken(properties.underline) } : {},
|
|
6852
|
+
...properties.strike !== void 0 ? { "@_strike": properties.strike ? "sngStrike" : "noStrike" } : {},
|
|
6853
|
+
...properties.baseline !== void 0 ? { "@_baseline": String(baselineToken(properties.baseline)) } : {},
|
|
6854
|
+
...properties.fontSize !== void 0 ? { "@_sz": String(Math.round(properties.fontSize * 100)) } : {},
|
|
6855
|
+
...properties.charSpacing !== void 0 ? { "@_spc": textPointToken(properties.charSpacing) } : {},
|
|
6856
|
+
...properties.outline !== void 0 ? { "a:ln": createTextOutlineXml(properties.outline) } : {},
|
|
6857
|
+
...properties.color !== void 0 ? { "a:solidFill": createSolidFillXml(properties.color) } : {},
|
|
6858
|
+
...properties.gradientFill !== void 0 ? { "a:gradFill": createGradientFillXml(properties.gradientFill) } : {},
|
|
6859
|
+
...properties.glow !== void 0 ? { "a:effectLst": { "a:glow": createGlowXml(properties.glow) } } : {},
|
|
6860
|
+
...properties.highlight !== void 0 ? { "a:highlight": createColorXml(properties.highlight) } : {},
|
|
6861
|
+
...properties.underline !== void 0 && typeof properties.underline !== "boolean" && properties.underline.color !== void 0 ? { "a:uFill": { "a:solidFill": createSolidFillXml(properties.underline.color) } } : {},
|
|
6862
|
+
...properties.fontFace !== void 0 ? {
|
|
6863
|
+
"a:latin": { "@_typeface": properties.fontFace },
|
|
6864
|
+
"a:ea": { "@_typeface": properties.fontFace },
|
|
6865
|
+
"a:cs": { "@_typeface": properties.fontFace }
|
|
6866
|
+
} : {}
|
|
6867
|
+
};
|
|
6868
|
+
}
|
|
6869
|
+
function createSolidFillXml(color) {
|
|
6870
|
+
return createColorXml(color);
|
|
6871
|
+
}
|
|
6872
|
+
function createColorXml(color) {
|
|
6873
|
+
if (!/^[0-9A-Fa-f]{6}$/.test(color.hex)) {
|
|
6874
|
+
throw new Error("buildTextBoxXml: color hex must be a 6-digit RGB value");
|
|
6875
|
+
}
|
|
6876
|
+
return {
|
|
6877
|
+
"a:srgbClr": {
|
|
6878
|
+
"@_val": color.hex.toUpperCase()
|
|
6879
|
+
}
|
|
6880
|
+
};
|
|
6881
|
+
}
|
|
6882
|
+
function createGradientFillXml(fill) {
|
|
6883
|
+
return {
|
|
6884
|
+
"a:gsLst": {
|
|
6885
|
+
"a:gs": fill.stops.map((stop) => ({
|
|
6886
|
+
"@_pos": String(stop.position),
|
|
6887
|
+
...createColorXml(stop.color)
|
|
6888
|
+
}))
|
|
6889
|
+
},
|
|
6890
|
+
"a:lin": {
|
|
6891
|
+
"@_ang": String(fill.angle ?? 0),
|
|
6892
|
+
"@_scaled": "1"
|
|
6893
|
+
}
|
|
6894
|
+
};
|
|
6895
|
+
}
|
|
6896
|
+
function createTextOutlineXml(outline) {
|
|
6897
|
+
return {
|
|
6898
|
+
...outline.width !== void 0 ? { "@_w": String(outline.width) } : {},
|
|
6899
|
+
...outline.color !== void 0 ? { "a:solidFill": createSolidFillXml(outline.color) } : {}
|
|
6900
|
+
};
|
|
6901
|
+
}
|
|
6902
|
+
function createGlowXml(glow) {
|
|
6903
|
+
return {
|
|
6904
|
+
"@_rad": String(glow.radius),
|
|
6905
|
+
...createColorXml(glow.color)
|
|
6906
|
+
};
|
|
6907
|
+
}
|
|
6908
|
+
function underlineStyleToken(underline) {
|
|
6909
|
+
if (typeof underline === "boolean") return underline ? "sng" : "none";
|
|
6910
|
+
return underline.style ?? "sng";
|
|
6911
|
+
}
|
|
6912
|
+
function baselineToken(baseline) {
|
|
6913
|
+
if (baseline === "superscript") return 3e4;
|
|
6914
|
+
return -25e3;
|
|
6915
|
+
}
|
|
6916
|
+
function textPointToken(value) {
|
|
6917
|
+
if (!Number.isInteger(value) || value < -4e5 || value > 4e5) {
|
|
6918
|
+
throw new Error("buildTextBoxXml: charSpacing must be an integer between -400000 and 400000");
|
|
6919
|
+
}
|
|
6920
|
+
return String(value);
|
|
6921
|
+
}
|
|
6922
|
+
function boolToken(value) {
|
|
6923
|
+
return value ? "1" : "0";
|
|
6924
|
+
}
|
|
6925
|
+
function textAlignToken(align) {
|
|
6926
|
+
switch (align) {
|
|
6927
|
+
case "left":
|
|
6928
|
+
return "l";
|
|
6929
|
+
case "center":
|
|
6930
|
+
return "ctr";
|
|
6931
|
+
case "right":
|
|
6932
|
+
return "r";
|
|
6933
|
+
case "justify":
|
|
6934
|
+
return "just";
|
|
6935
|
+
}
|
|
6936
|
+
}
|
|
6937
|
+
function verticalAnchorToken(anchor) {
|
|
6938
|
+
switch (anchor) {
|
|
6939
|
+
case "top":
|
|
6940
|
+
return "t";
|
|
6941
|
+
case "middle":
|
|
6942
|
+
return "ctr";
|
|
6943
|
+
case "bottom":
|
|
6944
|
+
return "b";
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6823
6947
|
function buildConnectorXml(params) {
|
|
6824
6948
|
return xmlBuilder.build({
|
|
6825
6949
|
"p:cxnSp": {
|
|
@@ -6908,6 +7032,25 @@ var CONNECTOR_PRESETS = /* @__PURE__ */ new Set([
|
|
|
6908
7032
|
]);
|
|
6909
7033
|
var ARROW_TYPES2 = /* @__PURE__ */ new Set(["triangle", "stealth", "diamond", "oval", "arrow"]);
|
|
6910
7034
|
var ARROW_SIZES2 = /* @__PURE__ */ new Set(["sm", "med", "lg"]);
|
|
7035
|
+
var UNDERLINE_STYLES = /* @__PURE__ */ new Set([
|
|
7036
|
+
"sng",
|
|
7037
|
+
"dbl",
|
|
7038
|
+
"heavy",
|
|
7039
|
+
"dotted",
|
|
7040
|
+
"dottedHeavy",
|
|
7041
|
+
"dash",
|
|
7042
|
+
"dashHeavy",
|
|
7043
|
+
"dashLong",
|
|
7044
|
+
"dashLongHeavy",
|
|
7045
|
+
"dotDash",
|
|
7046
|
+
"dotDashHeavy",
|
|
7047
|
+
"dotDotDash",
|
|
7048
|
+
"dotDotDashHeavy",
|
|
7049
|
+
"wavy",
|
|
7050
|
+
"wavyHeavy",
|
|
7051
|
+
"wavyDbl",
|
|
7052
|
+
"none"
|
|
7053
|
+
]);
|
|
6911
7054
|
function findShapeNodeBySourceHandle(source, handle) {
|
|
6912
7055
|
for (const slide of source.slides) {
|
|
6913
7056
|
const shape = findShapeNodeInTree(slide.shapes, handle);
|
|
@@ -7077,7 +7220,9 @@ function addTextBox(source, slideHandle, input) {
|
|
|
7077
7220
|
offsetY: input.offsetY,
|
|
7078
7221
|
width: input.width,
|
|
7079
7222
|
height: input.height,
|
|
7080
|
-
|
|
7223
|
+
...input.rotation !== void 0 ? { rotation: input.rotation } : {},
|
|
7224
|
+
...input.paragraphs !== void 0 ? { paragraphs: input.paragraphs } : { text: input.text },
|
|
7225
|
+
...input.body !== void 0 ? { body: input.body } : {}
|
|
7081
7226
|
});
|
|
7082
7227
|
const shape = parseShapeNodeXml(xml, slide.partPath, orderingSlot);
|
|
7083
7228
|
const slides = source.slides.map(
|
|
@@ -7314,13 +7459,208 @@ function assertTextBoxInput(input) {
|
|
|
7314
7459
|
assertFiniteEmu(input.offsetY, "addTextBox", "offsetY");
|
|
7315
7460
|
assertPositiveFiniteEmu(input.width, "addTextBox", "width");
|
|
7316
7461
|
assertPositiveFiniteEmu(input.height, "addTextBox", "height");
|
|
7317
|
-
if (
|
|
7318
|
-
|
|
7462
|
+
if (input.rotation !== void 0) {
|
|
7463
|
+
assertFiniteIntegerNumber(input.rotation, "addTextBox", "rotation");
|
|
7464
|
+
}
|
|
7465
|
+
if (input.text !== void 0 && input.paragraphs !== void 0) {
|
|
7466
|
+
throw new Error("addTextBox: specify either text or paragraphs, not both");
|
|
7467
|
+
}
|
|
7468
|
+
if (input.text === void 0 && input.paragraphs === void 0) {
|
|
7469
|
+
throw new Error("addTextBox: text or paragraphs must be provided");
|
|
7470
|
+
}
|
|
7471
|
+
if (input.text !== void 0 && typeof input.text !== "string") {
|
|
7472
|
+
throw new Error("addTextBox: text must be a string when provided");
|
|
7473
|
+
}
|
|
7474
|
+
if (input.paragraphs !== void 0) {
|
|
7475
|
+
assertTextBoxParagraphs(input.paragraphs);
|
|
7476
|
+
}
|
|
7477
|
+
if (input.body !== void 0) {
|
|
7478
|
+
assertTextBoxBody(input.body, "body");
|
|
7319
7479
|
}
|
|
7320
7480
|
if (input.name !== void 0 && input.name.trim() === "") {
|
|
7321
7481
|
throw new Error("addTextBox: name must be a non-empty string when provided");
|
|
7322
7482
|
}
|
|
7323
7483
|
}
|
|
7484
|
+
function assertTextBoxParagraphs(paragraphs) {
|
|
7485
|
+
if (!isArrayValue(paragraphs) || paragraphs.length === 0) {
|
|
7486
|
+
throw new Error("addTextBox: paragraphs must contain at least one paragraph");
|
|
7487
|
+
}
|
|
7488
|
+
paragraphs.forEach((paragraph, paragraphIndex) => {
|
|
7489
|
+
if (!isPlainRecord(paragraph)) {
|
|
7490
|
+
throw new Error(`addTextBox: paragraphs[${paragraphIndex}] must be an object`);
|
|
7491
|
+
}
|
|
7492
|
+
const runs = paragraph.runs;
|
|
7493
|
+
if (!isArrayValue(runs) || runs.length === 0) {
|
|
7494
|
+
throw new Error(
|
|
7495
|
+
`addTextBox: paragraphs[${paragraphIndex}].runs must contain at least one run`
|
|
7496
|
+
);
|
|
7497
|
+
}
|
|
7498
|
+
assertTextBoxParagraphProperties(paragraph.properties, paragraphIndex);
|
|
7499
|
+
runs.forEach((run, runIndex) => assertTextBoxRun(run, paragraphIndex, runIndex));
|
|
7500
|
+
});
|
|
7501
|
+
}
|
|
7502
|
+
function assertTextBoxParagraphProperties(properties, paragraphIndex) {
|
|
7503
|
+
if (properties === void 0) return;
|
|
7504
|
+
if (!isPlainRecord(properties)) {
|
|
7505
|
+
throw new Error(`addTextBox: paragraphs[${paragraphIndex}].properties must be an object`);
|
|
7506
|
+
}
|
|
7507
|
+
const align = properties.align;
|
|
7508
|
+
const lineSpacing = properties.lineSpacing;
|
|
7509
|
+
if (align !== void 0 && align !== "left" && align !== "center" && align !== "right" && align !== "justify") {
|
|
7510
|
+
throw new Error(`addTextBox: paragraphs[${paragraphIndex}].properties.align is not supported`);
|
|
7511
|
+
}
|
|
7512
|
+
if (lineSpacing !== void 0) {
|
|
7513
|
+
assertPositiveFiniteIntegerNumber(
|
|
7514
|
+
lineSpacing,
|
|
7515
|
+
"addTextBox",
|
|
7516
|
+
`paragraphs[${paragraphIndex}].properties.lineSpacing`
|
|
7517
|
+
);
|
|
7518
|
+
}
|
|
7519
|
+
}
|
|
7520
|
+
function assertTextBoxRun(run, paragraphIndex, runIndex) {
|
|
7521
|
+
const path = `paragraphs[${paragraphIndex}].runs[${runIndex}]`;
|
|
7522
|
+
if (!isPlainRecord(run)) {
|
|
7523
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
7524
|
+
}
|
|
7525
|
+
if (typeof run.text !== "string") {
|
|
7526
|
+
throw new Error(`addTextBox: ${path}.text must be a string`);
|
|
7527
|
+
}
|
|
7528
|
+
assertTextBoxRunProperties(run.properties, path);
|
|
7529
|
+
}
|
|
7530
|
+
function assertTextBoxRunProperties(properties, path) {
|
|
7531
|
+
if (properties === void 0) return;
|
|
7532
|
+
if (!isPlainRecord(properties)) {
|
|
7533
|
+
throw new Error(`addTextBox: ${path}.properties must be an object`);
|
|
7534
|
+
}
|
|
7535
|
+
const fontFace = properties.fontFace;
|
|
7536
|
+
const fontSize = properties.fontSize;
|
|
7537
|
+
const color = properties.color;
|
|
7538
|
+
const gradientFill = properties.gradientFill;
|
|
7539
|
+
const underline = properties.underline;
|
|
7540
|
+
const baseline = properties.baseline;
|
|
7541
|
+
const highlight = properties.highlight;
|
|
7542
|
+
const glow = properties.glow;
|
|
7543
|
+
const outline = properties.outline;
|
|
7544
|
+
const charSpacing = properties.charSpacing;
|
|
7545
|
+
if (fontFace !== void 0 && (typeof fontFace !== "string" || fontFace.trim() === "")) {
|
|
7546
|
+
throw new Error(`addTextBox: ${path}.properties.fontFace must be a non-empty string`);
|
|
7547
|
+
}
|
|
7548
|
+
if (fontSize !== void 0) {
|
|
7549
|
+
assertPositiveFiniteNumber(fontSize, "addTextBox", `${path}.properties.fontSize`);
|
|
7550
|
+
}
|
|
7551
|
+
assertBooleanOrUndefined(properties.bold, "addTextBox", `${path}.properties.bold`);
|
|
7552
|
+
assertBooleanOrUndefined(properties.italic, "addTextBox", `${path}.properties.italic`);
|
|
7553
|
+
assertBooleanOrUndefined(properties.strike, "addTextBox", `${path}.properties.strike`);
|
|
7554
|
+
if (color !== void 0) assertTextBoxColor(color, `${path}.properties.color`);
|
|
7555
|
+
if (gradientFill !== void 0) {
|
|
7556
|
+
if (color !== void 0) {
|
|
7557
|
+
throw new Error(`addTextBox: ${path}.properties cannot set both color and gradientFill`);
|
|
7558
|
+
}
|
|
7559
|
+
assertTextBoxGradientFill(gradientFill, `${path}.properties.gradientFill`);
|
|
7560
|
+
}
|
|
7561
|
+
if (underline !== void 0) {
|
|
7562
|
+
assertTextBoxUnderline(underline, `${path}.properties.underline`);
|
|
7563
|
+
}
|
|
7564
|
+
if (baseline !== void 0) {
|
|
7565
|
+
assertTextBoxBaseline(baseline, `${path}.properties.baseline`);
|
|
7566
|
+
}
|
|
7567
|
+
if (highlight !== void 0) {
|
|
7568
|
+
assertTextBoxColor(highlight, `${path}.properties.highlight`);
|
|
7569
|
+
}
|
|
7570
|
+
if (glow !== void 0) assertTextBoxGlow(glow, `${path}.properties.glow`);
|
|
7571
|
+
if (outline !== void 0) {
|
|
7572
|
+
assertTextBoxOutline(outline, `${path}.properties.outline`);
|
|
7573
|
+
}
|
|
7574
|
+
if (charSpacing !== void 0) {
|
|
7575
|
+
assertTextPointNumber(charSpacing, "addTextBox", `${path}.properties.charSpacing`);
|
|
7576
|
+
}
|
|
7577
|
+
}
|
|
7578
|
+
function assertTextBoxColor(color, path) {
|
|
7579
|
+
if (!isPlainRecord(color)) {
|
|
7580
|
+
throw new Error(`addTextBox: ${path} must be an srgb 6-digit hex color`);
|
|
7581
|
+
}
|
|
7582
|
+
if (color.kind !== "srgb" || typeof color.hex !== "string" || !/^[0-9A-Fa-f]{6}$/.test(color.hex)) {
|
|
7583
|
+
throw new Error(`addTextBox: ${path} must be an srgb 6-digit hex color`);
|
|
7584
|
+
}
|
|
7585
|
+
}
|
|
7586
|
+
function assertTextBoxGradientFill(fill, path) {
|
|
7587
|
+
if (!isPlainRecord(fill)) {
|
|
7588
|
+
throw new Error(`addTextBox: ${path} must be a gradient fill object`);
|
|
7589
|
+
}
|
|
7590
|
+
const stops = fill.stops;
|
|
7591
|
+
if (!isArrayValue(stops) || stops.length < 2) {
|
|
7592
|
+
throw new Error(`addTextBox: ${path}.stops must contain at least two stops`);
|
|
7593
|
+
}
|
|
7594
|
+
if (fill.angle !== void 0)
|
|
7595
|
+
assertFiniteIntegerNumber(fill.angle, "addTextBox", `${path}.angle`);
|
|
7596
|
+
stops.forEach((stop, index) => {
|
|
7597
|
+
if (!isPlainRecord(stop)) {
|
|
7598
|
+
throw new Error(`addTextBox: ${path}.stops[${index}] must be an object`);
|
|
7599
|
+
}
|
|
7600
|
+
const position = stop.position;
|
|
7601
|
+
assertFiniteIntegerNumber(position, "addTextBox", `${path}.stops[${index}].position`);
|
|
7602
|
+
if (typeof position !== "number" || position < 0 || position > 1e5) {
|
|
7603
|
+
throw new Error(`addTextBox: ${path}.stops[${index}].position must be between 0 and 100000`);
|
|
7604
|
+
}
|
|
7605
|
+
assertTextBoxColor(stop.color, `${path}.stops[${index}].color`);
|
|
7606
|
+
});
|
|
7607
|
+
}
|
|
7608
|
+
function isArrayValue(value) {
|
|
7609
|
+
return Array.isArray(value);
|
|
7610
|
+
}
|
|
7611
|
+
function assertTextBoxUnderline(underline, path) {
|
|
7612
|
+
if (typeof underline === "boolean") return;
|
|
7613
|
+
if (!isPlainRecord(underline)) {
|
|
7614
|
+
throw new Error(`addTextBox: ${path} must be a boolean or underline options object`);
|
|
7615
|
+
}
|
|
7616
|
+
const style = underline.style ?? "sng";
|
|
7617
|
+
if (typeof style !== "string" || !UNDERLINE_STYLES.has(style)) {
|
|
7618
|
+
throw new Error(`addTextBox: ${path}.style is not supported`);
|
|
7619
|
+
}
|
|
7620
|
+
if (underline.color !== void 0) {
|
|
7621
|
+
assertTextBoxColor(underline.color, `${path}.color`);
|
|
7622
|
+
}
|
|
7623
|
+
}
|
|
7624
|
+
function assertTextBoxBaseline(baseline, path) {
|
|
7625
|
+
if (baseline === "subscript" || baseline === "superscript") return;
|
|
7626
|
+
throw new Error(`addTextBox: ${path} must be subscript or superscript`);
|
|
7627
|
+
}
|
|
7628
|
+
function assertTextBoxGlow(glow, path) {
|
|
7629
|
+
if (!isPlainRecord(glow)) {
|
|
7630
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
7631
|
+
}
|
|
7632
|
+
assertPositiveFiniteEmu(glow.radius, "addTextBox", `${path}.radius`);
|
|
7633
|
+
assertTextBoxColor(glow.color, `${path}.color`);
|
|
7634
|
+
}
|
|
7635
|
+
function assertTextBoxOutline(outline, path) {
|
|
7636
|
+
if (!isPlainRecord(outline)) {
|
|
7637
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
7638
|
+
}
|
|
7639
|
+
if (outline.width === void 0 && outline.color === void 0) {
|
|
7640
|
+
throw new Error(`addTextBox: ${path} must set width or color`);
|
|
7641
|
+
}
|
|
7642
|
+
if (outline.width !== void 0) {
|
|
7643
|
+
assertPositiveFiniteEmu(outline.width, "addTextBox", `${path}.width`);
|
|
7644
|
+
}
|
|
7645
|
+
if (outline.color !== void 0) assertTextBoxColor(outline.color, `${path}.color`);
|
|
7646
|
+
}
|
|
7647
|
+
function assertTextBoxBody(body, path) {
|
|
7648
|
+
if (!isPlainRecord(body)) {
|
|
7649
|
+
throw new Error(`addTextBox: ${path} must be an object`);
|
|
7650
|
+
}
|
|
7651
|
+
if (body.anchor !== void 0 && body.anchor !== "top" && body.anchor !== "middle" && body.anchor !== "bottom") {
|
|
7652
|
+
throw new Error("addTextBox: body.anchor is not supported");
|
|
7653
|
+
}
|
|
7654
|
+
if (body.marginLeft !== void 0)
|
|
7655
|
+
assertFiniteEmu(body.marginLeft, "addTextBox", "body.marginLeft");
|
|
7656
|
+
if (body.marginRight !== void 0) {
|
|
7657
|
+
assertFiniteEmu(body.marginRight, "addTextBox", "body.marginRight");
|
|
7658
|
+
}
|
|
7659
|
+
if (body.marginTop !== void 0) assertFiniteEmu(body.marginTop, "addTextBox", "body.marginTop");
|
|
7660
|
+
if (body.marginBottom !== void 0) {
|
|
7661
|
+
assertFiniteEmu(body.marginBottom, "addTextBox", "body.marginBottom");
|
|
7662
|
+
}
|
|
7663
|
+
}
|
|
7324
7664
|
function assertConnectorInput(input) {
|
|
7325
7665
|
assertFiniteEmu(input.offsetX, "addConnector", "offsetX");
|
|
7326
7666
|
assertFiniteEmu(input.offsetY, "addConnector", "offsetY");
|
|
@@ -7359,13 +7699,39 @@ function assertArrowEndpoint(endpoint, fieldName) {
|
|
|
7359
7699
|
throw new Error(`addConnector: outline.${fieldName}.length is not supported`);
|
|
7360
7700
|
}
|
|
7361
7701
|
}
|
|
7702
|
+
function assertBooleanOrUndefined(value, operationName, fieldName) {
|
|
7703
|
+
if (value !== void 0 && typeof value !== "boolean") {
|
|
7704
|
+
throw new Error(`${operationName}: ${fieldName} must be a boolean value`);
|
|
7705
|
+
}
|
|
7706
|
+
}
|
|
7707
|
+
function assertFiniteIntegerNumber(value, operationName, fieldName) {
|
|
7708
|
+
if (!Number.isInteger(value)) {
|
|
7709
|
+
throw new Error(`${operationName}: ${fieldName} must be a finite integer`);
|
|
7710
|
+
}
|
|
7711
|
+
}
|
|
7712
|
+
function assertPositiveFiniteNumber(value, operationName, fieldName) {
|
|
7713
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
7714
|
+
throw new Error(`${operationName}: ${fieldName} must be a finite positive number`);
|
|
7715
|
+
}
|
|
7716
|
+
}
|
|
7717
|
+
function assertPositiveFiniteIntegerNumber(value, operationName, fieldName) {
|
|
7718
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
7719
|
+
throw new Error(`${operationName}: ${fieldName} must be a finite positive integer`);
|
|
7720
|
+
}
|
|
7721
|
+
}
|
|
7722
|
+
function assertTextPointNumber(value, operationName, fieldName) {
|
|
7723
|
+
assertFiniteIntegerNumber(value, operationName, fieldName);
|
|
7724
|
+
if (typeof value !== "number" || value < -4e5 || value > 4e5) {
|
|
7725
|
+
throw new Error(`${operationName}: ${fieldName} must be between -400000 and 400000`);
|
|
7726
|
+
}
|
|
7727
|
+
}
|
|
7362
7728
|
function assertFiniteEmu(value, operationName, fieldName) {
|
|
7363
|
-
if (!Number.isFinite(value)) {
|
|
7729
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
7364
7730
|
throw new Error(`${operationName}: ${fieldName} must be a finite EMU value`);
|
|
7365
7731
|
}
|
|
7366
7732
|
}
|
|
7367
7733
|
function assertPositiveFiniteEmu(value, operationName, fieldName) {
|
|
7368
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
7734
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
7369
7735
|
throw new Error(`${operationName}: ${fieldName} must be a finite positive EMU value`);
|
|
7370
7736
|
}
|
|
7371
7737
|
}
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectUsedFonts
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OOQWOZHT.js";
|
|
4
4
|
import {
|
|
5
5
|
convertPptxToPng,
|
|
6
6
|
convertPptxToSvg,
|
|
7
7
|
renderPptxSourceModelToSvg
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-Q3ZCUUGG.js";
|
|
9
|
+
import "./chunk-VBQRNQOT.js";
|
|
10
10
|
import {
|
|
11
11
|
DEFAULT_FONT_MAPPING,
|
|
12
12
|
clearFontCache,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pptx-glimpse",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "A lightweight JavaScript library for rendering PowerPoint (.pptx) files as SVG or PNG in Node.js and the browser. No LibreOffice required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"fast-xml-parser": "^5.7.3",
|
|
51
51
|
"fflate": "^0.8.2",
|
|
52
52
|
"opentype.js": "1.3.4",
|
|
53
|
-
"@pptx-glimpse/document": "^0.
|
|
53
|
+
"@pptx-glimpse/document": "^0.5.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@pptx-glimpse/editor-core": "0.0.
|
|
56
|
+
"@pptx-glimpse/editor-core": "0.0.5",
|
|
57
57
|
"@pptx-glimpse/renderer": "0.0.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|