@pptx-studio/validate 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -295,6 +295,22 @@ const RULES = [
295
295
  evidence: "both",
296
296
  title: "`a:gridCol/@w`, `a:tr/@h`, and typed `gridSpan`, `rowSpan`, `hMerge`, `vMerge`",
297
297
  why: "`CT_TableCol/@w` and `CT_TableRow/@h` are required `ST_Coordinate`s, the spans are `xsd:int` and the flags `xsd:boolean`. C7 measured each: a `gridCol` without `@w`, a `tr` without `@h`, `gridSpan=\"2.0\"` and `hMerge=\"on\"` are a repair prompt apiece; PowerPoint saves the column at its minimum width, the row at zero, the span gone and the flag as \"1\". `w=\"108pt\"`, the universal-measure spelling, opens clean and is not this rule."
298
+ },
299
+ {
300
+ id: "V032",
301
+ category: "ids",
302
+ severity: "warning",
303
+ evidence: "measured",
304
+ title: "a table names one of PowerPoint's 74 built-in table styles, or none",
305
+ why: "C8 drew 84 probe packages in three themes. A table whose `a:tableStyleId`, or inline `a:tableStyle`, names one of the 74 built-ins draws that built-in, in any case, whatever `ppt/tableStyles.xml` says about it; any other id - defined in the part or not - draws a 1-pt black grid with no fill, and an id nothing defines is dropped on the next save. The deck opens without a word, which is why this is a warning: the file names one style and PowerPoint draws another."
306
+ },
307
+ {
308
+ id: "V033",
309
+ category: "required",
310
+ severity: "fatal",
311
+ evidence: "both",
312
+ title: "a table style id is a braced GUID, and the table-style part is one PowerPoint keeps",
313
+ why: "`ST_Guid` is a GUID in braces, `CT_TableStyleList/@def` and `CT_TableStyle/@styleId` are required, `b` and `i` are `ST_OnOffStyleType` and a border or fill must hold one. C8 measured each as a repair prompt: an id without braces or with padding, a `tblPr` naming its style twice, a part whose root is not `a:tblStyleLst`, a list without `@def`, a style without `@styleId`, `b=\"yes\"`, an edge with neither `a:ln` nor `a:lnRef`, and an empty `a:fill`. PowerPoint writes the all-zero GUID for the id and empties the part."
298
314
  }
299
315
  ];
300
316
  const BY_ID = new Map(RULES.map((rule) => [rule.id, rule]));
@@ -645,14 +661,7 @@ function readRelsParts(ctx) {
645
661
  return parts;
646
662
  }
647
663
  /**
648
- * Memoised above, because five of the thirty-one rules want this list and each
649
- * would otherwise re-walk every `.rels` part in the package. The parsed trees
650
- * are already cached on the context; what is saved here is the element scan and
651
- * the allocation, which on a three-hundred-slide deck is five passes over a
652
- * thousand relationship parts for one answer that cannot have changed.
653
- *
654
- * Keyed by context rather than by store, so nothing survives one validation run
655
- * into the next.
664
+ * Memoised per context: several rules want every relationship part, and this walks them once.
656
665
  */
657
666
  function scanRelsParts(ctx) {
658
667
  const out = [];
@@ -1169,16 +1178,8 @@ function forEachElement$1(ctx, visit) {
1169
1178
  //#endregion
1170
1179
  //#region src/rules/required.ts
1171
1180
  /**
1172
- * `V013` … `V017`, `V030` and `V031`: children and attributes that are not optional.
1173
- *
1174
- * Every one of these is a `minOccurs` the schema states plainly, and every one
1175
- * is broken the same way: by an editor deleting the last of something. The last
1176
- * paragraph goes and a `p:txBody` is left with no `a:p`; a shape is dragged out
1177
- * of a group and the group's `p:grpSpPr` is dropped with it. That is why these
1178
- * are separate rules from the ordering ones even though a missing child and a
1179
- * misplaced child are both "the sequence is wrong": the messages have to say
1180
- * *add this*, not *move this*, and they have to fire on the parent rather than
1181
- * on a child that is not there to point at.
1181
+ * `V013` … `V017`, `V030`, `V031` and `V033`: children and attributes that are not optional.
1182
+ * Each is a `minOccurs` or a type the schema states, reported on the element that lacks it.
1182
1183
  */
1183
1184
  /** The twelve attributes of `CT_ColorMapping`. All required, no defaults. */
1184
1185
  const CLR_MAP_ATTRIBUTES = [
@@ -1288,6 +1289,82 @@ function v031TableAttributes(ctx) {
1288
1289
  }
1289
1290
  });
1290
1291
  }
