pptx-glimpse 3.1.0 → 3.1.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/cli.cjs CHANGED
@@ -6110,104 +6110,21 @@ init_warning_logger();
6110
6110
 
6111
6111
  // ../document/dist/index.js
6112
6112
  var import_fast_xml_parser = require("fast-xml-parser");
6113
- var import_fflate = require("fflate");
6114
6113
  var import_fast_xml_parser2 = require("fast-xml-parser");
6114
+ var import_fflate = require("fflate");
6115
6115
  var import_fflate2 = require("fflate");
6116
+ var import_fast_xml_parser3 = require("fast-xml-parser");
6116
6117
  function unsafeOoxmlBoundaryAssertion(value) {
6117
6118
  return value;
6118
6119
  }
6119
6120
  function unsafeBrandAssertion2(value) {
6120
6121
  return value;
6121
6122
  }
6122
- function asPartPath(value) {
6123
- return unsafeBrandAssertion2(value);
6124
- }
6125
- function asRelationshipId(value) {
6126
- return unsafeBrandAssertion2(value);
6127
- }
6128
- function asSourceNodeId(value) {
6129
- return unsafeBrandAssertion2(value);
6130
- }
6131
- function asRawSidecarId(value) {
6132
- return unsafeBrandAssertion2(value);
6133
- }
6134
- var RELS_SUFFIX = ".rels";
6135
- var RELS_MARKER = "_rels/";
6136
- var ABSOLUTE_URI_PATTERN = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
6137
- function isRelationshipPart(path) {
6138
- return path.endsWith(RELS_SUFFIX) && path.includes(RELS_MARKER);
6139
- }
6140
- function relationshipsSourcePartPath(relsPath) {
6141
- const idx = relsPath.lastIndexOf(RELS_MARKER);
6142
- const dir = relsPath.slice(0, idx);
6143
- const file = relsPath.slice(idx + RELS_MARKER.length);
6144
- const base = file.endsWith(RELS_SUFFIX) ? file.slice(0, -RELS_SUFFIX.length) : file;
6145
- return asPartPath(dir + base);
6146
- }
6147
- function resolveRelationshipTarget(sourcePartPath, target) {
6148
- if (ABSOLUTE_URI_PATTERN.test(target)) return target;
6149
- const combined = target.startsWith("/") ? target.slice(1) : joinPackageRelativeTarget(sourcePartPath, target);
6150
- return normalizePackagePath(combined);
6151
- }
6152
- function resolveInternalRelationshipTarget(sourcePartPath, relationship) {
6153
- if (relationship.targetMode === "External") return void 0;
6154
- return asPartPath(resolveRelationshipTarget(sourcePartPath, relationship.target));
6155
- }
6156
- function parseRelationshipTargetMode(value) {
6157
- if (value === "Internal" || value === "External") return value;
6158
- return void 0;
6159
- }
6160
- function joinPackageRelativeTarget(sourcePartPath, target) {
6161
- const slash = sourcePartPath.lastIndexOf("/");
6162
- const baseDir = slash === -1 ? "" : sourcePartPath.slice(0, slash);
6163
- return baseDir === "" ? target : `${baseDir}/${target}`;
6164
- }
6165
- function normalizePackagePath(path) {
6166
- const segments = [];
6167
- for (const segment of path.split("/")) {
6168
- if (segment === "" || segment === ".") continue;
6169
- if (segment === "..") {
6170
- segments.pop();
6171
- continue;
6172
- }
6173
- segments.push(segment);
6174
- }
6175
- return segments.join("/");
6176
- }
6177
- var EDITABLE_TEXT_RUN_PROPERTIES = [
6178
- "bold",
6179
- "italic",
6180
- "underline",
6181
- "fontSize",
6182
- "color",
6183
- "typeface"
6184
- ];
6185
- var EDITABLE_TEXT_RUN_PROPERTY_SET = new Set(EDITABLE_TEXT_RUN_PROPERTIES);
6186
- function asEmu2(value) {
6187
- return unsafeBrandAssertion2(value);
6188
- }
6189
- function asPt(value) {
6190
- return unsafeBrandAssertion2(value);
6191
- }
6192
- function asHundredthPt2(value) {
6193
- return unsafeBrandAssertion2(value);
6194
- }
6195
- function asOoxmlPercent(value) {
6196
- return unsafeBrandAssertion2(value);
6197
- }
6198
- function asOoxmlAngle(value) {
6199
- return unsafeBrandAssertion2(value);
6200
- }
6201
- function parseEnumValue(value, allowed) {
6202
- return value !== void 0 && allowed.has(unsafeOoxmlBoundaryAssertion(value)) ? unsafeOoxmlBoundaryAssertion(value) : void 0;
6203
- }
6204
- function parseEnumValueWithDefault(value, allowed, fallback) {
6205
- return parseEnumValue(value, allowed) ?? fallback;
6206
- }
6207
6123
  var parser = new import_fast_xml_parser.XMLParser({
6208
6124
  ignoreAttributes: false,
6209
6125
  attributeNamePrefix: "@_",
6210
6126
  parseAttributeValue: false,
6127
+ parseTagValue: false,
6211
6128
  // Retain prefix. See the comment at the beginning of the file for the reason.
6212
6129
  removeNSPrefix: false,
6213
6130
  // Do not trim text run (`a:t`) to preserve significant white space at the beginning and end.
@@ -6320,6 +6237,62 @@ function scalarToString(value) {
6320
6237
  if (typeof value === "number" || typeof value === "boolean") return String(value);
6321
6238
  return void 0;
6322
6239
  }
6240
+ function asPartPath(value) {
6241
+ return unsafeBrandAssertion2(value);
6242
+ }
6243
+ function asRelationshipId(value) {
6244
+ return unsafeBrandAssertion2(value);
6245
+ }
6246
+ function asSourceNodeId(value) {
6247
+ return unsafeBrandAssertion2(value);
6248
+ }
6249
+ function asRawSidecarId(value) {
6250
+ return unsafeBrandAssertion2(value);
6251
+ }
6252
+ var RELS_SUFFIX = ".rels";
6253
+ var RELS_MARKER = "_rels/";
6254
+ var ABSOLUTE_URI_PATTERN = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
6255
+ function isRelationshipPart(path) {
6256
+ return path.endsWith(RELS_SUFFIX) && path.includes(RELS_MARKER);
6257
+ }
6258
+ function relationshipsSourcePartPath(relsPath) {
6259
+ const idx = relsPath.lastIndexOf(RELS_MARKER);
6260
+ const dir = relsPath.slice(0, idx);
6261
+ const file = relsPath.slice(idx + RELS_MARKER.length);
6262
+ const base = file.endsWith(RELS_SUFFIX) ? file.slice(0, -RELS_SUFFIX.length) : file;
6263
+ return asPartPath(dir + base);
6264
+ }
6265
+ function resolveRelationshipTarget(sourcePartPath, target) {
6266
+ if (ABSOLUTE_URI_PATTERN.test(target)) return target;
6267
+ const combined = target.startsWith("/") ? target.slice(1) : joinPackageRelativeTarget(sourcePartPath, target);
6268
+ return normalizePackagePath(combined);
6269
+ }
6270
+ function resolveInternalRelationshipTarget(sourcePartPath, relationship) {
6271
+ if (relationship.targetMode === "External") return void 0;
6272
+ return asPartPath(resolveRelationshipTarget(sourcePartPath, relationship.target));
6273
+ }
6274
+ function parseRelationshipTargetMode(value) {
6275
+ if (value === "Internal" || value === "External") return value;
6276
+ return void 0;
6277
+ }
6278
+ function joinPackageRelativeTarget(sourcePartPath, target) {
6279
+ const slash = sourcePartPath.lastIndexOf("/");
6280
+ const baseDir = slash === -1 ? "" : sourcePartPath.slice(0, slash);
6281
+ return baseDir === "" ? target : `${baseDir}/${target}`;
6282
+ }
6283
+ function normalizePackagePath(path) {
6284
+ const segments = [];
6285
+ for (const segment of path.split("/")) {
6286
+ if (segment === "" || segment === ".") continue;
6287
+ if (segment === "..") {
6288
+ segments.pop();
6289
+ continue;
6290
+ }
6291
+ segments.push(segment);
6292
+ }
6293
+ return segments.join("/");
6294
+ }
6295
+ var textDecoder = new TextDecoder();
6323
6296
  var ATTR_PREFIX = "@_";
6324
6297
  var TEXT_KEY = "#text";
6325
6298
  function createSidecarIdFactory(partPath) {
@@ -6389,790 +6362,365 @@ function scalarText(value) {
6389
6362
  if (typeof value === "number" || typeof value === "boolean") return String(value);
6390
6363
  return void 0;
6391
6364
  }
6392
- var RECTANGLE_ALIGNMENT_TOKENS = /* @__PURE__ */ new Set([
6393
- "tl",
6394
- "t",
6395
- "tr",
6396
- "l",
6397
- "ctr",
6398
- "r",
6399
- "bl",
6400
- "b",
6401
- "br"
6402
- ]);
6403
- var COLOR_TRANSFORM_KINDS = /* @__PURE__ */ new Set([
6404
- "lumMod",
6405
- "lumOff",
6406
- "tint",
6407
- "shade",
6408
- "alpha"
6409
- ]);
6410
- var RAW_FILL_LOCAL_NAMES = ["grpFill"];
6411
- var PRESET_COLOR_HEX = {
6412
- black: "000000",
6413
- white: "FFFFFF",
6414
- red: "FF0000",
6415
- green: "008000",
6416
- blue: "0000FF",
6417
- yellow: "FFFF00",
6418
- cyan: "00FFFF",
6419
- magenta: "FF00FF"
6420
- };
6421
- function parseColorElement(parent) {
6422
- if (!parent) return void 0;
6423
- const srgb = getChild(parent, "srgbClr");
6424
- if (srgb) {
6425
- const hex = getAttr(srgb, "val");
6426
- if (hex !== void 0) {
6427
- return withTransforms({ kind: "srgb", hex: hex.toUpperCase() }, srgb);
6428
- }
6429
- }
6430
- const scheme = getChild(parent, "schemeClr");
6431
- if (scheme) {
6432
- const name = getAttr(scheme, "val");
6433
- if (name !== void 0) {
6434
- return withTransforms({ kind: "scheme", scheme: name }, scheme);
6435
- }
6436
- }
6437
- const sys = getChild(parent, "sysClr");
6438
- if (sys) {
6439
- const val = getAttr(sys, "val");
6440
- if (val !== void 0) {
6441
- const lastClr = getAttr(sys, "lastClr");
6442
- return withTransforms(
6443
- {
6444
- kind: "system",
6445
- value: val,
6446
- ...lastClr !== void 0 ? { lastColor: lastClr.toUpperCase() } : {}
6447
- },
6448
- sys
6449
- );
6450
- }
6365
+ function parseCustomGeometry(custGeom, orderedCustGeom) {
6366
+ const pathLst = getChild(custGeom, "pathLst");
6367
+ const paths = getChildArray(pathLst, "path");
6368
+ if (paths.length === 0) return void 0;
6369
+ const avGuides = parseGuideList(getChild(custGeom, "avLst"));
6370
+ const guides = parseGuideList(getChild(custGeom, "gdLst"));
6371
+ const orderedPaths = orderedChildEntries(
6372
+ orderedChildChildren(orderedCustGeom, "pathLst"),
6373
+ "path"
6374
+ );
6375
+ const result = [];
6376
+ for (const [index, path] of paths.entries()) {
6377
+ const width = numericAttr(path, "w") ?? 0;
6378
+ const height = numericAttr(path, "h") ?? 0;
6379
+ if (width === 0 && height === 0) continue;
6380
+ const variables = evaluateGuides(avGuides, guides, width, height);
6381
+ const commands = buildPathCommands(path, variables, orderedNodeChildren(orderedPaths[index]));
6382
+ if (commands !== void 0) result.push({ width, height, commands });
6451
6383
  }
6452
- return void 0;
6453
- }
6454
- function parseEffectList(effectList) {
6455
- if (effectList === void 0) return void 0;
6456
- const outerShadow = parseOuterShadow(getChild(effectList, "outerShdw"));
6457
- const innerShadow = parseInnerShadow(getChild(effectList, "innerShdw"));
6458
- const glow = parseGlow(getChild(effectList, "glow"));
6459
- const softEdge = parseSoftEdge(getChild(effectList, "softEdge"));
6460
- const parsed = {
6461
- ...outerShadow !== void 0 ? { outerShadow } : {},
6462
- ...innerShadow !== void 0 ? { innerShadow } : {},
6463
- ...glow !== void 0 ? { glow } : {},
6464
- ...softEdge !== void 0 ? { softEdge } : {}
6465
- };
6466
- return Object.keys(parsed).length > 0 ? parsed : void 0;
6384
+ return result.length > 0 ? result : void 0;
6467
6385
  }
6468
- function parseBlipEffects(blip) {
6469
- if (blip === void 0) return void 0;
6470
- const grayscale = getChild(blip, "grayscl") !== void 0;
6471
- const biLevel = parseBiLevel(getChild(blip, "biLevel"));
6472
- const blur = parseBlurEffect(getChild(blip, "blur"));
6473
- const lum = parseLumEffect(getChild(blip, "lum"));
6474
- const duotone = parseDuotoneEffect(getChild(blip, "duotone"));
6475
- const clrChange = parseColorChangeEffect(getChild(blip, "clrChange"));
6476
- const parsed = {
6477
- grayscale,
6478
- ...biLevel !== void 0 ? { biLevel } : {},
6479
- ...blur !== void 0 ? { blur } : {},
6480
- ...lum !== void 0 ? { lum } : {},
6481
- ...duotone !== void 0 ? { duotone } : {},
6482
- ...clrChange !== void 0 ? { clrChange } : {}
6483
- };
6484
- return grayscale || biLevel !== void 0 || blur !== void 0 || lum !== void 0 || duotone !== void 0 || clrChange !== void 0 ? parsed : void 0;
6386
+ function parseGuideList(parent) {
6387
+ return getChildArray(parent, "gd").map((guide) => ({
6388
+ name: getAttr(guide, "name") ?? "",
6389
+ formula: getAttr(guide, "fmla") ?? ""
6390
+ })).filter((guide) => guide.name !== "" && guide.formula !== "");
6485
6391
  }
6486
- function parseOuterShadow(node) {
6487
- if (node === void 0) return void 0;
6488
- const color = parseColorElement(node);
6489
- if (color === void 0) return void 0;
6490
- return {
6491
- blurRadius: asEmu2(numericAttr(node, "blurRad") ?? 0),
6492
- distance: asEmu2(numericAttr(node, "dist") ?? 0),
6493
- direction: asOoxmlAngle(numericAttr(node, "dir") ?? 0),
6494
- color,
6495
- alignment: parseRectangleAlignment(getAttr(node, "algn"), "b"),
6496
- rotateWithShape: getAttr(node, "rotWithShape") !== "0"
6497
- };
6392
+ function buildPathCommands(path, variables, orderedCommands) {
6393
+ const parts = [];
6394
+ let currentX = 0;
6395
+ let currentY = 0;
6396
+ let startX = 0;
6397
+ let startY = 0;
6398
+ for (const { local, nodes } of pathCommandNodes(path, orderedCommands)) {
6399
+ for (const node of nodes) {
6400
+ if (local === "moveTo") {
6401
+ const point = firstPoint(node, variables);
6402
+ if (point !== void 0) {
6403
+ parts.push(`M ${point.x} ${point.y}`);
6404
+ currentX = point.x;
6405
+ currentY = point.y;
6406
+ startX = point.x;
6407
+ startY = point.y;
6408
+ }
6409
+ } else if (local === "lnTo") {
6410
+ const point = firstPoint(node, variables);
6411
+ if (point !== void 0) {
6412
+ parts.push(`L ${point.x} ${point.y}`);
6413
+ currentX = point.x;
6414
+ currentY = point.y;
6415
+ }
6416
+ } else if (local === "cubicBezTo") {
6417
+ const points = allPoints(node, variables);
6418
+ if (points.length >= 3) {
6419
+ parts.push(`C ${points.map((point) => `${point.x} ${point.y}`).join(", ")}`);
6420
+ currentX = points[points.length - 1].x;
6421
+ currentY = points[points.length - 1].y;
6422
+ }
6423
+ } else if (local === "quadBezTo") {
6424
+ const points = allPoints(node, variables);
6425
+ if (points.length >= 2) {
6426
+ parts.push(`Q ${points.map((point) => `${point.x} ${point.y}`).join(", ")}`);
6427
+ currentX = points[points.length - 1].x;
6428
+ currentY = points[points.length - 1].y;
6429
+ }
6430
+ } else if (local === "arcTo") {
6431
+ const arc = convertArcTo(node, currentX, currentY, variables);
6432
+ if (arc !== void 0) {
6433
+ parts.push(arc.command);
6434
+ currentX = arc.endX;
6435
+ currentY = arc.endY;
6436
+ }
6437
+ } else if (local === "close") {
6438
+ parts.push("Z");
6439
+ currentX = startX;
6440
+ currentY = startY;
6441
+ }
6442
+ }
6443
+ }
6444
+ return parts.length > 0 ? parts.join(" ") : void 0;
6498
6445
  }
6499
- function parseInnerShadow(node) {
6500
- if (node === void 0) return void 0;
6501
- const color = parseColorElement(node);
6502
- if (color === void 0) return void 0;
6503
- return {
6504
- blurRadius: asEmu2(numericAttr(node, "blurRad") ?? 0),
6505
- distance: asEmu2(numericAttr(node, "dist") ?? 0),
6506
- direction: asOoxmlAngle(numericAttr(node, "dir") ?? 0),
6507
- color
6508
- };
6446
+ function pathCommandNodes(path, orderedCommands) {
6447
+ if (orderedCommands === void 0) {
6448
+ return Object.keys(path).filter((key) => !key.startsWith("@_")).map((key) => ({ local: localName(key), nodes: getChildArray(path, localName(key)) }));
6449
+ }
6450
+ const counters = {};
6451
+ const result = [];
6452
+ for (const command of orderedCommands) {
6453
+ const key = orderedNodeKey(command);
6454
+ if (key === void 0) continue;
6455
+ const local = localName(key);
6456
+ const index = counters[local] ?? 0;
6457
+ counters[local] = index + 1;
6458
+ const node = getChildArray(path, local)[index];
6459
+ if (node !== void 0) result.push({ local, nodes: [node] });
6460
+ }
6461
+ return result;
6509
6462
  }
6510
- function parseGlow(node) {
6511
- if (node === void 0) return void 0;
6512
- const color = parseColorElement(node);
6513
- if (color === void 0) return void 0;
6514
- return {
6515
- radius: asEmu2(numericAttr(node, "rad") ?? 0),
6516
- color
6517
- };
6463
+ function firstPoint(node, variables) {
6464
+ return allPoints(node, variables)[0];
6518
6465
  }
6519
- function parseSoftEdge(node) {
6520
- if (node === void 0) return void 0;
6521
- return {
6522
- radius: asEmu2(numericAttr(node, "rad") ?? 0)
6523
- };
6466
+ function allPoints(node, variables) {
6467
+ return getChildArray(node, "pt").map((point) => ({
6468
+ x: resolveValue(getAttr(point, "x") ?? "0", variables),
6469
+ y: resolveValue(getAttr(point, "y") ?? "0", variables)
6470
+ }));
6524
6471
  }
6525
- function parseBiLevel(node) {
6526
- if (node === void 0) return void 0;
6472
+ function convertArcTo(arc, currentX, currentY, variables) {
6473
+ const widthRadius = resolveValue(getAttr(arc, "wR") ?? "0", variables);
6474
+ const heightRadius = resolveValue(getAttr(arc, "hR") ?? "0", variables);
6475
+ const startAngle = resolveValue(getAttr(arc, "stAng") ?? "0", variables);
6476
+ const sweepAngle = resolveValue(getAttr(arc, "swAng") ?? "0", variables);
6477
+ if (widthRadius === 0 && heightRadius === 0 || sweepAngle === 0) return void 0;
6478
+ const startRadians = startAngle / 6e4 * (Math.PI / 180);
6479
+ const endRadians = (startAngle + sweepAngle) / 6e4 * (Math.PI / 180);
6480
+ const centerX = currentX - widthRadius * Math.cos(startRadians);
6481
+ const centerY = currentY - heightRadius * Math.sin(startRadians);
6482
+ const endX = centerX + widthRadius * Math.cos(endRadians);
6483
+ const endY = centerY + heightRadius * Math.sin(endRadians);
6484
+ const largeArcFlag = Math.abs(sweepAngle / 6e4) > 180 ? 1 : 0;
6485
+ const sweepFlag = sweepAngle > 0 ? 1 : 0;
6527
6486
  return {
6528
- threshold: (numericAttr(node, "thresh") ?? 5e4) / 1e5
6487
+ command: `A ${round4(widthRadius)} ${round4(heightRadius)} 0 ${largeArcFlag} ${sweepFlag} ${round4(endX)} ${round4(endY)}`,
6488
+ endX,
6489
+ endY
6529
6490
  };
6530
6491
  }
6531
- function parseBlurEffect(node) {
6532
- if (node === void 0) return void 0;
6492
+ function evaluateGuides(avGuides, guides, width, height) {
6493
+ const variables = createBuiltinVariables(width, height);
6494
+ for (const guide of avGuides) variables[guide.name] = evaluateFormula(guide.formula, variables);
6495
+ for (const guide of guides) variables[guide.name] = evaluateFormula(guide.formula, variables);
6496
+ return variables;
6497
+ }
6498
+ function createBuiltinVariables(width, height) {
6533
6499
  return {
6534
- radius: asEmu2(numericAttr(node, "rad") ?? 0),
6535
- grow: getAttr(node, "grow") !== "0"
6500
+ w: width,
6501
+ h: height,
6502
+ l: 0,
6503
+ t: 0,
6504
+ r: width,
6505
+ b: height,
6506
+ wd2: width / 2,
6507
+ hd2: height / 2,
6508
+ wd4: width / 4,
6509
+ hd4: height / 4,
6510
+ ss: Math.min(width, height),
6511
+ ls: Math.max(width, height),
6512
+ cd2: 108e5,
6513
+ cd4: 54e5,
6514
+ cd8: 27e5,
6515
+ "3cd4": 162e5
6536
6516
  };
6537
6517
  }
6538
- function parseLumEffect(node) {
6539
- if (node === void 0) return void 0;
6540
- return {
6541
- brightness: (numericAttr(node, "bright") ?? 0) / 1e5,
6542
- contrast: (numericAttr(node, "contrast") ?? 0) / 1e5
6518
+ function evaluateFormula(formula, variables) {
6519
+ const tokens = formula.trim().split(/\s+/);
6520
+ const op = tokens[0];
6521
+ const resolve2 = (token) => {
6522
+ if (token === void 0) return 0;
6523
+ const value = Number(token);
6524
+ return Number.isNaN(value) ? variables[token] ?? 0 : value;
6543
6525
  };
6526
+ if (op === "val") return resolve2(tokens[1]);
6527
+ if (op === "+-") return resolve2(tokens[1]) + resolve2(tokens[2]) - resolve2(tokens[3]);
6528
+ if (op === "*/")
6529
+ return Math.round(resolve2(tokens[1]) * resolve2(tokens[2]) / (resolve2(tokens[3]) || 1));
6530
+ if (op === "+/")
6531
+ return Math.round((resolve2(tokens[1]) + resolve2(tokens[2])) / (resolve2(tokens[3]) || 1));
6532
+ if (op === "pin")
6533
+ return Math.max(resolve2(tokens[1]), Math.min(resolve2(tokens[2]), resolve2(tokens[3])));
6534
+ if (op === "min") return Math.min(resolve2(tokens[1]), resolve2(tokens[2]));
6535
+ if (op === "max") return Math.max(resolve2(tokens[1]), resolve2(tokens[2]));
6536
+ if (op === "abs") return Math.abs(resolve2(tokens[1]));
6537
+ if (op === "sqrt") return Math.round(Math.sqrt(resolve2(tokens[1])));
6538
+ if (op === "sin") return Math.round(resolve2(tokens[1]) * Math.sin(toRadians(resolve2(tokens[2]))));
6539
+ if (op === "cos") return Math.round(resolve2(tokens[1]) * Math.cos(toRadians(resolve2(tokens[2]))));
6540
+ if (op === "tan") return Math.round(resolve2(tokens[1]) * Math.tan(toRadians(resolve2(tokens[2]))));
6541
+ if (op === "at2")
6542
+ return Math.round(Math.atan2(resolve2(tokens[2]), resolve2(tokens[1])) * (180 / Math.PI) * 6e4);
6543
+ if (op === "mod") {
6544
+ const a = resolve2(tokens[1]);
6545
+ const b = resolve2(tokens[2]);
6546
+ const c = resolve2(tokens[3]);
6547
+ return Math.round(Math.sqrt(a * a + b * b + c * c));
6548
+ }
6549
+ if (op === "cat2") {
6550
+ return Math.round(
6551
+ resolve2(tokens[1]) * Math.cos(Math.atan2(resolve2(tokens[3]), resolve2(tokens[2])))
6552
+ );
6553
+ }
6554
+ if (op === "sat2") {
6555
+ return Math.round(
6556
+ resolve2(tokens[1]) * Math.sin(Math.atan2(resolve2(tokens[3]), resolve2(tokens[2])))
6557
+ );
6558
+ }
6559
+ if (op === "?:") return resolve2(tokens[1]) > 0 ? resolve2(tokens[2]) : resolve2(tokens[3]);
6560
+ return 0;
6544
6561
  }
6545
- function parseDuotoneEffect(node) {
6546
- if (node === void 0) return void 0;
6547
- const colors = collectColorChildren(node);
6548
- if (colors.length < 2) return void 0;
6549
- return { color1: colors[0], color2: colors[1] };
6562
+ function resolveValue(value, variables) {
6563
+ const numeric = Number(value);
6564
+ return Number.isNaN(numeric) ? variables[value] ?? 0 : numeric;
6550
6565
  }
6551
- function parseColorChangeEffect(node) {
6552
- if (node === void 0) return void 0;
6553
- const from = firstColorChild(getChild(node, "clrFrom"));
6554
- const to = firstColorChild(getChild(node, "clrTo"));
6555
- return from !== void 0 && to !== void 0 ? { from, to } : void 0;
6566
+ function numericAttr(node, name) {
6567
+ const raw = getAttr(node, name);
6568
+ if (raw === void 0) return void 0;
6569
+ const value = Number(raw);
6570
+ return Number.isFinite(value) ? value : void 0;
6556
6571
  }
6557
- function collectColorChildren(parent) {
6558
- const colors = [];
6559
- for (const [key, value] of Object.entries(parent)) {
6560
- if (key.startsWith("@_")) continue;
6561
- const nodes = Array.isArray(value) ? value : [value];
6562
- for (const node of nodes) {
6563
- if (!isXmlNode(node)) continue;
6564
- const color = parseColorChild(key, node);
6565
- if (color !== void 0) colors.push(color);
6566
- }
6567
- }
6568
- return colors;
6572
+ function round4(value) {
6573
+ return Math.round(value * 1e3) / 1e3;
6569
6574
  }
6570
- function firstColorChild(parent) {
6571
- return parent !== void 0 ? collectColorChildren(parent)[0] : void 0;
6575
+ function toRadians(ooxmlAngle) {
6576
+ return ooxmlAngle / 6e4 * (Math.PI / 180);
6572
6577
  }
6573
- function parseColorChild(key, node) {
6574
- const name = localName(key);
6575
- return name === "prstClr" ? parsePresetColor(node) : parseColorElement({ [name]: node });
6578
+ function orderedChildChildren(parent, childLocalName) {
6579
+ const child = orderedChildEntries(parent, childLocalName)[0];
6580
+ return orderedNodeChildren(child);
6576
6581
  }
6577
- function isXmlNode(value) {
6578
- return typeof value === "object" && value !== null;
6582
+ function orderedChildEntries(parent, childLocalName) {
6583
+ if (parent === void 0) return [];
6584
+ return parent.filter((child) => {
6585
+ const key = orderedNodeKey(child);
6586
+ return key !== void 0 && localName(key) === childLocalName;
6587
+ });
6579
6588
  }
6580
- function parsePresetColor(node) {
6581
- const value = getAttr(node, "val");
6582
- const hex = value !== void 0 ? PRESET_COLOR_HEX[value] : void 0;
6583
- return hex !== void 0 ? withTransforms({ kind: "srgb", hex }, node) : void 0;
6589
+ function orderedNodeChildren(node) {
6590
+ const key = node !== void 0 ? orderedNodeKey(node) : void 0;
6591
+ const value = key !== void 0 ? node?.[key] : void 0;
6592
+ return Array.isArray(value) ? value : void 0;
6584
6593
  }
6585
- function parseFill(parent, nextId) {
6586
- if (!parent) return void 0;
6587
- const solid = getChild(parent, "solidFill");
6588
- if (solid) {
6589
- const color = parseColorElement(solid);
6590
- if (color) return { kind: "solid", color };
6591
- return { kind: "raw", raw: makeSidecar("a:solidFill", solid, nextId) };
6592
- }
6593
- if (hasChild(parent, "noFill")) return { kind: "none" };
6594
- const grad = getChild(parent, "gradFill");
6595
- if (grad) {
6596
- const fill = parseGradientFill(grad);
6597
- return fill ?? { kind: "raw", raw: makeSidecar("a:gradFill", grad, nextId) };
6598
- }
6599
- const blip = getChild(parent, "blipFill");
6600
- if (blip) {
6601
- return parseBlipFill(blip) ?? { kind: "raw", raw: makeSidecar("a:blipFill", blip, nextId) };
6602
- }
6603
- const pattern = getChild(parent, "pattFill");
6604
- if (pattern) {
6605
- const fill = parsePatternFill(pattern);
6606
- return fill ?? { kind: "raw", raw: makeSidecar("a:pattFill", pattern, nextId) };
6607
- }
6608
- for (const name of RAW_FILL_LOCAL_NAMES) {
6609
- if (hasChild(parent, name)) {
6610
- return { kind: "raw", raw: makeSidecar(`a:${name}`, getChild(parent, name) ?? {}, nextId) };
6611
- }
6612
- }
6613
- return void 0;
6614
- }
6615
- function parseGradientFill(grad) {
6616
- const stops = [];
6617
- for (const gs of getChildArray(getChild(grad, "gsLst"), "gs")) {
6618
- const color = parseColorElement(gs);
6619
- if (color === void 0) continue;
6620
- stops.push({
6621
- position: (numericAttr(gs, "pos") ?? 0) / 1e5,
6622
- color
6623
- });
6624
- }
6625
- if (stops.length === 0) return void 0;
6626
- const path = getChild(grad, "path");
6627
- if (path !== void 0) {
6628
- const fillToRect = getChild(path, "fillToRect");
6629
- const l = numericAttr(fillToRect, "l") ?? 0;
6630
- const t = numericAttr(fillToRect, "t") ?? 0;
6631
- const r = numericAttr(fillToRect, "r") ?? 0;
6632
- const b = numericAttr(fillToRect, "b") ?? 0;
6633
- return {
6634
- kind: "gradient",
6635
- gradientType: "radial",
6636
- stops,
6637
- centerX: (l + (1e5 - r)) / 2 / 1e5,
6638
- centerY: (t + (1e5 - b)) / 2 / 1e5
6639
- };
6640
- }
6641
- return {
6642
- kind: "gradient",
6643
- gradientType: "linear",
6644
- stops,
6645
- angle: asOoxmlAngle(numericAttr(getChild(grad, "lin"), "ang") ?? 0)
6646
- };
6647
- }
6648
- function parseBlipFill(blipFill) {
6649
- const blip = getChild(blipFill, "blip");
6650
- const embed = getNamespacedAttr(blip, "embed");
6651
- if (embed === void 0) return void 0;
6652
- const tile = parseImageFillTile(getChild(blipFill, "tile"));
6653
- return {
6654
- kind: "image",
6655
- blipRelationshipId: asRelationshipId(embed),
6656
- ...tile !== void 0 ? { tile } : {}
6657
- };
6658
- }
6659
- function parseImageFillTile(tile) {
6660
- if (tile === void 0) return void 0;
6661
- const flip = getAttr(tile, "flip") ?? "none";
6662
- return {
6663
- tx: asEmu2(numericAttr(tile, "tx") ?? 0),
6664
- ty: asEmu2(numericAttr(tile, "ty") ?? 0),
6665
- sx: (numericAttr(tile, "sx") ?? 1e5) / 1e5,
6666
- sy: (numericAttr(tile, "sy") ?? 1e5) / 1e5,
6667
- flip: flip === "x" || flip === "y" || flip === "xy" ? flip : "none",
6668
- align: parseRectangleAlignment(getAttr(tile, "algn"), "tl")
6669
- };
6670
- }
6671
- function parseRectangleAlignment(value, fallback) {
6672
- return parseEnumValueWithDefault(value, RECTANGLE_ALIGNMENT_TOKENS, fallback);
6594
+ function orderedNodeKey(node) {
6595
+ return Object.keys(node).find((key) => key !== ":@");
6673
6596
  }
6674
- function parsePatternFill(pattern) {
6675
- const foregroundColor = parseColorElement(getChild(pattern, "fgClr"));
6676
- const backgroundColor = parseColorElement(getChild(pattern, "bgClr"));
6677
- if (foregroundColor === void 0 || backgroundColor === void 0) return void 0;
6678
- return {
6679
- kind: "pattern",
6680
- preset: getAttr(pattern, "prst") ?? "ltDnDiag",
6681
- foregroundColor,
6682
- backgroundColor
6683
- };
6597
+ function parseEnumValue(value, allowed) {
6598
+ return value !== void 0 && allowed.has(unsafeOoxmlBoundaryAssertion(value)) ? unsafeOoxmlBoundaryAssertion(value) : void 0;
6684
6599
  }
6685
- function parseOutline(spPr, nextId) {
6686
- const ln = getChild(spPr, "ln");
6687
- return parseLine(ln, nextId);
6600
+ function parseEnumValueWithDefault(value, allowed, fallback) {
6601
+ return parseEnumValue(value, allowed) ?? fallback;
6688
6602
  }
6689
- function parseLine(ln, nextId) {
6690
- if (!ln) return void 0;
6691
- const width = numericAttr(ln, "w");
6692
- const fill = parseFill(ln, nextId);
6693
- const dashStyle = parseDashStyle(getChild(ln, "prstDash"));
6694
- const customDash = parseCustomDash(ln);
6695
- const lineCap = parseLineCap(getAttr(ln, "cap"));
6696
- const lineJoin = parseLineJoin(ln);
6697
- const headEnd = parseArrowEndpoint(getChild(ln, "headEnd"));
6698
- const tailEnd = parseArrowEndpoint(getChild(ln, "tailEnd"));
6603
+ var KNOWN_TXBODY_CHILDREN = /* @__PURE__ */ new Set(["bodyPr", "lstStyle", "p"]);
6604
+ var KNOWN_PARAGRAPH_CHILDREN = /* @__PURE__ */ new Set([
6605
+ "pPr",
6606
+ "r",
6607
+ "fld",
6608
+ "br",
6609
+ "endParaRPr"
6610
+ ]);
6611
+ var KNOWN_RUN_CHILDREN = /* @__PURE__ */ new Set(["rPr", "t"]);
6612
+ var KNOWN_RUN_PROPERTY_CHILDREN = /* @__PURE__ */ new Set([
6613
+ "latin",
6614
+ "ea",
6615
+ "cs",
6616
+ "solidFill"
6617
+ ]);
6618
+ var ALIGN_MAP = {
6619
+ l: "left",
6620
+ ctr: "center",
6621
+ r: "right",
6622
+ just: "justify"
6623
+ };
6624
+ var ANCHOR_MAP = {
6625
+ t: "top",
6626
+ ctr: "middle",
6627
+ b: "bottom"
6628
+ };
6629
+ var WRAP_VALUES = /* @__PURE__ */ new Set(["square", "none"]);
6630
+ var VERTICAL_VALUES = /* @__PURE__ */ new Set([
6631
+ "horz",
6632
+ "vert",
6633
+ "vert270",
6634
+ "eaVert",
6635
+ "wordArtVert",
6636
+ "mongolianVert"
6637
+ ]);
6638
+ var VALID_AUTO_NUM_SCHEMES = /* @__PURE__ */ new Set([
6639
+ "arabicPeriod",
6640
+ "arabicParenR",
6641
+ "romanUcPeriod",
6642
+ "romanLcPeriod",
6643
+ "alphaUcPeriod",
6644
+ "alphaLcPeriod",
6645
+ "alphaLcParenR",
6646
+ "alphaUcParenR",
6647
+ "arabicPlain"
6648
+ ]);
6649
+ function parseTextBody(txBody, partPath, nextId, ownerNodeId, ownerOrderingSlot, orderedTxBody) {
6650
+ if (!txBody) return void 0;
6651
+ const properties = parseBodyProperties(getChild(txBody, "bodyPr"));
6652
+ const listStyle = parseTextStyle(getChild(txBody, "lstStyle"));
6653
+ const orderedParagraphs = orderedTxBody?.filter((child) => orderedLocalName(child) === "p").map((child) => {
6654
+ const key = orderedKey(child);
6655
+ const value = key !== void 0 ? child[key] : void 0;
6656
+ return Array.isArray(value) ? value : void 0;
6657
+ });
6658
+ const paragraphs = [];
6659
+ let logicalParagraphIndex = 0;
6660
+ getChildArray(txBody, "p").forEach((p, paragraphIndex) => {
6661
+ const orderedChildren = orderedParagraphs?.[paragraphIndex];
6662
+ if (orderedChildren !== void 0 && hasMultipleBulletPPr(p, orderedChildren)) {
6663
+ const split = splitInterleavedParagraph(
6664
+ p,
6665
+ orderedChildren,
6666
+ partPath,
6667
+ nextId,
6668
+ ownerNodeId,
6669
+ ownerOrderingSlot,
6670
+ logicalParagraphIndex
6671
+ );
6672
+ paragraphs.push(...split);
6673
+ logicalParagraphIndex += split.length;
6674
+ return;
6675
+ }
6676
+ paragraphs.push(
6677
+ parseParagraph(
6678
+ p,
6679
+ partPath,
6680
+ nextId,
6681
+ ownerNodeId,
6682
+ ownerOrderingSlot,
6683
+ logicalParagraphIndex,
6684
+ orderedChildren
6685
+ )
6686
+ );
6687
+ logicalParagraphIndex++;
6688
+ });
6689
+ const rawSidecars = collectUnknownSidecars(txBody, KNOWN_TXBODY_CHILDREN, nextId);
6699
6690
  return {
6700
- ...width !== void 0 ? { width: asEmu2(width) } : {},
6701
- ...fill !== void 0 ? { fill } : {},
6702
- ...dashStyle !== void 0 ? { dashStyle } : {},
6703
- ...customDash !== void 0 ? { customDash } : {},
6704
- ...lineCap !== void 0 ? { lineCap } : {},
6705
- ...lineJoin !== void 0 ? { lineJoin } : {},
6706
- ...headEnd !== void 0 ? { headEnd } : {},
6707
- ...tailEnd !== void 0 ? { tailEnd } : {}
6691
+ paragraphs,
6692
+ ...properties !== void 0 ? { properties } : {},
6693
+ ...listStyle !== void 0 ? { listStyle } : {},
6694
+ handle: { partPath },
6695
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
6708
6696
  };
6709
6697
  }
6710
- function parseTransform(spPr) {
6711
- const xfrm = getChild(spPr, "xfrm");
6712
- if (!xfrm) return void 0;
6713
- const off = getChild(xfrm, "off");
6714
- const ext = getChild(xfrm, "ext");
6715
- const offsetX = numericAttr(off, "x");
6716
- const offsetY = numericAttr(off, "y");
6717
- const width = numericAttr(ext, "cx");
6718
- const height = numericAttr(ext, "cy");
6719
- if (offsetX === void 0 || offsetY === void 0 || width === void 0 || height === void 0) {
6698
+ function parseTextStyle(node) {
6699
+ if (node === void 0) return void 0;
6700
+ const defaultParagraph = parseParagraphProperties(getChild(node, "defPPr"));
6701
+ const levels = Array.from(
6702
+ { length: 9 },
6703
+ (_, index) => parseParagraphProperties(getChild(node, `lvl${index + 1}pPr`))
6704
+ );
6705
+ if (defaultParagraph === void 0 && levels.every((level) => level === void 0)) {
6720
6706
  return void 0;
6721
6707
  }
6722
- const rotation = numericAttr(xfrm, "rot");
6723
- const flipH = getAttr(xfrm, "flipH");
6724
- const flipV = getAttr(xfrm, "flipV");
6725
- return {
6726
- offsetX: asEmu2(offsetX),
6727
- offsetY: asEmu2(offsetY),
6728
- width: asEmu2(width),
6729
- height: asEmu2(height),
6730
- ...rotation !== void 0 ? { rotation: asOoxmlAngle(rotation) } : {},
6731
- ...isTrue(flipH) ? { flipHorizontal: true } : {},
6732
- ...isTrue(flipV) ? { flipVertical: true } : {}
6733
- };
6708
+ return { ...defaultParagraph !== void 0 ? { defaultParagraph } : {}, levels };
6734
6709
  }
6735
- function withTransforms(base, colorNode) {
6736
- const transforms = [];
6737
- for (const key of Object.keys(colorNode)) {
6738
- if (key.startsWith("@_")) continue;
6739
- const kind = localName(key);
6740
- const transformKind = parseEnumValue(kind, COLOR_TRANSFORM_KINDS);
6741
- if (transformKind === void 0) continue;
6742
- const value = colorNode[key];
6743
- const items = Array.isArray(value) ? value : [value];
6744
- for (const item of items) {
6745
- const raw = getAttr(unsafeOoxmlBoundaryAssertion(item), "val");
6746
- if (raw === void 0) continue;
6747
- const numeric = Number(raw);
6748
- if (!Number.isFinite(numeric)) continue;
6749
- transforms.push({
6750
- kind: transformKind,
6751
- value: asOoxmlPercent(numeric)
6752
- });
6710
+ function hasMultipleBulletPPr(p, orderedChildren) {
6711
+ const pPrList = getChildArray(p, "pPr");
6712
+ let bulletPPrCount = 0;
6713
+ let pPrCounter = 0;
6714
+ for (const child of orderedChildren) {
6715
+ if (orderedLocalName(child) !== "pPr") continue;
6716
+ const pPr = pPrList[pPrCounter];
6717
+ if (pPr !== void 0 && (getChild(pPr, "buChar") !== void 0 || getChild(pPr, "buAutoNum") !== void 0)) {
6718
+ bulletPPrCount++;
6719
+ if (bulletPPrCount >= 2) return true;
6753
6720
  }
6721
+ pPrCounter++;
6754
6722
  }
6755
- return transforms.length > 0 ? { ...base, transforms } : base;
6756
- }
6757
- function numericAttr(node, name) {
6758
- const raw = getAttr(node, name);
6759
- if (raw === void 0) return void 0;
6760
- const value = Number(raw);
6761
- return Number.isFinite(value) ? value : void 0;
6762
- }
6763
- function isTrue(value) {
6764
- return value === "1" || value === "true";
6765
- }
6766
- function parseDashStyle(prstDash) {
6767
- const value = getAttr(prstDash, "val");
6768
- return parseEnumValue(value, DASH_STYLES);
6769
- }
6770
- function parseCustomDash(ln) {
6771
- const custDash = getChild(ln, "custDash");
6772
- const segments = getChildArray(custDash, "ds");
6773
- if (segments.length === 0) return void 0;
6774
- return segments.flatMap((segment) => [
6775
- (numericAttr(segment, "d") ?? 1e5) / 1e5,
6776
- (numericAttr(segment, "sp") ?? 1e5) / 1e5
6777
- ]);
6778
- }
6779
- var LINE_CAP_MAP = {
6780
- flat: "butt",
6781
- sq: "square",
6782
- rnd: "round"
6783
- };
6784
- function parseLineCap(value) {
6785
- return value !== void 0 ? LINE_CAP_MAP[value] : void 0;
6786
- }
6787
- function parseLineJoin(ln) {
6788
- if (hasChild(ln, "round")) return "round";
6789
- if (hasChild(ln, "bevel")) return "bevel";
6790
- if (hasChild(ln, "miter")) return "miter";
6791
- return void 0;
6792
- }
6793
- function parseArrowEndpoint(node) {
6794
- if (!node) return void 0;
6795
- const type = parseEnumValue(getAttr(node, "type"), ARROW_TYPES2);
6796
- if (type === void 0) return void 0;
6797
- const width = getAttr(node, "w") ?? "med";
6798
- const length = getAttr(node, "len") ?? "med";
6799
- return {
6800
- type,
6801
- width: parseEnumValueWithDefault(width, ARROW_SIZES2, "med"),
6802
- length: parseEnumValueWithDefault(length, ARROW_SIZES2, "med")
6803
- };
6804
- }
6805
- var DASH_STYLES = /* @__PURE__ */ new Set([
6806
- "solid",
6807
- "dash",
6808
- "dot",
6809
- "dashDot",
6810
- "lgDash",
6811
- "lgDashDot",
6812
- "sysDash",
6813
- "sysDot"
6814
- ]);
6815
- var ARROW_TYPES2 = /* @__PURE__ */ new Set([
6816
- "triangle",
6817
- "stealth",
6818
- "diamond",
6819
- "oval",
6820
- "arrow"
6821
- ]);
6822
- var ARROW_SIZES2 = /* @__PURE__ */ new Set(["sm", "med", "lg"]);
6823
- function parseCustomGeometry(custGeom, orderedCustGeom) {
6824
- const pathLst = getChild(custGeom, "pathLst");
6825
- const paths = getChildArray(pathLst, "path");
6826
- if (paths.length === 0) return void 0;
6827
- const avGuides = parseGuideList(getChild(custGeom, "avLst"));
6828
- const guides = parseGuideList(getChild(custGeom, "gdLst"));
6829
- const orderedPaths = orderedChildEntries(
6830
- orderedChildChildren(orderedCustGeom, "pathLst"),
6831
- "path"
6832
- );
6833
- const result = [];
6834
- for (const [index, path] of paths.entries()) {
6835
- const width = numericAttr2(path, "w") ?? 0;
6836
- const height = numericAttr2(path, "h") ?? 0;
6837
- if (width === 0 && height === 0) continue;
6838
- const variables = evaluateGuides(avGuides, guides, width, height);
6839
- const commands = buildPathCommands(path, variables, orderedNodeChildren(orderedPaths[index]));
6840
- if (commands !== void 0) result.push({ width, height, commands });
6841
- }
6842
- return result.length > 0 ? result : void 0;
6843
- }
6844
- function parseGuideList(parent) {
6845
- return getChildArray(parent, "gd").map((guide) => ({
6846
- name: getAttr(guide, "name") ?? "",
6847
- formula: getAttr(guide, "fmla") ?? ""
6848
- })).filter((guide) => guide.name !== "" && guide.formula !== "");
6849
- }
6850
- function buildPathCommands(path, variables, orderedCommands) {
6851
- const parts = [];
6852
- let currentX = 0;
6853
- let currentY = 0;
6854
- let startX = 0;
6855
- let startY = 0;
6856
- for (const { local, nodes } of pathCommandNodes(path, orderedCommands)) {
6857
- for (const node of nodes) {
6858
- if (local === "moveTo") {
6859
- const point = firstPoint(node, variables);
6860
- if (point !== void 0) {
6861
- parts.push(`M ${point.x} ${point.y}`);
6862
- currentX = point.x;
6863
- currentY = point.y;
6864
- startX = point.x;
6865
- startY = point.y;
6866
- }
6867
- } else if (local === "lnTo") {
6868
- const point = firstPoint(node, variables);
6869
- if (point !== void 0) {
6870
- parts.push(`L ${point.x} ${point.y}`);
6871
- currentX = point.x;
6872
- currentY = point.y;
6873
- }
6874
- } else if (local === "cubicBezTo") {
6875
- const points = allPoints(node, variables);
6876
- if (points.length >= 3) {
6877
- parts.push(`C ${points.map((point) => `${point.x} ${point.y}`).join(", ")}`);
6878
- currentX = points[points.length - 1].x;
6879
- currentY = points[points.length - 1].y;
6880
- }
6881
- } else if (local === "quadBezTo") {
6882
- const points = allPoints(node, variables);
6883
- if (points.length >= 2) {
6884
- parts.push(`Q ${points.map((point) => `${point.x} ${point.y}`).join(", ")}`);
6885
- currentX = points[points.length - 1].x;
6886
- currentY = points[points.length - 1].y;
6887
- }
6888
- } else if (local === "arcTo") {
6889
- const arc = convertArcTo(node, currentX, currentY, variables);
6890
- if (arc !== void 0) {
6891
- parts.push(arc.command);
6892
- currentX = arc.endX;
6893
- currentY = arc.endY;
6894
- }
6895
- } else if (local === "close") {
6896
- parts.push("Z");
6897
- currentX = startX;
6898
- currentY = startY;
6899
- }
6900
- }
6901
- }
6902
- return parts.length > 0 ? parts.join(" ") : void 0;
6903
- }
6904
- function pathCommandNodes(path, orderedCommands) {
6905
- if (orderedCommands === void 0) {
6906
- return Object.keys(path).filter((key) => !key.startsWith("@_")).map((key) => ({ local: localName(key), nodes: getChildArray(path, localName(key)) }));
6907
- }
6908
- const counters = {};
6909
- const result = [];
6910
- for (const command of orderedCommands) {
6911
- const key = orderedNodeKey(command);
6912
- if (key === void 0) continue;
6913
- const local = localName(key);
6914
- const index = counters[local] ?? 0;
6915
- counters[local] = index + 1;
6916
- const node = getChildArray(path, local)[index];
6917
- if (node !== void 0) result.push({ local, nodes: [node] });
6918
- }
6919
- return result;
6920
- }
6921
- function firstPoint(node, variables) {
6922
- return allPoints(node, variables)[0];
6923
- }
6924
- function allPoints(node, variables) {
6925
- return getChildArray(node, "pt").map((point) => ({
6926
- x: resolveValue(getAttr(point, "x") ?? "0", variables),
6927
- y: resolveValue(getAttr(point, "y") ?? "0", variables)
6928
- }));
6929
- }
6930
- function convertArcTo(arc, currentX, currentY, variables) {
6931
- const widthRadius = resolveValue(getAttr(arc, "wR") ?? "0", variables);
6932
- const heightRadius = resolveValue(getAttr(arc, "hR") ?? "0", variables);
6933
- const startAngle = resolveValue(getAttr(arc, "stAng") ?? "0", variables);
6934
- const sweepAngle = resolveValue(getAttr(arc, "swAng") ?? "0", variables);
6935
- if (widthRadius === 0 && heightRadius === 0 || sweepAngle === 0) return void 0;
6936
- const startRadians = startAngle / 6e4 * (Math.PI / 180);
6937
- const endRadians = (startAngle + sweepAngle) / 6e4 * (Math.PI / 180);
6938
- const centerX = currentX - widthRadius * Math.cos(startRadians);
6939
- const centerY = currentY - heightRadius * Math.sin(startRadians);
6940
- const endX = centerX + widthRadius * Math.cos(endRadians);
6941
- const endY = centerY + heightRadius * Math.sin(endRadians);
6942
- const largeArcFlag = Math.abs(sweepAngle / 6e4) > 180 ? 1 : 0;
6943
- const sweepFlag = sweepAngle > 0 ? 1 : 0;
6944
- return {
6945
- command: `A ${round4(widthRadius)} ${round4(heightRadius)} 0 ${largeArcFlag} ${sweepFlag} ${round4(endX)} ${round4(endY)}`,
6946
- endX,
6947
- endY
6948
- };
6949
- }
6950
- function evaluateGuides(avGuides, guides, width, height) {
6951
- const variables = createBuiltinVariables(width, height);
6952
- for (const guide of avGuides) variables[guide.name] = evaluateFormula(guide.formula, variables);
6953
- for (const guide of guides) variables[guide.name] = evaluateFormula(guide.formula, variables);
6954
- return variables;
6955
- }
6956
- function createBuiltinVariables(width, height) {
6957
- return {
6958
- w: width,
6959
- h: height,
6960
- l: 0,
6961
- t: 0,
6962
- r: width,
6963
- b: height,
6964
- wd2: width / 2,
6965
- hd2: height / 2,
6966
- wd4: width / 4,
6967
- hd4: height / 4,
6968
- ss: Math.min(width, height),
6969
- ls: Math.max(width, height),
6970
- cd2: 108e5,
6971
- cd4: 54e5,
6972
- cd8: 27e5,
6973
- "3cd4": 162e5
6974
- };
6975
- }
6976
- function evaluateFormula(formula, variables) {
6977
- const tokens = formula.trim().split(/\s+/);
6978
- const op = tokens[0];
6979
- const resolve2 = (token) => {
6980
- if (token === void 0) return 0;
6981
- const value = Number(token);
6982
- return Number.isNaN(value) ? variables[token] ?? 0 : value;
6983
- };
6984
- if (op === "val") return resolve2(tokens[1]);
6985
- if (op === "+-") return resolve2(tokens[1]) + resolve2(tokens[2]) - resolve2(tokens[3]);
6986
- if (op === "*/")
6987
- return Math.round(resolve2(tokens[1]) * resolve2(tokens[2]) / (resolve2(tokens[3]) || 1));
6988
- if (op === "+/")
6989
- return Math.round((resolve2(tokens[1]) + resolve2(tokens[2])) / (resolve2(tokens[3]) || 1));
6990
- if (op === "pin")
6991
- return Math.max(resolve2(tokens[1]), Math.min(resolve2(tokens[2]), resolve2(tokens[3])));
6992
- if (op === "min") return Math.min(resolve2(tokens[1]), resolve2(tokens[2]));
6993
- if (op === "max") return Math.max(resolve2(tokens[1]), resolve2(tokens[2]));
6994
- if (op === "abs") return Math.abs(resolve2(tokens[1]));
6995
- if (op === "sqrt") return Math.round(Math.sqrt(resolve2(tokens[1])));
6996
- if (op === "sin") return Math.round(resolve2(tokens[1]) * Math.sin(toRadians(resolve2(tokens[2]))));
6997
- if (op === "cos") return Math.round(resolve2(tokens[1]) * Math.cos(toRadians(resolve2(tokens[2]))));
6998
- if (op === "tan") return Math.round(resolve2(tokens[1]) * Math.tan(toRadians(resolve2(tokens[2]))));
6999
- if (op === "at2")
7000
- return Math.round(Math.atan2(resolve2(tokens[2]), resolve2(tokens[1])) * (180 / Math.PI) * 6e4);
7001
- if (op === "mod") {
7002
- const a = resolve2(tokens[1]);
7003
- const b = resolve2(tokens[2]);
7004
- const c = resolve2(tokens[3]);
7005
- return Math.round(Math.sqrt(a * a + b * b + c * c));
7006
- }
7007
- if (op === "cat2") {
7008
- return Math.round(
7009
- resolve2(tokens[1]) * Math.cos(Math.atan2(resolve2(tokens[3]), resolve2(tokens[2])))
7010
- );
7011
- }
7012
- if (op === "sat2") {
7013
- return Math.round(
7014
- resolve2(tokens[1]) * Math.sin(Math.atan2(resolve2(tokens[3]), resolve2(tokens[2])))
7015
- );
7016
- }
7017
- if (op === "?:") return resolve2(tokens[1]) > 0 ? resolve2(tokens[2]) : resolve2(tokens[3]);
7018
- return 0;
7019
- }
7020
- function resolveValue(value, variables) {
7021
- const numeric = Number(value);
7022
- return Number.isNaN(numeric) ? variables[value] ?? 0 : numeric;
7023
- }
7024
- function numericAttr2(node, name) {
7025
- const raw = getAttr(node, name);
7026
- if (raw === void 0) return void 0;
7027
- const value = Number(raw);
7028
- return Number.isFinite(value) ? value : void 0;
7029
- }
7030
- function round4(value) {
7031
- return Math.round(value * 1e3) / 1e3;
7032
- }
7033
- function toRadians(ooxmlAngle) {
7034
- return ooxmlAngle / 6e4 * (Math.PI / 180);
7035
- }
7036
- function orderedChildChildren(parent, childLocalName) {
7037
- const child = orderedChildEntries(parent, childLocalName)[0];
7038
- return orderedNodeChildren(child);
7039
- }
7040
- function orderedChildEntries(parent, childLocalName) {
7041
- if (parent === void 0) return [];
7042
- return parent.filter((child) => {
7043
- const key = orderedNodeKey(child);
7044
- return key !== void 0 && localName(key) === childLocalName;
7045
- });
7046
- }
7047
- function orderedNodeChildren(node) {
7048
- const key = node !== void 0 ? orderedNodeKey(node) : void 0;
7049
- const value = key !== void 0 ? node?.[key] : void 0;
7050
- return Array.isArray(value) ? value : void 0;
7051
- }
7052
- function orderedNodeKey(node) {
7053
- return Object.keys(node).find((key) => key !== ":@");
7054
- }
7055
- var KNOWN_TXBODY_CHILDREN = /* @__PURE__ */ new Set(["bodyPr", "lstStyle", "p"]);
7056
- var KNOWN_PARAGRAPH_CHILDREN = /* @__PURE__ */ new Set([
7057
- "pPr",
7058
- "r",
7059
- "fld",
7060
- "br",
7061
- "endParaRPr"
7062
- ]);
7063
- var KNOWN_RUN_CHILDREN = /* @__PURE__ */ new Set(["rPr", "t"]);
7064
- var KNOWN_RUN_PROPERTY_CHILDREN = /* @__PURE__ */ new Set([
7065
- "latin",
7066
- "ea",
7067
- "cs",
7068
- "solidFill"
7069
- ]);
7070
- var ALIGN_MAP = {
7071
- l: "left",
7072
- ctr: "center",
7073
- r: "right",
7074
- just: "justify"
7075
- };
7076
- var ANCHOR_MAP = {
7077
- t: "top",
7078
- ctr: "middle",
7079
- b: "bottom"
7080
- };
7081
- var WRAP_VALUES = /* @__PURE__ */ new Set(["square", "none"]);
7082
- var VERTICAL_VALUES = /* @__PURE__ */ new Set([
7083
- "horz",
7084
- "vert",
7085
- "vert270",
7086
- "eaVert",
7087
- "wordArtVert",
7088
- "mongolianVert"
7089
- ]);
7090
- var VALID_AUTO_NUM_SCHEMES = /* @__PURE__ */ new Set([
7091
- "arabicPeriod",
7092
- "arabicParenR",
7093
- "romanUcPeriod",
7094
- "romanLcPeriod",
7095
- "alphaUcPeriod",
7096
- "alphaLcPeriod",
7097
- "alphaLcParenR",
7098
- "alphaUcParenR",
7099
- "arabicPlain"
7100
- ]);
7101
- function parseTextBody(txBody, partPath, nextId, ownerNodeId, ownerOrderingSlot, orderedTxBody) {
7102
- if (!txBody) return void 0;
7103
- const properties = parseBodyProperties(getChild(txBody, "bodyPr"));
7104
- const listStyle = parseTextStyle(getChild(txBody, "lstStyle"));
7105
- const orderedParagraphs = orderedTxBody?.filter((child) => orderedLocalName(child) === "p").map((child) => {
7106
- const key = orderedKey(child);
7107
- const value = key !== void 0 ? child[key] : void 0;
7108
- return Array.isArray(value) ? value : void 0;
7109
- });
7110
- const paragraphs = [];
7111
- let logicalParagraphIndex = 0;
7112
- getChildArray(txBody, "p").forEach((p, paragraphIndex) => {
7113
- const orderedChildren = orderedParagraphs?.[paragraphIndex];
7114
- if (orderedChildren !== void 0 && hasMultipleBulletPPr(p, orderedChildren)) {
7115
- const split = splitInterleavedParagraph(
7116
- p,
7117
- orderedChildren,
7118
- partPath,
7119
- nextId,
7120
- ownerNodeId,
7121
- ownerOrderingSlot,
7122
- logicalParagraphIndex
7123
- );
7124
- paragraphs.push(...split);
7125
- logicalParagraphIndex += split.length;
7126
- return;
7127
- }
7128
- paragraphs.push(
7129
- parseParagraph(
7130
- p,
7131
- partPath,
7132
- nextId,
7133
- ownerNodeId,
7134
- ownerOrderingSlot,
7135
- logicalParagraphIndex,
7136
- orderedChildren
7137
- )
7138
- );
7139
- logicalParagraphIndex++;
7140
- });
7141
- const rawSidecars = collectUnknownSidecars(txBody, KNOWN_TXBODY_CHILDREN, nextId);
7142
- return {
7143
- paragraphs,
7144
- ...properties !== void 0 ? { properties } : {},
7145
- ...listStyle !== void 0 ? { listStyle } : {},
7146
- handle: { partPath },
7147
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7148
- };
7149
- }
7150
- function parseTextStyle(node) {
7151
- if (node === void 0) return void 0;
7152
- const defaultParagraph = parseParagraphProperties(getChild(node, "defPPr"));
7153
- const levels = Array.from(
7154
- { length: 9 },
7155
- (_, index) => parseParagraphProperties(getChild(node, `lvl${index + 1}pPr`))
7156
- );
7157
- if (defaultParagraph === void 0 && levels.every((level) => level === void 0)) {
7158
- return void 0;
7159
- }
7160
- return { ...defaultParagraph !== void 0 ? { defaultParagraph } : {}, levels };
7161
- }
7162
- function hasMultipleBulletPPr(p, orderedChildren) {
7163
- const pPrList = getChildArray(p, "pPr");
7164
- let bulletPPrCount = 0;
7165
- let pPrCounter = 0;
7166
- for (const child of orderedChildren) {
7167
- if (orderedLocalName(child) !== "pPr") continue;
7168
- const pPr = pPrList[pPrCounter];
7169
- if (pPr !== void 0 && (getChild(pPr, "buChar") !== void 0 || getChild(pPr, "buAutoNum") !== void 0)) {
7170
- bulletPPrCount++;
7171
- if (bulletPPrCount >= 2) return true;
7172
- }
7173
- pPrCounter++;
7174
- }
7175
- return false;
6723
+ return false;
7176
6724
  }
7177
6725
  function splitInterleavedParagraph(p, orderedChildren, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex) {
7178
6726
  const pPrList = getChildArray(p, "pPr");
@@ -7273,20 +6821,20 @@ function splitInterleavedParagraph(p, orderedChildren, partPath, nextId, ownerNo
7273
6821
  }
7274
6822
  function parseBodyProperties(bodyPr) {
7275
6823
  if (!bodyPr) return void 0;
7276
- const marginLeft = numericAttr(bodyPr, "lIns");
7277
- const marginRight = numericAttr(bodyPr, "rIns");
7278
- const marginTop = numericAttr(bodyPr, "tIns");
7279
- const marginBottom = numericAttr(bodyPr, "bIns");
6824
+ const marginLeft = numericAttr2(bodyPr, "lIns");
6825
+ const marginRight = numericAttr2(bodyPr, "rIns");
6826
+ const marginTop = numericAttr2(bodyPr, "tIns");
6827
+ const marginBottom = numericAttr2(bodyPr, "bIns");
7280
6828
  const anchorToken = getAttr(bodyPr, "anchor");
7281
6829
  const anchor = anchorToken !== void 0 ? ANCHOR_MAP[anchorToken] : void 0;
7282
6830
  const wrap = parseWrap(getAttr(bodyPr, "wrap"));
7283
6831
  const vert = parseVerticalType(getAttr(bodyPr, "vert"));
7284
- const numCol = numericAttr(bodyPr, "numCol");
6832
+ const numCol = numericAttr2(bodyPr, "numCol");
7285
6833
  const normAutofit = getChild(bodyPr, "normAutofit");
7286
6834
  const hasSpAutofit = getChild(bodyPr, "spAutoFit") !== void 0;
7287
6835
  const hasNoAutofit = getChild(bodyPr, "noAutofit") !== void 0;
7288
- const fontScale = numericAttr(normAutofit, "fontScale");
7289
- const lnSpcReduction = numericAttr(normAutofit, "lnSpcReduction");
6836
+ const fontScale = numericAttr2(normAutofit, "fontScale");
6837
+ const lnSpcReduction = numericAttr2(normAutofit, "lnSpcReduction");
7290
6838
  const properties = {
7291
6839
  ...marginLeft !== void 0 ? { marginLeft: emu(marginLeft) } : {},
7292
6840
  ...marginRight !== void 0 ? { marginRight: emu(marginRight) } : {},
@@ -7418,16 +6966,16 @@ function parseParagraphProperties(pPr) {
7418
6966
  if (!pPr) return void 0;
7419
6967
  const alignToken = getAttr(pPr, "algn");
7420
6968
  const align = alignToken !== void 0 ? ALIGN_MAP[alignToken] : void 0;
7421
- const level = numericAttr(pPr, "lvl");
6969
+ const level = numericAttr2(pPr, "lvl");
7422
6970
  const lineSpacing = parseSpacing(getChild(pPr, "lnSpc"));
7423
6971
  const spaceBefore = parseSpacing(getChild(pPr, "spcBef"));
7424
6972
  const spaceAfter = parseSpacing(getChild(pPr, "spcAft"));
7425
- const marginLeft = numericAttr(pPr, "marL");
7426
- const indent = numericAttr(pPr, "indent");
6973
+ const marginLeft = numericAttr2(pPr, "marL");
6974
+ const indent = numericAttr2(pPr, "indent");
7427
6975
  const bullet = parseBullet(pPr);
7428
6976
  const bulletFont = getAttr(getChild(pPr, "buFont"), "typeface");
7429
6977
  const bulletColor = parseColorElement(getChild(pPr, "buClr"));
7430
- const bulletSizePct = numericAttr(getChild(pPr, "buSzPct"), "val");
6978
+ const bulletSizePct = numericAttr2(getChild(pPr, "buSzPct"), "val");
7431
6979
  const tabStops = parseTabStops(pPr);
7432
6980
  const defaultRunProperties = parseRunProperties(getChild(pPr, "defRPr"));
7433
6981
  const properties = {
@@ -7447,859 +6995,1344 @@ function parseParagraphProperties(pPr) {
7447
6995
  };
7448
6996
  return Object.keys(properties).length > 0 ? properties : void 0;
7449
6997
  }
7450
- function parseTabStops(pPr) {
7451
- return getChildArray(getChild(pPr, "tabLst"), "tab").map((tab) => ({
7452
- position: emu(numericAttr(tab, "pos") ?? 0),
7453
- alignment: unsafeOoxmlBoundaryAssertion(getAttr(tab, "algn")) ?? "l"
7454
- }));
6998
+ function parseTabStops(pPr) {
6999
+ return getChildArray(getChild(pPr, "tabLst"), "tab").map((tab) => ({
7000
+ position: emu(numericAttr2(tab, "pos") ?? 0),
7001
+ alignment: unsafeOoxmlBoundaryAssertion(getAttr(tab, "algn")) ?? "l"
7002
+ }));
7003
+ }
7004
+ function parseSpacing(node) {
7005
+ const points = numericAttr2(getChild(node, "spcPts"), "val");
7006
+ if (points !== void 0) return { type: "pts", value: asHundredthPt2(points) };
7007
+ const percent = numericAttr2(getChild(node, "spcPct"), "val");
7008
+ if (percent !== void 0) return { type: "pct", value: percent };
7009
+ return void 0;
7010
+ }
7011
+ function parseBullet(pPr) {
7012
+ if (pPr === void 0) return void 0;
7013
+ if (getChild(pPr, "buNone") !== void 0) return { type: "none" };
7014
+ const buChar = getChild(pPr, "buChar");
7015
+ if (buChar !== void 0) {
7016
+ return { type: "char", char: decodeXmlCharRef(getAttr(buChar, "char") ?? "\u2022") };
7017
+ }
7018
+ const buAutoNum = getChild(pPr, "buAutoNum");
7019
+ if (buAutoNum !== void 0) {
7020
+ const scheme = getAttr(buAutoNum, "type") ?? "arabicPeriod";
7021
+ return {
7022
+ type: "autoNum",
7023
+ scheme: parseEnumValueWithDefault(scheme, VALID_AUTO_NUM_SCHEMES, "arabicPeriod"),
7024
+ startAt: numericAttr2(buAutoNum, "startAt") ?? 1
7025
+ };
7026
+ }
7027
+ return void 0;
7028
+ }
7029
+ function decodeXmlCharRef(value) {
7030
+ return value.replace(
7031
+ /&#x([0-9a-fA-F]+);|&#([0-9]+);/g,
7032
+ (_match, hex, decimal) => String.fromCodePoint(parseInt(hex ?? decimal ?? "0", hex !== void 0 ? 16 : 10))
7033
+ );
7034
+ }
7035
+ function parseRun(r, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7036
+ const properties = parseRunProperties(getChild(r, "rPr"));
7037
+ const rawSidecars = collectRunSidecars(r, nextId);
7038
+ return {
7039
+ kind: "textRun",
7040
+ text: decodeXmlCharRef(getChildText(r, "t") ?? ""),
7041
+ ...properties !== void 0 ? { properties } : {},
7042
+ handle: {
7043
+ partPath,
7044
+ nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7045
+ orderingSlot: runIndex
7046
+ },
7047
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7048
+ };
7049
+ }
7050
+ function parseBreakRun(br, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7051
+ const properties = parseRunProperties(getChild(br, "rPr"));
7052
+ return {
7053
+ kind: "textRun",
7054
+ text: "\n",
7055
+ ...properties !== void 0 ? { properties } : {},
7056
+ handle: {
7057
+ partPath,
7058
+ nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7059
+ orderingSlot: runIndex
7060
+ }
7061
+ };
7062
+ }
7063
+ function parseRunProperties(rPr) {
7064
+ if (!rPr) return void 0;
7065
+ const bold = getAttr(rPr, "b");
7066
+ const italic = getAttr(rPr, "i");
7067
+ const underline = getAttr(rPr, "u");
7068
+ const strike = getAttr(rPr, "strike");
7069
+ const baseline = numericAttr2(rPr, "baseline");
7070
+ const size = numericAttr2(rPr, "sz");
7071
+ const typeface = getAttr(getChild(rPr, "latin"), "typeface");
7072
+ const typefaceEa = getAttr(getChild(rPr, "ea"), "typeface");
7073
+ const typefaceCs = getAttr(getChild(rPr, "cs"), "typeface");
7074
+ const hasHyperlink = getChild(rPr, "hlinkClick") !== void 0;
7075
+ const color = parseColorElement(getChild(rPr, "solidFill"));
7076
+ const properties = {
7077
+ ...bold !== void 0 ? { bold: isTrue(bold) } : {},
7078
+ ...italic !== void 0 ? { italic: isTrue(italic) } : {},
7079
+ ...underline !== void 0 ? { underline: underline !== "none" } : hasHyperlink ? { underline: true } : {},
7080
+ ...strike !== void 0 ? { strikethrough: strike !== "noStrike" } : {},
7081
+ ...baseline !== void 0 ? { baseline: baseline / 1e3 } : {},
7082
+ // `a:rPr@sz` is in 1/100 pt unit. Convert to pt and save.
7083
+ ...size !== void 0 ? { fontSize: asPt(size / 100) } : {},
7084
+ ...typeface !== void 0 ? { typeface } : {},
7085
+ ...typefaceEa !== void 0 ? { typefaceEa } : {},
7086
+ ...typefaceCs !== void 0 ? { typefaceCs } : {},
7087
+ ...color !== void 0 ? { color } : hasHyperlink ? { color: { kind: "scheme", scheme: "hlink" } } : {}
7088
+ };
7089
+ return Object.keys(properties).length > 0 ? properties : void 0;
7090
+ }
7091
+ function collectRunSidecars(r, nextId) {
7092
+ const runLevel = collectUnknownSidecars(r, KNOWN_RUN_CHILDREN, nextId);
7093
+ const propLevel = collectUnknownSidecars(getChild(r, "rPr"), KNOWN_RUN_PROPERTY_CHILDREN, nextId);
7094
+ return [...runLevel, ...propLevel];
7455
7095
  }
7456
- function parseSpacing(node) {
7457
- const points = numericAttr(getChild(node, "spcPts"), "val");
7458
- if (points !== void 0) return { type: "pts", value: asHundredthPt2(points) };
7459
- const percent = numericAttr(getChild(node, "spcPct"), "val");
7460
- if (percent !== void 0) return { type: "pct", value: percent };
7461
- return void 0;
7096
+ function emu(value) {
7097
+ return asEmu2(value);
7462
7098
  }
7463
- function parseBullet(pPr) {
7464
- if (pPr === void 0) return void 0;
7465
- if (getChild(pPr, "buNone") !== void 0) return { type: "none" };
7466
- const buChar = getChild(pPr, "buChar");
7467
- if (buChar !== void 0) {
7468
- return { type: "char", char: decodeXmlCharRef(getAttr(buChar, "char") ?? "\u2022") };
7099
+ function textNodeId(kind, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7100
+ const owner = ownerNodeId !== void 0 ? `shape:${ownerNodeId}` : `shapeSlot:${ownerOrderingSlot}`;
7101
+ const suffix = kind === "paragraph" ? `p:${paragraphIndex}` : `p:${paragraphIndex}:r:${runIndex}`;
7102
+ return asSourceNodeId(`text:${owner}:${suffix}`);
7103
+ }
7104
+ function orderedKey(node) {
7105
+ return Object.keys(node).find((key) => key !== ":@");
7106
+ }
7107
+ function orderedLocalName(node) {
7108
+ const key = orderedKey(node);
7109
+ return key !== void 0 ? localName(key) : void 0;
7110
+ }
7111
+ var KNOWN_SHAPE_CHILDREN = /* @__PURE__ */ new Set(["nvSpPr", "spPr", "style", "txBody"]);
7112
+ var KNOWN_CONNECTOR_CHILDREN = /* @__PURE__ */ new Set(["nvCxnSpPr", "spPr", "style"]);
7113
+ var KNOWN_GROUP_CHILDREN = /* @__PURE__ */ new Set(["nvGrpSpPr", "grpSpPr"]);
7114
+ var KNOWN_PICTURE_CHILDREN = /* @__PURE__ */ new Set(["nvPicPr", "blipFill", "spPr"]);
7115
+ var KNOWN_BLIP_FILL_CHILDREN = /* @__PURE__ */ new Set([
7116
+ "blip",
7117
+ "srcRect",
7118
+ "stretch",
7119
+ "tile"
7120
+ ]);
7121
+ var KNOWN_BLIP_CHILDREN = /* @__PURE__ */ new Set([
7122
+ "grayscl",
7123
+ "biLevel",
7124
+ "blur",
7125
+ "lum",
7126
+ "duotone",
7127
+ "clrChange"
7128
+ ]);
7129
+ var KNOWN_EFFECT_CHILDREN = /* @__PURE__ */ new Set([
7130
+ "outerShdw",
7131
+ "innerShdw",
7132
+ "glow",
7133
+ "softEdge"
7134
+ ]);
7135
+ var KNOWN_GRAPHIC_FRAME_CHILDREN = /* @__PURE__ */ new Set([
7136
+ "nvGraphicFramePr",
7137
+ "xfrm",
7138
+ "graphic"
7139
+ ]);
7140
+ var KNOWN_GRAPHIC_CHILDREN = /* @__PURE__ */ new Set(["graphicData"]);
7141
+ var KNOWN_GRAPHIC_DATA_CHILDREN = /* @__PURE__ */ new Set(["tbl"]);
7142
+ var KNOWN_TABLE_CHILDREN = /* @__PURE__ */ new Set(["tblPr", "tblGrid", "tr"]);
7143
+ var KNOWN_TABLE_CELL_CHILDREN = /* @__PURE__ */ new Set(["txBody", "tcPr"]);
7144
+ var KNOWN_TABLE_CELL_PROPERTIES_CHILDREN = /* @__PURE__ */ new Set([
7145
+ "lnL",
7146
+ "lnR",
7147
+ "lnT",
7148
+ "lnB",
7149
+ "solidFill",
7150
+ "noFill",
7151
+ "gradFill",
7152
+ "blipFill",
7153
+ "pattFill",
7154
+ "grpFill"
7155
+ ]);
7156
+ var KNOWN_SP_PR_CHILDREN = /* @__PURE__ */ new Set([
7157
+ "xfrm",
7158
+ "prstGeom",
7159
+ "solidFill",
7160
+ "noFill",
7161
+ "gradFill",
7162
+ "blipFill",
7163
+ "pattFill",
7164
+ "grpFill",
7165
+ "ln",
7166
+ "effectLst"
7167
+ ]);
7168
+ var SHAPE_TREE_NODE_TAGS = /* @__PURE__ */ new Set([
7169
+ "sp",
7170
+ "pic",
7171
+ "cxnSp",
7172
+ "grpSp",
7173
+ "graphicFrame"
7174
+ ]);
7175
+ var CHART_GRAPHIC_DATA_URIS = /* @__PURE__ */ new Set([
7176
+ "http://schemas.openxmlformats.org/drawingml/2006/chart",
7177
+ "http://purl.oclc.org/ooxml/drawingml/chart"
7178
+ ]);
7179
+ var SMARTART_DIAGRAM_URIS = /* @__PURE__ */ new Set([
7180
+ "http://schemas.openxmlformats.org/drawingml/2006/diagram",
7181
+ "http://purl.oclc.org/ooxml/drawingml/diagram"
7182
+ ]);
7183
+ function parseShapeTree(spTree, partPath, nextId, orderedChildren) {
7184
+ if (!spTree) return [];
7185
+ if (orderedChildren !== void 0) {
7186
+ return parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren);
7469
7187
  }
7470
- const buAutoNum = getChild(pPr, "buAutoNum");
7471
- if (buAutoNum !== void 0) {
7472
- const scheme = getAttr(buAutoNum, "type") ?? "arabicPeriod";
7473
- return {
7474
- type: "autoNum",
7475
- scheme: parseEnumValueWithDefault(scheme, VALID_AUTO_NUM_SCHEMES, "arabicPeriod"),
7476
- startAt: numericAttr(buAutoNum, "startAt") ?? 1
7477
- };
7188
+ const nodes = [];
7189
+ let orderingSlot = 0;
7190
+ for (const key of Object.keys(spTree)) {
7191
+ if (key.startsWith("@_")) continue;
7192
+ if (key === "#text") continue;
7193
+ const local = localName(key);
7194
+ if (local === "nvGrpSpPr" || local === "grpSpPr") continue;
7195
+ const value = spTree[key];
7196
+ const items = Array.isArray(value) ? value : [value];
7197
+ for (const item of items) {
7198
+ const node = unsafeOoxmlBoundaryAssertion(item);
7199
+ if (local === "sp") {
7200
+ nodes.push(parseShape(node, partPath, nextId, orderingSlot));
7201
+ } else if (local === "pic") {
7202
+ nodes.push(parseImage(node, partPath, nextId, orderingSlot));
7203
+ } else if (local === "cxnSp") {
7204
+ nodes.push(parseConnector(node, partPath, nextId, orderingSlot));
7205
+ } else if (local === "grpSp") {
7206
+ nodes.push(parseGroup(node, partPath, nextId, orderingSlot));
7207
+ } else if (local === "graphicFrame") {
7208
+ nodes.push(parseGraphicFrame(node, partPath, nextId, orderingSlot));
7209
+ } else if (local === "AlternateContent") {
7210
+ const parsed = parseAlternateContent(node, partPath, nextId, orderingSlot);
7211
+ nodes.push(...parsed);
7212
+ } else {
7213
+ nodes.push(parseRawShapeNode(key, node, partPath, nextId, orderingSlot));
7214
+ }
7215
+ orderingSlot++;
7216
+ }
7478
7217
  }
7479
- return void 0;
7218
+ return nodes;
7480
7219
  }
7481
- function decodeXmlCharRef(value) {
7482
- return value.replace(
7483
- /&#x([0-9a-fA-F]+);|&#([0-9]+);/g,
7484
- (_match, hex, decimal) => String.fromCodePoint(parseInt(hex ?? decimal ?? "0", hex !== void 0 ? 16 : 10))
7220
+ function parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren) {
7221
+ const nodes = [];
7222
+ const tagCounters = {};
7223
+ let orderingSlot = 0;
7224
+ for (const child of orderedChildren) {
7225
+ const key = Object.keys(child).find((candidate) => candidate !== ":@");
7226
+ if (key === void 0) continue;
7227
+ const local = localName(key);
7228
+ if (local === "AlternateContent") {
7229
+ const index2 = tagCounters[local] ?? 0;
7230
+ tagCounters[local] = index2 + 1;
7231
+ const alternateContents = getChildArray(spTree, "AlternateContent");
7232
+ const alternateContent = alternateContents[index2];
7233
+ if (alternateContent !== void 0) {
7234
+ nodes.push(...parseAlternateContent(alternateContent, partPath, nextId, orderingSlot));
7235
+ orderingSlot++;
7236
+ }
7237
+ continue;
7238
+ }
7239
+ if (!SHAPE_TREE_NODE_TAGS.has(local)) continue;
7240
+ const index = tagCounters[local] ?? 0;
7241
+ tagCounters[local] = index + 1;
7242
+ const node = getChildArray(spTree, local)[index];
7243
+ if (node === void 0) continue;
7244
+ nodes.push(parseShapeTreeNode(local, node, child, partPath, nextId, orderingSlot));
7245
+ orderingSlot++;
7246
+ }
7247
+ return nodes;
7248
+ }
7249
+ function parseShapeTreeNode(local, node, orderedNode, partPath, nextId, orderingSlot) {
7250
+ if (local === "sp") return parseShape(node, partPath, nextId, orderingSlot, orderedNode);
7251
+ if (local === "pic") return parseImage(node, partPath, nextId, orderingSlot);
7252
+ if (local === "cxnSp") {
7253
+ return parseConnector(node, partPath, nextId, orderingSlot, orderedNode);
7254
+ }
7255
+ if (local === "grpSp") {
7256
+ const orderedGroupChildren = unsafeOoxmlBoundaryAssertion(orderedNode?.[local]);
7257
+ return parseGroup(node, partPath, nextId, orderingSlot, orderedGroupChildren);
7258
+ }
7259
+ if (local === "graphicFrame") {
7260
+ return parseGraphicFrame(node, partPath, nextId, orderingSlot, orderedNode);
7261
+ }
7262
+ return parseRawShapeNode(`p:${local}`, node, partPath, nextId, orderingSlot);
7263
+ }
7264
+ function parseShape(sp, partPath, nextId, orderingSlot, orderedNode) {
7265
+ const nvSpPr = getChild(sp, "nvSpPr");
7266
+ const cNvPr = getChild(nvSpPr, "cNvPr");
7267
+ const nodeId = sourceNodeId(cNvPr);
7268
+ const name = getAttr(cNvPr, "name");
7269
+ const placeholder = parsePlaceholder(getChild(getChild(nvSpPr, "nvPr"), "ph"));
7270
+ const spPr = getChild(sp, "spPr");
7271
+ const transform = parseTransform(spPr);
7272
+ const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "sp", "spPr"));
7273
+ const fill = parseFill(spPr, nextId);
7274
+ const outline = parseOutline(spPr, nextId);
7275
+ const effects = parseEffectList(getChild(spPr, "effectLst"));
7276
+ const style = parseShapeStyle(getChild(sp, "style"));
7277
+ const textBody = parseTextBody(
7278
+ getChild(sp, "txBody"),
7279
+ partPath,
7280
+ nextId,
7281
+ nodeId,
7282
+ orderingSlot,
7283
+ orderedNestedChildChildren(orderedNode, "sp", "txBody")
7485
7284
  );
7285
+ const rawSidecars = [
7286
+ ...collectUnknownSidecars(sp, KNOWN_SHAPE_CHILDREN, nextId),
7287
+ ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7288
+ ...collectEffectSidecars(spPr, effects, nextId)
7289
+ ];
7290
+ return {
7291
+ kind: "shape",
7292
+ ...nodeId !== void 0 ? { nodeId } : {},
7293
+ ...name !== void 0 ? { name } : {},
7294
+ ...transform !== void 0 ? { transform } : {},
7295
+ ...geometry !== void 0 ? { geometry } : {},
7296
+ ...fill !== void 0 ? { fill } : {},
7297
+ ...outline !== void 0 ? { outline } : {},
7298
+ ...effects !== void 0 ? { effects } : {},
7299
+ ...style !== void 0 ? { style } : {},
7300
+ ...textBody !== void 0 ? { textBody } : {},
7301
+ ...placeholder !== void 0 ? { placeholder } : {},
7302
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7303
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7304
+ };
7486
7305
  }
7487
- function parseRun(r, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7488
- const properties = parseRunProperties(getChild(r, "rPr"));
7489
- const rawSidecars = collectRunSidecars(r, nextId);
7306
+ function parseConnector(cxnSp, partPath, nextId, orderingSlot, orderedNode) {
7307
+ const nvCxnSpPr = getChild(cxnSp, "nvCxnSpPr");
7308
+ const cNvPr = getChild(nvCxnSpPr, "cNvPr");
7309
+ const cNvCxnSpPr = getChild(nvCxnSpPr, "cNvCxnSpPr");
7310
+ const nodeId = sourceNodeId(cNvPr);
7311
+ const name = getAttr(cNvPr, "name");
7312
+ const connection = parseConnectorConnection(cNvCxnSpPr);
7313
+ const spPr = getChild(cxnSp, "spPr");
7314
+ const transform = parseTransform(spPr);
7315
+ const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "cxnSp", "spPr"));
7316
+ const outline = parseOutline(spPr, nextId);
7317
+ const effects = parseEffectList(getChild(spPr, "effectLst"));
7318
+ const style = parseShapeStyle(getChild(cxnSp, "style"));
7319
+ const rawSidecars = [
7320
+ ...collectUnknownSidecars(cxnSp, KNOWN_CONNECTOR_CHILDREN, nextId),
7321
+ ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7322
+ ...collectEffectSidecars(spPr, effects, nextId)
7323
+ ];
7490
7324
  return {
7491
- kind: "textRun",
7492
- text: decodeXmlCharRef(getChildText(r, "t") ?? ""),
7493
- ...properties !== void 0 ? { properties } : {},
7494
- handle: {
7495
- partPath,
7496
- nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7497
- orderingSlot: runIndex
7498
- },
7325
+ kind: "connector",
7326
+ ...nodeId !== void 0 ? { nodeId } : {},
7327
+ ...name !== void 0 ? { name } : {},
7328
+ ...connection !== void 0 ? { connection } : {},
7329
+ ...transform !== void 0 ? { transform } : {},
7330
+ ...geometry !== void 0 ? { geometry } : {},
7331
+ ...outline !== void 0 ? { outline } : {},
7332
+ ...effects !== void 0 ? { effects } : {},
7333
+ ...style !== void 0 ? { style } : {},
7334
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7499
7335
  ...rawSidecars.length > 0 ? { rawSidecars } : {}
7500
7336
  };
7501
7337
  }
7502
- function parseBreakRun(br, partPath, nextId, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7503
- const properties = parseRunProperties(getChild(br, "rPr"));
7338
+ function parseConnectorConnection(cNvCxnSpPr) {
7339
+ const start = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "stCxn"));
7340
+ const end = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "endCxn"));
7341
+ return start !== void 0 || end !== void 0 ? {
7342
+ ...start !== void 0 ? { start } : {},
7343
+ ...end !== void 0 ? { end } : {}
7344
+ } : void 0;
7345
+ }
7346
+ function parseConnectorConnectionEndpoint(node) {
7347
+ const shapeId = getAttr(node, "id");
7348
+ const connectionSiteIndex = numericAttr2(node, "idx");
7349
+ if (shapeId === void 0 || connectionSiteIndex === void 0) return void 0;
7504
7350
  return {
7505
- kind: "textRun",
7506
- text: "\n",
7507
- ...properties !== void 0 ? { properties } : {},
7508
- handle: {
7509
- partPath,
7510
- nodeId: textNodeId("run", ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex),
7511
- orderingSlot: runIndex
7512
- }
7351
+ shapeId: asSourceNodeId(shapeId),
7352
+ connectionSiteIndex
7513
7353
  };
7514
7354
  }
7515
- function parseRunProperties(rPr) {
7516
- if (!rPr) return void 0;
7517
- const bold = getAttr(rPr, "b");
7518
- const italic = getAttr(rPr, "i");
7519
- const underline = getAttr(rPr, "u");
7520
- const strike = getAttr(rPr, "strike");
7521
- const baseline = numericAttr(rPr, "baseline");
7522
- const size = numericAttr(rPr, "sz");
7523
- const typeface = getAttr(getChild(rPr, "latin"), "typeface");
7524
- const typefaceEa = getAttr(getChild(rPr, "ea"), "typeface");
7525
- const typefaceCs = getAttr(getChild(rPr, "cs"), "typeface");
7526
- const hasHyperlink = getChild(rPr, "hlinkClick") !== void 0;
7527
- const color = parseColorElement(getChild(rPr, "solidFill"));
7528
- const properties = {
7529
- ...bold !== void 0 ? { bold: isTrue(bold) } : {},
7530
- ...italic !== void 0 ? { italic: isTrue(italic) } : {},
7531
- ...underline !== void 0 ? { underline: underline !== "none" } : hasHyperlink ? { underline: true } : {},
7532
- ...strike !== void 0 ? { strikethrough: strike !== "noStrike" } : {},
7533
- ...baseline !== void 0 ? { baseline: baseline / 1e3 } : {},
7534
- // `a:rPr@sz` is in 1/100 pt unit. Convert to pt and save.
7535
- ...size !== void 0 ? { fontSize: asPt(size / 100) } : {},
7536
- ...typeface !== void 0 ? { typeface } : {},
7537
- ...typefaceEa !== void 0 ? { typefaceEa } : {},
7538
- ...typefaceCs !== void 0 ? { typefaceCs } : {},
7539
- ...color !== void 0 ? { color } : hasHyperlink ? { color: { kind: "scheme", scheme: "hlink" } } : {}
7355
+ function parseShapeStyle(style) {
7356
+ if (style === void 0) return void 0;
7357
+ const fillRef = parseStyleReference(getChild(style, "fillRef"));
7358
+ const lineRef = parseStyleReference(getChild(style, "lnRef"));
7359
+ const effectRef = parseStyleReference(getChild(style, "effectRef"));
7360
+ const parsed = {
7361
+ ...fillRef !== void 0 ? { fillRef } : {},
7362
+ ...lineRef !== void 0 ? { lineRef } : {},
7363
+ ...effectRef !== void 0 ? { effectRef } : {}
7540
7364
  };
7541
- return Object.keys(properties).length > 0 ? properties : void 0;
7542
- }
7543
- function collectRunSidecars(r, nextId) {
7544
- const runLevel = collectUnknownSidecars(r, KNOWN_RUN_CHILDREN, nextId);
7545
- const propLevel = collectUnknownSidecars(getChild(r, "rPr"), KNOWN_RUN_PROPERTY_CHILDREN, nextId);
7546
- return [...runLevel, ...propLevel];
7547
- }
7548
- function emu(value) {
7549
- return asEmu2(value);
7365
+ return Object.keys(parsed).length > 0 ? parsed : void 0;
7550
7366
  }
7551
- function textNodeId(kind, ownerNodeId, ownerOrderingSlot, paragraphIndex, runIndex) {
7552
- const owner = ownerNodeId !== void 0 ? `shape:${ownerNodeId}` : `shapeSlot:${ownerOrderingSlot}`;
7553
- const suffix = kind === "paragraph" ? `p:${paragraphIndex}` : `p:${paragraphIndex}:r:${runIndex}`;
7554
- return asSourceNodeId(`text:${owner}:${suffix}`);
7367
+ function parseStyleReference(ref) {
7368
+ if (ref === void 0) return void 0;
7369
+ const index = numericAttr2(ref, "idx") ?? 0;
7370
+ const color = parseColorElement(ref);
7371
+ return {
7372
+ index,
7373
+ ...color !== void 0 ? { color } : {}
7374
+ };
7555
7375
  }
7556
- function orderedKey(node) {
7557
- return Object.keys(node).find((key) => key !== ":@");
7376
+ function parseGroup(grpSp, partPath, nextId, orderingSlot, orderedChildren) {
7377
+ const nvGrpSpPr = getChild(grpSp, "nvGrpSpPr");
7378
+ const cNvPr = getChild(nvGrpSpPr, "cNvPr");
7379
+ const nodeId = sourceNodeId(cNvPr);
7380
+ const name = getAttr(cNvPr, "name");
7381
+ const grpSpPr = getChild(grpSp, "grpSpPr");
7382
+ const transform = parseTransform(grpSpPr);
7383
+ const childTransform = parseChildTransform(grpSpPr, transform);
7384
+ const fill = parseFill(grpSpPr, nextId);
7385
+ const effects = parseEffectList(getChild(grpSpPr, "effectLst"));
7386
+ const rawSidecars = [
7387
+ ...collectUnknownSidecars(grpSp, KNOWN_GROUP_CHILDREN, nextId),
7388
+ ...collectUnknownSidecars(grpSpPr, KNOWN_SP_PR_CHILDREN, nextId),
7389
+ ...collectEffectSidecars(grpSpPr, effects, nextId)
7390
+ ];
7391
+ return {
7392
+ kind: "group",
7393
+ ...nodeId !== void 0 ? { nodeId } : {},
7394
+ ...name !== void 0 ? { name } : {},
7395
+ ...transform !== void 0 ? { transform } : {},
7396
+ ...childTransform !== void 0 ? { childTransform } : {},
7397
+ ...fill !== void 0 ? { fill } : {},
7398
+ ...effects !== void 0 ? { effects } : {},
7399
+ children: parseShapeTree(grpSp, partPath, nextId, orderedChildren),
7400
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7401
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7402
+ };
7558
7403
  }
7559
- function orderedLocalName(node) {
7560
- const key = orderedKey(node);
7561
- return key !== void 0 ? localName(key) : void 0;
7404
+ function parseImage(pic, partPath, nextId, orderingSlot) {
7405
+ const cNvPr = getChild(getChild(pic, "nvPicPr"), "cNvPr");
7406
+ const nodeId = sourceNodeId(cNvPr);
7407
+ const name = getAttr(cNvPr, "name");
7408
+ const blipFill = getChild(pic, "blipFill");
7409
+ const blip = getChild(blipFill, "blip");
7410
+ const embed = getNamespacedAttr(blip, "embed");
7411
+ const crop = parseCrop(getChild(blipFill, "srcRect"));
7412
+ const stretch = parseStretch(getChild(blipFill, "stretch"));
7413
+ const tile = parseImageFillTile(getChild(blipFill, "tile"));
7414
+ const blipEffects = parseBlipEffects(blip);
7415
+ const spPr = getChild(pic, "spPr");
7416
+ const transform = parseTransform(spPr);
7417
+ const effects = parseEffectList(getChild(spPr, "effectLst"));
7418
+ const rawSidecars = [
7419
+ ...collectUnknownSidecars(pic, KNOWN_PICTURE_CHILDREN, nextId),
7420
+ ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7421
+ ...collectEffectSidecars(spPr, effects, nextId),
7422
+ // Retains fill mode such as `a:stretch` / `a:tile` and recolor operation under blip.
7423
+ ...collectUnknownSidecars(blipFill, KNOWN_BLIP_FILL_CHILDREN, nextId),
7424
+ ...collectBlipEffectSidecars(blip, blipEffects, nextId)
7425
+ ];
7426
+ return {
7427
+ kind: "image",
7428
+ ...nodeId !== void 0 ? { nodeId } : {},
7429
+ ...name !== void 0 ? { name } : {},
7430
+ ...transform !== void 0 ? { transform } : {},
7431
+ ...embed !== void 0 ? { blipRelationshipId: asRelationshipId(embed) } : {},
7432
+ ...crop !== void 0 ? { crop } : {},
7433
+ ...stretch !== void 0 ? { stretch } : {},
7434
+ ...tile !== void 0 ? { tile } : {},
7435
+ ...effects !== void 0 ? { effects } : {},
7436
+ ...blipEffects !== void 0 ? { blipEffects } : {},
7437
+ handle: {
7438
+ partPath,
7439
+ ...nodeId !== void 0 ? { nodeId } : {},
7440
+ ...embed !== void 0 ? { relationshipId: asRelationshipId(embed) } : {},
7441
+ orderingSlot
7442
+ },
7443
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7444
+ };
7562
7445
  }
7563
- var KNOWN_SHAPE_CHILDREN = /* @__PURE__ */ new Set(["nvSpPr", "spPr", "style", "txBody"]);
7564
- var KNOWN_CONNECTOR_CHILDREN = /* @__PURE__ */ new Set(["nvCxnSpPr", "spPr", "style"]);
7565
- var KNOWN_GROUP_CHILDREN = /* @__PURE__ */ new Set(["nvGrpSpPr", "grpSpPr"]);
7566
- var KNOWN_PICTURE_CHILDREN = /* @__PURE__ */ new Set(["nvPicPr", "blipFill", "spPr"]);
7567
- var KNOWN_BLIP_FILL_CHILDREN = /* @__PURE__ */ new Set([
7568
- "blip",
7569
- "srcRect",
7570
- "stretch",
7571
- "tile"
7572
- ]);
7573
- var KNOWN_BLIP_CHILDREN = /* @__PURE__ */ new Set([
7574
- "grayscl",
7575
- "biLevel",
7576
- "blur",
7577
- "lum",
7578
- "duotone",
7579
- "clrChange"
7580
- ]);
7581
- var KNOWN_EFFECT_CHILDREN = /* @__PURE__ */ new Set([
7582
- "outerShdw",
7583
- "innerShdw",
7584
- "glow",
7585
- "softEdge"
7586
- ]);
7587
- var KNOWN_GRAPHIC_FRAME_CHILDREN = /* @__PURE__ */ new Set([
7588
- "nvGraphicFramePr",
7589
- "xfrm",
7590
- "graphic"
7591
- ]);
7592
- var KNOWN_GRAPHIC_CHILDREN = /* @__PURE__ */ new Set(["graphicData"]);
7593
- var KNOWN_GRAPHIC_DATA_CHILDREN = /* @__PURE__ */ new Set(["tbl"]);
7594
- var KNOWN_TABLE_CHILDREN = /* @__PURE__ */ new Set(["tblPr", "tblGrid", "tr"]);
7595
- var KNOWN_TABLE_CELL_CHILDREN = /* @__PURE__ */ new Set(["txBody", "tcPr"]);
7596
- var KNOWN_TABLE_CELL_PROPERTIES_CHILDREN = /* @__PURE__ */ new Set([
7597
- "lnL",
7598
- "lnR",
7599
- "lnT",
7600
- "lnB",
7601
- "solidFill",
7602
- "noFill",
7603
- "gradFill",
7604
- "blipFill",
7605
- "pattFill",
7606
- "grpFill"
7607
- ]);
7608
- var KNOWN_SP_PR_CHILDREN = /* @__PURE__ */ new Set([
7609
- "xfrm",
7610
- "prstGeom",
7611
- "solidFill",
7612
- "noFill",
7613
- "gradFill",
7614
- "blipFill",
7615
- "pattFill",
7616
- "grpFill",
7617
- "ln",
7618
- "effectLst"
7619
- ]);
7620
- var SHAPE_TREE_NODE_TAGS = /* @__PURE__ */ new Set([
7621
- "sp",
7622
- "pic",
7623
- "cxnSp",
7624
- "grpSp",
7625
- "graphicFrame"
7626
- ]);
7627
- var CHART_GRAPHIC_DATA_URIS = /* @__PURE__ */ new Set([
7628
- "http://schemas.openxmlformats.org/drawingml/2006/chart",
7629
- "http://purl.oclc.org/ooxml/drawingml/chart"
7630
- ]);
7631
- var SMARTART_DIAGRAM_URIS = /* @__PURE__ */ new Set([
7632
- "http://schemas.openxmlformats.org/drawingml/2006/diagram",
7633
- "http://purl.oclc.org/ooxml/drawingml/diagram"
7634
- ]);
7635
- function parseShapeTree(spTree, partPath, nextId, orderedChildren) {
7636
- if (!spTree) return [];
7637
- if (orderedChildren !== void 0) {
7638
- return parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren);
7446
+ function collectEffectSidecars(spPr, effects, nextId) {
7447
+ const effectList = getChild(spPr, "effectLst");
7448
+ if (effectList === void 0) return [];
7449
+ const sidecars = collectUnknownSidecars(effectList, KNOWN_EFFECT_CHILDREN, nextId);
7450
+ const supportedChildren = [
7451
+ ["outerShdw", effects?.outerShadow],
7452
+ ["innerShdw", effects?.innerShadow],
7453
+ ["glow", effects?.glow],
7454
+ ["softEdge", effects?.softEdge]
7455
+ ];
7456
+ for (const [name, parsed] of supportedChildren) {
7457
+ const node = getChild(effectList, name);
7458
+ if (node !== void 0 && parsed === void 0) {
7459
+ sidecars.push(makeSidecar(`a:${name}`, node, nextId));
7460
+ }
7461
+ }
7462
+ return sidecars;
7463
+ }
7464
+ function collectBlipEffectSidecars(blip, effects, nextId) {
7465
+ if (blip === void 0) return [];
7466
+ const sidecars = collectUnknownSidecars(blip, KNOWN_BLIP_CHILDREN, nextId);
7467
+ const supportedChildren = [
7468
+ ["grayscl", effects?.grayscale === true],
7469
+ ["biLevel", effects?.biLevel],
7470
+ ["blur", effects?.blur],
7471
+ ["lum", effects?.lum],
7472
+ ["duotone", effects?.duotone],
7473
+ ["clrChange", effects?.clrChange]
7474
+ ];
7475
+ for (const [name, parsed] of supportedChildren) {
7476
+ const node = getChild(blip, name);
7477
+ if (node !== void 0 && (parsed === void 0 || parsed === false)) {
7478
+ sidecars.push(makeSidecar(`a:${name}`, node, nextId));
7479
+ }
7480
+ }
7481
+ return sidecars;
7482
+ }
7483
+ function parseGraphicFrame(graphicFrame, partPath, nextId, orderingSlot, orderedNode) {
7484
+ const graphic = getChild(graphicFrame, "graphic");
7485
+ const graphicData = getChild(graphic, "graphicData");
7486
+ const uri = getAttr(graphicData, "uri");
7487
+ if (uri !== void 0 && CHART_GRAPHIC_DATA_URIS.has(uri)) {
7488
+ const parsedChart = parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7489
+ if (parsedChart !== void 0) return parsedChart;
7490
+ }
7491
+ if (uri !== void 0 && SMARTART_DIAGRAM_URIS.has(uri)) {
7492
+ const parsedSmartArt = parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7493
+ if (parsedSmartArt !== void 0) return parsedSmartArt;
7494
+ }
7495
+ const table = getChild(graphicData, "tbl");
7496
+ if (table === void 0) {
7497
+ return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
7498
+ }
7499
+ const orderedGraphicChildren = orderedNestedChildChildren(orderedNode, "graphicFrame", "graphic");
7500
+ const orderedGraphicDataChildren = orderedChildChildren2(orderedGraphicChildren, "graphicData");
7501
+ const orderedTableChildren = orderedChildChildren2(orderedGraphicDataChildren, "tbl");
7502
+ const parsedTable = parseTable(
7503
+ table,
7504
+ graphicFrame,
7505
+ partPath,
7506
+ nextId,
7507
+ orderingSlot,
7508
+ orderedTableChildren
7509
+ );
7510
+ if (parsedTable === void 0) {
7511
+ return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
7512
+ }
7513
+ return parsedTable;
7514
+ }
7515
+ function parseAlternateContent(alternateContent, partPath, nextId, orderingSlot) {
7516
+ const branches = [
7517
+ ...getChildArray(alternateContent, "Choice"),
7518
+ ...getChildArray(alternateContent, "Fallback")
7519
+ ];
7520
+ for (const branch of branches) {
7521
+ const parsed = parseAlternateContentBranch(branch, partPath, nextId, orderingSlot);
7522
+ if (parsed.length > 0) {
7523
+ if (parsed.every((node) => node.kind === "raw")) {
7524
+ continue;
7525
+ }
7526
+ return parsed.map(
7527
+ (node) => attachRawSidecar(node, makeSidecar("mc:AlternateContent", alternateContent, nextId))
7528
+ );
7529
+ }
7639
7530
  }
7531
+ return [
7532
+ parseRawShapeNode("mc:AlternateContent", alternateContent, partPath, nextId, orderingSlot)
7533
+ ];
7534
+ }
7535
+ function attachRawSidecar(node, sidecar) {
7536
+ if (node.kind === "raw") return node;
7537
+ return {
7538
+ ...node,
7539
+ rawSidecars: [...node.rawSidecars ?? [], sidecar]
7540
+ };
7541
+ }
7542
+ function parseAlternateContentBranch(branch, partPath, nextId, orderingSlot) {
7640
7543
  const nodes = [];
7641
- let orderingSlot = 0;
7642
- for (const key of Object.keys(spTree)) {
7643
- if (key.startsWith("@_")) continue;
7644
- if (key === "#text") continue;
7544
+ for (const key of Object.keys(branch)) {
7545
+ if (key.startsWith("@_") || key === "#text") continue;
7645
7546
  const local = localName(key);
7646
- if (local === "nvGrpSpPr" || local === "grpSpPr") continue;
7647
- const value = spTree[key];
7547
+ const value = branch[key];
7648
7548
  const items = Array.isArray(value) ? value : [value];
7649
7549
  for (const item of items) {
7650
7550
  const node = unsafeOoxmlBoundaryAssertion(item);
7651
- if (local === "sp") {
7652
- nodes.push(parseShape(node, partPath, nextId, orderingSlot));
7653
- } else if (local === "pic") {
7654
- nodes.push(parseImage(node, partPath, nextId, orderingSlot));
7655
- } else if (local === "cxnSp") {
7551
+ if (local === "sp") nodes.push(parseShape(node, partPath, nextId, orderingSlot));
7552
+ else if (local === "pic") nodes.push(parseImage(node, partPath, nextId, orderingSlot));
7553
+ else if (local === "cxnSp") {
7656
7554
  nodes.push(parseConnector(node, partPath, nextId, orderingSlot));
7657
7555
  } else if (local === "grpSp") {
7658
7556
  nodes.push(parseGroup(node, partPath, nextId, orderingSlot));
7659
7557
  } else if (local === "graphicFrame") {
7660
7558
  nodes.push(parseGraphicFrame(node, partPath, nextId, orderingSlot));
7661
- } else if (local === "AlternateContent") {
7662
- const parsed = parseAlternateContent(node, partPath, nextId, orderingSlot);
7663
- nodes.push(...parsed);
7664
7559
  } else {
7665
7560
  nodes.push(parseRawShapeNode(key, node, partPath, nextId, orderingSlot));
7666
7561
  }
7667
- orderingSlot++;
7668
7562
  }
7669
7563
  }
7670
7564
  return nodes;
7671
7565
  }
7672
- function parseShapeTreeOrdered(spTree, partPath, nextId, orderedChildren) {
7673
- const nodes = [];
7674
- const tagCounters = {};
7675
- let orderingSlot = 0;
7676
- for (const child of orderedChildren) {
7677
- const key = Object.keys(child).find((candidate) => candidate !== ":@");
7678
- if (key === void 0) continue;
7679
- const local = localName(key);
7680
- if (local === "AlternateContent") {
7681
- const index2 = tagCounters[local] ?? 0;
7682
- tagCounters[local] = index2 + 1;
7683
- const alternateContents = getChildArray(spTree, "AlternateContent");
7684
- const alternateContent = alternateContents[index2];
7685
- if (alternateContent !== void 0) {
7686
- nodes.push(...parseAlternateContent(alternateContent, partPath, nextId, orderingSlot));
7687
- orderingSlot++;
7688
- }
7689
- continue;
7690
- }
7691
- if (!SHAPE_TREE_NODE_TAGS.has(local)) continue;
7692
- const index = tagCounters[local] ?? 0;
7693
- tagCounters[local] = index + 1;
7694
- const node = getChildArray(spTree, local)[index];
7695
- if (node === void 0) continue;
7696
- nodes.push(parseShapeTreeNode(local, node, child, partPath, nextId, orderingSlot));
7697
- orderingSlot++;
7698
- }
7699
- return nodes;
7566
+ function parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
7567
+ const graphic = getChild(graphicFrame, "graphic");
7568
+ const graphicData = getChild(graphic, "graphicData");
7569
+ const chart = getChild(graphicData, "chart");
7570
+ const rId = getNamespacedAttr(chart, "id") ?? getAttr(chart, "id");
7571
+ if (rId === void 0) return void 0;
7572
+ const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
7573
+ const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
7574
+ const nodeId = sourceNodeId(cNvPr);
7575
+ const name = getAttr(cNvPr, "name");
7576
+ const transform = parseTransform(graphicFrame);
7577
+ const rawSidecars = [
7578
+ ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
7579
+ ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
7580
+ ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
7581
+ ];
7582
+ return {
7583
+ kind: "chart",
7584
+ ...nodeId !== void 0 ? { nodeId } : {},
7585
+ ...name !== void 0 ? { name } : {},
7586
+ ...transform !== void 0 ? { transform } : {},
7587
+ chartRelationshipId: asRelationshipId(rId),
7588
+ handle: {
7589
+ partPath,
7590
+ ...nodeId !== void 0 ? { nodeId } : {},
7591
+ relationshipId: asRelationshipId(rId),
7592
+ orderingSlot
7593
+ },
7594
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7595
+ };
7700
7596
  }
7701
- function parseShapeTreeNode(local, node, orderedNode, partPath, nextId, orderingSlot) {
7702
- if (local === "sp") return parseShape(node, partPath, nextId, orderingSlot, orderedNode);
7703
- if (local === "pic") return parseImage(node, partPath, nextId, orderingSlot);
7704
- if (local === "cxnSp") {
7705
- return parseConnector(node, partPath, nextId, orderingSlot, orderedNode);
7706
- }
7707
- if (local === "grpSp") {
7708
- const orderedGroupChildren = unsafeOoxmlBoundaryAssertion(orderedNode?.[local]);
7709
- return parseGroup(node, partPath, nextId, orderingSlot, orderedGroupChildren);
7710
- }
7711
- if (local === "graphicFrame") {
7712
- return parseGraphicFrame(node, partPath, nextId, orderingSlot, orderedNode);
7713
- }
7714
- return parseRawShapeNode(`p:${local}`, node, partPath, nextId, orderingSlot);
7597
+ function parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
7598
+ const graphic = getChild(graphicFrame, "graphic");
7599
+ const graphicData = getChild(graphic, "graphicData");
7600
+ const relIds = getChild(graphicData, "relIds");
7601
+ const dmRId = getNamespacedAttr(relIds, "dm") ?? getAttr(relIds, "dm");
7602
+ if (dmRId === void 0) return void 0;
7603
+ const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
7604
+ const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
7605
+ const nodeId = sourceNodeId(cNvPr);
7606
+ const name = getAttr(cNvPr, "name");
7607
+ const transform = parseTransform(graphicFrame);
7608
+ const rawSidecars = [
7609
+ ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
7610
+ ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
7611
+ ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
7612
+ ];
7613
+ return {
7614
+ kind: "smartArt",
7615
+ ...nodeId !== void 0 ? { nodeId } : {},
7616
+ ...name !== void 0 ? { name } : {},
7617
+ ...transform !== void 0 ? { transform } : {},
7618
+ dataRelationshipId: asRelationshipId(dmRId),
7619
+ handle: {
7620
+ partPath,
7621
+ ...nodeId !== void 0 ? { nodeId } : {},
7622
+ relationshipId: asRelationshipId(dmRId),
7623
+ orderingSlot
7624
+ },
7625
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7626
+ };
7627
+ }
7628
+ function parseTable(tbl, graphicFrame, partPath, nextId, orderingSlot, orderedTableChildren) {
7629
+ const columns = parseTableColumns(getChild(tbl, "tblGrid"));
7630
+ if (columns.length === 0) return void 0;
7631
+ const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
7632
+ const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
7633
+ const nodeId = sourceNodeId(cNvPr);
7634
+ const name = getAttr(cNvPr, "name");
7635
+ const tblPr = getChild(tbl, "tblPr");
7636
+ const tableStyleId = getChildText(tblPr, "tableStyleId");
7637
+ const graphic = getChild(graphicFrame, "graphic");
7638
+ const graphicData = getChild(graphic, "graphicData");
7639
+ const transform = parseTransform(graphicFrame);
7640
+ const rows = parseTableRows(tbl, partPath, nextId, nodeId, orderingSlot, orderedTableChildren);
7641
+ const rawSidecars = [
7642
+ ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
7643
+ ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
7644
+ ...collectUnknownSidecars(graphicData, KNOWN_GRAPHIC_DATA_CHILDREN, nextId),
7645
+ ...collectUnknownSidecars(tbl, KNOWN_TABLE_CHILDREN, nextId)
7646
+ ];
7647
+ return {
7648
+ kind: "table",
7649
+ ...nodeId !== void 0 ? { nodeId } : {},
7650
+ ...name !== void 0 ? { name } : {},
7651
+ ...transform !== void 0 ? { transform } : {},
7652
+ table: {
7653
+ columns,
7654
+ rows,
7655
+ ...tableStyleId !== void 0 ? { tableStyleId } : {}
7656
+ },
7657
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7658
+ ...rawSidecars.length > 0 ? { rawSidecars } : {}
7659
+ };
7660
+ }
7661
+ function parseTableColumns(tblGrid) {
7662
+ return getChildArray(tblGrid, "gridCol").map((col) => ({ width: emuAttr(col, "w") }));
7663
+ }
7664
+ function parseTableRows(tbl, partPath, nextId, tableNodeId, tableOrderingSlot, orderedTableChildren) {
7665
+ const orderedRows = orderedChildChildrenList(orderedTableChildren, "tr");
7666
+ return getChildArray(tbl, "tr").map((tr, rowIndex) => ({
7667
+ height: emuAttr(tr, "h"),
7668
+ cells: getChildArray(tr, "tc").map((tc, cellIndex) => {
7669
+ const orderedCells = orderedChildChildrenList(orderedRows[rowIndex], "tc");
7670
+ return parseTableCell(
7671
+ tc,
7672
+ partPath,
7673
+ nextId,
7674
+ tableNodeId,
7675
+ tableOrderingSlot,
7676
+ rowIndex,
7677
+ cellIndex,
7678
+ orderedCells[cellIndex]
7679
+ );
7680
+ })
7681
+ }));
7715
7682
  }
7716
- function parseShape(sp, partPath, nextId, orderingSlot, orderedNode) {
7717
- const nvSpPr = getChild(sp, "nvSpPr");
7718
- const cNvPr = getChild(nvSpPr, "cNvPr");
7719
- const nodeId = sourceNodeId(cNvPr);
7720
- const name = getAttr(cNvPr, "name");
7721
- const placeholder = parsePlaceholder(getChild(getChild(nvSpPr, "nvPr"), "ph"));
7722
- const spPr = getChild(sp, "spPr");
7723
- const transform = parseTransform(spPr);
7724
- const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "sp", "spPr"));
7725
- const fill = parseFill(spPr, nextId);
7726
- const outline = parseOutline(spPr, nextId);
7727
- const effects = parseEffectList(getChild(spPr, "effectLst"));
7728
- const style = parseShapeStyle(getChild(sp, "style"));
7683
+ function parseTableCell(tc, partPath, nextId, tableNodeId, tableOrderingSlot, rowIndex, cellIndex, orderedCellChildren) {
7684
+ const tcPr = getChild(tc, "tcPr");
7685
+ const textOrderingSlot = tableOrderingSlot * 1e9 + rowIndex * 1e6 + cellIndex;
7729
7686
  const textBody = parseTextBody(
7730
- getChild(sp, "txBody"),
7687
+ getChild(tc, "txBody"),
7731
7688
  partPath,
7732
7689
  nextId,
7733
- nodeId,
7734
- orderingSlot,
7735
- orderedNestedChildChildren(orderedNode, "sp", "txBody")
7690
+ tableNodeId,
7691
+ textOrderingSlot,
7692
+ orderedChildChildren2(orderedCellChildren, "txBody")
7736
7693
  );
7694
+ const fill = parseFill(tcPr, nextId);
7695
+ const borders = parseCellBorders(tcPr, nextId);
7737
7696
  const rawSidecars = [
7738
- ...collectUnknownSidecars(sp, KNOWN_SHAPE_CHILDREN, nextId),
7739
- ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7740
- ...collectEffectSidecars(spPr, effects, nextId)
7697
+ ...collectUnknownSidecars(tc, KNOWN_TABLE_CELL_CHILDREN, nextId),
7698
+ ...collectUnknownSidecars(tcPr, KNOWN_TABLE_CELL_PROPERTIES_CHILDREN, nextId)
7741
7699
  ];
7742
7700
  return {
7743
- kind: "shape",
7744
- ...nodeId !== void 0 ? { nodeId } : {},
7745
- ...name !== void 0 ? { name } : {},
7746
- ...transform !== void 0 ? { transform } : {},
7747
- ...geometry !== void 0 ? { geometry } : {},
7748
- ...fill !== void 0 ? { fill } : {},
7749
- ...outline !== void 0 ? { outline } : {},
7750
- ...effects !== void 0 ? { effects } : {},
7751
- ...style !== void 0 ? { style } : {},
7752
7701
  ...textBody !== void 0 ? { textBody } : {},
7753
- ...placeholder !== void 0 ? { placeholder } : {},
7754
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7702
+ ...fill !== void 0 ? { fill } : {},
7703
+ ...borders !== void 0 ? { borders } : {},
7704
+ gridSpan: numericAttr2(tc, "gridSpan") ?? 1,
7705
+ rowSpan: numericAttr2(tc, "rowSpan") ?? 1,
7706
+ hMerge: isTrue(getAttr(tc, "hMerge") ?? getAttr(tcPr, "hMerge")),
7707
+ vMerge: isTrue(getAttr(tc, "vMerge") ?? getAttr(tcPr, "vMerge")),
7755
7708
  ...rawSidecars.length > 0 ? { rawSidecars } : {}
7756
7709
  };
7757
7710
  }
7758
- function parseConnector(cxnSp, partPath, nextId, orderingSlot, orderedNode) {
7759
- const nvCxnSpPr = getChild(cxnSp, "nvCxnSpPr");
7760
- const cNvPr = getChild(nvCxnSpPr, "cNvPr");
7761
- const cNvCxnSpPr = getChild(nvCxnSpPr, "cNvCxnSpPr");
7762
- const nodeId = sourceNodeId(cNvPr);
7763
- const name = getAttr(cNvPr, "name");
7764
- const connection = parseConnectorConnection(cNvCxnSpPr);
7765
- const spPr = getChild(cxnSp, "spPr");
7766
- const transform = parseTransform(spPr);
7767
- const geometry = parseGeometry(spPr, orderedNestedChildChildren(orderedNode, "cxnSp", "spPr"));
7768
- const outline = parseOutline(spPr, nextId);
7769
- const effects = parseEffectList(getChild(spPr, "effectLst"));
7770
- const style = parseShapeStyle(getChild(cxnSp, "style"));
7771
- const rawSidecars = [
7772
- ...collectUnknownSidecars(cxnSp, KNOWN_CONNECTOR_CHILDREN, nextId),
7773
- ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7774
- ...collectEffectSidecars(spPr, effects, nextId)
7775
- ];
7711
+ function parseCellBorders(tcPr, nextId) {
7712
+ const left = parseLine(getChild(tcPr, "lnL"), nextId);
7713
+ const right = parseLine(getChild(tcPr, "lnR"), nextId);
7714
+ const top = parseLine(getChild(tcPr, "lnT"), nextId);
7715
+ const bottom = parseLine(getChild(tcPr, "lnB"), nextId);
7716
+ if (left === void 0 && right === void 0 && top === void 0 && bottom === void 0) {
7717
+ return void 0;
7718
+ }
7776
7719
  return {
7777
- kind: "connector",
7720
+ ...top !== void 0 ? { top } : {},
7721
+ ...bottom !== void 0 ? { bottom } : {},
7722
+ ...left !== void 0 ? { left } : {},
7723
+ ...right !== void 0 ? { right } : {}
7724
+ };
7725
+ }
7726
+ function parseRawShapeNode(key, node, partPath, nextId, orderingSlot) {
7727
+ const nodeId = sourceNodeId(getChild(getChild(node, "nvSpPr"), "cNvPr"));
7728
+ return {
7729
+ kind: "raw",
7778
7730
  ...nodeId !== void 0 ? { nodeId } : {},
7779
- ...name !== void 0 ? { name } : {},
7780
- ...connection !== void 0 ? { connection } : {},
7781
- ...transform !== void 0 ? { transform } : {},
7782
- ...geometry !== void 0 ? { geometry } : {},
7783
- ...outline !== void 0 ? { outline } : {},
7784
- ...effects !== void 0 ? { effects } : {},
7785
- ...style !== void 0 ? { style } : {},
7786
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7787
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
7731
+ raw: makeSidecar(key, node, nextId),
7732
+ handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot }
7788
7733
  };
7789
7734
  }
7790
- function parseConnectorConnection(cNvCxnSpPr) {
7791
- const start = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "stCxn"));
7792
- const end = parseConnectorConnectionEndpoint(getChild(cNvCxnSpPr, "endCxn"));
7793
- return start !== void 0 || end !== void 0 ? {
7794
- ...start !== void 0 ? { start } : {},
7795
- ...end !== void 0 ? { end } : {}
7796
- } : void 0;
7735
+ function parsePlaceholder(ph) {
7736
+ if (!ph) return void 0;
7737
+ const type = getAttr(ph, "type");
7738
+ const index = numericAttr2(ph, "idx");
7739
+ if (type === void 0 && index === void 0) return void 0;
7740
+ return {
7741
+ ...type !== void 0 ? { type } : {},
7742
+ ...index !== void 0 ? { index } : {}
7743
+ };
7797
7744
  }
7798
- function parseConnectorConnectionEndpoint(node) {
7799
- const shapeId = getAttr(node, "id");
7800
- const connectionSiteIndex = numericAttr(node, "idx");
7801
- if (shapeId === void 0 || connectionSiteIndex === void 0) return void 0;
7745
+ function parseGeometry(spPr, orderedSpPr) {
7746
+ const prstGeom = getChild(spPr, "prstGeom");
7747
+ if (prstGeom) {
7748
+ const preset = getAttr(prstGeom, "prst");
7749
+ const adjustValues = parseAdjustValues(getChild(prstGeom, "avLst"));
7750
+ return preset !== void 0 ? {
7751
+ preset,
7752
+ ...Object.keys(adjustValues).length > 0 ? { adjustValues } : {}
7753
+ } : void 0;
7754
+ }
7755
+ const customPaths = parseCustomGeometry(
7756
+ getChild(spPr, "custGeom"),
7757
+ orderedChildChildren2(orderedSpPr, "custGeom")
7758
+ );
7759
+ if (customPaths !== void 0) return { kind: "custom", paths: customPaths };
7760
+ return void 0;
7761
+ }
7762
+ function parseAdjustValues(avLst) {
7763
+ const adjustValues = {};
7764
+ for (const guide of getChildArray(avLst, "gd")) {
7765
+ const name = getAttr(guide, "name");
7766
+ const formula = getAttr(guide, "fmla");
7767
+ const match = formula?.match(/val\s+(-?\d+)/);
7768
+ if (name !== void 0 && match !== void 0 && match !== null) {
7769
+ adjustValues[name] = Number(match[1]);
7770
+ }
7771
+ }
7772
+ return adjustValues;
7773
+ }
7774
+ function parseChildTransform(grpSpPr, fallback) {
7775
+ const xfrm = getChild(grpSpPr, "xfrm");
7776
+ const childOff = getChild(xfrm, "chOff");
7777
+ const childExt = getChild(xfrm, "chExt");
7778
+ const offsetX = numericAttr2(childOff, "x") ?? 0;
7779
+ const offsetY = numericAttr2(childOff, "y") ?? 0;
7780
+ const width = numericAttr2(childExt, "cx") ?? fallback?.width;
7781
+ const height = numericAttr2(childExt, "cy") ?? fallback?.height;
7782
+ if (width === void 0 || height === void 0) return void 0;
7802
7783
  return {
7803
- shapeId: asSourceNodeId(shapeId),
7804
- connectionSiteIndex
7784
+ offsetX: asEmu2(offsetX),
7785
+ offsetY: asEmu2(offsetY),
7786
+ width: asEmu2(Number(width)),
7787
+ height: asEmu2(Number(height))
7788
+ };
7789
+ }
7790
+ function parseCrop(srcRect) {
7791
+ if (!srcRect) return void 0;
7792
+ const left = numericAttr2(srcRect, "l");
7793
+ const top = numericAttr2(srcRect, "t");
7794
+ const right = numericAttr2(srcRect, "r");
7795
+ const bottom = numericAttr2(srcRect, "b");
7796
+ const crop = {
7797
+ ...left !== void 0 ? { left: asOoxmlPercent(left) } : {},
7798
+ ...top !== void 0 ? { top: asOoxmlPercent(top) } : {},
7799
+ ...right !== void 0 ? { right: asOoxmlPercent(right) } : {},
7800
+ ...bottom !== void 0 ? { bottom: asOoxmlPercent(bottom) } : {}
7805
7801
  };
7802
+ return Object.keys(crop).length > 0 ? crop : void 0;
7803
+ }
7804
+ function parseStretch(stretch) {
7805
+ const fillRect = getChild(stretch, "fillRect");
7806
+ if (fillRect === void 0) return void 0;
7807
+ const left = (numericAttr2(fillRect, "l") ?? 0) / 1e5;
7808
+ const top = (numericAttr2(fillRect, "t") ?? 0) / 1e5;
7809
+ const right = (numericAttr2(fillRect, "r") ?? 0) / 1e5;
7810
+ const bottom = (numericAttr2(fillRect, "b") ?? 0) / 1e5;
7811
+ if (left === 0 && top === 0 && right === 0 && bottom === 0) return void 0;
7812
+ return { left, top, right, bottom };
7813
+ }
7814
+ function sourceNodeId(cNvPr) {
7815
+ const id = getAttr(cNvPr, "id");
7816
+ return id !== void 0 ? asSourceNodeId(id) : void 0;
7817
+ }
7818
+ function emuAttr(node, attrName) {
7819
+ return asEmu2(numericAttr2(node, attrName) ?? 0);
7820
+ }
7821
+ var EMPTY_KNOWN = /* @__PURE__ */ new Set();
7822
+ function orderedChildChildren2(parent, childLocalName) {
7823
+ const child = parent?.find((entry) => {
7824
+ const key2 = Object.keys(entry).find((candidate) => candidate !== ":@");
7825
+ return key2 !== void 0 && localName(key2) === childLocalName;
7826
+ });
7827
+ if (child === void 0) return void 0;
7828
+ const key = Object.keys(child).find((candidate) => candidate !== ":@");
7829
+ const value = key !== void 0 ? child[key] : void 0;
7830
+ return Array.isArray(value) ? value : void 0;
7831
+ }
7832
+ function orderedChildChildrenList(parent, childLocalName) {
7833
+ if (parent === void 0) return [];
7834
+ return parent.filter((entry) => {
7835
+ const key = Object.keys(entry).find((candidate) => candidate !== ":@");
7836
+ return key !== void 0 && localName(key) === childLocalName;
7837
+ }).map((entry) => {
7838
+ const key = Object.keys(entry).find((candidate) => candidate !== ":@");
7839
+ const value = key !== void 0 ? entry[key] : void 0;
7840
+ return Array.isArray(value) ? value : void 0;
7841
+ });
7842
+ }
7843
+ function orderedNestedChildChildren(node, parentLocalName, childLocalName) {
7844
+ if (node === void 0) return void 0;
7845
+ const parentChildren = node[parentLocalName];
7846
+ return orderedChildChildren2(
7847
+ Array.isArray(parentChildren) ? parentChildren : void 0,
7848
+ childLocalName
7849
+ );
7850
+ }
7851
+ var xmlBuilder = new import_fast_xml_parser2.XMLBuilder({
7852
+ ignoreAttributes: false,
7853
+ attributeNamePrefix: "@_",
7854
+ format: false,
7855
+ suppressEmptyNode: true
7856
+ });
7857
+ var EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS = {
7858
+ bold: (value) => requireBooleanOrUndefined(value, "bold"),
7859
+ italic: (value) => requireBooleanOrUndefined(value, "italic"),
7860
+ underline: (value) => requireBooleanOrUndefined(value, "underline"),
7861
+ fontSize: (value) => {
7862
+ if (value !== void 0 && (!Number.isFinite(value) || value <= 0)) {
7863
+ throw new Error("updateTextRunProperties: fontSize must be a finite positive pt value");
7864
+ }
7865
+ },
7866
+ color: (value) => {
7867
+ if (value === void 0) return;
7868
+ if (value.kind !== "srgb") {
7869
+ throw new Error("updateTextRunProperties: only srgb text run color is supported");
7870
+ }
7871
+ if (!/^[0-9A-Fa-f]{6}$/.test(value.hex)) {
7872
+ throw new Error("updateTextRunProperties: srgb text run color must be a 6-digit hex value");
7873
+ }
7874
+ },
7875
+ typeface: (value) => {
7876
+ if (value !== void 0 && value.trim() === "") {
7877
+ throw new Error("updateTextRunProperties: typeface must be a non-empty string");
7878
+ }
7879
+ }
7880
+ };
7881
+ var EDITABLE_TEXT_RUN_PROPERTIES = Object.keys(EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS).filter(
7882
+ (property) => property in EDITABLE_TEXT_RUN_PROPERTY_VALIDATORS
7883
+ );
7884
+ var EDITABLE_TEXT_RUN_PROPERTY_SET = new Set(EDITABLE_TEXT_RUN_PROPERTIES);
7885
+ function requireBooleanOrUndefined(value, fieldName) {
7886
+ if (value !== void 0 && typeof value !== "boolean") {
7887
+ throw new Error(`updateTextRunProperties: ${fieldName} must be a boolean value`);
7888
+ }
7889
+ }
7890
+ function asEmu2(value) {
7891
+ return unsafeBrandAssertion2(value);
7892
+ }
7893
+ function asPt(value) {
7894
+ return unsafeBrandAssertion2(value);
7895
+ }
7896
+ function asHundredthPt2(value) {
7897
+ return unsafeBrandAssertion2(value);
7898
+ }
7899
+ function asOoxmlPercent(value) {
7900
+ return unsafeBrandAssertion2(value);
7901
+ }
7902
+ function asOoxmlAngle(value) {
7903
+ return unsafeBrandAssertion2(value);
7904
+ }
7905
+ var RECTANGLE_ALIGNMENT_TOKENS = /* @__PURE__ */ new Set([
7906
+ "tl",
7907
+ "t",
7908
+ "tr",
7909
+ "l",
7910
+ "ctr",
7911
+ "r",
7912
+ "bl",
7913
+ "b",
7914
+ "br"
7915
+ ]);
7916
+ var COLOR_TRANSFORM_KINDS = /* @__PURE__ */ new Set([
7917
+ "lumMod",
7918
+ "lumOff",
7919
+ "tint",
7920
+ "shade",
7921
+ "alpha"
7922
+ ]);
7923
+ var RAW_FILL_LOCAL_NAMES = ["grpFill"];
7924
+ var PRESET_COLOR_HEX = {
7925
+ black: "000000",
7926
+ white: "FFFFFF",
7927
+ red: "FF0000",
7928
+ green: "008000",
7929
+ blue: "0000FF",
7930
+ yellow: "FFFF00",
7931
+ cyan: "00FFFF",
7932
+ magenta: "FF00FF"
7933
+ };
7934
+ function parseColorElement(parent) {
7935
+ if (!parent) return void 0;
7936
+ const srgb = getChild(parent, "srgbClr");
7937
+ if (srgb) {
7938
+ const hex = getAttr(srgb, "val");
7939
+ if (hex !== void 0) {
7940
+ return withTransforms({ kind: "srgb", hex: hex.toUpperCase() }, srgb);
7941
+ }
7942
+ }
7943
+ const scheme = getChild(parent, "schemeClr");
7944
+ if (scheme) {
7945
+ const name = getAttr(scheme, "val");
7946
+ if (name !== void 0) {
7947
+ return withTransforms({ kind: "scheme", scheme: name }, scheme);
7948
+ }
7949
+ }
7950
+ const sys = getChild(parent, "sysClr");
7951
+ if (sys) {
7952
+ const val = getAttr(sys, "val");
7953
+ if (val !== void 0) {
7954
+ const lastClr = getAttr(sys, "lastClr");
7955
+ return withTransforms(
7956
+ {
7957
+ kind: "system",
7958
+ value: val,
7959
+ ...lastClr !== void 0 ? { lastColor: lastClr.toUpperCase() } : {}
7960
+ },
7961
+ sys
7962
+ );
7963
+ }
7964
+ }
7965
+ return void 0;
7806
7966
  }
7807
- function parseShapeStyle(style) {
7808
- if (style === void 0) return void 0;
7809
- const fillRef = parseStyleReference(getChild(style, "fillRef"));
7810
- const lineRef = parseStyleReference(getChild(style, "lnRef"));
7811
- const effectRef = parseStyleReference(getChild(style, "effectRef"));
7967
+ function parseEffectList(effectList) {
7968
+ if (effectList === void 0) return void 0;
7969
+ const outerShadow = parseOuterShadow(getChild(effectList, "outerShdw"));
7970
+ const innerShadow = parseInnerShadow(getChild(effectList, "innerShdw"));
7971
+ const glow = parseGlow(getChild(effectList, "glow"));
7972
+ const softEdge = parseSoftEdge(getChild(effectList, "softEdge"));
7812
7973
  const parsed = {
7813
- ...fillRef !== void 0 ? { fillRef } : {},
7814
- ...lineRef !== void 0 ? { lineRef } : {},
7815
- ...effectRef !== void 0 ? { effectRef } : {}
7974
+ ...outerShadow !== void 0 ? { outerShadow } : {},
7975
+ ...innerShadow !== void 0 ? { innerShadow } : {},
7976
+ ...glow !== void 0 ? { glow } : {},
7977
+ ...softEdge !== void 0 ? { softEdge } : {}
7816
7978
  };
7817
7979
  return Object.keys(parsed).length > 0 ? parsed : void 0;
7818
7980
  }
7819
- function parseStyleReference(ref) {
7820
- if (ref === void 0) return void 0;
7821
- const index = numericAttr(ref, "idx") ?? 0;
7822
- const color = parseColorElement(ref);
7823
- return {
7824
- index,
7825
- ...color !== void 0 ? { color } : {}
7981
+ function parseBlipEffects(blip) {
7982
+ if (blip === void 0) return void 0;
7983
+ const grayscale = getChild(blip, "grayscl") !== void 0;
7984
+ const biLevel = parseBiLevel(getChild(blip, "biLevel"));
7985
+ const blur = parseBlurEffect(getChild(blip, "blur"));
7986
+ const lum = parseLumEffect(getChild(blip, "lum"));
7987
+ const duotone = parseDuotoneEffect(getChild(blip, "duotone"));
7988
+ const clrChange = parseColorChangeEffect(getChild(blip, "clrChange"));
7989
+ const parsed = {
7990
+ grayscale,
7991
+ ...biLevel !== void 0 ? { biLevel } : {},
7992
+ ...blur !== void 0 ? { blur } : {},
7993
+ ...lum !== void 0 ? { lum } : {},
7994
+ ...duotone !== void 0 ? { duotone } : {},
7995
+ ...clrChange !== void 0 ? { clrChange } : {}
7826
7996
  };
7997
+ return grayscale || biLevel !== void 0 || blur !== void 0 || lum !== void 0 || duotone !== void 0 || clrChange !== void 0 ? parsed : void 0;
7827
7998
  }
7828
- function parseGroup(grpSp, partPath, nextId, orderingSlot, orderedChildren) {
7829
- const nvGrpSpPr = getChild(grpSp, "nvGrpSpPr");
7830
- const cNvPr = getChild(nvGrpSpPr, "cNvPr");
7831
- const nodeId = sourceNodeId(cNvPr);
7832
- const name = getAttr(cNvPr, "name");
7833
- const grpSpPr = getChild(grpSp, "grpSpPr");
7834
- const transform = parseTransform(grpSpPr);
7835
- const childTransform = parseChildTransform(grpSpPr, transform);
7836
- const fill = parseFill(grpSpPr, nextId);
7837
- const effects = parseEffectList(getChild(grpSpPr, "effectLst"));
7838
- const rawSidecars = [
7839
- ...collectUnknownSidecars(grpSp, KNOWN_GROUP_CHILDREN, nextId),
7840
- ...collectUnknownSidecars(grpSpPr, KNOWN_SP_PR_CHILDREN, nextId),
7841
- ...collectEffectSidecars(grpSpPr, effects, nextId)
7842
- ];
7999
+ function parseOuterShadow(node) {
8000
+ if (node === void 0) return void 0;
8001
+ const color = parseColorElement(node);
8002
+ if (color === void 0) return void 0;
7843
8003
  return {
7844
- kind: "group",
7845
- ...nodeId !== void 0 ? { nodeId } : {},
7846
- ...name !== void 0 ? { name } : {},
7847
- ...transform !== void 0 ? { transform } : {},
7848
- ...childTransform !== void 0 ? { childTransform } : {},
7849
- ...fill !== void 0 ? { fill } : {},
7850
- ...effects !== void 0 ? { effects } : {},
7851
- children: parseShapeTree(grpSp, partPath, nextId, orderedChildren),
7852
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
7853
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
8004
+ blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
8005
+ distance: asEmu2(numericAttr2(node, "dist") ?? 0),
8006
+ direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
8007
+ color,
8008
+ alignment: parseRectangleAlignment(getAttr(node, "algn"), "b"),
8009
+ rotateWithShape: getAttr(node, "rotWithShape") !== "0"
7854
8010
  };
7855
8011
  }
7856
- function parseImage(pic, partPath, nextId, orderingSlot) {
7857
- const cNvPr = getChild(getChild(pic, "nvPicPr"), "cNvPr");
7858
- const nodeId = sourceNodeId(cNvPr);
7859
- const name = getAttr(cNvPr, "name");
7860
- const blipFill = getChild(pic, "blipFill");
7861
- const blip = getChild(blipFill, "blip");
7862
- const embed = getNamespacedAttr(blip, "embed");
7863
- const crop = parseCrop(getChild(blipFill, "srcRect"));
7864
- const stretch = parseStretch(getChild(blipFill, "stretch"));
7865
- const tile = parseImageFillTile(getChild(blipFill, "tile"));
7866
- const blipEffects = parseBlipEffects(blip);
7867
- const spPr = getChild(pic, "spPr");
7868
- const transform = parseTransform(spPr);
7869
- const effects = parseEffectList(getChild(spPr, "effectLst"));
7870
- const rawSidecars = [
7871
- ...collectUnknownSidecars(pic, KNOWN_PICTURE_CHILDREN, nextId),
7872
- ...collectUnknownSidecars(spPr, KNOWN_SP_PR_CHILDREN, nextId),
7873
- ...collectEffectSidecars(spPr, effects, nextId),
7874
- // Retains fill mode such as `a:stretch` / `a:tile` and recolor operation under blip.
7875
- ...collectUnknownSidecars(blipFill, KNOWN_BLIP_FILL_CHILDREN, nextId),
7876
- ...collectBlipEffectSidecars(blip, blipEffects, nextId)
7877
- ];
8012
+ function parseInnerShadow(node) {
8013
+ if (node === void 0) return void 0;
8014
+ const color = parseColorElement(node);
8015
+ if (color === void 0) return void 0;
7878
8016
  return {
7879
- kind: "image",
7880
- ...nodeId !== void 0 ? { nodeId } : {},
7881
- ...name !== void 0 ? { name } : {},
7882
- ...transform !== void 0 ? { transform } : {},
7883
- ...embed !== void 0 ? { blipRelationshipId: asRelationshipId(embed) } : {},
7884
- ...crop !== void 0 ? { crop } : {},
7885
- ...stretch !== void 0 ? { stretch } : {},
7886
- ...tile !== void 0 ? { tile } : {},
7887
- ...effects !== void 0 ? { effects } : {},
7888
- ...blipEffects !== void 0 ? { blipEffects } : {},
7889
- handle: {
7890
- partPath,
7891
- ...nodeId !== void 0 ? { nodeId } : {},
7892
- ...embed !== void 0 ? { relationshipId: asRelationshipId(embed) } : {},
7893
- orderingSlot
7894
- },
7895
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
8017
+ blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
8018
+ distance: asEmu2(numericAttr2(node, "dist") ?? 0),
8019
+ direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
8020
+ color
7896
8021
  };
7897
8022
  }
7898
- function collectEffectSidecars(spPr, effects, nextId) {
7899
- const effectList = getChild(spPr, "effectLst");
7900
- if (effectList === void 0) return [];
7901
- const sidecars = collectUnknownSidecars(effectList, KNOWN_EFFECT_CHILDREN, nextId);
7902
- const supportedChildren = [
7903
- ["outerShdw", effects?.outerShadow],
7904
- ["innerShdw", effects?.innerShadow],
7905
- ["glow", effects?.glow],
7906
- ["softEdge", effects?.softEdge]
7907
- ];
7908
- for (const [name, parsed] of supportedChildren) {
7909
- const node = getChild(effectList, name);
7910
- if (node !== void 0 && parsed === void 0) {
7911
- sidecars.push(makeSidecar(`a:${name}`, node, nextId));
7912
- }
7913
- }
7914
- return sidecars;
7915
- }
7916
- function collectBlipEffectSidecars(blip, effects, nextId) {
7917
- if (blip === void 0) return [];
7918
- const sidecars = collectUnknownSidecars(blip, KNOWN_BLIP_CHILDREN, nextId);
7919
- const supportedChildren = [
7920
- ["grayscl", effects?.grayscale === true],
7921
- ["biLevel", effects?.biLevel],
7922
- ["blur", effects?.blur],
7923
- ["lum", effects?.lum],
7924
- ["duotone", effects?.duotone],
7925
- ["clrChange", effects?.clrChange]
7926
- ];
7927
- for (const [name, parsed] of supportedChildren) {
7928
- const node = getChild(blip, name);
7929
- if (node !== void 0 && (parsed === void 0 || parsed === false)) {
7930
- sidecars.push(makeSidecar(`a:${name}`, node, nextId));
7931
- }
7932
- }
7933
- return sidecars;
7934
- }
7935
- function parseGraphicFrame(graphicFrame, partPath, nextId, orderingSlot, orderedNode) {
7936
- const graphic = getChild(graphicFrame, "graphic");
7937
- const graphicData = getChild(graphic, "graphicData");
7938
- const uri = getAttr(graphicData, "uri");
7939
- if (uri !== void 0 && CHART_GRAPHIC_DATA_URIS.has(uri)) {
7940
- const parsedChart = parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7941
- if (parsedChart !== void 0) return parsedChart;
7942
- }
7943
- if (uri !== void 0 && SMARTART_DIAGRAM_URIS.has(uri)) {
7944
- const parsedSmartArt = parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot);
7945
- if (parsedSmartArt !== void 0) return parsedSmartArt;
7946
- }
7947
- const table = getChild(graphicData, "tbl");
7948
- if (table === void 0) {
7949
- return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
7950
- }
7951
- const orderedGraphicChildren = orderedNestedChildChildren(orderedNode, "graphicFrame", "graphic");
7952
- const orderedGraphicDataChildren = orderedChildChildren2(orderedGraphicChildren, "graphicData");
7953
- const orderedTableChildren = orderedChildChildren2(orderedGraphicDataChildren, "tbl");
7954
- const parsedTable = parseTable(
7955
- table,
7956
- graphicFrame,
7957
- partPath,
7958
- nextId,
7959
- orderingSlot,
7960
- orderedTableChildren
7961
- );
7962
- if (parsedTable === void 0) {
7963
- return parseRawShapeNode("p:graphicFrame", graphicFrame, partPath, nextId, orderingSlot);
7964
- }
7965
- return parsedTable;
7966
- }
7967
- function parseAlternateContent(alternateContent, partPath, nextId, orderingSlot) {
7968
- const branches = [
7969
- ...getChildArray(alternateContent, "Choice"),
7970
- ...getChildArray(alternateContent, "Fallback")
7971
- ];
7972
- for (const branch of branches) {
7973
- const parsed = parseAlternateContentBranch(branch, partPath, nextId, orderingSlot);
7974
- if (parsed.length > 0) {
7975
- if (parsed.every((node) => node.kind === "raw")) {
7976
- continue;
7977
- }
7978
- return parsed.map(
7979
- (node) => attachRawSidecar(node, makeSidecar("mc:AlternateContent", alternateContent, nextId))
7980
- );
7981
- }
7982
- }
7983
- return [
7984
- parseRawShapeNode("mc:AlternateContent", alternateContent, partPath, nextId, orderingSlot)
7985
- ];
7986
- }
7987
- function attachRawSidecar(node, sidecar) {
7988
- if (node.kind === "raw") return node;
8023
+ function parseGlow(node) {
8024
+ if (node === void 0) return void 0;
8025
+ const color = parseColorElement(node);
8026
+ if (color === void 0) return void 0;
7989
8027
  return {
7990
- ...node,
7991
- rawSidecars: [...node.rawSidecars ?? [], sidecar]
8028
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0),
8029
+ color
7992
8030
  };
7993
8031
  }
7994
- function parseAlternateContentBranch(branch, partPath, nextId, orderingSlot) {
7995
- const nodes = [];
7996
- for (const key of Object.keys(branch)) {
7997
- if (key.startsWith("@_") || key === "#text") continue;
7998
- const local = localName(key);
7999
- const value = branch[key];
8000
- const items = Array.isArray(value) ? value : [value];
8001
- for (const item of items) {
8002
- const node = unsafeOoxmlBoundaryAssertion(item);
8003
- if (local === "sp") nodes.push(parseShape(node, partPath, nextId, orderingSlot));
8004
- else if (local === "pic") nodes.push(parseImage(node, partPath, nextId, orderingSlot));
8005
- else if (local === "cxnSp") {
8006
- nodes.push(parseConnector(node, partPath, nextId, orderingSlot));
8007
- } else if (local === "grpSp") {
8008
- nodes.push(parseGroup(node, partPath, nextId, orderingSlot));
8009
- } else if (local === "graphicFrame") {
8010
- nodes.push(parseGraphicFrame(node, partPath, nextId, orderingSlot));
8011
- } else {
8012
- nodes.push(parseRawShapeNode(key, node, partPath, nextId, orderingSlot));
8013
- }
8014
- }
8015
- }
8016
- return nodes;
8032
+ function parseSoftEdge(node) {
8033
+ if (node === void 0) return void 0;
8034
+ return {
8035
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0)
8036
+ };
8017
8037
  }
8018
- function parseChartGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
8019
- const graphic = getChild(graphicFrame, "graphic");
8020
- const graphicData = getChild(graphic, "graphicData");
8021
- const chart = getChild(graphicData, "chart");
8022
- const rId = getNamespacedAttr(chart, "id") ?? getAttr(chart, "id");
8023
- if (rId === void 0) return void 0;
8024
- const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
8025
- const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
8026
- const nodeId = sourceNodeId(cNvPr);
8027
- const name = getAttr(cNvPr, "name");
8028
- const transform = parseTransform(graphicFrame);
8029
- const rawSidecars = [
8030
- ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
8031
- ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
8032
- ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
8033
- ];
8038
+ function parseBiLevel(node) {
8039
+ if (node === void 0) return void 0;
8034
8040
  return {
8035
- kind: "chart",
8036
- ...nodeId !== void 0 ? { nodeId } : {},
8037
- ...name !== void 0 ? { name } : {},
8038
- ...transform !== void 0 ? { transform } : {},
8039
- chartRelationshipId: asRelationshipId(rId),
8040
- handle: {
8041
- partPath,
8042
- ...nodeId !== void 0 ? { nodeId } : {},
8043
- relationshipId: asRelationshipId(rId),
8044
- orderingSlot
8045
- },
8046
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
8041
+ threshold: (numericAttr2(node, "thresh") ?? 5e4) / 1e5
8047
8042
  };
8048
8043
  }
8049
- function parseSmartArtGraphicFrame(graphicFrame, partPath, nextId, orderingSlot) {
8050
- const graphic = getChild(graphicFrame, "graphic");
8051
- const graphicData = getChild(graphic, "graphicData");
8052
- const relIds = getChild(graphicData, "relIds");
8053
- const dmRId = getNamespacedAttr(relIds, "dm") ?? getAttr(relIds, "dm");
8054
- if (dmRId === void 0) return void 0;
8055
- const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
8056
- const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
8057
- const nodeId = sourceNodeId(cNvPr);
8058
- const name = getAttr(cNvPr, "name");
8059
- const transform = parseTransform(graphicFrame);
8060
- const rawSidecars = [
8061
- ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
8062
- ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
8063
- ...collectUnknownSidecars(graphicData, EMPTY_KNOWN, nextId)
8064
- ];
8044
+ function parseBlurEffect(node) {
8045
+ if (node === void 0) return void 0;
8065
8046
  return {
8066
- kind: "smartArt",
8067
- ...nodeId !== void 0 ? { nodeId } : {},
8068
- ...name !== void 0 ? { name } : {},
8069
- ...transform !== void 0 ? { transform } : {},
8070
- dataRelationshipId: asRelationshipId(dmRId),
8071
- handle: {
8072
- partPath,
8073
- ...nodeId !== void 0 ? { nodeId } : {},
8074
- relationshipId: asRelationshipId(dmRId),
8075
- orderingSlot
8076
- },
8077
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
8047
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0),
8048
+ grow: getAttr(node, "grow") !== "0"
8078
8049
  };
8079
8050
  }
8080
- function parseTable(tbl, graphicFrame, partPath, nextId, orderingSlot, orderedTableChildren) {
8081
- const columns = parseTableColumns(getChild(tbl, "tblGrid"));
8082
- if (columns.length === 0) return void 0;
8083
- const nvGraphicFramePr = getChild(graphicFrame, "nvGraphicFramePr");
8084
- const cNvPr = getChild(nvGraphicFramePr, "cNvPr");
8085
- const nodeId = sourceNodeId(cNvPr);
8086
- const name = getAttr(cNvPr, "name");
8087
- const tblPr = getChild(tbl, "tblPr");
8088
- const tableStyleId = getChildText(tblPr, "tableStyleId");
8089
- const graphic = getChild(graphicFrame, "graphic");
8090
- const graphicData = getChild(graphic, "graphicData");
8091
- const transform = parseTransform(graphicFrame);
8092
- const rows = parseTableRows(tbl, partPath, nextId, nodeId, orderingSlot, orderedTableChildren);
8093
- const rawSidecars = [
8094
- ...collectUnknownSidecars(graphicFrame, KNOWN_GRAPHIC_FRAME_CHILDREN, nextId),
8095
- ...collectUnknownSidecars(graphic, KNOWN_GRAPHIC_CHILDREN, nextId),
8096
- ...collectUnknownSidecars(graphicData, KNOWN_GRAPHIC_DATA_CHILDREN, nextId),
8097
- ...collectUnknownSidecars(tbl, KNOWN_TABLE_CHILDREN, nextId)
8098
- ];
8051
+ function parseLumEffect(node) {
8052
+ if (node === void 0) return void 0;
8099
8053
  return {
8100
- kind: "table",
8101
- ...nodeId !== void 0 ? { nodeId } : {},
8102
- ...name !== void 0 ? { name } : {},
8103
- ...transform !== void 0 ? { transform } : {},
8104
- table: {
8105
- columns,
8106
- rows,
8107
- ...tableStyleId !== void 0 ? { tableStyleId } : {}
8108
- },
8109
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot },
8110
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
8054
+ brightness: (numericAttr2(node, "bright") ?? 0) / 1e5,
8055
+ contrast: (numericAttr2(node, "contrast") ?? 0) / 1e5
8111
8056
  };
8112
8057
  }
8113
- function parseTableColumns(tblGrid) {
8114
- return getChildArray(tblGrid, "gridCol").map((col) => ({ width: emuAttr(col, "w") }));
8058
+ function parseDuotoneEffect(node) {
8059
+ if (node === void 0) return void 0;
8060
+ const colors = collectColorChildren(node);
8061
+ if (colors.length < 2) return void 0;
8062
+ return { color1: colors[0], color2: colors[1] };
8115
8063
  }
8116
- function parseTableRows(tbl, partPath, nextId, tableNodeId, tableOrderingSlot, orderedTableChildren) {
8117
- const orderedRows = orderedChildChildrenList(orderedTableChildren, "tr");
8118
- return getChildArray(tbl, "tr").map((tr, rowIndex) => ({
8119
- height: emuAttr(tr, "h"),
8120
- cells: getChildArray(tr, "tc").map((tc, cellIndex) => {
8121
- const orderedCells = orderedChildChildrenList(orderedRows[rowIndex], "tc");
8122
- return parseTableCell(
8123
- tc,
8124
- partPath,
8125
- nextId,
8126
- tableNodeId,
8127
- tableOrderingSlot,
8128
- rowIndex,
8129
- cellIndex,
8130
- orderedCells[cellIndex]
8131
- );
8132
- })
8133
- }));
8064
+ function parseColorChangeEffect(node) {
8065
+ if (node === void 0) return void 0;
8066
+ const from = firstColorChild(getChild(node, "clrFrom"));
8067
+ const to = firstColorChild(getChild(node, "clrTo"));
8068
+ return from !== void 0 && to !== void 0 ? { from, to } : void 0;
8134
8069
  }
8135
- function parseTableCell(tc, partPath, nextId, tableNodeId, tableOrderingSlot, rowIndex, cellIndex, orderedCellChildren) {
8136
- const tcPr = getChild(tc, "tcPr");
8137
- const textOrderingSlot = tableOrderingSlot * 1e9 + rowIndex * 1e6 + cellIndex;
8138
- const textBody = parseTextBody(
8139
- getChild(tc, "txBody"),
8140
- partPath,
8141
- nextId,
8142
- tableNodeId,
8143
- textOrderingSlot,
8144
- orderedChildChildren2(orderedCellChildren, "txBody")
8145
- );
8146
- const fill = parseFill(tcPr, nextId);
8147
- const borders = parseCellBorders(tcPr, nextId);
8148
- const rawSidecars = [
8149
- ...collectUnknownSidecars(tc, KNOWN_TABLE_CELL_CHILDREN, nextId),
8150
- ...collectUnknownSidecars(tcPr, KNOWN_TABLE_CELL_PROPERTIES_CHILDREN, nextId)
8151
- ];
8152
- return {
8153
- ...textBody !== void 0 ? { textBody } : {},
8154
- ...fill !== void 0 ? { fill } : {},
8155
- ...borders !== void 0 ? { borders } : {},
8156
- gridSpan: numericAttr(tc, "gridSpan") ?? 1,
8157
- rowSpan: numericAttr(tc, "rowSpan") ?? 1,
8158
- hMerge: isTrue(getAttr(tc, "hMerge") ?? getAttr(tcPr, "hMerge")),
8159
- vMerge: isTrue(getAttr(tc, "vMerge") ?? getAttr(tcPr, "vMerge")),
8160
- ...rawSidecars.length > 0 ? { rawSidecars } : {}
8070
+ function collectColorChildren(parent) {
8071
+ const colors = [];
8072
+ for (const [key, value] of Object.entries(parent)) {
8073
+ if (key.startsWith("@_")) continue;
8074
+ const nodes = Array.isArray(value) ? value : [value];
8075
+ for (const node of nodes) {
8076
+ if (!isXmlNode(node)) continue;
8077
+ const color = parseColorChild(key, node);
8078
+ if (color !== void 0) colors.push(color);
8079
+ }
8080
+ }
8081
+ return colors;
8082
+ }
8083
+ function firstColorChild(parent) {
8084
+ return parent !== void 0 ? collectColorChildren(parent)[0] : void 0;
8085
+ }
8086
+ function parseColorChild(key, node) {
8087
+ const name = localName(key);
8088
+ return name === "prstClr" ? parsePresetColor(node) : parseColorElement({ [name]: node });
8089
+ }
8090
+ function isXmlNode(value) {
8091
+ return typeof value === "object" && value !== null;
8092
+ }
8093
+ function parsePresetColor(node) {
8094
+ const value = getAttr(node, "val");
8095
+ const hex = value !== void 0 ? PRESET_COLOR_HEX[value] : void 0;
8096
+ return hex !== void 0 ? withTransforms({ kind: "srgb", hex }, node) : void 0;
8097
+ }
8098
+ function parseFill(parent, nextId) {
8099
+ if (!parent) return void 0;
8100
+ const solid = getChild(parent, "solidFill");
8101
+ if (solid) {
8102
+ const color = parseColorElement(solid);
8103
+ if (color) return { kind: "solid", color };
8104
+ return { kind: "raw", raw: makeSidecar("a:solidFill", solid, nextId) };
8105
+ }
8106
+ if (hasChild(parent, "noFill")) return { kind: "none" };
8107
+ const grad = getChild(parent, "gradFill");
8108
+ if (grad) {
8109
+ const fill = parseGradientFill(grad);
8110
+ return fill ?? { kind: "raw", raw: makeSidecar("a:gradFill", grad, nextId) };
8111
+ }
8112
+ const blip = getChild(parent, "blipFill");
8113
+ if (blip) {
8114
+ return parseBlipFill(blip) ?? { kind: "raw", raw: makeSidecar("a:blipFill", blip, nextId) };
8115
+ }
8116
+ const pattern = getChild(parent, "pattFill");
8117
+ if (pattern) {
8118
+ const fill = parsePatternFill(pattern);
8119
+ return fill ?? { kind: "raw", raw: makeSidecar("a:pattFill", pattern, nextId) };
8120
+ }
8121
+ for (const name of RAW_FILL_LOCAL_NAMES) {
8122
+ if (hasChild(parent, name)) {
8123
+ return { kind: "raw", raw: makeSidecar(`a:${name}`, getChild(parent, name) ?? {}, nextId) };
8124
+ }
8125
+ }
8126
+ return void 0;
8127
+ }
8128
+ function parseGradientFill(grad) {
8129
+ const stops = [];
8130
+ for (const gs of getChildArray(getChild(grad, "gsLst"), "gs")) {
8131
+ const color = parseColorElement(gs);
8132
+ if (color === void 0) continue;
8133
+ stops.push({
8134
+ position: (numericAttr2(gs, "pos") ?? 0) / 1e5,
8135
+ color
8136
+ });
8137
+ }
8138
+ if (stops.length === 0) return void 0;
8139
+ const path = getChild(grad, "path");
8140
+ if (path !== void 0) {
8141
+ const fillToRect = getChild(path, "fillToRect");
8142
+ const l = numericAttr2(fillToRect, "l") ?? 0;
8143
+ const t = numericAttr2(fillToRect, "t") ?? 0;
8144
+ const r = numericAttr2(fillToRect, "r") ?? 0;
8145
+ const b = numericAttr2(fillToRect, "b") ?? 0;
8146
+ return {
8147
+ kind: "gradient",
8148
+ gradientType: "radial",
8149
+ stops,
8150
+ centerX: (l + (1e5 - r)) / 2 / 1e5,
8151
+ centerY: (t + (1e5 - b)) / 2 / 1e5
8152
+ };
8153
+ }
8154
+ return {
8155
+ kind: "gradient",
8156
+ gradientType: "linear",
8157
+ stops,
8158
+ angle: asOoxmlAngle(numericAttr2(getChild(grad, "lin"), "ang") ?? 0)
8161
8159
  };
8162
8160
  }
8163
- function parseCellBorders(tcPr, nextId) {
8164
- const left = parseLine(getChild(tcPr, "lnL"), nextId);
8165
- const right = parseLine(getChild(tcPr, "lnR"), nextId);
8166
- const top = parseLine(getChild(tcPr, "lnT"), nextId);
8167
- const bottom = parseLine(getChild(tcPr, "lnB"), nextId);
8168
- if (left === void 0 && right === void 0 && top === void 0 && bottom === void 0) {
8169
- return void 0;
8170
- }
8161
+ function parseBlipFill(blipFill) {
8162
+ const blip = getChild(blipFill, "blip");
8163
+ const embed = getNamespacedAttr(blip, "embed");
8164
+ if (embed === void 0) return void 0;
8165
+ const tile = parseImageFillTile(getChild(blipFill, "tile"));
8171
8166
  return {
8172
- ...top !== void 0 ? { top } : {},
8173
- ...bottom !== void 0 ? { bottom } : {},
8174
- ...left !== void 0 ? { left } : {},
8175
- ...right !== void 0 ? { right } : {}
8167
+ kind: "image",
8168
+ blipRelationshipId: asRelationshipId(embed),
8169
+ ...tile !== void 0 ? { tile } : {}
8176
8170
  };
8177
8171
  }
8178
- function parseRawShapeNode(key, node, partPath, nextId, orderingSlot) {
8179
- const nodeId = sourceNodeId(getChild(getChild(node, "nvSpPr"), "cNvPr"));
8172
+ function parseImageFillTile(tile) {
8173
+ if (tile === void 0) return void 0;
8174
+ const flip = getAttr(tile, "flip") ?? "none";
8180
8175
  return {
8181
- kind: "raw",
8182
- ...nodeId !== void 0 ? { nodeId } : {},
8183
- raw: makeSidecar(key, node, nextId),
8184
- handle: { partPath, ...nodeId !== void 0 ? { nodeId } : {}, orderingSlot }
8176
+ tx: asEmu2(numericAttr2(tile, "tx") ?? 0),
8177
+ ty: asEmu2(numericAttr2(tile, "ty") ?? 0),
8178
+ sx: (numericAttr2(tile, "sx") ?? 1e5) / 1e5,
8179
+ sy: (numericAttr2(tile, "sy") ?? 1e5) / 1e5,
8180
+ flip: flip === "x" || flip === "y" || flip === "xy" ? flip : "none",
8181
+ align: parseRectangleAlignment(getAttr(tile, "algn"), "tl")
8185
8182
  };
8186
8183
  }
8187
- function parsePlaceholder(ph) {
8188
- if (!ph) return void 0;
8189
- const type = getAttr(ph, "type");
8190
- const index = numericAttr(ph, "idx");
8191
- if (type === void 0 && index === void 0) return void 0;
8184
+ function parseRectangleAlignment(value, fallback) {
8185
+ return parseEnumValueWithDefault(value, RECTANGLE_ALIGNMENT_TOKENS, fallback);
8186
+ }
8187
+ function parsePatternFill(pattern) {
8188
+ const foregroundColor = parseColorElement(getChild(pattern, "fgClr"));
8189
+ const backgroundColor = parseColorElement(getChild(pattern, "bgClr"));
8190
+ if (foregroundColor === void 0 || backgroundColor === void 0) return void 0;
8192
8191
  return {
8193
- ...type !== void 0 ? { type } : {},
8194
- ...index !== void 0 ? { index } : {}
8192
+ kind: "pattern",
8193
+ preset: getAttr(pattern, "prst") ?? "ltDnDiag",
8194
+ foregroundColor,
8195
+ backgroundColor
8195
8196
  };
8196
8197
  }
8197
- function parseGeometry(spPr, orderedSpPr) {
8198
- const prstGeom = getChild(spPr, "prstGeom");
8199
- if (prstGeom) {
8200
- const preset = getAttr(prstGeom, "prst");
8201
- const adjustValues = parseAdjustValues(getChild(prstGeom, "avLst"));
8202
- return preset !== void 0 ? {
8203
- preset,
8204
- ...Object.keys(adjustValues).length > 0 ? { adjustValues } : {}
8205
- } : void 0;
8206
- }
8207
- const customPaths = parseCustomGeometry(
8208
- getChild(spPr, "custGeom"),
8209
- orderedChildChildren2(orderedSpPr, "custGeom")
8210
- );
8211
- if (customPaths !== void 0) return { kind: "custom", paths: customPaths };
8212
- return void 0;
8198
+ function parseOutline(spPr, nextId) {
8199
+ const ln = getChild(spPr, "ln");
8200
+ return parseLine(ln, nextId);
8213
8201
  }
8214
- function parseAdjustValues(avLst) {
8215
- const adjustValues = {};
8216
- for (const guide of getChildArray(avLst, "gd")) {
8217
- const name = getAttr(guide, "name");
8218
- const formula = getAttr(guide, "fmla");
8219
- const match = formula?.match(/val\s+(-?\d+)/);
8220
- if (name !== void 0 && match !== void 0 && match !== null) {
8221
- adjustValues[name] = Number(match[1]);
8222
- }
8223
- }
8224
- return adjustValues;
8202
+ function parseLine(ln, nextId) {
8203
+ if (!ln) return void 0;
8204
+ const width = numericAttr2(ln, "w");
8205
+ const fill = parseFill(ln, nextId);
8206
+ const dashStyle = parseDashStyle(getChild(ln, "prstDash"));
8207
+ const customDash = parseCustomDash(ln);
8208
+ const lineCap = parseLineCap(getAttr(ln, "cap"));
8209
+ const lineJoin = parseLineJoin(ln);
8210
+ const headEnd = parseArrowEndpoint(getChild(ln, "headEnd"));
8211
+ const tailEnd = parseArrowEndpoint(getChild(ln, "tailEnd"));
8212
+ return {
8213
+ ...width !== void 0 ? { width: asEmu2(width) } : {},
8214
+ ...fill !== void 0 ? { fill } : {},
8215
+ ...dashStyle !== void 0 ? { dashStyle } : {},
8216
+ ...customDash !== void 0 ? { customDash } : {},
8217
+ ...lineCap !== void 0 ? { lineCap } : {},
8218
+ ...lineJoin !== void 0 ? { lineJoin } : {},
8219
+ ...headEnd !== void 0 ? { headEnd } : {},
8220
+ ...tailEnd !== void 0 ? { tailEnd } : {}
8221
+ };
8225
8222
  }
8226
- function parseChildTransform(grpSpPr, fallback) {
8227
- const xfrm = getChild(grpSpPr, "xfrm");
8228
- const childOff = getChild(xfrm, "chOff");
8229
- const childExt = getChild(xfrm, "chExt");
8230
- const offsetX = numericAttr(childOff, "x") ?? 0;
8231
- const offsetY = numericAttr(childOff, "y") ?? 0;
8232
- const width = numericAttr(childExt, "cx") ?? fallback?.width;
8233
- const height = numericAttr(childExt, "cy") ?? fallback?.height;
8234
- if (width === void 0 || height === void 0) return void 0;
8223
+ function parseTransform(spPr) {
8224
+ const xfrm = getChild(spPr, "xfrm");
8225
+ if (!xfrm) return void 0;
8226
+ const off = getChild(xfrm, "off");
8227
+ const ext = getChild(xfrm, "ext");
8228
+ const offsetX = numericAttr2(off, "x");
8229
+ const offsetY = numericAttr2(off, "y");
8230
+ const width = numericAttr2(ext, "cx");
8231
+ const height = numericAttr2(ext, "cy");
8232
+ if (offsetX === void 0 || offsetY === void 0 || width === void 0 || height === void 0) {
8233
+ return void 0;
8234
+ }
8235
+ const rotation = numericAttr2(xfrm, "rot");
8236
+ const flipH = getAttr(xfrm, "flipH");
8237
+ const flipV = getAttr(xfrm, "flipV");
8235
8238
  return {
8236
8239
  offsetX: asEmu2(offsetX),
8237
8240
  offsetY: asEmu2(offsetY),
8238
- width: asEmu2(Number(width)),
8239
- height: asEmu2(Number(height))
8241
+ width: asEmu2(width),
8242
+ height: asEmu2(height),
8243
+ ...rotation !== void 0 ? { rotation: asOoxmlAngle(rotation) } : {},
8244
+ ...isTrue(flipH) ? { flipHorizontal: true } : {},
8245
+ ...isTrue(flipV) ? { flipVertical: true } : {}
8240
8246
  };
8241
8247
  }
8242
- function parseCrop(srcRect) {
8243
- if (!srcRect) return void 0;
8244
- const left = numericAttr(srcRect, "l");
8245
- const top = numericAttr(srcRect, "t");
8246
- const right = numericAttr(srcRect, "r");
8247
- const bottom = numericAttr(srcRect, "b");
8248
- const crop = {
8249
- ...left !== void 0 ? { left: asOoxmlPercent(left) } : {},
8250
- ...top !== void 0 ? { top: asOoxmlPercent(top) } : {},
8251
- ...right !== void 0 ? { right: asOoxmlPercent(right) } : {},
8252
- ...bottom !== void 0 ? { bottom: asOoxmlPercent(bottom) } : {}
8253
- };
8254
- return Object.keys(crop).length > 0 ? crop : void 0;
8248
+ function withTransforms(base, colorNode) {
8249
+ const transforms = [];
8250
+ for (const key of Object.keys(colorNode)) {
8251
+ if (key.startsWith("@_")) continue;
8252
+ const kind = localName(key);
8253
+ const transformKind = parseEnumValue(kind, COLOR_TRANSFORM_KINDS);
8254
+ if (transformKind === void 0) continue;
8255
+ const value = colorNode[key];
8256
+ const items = Array.isArray(value) ? value : [value];
8257
+ for (const item of items) {
8258
+ const raw = getAttr(unsafeOoxmlBoundaryAssertion(item), "val");
8259
+ if (raw === void 0) continue;
8260
+ const numeric = Number(raw);
8261
+ if (!Number.isFinite(numeric)) continue;
8262
+ transforms.push({
8263
+ kind: transformKind,
8264
+ value: asOoxmlPercent(numeric)
8265
+ });
8266
+ }
8267
+ }
8268
+ return transforms.length > 0 ? { ...base, transforms } : base;
8255
8269
  }
8256
- function parseStretch(stretch) {
8257
- const fillRect = getChild(stretch, "fillRect");
8258
- if (fillRect === void 0) return void 0;
8259
- const left = (numericAttr(fillRect, "l") ?? 0) / 1e5;
8260
- const top = (numericAttr(fillRect, "t") ?? 0) / 1e5;
8261
- const right = (numericAttr(fillRect, "r") ?? 0) / 1e5;
8262
- const bottom = (numericAttr(fillRect, "b") ?? 0) / 1e5;
8263
- if (left === 0 && top === 0 && right === 0 && bottom === 0) return void 0;
8264
- return { left, top, right, bottom };
8270
+ function numericAttr2(node, name) {
8271
+ const raw = getAttr(node, name);
8272
+ if (raw === void 0) return void 0;
8273
+ const value = Number(raw);
8274
+ return Number.isFinite(value) ? value : void 0;
8265
8275
  }
8266
- function sourceNodeId(cNvPr) {
8267
- const id = getAttr(cNvPr, "id");
8268
- return id !== void 0 ? asSourceNodeId(id) : void 0;
8276
+ function isTrue(value) {
8277
+ return value === "1" || value === "true";
8269
8278
  }
8270
- function emuAttr(node, attrName) {
8271
- return asEmu2(numericAttr(node, attrName) ?? 0);
8279
+ function parseDashStyle(prstDash) {
8280
+ const value = getAttr(prstDash, "val");
8281
+ return parseEnumValue(value, DASH_STYLES);
8272
8282
  }
8273
- var EMPTY_KNOWN = /* @__PURE__ */ new Set();
8274
- function orderedChildChildren2(parent, childLocalName) {
8275
- const child = parent?.find((entry) => {
8276
- const key2 = Object.keys(entry).find((candidate) => candidate !== ":@");
8277
- return key2 !== void 0 && localName(key2) === childLocalName;
8278
- });
8279
- if (child === void 0) return void 0;
8280
- const key = Object.keys(child).find((candidate) => candidate !== ":@");
8281
- const value = key !== void 0 ? child[key] : void 0;
8282
- return Array.isArray(value) ? value : void 0;
8283
+ function parseCustomDash(ln) {
8284
+ const custDash = getChild(ln, "custDash");
8285
+ const segments = getChildArray(custDash, "ds");
8286
+ if (segments.length === 0) return void 0;
8287
+ return segments.flatMap((segment) => [
8288
+ (numericAttr2(segment, "d") ?? 1e5) / 1e5,
8289
+ (numericAttr2(segment, "sp") ?? 1e5) / 1e5
8290
+ ]);
8283
8291
  }
8284
- function orderedChildChildrenList(parent, childLocalName) {
8285
- if (parent === void 0) return [];
8286
- return parent.filter((entry) => {
8287
- const key = Object.keys(entry).find((candidate) => candidate !== ":@");
8288
- return key !== void 0 && localName(key) === childLocalName;
8289
- }).map((entry) => {
8290
- const key = Object.keys(entry).find((candidate) => candidate !== ":@");
8291
- const value = key !== void 0 ? entry[key] : void 0;
8292
- return Array.isArray(value) ? value : void 0;
8293
- });
8292
+ var LINE_CAP_MAP = {
8293
+ flat: "butt",
8294
+ sq: "square",
8295
+ rnd: "round"
8296
+ };
8297
+ function parseLineCap(value) {
8298
+ return value !== void 0 ? LINE_CAP_MAP[value] : void 0;
8294
8299
  }
8295
- function orderedNestedChildChildren(node, parentLocalName, childLocalName) {
8296
- if (node === void 0) return void 0;
8297
- const parentChildren = node[parentLocalName];
8298
- return orderedChildChildren2(
8299
- Array.isArray(parentChildren) ? parentChildren : void 0,
8300
- childLocalName
8301
- );
8300
+ function parseLineJoin(ln) {
8301
+ if (hasChild(ln, "round")) return "round";
8302
+ if (hasChild(ln, "bevel")) return "bevel";
8303
+ if (hasChild(ln, "miter")) return "miter";
8304
+ return void 0;
8305
+ }
8306
+ function parseArrowEndpoint(node) {
8307
+ if (!node) return void 0;
8308
+ const type = parseEnumValue(getAttr(node, "type"), ARROW_TYPES2);
8309
+ if (type === void 0) return void 0;
8310
+ const width = getAttr(node, "w") ?? "med";
8311
+ const length = getAttr(node, "len") ?? "med";
8312
+ return {
8313
+ type,
8314
+ width: parseEnumValueWithDefault(width, ARROW_SIZES2, "med"),
8315
+ length: parseEnumValueWithDefault(length, ARROW_SIZES2, "med")
8316
+ };
8302
8317
  }
8318
+ var DASH_STYLES = /* @__PURE__ */ new Set([
8319
+ "solid",
8320
+ "dash",
8321
+ "dot",
8322
+ "dashDot",
8323
+ "lgDash",
8324
+ "lgDashDot",
8325
+ "sysDash",
8326
+ "sysDot"
8327
+ ]);
8328
+ var ARROW_TYPES2 = /* @__PURE__ */ new Set([
8329
+ "triangle",
8330
+ "stealth",
8331
+ "diamond",
8332
+ "oval",
8333
+ "arrow"
8334
+ ]);
8335
+ var ARROW_SIZES2 = /* @__PURE__ */ new Set(["sm", "med", "lg"]);
8303
8336
  var DEFAULT_COLOR_MAP = {
8304
8337
  bg1: "lt1",
8305
8338
  tx1: "dk1",
@@ -8718,7 +8751,7 @@ var DIAGRAM_DRAWING_REL_TYPES = /* @__PURE__ */ new Set([
8718
8751
  "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing",
8719
8752
  "http://purl.oclc.org/ooxml/officeDocument/relationships/diagramDrawing"
8720
8753
  ]);
8721
- var textDecoder = new TextDecoder();
8754
+ var textDecoder2 = new TextDecoder();
8722
8755
  var DEFAULT_TABLE_STYLE_BORDERS = {
8723
8756
  top: {
8724
8757
  width: asEmu2(12700),
@@ -9429,7 +9462,7 @@ function isEmptyPlaceholder(shape) {
9429
9462
  }
9430
9463
  function readRawPackageText(source, partPath) {
9431
9464
  const rawPart = source.packageGraph.rawParts?.find((part) => part.partPath === partPath);
9432
- if (rawPart?.kind === "binary") return textDecoder.decode(rawPart.bytes);
9465
+ if (rawPart?.kind === "binary") return textDecoder2.decode(rawPart.bytes);
9433
9466
  return void 0;
9434
9467
  }
9435
9468
  function numericAttr3(node, attrName) {
@@ -9556,7 +9589,7 @@ function parseBackground(bg, nextId) {
9556
9589
  const bgRef = getChild(bg, "bgRef");
9557
9590
  if (bgRef) {
9558
9591
  const color = parseColorElement(bgRef);
9559
- const index = numericAttr(bgRef, "idx");
9592
+ const index = numericAttr2(bgRef, "idx");
9560
9593
  if (color !== void 0) {
9561
9594
  return { kind: "styleReference", index: index ?? 0, color };
9562
9595
  }
@@ -9686,9 +9719,9 @@ function parseOuterShadow2(node) {
9686
9719
  const color = parseColorElement(node);
9687
9720
  if (node === void 0 || color === void 0) return void 0;
9688
9721
  return {
9689
- blurRadius: asEmu2(numericAttr(node, "blurRad") ?? 0),
9690
- distance: asEmu2(numericAttr(node, "dist") ?? 0),
9691
- direction: asOoxmlAngle(numericAttr(node, "dir") ?? 0),
9722
+ blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
9723
+ distance: asEmu2(numericAttr2(node, "dist") ?? 0),
9724
+ direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
9692
9725
  color,
9693
9726
  alignment: parseRectangleAlignment(getAttr(node, "algn"), "b"),
9694
9727
  rotateWithShape: getAttr(node, "rotWithShape") !== "0"
@@ -9698,9 +9731,9 @@ function parseInnerShadow2(node) {
9698
9731
  const color = parseColorElement(node);
9699
9732
  if (node === void 0 || color === void 0) return void 0;
9700
9733
  return {
9701
- blurRadius: asEmu2(numericAttr(node, "blurRad") ?? 0),
9702
- distance: asEmu2(numericAttr(node, "dist") ?? 0),
9703
- direction: asOoxmlAngle(numericAttr(node, "dir") ?? 0),
9734
+ blurRadius: asEmu2(numericAttr2(node, "blurRad") ?? 0),
9735
+ distance: asEmu2(numericAttr2(node, "dist") ?? 0),
9736
+ direction: asOoxmlAngle(numericAttr2(node, "dir") ?? 0),
9704
9737
  color
9705
9738
  };
9706
9739
  }
@@ -9708,14 +9741,14 @@ function parseGlow2(node) {
9708
9741
  const color = parseColorElement(node);
9709
9742
  if (node === void 0 || color === void 0) return void 0;
9710
9743
  return {
9711
- radius: asEmu2(numericAttr(node, "rad") ?? 0),
9744
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0),
9712
9745
  color
9713
9746
  };
9714
9747
  }
9715
9748
  function parseSoftEdge2(node) {
9716
9749
  if (node === void 0) return void 0;
9717
9750
  return {
9718
- radius: asEmu2(numericAttr(node, "rad") ?? 0)
9751
+ radius: asEmu2(numericAttr2(node, "rad") ?? 0)
9719
9752
  };
9720
9753
  }
9721
9754
  function booleanAttr(node, name) {
@@ -9734,7 +9767,7 @@ var SLIDE_LAYOUT_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2
9734
9767
  var SLIDE_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster";
9735
9768
  var THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
9736
9769
  var PRESENTATION_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
9737
- var textDecoder2 = new TextDecoder();
9770
+ var textDecoder3 = new TextDecoder();
9738
9771
  function readPptx(input) {
9739
9772
  const entries = unzipPackage(input);
9740
9773
  const diagnostics = [];
@@ -9885,7 +9918,7 @@ function parsePartRoot(entries, partPath, rootLocalName, diagnostics, includeOrd
9885
9918
  });
9886
9919
  return void 0;
9887
9920
  }
9888
- const xml = textDecoder2.decode(bytes);
9921
+ const xml = textDecoder3.decode(bytes);
9889
9922
  const root = getChild(parseXml(xml), rootLocalName);
9890
9923
  if (root === void 0) {
9891
9924
  diagnostics.push({
@@ -9936,7 +9969,7 @@ function unzipPackage(input) {
9936
9969
  function readContentTypes(entries) {
9937
9970
  const bytes = entries.get(CONTENT_TYPES_PART);
9938
9971
  if (!bytes) return { defaults: [], overrides: [] };
9939
- const root = getChild(parseXml(textDecoder2.decode(bytes)), "Types");
9972
+ const root = getChild(parseXml(textDecoder3.decode(bytes)), "Types");
9940
9973
  const defaults = [];
9941
9974
  for (const node of getChildArray(root, "Default")) {
9942
9975
  const extension = getAttr(node, "Extension");
@@ -9957,7 +9990,7 @@ function readRelationships(entries) {
9957
9990
  const result = [];
9958
9991
  for (const [path, bytes] of entries) {
9959
9992
  if (!isRelationshipPart(path)) continue;
9960
- const root = getChild(parseXml(textDecoder2.decode(bytes)), "Relationships");
9993
+ const root = getChild(parseXml(textDecoder3.decode(bytes)), "Relationships");
9961
9994
  const relationships = [];
9962
9995
  for (const node of getChildArray(root, "Relationship")) {
9963
9996
  const id = getAttr(node, "Id");
@@ -9988,7 +10021,7 @@ function readPresentation(entries, relationships, overrides, diagnostics) {
9988
10021
  );
9989
10022
  }
9990
10023
  const presentationPartPath = asPartPath(presentationPath);
9991
- const root = getChild(parseXml(textDecoder2.decode(bytes)), "presentation");
10024
+ const root = getChild(parseXml(textDecoder3.decode(bytes)), "presentation");
9992
10025
  if (root === void 0) {
9993
10026
  throw new Error(
9994
10027
  `readPptx: part '${presentationPath}' is not a presentation part (missing p:presentation root)`
@@ -10085,8 +10118,8 @@ function stripLeadingSlash(path) {
10085
10118
  return path.startsWith("/") ? path.slice(1) : path;
10086
10119
  }
10087
10120
  var textEncoder = new TextEncoder();
10088
- var textDecoder3 = new TextDecoder();
10089
- var xmlBuilder = new import_fast_xml_parser2.XMLBuilder({
10121
+ var textDecoder4 = new TextDecoder();
10122
+ var xmlBuilder2 = new import_fast_xml_parser3.XMLBuilder({
10090
10123
  ignoreAttributes: false,
10091
10124
  attributeNamePrefix: "@_",
10092
10125
  format: false,