1292
+ /** `ST_Guid`, in any case: C8 measured lower case opening clean. */
1293
+ const TABLE_STYLE_GUID$1 = /^\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}$/i;
1294
+ const ON_OFF_STYLES = /* @__PURE__ */ new Set([
1295
+ "on",
1296
+ "off",
1297
+ "def"
1298
+ ]);
1299
+ const TABLE_STYLE_EDGES = /* @__PURE__ */ new Set([
1300
+ "left",
1301
+ "right",
1302
+ "top",
1303
+ "bottom",
1304
+ "insideH",
1305
+ "insideV",
1306
+ "tl2br",
1307
+ "tr2bl"
1308
+ ]);
1309
+ const FILL_PROPERTIES = /* @__PURE__ */ new Set([
1310
+ "noFill",
1311
+ "solidFill",
1312
+ "gradFill",
1313
+ "blipFill",
1314
+ "pattFill",
1315
+ "grpFill"
1316
+ ]);
1317
+ const drawingChildren = (element, local) => childElements(element).filter((child) => child.local === local && namespaceOf(child) === NS.a);
1318
+ /** A table-style id is a braced GUID, and a table style has the parts C8 measured as required. */
1319
+ function v033TableStyles(ctx) {
1320
+ for (const part of ctx.parts()) {
1321
+ if (ctx.contentType(part) !== CONTENT_TYPE.tableStyles) continue;
1322
+ const root = ctx.document(part)?.root;
1323
+ if (root === void 0 || root.local === "tblStyleLst" && namespaceOf(root) === NS.a) continue;
1324
+ ctx.add("V033", elementLocation(part, root), `The table-style part's root is <${root.qname}>, not <a:tblStyleLst>. C8 measured this as a repair prompt.`);
1325
+ }
1326
+ forEachElement(ctx, (part, element) => {
1327
+ if (namespaceOf(element) !== NS.a) return;
1328
+ const report = (at, what) => {
1329
+ ctx.add("V033", elementLocation(part, at), what + " C8 measured this as a repair prompt.");
1330
+ };
1331
+ if (element.local === "tblPr" && drawingChildren(element, "tableStyleId").length > 0 && drawingChildren(element, "tableStyle").length > 0) report(element, "<a:tblPr> names its style twice, by <a:tableStyleId> and <a:tableStyle>.");
1332
+ const guid = (raw, what) => {
1333
+ if (!TABLE_STYLE_GUID$1.test(raw)) report(element, `${what} is "${raw}", which is not a GUID in braces.`);
1334
+ };
1335
+ switch (element.local) {
1336
+ case "tableStyleId":
1337
+ guid(textContent(element), "<a:tableStyleId>");
1338
+ return;
1339
+ case "tableStyle":
1340
+ case "tblStyle": {
1341
+ const id = attributeValue(element, "styleId");
1342
+ if (id === void 0) report(element, `<a:${element.local}> has no @styleId.`);
1343
+ else guid(id, `<a:${element.local}>/@styleId`);
1344
+ return;
1345
+ }
1346
+ case "tblStyleLst":
1347
+ if (attributeValue(element, "def") === void 0) report(element, "<a:tblStyleLst> has no @def.");
1348
+ return;
1349
+ case "tcTxStyle":
1350
+ for (const name of ["b", "i"]) {
1351
+ const raw = attributeValue(element, name);
1352
+ if (raw !== void 0 && !ON_OFF_STYLES.has(raw)) report(element, `<a:tcTxStyle>/@${name} is "${raw}", not on, off or def.`);
1353
+ }
1354
+ return;
1355
+ case "tcBdr":
1356
+ for (const edge of childElements(element)) {
1357
+ if (!TABLE_STYLE_EDGES.has(edge.local) || namespaceOf(edge) !== NS.a) continue;
1358
+ if (drawingChildren(edge, "ln").length + drawingChildren(edge, "lnRef").length === 0) report(edge, `<a:${edge.local}> has neither <a:ln> nor <a:lnRef>.`);
1359
+ }
1360
+ return;
1361
+ case "tcStyle":
1362
+ case "tblBg":
1363
+ for (const fill of drawingChildren(element, "fill")) if (!childElements(fill).some((child) => FILL_PROPERTIES.has(child.local))) report(fill, "<a:fill> holds no fill.");
1364
+ return;
1365
+ }
1366
+ });
1367
+ }
1291
1368
  /** Zero is one and a negative runs to the edge: C7's span-zero and span-negative. */
1292
1369
  function spanOf(raw) {
1293
1370
  if (raw === void 0) return 1;
@@ -1404,22 +1481,93 @@ function forEachElement(ctx, visit) {
1404
1481
  }
1405
1482
  }
1406
1483
  //#endregion
1484
+ //#region src/rules/table-style-ids.ts
1485
+ /**
1486
+ * The GUIDs of PowerPoint's 74 built-in table styles, in its gallery's order.
1487
+ * GENERATED by tools/ground-truth/model/tables/styles/write-tables.ts from
1488
+ * corpus/ground-truth/table-styles.json. Do not edit: rules.test.ts re-derives it.
1489
+ */
1490
+ const BUILTIN_TABLE_STYLE_IDS = [
1491
+ "{2D5ABB26-0587-4C30-8999-92F81FD0307C}",
1492
+ "{3C2FFA5D-87B4-456A-9821-1D502468CF0F}",
1493
+ "{284E427A-3D55-4303-BF80-6455036E1DE7}",
1494
+ "{69C7853C-536D-4A76-A0AE-DD22124D55A5}",
1495
+ "{775DCB02-9BB8-47FD-8907-85C794F793BA}",
1496
+ "{35758FB7-9AC5-4552-8A53-C91805E547FA}",
1497
+ "{08FB837D-C827-4EFA-A057-4D05807E0F7C}",
1498
+ "{5940675A-B579-460E-94D1-54222C63F5DA}",
1499
+ "{D113A9D2-9D6B-4929-AA2D-F23B5EE8CBE7}",
1500
+ "{18603FDC-E32A-4AB5-989C-0864C3EAD2B8}",
1501
+ "{306799F8-075E-4A3A-A7F6-7FBC6576F1A4}",
1502
+ "{E269D01E-BC32-4049-B463-5C60D7B0CCD2}",
1503
+ "{327F97BB-C833-4FB7-BDE5-3F7075034690}",
1504
+ "{638B1855-1B75-4FBE-930C-398BA8C253C6}",
1505
+ "{9D7B26C5-4107-4FEC-AEDC-1716B250A1EF}",
1506
+ "{3B4B98B0-60AC-42C2-AFA5-B58CD77FA1E5}",
1507
+ "{0E3FDE45-AF77-4B5C-9715-49D594BDF05E}",
1508
+ "{C083E6E3-FA7D-4D7B-A595-EF9225AFEA82}",
1509
+ "{D27102A9-8310-4765-A935-A1911B00CA55}",
1510
+ "{5FD0F851-EC5A-4D38-B0AD-8093EC10F338}",
1511
+ "{68D230F3-CF80-4859-8CE7-A43EE81993B5}",
1512
+ "{7E9639D4-E3E2-4D34-9284-5A2195B3D0D7}",
1513
+ "{69012ECD-51FC-41F1-AA8D-1B2483CD663E}",
1514
+ "{72833802-FEF1-4C79-8D5D-14CF1EAF98D9}",
1515
+ "{F2DE63D5-997A-4646-A377-4702673A728D}",
1516
+ "{17292A2E-F333-43FB-9621-5CBBE7FDCDCB}",
1517
+ "{5A111915-BE36-4E01-A7E5-04B1672EAD32}",
1518
+ "{912C8C85-51F0-491E-9774-3900AFEF0FD7}",
1519
+ "{616DA210-FB5B-4158-B5E0-FEB733F419BA}",
1520
+ "{BC89EF96-8CEA-46FF-86C4-4CE0E7609802}",
1521
+ "{5DA37D80-6434-44D0-A028-1B22A696006F}",
1522
+ "{8799B23B-EC83-4686-B30A-512413B5E67A}",
1523
+ "{ED083AE6-46FA-4A59-8FB0-9F97EB10719F}",
1524
+ "{BDBED569-4797-4DF1-A0F4-6AAB3CD982D8}",
1525
+ "{E8B1032C-EA38-4F05-BA0D-38AFFFC7BED3}",
1526
+ "{793D81CF-94F2-401A-BA57-92F5A7B2D0C5}",
1527
+ "{B301B821-A1FF-4177-AEE7-76D212191A09}",
1528
+ "{9DCAF9ED-07DC-4A11-8D7F-57B35C25682E}",
1529
+ "{1FECB4D8-DB02-4DC6-A0A2-4F2EBAE1DC90}",
1530
+ "{1E171933-4619-4E11-9A3F-F7608DF75F80}",
1531
+ "{FABFCF23-3B69-468F-B69F-88F6DE6A72F2}",
1532
+ "{10A1B5D5-9B99-4C35-A422-299274C87663}",
1533
+ "{073A0DAA-6AF3-43AB-8588-CEC1D06C72B9}",
1534
+ "{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}",
1535
+ "{21E4AEA4-8DFA-4A89-87EB-49C32662AFE0}",
1536
+ "{F5AB1C69-6EDB-4FF4-983F-18BD219EF322}",
1537
+ "{00A15C55-8517-42AA-B614-E9B94910E393}",
1538
+ "{7DF18680-E054-41AD-8BC1-D1AEF772440D}",
1539
+ "{93296810-A885-4BE3-A3E7-6D5BEEA58F35}",
1540
+ "{8EC20E35-A176-4012-BC5E-935CFFF8708E}",
1541
+ "{6E25E649-3F16-4E02-A733-19D2CDBF48F0}",
1542
+ "{85BE263C-DBD7-4A20-BB59-AAB30ACAA65A}",
1543
+ "{EB344D84-9AFB-497E-A393-DC336BA19D2E}",
1544
+ "{EB9631B5-78F2-41C9-869B-9F39066F8104}",
1545
+ "{74C1A8A3-306A-4EB7-A6B1-4F7E0EB9C5D6}",
1546
+ "{2A488322-F2BA-4B5B-9748-0D474271808F}",
1547
+ "{D7AC3CCA-C797-4891-BE02-D94E43425B78}",
1548
+ "{69CF1AB2-1976-4502-BF36-3FF5EA218861}",
1549
+ "{8A107856-5554-42FB-B03E-39F5DBC370BA}",
1550
+ "{0505E3EF-67EA-436B-97B2-0124C06EBD24}",
1551
+ "{C4B1156A-380E-4F78-BDF5-A606A8083BF9}",
1552
+ "{22838BEF-8BB2-4498-84A7-C5851F593DF1}",
1553
+ "{16D9F66E-5EB9-4882-86FB-DCBF35E3C3E4}",
1554
+ "{E8034E78-7F5D-4C2E-B375-FC64B27BC917}",
1555
+ "{125E5076-3810-47DD-B79F-674D7AD40C01}",
1556
+ "{37CE84F3-28C3-443E-9E96-99CF82512B78}",
1557
+ "{D03447BB-5D67-496B-8E87-E561075AD55C}",
1558
+ "{E929F9F4-4A8F-4326-A1B4-22849713DDAB}",
1559
+ "{8FD4443E-F989-4FC4-A0C8-D5A2AF1F390B}",
1560
+ "{AF606853-7671-496A-8E4F-DF71F8EC918B}",
1561
+ "{5202B0CA-FC54-4496-8BCA-5EF66A818D29}",
1562
+ "{0660B408-B3CF-4A94-85FC-2B1E0A45F4A2}",
1563
+ "{91EBBBCC-DAD2-459C-BE2E-F6DE35CF9A28}",
1564
+ "{46F890A9-2807-4EBB-B81D-B2AA78EC7F39}"
1565
+ ];
1566
+ //#endregion
1407
1567
  //#region src/rules/id.ts
1408
1568
  /**
1409
- * `V018` … `V021`: four identifier spaces, and never one allocator.
1410
- *
1411
- * A presentation has four kinds of id and they do not share a rule between
1412
- * them. Slide ids start at 256 and stop at 2147483647. Master and layout ids
1413
- * start at 2147483648, and - the part no schema says - come out of **one**
1414
- * counter shared between them. Shape ids are unique inside a part and free to
1415
- * repeat across parts. Placeholder indices are not identifiers at all; they are
1416
- * a join key against another part.
1417
- *
1418
- * Every one of those is a way to break a file that looks like a way to be
1419
- * tidy. Renumbering shape ids to be unique across the deck is the obvious
1420
- * example: it is more consistent, it is what a database would do, and it
1421
- * detaches every `p:custDataLst`, VML `@spid` and animation target that names
1422
- * the old number.
1569
+ * `V018` … `V021` and `V032`: identifier spaces and the ids that name into them. Slide, sheet and
1570
+ * shape ids never share an allocator, and a table style id names one of PowerPoint's built-ins.
1423
1571
  */
1424
1572
  const SLIDE_ID_MIN = 256;
1425
1573
  const SLIDE_ID_MAX = 2147483647;
@@ -1641,6 +1789,19 @@ function v021PlaceholderIndices(ctx) {
1641
1789
  }
1642
1790
  }
1643
1791
  }
1792
+ const BUILTIN_TABLE_STYLES = new Set(BUILTIN_TABLE_STYLE_IDS);
1793
+ /** A well-formed id; V033 reports the rest. */
1794
+ const TABLE_STYLE_GUID = /^\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}$/i;
1795
+ /** A table's `a:tableStyleId`, or its inline `a:tableStyle/@styleId`, names a built-in (C8). */
1796
+ function v032TableStyleIds(ctx) {
1797
+ forEachElement(ctx, (part, element) => {
1798
+ if (namespaceOf(element) !== NS.a) return;
1799
+ const named = element.local === "tableStyleId" ? textContent(element) : element.local === "tableStyle" ? attributeValue(element, "styleId") : void 0;
1800
+ if (named === void 0 || !TABLE_STYLE_GUID.test(named)) return;
1801
+ if (BUILTIN_TABLE_STYLES.has(named.toUpperCase())) return;
1802
+ ctx.add("V032", elementLocation(part, element), `<a:${element.local}> names ${named}, none of PowerPoint's 74 built-in table styles. PowerPoint draws a 1-pt black grid instead, whatever ppt/tableStyles.xml defines (C8).`);
1803
+ });
1804
+ }
1644
1805
  //#endregion
1645
1806
  //#region src/rules/refusal.ts
1646
1807
  /**
@@ -2109,12 +2270,7 @@ function v029TextAndFieldIdentity(ctx) {
2109
2270
  //#endregion
2110
2271
  //#region src/validate.ts
2111
2272
  /**
2112
- * The thirty-one, wired to their implementations.
2113
- *
2114
- * A plain table, so that "is every rule reachable" is a thing a test can ask
2115
- * rather than a thing a reader has to believe. `rules.test.ts` asserts that the
2116
- * keys here are exactly `RULE_IDS` - a rule with a definition and no function
2117
- * would otherwise sit in the table looking enforced.
2273
+ * Every rule wired to its implementation; `rules.test.ts` holds the keys to `RULE_IDS`.
2118
2274
  */
2119
2275
  const IMPLEMENTATIONS = {
2120
2276
  V001: v001ContentTypeCoverage,
@@ -2147,7 +2303,9 @@ const IMPLEMENTATIONS = {
2147
2303
  V028: v028OpaqueContainersUnchanged,
2148
2304
  V029: v029TextAndFieldIdentity,
2149
2305
  V030: v030TableGrid,
2150
- V031: v031TableAttributes
2306
+ V031: v031TableAttributes,
2307
+ V032: v032TableStyleIds,
2308
+ V033: v033TableStyles
2151
2309
  };
2152
2310
  /** Rules that cannot run without the archive bytes. See `Context.archive`. */
2153
2311
  const ARCHIVE_RULES = ["V003"];
@@ -2220,20 +2378,9 @@ function run(ctx, rules) {
2220
2378
  for (const id of rules) IMPLEMENTATIONS[id](ctx);
2221
2379
  }
2222
2380
  /**
2223
- * Decide, for each finding, whether we introduced it.
2224
- *
2225
- * The second pass is the whole of it: run the same rules against the package as
2226
- * it was opened and difference the two sets. A finding in both was already
2227
- * there. See `report.ts` for why that question is the one that decides whether
2228
- * an export is refused, and why answering it by differencing beats answering it
2229
- * per rule.
2230
- *
2231
- * Three properties make it cheap enough to be unconditional in the only case
2232
- * that matters. It runs **only when something fatal was found**, so a clean
2233
- * export - which is nearly all of them - pays nothing. It runs **only the rules
2234
- * that fired**, not all twenty-nine. And it skips the preservation rules, which
2235
- * would be comparing the baseline against itself and would find nothing by
2236
- * construction.
2381
+ * Which findings were already in the package as it was opened: the fired rules run again on
2382
+ * the baseline and the two sets are differenced. Only when something fatal was found, only the
2383
+ * rules that fired, and never the preservation rules. `report.ts` has why.
2237
2384
  */
2238
2385
  function attributeOrigins(ctx, options, running) {
2239
2386
  const baseline = options.baseline;