@openpresentation/opf 0.34.1 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/browser.js +19 -19
- package/dist/{catalog-refs-CoIrOdAw.d.ts → catalog-refs-BgotJhR5.d.ts} +117 -98
- package/dist/{catalog-schemas-FjLRPtjB.d.ts → catalog-schemas-BX-VEc5Q.d.ts} +1 -1
- package/dist/{chunk-MUILZGRY.js → chunk-2GCTKQDD.js} +4 -4
- package/dist/{chunk-LCT5ZV3Q.js → chunk-3KPTVK77.js} +92 -284
- package/dist/{chunk-SR6T4LKI.js → chunk-3ZTKRX7F.js} +4 -6
- package/dist/{chunk-MAFJ5O2D.js → chunk-4UMZDDJG.js} +11 -29
- package/dist/{chunk-NLJFNCZ4.js → chunk-6JHV2K67.js} +6 -6
- package/dist/{chunk-FK5XG742.js → chunk-6VGLE7C5.js} +114 -2
- package/dist/{chunk-AAWHOCXS.js → chunk-7KUUIL7W.js} +8 -8
- package/dist/{chunk-FCSYIBVR.js → chunk-ARPMSD7V.js} +1 -1
- package/dist/{chunk-244OPLAV.js → chunk-GGN3NQDK.js} +1 -1
- package/dist/{chunk-L3MCLD3X.js → chunk-GKUAVSXU.js} +3 -10
- package/dist/{chunk-6PMXVP5G.js → chunk-HORPH6O7.js} +202 -21
- package/dist/{chunk-XLSWZSQS.js → chunk-JQNT37IO.js} +4 -13
- package/dist/{chunk-AEHDXNZX.js → chunk-KNMMEE67.js} +1433 -916
- package/dist/{chunk-CJVKOJ6B.js → chunk-LDLLZQPP.js} +1094 -472
- package/dist/{chunk-HHVQ2SDT.js → chunk-MS2LPR7F.js} +1 -5
- package/dist/{chunk-AGYPRTEC.js → chunk-MVPQEMCP.js} +97 -15
- package/dist/{chunk-2B6GLT2O.js → chunk-NPRNWPP4.js} +1 -1
- package/dist/{chunk-X72WPTST.js → chunk-P2ACZJUL.js} +6 -6
- package/dist/chunk-SEC4IOOS.js +1 -0
- package/dist/{chunk-CQXBGZQP.js → chunk-VMPOCXTE.js} +5 -17
- package/dist/{chunk-ABA2D6X5.js → chunk-ZZWX4W2G.js} +2 -2
- package/dist/{composition-CvtvgBDE.d.ts → composition-BmJfljJl.d.ts} +345 -242
- package/dist/composition.d.ts +2 -2
- package/dist/composition.js +1 -1
- package/dist/{conversion-CyNRlWGw.d.ts → conversion-BbXhlurO.d.ts} +10 -8
- package/dist/conversion-VWCH3NKR.js +25 -0
- package/dist/convert.d.ts +11 -11
- package/dist/convert.js +61 -86
- package/dist/data.d.ts +1 -1
- package/dist/data.js +2 -2
- package/dist/{deck-report-BVlQZ42f.d.ts → deck-report-BYkbL7uT.d.ts} +3 -3
- package/dist/deck.d.ts +6 -6
- package/dist/deck.js +11 -11
- package/dist/diagram-engine-eager.js +1 -1
- package/dist/diagram-engine-lazy.js +1 -1
- package/dist/{diagram-plantuml-XRZ6VAOL.js → diagram-plantuml-GWXGKY7R.js} +1 -1
- package/dist/diff.d.ts +2 -2
- package/dist/diff.js +4 -4
- package/dist/docs.js +40 -40
- package/dist/example-files/technical/assets/alice.png +0 -0
- package/dist/example-files/technical/assets/context-photo.png +0 -0
- package/dist/example-files/technical/assets/cover-image.png +0 -0
- package/dist/example-files/technical/assets/cover.png +0 -0
- package/dist/example-files/technical/assets/diagram.svg +1 -0
- package/dist/example-files/technical/assets/icon.svg +1 -0
- package/dist/example-files/technical/assets/logo-dark.svg +1 -0
- package/dist/example-files/technical/assets/logo-light.svg +1 -0
- package/dist/example-files/technical/assets/logo.svg +1 -0
- package/dist/example-files/technical/assets/primary-logo.svg +1 -0
- package/dist/example-files/technical/assets/product-shot.png +0 -0
- package/dist/example-files/technical/assets/watermark.png +0 -0
- package/dist/example-files/technical/assets/wordmark.svg +1 -0
- package/dist/examples.js +6383 -8169
- package/dist/{finding-l9dlQ2NF.d.ts → finding-mcHslZLA.d.ts} +6 -2
- package/dist/font-policy.d.ts +16 -2
- package/dist/font-policy.js +1 -1
- package/dist/format.js +2 -2
- package/dist/ids.d.ts +2 -2
- package/dist/ids.js +4 -4
- package/dist/index.d.ts +125 -27
- package/dist/index.js +24 -23
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.js +8 -8
- package/dist/node-engine.d.ts +22 -8
- package/dist/node-engine.js +38 -22
- package/dist/{pagination-CZQQYk7L.d.ts → pagination-C0FPjO29.d.ts} +4 -4
- package/dist/pagination.d.ts +3 -3
- package/dist/pagination.js +4 -4
- package/dist/patch.d.ts +4 -4
- package/dist/patch.js +3 -3
- package/dist/precompiled.js +2 -2
- package/dist/{presentation-s9262acV.d.ts → presentation-Dx-kZC8Y.d.ts} +33 -81
- package/dist/repo-readme.js +1 -1
- package/dist/schema-engine-ajv.js +1 -1
- package/dist/schema-engine-precompiled.js +2 -2
- package/dist/schema.d.ts +5 -7
- package/dist/schema.js +3 -3
- package/dist/schemas.js +1 -1
- package/dist/source.d.ts +5 -0
- package/dist/source.js +10 -10
- package/dist/spec/reference/engine-defaults.json +1 -1
- package/dist/spec/reference/engine-vocabularies.json +43 -43
- package/dist/spec/reference/font-policy.json +114 -2
- package/dist/spec/reference/font-policy.schema.json +45 -1
- package/dist/spec/schemas/color-scheme.schema.json +2 -2
- package/dist/spec/schemas/finding.schema.json +2 -1
- package/dist/spec/schemas/icon-set.schema.json +5 -0
- package/dist/spec/schemas/layout.schema.json +27 -85
- package/dist/spec/schemas/opf.schema.json +35 -176
- package/dist/spec/schemas/theme.schema.json +10 -10
- package/dist/symbol-font-encodings.d.ts +2 -2
- package/dist/symbol-font-encodings.js +12695 -12736
- package/dist/types.d.ts +74 -86
- package/dist/{validation-types-CYbsUuZ9.d.ts → validation-types-DKIe1RQW.d.ts} +5 -5
- package/dist/validator.d.ts +5 -7
- package/dist/validator.js +3 -3
- package/dist/yaml.d.ts +1 -1
- package/dist/yaml.js +7 -7
- package/package.json +7 -7
- package/dist/chunk-UJZN2ZH6.js +0 -1
- package/dist/conversion-CSQ5EHD2.js +0 -25
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { original } from './chunk-JBARNYFR.js';
|
|
2
|
-
import { schemas, schemaEntries } from './chunk-
|
|
3
|
-
import {
|
|
2
|
+
import { schemas, schemaEntries } from './chunk-3KPTVK77.js';
|
|
3
|
+
import { SHAPE_BLOCK_KEYS, VARIABLE_KINDS, resolveChartData, chartPaletteForFill, chartSeriesPalette, chartSchemeSeries, chartSlicePlan, CHART_SERIES_MIN_LIGHTNESS_STEP, normalizeHexColor, resolveChartColors, colorContrast, languageOfText, imageBackground, CODE_NOMINAL_SIZE, QUOTE_NOMINAL_SIZE, TABLE_NOMINAL_SIZE, LIST_NOMINAL_SIZE, PROSE_NOMINAL_SIZE, quoteMarksFor, quoteLanguage, emphasisSurface, textInkBox, tableGrid, metricValueColor, timelineTextColor, LOGO_SHAPES, visitContentPayloads, resolveReference, intrinsicImageSize, layoutTable, nearestGridCell, colorTransform, applyColorTransform, resolveColorRef, readingRows, visualReadingOrder, numberingSystemExtension, isSupportedNumberingSystem, plainLanguageTag, supportedNumberingSystems, catalogGroupSource, resolveDesignRecords, resolveFontFamilies, checkCatalogsOption, provenanceOf, unresolvedReference, OPFUnresolvedReferenceError, composeSlide, resolveColorRoles, layoutVariantApplies, resolveCanvasDimensions, resolveSlideVariables, registeredCatalog, embeddedCopy, renamedLayout, renamedLayoutTitlePosition, layoutVariantKind, deckBackgroundIsChosen, LONE_DISPLAY_SIZES, normalizeColorVariant, layoutColorVariant, inlineDatasets, hasBuiltinDependency, isRecord, hasContentVariables, isTemplate, instantiateForValidation, layoutTemplateIssues, REMOVED_DESIGN_KEYS, deckBackgroundIsFixed, resolveScriptFonts, lonePayload, annotationText, isLayoutTemplate, layoutTemplate, statementMessage, messageWords, SHORT_MESSAGE_WORDS, catalogReferenceSites, parseReference, catalogGroupDeclared, pointerPath, unusedDatasets, documentIcons, iconIssue, walkCitationRuns, HALF_STEPPED, MAX_COMPOSITION_DEPTH, isOverlayConnector, connectorAdjustPreset, shapeIssues, pathFor, overlayIssues, datasetDiagnostics, defaultSlideBackground, removedLayoutAuto, renamedLayoutChangesDrawing, catalogRecords, collectCitations, resolveSlideDirection, isGridCell, gridCellSpan, numberingFindings, chartDrawDiagnostics, resolveTableData, resolveChartOptions, chartOptionTarget, codeHighlightLines, relatedName, chartNumberFixesByCell, catalogKinds, representablePositionBox, PositionRangeError, cellsInReadingOrder, isShapeBlock, OPFCompositionError } from './chunk-LDLLZQPP.js';
|
|
4
4
|
import { schemaEngine } from '#schema-engine';
|
|
5
5
|
import { parseTree, printParseErrorCode, getNodePath } from 'jsonc-parser';
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@ var catalogSchemaNames = {
|
|
|
25
25
|
|
|
26
26
|
// src/annotation-validation.ts
|
|
27
27
|
var issue = (path, message, params2) => ({ path, message, keyword: "opf", schemaPath: "#/x-opf-semantics", params: params2 });
|
|
28
|
-
var pointer = (dotted2) => `/${dotted2.split(".").map((
|
|
28
|
+
var pointer = (dotted2) => `/${dotted2.split(".").map((part2) => part2.replaceAll("~", "~0").replaceAll("/", "~1")).join("/")}`;
|
|
29
29
|
function markedRuns(value) {
|
|
30
30
|
if (!Array.isArray(value)) return [];
|
|
31
31
|
return value.flatMap((run, index) => isRecord(run) && (run.cite !== void 0 || run.footnote !== void 0) ? [index] : []);
|
|
@@ -89,10 +89,116 @@ function unusedReferenceWarnings(value) {
|
|
|
89
89
|
return value.references.flatMap((reference, index) => isRecord(reference) && typeof reference.id === "string" && unused.includes(reference.id) ? [issue(`/references/${index}`, `reference '${reference.id}' is never cited; cite it with a run's cite field or remove it`, { code: "unused-reference", id: reference.id })] : []);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
// src/finding-text-util.ts
|
|
93
|
+
var WORDS = { object: "an object", array: "a list", string: "text", number: "a number", integer: "a whole number", boolean: "true or false", null: "null" };
|
|
94
|
+
var KIND_WORDS = { layouts: "layout", themes: "theme", colorSchemes: "color scheme", fontSchemes: "font scheme", narratives: "narrative", audiences: "audience", purposes: "purpose", tones: "tone", languages: "language" };
|
|
95
|
+
var KIND_EXAMPLES = { layouts: "`pillars` or `acme:hero`", themes: "`minimal` or `acme:bold`", colorSchemes: "`boost` or `acme:night`", fontSchemes: "`aptos` or `acme:brand`", narratives: "`classic-story`", audiences: "`board`", purposes: "`inform`", tones: "`formal`" };
|
|
96
|
+
var ALIASES = { middle: "center", centre: "center", centered: "center", centred: "center", justify: "start", left: "start", right: "end", col: "column", cols: "column", pic: "image", picture: "image", photo: "image", paragraph: "text", bullets: "list", bullet: "list" };
|
|
97
|
+
function segmentsOf(path) {
|
|
98
|
+
if (Array.isArray(path)) return path.map(String);
|
|
99
|
+
if (typeof path !== "string" || path === "" || path === "/") return [];
|
|
100
|
+
return path.replace(/^\//, "").split("/").map((part2) => part2.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
101
|
+
}
|
|
102
|
+
function pointerOf(segments) {
|
|
103
|
+
return segments.map((part2) => `/${String(part2).replaceAll("~", "~0").replaceAll("/", "~1")}`).join("");
|
|
104
|
+
}
|
|
105
|
+
var code = (value) => `\`${String(value)}\``;
|
|
106
|
+
var isIndex = (segment) => /^\d+$/.test(String(segment));
|
|
107
|
+
function cap(text2) {
|
|
108
|
+
return text2.startsWith("`") ? text2 : text2.charAt(0).toUpperCase() + text2.slice(1);
|
|
109
|
+
}
|
|
110
|
+
function fieldLabel(segments) {
|
|
111
|
+
if (!segments.length) return "the deck";
|
|
112
|
+
const last = segments[segments.length - 1];
|
|
113
|
+
if (isIndex(last)) {
|
|
114
|
+
const owner = [...segments].reverse().find((segment) => !isIndex(segment));
|
|
115
|
+
return owner === "slides" ? `slide ${Number(last) + 1}` : owner ? `${owner} entry ${Number(last) + 1}` : `entry ${Number(last) + 1}`;
|
|
116
|
+
}
|
|
117
|
+
return code(last);
|
|
118
|
+
}
|
|
119
|
+
function placeWords(segments) {
|
|
120
|
+
if (!segments.length) return "at the top level";
|
|
121
|
+
const slide = segments[0] === "slides" && segments.length >= 2 && isIndex(segments[1]) ? Number(segments[1]) + 1 : void 0;
|
|
122
|
+
if (slide !== void 0 && segments.length === 2) return `in slide ${slide}`;
|
|
123
|
+
const last = segments[segments.length - 1];
|
|
124
|
+
const inner = isIndex(last) ? fieldLabel(segments) : code(last);
|
|
125
|
+
return slide !== void 0 ? `in ${inner} of slide ${slide}` : `in ${inner}`;
|
|
126
|
+
}
|
|
127
|
+
function containerName(segments) {
|
|
128
|
+
if (!segments.length) return "the deck";
|
|
129
|
+
if (segments.length === 2 && segments[0] === "slides" && isIndex(segments[1])) return "a slide";
|
|
130
|
+
const last = segments[segments.length - 1];
|
|
131
|
+
return isIndex(last) ? fieldLabel(segments) : code(last);
|
|
132
|
+
}
|
|
133
|
+
function describeValue(value) {
|
|
134
|
+
if (value === void 0) return "missing";
|
|
135
|
+
if (value === null) return "null";
|
|
136
|
+
if (Array.isArray(value)) return value.length ? `a list of ${value.length}` : "an empty list";
|
|
137
|
+
if (typeof value === "object") return "an object";
|
|
138
|
+
if (typeof value === "string") return value === "" ? "empty" : code(value.length > 30 ? `${value.slice(0, 29)}\u2026` : value);
|
|
139
|
+
return `${typeof value === "number" ? "a number" : "true or false"} (${code(String(value))})`;
|
|
140
|
+
}
|
|
141
|
+
function describeKind(value) {
|
|
142
|
+
if (typeof value === "string") return value === "" ? "empty text" : `text (${describeValue(value)})`;
|
|
143
|
+
return describeValue(value);
|
|
144
|
+
}
|
|
145
|
+
function typeWords(type) {
|
|
146
|
+
const list = (Array.isArray(type) ? type : [type]).filter(Boolean).map((entry2) => WORDS[String(entry2)] ?? String(entry2));
|
|
147
|
+
return [...new Set(list)].join(" or ") || "a different kind of value";
|
|
148
|
+
}
|
|
149
|
+
function distance(a, b) {
|
|
150
|
+
const x = a.toLowerCase();
|
|
151
|
+
const y = b.toLowerCase();
|
|
152
|
+
if (x === y) return 0;
|
|
153
|
+
const row = Array.from({ length: y.length + 1 }, (_, index) => index);
|
|
154
|
+
for (let i = 1; i <= x.length; i++) {
|
|
155
|
+
let previous = row[0];
|
|
156
|
+
row[0] = i;
|
|
157
|
+
for (let j = 1; j <= y.length; j++) {
|
|
158
|
+
const keep3 = row[j];
|
|
159
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (x[i - 1] === y[j - 1] ? 0 : 1));
|
|
160
|
+
previous = keep3;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return row[y.length];
|
|
164
|
+
}
|
|
165
|
+
function nearest(value, candidates, limit = 5) {
|
|
166
|
+
const text2 = String(value ?? "");
|
|
167
|
+
const alias = ALIASES[text2.toLowerCase()];
|
|
168
|
+
const ranked = candidates.map((candidate) => ({ candidate, score: String(candidate).toLowerCase() === alias ? 0 : distance(text2, String(candidate)) }));
|
|
169
|
+
ranked.sort((a, b) => a.score - b.score);
|
|
170
|
+
const close = ranked.filter((entry2) => entry2.score <= Math.max(2, Math.floor(text2.length / 4))).map((entry2) => entry2.candidate);
|
|
171
|
+
return { close: close.slice(0, limit), all: ranked.map((entry2) => entry2.candidate) };
|
|
172
|
+
}
|
|
173
|
+
function valueList(values, max = 5) {
|
|
174
|
+
const list = values.map((value) => typeof value === "string" ? value : JSON.stringify(value));
|
|
175
|
+
if (list.length <= max) return list.length > 1 ? `${list.slice(0, -1).join(", ")} or ${list.at(-1)}` : list.join("");
|
|
176
|
+
return `one of ${list.length} values (${list.slice(0, 3).join(", ")}, \u2026)`;
|
|
177
|
+
}
|
|
178
|
+
var firstSentence = (text2) => /^.*?[.!?](?=\s|$)/.exec(String(text2 ?? "").replace(/\s+/g, " ").trim())?.[0] ?? "";
|
|
179
|
+
function asNext(text2) {
|
|
180
|
+
const trimmed = text2.trim();
|
|
181
|
+
return /^[A-Z][a-z]/.test(trimmed) ? trimmed.charAt(0).toLowerCase() + trimmed.slice(1) : trimmed;
|
|
182
|
+
}
|
|
183
|
+
var isRecord2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
184
|
+
function readAt(document, segments) {
|
|
185
|
+
let value = document;
|
|
186
|
+
for (const segment of segments) {
|
|
187
|
+
if (Array.isArray(value)) value = value[Number(segment)];
|
|
188
|
+
else if (isRecord2(value)) value = value[segment];
|
|
189
|
+
else return void 0;
|
|
190
|
+
}
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
|
|
92
194
|
// src/union-errors.ts
|
|
195
|
+
function respellings(typed, declared) {
|
|
196
|
+
const limit = typed.length <= 3 ? 1 : 2;
|
|
197
|
+
return declared.map((name) => ({ name, away: distance(typed, name) })).filter(({ name, away }) => name !== typed && away <= limit && relatedName(typed, name)).sort((a, b) => a.away - b.away || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)).map(({ name }) => name);
|
|
198
|
+
}
|
|
93
199
|
var isUnion = (error) => (error.keyword === "oneOf" || error.keyword === "anyOf") && Array.isArray(error.schema);
|
|
94
200
|
var key = (error) => `${error.instancePath}\0${error.keyword}\0${error.message}\0${JSON.stringify(error.params)}`;
|
|
95
|
-
var depth = (
|
|
201
|
+
var depth = (pointer5) => pointer5 ? pointer5.split("/").length - 1 : 0;
|
|
96
202
|
function branchLabel(branch, index) {
|
|
97
203
|
if (typeof branch.$ref === "string") return branch.$ref.slice(branch.$ref.lastIndexOf("/") + 1);
|
|
98
204
|
if (typeof branch.type === "string") return branch.type;
|
|
@@ -139,10 +245,10 @@ function analyze(engine, rootId, union) {
|
|
|
139
245
|
if (!validate2) return void 0;
|
|
140
246
|
if (validate2(union.data) === true) return void 0;
|
|
141
247
|
const raw = (validate2.errors ?? []).map((error) => ({ ...error, instancePath: union.instancePath + error.instancePath }));
|
|
142
|
-
results.push({ label: branchLabel(branch, index), errors: raw });
|
|
248
|
+
results.push({ label: branchLabel(branch, index), errors: raw, branch });
|
|
143
249
|
}
|
|
144
250
|
const span = /* @__PURE__ */ new Set([key(union), ...results.flatMap((result) => result.errors.map(key))]);
|
|
145
|
-
const reduced = results.map((result) => ({ label: result.label, errors: bestMatchErrors(engine, rootId, result.errors) }));
|
|
251
|
+
const reduced = results.map((result) => ({ label: result.label, branch: result.branch, errors: bestMatchErrors(engine, rootId, result.errors) }));
|
|
146
252
|
const mismatch = (error) => {
|
|
147
253
|
const level = depth(error.instancePath) - base;
|
|
148
254
|
return level === 0 && (error.keyword === "type" || isUnion(error)) || level === 1 && error.keyword === "const";
|
|
@@ -159,7 +265,22 @@ function analyze(engine, rootId, union) {
|
|
|
159
265
|
const types = [...new Set(rootTypes.flatMap((list) => list.flatMap((error) => [error.params.type].flat())))].map(String);
|
|
160
266
|
return { union, span, replacement: [{ ...union, message: plain ? `must be ${named(types)}` : union.message, alternatives: summary(reduced) }] };
|
|
161
267
|
}
|
|
162
|
-
|
|
268
|
+
let top = ranked.filter((result) => reach(result.errors) === reach(lead.errors));
|
|
269
|
+
const keys = isObject(union.data) ? Object.keys(union.data) : [];
|
|
270
|
+
const rejected = (errors) => new Set(errors.filter((error) => error.keyword === "additionalProperties" && error.instancePath === union.instancePath).map((error) => String(error.params.additionalProperty)));
|
|
271
|
+
const accepted = (errors) => {
|
|
272
|
+
const unknown = rejected(errors);
|
|
273
|
+
return keys.filter((name) => !unknown.has(name)).length;
|
|
274
|
+
};
|
|
275
|
+
const most = Math.max(...top.map((result) => accepted(result.errors)));
|
|
276
|
+
if (keys.length && most > 0) top = top.filter((result) => accepted(result.errors) === most);
|
|
277
|
+
const declared = (errors) => errors.flatMap((error) => error.keyword === "additionalProperties" && error.instancePath === union.instancePath && isObject(error.parentSchema) && isObject(error.parentSchema.properties) ? Object.keys(error.parentSchema.properties) : []);
|
|
278
|
+
if (keys.length && most === 0 && top.every((result) => !keys.some((name) => respellings(name, declared(result.errors)).length))) {
|
|
279
|
+
const belongsTo = homesOf(rootId, keys);
|
|
280
|
+
const params2 = { properties: keys, ...belongsTo.length ? { belongsTo } : {} };
|
|
281
|
+
const alternatives = reduced.map((result) => formOf(result.label, result.branch, rootId));
|
|
282
|
+
return { union, span, replacement: [{ ...union, params: { ...union.params, ...params2 }, message: foreignMessage(params2), alternatives }] };
|
|
283
|
+
}
|
|
163
284
|
const others = reduced.filter((result) => !top.includes(result));
|
|
164
285
|
const single = (result) => {
|
|
165
286
|
const only = result.errors[0];
|
|
@@ -179,6 +300,86 @@ function analyze(engine, rootId, union) {
|
|
|
179
300
|
});
|
|
180
301
|
return { union, span, replacement: chosen };
|
|
181
302
|
}
|
|
303
|
+
var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
304
|
+
var quoted = (names2, joiner) => {
|
|
305
|
+
const list = names2.map((name) => JSON.stringify(name));
|
|
306
|
+
return list.length > 1 ? `${list.slice(0, -1).join(", ")} ${joiner} ${list.at(-1)}` : list[0] ?? "";
|
|
307
|
+
};
|
|
308
|
+
function resolved(node, rootId) {
|
|
309
|
+
if (!isObject(node)) return void 0;
|
|
310
|
+
if (typeof node.$ref !== "string") return node;
|
|
311
|
+
const [base, fragment = ""] = node.$ref.split("#");
|
|
312
|
+
const root = schemaEntries.find((entry2) => entry2.schema.$id === (base || rootId))?.schema;
|
|
313
|
+
let target = root;
|
|
314
|
+
for (const token of fragment.split("/").slice(1)) target = isObject(target) ? target[token.replaceAll("~1", "/").replaceAll("~0", "~")] : void 0;
|
|
315
|
+
return isObject(target) ? resolved(target, rootId) : void 0;
|
|
316
|
+
}
|
|
317
|
+
function fieldsOf(schema) {
|
|
318
|
+
if (!isObject(schema.properties)) return void 0;
|
|
319
|
+
const required = Array.isArray(schema.required) ? schema.required.map(String) : [];
|
|
320
|
+
const names2 = [.../* @__PURE__ */ new Set([...required, ...Object.keys(schema.properties)])];
|
|
321
|
+
return `{ ${names2.slice(0, 4).join(", ")}${names2.length > 4 ? ", \u2026" : ""} }`;
|
|
322
|
+
}
|
|
323
|
+
function formOf(label, branch, rootId) {
|
|
324
|
+
const schema = resolved(branch, rootId);
|
|
325
|
+
const fields2 = schema ? fieldsOf(schema) : void 0;
|
|
326
|
+
if (fields2) return `${label}: ${fields2}`;
|
|
327
|
+
const items = schema?.type === "array" ? resolved(schema.items, rootId) : void 0;
|
|
328
|
+
const item = isObject(schema?.items) && typeof schema.items.$ref === "string" ? branchLabel(schema.items, 0) : typeof items?.type === "string" ? items.type : void 0;
|
|
329
|
+
return item ? `${label}: a list of ${item}` : label;
|
|
330
|
+
}
|
|
331
|
+
var homes = /* @__PURE__ */ new Map();
|
|
332
|
+
function homesOf(rootId, keys) {
|
|
333
|
+
let forms = homes.get(rootId);
|
|
334
|
+
if (!forms) {
|
|
335
|
+
forms = [];
|
|
336
|
+
const payload = resolved({ $ref: "#/$defs/ContentPayload" }, rootId);
|
|
337
|
+
const properties = isObject(payload?.properties) ? payload.properties : {};
|
|
338
|
+
const kinds = isObject(properties.type) && Array.isArray(properties.type.enum) ? properties.type.enum.map(String) : [];
|
|
339
|
+
for (const kind of kinds) {
|
|
340
|
+
const field = resolved(properties[kind], rootId);
|
|
341
|
+
const branches = [field, ...Array.isArray(field?.oneOf) ? field.oneOf : [], ...Array.isArray(field?.anyOf) ? field.anyOf : []];
|
|
342
|
+
for (const branch of branches) {
|
|
343
|
+
const schema = resolved(branch, rootId);
|
|
344
|
+
if (schema && isObject(schema.properties)) forms.push({ kind, properties: Object.keys(schema.properties), required: Array.isArray(schema.required) ? schema.required.map(String) : [] });
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
homes.set(rootId, forms);
|
|
348
|
+
}
|
|
349
|
+
return [...new Set(forms.filter((form) => keys.every((name) => form.properties.includes(name)) && form.required.every((name) => keys.includes(name))).map((form) => form.kind))];
|
|
350
|
+
}
|
|
351
|
+
function foreignMessage(params2) {
|
|
352
|
+
const home = params2.belongsTo?.length ? ` (${params2.properties.length > 1 ? "those are fields" : "that is a field"} of ${quoted(params2.belongsTo, "or")})` : "";
|
|
353
|
+
const indexes = (params2.alsoAt ?? []).map((path) => path.slice(path.lastIndexOf("/") + 1));
|
|
354
|
+
const also = indexes.length ? `; the same at index${indexes.length > 1 ? "es" : ""} ${indexes.length > 1 ? `${indexes.slice(0, -1).join(", ")} and ${indexes.at(-1)}` : indexes[0]} of this list` : "";
|
|
355
|
+
return `none of the forms accepted here has ${quoted(params2.properties, "or")}${home}${also}`;
|
|
356
|
+
}
|
|
357
|
+
var isForeign = (error) => isUnion(error) && Array.isArray(error.params.properties);
|
|
358
|
+
function collapseRepeats(errors) {
|
|
359
|
+
const first = /* @__PURE__ */ new Map();
|
|
360
|
+
const result = [];
|
|
361
|
+
for (const error of errors) {
|
|
362
|
+
const entry2 = isForeign(error) ? /^(.*)\/\d+$/.exec(error.instancePath) : null;
|
|
363
|
+
if (!entry2) {
|
|
364
|
+
result.push(error);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const params2 = error.params;
|
|
368
|
+
const group = `${entry2[1]}\0${error.schemaPath}\0${JSON.stringify(params2.belongsTo ?? [])}`;
|
|
369
|
+
const lead = first.get(group);
|
|
370
|
+
if (!lead) {
|
|
371
|
+
const copy = { ...error, params: { ...error.params } };
|
|
372
|
+
first.set(group, copy);
|
|
373
|
+
result.push(copy);
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const merged = lead.params;
|
|
377
|
+
merged.properties = [.../* @__PURE__ */ new Set([...merged.properties, ...params2.properties])];
|
|
378
|
+
merged.alsoAt = [...merged.alsoAt ?? [], error.instancePath];
|
|
379
|
+
lead.message = foreignMessage(merged);
|
|
380
|
+
}
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
182
383
|
|
|
183
384
|
// src/validation-definitions.ts
|
|
184
385
|
var schemaLocations;
|
|
@@ -222,7 +423,6 @@ function validationDefinition(issue2) {
|
|
|
222
423
|
|
|
223
424
|
// src/schema-check.ts
|
|
224
425
|
var schemaNameByCatalogKind = catalogSchemaNames;
|
|
225
|
-
var promotedRegionKeySet = new Set(promotedRegionKeys);
|
|
226
426
|
var rootPayloadFields = [
|
|
227
427
|
"type",
|
|
228
428
|
"text",
|
|
@@ -298,22 +498,6 @@ var captionableKinds = /* @__PURE__ */ new Set(["image", "chart", "table", "vide
|
|
|
298
498
|
var imageOptionFields = ["fit", "focus", "aspectRatio", "shape", "adjust", "stroke", "opacity", "recolor", "overlay", "placement", "portrait"];
|
|
299
499
|
var shapeImageFields = /* @__PURE__ */ new Set(["aspectRatio", "shape", "adjust", "stroke", "opacity"]);
|
|
300
500
|
var shapeOptionFields = SHAPE_BLOCK_KEYS.filter((field) => field !== "path");
|
|
301
|
-
var columnSpans = {
|
|
302
|
-
start: [0],
|
|
303
|
-
center: [1],
|
|
304
|
-
end: [2],
|
|
305
|
-
"start+center": [0, 1],
|
|
306
|
-
"center+end": [1, 2],
|
|
307
|
-
"start+center+end": [0, 1, 2]
|
|
308
|
-
};
|
|
309
|
-
var rowSpans = {
|
|
310
|
-
top: [0],
|
|
311
|
-
middle: [1],
|
|
312
|
-
bottom: [2],
|
|
313
|
-
"top+middle": [0, 1],
|
|
314
|
-
"middle+bottom": [1, 2],
|
|
315
|
-
"top+middle+bottom": [0, 1, 2]
|
|
316
|
-
};
|
|
317
501
|
function isSchemaName(value) {
|
|
318
502
|
return typeof value === "string" && hasOwn(schemas, value);
|
|
319
503
|
}
|
|
@@ -421,7 +605,7 @@ function validateContentPayload(value, path, options2 = {}) {
|
|
|
421
605
|
for (const field of shapeOptionFields) if (hasOwn(value, field) && !(field === "hidden" && options2.slideRoot)) issues.push(semanticIssue(pathFor(path, field), `${field} is only valid on a shape block; ${reason}`, { code: "shape-option-unsupported-payload", field, ...params2 }));
|
|
422
606
|
};
|
|
423
607
|
if (hasOwn(value, "placement") && !options2.topLevel && !hasBlocks && explicitType !== "group" && inferredKinds(value).includes("image")) {
|
|
424
|
-
issues.push(semanticIssue(pathFor(path, "placement"), "placement is only valid on a top-level block (slides.N.blocks.I); a block inside a group
|
|
608
|
+
issues.push(semanticIssue(pathFor(path, "placement"), "placement is only valid on a top-level block (slides.N.blocks.I); a block inside a group cannot bleed to a slide edge", { code: "image-placement-invalid" }));
|
|
425
609
|
}
|
|
426
610
|
if (hasBlocks || explicitType === "group") {
|
|
427
611
|
if (hasOwn(value, "caption")) issues.push(captionIssue("a group cannot carry one"));
|
|
@@ -523,64 +707,34 @@ function validateContentPayload(value, path, options2 = {}) {
|
|
|
523
707
|
}
|
|
524
708
|
return issues;
|
|
525
709
|
}
|
|
526
|
-
function
|
|
527
|
-
|
|
528
|
-
const [rowPart, columnPart] = key3.split(":");
|
|
529
|
-
if (!rowPart || !columnPart) return void 0;
|
|
530
|
-
const rows = rowSpans[rowPart];
|
|
531
|
-
const columns = columnSpans[columnPart];
|
|
532
|
-
return rows && columns ? { rows, columns } : void 0;
|
|
533
|
-
}
|
|
534
|
-
if (key3 in columnSpans) {
|
|
535
|
-
const columns = columnSpans[key3];
|
|
536
|
-
return columns ? { rows: [0, 1, 2], columns } : void 0;
|
|
537
|
-
}
|
|
538
|
-
if (key3 in rowSpans) {
|
|
539
|
-
const rows = rowSpans[key3];
|
|
540
|
-
return rows ? { rows, columns: [0, 1, 2] } : void 0;
|
|
541
|
-
}
|
|
542
|
-
return void 0;
|
|
710
|
+
function validateSlideRoot(slide, slidePath, canvas) {
|
|
711
|
+
return presentFields(slide, rootPayloadFields).length > 0 ? validateContentPayload(slide, slidePath, { slideRoot: true, ...canvas ? { canvas } : {} }) : [];
|
|
543
712
|
}
|
|
544
713
|
function intersects(left, right) {
|
|
545
714
|
return left.some((value) => right.includes(value));
|
|
546
715
|
}
|
|
547
|
-
function
|
|
548
|
-
return intersects(left.rows, right.rows) && intersects(left.columns, right.columns);
|
|
549
|
-
}
|
|
550
|
-
function validateSlideRegions(slide, slidePath, canvas) {
|
|
716
|
+
function validateSlideCells(slide, slidePath) {
|
|
551
717
|
const issues = [];
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
issues.push(
|
|
562
|
-
}
|
|
563
|
-
for (const
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const leftRegion = slideRegion(leftKey);
|
|
573
|
-
if (!leftRegion) continue;
|
|
574
|
-
for (let rightIndex = leftIndex + 1; rightIndex < regionKeys.length; rightIndex += 1) {
|
|
575
|
-
const rightKey = regionKeys[rightIndex];
|
|
576
|
-
if (!rightKey) continue;
|
|
577
|
-
const rightRegion = slideRegion(rightKey);
|
|
578
|
-
if (!rightRegion) continue;
|
|
579
|
-
if (regionsOverlap(leftRegion, rightRegion)) {
|
|
580
|
-
issues.push(semanticIssue(slidePath, `promoted region keys '${leftKey}' and '${rightKey}' overlap`, {
|
|
581
|
-
regionKeys: [leftKey, rightKey]
|
|
582
|
-
}));
|
|
583
|
-
}
|
|
718
|
+
if (slide.layout !== void 0 || !Array.isArray(slide.blocks)) return issues;
|
|
719
|
+
const blocks = slide.blocks.flatMap((block, index) => isRecord(block) ? [{ block, index }] : []);
|
|
720
|
+
const placed = blocks.filter(({ block }) => isGridCell(block.region));
|
|
721
|
+
if (!placed.length) return issues;
|
|
722
|
+
const cells = [...new Set(placed.map(({ block }) => String(block.region)))];
|
|
723
|
+
for (const { block, index } of blocks) {
|
|
724
|
+
if (isGridCell(block.region) || typeof block.region === "string" && /[:+]/.test(block.region)) continue;
|
|
725
|
+
const path = pathFor(pathFor(slidePath, "blocks"), String(index));
|
|
726
|
+
const meant = typeof block.region === "string" ? nearestGridCell(block.region)?.cell : void 0;
|
|
727
|
+
issues.push(semanticIssue(typeof block.region === "string" ? pathFor(path, "region") : path, typeof block.region === "string" ? `a slide places every block in a cell of its grid or none: '${block.region}' is no cell (${meant ? `write '${meant}': layout words follow the deck's direction` : `write one of the cells the other blocks use, such as '${cells[0]}', or give the slide a layout`})` : `a slide places every block in a cell of its grid or none: give this block a 'region' cell too (the other blocks use ${cells.map((cell) => `'${cell}'`).join(", ")})`, { cells }));
|
|
728
|
+
}
|
|
729
|
+
for (const { block, index } of placed) {
|
|
730
|
+
if (hasOwn(block, "placement")) issues.push(semanticIssue(pathFor(pathFor(pathFor(slidePath, "blocks"), String(index)), "placement"), "placement is only valid on a top-level block of a slide whose blocks are not in cells; a block in a cell of the slide's grid cannot bleed to a slide edge", { code: "image-placement-invalid" }));
|
|
731
|
+
}
|
|
732
|
+
for (let left = 0; left < cells.length; left += 1) {
|
|
733
|
+
for (let right = left + 1; right < cells.length; right += 1) {
|
|
734
|
+
const a = gridCellSpan(cells[left]), b = gridCellSpan(cells[right]);
|
|
735
|
+
if (!a || !b || !intersects(a.rows, b.rows) || !intersects(a.columns, b.columns)) continue;
|
|
736
|
+
const at2 = placed.find(({ block }) => block.region === cells[right]);
|
|
737
|
+
issues.push(semanticIssue(pathFor(pathFor(pathFor(slidePath, "blocks"), String(at2.index)), "region"), `cells '${cells[left]}' and '${cells[right]}' overlap`, { cells: [cells[left], cells[right]] }));
|
|
584
738
|
}
|
|
585
739
|
}
|
|
586
740
|
return issues;
|
|
@@ -638,7 +792,7 @@ function presentationSemanticIssues(value, catalogs) {
|
|
|
638
792
|
const canvas = deckCanvas();
|
|
639
793
|
return canvas ? { ...canvas, rtl: resolveSlideDirection(value, index) === "rtl" } : void 0;
|
|
640
794
|
};
|
|
641
|
-
const hasCallouts = (node, depth2 = 0) => isRecord(node) && depth2 <= 34 && Object.entries(node).some(([key3, entry2]) => key3 === "callouts" ? Array.isArray(entry2) && entry2.length > 0 : key3 === "image" || key3 === "blocks"
|
|
795
|
+
const hasCallouts = (node, depth2 = 0) => isRecord(node) && depth2 <= 34 && Object.entries(node).some(([key3, entry2]) => key3 === "callouts" ? Array.isArray(entry2) && entry2.length > 0 : key3 === "image" || key3 === "blocks" ? Array.isArray(entry2) ? entry2.some((item) => hasCallouts(item, depth2 + 1)) : hasCallouts(entry2, depth2 + 1) : false);
|
|
642
796
|
value.slides.forEach((slide, index) => {
|
|
643
797
|
if (isRecord(slide)) {
|
|
644
798
|
const slidePath = `/slides/${index}`;
|
|
@@ -666,7 +820,7 @@ function presentationSemanticIssues(value, catalogs) {
|
|
|
666
820
|
});
|
|
667
821
|
for (const issue2 of overlayIssues(slide, slidePath, value, canvasForOverlays(slide, index))) issues.push(semanticIssue(issue2.path, issue2.message, { ...issue2.code ? { code: issue2.code } : {}, ...issue2.params }));
|
|
668
822
|
issues.push(...enUkIssues(slide.language, `${slidePath}/language`));
|
|
669
|
-
issues.push(...
|
|
823
|
+
issues.push(...validateSlideRoot(slide, slidePath, hasCallouts(slide) ? deckCanvas() : void 0), ...validateSlideCells(slide, slidePath));
|
|
670
824
|
const payloadTableIssues = (payload, path) => {
|
|
671
825
|
if (isRecord(payload.table)) for (const issue2 of tableGrid(payload.table).issues) issues.push(semanticIssue(pathFor(path, "table") + issue2.path.slice(5).replaceAll(".", "/"), issue2.message));
|
|
672
826
|
};
|
|
@@ -785,9 +939,9 @@ function dataIssues(value) {
|
|
|
785
939
|
add(datasetDiagnostics(value));
|
|
786
940
|
const payload = (node, path) => {
|
|
787
941
|
if (isRecord(node.chart)) {
|
|
788
|
-
const
|
|
789
|
-
add(
|
|
790
|
-
add(chartDrawDiagnostics(node.chart,
|
|
942
|
+
const resolved2 = resolveChartData(node.chart, value, { path: pathFor(path, "chart") });
|
|
943
|
+
add(resolved2.diagnostics);
|
|
944
|
+
add(chartDrawDiagnostics(node.chart, resolved2, pathFor(path, "chart"), { language: typeof value.language === "string" ? value.language : void 0 }));
|
|
791
945
|
}
|
|
792
946
|
if (isRecord(node.table)) add(resolveTableData(node.table, value, { path: pathFor(path, "table") }).diagnostics);
|
|
793
947
|
};
|
|
@@ -978,11 +1132,6 @@ function presentationReferenceWarnings(value, catalogs) {
|
|
|
978
1132
|
};
|
|
979
1133
|
highlightWarnings(slide, slidePath);
|
|
980
1134
|
visitContentPayloads(slide, slidePath, highlightWarnings);
|
|
981
|
-
for (const key3 of Object.keys(slide)) {
|
|
982
|
-
if (promotedRegionKeySet.has(key3)) {
|
|
983
|
-
issues.push(...chartTypeWarnings(slide[key3], pathFor(slidePath, key3)));
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
1135
|
});
|
|
987
1136
|
return issues;
|
|
988
1137
|
}
|
|
@@ -997,7 +1146,6 @@ function contentDepthIssues(value) {
|
|
|
997
1146
|
if (Array.isArray(slide.blocks)) slide.blocks.forEach((block, i) => {
|
|
998
1147
|
stack.push({ value: block, path: `/slides/${index}/blocks/${i}`, depth: 0, ancestors: [] });
|
|
999
1148
|
});
|
|
1000
|
-
for (const key3 of promotedRegionKeys) if (hasOwn(slide, key3)) stack.push({ value: slide[key3], path: `/slides/${index}/${key3}`, depth: 0, ancestors: [] });
|
|
1001
1149
|
});
|
|
1002
1150
|
while (stack.length) {
|
|
1003
1151
|
const entry2 = stack.pop();
|
|
@@ -1048,9 +1196,9 @@ function typedVariableErrors(errors, value) {
|
|
|
1048
1196
|
}
|
|
1049
1197
|
return kept;
|
|
1050
1198
|
}
|
|
1051
|
-
function pointerValue(root,
|
|
1199
|
+
function pointerValue(root, pointer5) {
|
|
1052
1200
|
let current = root;
|
|
1053
|
-
for (const token of
|
|
1201
|
+
for (const token of pointer5.split("/").slice(1)) {
|
|
1054
1202
|
const key3 = token.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
1055
1203
|
if (Array.isArray(current)) current = current[Number(key3)];
|
|
1056
1204
|
else if (isRecord(current) && hasOwn(current, key3)) current = current[key3];
|
|
@@ -1085,17 +1233,17 @@ function dataUnionErrors(errors, value) {
|
|
|
1085
1233
|
});
|
|
1086
1234
|
}
|
|
1087
1235
|
function validateAgainstSchema(value, schemaOrKind = "presentation", options2 = {}) {
|
|
1088
|
-
const
|
|
1089
|
-
if (
|
|
1236
|
+
const resolved2 = resolveValidator(schemaOrKind);
|
|
1237
|
+
if (resolved2.schemaName === "presentation") {
|
|
1090
1238
|
const errors2 = contentDepthIssues(value);
|
|
1091
|
-
if (errors2.length) return { valid: false, errors: errors2, warnings: [], unfilled: [], schemaName:
|
|
1239
|
+
if (errors2.length) return { valid: false, errors: errors2, warnings: [], unfilled: [], schemaName: resolved2.schemaName };
|
|
1092
1240
|
}
|
|
1093
1241
|
const variableIssues = { errors: [], warnings: [] };
|
|
1094
1242
|
const unfilled = [];
|
|
1095
1243
|
let subject = value;
|
|
1096
1244
|
let template;
|
|
1097
1245
|
let unfilledVariables;
|
|
1098
|
-
if (
|
|
1246
|
+
if (resolved2.schemaName === "presentation" && isRecord(value) && (hasContentVariables(value) || options2.values !== void 0 || options2.template !== void 0)) {
|
|
1099
1247
|
template = options2.template ?? isTemplate(value);
|
|
1100
1248
|
const view = instantiateForValidation(value, options2.values ?? {}, template);
|
|
1101
1249
|
subject = view.presentation;
|
|
@@ -1113,14 +1261,14 @@ function validateAgainstSchema(value, schemaOrKind = "presentation", options2 =
|
|
|
1113
1261
|
}
|
|
1114
1262
|
}
|
|
1115
1263
|
}
|
|
1116
|
-
const valid =
|
|
1117
|
-
const ajvErrors = valid ? [] : typedVariableErrors(
|
|
1118
|
-
const specific =
|
|
1119
|
-
const mapped = bestMatchErrors(schemaEngine(), schemas[
|
|
1264
|
+
const valid = resolved2.validate(subject) === true;
|
|
1265
|
+
const ajvErrors = valid ? [] : typedVariableErrors(resolved2.validate.errors ?? [], subject);
|
|
1266
|
+
const specific = resolved2.schemaName === "presentation" ? dataUnionErrors(ajvErrors, subject) : ajvErrors;
|
|
1267
|
+
const mapped = collapseRepeats(bestMatchErrors(schemaEngine(), schemas[resolved2.schemaName].$id, specific)).map(toIssue);
|
|
1120
1268
|
const errors = mapped;
|
|
1121
|
-
if (
|
|
1269
|
+
if (resolved2.schemaName === "layout" && valid) for (const issue2 of layoutTemplateIssues(subject)) errors.push(semanticIssue(issue2.path, issue2.message, { code: issue2.code }));
|
|
1122
1270
|
const warnings = [];
|
|
1123
|
-
if (
|
|
1271
|
+
if (resolved2.schemaName === "presentation") {
|
|
1124
1272
|
errors.push(...presentationSemanticIssues(subject, options2.catalogs));
|
|
1125
1273
|
errors.push(...variableIssues.errors);
|
|
1126
1274
|
const data = dataIssues(subject);
|
|
@@ -1129,7 +1277,7 @@ function validateAgainstSchema(value, schemaOrKind = "presentation", options2 =
|
|
|
1129
1277
|
warnings.push(...data.warnings);
|
|
1130
1278
|
warnings.push(...overlayAnchorSizeWarnings(subject));
|
|
1131
1279
|
warnings.push(...variableIssues.warnings);
|
|
1132
|
-
} else if (
|
|
1280
|
+
} else if (resolved2.schemaName === "language") {
|
|
1133
1281
|
errors.push(...validateLanguageSemantics(value));
|
|
1134
1282
|
}
|
|
1135
1283
|
return {
|
|
@@ -1137,8 +1285,8 @@ function validateAgainstSchema(value, schemaOrKind = "presentation", options2 =
|
|
|
1137
1285
|
errors,
|
|
1138
1286
|
warnings,
|
|
1139
1287
|
unfilled,
|
|
1140
|
-
schemaName:
|
|
1141
|
-
catalogKind:
|
|
1288
|
+
schemaName: resolved2.schemaName,
|
|
1289
|
+
catalogKind: resolved2.catalogKind,
|
|
1142
1290
|
...template !== void 0 ? { template, unfilledVariables } : {}
|
|
1143
1291
|
};
|
|
1144
1292
|
}
|
|
@@ -1258,10 +1406,10 @@ var CVD_MATRICES = {
|
|
|
1258
1406
|
[4733e-6, 0.691367, 0.3039]
|
|
1259
1407
|
]
|
|
1260
1408
|
};
|
|
1261
|
-
var visionModels = ["protanopia", "deuteranopia", "tritanopia", "
|
|
1409
|
+
var visionModels = ["protanopia", "deuteranopia", "tritanopia", "grayscale"];
|
|
1262
1410
|
function simulateVision(hex, model) {
|
|
1263
1411
|
const rgb = toRgb(hex).map(linear);
|
|
1264
|
-
if (model === "
|
|
1412
|
+
if (model === "grayscale") {
|
|
1265
1413
|
const y = 0.2126 * (rgb[0] ?? 0) + 0.7152 * (rgb[1] ?? 0) + 0.0722 * (rgb[2] ?? 0);
|
|
1266
1414
|
const v = delinear(y);
|
|
1267
1415
|
return toHex([v, v, v]);
|
|
@@ -1405,13 +1553,13 @@ function colorLevels(slideDesign, layout, deckDesign, theme, scheme, variables =
|
|
|
1405
1553
|
}
|
|
1406
1554
|
function resolveDesign(document, index, context) {
|
|
1407
1555
|
const deck = rec(document.design), own4 = rec(rec(Array.isArray(document.slides) ? document.slides[index] : void 0).design);
|
|
1408
|
-
const { options: options2, diagnostics, resolved } = context;
|
|
1409
|
-
const { theme, colorScheme, fontScheme, fontSchemePath } =
|
|
1556
|
+
const { options: options2, diagnostics, resolved: resolved2 } = context;
|
|
1557
|
+
const { theme, colorScheme, fontScheme, fontSchemePath } = resolved2;
|
|
1410
1558
|
const fontPath = `/${fontSchemePath.split(".").join("/")}`;
|
|
1411
1559
|
const fontDiagnostic = diagnostics.find((diagnostic) => diagnostic.kind === "fontSchemes");
|
|
1412
1560
|
const dimensions = { width: options2.width, height: options2.height };
|
|
1413
1561
|
const variables = rec(document.variables);
|
|
1414
|
-
const choice = colorChoice(colorLevels(own4,
|
|
1562
|
+
const choice = colorChoice(colorLevels(own4, resolved2.layout, deck, theme, colorScheme, variables, resolved2.messageSurface?.variant), colorScheme, variables);
|
|
1415
1563
|
const roles = resolveColorRoles(colorScheme, { background: choice.background, variant: choice.variant });
|
|
1416
1564
|
const dark = roles.dark;
|
|
1417
1565
|
const text2 = roles.text;
|
|
@@ -1469,7 +1617,7 @@ function resolveTextColor(reference, design, fallback) {
|
|
|
1469
1617
|
fallback
|
|
1470
1618
|
});
|
|
1471
1619
|
}
|
|
1472
|
-
var
|
|
1620
|
+
var GRAY_RAMP = [0, 32, 64, 96, 128, 160, 192, 224, 255].map((v) => toHex([v, v, v]));
|
|
1473
1621
|
function backdropColors(backdrop, box, size, layer) {
|
|
1474
1622
|
switch (backdrop.kind) {
|
|
1475
1623
|
case "solid":
|
|
@@ -1496,9 +1644,9 @@ function backdropColors(backdrop, box, size, layer) {
|
|
|
1496
1644
|
}
|
|
1497
1645
|
case "image": {
|
|
1498
1646
|
const opacity = layer?.opacity ?? backdrop.opacity;
|
|
1499
|
-
const ramp = layer?.grays ? [.../* @__PURE__ */ new Set([layer.grays[0], ...[0, 32, 64, 96, 128, 160, 192, 224, 255].filter((v) => v > layer.grays[0] && v < layer.grays[1]), layer.grays[1]])].map((v) => toHex([v, v, v])) :
|
|
1500
|
-
const colors = ramp.map((
|
|
1501
|
-
const pixel = layer?.duotone ? blend(layer.duotone[1], layer.duotone[0], toRgb(
|
|
1647
|
+
const ramp = layer?.grays ? [.../* @__PURE__ */ new Set([layer.grays[0], ...[0, 32, 64, 96, 128, 160, 192, 224, 255].filter((v) => v > layer.grays[0] && v < layer.grays[1]), layer.grays[1]])].map((v) => toHex([v, v, v])) : GRAY_RAMP;
|
|
1648
|
+
const colors = ramp.map((gray) => {
|
|
1649
|
+
const pixel = layer?.duotone ? blend(layer.duotone[1], layer.duotone[0], toRgb(gray)[0] / 255) : gray;
|
|
1502
1650
|
let color = blend(pixel, backdrop.base, opacity);
|
|
1503
1651
|
if (layer?.overlay) color = blend(layer.overlay.color, color, layer.overlay.opacity);
|
|
1504
1652
|
return color;
|
|
@@ -1524,8 +1672,8 @@ function readableColor(candidates, sample, minimum) {
|
|
|
1524
1672
|
}
|
|
1525
1673
|
|
|
1526
1674
|
// src/rule-content.ts
|
|
1527
|
-
var pointer2 = (...parts2) => parts2.length ? "/" + parts2.map((
|
|
1528
|
-
var pointerOfDotted = (path) => "/" + path.split(".").map((
|
|
1675
|
+
var pointer2 = (...parts2) => parts2.length ? "/" + parts2.map((part2) => String(part2).replaceAll("~", "~0").replaceAll("/", "~1")).join("/") : "";
|
|
1676
|
+
var pointerOfDotted = (path) => "/" + path.split(".").map((part2) => part2.replaceAll("~", "~0").replaceAll("/", "~1")).join("/");
|
|
1529
1677
|
function slidePayloads(slide, slidePath) {
|
|
1530
1678
|
const out = [{ path: slidePath, node: slide, root: true }];
|
|
1531
1679
|
visitContentPayloads(slide, slidePath, (node, path) => out.push({ path, node, root: false }));
|
|
@@ -1600,7 +1748,7 @@ function textValues(slide, slidePath) {
|
|
|
1600
1748
|
return out;
|
|
1601
1749
|
}
|
|
1602
1750
|
function splitPointer(path) {
|
|
1603
|
-
return path === "" ? [] : path.slice(1).split("/").map((
|
|
1751
|
+
return path === "" ? [] : path.slice(1).split("/").map((part2) => part2.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
1604
1752
|
}
|
|
1605
1753
|
var plainText = (value) => typeof value === "string" ? value : value.map((run) => typeof run === "string" ? run : typeof rec(run).text === "string" ? rec(run).text : "").join("");
|
|
1606
1754
|
function runsOf(tv) {
|
|
@@ -1616,8 +1764,8 @@ function runsOf(tv) {
|
|
|
1616
1764
|
function altOf(value, assets, variables, template) {
|
|
1617
1765
|
if (typeof value === "string" && value.startsWith("var:")) {
|
|
1618
1766
|
const variable = rec(rec(variables)[value.slice(4)]);
|
|
1619
|
-
const
|
|
1620
|
-
return
|
|
1767
|
+
const resolved2 = variable.type === "image" ? variable.value ?? (template === true ? variable.example : void 0) : void 0;
|
|
1768
|
+
return resolved2 === void 0 || typeof resolved2 === "string" && resolved2.startsWith("var:") ? void 0 : altOf(resolved2, assets);
|
|
1621
1769
|
}
|
|
1622
1770
|
const own4 = typeof value === "object" && value !== null ? value.alt : void 0;
|
|
1623
1771
|
if (typeof own4 === "string") return own4;
|
|
@@ -1736,7 +1884,7 @@ var formatRules = [
|
|
|
1736
1884
|
rule("shape-anchor-missing", "format", "error", "An overlay shape has no resolvable block or qualified plotted chart point.", "An overlay shape placed with `at` sits against a composed block of its slide, named by the block's `id`. A chart point also requires a unique plotted category and series in a qualified shared plot. When an identity or geometry is missing, the shape is not drawn.", { standard: SCHEMA }),
|
|
1737
1885
|
rule("shape-anchor-size-unit", "format", "warning", "A pixel size is under a fraction key.", "In `at`, `width` and `height` are fractions of the block (up to 8); pixels are `widthPx` and `heightPx`. A value above 4 and up to 8 is reported here; above 8 it is a schema error that offers the same rename.", { standard: SCHEMA }),
|
|
1738
1886
|
rule("connector-end-missing", "format", "error", "A connector end names no block or overlay shape on the slide.", "A connector joins two shapes of its slide, each named by the `id` of a block or an overlay shape. With an end that names nothing (or names a connector) there is nothing to glue it to, so it is not drawn.", { standard: SCHEMA }),
|
|
1739
|
-
rule("image-placement-invalid", "format", "error", "An image placement cannot be
|
|
1887
|
+
rule("image-placement-invalid", "format", "error", "An image placement cannot be honored.", "A placed image bleeds to a slide edge and the rest of the slide composes beside it. Only a top-level block (slides.N.blocks.I) can do that, and a slide edge holds one placed image; a block in a group or in a cell of the slide grid, or a second block on the same edge, has nowhere to go.", { standard: SCHEMA }),
|
|
1740
1888
|
rule("layout-placeholder-group", "format", "error", "A layout record's placeholder group breaks a nesting rule.", "A placeholder group arranges body regions inside one cell of its layout record. Groups nest at most three levels inside a record, and a group holds body regions and groups only: the headings (title, subtitle, tag) stay at the record's top level, where the engine places them. Composition cannot use a record that breaks either rule.", { standard: SCHEMA }),
|
|
1741
1889
|
rule("dataset-unknown", "format", "error", "A chart or table names a dataset that does not exist.", "The data cannot be drawn without the dataset it refers to.", { standard: SCHEMA }),
|
|
1742
1890
|
rule("dataset-field-unknown", "format", "error", "A table asks a dataset for a column it does not have.", "The column cannot be shown when the dataset has no column of that name.", { standard: SCHEMA }),
|
|
@@ -1748,19 +1896,19 @@ var formatRules = [
|
|
|
1748
1896
|
rule("variable-invalid-value", "format", "error", "A variable value does not match its declared type.", "A number variable given text, or a date given a non-date, cannot be filled into the deck.", { standard: SCHEMA }),
|
|
1749
1897
|
rule("variable-unknown-builtin", "format", "error", "A token names a built-in variable that does not exist.", "The `deck.`, `speaker.`, `organization.` and `slide.` names (and `speakers`) are reserved for built-in variables; a name under them that is not a built-in can never be filled, so the token would show literally. The slide-scoped `slide.number`, `slide.section` and `deck.slideCount` are inline tokens only, so `var:slide.*` and `var:deck.slideCount` are reported too; organization logos are whole-field references only (`var:organization.logo.icon`), so a `{{organization.logo}}` token, an unknown logo shape or an unknown organization id is reported.", { standard: SCHEMA }),
|
|
1750
1898
|
rule("table-highlight-unknown-name", "format", "error", "A table highlight names a row the table does not have.", "`table.highlight` emphasizes body rows by their first-column text; a name that matches no row highlights nothing, so the table is not drawn as authored.", { standard: SCHEMA }),
|
|
1751
|
-
rule("chart-highlight-unknown-name", "format", "error", "A chart highlight names a series or category the chart does not have.", "`chart.highlight`
|
|
1899
|
+
rule("chart-highlight-unknown-name", "format", "error", "A chart highlight names a series or category the chart does not have.", "`chart.highlight` emphasizes marks by name; a name that matches no series or category in the chart data highlights nothing, so the chart is not drawn as authored.", { standard: SCHEMA }),
|
|
1752
1900
|
rule("variable-format", "format", "error", "A variable cannot be formatted.", "A number or date format that does not apply to the value leaves the token unreadable.", { standard: SCHEMA }),
|
|
1753
1901
|
rule(
|
|
1754
1902
|
"variable-unfilled",
|
|
1755
1903
|
"format",
|
|
1756
1904
|
"error",
|
|
1757
1905
|
"A required template variable has no value.",
|
|
1758
|
-
"A variable a deck declares as required, with no value, is template scaffolding: `{{name}}` tokens show up literally and
|
|
1906
|
+
"A variable a deck declares as required, with no value, is template scaffolding: `{{name}}` tokens show up literally and color variables fall back to a default. A normal deck must be filled, so this is an error and the deck is not valid; a template (`template: true`) is incomplete on purpose, so it is a warning.",
|
|
1759
1907
|
{
|
|
1760
|
-
approximations: "Required variables are those the variable machinery reports as unfilled for the document (declared, no value, not `required: false`, not given by the `values` option). For a document that declares no content variables, `{{id}}` / `{{id|format}}` tokens (`{{` escapes) left in any string outside `variables`, `extensions`, `catalogs` and `assets` are reported as warnings. `var:`
|
|
1908
|
+
approximations: "Required variables are those the variable machinery reports as unfilled for the document (declared, no value, not `required: false`, not given by the `values` option). For a document that declares no content variables, `{{id}}` / `{{id|format}}` tokens (`{{` escapes) left in any string outside `variables`, `extensions`, `catalogs` and `assets` are reported as warnings. `var:` color references with no declaration are reported as `opf/variable-reference-unknown`. Fill a template with `opf fill` or `resolveVariables` to clear the findings."
|
|
1761
1909
|
}
|
|
1762
1910
|
),
|
|
1763
|
-
rule("run-color-unrecognized", "format", "warning", "A text run
|
|
1911
|
+
rule("run-color-unrecognized", "format", "warning", "A text run color is none of the documented forms.", "Run colors are open strings so imported decks stay valid, but a value that is not a hex color, a color-scheme name or a `var:` reference falls back to the theme color.", { standard: SCHEMA }),
|
|
1764
1912
|
rule("numbering-start-ignored", "format", "warning", "A list entry sets `start` where nothing is numbered.", "A start value only restarts an auto-number; without `numbering` on the payload it has no effect.", { standard: SCHEMA }),
|
|
1765
1913
|
rule(
|
|
1766
1914
|
"slide-size-out-of-range",
|
|
@@ -1770,7 +1918,7 @@ var formatRules = [
|
|
|
1770
1918
|
"The schema accepts any positive custom `widthInches` and `heightInches`, but a PPTX stores the size as `p:sldSz` with each side between 914400 and 51206400 EMU, which is 1 to 56 inches. A custom size outside that range exports a file that does not conform to the standard, which PowerPoint may reject or clamp. It is a warning because the document is still correct OPF and the preview draws it.",
|
|
1771
1919
|
{
|
|
1772
1920
|
standard: "ECMA-376 / ISO/IEC 29500-1 section 19.2.1.39 (p:sldSz) and section 19.7.17 (ST_SlideSizeCoordinate): 914400 to 51206400 EMU",
|
|
1773
|
-
approximations: "Checks the deck's resolved size: `design.dimensions`, else the resolved theme's `dimensions`. Inches are converted to EMU as the PPTX exporter does (`Math.round(inches * 914400)`), so a side of exactly 1 in or 56 in passes. A slide-level theme with another size is `opf/slide-theme-dimensions`. Presets are always in range. PowerPoint's own
|
|
1921
|
+
approximations: "Checks the deck's resolved size: `design.dimensions`, else the resolved theme's `dimensions`. Inches are converted to EMU as the PPTX exporter does (`Math.round(inches * 914400)`), so a side of exactly 1 in or 56 in passes. A slide-level theme with another size is `opf/slide-theme-dimensions`. Presets are always in range. PowerPoint's own behavior at the limits was not measured."
|
|
1774
1922
|
}
|
|
1775
1923
|
)
|
|
1776
1924
|
];
|
|
@@ -1805,7 +1953,7 @@ var referenceRules = [
|
|
|
1805
1953
|
"references",
|
|
1806
1954
|
"error",
|
|
1807
1955
|
"A layout template's regions are not valid.",
|
|
1808
|
-
"Region names are unique across the whole record and may not be tag, auto or a
|
|
1956
|
+
"Region names are unique across the whole record and may not be tag, auto or a cell word of the slide grid (start, center, end, top, middle, bottom), so a block's region (and a Markdown block's region=) stays unambiguous; title and subtitle name the heading regions, which take only a size, an anchor and (the title) a rule; a subtitle region needs a title region; a region accepts at least one content kind; overflowRegion must name a body region. composeSlide refuses such a record.",
|
|
1809
1957
|
{ standard: "spec/schemas/layout.schema.json and the region rules (docs/layout-templates.md)" }
|
|
1810
1958
|
),
|
|
1811
1959
|
rule(
|
|
@@ -1813,7 +1961,7 @@ var referenceRules = [
|
|
|
1813
1961
|
"references",
|
|
1814
1962
|
"warning",
|
|
1815
1963
|
"A content reference resolves nowhere.",
|
|
1816
|
-
"A layout, theme,
|
|
1964
|
+
"A layout, theme, color scheme, font scheme, narrative, audience, purpose or tone reference that neither the document embeds nor a registered catalog defines falls back: a slide composes automatically, a design uses the engine default. A strict export fails instead. A slide with no layout is automatic composition and is never reported. A layout id that OPF has removed is reported with the safe fix that writes its replacement or deletes the key.",
|
|
1817
1965
|
{ standard: SCHEMA, approximations: 'Resolved like every engine resolves it: catalogs.custom, then the records embedded under catalogs.default, then the catalog registered for its source (the first registered catalog when `default` is omitted); `name:id` in catalogs.<name>, then the catalog registered for its source. Nothing is fetched. Free-form audience and purpose text is not a reference. It is a warning, not an error, because catalogs are open and a host may register the id; `--fail-on warning` is the check that a deck is done. With a catalog registered, the hint names the nearest records that exist ("Did you mean `two-column`?").' }
|
|
1818
1966
|
),
|
|
1819
1967
|
rule(
|
|
@@ -1834,7 +1982,7 @@ var referenceRules = [
|
|
|
1834
1982
|
rule("variable-unknown", "references", "warning", "A `{{token}}` names a variable that is not declared.", "An undeclared token is shown literally.", { standard: SCHEMA }),
|
|
1835
1983
|
rule("variable-unknown-value", "references", "warning", "A value was supplied for a variable that is not declared.", "The value is never used.", { standard: SCHEMA }),
|
|
1836
1984
|
rule("variable-unused", "references", "warning", "A variable is declared but never used.", "A declaration nothing refers to has no effect.", { standard: SCHEMA }),
|
|
1837
|
-
rule("variable-reference-unknown", "references", "warning", "A `var:`
|
|
1985
|
+
rule("variable-reference-unknown", "references", "warning", "A `var:` color names a variable that is not declared.", "An undeclared color variable falls back to a default color.", { standard: SCHEMA })
|
|
1838
1986
|
];
|
|
1839
1987
|
var policyRules = [
|
|
1840
1988
|
rule(
|
|
@@ -1862,7 +2010,7 @@ var dataRules = [
|
|
|
1862
2010
|
rule("code-highlight-out-of-range", "content", "warning", "A code highlight marks a line the code does not have.", "Marked lines count from 1 by line break in code.source; an entry past the last line marks nothing.", { standard: SCHEMA }),
|
|
1863
2011
|
rule("code-highlight-range-reversed", "content", "warning", "A code highlight range ends before it starts.", "A range written end before start marks nothing; write the smaller line number first.", { standard: SCHEMA }),
|
|
1864
2012
|
rule("variable-builtin-missing", "content", "warning", "A built-in variable has no value in this document.", "A `{{deck.*}}`, `{{speaker.*}}` or `{{organization.*}}` token whose field the document does not set resolves to nothing, so the text shows a gap; a `var:organization.logo` reference to an organization without a logo draws no image. `{{slide.section}}` is checked per slide: a slide without a `section` that uses it, in its own text or in the header or footer it inherits, is reported at that slide.", { standard: SCHEMA }),
|
|
1865
|
-
rule("variable-group-omitted", "content", "info", "A group is drawn only when one of its optional variables has a value.", "A group (a block
|
|
2013
|
+
rule("variable-group-omitted", "content", "info", "A group is drawn only when one of its optional variables has a value.", "A group (a block with `blocks`) whose content variables are all optional (`required: false`) and all unfilled is left out whole when the deck is filled: its pictures, cards and other text go with the fields the variables would fill, so a slide never draws a card around a picture with no text. Validation fills every variable with its example or a sample, so it reports the group here instead.", { standard: SCHEMA, approximations: "Counts the declared text, number, date, image, url and list variables the group uses as `{{id}}` or `var:id`, at any depth; color variables and built-ins do not count. A group that uses none, or any required or filled one, is kept and not reported." }),
|
|
1866
2014
|
rule("duration-outside-narrative", "content", "warning", "The target duration is outside the range the narrative suits.", "A narrative records the talk lengths it suits. A deck whose duration is outside that range probably needs a different narrative or a different length; nothing is drawn or exported differently.", { standard: SCHEMA }),
|
|
1867
2015
|
rule("narrative-duration-range", "content", "warning", "An inline narrative duration range has min greater than max.", "A range with its bounds swapped matches no duration, so the duration check cannot help.", { standard: "spec/schemas/narrative.schema.json" })
|
|
1868
2016
|
];
|
|
@@ -1870,13 +2018,13 @@ var contrastRule = rule(
|
|
|
1870
2018
|
"text-contrast",
|
|
1871
2019
|
"accessibility",
|
|
1872
2020
|
"warning",
|
|
1873
|
-
"Text
|
|
1874
|
-
"Low-contrast text is hard or impossible to read for people with low vision,
|
|
2021
|
+
"Text color has too little contrast against the background it sits on.",
|
|
2022
|
+
"Low-contrast text is hard or impossible to read for people with low vision, color-vision differences, glare on a projector or a poor display. WCAG sets 4.5:1 for normal text and 3:1 for large text.",
|
|
1875
2023
|
{
|
|
1876
2024
|
standard: "WCAG 2.2 SC 1.4.3 Contrast (Minimum), level AA",
|
|
1877
2025
|
thresholds: ["contrastNormal", "contrastLarge"],
|
|
1878
2026
|
cost: "composition",
|
|
1879
|
-
approximations: "Computed on sRGB
|
|
2027
|
+
approximations: "Computed on sRGB colors with the WCAG relative-luminance formula, against the background the preview draws: a solid or theme color, the card surface, a table cell fill, every color a gradient takes under the text box (sampled on a 5x5 grid, angle respected), or both colors of a pattern. Anti-aliasing, text shadows and font weight are not modeled. Text color is the preview's (the scheme's text role or dark1 on a light background and light1 on a dark one, chosen from the background luminance, where a gradient or picture background uses the scheme's default background color), so a default can fail on a dark gradient. A link with no color of its own is measured in the scheme's hyperlink color."
|
|
1880
2028
|
}
|
|
1881
2029
|
);
|
|
1882
2030
|
var onImageRule = rule(
|
|
@@ -1936,7 +2084,7 @@ var readingOrderRule = rule(
|
|
|
1936
2084
|
{
|
|
1937
2085
|
standard: 'WCAG 2.2 SC 1.3.2 Meaningful Sequence, level A (PowerPoint: "Check reading order")',
|
|
1938
2086
|
cost: "composition",
|
|
1939
|
-
approximations: "Compares the composed content order with a visual order recomputed from the composed boxes: items whose vertical
|
|
2087
|
+
approximations: "Compares the composed content order with a visual order recomputed from the composed boxes: items whose vertical centers fall in the same row are ordered along the reading direction (a right-to-left deck is checked by rows only), rows from top to bottom. A block is one unit (RR-105): blocks are ordered by the boxes that hold them, and a group's own items are read, in their own visual order, before the next block, so cards side by side (a picture over a name) read card by card. Headings are expected first. Content drawn entirely above the title, over the columns of the title, is reported; content in a column beside the title is read after it. Free-form overlap is not analyzed. On a slide with a template layout (OPF 0.19) the expected order is the binding order instead (the regions in reading order, then the blocks of each region), and items outside a region (placed images, the row below the grid) are not compared."
|
|
1940
2088
|
}
|
|
1941
2089
|
);
|
|
1942
2090
|
var linkRule = rule(
|
|
@@ -1951,12 +2099,12 @@ var chartColorRule = rule(
|
|
|
1951
2099
|
"chart-color-only",
|
|
1952
2100
|
"accessibility",
|
|
1953
2101
|
"info",
|
|
1954
|
-
"Chart series may be indistinguishable without
|
|
1955
|
-
"OPF charts have no data labels or patterns, so series are told apart by
|
|
2102
|
+
"Chart series may be indistinguishable without color vision.",
|
|
2103
|
+
"OPF charts have no data labels or patterns, so series are told apart by color alone (and legend order). Colors that look alike to someone with color-vision deficiency, or when printed in grayscale, make series impossible to tell apart.",
|
|
1956
2104
|
{
|
|
1957
2105
|
standard: "WCAG 2.2 SC 1.4.1 Use of Color, level A",
|
|
1958
2106
|
thresholds: ["minSeriesColorDifference"],
|
|
1959
|
-
approximations: "Uses the engine's series palette (ValidateOptions.chartPalette; default chartSeriesPalette of each slide color scheme (accent1 to accent6, then their tints), adjusted for the slide background and softened like the engines draw them, LH-105) in series order: series i takes color i, pie/doughnut/treemap/funnel slices take
|
|
2107
|
+
approximations: "Uses the engine's series palette (ValidateOptions.chartPalette; default chartSeriesPalette of each slide color scheme (accent1 to accent6, then their tints), adjusted for the slide background and softened like the engines draw them, LH-105) in series order: series i takes color i, pie/doughnut/treemap/funnel slices take colors per category. Pairs are compared by CIE76 distance after simulating protanopia, deuteranopia, tritanopia (Machado 2009, severity 1) and grayscale. Neighboring series (and neighboring slices, on a pie or doughnut the last beside the first, which the engines move off the first by at most 20 L* or, where that is not enough, separate with a surface-colored slice border that this rule accepts, LH-161) must also differ by at least 11 in CIE L* (the lightness step the engines keep when they adjust a palette), since lightness is the cue left without hue (LH-35); a pair under it is reported as a lightness pair. Single-series charts and chart types without a series legend are skipped."
|
|
1960
2108
|
}
|
|
1961
2109
|
);
|
|
1962
2110
|
var chartAltRule = rule(
|
|
@@ -1971,11 +2119,11 @@ var chartColorsRule = rule(
|
|
|
1971
2119
|
"chart-colors-adjusted",
|
|
1972
2120
|
"accessibility",
|
|
1973
2121
|
"warning",
|
|
1974
|
-
"A chart
|
|
1975
|
-
"`chart.colors` sets the
|
|
2122
|
+
"A chart color cannot be used as authored.",
|
|
2123
|
+
"`chart.colors` sets the color of series 1, 2, 3 and so on. A color that cannot be resolved (a `var:` color variable the deck does not define, or a name that is not a color) is ignored and the deck palette color of that position is used. A color with under 3:1 contrast against the slide background the chart stands on is kept for its hue but drawn lighter or darker, so the chart does not show the color that was written.",
|
|
1976
2124
|
{
|
|
1977
2125
|
standard: "WCAG 2.2 SC 1.4.11 Non-text Contrast, level AA",
|
|
1978
|
-
approximations: "Resolves each entry like any
|
|
2126
|
+
approximations: "Resolves each entry like any color reference (hex, color-scheme slot or role, `var:` variable) against the slide's scheme and compares it with the slide background (no chart has a panel, LH-105; a chart in a card stands on the card, which is not measured) by WCAG contrast; 3:1 is the threshold the engines enforce. Translucent colors and unresolved backgrounds are not measured. Colors that look alike to color-vision deficiency are reported by opf/chart-color-only, which judges the authored colors."
|
|
1979
2127
|
}
|
|
1980
2128
|
);
|
|
1981
2129
|
var languageRule = rule(
|
|
@@ -1984,7 +2132,7 @@ var languageRule = rule(
|
|
|
1984
2132
|
"info",
|
|
1985
2133
|
"The presentation does not declare its language.",
|
|
1986
2134
|
"Screen readers and text-to-speech choose pronunciation and hyphenation from the declared language; spell checkers and translation tools use it too.",
|
|
1987
|
-
{ standard: "WCAG 2.2 SC 3.1.1 Language of Page, level A", approximations: "Only the presentation-level `language` is checked, not the language of individual runs (`TextRun.language`; opf/language-tag checks how those tags are written)." }
|
|
2135
|
+
{ standard: "WCAG 2.2 SC 3.1.1 Language of Page, level A", approximations: "Only the presentation-level `language` is checked, not the language of individual runs (`TextRun.language`; opf/language-tag checks how those tags are written). With no language set, a slide whose letters are mostly Arabic-script or Hebrew is laid out as Arabic or Hebrew, right to left (OPF 0.35); the message names those slides." }
|
|
1988
2136
|
);
|
|
1989
2137
|
var MAX_FURNITURE_LINES = 2;
|
|
1990
2138
|
var overflowRule = rule(
|
|
@@ -2063,8 +2211,8 @@ var arrangementAdaptedRule = rule(
|
|
|
2063
2211
|
"arrangement-adapted",
|
|
2064
2212
|
"layout",
|
|
2065
2213
|
"info",
|
|
2066
|
-
"A pyramid, matrix, cycle, row of chevrons or
|
|
2067
|
-
"A `pyramid`, `matrix`, `cycle`, `chevrons`, `
|
|
2214
|
+
"A diagram arrangement (a pyramid, matrix, cycle, row of chevrons, process, tree or Venn) is drawn another way.",
|
|
2215
|
+
"A region whose `arrangement` is `pyramid`, `inverted-pyramid`, `matrix`, `cycle`, `chevrons`, `process`, `vertical-process`, `org-chart`, `hierarchy` or `venn` draws a list of one level of short entries as that diagram (docs/smartart.md). A matrix needs exactly four entries for its quadrants; with another count its entries are drawn as a grid of cards. A list the arrangement does not draw (nested entries, descriptions, icons, numbering, too many entries), or whose entries fit neither PowerPoint's design nor OPF's at the list's size, is drawn as a list.",
|
|
2068
2216
|
{ cost: "composition" }
|
|
2069
2217
|
);
|
|
2070
2218
|
var shapeOffSlideRule = rule(
|
|
@@ -2255,7 +2403,7 @@ var chartPieManySlicesRule = rule(
|
|
|
2255
2403
|
"content",
|
|
2256
2404
|
"info",
|
|
2257
2405
|
`A pie or doughnut chart has more than ${PIE_MAX_SLICES} slices.`,
|
|
2258
|
-
"People compare angles and areas poorly, and past a few slices the small ones cannot be told apart or
|
|
2406
|
+
"People compare angles and areas poorly, and past a few slices the small ones cannot be told apart or labeled. Bars along one axis show the same parts of a whole and let them be compared and ranked (Few, Show Me the Numbers).",
|
|
2259
2407
|
{
|
|
2260
2408
|
standard: `Stephen Few, Show Me the Numbers (2012), on pie charts; more than ${PIE_MAX_SLICES} categories.`,
|
|
2261
2409
|
approximations: "Counts the rows (categories) of a `pie` or `doughnut` chart as its data resolves; a doughnut of several series (nested rings) counts the categories of a ring. Treemaps and funnels are not checked."
|
|
@@ -2394,18 +2542,18 @@ function collectSamples(context) {
|
|
|
2394
2542
|
const valueColor = item.metricLayout ? metricValueColor(itemDesign.colors.primary, item.frameBox && !item.emphasis ? design.neutrals.card.hex : itemDesign.colors.background, itemDesign.colors.text) : itemDesign.colors.primary;
|
|
2395
2543
|
const valueRole = (role) => role === "value" || role === "unit" && item.metricLayout?.arrangement === "inline-unit";
|
|
2396
2544
|
if (layoutOf)
|
|
2397
|
-
for (const
|
|
2398
|
-
if (!
|
|
2399
|
-
const role = String(
|
|
2545
|
+
for (const part2 of layoutOf.parts) {
|
|
2546
|
+
if (!part2.fit || part2.visible === false) continue;
|
|
2547
|
+
const role = String(part2.role ?? "");
|
|
2400
2548
|
parts2.push({
|
|
2401
|
-
path: typeof
|
|
2402
|
-
sizePx:
|
|
2403
|
-
color: role === "footer" ? itemDesign.colors.mutedText : valueRole(role) && item.metricLayout ? valueColor : item.timelineLayout ? timelineTextColor(
|
|
2549
|
+
path: typeof part2.path === "string" && part2.path.startsWith("slides.") ? pointerOfDotted(part2.path) : itemPath,
|
|
2550
|
+
sizePx: part2.fit.fontSize / scale,
|
|
2551
|
+
color: role === "footer" ? itemDesign.colors.mutedText : valueRole(role) && item.metricLayout ? valueColor : item.timelineLayout ? timelineTextColor(part2, { background: itemDesign.colors.background, primary: itemDesign.colors.primary, text: itemDesign.colors.text, mutedText: itemDesign.colors.mutedText }) : itemDesign.colors.text,
|
|
2404
2552
|
label: item.field === "quote" ? role === "footer" ? "Quote attribution" : "Quote" : item.field === "metric" ? role === "value" ? "Metric value" : "Metric label" : "Timeline text"
|
|
2405
2553
|
});
|
|
2406
2554
|
}
|
|
2407
2555
|
else parts2.push({ path: itemPath, sizePx: baseSize, color: itemDesign.colors.text, label: heading || item.field === "text" ? label : item.field === "items" || item.field === "bullets" ? "List text" : label });
|
|
2408
|
-
for (const
|
|
2556
|
+
for (const part2 of parts2) samples.push({ path: part2.path, color: part2.color, sizePx: part2.sizePx, bold, backdrop, source: "default", label: part2.label });
|
|
2409
2557
|
const owners = textValues({ [item.field]: item.value }, "");
|
|
2410
2558
|
for (const owner of owners) {
|
|
2411
2559
|
if (typeof owner.value === "string") continue;
|
|
@@ -2416,13 +2564,13 @@ function collectSamples(context) {
|
|
|
2416
2564
|
const color = resolveTextColor(run.style.color, itemDesign, itemDesign.colors.text);
|
|
2417
2565
|
if (!color) continue;
|
|
2418
2566
|
const size = typeof run.style.fontSize === "number" ? run.style.fontSize / PX_TO_PT : baseSize;
|
|
2419
|
-
samples.push({ path: `${run.path}/color`, color, sizePx: size, bold: Boolean(run.style.bold) || bold, backdrop, source: "override", colorPath: `${run.path}/color`, label: "
|
|
2567
|
+
samples.push({ path: `${run.path}/color`, color, sizePx: size, bold: Boolean(run.style.bold) || bold, backdrop, source: "override", colorPath: `${run.path}/color`, label: "Colored text" });
|
|
2420
2568
|
}
|
|
2421
2569
|
}
|
|
2422
2570
|
}
|
|
2423
|
-
for (const
|
|
2424
|
-
if (
|
|
2425
|
-
samples.push({ path: pointerOfDotted(
|
|
2571
|
+
for (const part2 of composition.furniture?.parts ?? [])
|
|
2572
|
+
if (part2.type === "text")
|
|
2573
|
+
samples.push({ path: pointerOfDotted(part2.sourcePath ?? part2.path), color: design.colors.mutedText, sizePx: (part2.fit?.fontSize ?? 13 * scale) / scale, bold: false, backdrop: slideBackdrop(context, part2.box), source: "default", label: part2.kind === "header" ? "Header text" : "Footer text" });
|
|
2426
2574
|
return samples;
|
|
2427
2575
|
}
|
|
2428
2576
|
var contrastRules = [
|
|
@@ -2445,7 +2593,7 @@ var contrastRules = [
|
|
|
2445
2593
|
path: sample.path,
|
|
2446
2594
|
slide,
|
|
2447
2595
|
severity: "warning",
|
|
2448
|
-
message: `${sample.label}
|
|
2596
|
+
message: `${sample.label} color ${sample.color} is too faint on this background picture: over every color the picture can show here its contrast is at most ${best.toFixed(1)}:1, and ${needed}:1 is needed at this size.`,
|
|
2449
2597
|
help: "Set the background's tone (dark or light) so the text color follows the picture, give the text a readable color, or make the overlay strong enough for the text to read.",
|
|
2450
2598
|
measured: { ratio: round(worst.ratio), best: round(best), needed, textColor: sample.color }
|
|
2451
2599
|
});
|
|
@@ -2474,14 +2622,14 @@ var contrastRules = [
|
|
|
2474
2622
|
const preferred = readableColor([slide.design.colors.text], sample.backdrop, needed);
|
|
2475
2623
|
if (preferred !== void 0) {
|
|
2476
2624
|
const value = preferred.toUpperCase() === slide.design.colors.text.toUpperCase() ? "text" : preferred;
|
|
2477
|
-
fixes.push({ id: "use-readable-color", title: value === "text" ? "Use the slide text
|
|
2625
|
+
fixes.push({ id: "use-readable-color", title: value === "text" ? "Use the slide text color" : `Use ${preferred}`, kind: "patch", safe: false, patch: [{ op: "replace", path: sample.colorPath, value }] });
|
|
2478
2626
|
}
|
|
2479
2627
|
}
|
|
2480
2628
|
const diagnostic = context.report(contrastRule, {
|
|
2481
2629
|
path: sample.path,
|
|
2482
2630
|
slide,
|
|
2483
|
-
message: `${sample.label}
|
|
2484
|
-
help: sample.source === "override" ? "Pick a
|
|
2631
|
+
message: `${sample.label} color ${sample.color} on ${worst.against} has a contrast ratio of ${worst.ratio.toFixed(2)}:1; ${needed}:1 is needed for ${large ? "large" : "normal"} text.`,
|
|
2632
|
+
help: sample.source === "override" ? "Pick a color with enough contrast against the background, or remove this color override so the theme chooses a readable text color." : "The theme text color is unreadable on this background. Change the slide or deck background, the color scheme (dark1/light1), or give the text an explicit readable color.",
|
|
2485
2633
|
measured: { ratio: round(worst.ratio), needed, large, sizePt: round(sample.sizePx * PX_TO_PT), textColor: sample.color, backgroundColor: worst.against },
|
|
2486
2634
|
fixes
|
|
2487
2635
|
});
|
|
@@ -2654,7 +2802,7 @@ var readingOrderRules = [
|
|
|
2654
2802
|
path: pointerOfDotted(composed[index]),
|
|
2655
2803
|
slide,
|
|
2656
2804
|
message: `Reading order differs from visual order: ${JSON.stringify(name(composed[index]))} is read at ${ordinal(index)} but appears at ${ordinal(visual.indexOf(composed[index]))}. Composed order: ${composed.map(name).join(", ")}; visual order: ${visual.map(name).join(", ")}.`,
|
|
2657
|
-
help: "Reorder the blocks (or
|
|
2805
|
+
help: "Reorder the blocks (or place them in other cells of the slide's grid) so the composed order follows the visual order, or use blocks with an explicit composition instead of cells.",
|
|
2658
2806
|
measured: { firstMismatch: index, composed: composed.length }
|
|
2659
2807
|
});
|
|
2660
2808
|
}
|
|
@@ -2743,9 +2891,9 @@ var chartRules = [
|
|
|
2743
2891
|
for (const slide of context.slides)
|
|
2744
2892
|
for (const payload of slidePayloads(slide.slide, slide.path)) {
|
|
2745
2893
|
const chart = rec(payload.node.chart);
|
|
2746
|
-
const
|
|
2747
|
-
if (!
|
|
2748
|
-
const data = { columns:
|
|
2894
|
+
const resolved2 = resolveChartData(chart, context.document);
|
|
2895
|
+
if (!resolved2.ok) continue;
|
|
2896
|
+
const data = { columns: resolved2.columns.filter((_, index) => !(resolved2.hasX && index === 1)), rows: resolved2.rows };
|
|
2749
2897
|
const type = String(chart.type ?? "").toLowerCase();
|
|
2750
2898
|
if (chartSkip.test(type)) continue;
|
|
2751
2899
|
const slices = perCategory.test(type);
|
|
@@ -2780,7 +2928,7 @@ var chartRules = [
|
|
|
2780
2928
|
context.report(chartColorRule, {
|
|
2781
2929
|
path: `${payload.path === slide.path ? slide.path : payload.path}/chart`,
|
|
2782
2930
|
slide,
|
|
2783
|
-
message: `${slices ? "Slices" : "Series"} may be hard to tell apart without
|
|
2931
|
+
message: `${slices ? "Slices" : "Series"} may be hard to tell apart without color: ${pairs.slice(0, 3).map(describe2).join("; ")}${cycles ? `${pairs.length ? "; " : ""}${count} ${slices ? "slices" : "series"} exceed the ${palette.length}-color palette, so colors repeat` : ""}.`,
|
|
2784
2932
|
help: "Show fewer series per chart (split into two charts), state the key values in the slide text or a table next to the chart, or choose a chart type whose categories sit on an axis instead of in a legend.",
|
|
2785
2933
|
measured: { series: count, confusablePairs: pairs.length, minDifference: pairs[0] ? round(pairs[0].difference) : null }
|
|
2786
2934
|
});
|
|
@@ -2795,16 +2943,16 @@ var chartRules = [
|
|
|
2795
2943
|
const chart = rec(payload.node.chart);
|
|
2796
2944
|
if (!Array.isArray(chart.colors)) continue;
|
|
2797
2945
|
const surface = normalizeHexColor(slide.design.colors.background);
|
|
2798
|
-
const
|
|
2799
|
-
|
|
2946
|
+
const resolved2 = resolveChartColors(chart.colors, slide.design.colorScheme, chartColorContext(slide.design));
|
|
2947
|
+
resolved2.forEach((color, index) => {
|
|
2800
2948
|
const path = `${payload.path === slide.path ? slide.path : payload.path}/chart/colors/${index}`;
|
|
2801
2949
|
const entry2 = chart.colors[index];
|
|
2802
2950
|
if (color === void 0) {
|
|
2803
2951
|
context.report(chartColorsRule, {
|
|
2804
2952
|
path,
|
|
2805
2953
|
slide,
|
|
2806
|
-
message: `Chart
|
|
2807
|
-
help: 'Use a hex
|
|
2954
|
+
message: `Chart color ${index + 1} (${JSON.stringify(entry2)}) cannot be resolved, so the palette color of that position is used.`,
|
|
2955
|
+
help: 'Use a hex color, a color-scheme name such as "accent2", or the id of a color variable the deck defines (var:<id>).'
|
|
2808
2956
|
});
|
|
2809
2957
|
return;
|
|
2810
2958
|
}
|
|
@@ -2813,8 +2961,8 @@ var chartRules = [
|
|
|
2813
2961
|
context.report(chartColorsRule, {
|
|
2814
2962
|
path,
|
|
2815
2963
|
slide,
|
|
2816
|
-
message: `Chart
|
|
2817
|
-
help: "Choose a
|
|
2964
|
+
message: `Chart color ${index + 1} (${color}) has ${contrast.toFixed(1)}:1 contrast against the slide background (${surface}); it is drawn lighter or darker to reach 3:1.`,
|
|
2965
|
+
help: "Choose a color that already has at least 3:1 contrast against the slide background, so the chart shows the color you wrote.",
|
|
2818
2966
|
measured: { contrast: round(contrast), panel: surface }
|
|
2819
2967
|
});
|
|
2820
2968
|
});
|
|
@@ -2865,10 +3013,23 @@ var languageRules = [
|
|
|
2865
3013
|
info: languageRule,
|
|
2866
3014
|
run(context) {
|
|
2867
3015
|
if (context.document.language !== void 0) return;
|
|
3016
|
+
const read = /* @__PURE__ */ new Map();
|
|
3017
|
+
for (const slide of context.slides) {
|
|
3018
|
+
const tag = slide.slide.language === void 0 ? languageOfText(context.document, slide.index) : void 0;
|
|
3019
|
+
if (tag) read.set(tag, [...read.get(tag) ?? [], slide.index + 1]);
|
|
3020
|
+
}
|
|
3021
|
+
const NAMES = { ar: "Arabic", he: "Hebrew" };
|
|
3022
|
+
const list = (numbers) => numbers.length === 1 ? `slide ${numbers[0]} is` : `slides ${numbers.slice(0, -1).join(", ")} and ${numbers.at(-1)} are`;
|
|
3023
|
+
const notes = [...read].map(([tag, numbers]) => {
|
|
3024
|
+
const name = NAMES[tag] ?? tag;
|
|
3025
|
+
const who = numbers.length === context.slides.length ? numbers.length === 1 ? "Its slide is" : "Its slides are" : `${list(numbers).replace(/^s/, "S")}`;
|
|
3026
|
+
return `${who} written in the ${name} script, so OPF lays ${numbers.length === 1 ? "it" : "them"} out as ${name} ("${tag}"): right to left, with that language's default fonts.`;
|
|
3027
|
+
});
|
|
3028
|
+
const first = [...read.keys()][0];
|
|
2868
3029
|
context.report(languageRule, {
|
|
2869
3030
|
path: "",
|
|
2870
|
-
message: "The presentation has no language set.",
|
|
2871
|
-
help: 'Set `language` to a BCP 47 tag, for example "en-US".',
|
|
3031
|
+
message: ["The presentation has no language set.", ...notes].join(" "),
|
|
3032
|
+
help: !first ? 'Set `language` to a BCP 47 tag, for example "en-US".' : read.size === 1 && read.get(first)?.length === context.slides.length ? `Set \`language\` to say so, for example "${first}", or to another BCP 47 tag to choose differently.` : `Set the deck's \`language\` to its main language, and \`language\` on those slides to say so (for example "${first}") or to choose differently.`,
|
|
2872
3033
|
fixes: [{ id: "focus-language", title: "Set the language", kind: "focus", safe: true, focus: { path: "/language", field: "language" } }]
|
|
2873
3034
|
});
|
|
2874
3035
|
}
|
|
@@ -2986,127 +3147,464 @@ var languageTagRules = [
|
|
|
2986
3147
|
}
|
|
2987
3148
|
];
|
|
2988
3149
|
|
|
2989
|
-
// src/
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
const key3 = `${diagnostic.code}|${path}|${diagnostic.message}`;
|
|
3009
|
-
if (deckLevel.has(key3)) continue;
|
|
3010
|
-
deckLevel.add(key3);
|
|
3011
|
-
}
|
|
3012
|
-
if (diagnostic.code === "text-overflow")
|
|
3013
|
-
context.report(overflowRule, { path, slide, message: diagnostic.message, help: "Shorten the text, give it more space (fewer blocks, a different composition) or split the slide (paginate); raising the readable minimum makes it worse." });
|
|
3014
|
-
else if (diagnostic.code === "shape-anchor-missing") context.report(pointAnchorRule, { path, slide, message: diagnostic.message, help: "Choose a plotted point in a qualified classic chart, or use a whole-block anchor." });
|
|
3015
|
-
else if (diagnostic.code === "small-cell") continue;
|
|
3016
|
-
else if (diagnostic.code === "icon-dropped")
|
|
3017
|
-
context.report(iconDroppedRule, { path, slide, message: diagnostic.message, help: "Shorten the text or give the slide more room so the chips fit at the same text size, or remove the icon. An icon draws on the first-level entries of an unnumbered list, on a metric and on a group." });
|
|
3018
|
-
else if (diagnostic.code === "arrangement-adapted")
|
|
3019
|
-
context.report(arrangementAdaptedRule, { path, slide, message: diagnostic.message, help: /four entries/.test(diagnostic.message) ? "Write four entries for the quadrants, or choose another layout for this many." : "Shorten the entries, write one level without descriptions, or choose another layout." });
|
|
3020
|
-
else if (diagnostic.code === "shape-off-slide")
|
|
3021
|
-
context.report(shapeOffSlideRule, { path, slide, message: diagnostic.message, help: "Write the position as fractions (0.2 for 20%), move the shape so part of it is on the slide, or remove it. A shape may hang over an edge; only one with nothing on the slide is reported." });
|
|
3022
|
-
else if (diagnostic.code === "chart-label-collision")
|
|
3023
|
-
context.report(chartLabelCollisionRule, { path, slide, message: diagnostic.message, help: "Put the label at the other end of its line (labelPosition 'start' or 'end'), shorten it, or give the chart more room. Its text and value are kept." });
|
|
3024
|
-
else if (diagnostic.code === "timeline-period-short")
|
|
3025
|
-
context.report(timelinePeriodShortRule, { path, slide, message: diagnostic.message, help: "Give the timeline more room, or make its shortest period longer relative to the others." });
|
|
3026
|
-
else if (Object.hasOwn(REGION_RULES, diagnostic.code))
|
|
3027
|
-
context.report(REGION_RULES[diagnostic.code], { path, slide, message: diagnostic.message, help: diagnostic.code === "layout-unplaced" ? "Paginate the slide, choose a layout with more room, pin the block to a region with room, or remove a block." : "Pin the block to a region of the layout that accepts it and has room, or remove the pin." });
|
|
3028
|
-
else if (diagnostic.message.startsWith("The diagram cannot be drawn"))
|
|
3029
|
-
context.report(unresolvedRule, { path, slide: path.startsWith("/slides/") ? slide : void 0, message: diagnostic.message, help: "Fix the diagram source where the message points. OPF refuses what it does not draw: write it in the form the diagrams guide lists for that syntax, or remove it." });
|
|
3030
|
-
else context.report(unresolvedRule, { path, slide: path.startsWith("/slides/") ? slide : void 0, message: diagnostic.message, help: "Supply what the message asks for, or remove the setting that cannot be honoured." });
|
|
3031
|
-
}
|
|
3032
|
-
for (const tv of slide.texts)
|
|
3033
|
-
for (const run of runsOf(tv))
|
|
3034
|
-
if (typeof run.style.fontSize === "number" && run.style.fontSize < context.thresholds.minFontSizePt)
|
|
3035
|
-
context.report(minFontRule, {
|
|
3036
|
-
path: `${run.path}/fontSize`,
|
|
3037
|
-
slide,
|
|
3038
|
-
message: `Text run is set to ${run.style.fontSize} pt, below the ${context.thresholds.minFontSizePt} pt minimum.`,
|
|
3039
|
-
help: "Remove the size override so the text uses the fitted size, or raise it.",
|
|
3040
|
-
measured: { sizePt: run.style.fontSize, minimumPt: context.thresholds.minFontSizePt },
|
|
3041
|
-
fixes: [{ id: "focus-font-size", title: "Edit the size", kind: "focus", safe: true, focus: { path: `${run.path}/fontSize`, field: "fontSize" } }]
|
|
3042
|
-
});
|
|
3043
|
-
const composition = slide.composition;
|
|
3044
|
-
if (!composition) continue;
|
|
3045
|
-
const scale = Math.min(composition.width, composition.height) / 720;
|
|
3046
|
-
const limitPx = context.thresholds.minFontSizePt / PX_TO_PT2;
|
|
3047
|
-
const small = (path, sizes, label) => {
|
|
3048
|
-
const known = sizes.filter((size) => size !== void 0);
|
|
3049
|
-
const sizePx = known.length ? Math.min(...known) / scale : void 0;
|
|
3050
|
-
if (sizePx === void 0 || sizePx >= limitPx - 1e-6) return;
|
|
3051
|
-
context.report(minFontRule, {
|
|
3052
|
-
path,
|
|
3053
|
-
slide,
|
|
3054
|
-
message: `${label} is drawn at ${round2(sizePx * PX_TO_PT2)} pt${scale === 1 ? "" : " (reference slide size)"}, below the ${context.thresholds.minFontSizePt} pt minimum.`,
|
|
3055
|
-
help: "Shorten the text or give it more room so it can be drawn larger; check composition.minFontSize and run fontSize settings that force small type.",
|
|
3056
|
-
measured: { sizePt: round2(sizePx * PX_TO_PT2, 2), minimumPt: context.thresholds.minFontSizePt }
|
|
3057
|
-
});
|
|
3058
|
-
};
|
|
3059
|
-
for (const item of composition.items) {
|
|
3060
|
-
if (item.field === "code" || item.field === "table" || item.type === "code" || item.type === "table") continue;
|
|
3061
|
-
const layout = item.quoteLayout ?? item.metricLayout ?? item.timelineLayout;
|
|
3062
|
-
if (layout) small(pointerOfDotted(item.path), layout.parts.map((part) => part.visible === false ? void 0 : part.fit?.fontSize), "The smallest text");
|
|
3063
|
-
else small(pointerOfDotted(item.path), [item.text?.fontSize], item.field === "title" ? "Title" : "Text");
|
|
3064
|
-
}
|
|
3150
|
+
// src/document-hash.ts
|
|
3151
|
+
function canonicalJson(value) {
|
|
3152
|
+
const stack = [];
|
|
3153
|
+
const write = (item) => {
|
|
3154
|
+
if (item === null || typeof item === "boolean" || typeof item === "string") return JSON.stringify(item);
|
|
3155
|
+
if (typeof item === "number") return JSON.stringify(item);
|
|
3156
|
+
if (typeof item === "bigint") throw new TypeError("A BigInt is not JSON.");
|
|
3157
|
+
if (typeof item !== "object") return void 0;
|
|
3158
|
+
if (stack.includes(item)) throw new TypeError("A cyclic value has no canonical JSON.");
|
|
3159
|
+
stack.push(item);
|
|
3160
|
+
let text2;
|
|
3161
|
+
if (Array.isArray(item)) {
|
|
3162
|
+
text2 = `[${item.map((entry2) => write(entry2) ?? "null").join(",")}]`;
|
|
3163
|
+
} else {
|
|
3164
|
+
const record = item;
|
|
3165
|
+
const members = [];
|
|
3166
|
+
for (const key3 of Object.keys(record).sort()) {
|
|
3167
|
+
const member = write(record[key3]);
|
|
3168
|
+
if (member !== void 0) members.push(`${JSON.stringify(key3)}:${member}`);
|
|
3065
3169
|
}
|
|
3170
|
+
text2 = `{${members.join(",")}}`;
|
|
3066
3171
|
}
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3172
|
+
stack.pop();
|
|
3173
|
+
return text2;
|
|
3174
|
+
};
|
|
3175
|
+
return write(value) ?? "null";
|
|
3176
|
+
}
|
|
3177
|
+
var K = new Uint32Array([
|
|
3178
|
+
1116352408,
|
|
3179
|
+
1899447441,
|
|
3180
|
+
3049323471,
|
|
3181
|
+
3921009573,
|
|
3182
|
+
961987163,
|
|
3183
|
+
1508970993,
|
|
3184
|
+
2453635748,
|
|
3185
|
+
2870763221,
|
|
3186
|
+
3624381080,
|
|
3187
|
+
310598401,
|
|
3188
|
+
607225278,
|
|
3189
|
+
1426881987,
|
|
3190
|
+
1925078388,
|
|
3191
|
+
2162078206,
|
|
3192
|
+
2614888103,
|
|
3193
|
+
3248222580,
|
|
3194
|
+
3835390401,
|
|
3195
|
+
4022224774,
|
|
3196
|
+
264347078,
|
|
3197
|
+
604807628,
|
|
3198
|
+
770255983,
|
|
3199
|
+
1249150122,
|
|
3200
|
+
1555081692,
|
|
3201
|
+
1996064986,
|
|
3202
|
+
2554220882,
|
|
3203
|
+
2821834349,
|
|
3204
|
+
2952996808,
|
|
3205
|
+
3210313671,
|
|
3206
|
+
3336571891,
|
|
3207
|
+
3584528711,
|
|
3208
|
+
113926993,
|
|
3209
|
+
338241895,
|
|
3210
|
+
666307205,
|
|
3211
|
+
773529912,
|
|
3212
|
+
1294757372,
|
|
3213
|
+
1396182291,
|
|
3214
|
+
1695183700,
|
|
3215
|
+
1986661051,
|
|
3216
|
+
2177026350,
|
|
3217
|
+
2456956037,
|
|
3218
|
+
2730485921,
|
|
3219
|
+
2820302411,
|
|
3220
|
+
3259730800,
|
|
3221
|
+
3345764771,
|
|
3222
|
+
3516065817,
|
|
3223
|
+
3600352804,
|
|
3224
|
+
4094571909,
|
|
3225
|
+
275423344,
|
|
3226
|
+
430227734,
|
|
3227
|
+
506948616,
|
|
3228
|
+
659060556,
|
|
3229
|
+
883997877,
|
|
3230
|
+
958139571,
|
|
3231
|
+
1322822218,
|
|
3232
|
+
1537002063,
|
|
3233
|
+
1747873779,
|
|
3234
|
+
1955562222,
|
|
3235
|
+
2024104815,
|
|
3236
|
+
2227730452,
|
|
3237
|
+
2361852424,
|
|
3238
|
+
2428436474,
|
|
3239
|
+
2756734187,
|
|
3240
|
+
3204031479,
|
|
3241
|
+
3329325298
|
|
3242
|
+
]);
|
|
3243
|
+
function sha256Hex(bytes) {
|
|
3244
|
+
const length = bytes.length;
|
|
3245
|
+
const padded = new Uint8Array(length + 9 + 63 >> 6 << 6);
|
|
3246
|
+
padded.set(bytes);
|
|
3247
|
+
padded[length] = 128;
|
|
3248
|
+
const view = new DataView(padded.buffer);
|
|
3249
|
+
view.setUint32(padded.length - 8, Math.floor(length / 536870912), false);
|
|
3250
|
+
view.setUint32(padded.length - 4, length << 3 >>> 0, false);
|
|
3251
|
+
const h = new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]);
|
|
3252
|
+
const w = new Uint32Array(64);
|
|
3253
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
3254
|
+
for (let i = 0; i < 16; i += 1) w[i] = view.getUint32(offset + i * 4, false);
|
|
3255
|
+
for (let i = 16; i < 64; i += 1) {
|
|
3256
|
+
const a2 = w[i - 15], b2 = w[i - 2];
|
|
3257
|
+
const s0 = (a2 >>> 7 | a2 << 25) ^ (a2 >>> 18 | a2 << 14) ^ a2 >>> 3;
|
|
3258
|
+
const s1 = (b2 >>> 17 | b2 << 15) ^ (b2 >>> 19 | b2 << 13) ^ b2 >>> 10;
|
|
3259
|
+
w[i] = w[i - 16] + s0 + w[i - 7] + s1 | 0;
|
|
3260
|
+
}
|
|
3261
|
+
let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];
|
|
3262
|
+
for (let i = 0; i < 64; i += 1) {
|
|
3263
|
+
const s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
3264
|
+
const choose = e & f ^ ~e & g;
|
|
3265
|
+
const t1 = hh + s1 + choose + K[i] + w[i] | 0;
|
|
3266
|
+
const s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
3267
|
+
const majority = a & b ^ a & c ^ b & c;
|
|
3268
|
+
const t2 = s0 + majority | 0;
|
|
3269
|
+
hh = g;
|
|
3270
|
+
g = f;
|
|
3271
|
+
f = e;
|
|
3272
|
+
e = d + t1 | 0;
|
|
3273
|
+
d = c;
|
|
3274
|
+
c = b;
|
|
3275
|
+
b = a;
|
|
3276
|
+
a = t1 + t2 | 0;
|
|
3277
|
+
}
|
|
3278
|
+
h[0] = h[0] + a | 0;
|
|
3279
|
+
h[1] = h[1] + b | 0;
|
|
3280
|
+
h[2] = h[2] + c | 0;
|
|
3281
|
+
h[3] = h[3] + d | 0;
|
|
3282
|
+
h[4] = h[4] + e | 0;
|
|
3283
|
+
h[5] = h[5] + f | 0;
|
|
3284
|
+
h[6] = h[6] + g | 0;
|
|
3285
|
+
h[7] = h[7] + hh | 0;
|
|
3286
|
+
}
|
|
3287
|
+
let hex = "";
|
|
3288
|
+
for (const word of h) hex += word.toString(16).padStart(8, "0");
|
|
3289
|
+
return hex;
|
|
3290
|
+
}
|
|
3291
|
+
function documentHash(document) {
|
|
3292
|
+
return `sha256:${sha256Hex(new TextEncoder().encode(canonicalJson(document)))}`;
|
|
3293
|
+
}
|
|
3294
|
+
var HASH_PATTERN = /^(?:sha256:)?([0-9a-fA-F]{64})$/;
|
|
3295
|
+
function normalizeDocumentHash(value) {
|
|
3296
|
+
if (typeof value !== "string") return void 0;
|
|
3297
|
+
const match2 = HASH_PATTERN.exec(value);
|
|
3298
|
+
return match2 ? `sha256:${match2[1].toLowerCase()}` : void 0;
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
// src/stale-records.ts
|
|
3302
|
+
var isRec2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3303
|
+
var rec2 = (value) => isRec2(value) ? value : {};
|
|
3304
|
+
var part = (value) => String(value).replaceAll("~", "~0").replaceAll("/", "~1");
|
|
3305
|
+
var pointer3 = (segments) => `/${segments.map(part).join("/")}`;
|
|
3306
|
+
var slideAt = (document, index) => {
|
|
3307
|
+
const slides = rec2(document).slides;
|
|
3308
|
+
return Array.isArray(slides) ? rec2(slides[index]) : {};
|
|
3309
|
+
};
|
|
3310
|
+
var embeddedLayouts = (document, group) => rec2(rec2(rec2(rec2(document).catalogs)[group]).layouts);
|
|
3311
|
+
var RENAMED_REGIONS = Object.freeze({
|
|
3312
|
+
agenda: { items: "body" },
|
|
3313
|
+
"agenda-split": { items: "body" },
|
|
3314
|
+
chart: { charts: "body", note: "aside" },
|
|
3315
|
+
"chart-beside": { chart: "body", notes: "aside" },
|
|
3316
|
+
chevrons: { stages: "body" },
|
|
3317
|
+
closing: { details: "body" },
|
|
3318
|
+
code: { code: "body", notes: "aside" },
|
|
3319
|
+
comparison: { verdict: "aside" },
|
|
3320
|
+
cycle: { stages: "body" },
|
|
3321
|
+
dashboard: { kpis: "lead", charts: "body" },
|
|
3322
|
+
faq: { questions: "body" },
|
|
3323
|
+
flow: { stages: "body" },
|
|
3324
|
+
gallery: { pictures: "body" },
|
|
3325
|
+
hero: { support: "body" },
|
|
3326
|
+
hierarchy: { nodes: "body" },
|
|
3327
|
+
"inverted-pyramid": { levels: "body" },
|
|
3328
|
+
logos: { logos: "body" },
|
|
3329
|
+
matrix: { quadrants: "body" },
|
|
3330
|
+
metrics: { metrics: "body", note: "aside" },
|
|
3331
|
+
"org-chart": { people: "body" },
|
|
3332
|
+
pillars: { pillars: "body" },
|
|
3333
|
+
process: { steps: "body", stages: "body" },
|
|
3334
|
+
pyramid: { levels: "body" },
|
|
3335
|
+
quote: { quotes: "body" },
|
|
3336
|
+
scorecard: { cards: "body" },
|
|
3337
|
+
statement: { message: "body" },
|
|
3338
|
+
table: { table: "body", note: "aside" },
|
|
3339
|
+
"table-beside": { table: "body", notes: "aside" },
|
|
3340
|
+
team: { people: "body" },
|
|
3341
|
+
timeline: { timeline: "body", notes: "aside" },
|
|
3342
|
+
venn: { sets: "body" },
|
|
3343
|
+
"vertical-flow": { stages: "body" },
|
|
3344
|
+
"vertical-process": { stages: "body" }
|
|
3345
|
+
});
|
|
3346
|
+
function renamedRegion(layout, region) {
|
|
3347
|
+
const names2 = Object.hasOwn(RENAMED_REGIONS, layout) ? RENAMED_REGIONS[layout] : void 0;
|
|
3348
|
+
return names2 && Object.hasOwn(names2, region) ? names2[region] : void 0;
|
|
3349
|
+
}
|
|
3350
|
+
function layoutRegionNames(record) {
|
|
3351
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
3352
|
+
const walk2 = (regions) => {
|
|
3353
|
+
if (!Array.isArray(regions)) return;
|
|
3354
|
+
for (const region of regions) {
|
|
3355
|
+
if (!isRec2(region)) continue;
|
|
3356
|
+
if (typeof region.name === "string") names2.add(region.name);
|
|
3357
|
+
walk2(region.regions);
|
|
3358
|
+
}
|
|
3359
|
+
};
|
|
3360
|
+
walk2(rec2(record).regions);
|
|
3361
|
+
return names2;
|
|
3362
|
+
}
|
|
3363
|
+
function layoutRecordIssues(id, record) {
|
|
3364
|
+
return validateAgainstSchema(isRec2(record) ? { $schema: schemas[catalogSchemaNames.layouts].$id, id, ...record } : record, "layouts").errors;
|
|
3365
|
+
}
|
|
3366
|
+
function staleLayoutCopy(document, group, id, options2 = {}) {
|
|
3367
|
+
if (group === "custom") return void 0;
|
|
3368
|
+
const record = embeddedLayouts(document, group)[id];
|
|
3369
|
+
if (!isRec2(record)) return void 0;
|
|
3370
|
+
const registered = rec2(registeredCatalog(catalogGroupSource(document, group, options2), options2)?.layouts);
|
|
3371
|
+
const base = { group, id, path: pointer3(["catalogs", group, "layouts", id]) };
|
|
3372
|
+
if (isRec2(registered[id])) return { ...base, current: embeddedCopy(registered[id]) };
|
|
3373
|
+
const next = renamedLayout("layouts", id);
|
|
3374
|
+
if (next === void 0) return void 0;
|
|
3375
|
+
const position = renamedLayoutTitlePosition("layouts", id);
|
|
3376
|
+
return { ...base, renamed: { id: next, ...isRec2(registered[next]) ? { current: embeddedCopy(registered[next]) } : {}, ...position ? { titlePosition: position } : {} } };
|
|
3377
|
+
}
|
|
3378
|
+
function staleCopyCause(copy) {
|
|
3379
|
+
const head = `catalogs.${copy.group}.layouts.${copy.id} is a copy of the built-in layout '${copy.id}' from before OPF 0.35${copy.renamed ? `, which 0.35 removed (use '${copy.renamed.id}')` : ""}; 0.35 changed the keys of the built-in records, so the copy fails the 0.35 layout schema.`;
|
|
3380
|
+
const mirror = `catalogs.${copy.group} mirrors the built-in records (keep a customized layout in catalogs.custom), and the 0.35 engine draws the slides, which may look different.`;
|
|
3381
|
+
if (copy.renamed) return `${head} The fix rename-layout (\`opf fix -i\` and \`opf embed -i\` apply it) moves its slides to '${copy.renamed.id}'${copy.renamed.titlePosition ? ` with design.titlePosition "${copy.renamed.titlePosition}"` : ""} and drops the copy; ${mirror}`;
|
|
3382
|
+
return `${head} The fix use-current-record (\`opf fix -i\` and \`opf embed -i\` apply it) replaces it with the current record and renames the region pins of its slides; ${mirror}`;
|
|
3383
|
+
}
|
|
3384
|
+
function slidesUsing(document, copy, options2) {
|
|
3385
|
+
const slides = rec2(document).slides;
|
|
3386
|
+
const using = [];
|
|
3387
|
+
(Array.isArray(slides) ? slides : []).forEach((slide, index) => {
|
|
3388
|
+
const reference = rec2(slide).layout;
|
|
3389
|
+
if (typeof reference !== "string") return;
|
|
3390
|
+
const found = resolveReference(document, "layouts", reference, options2);
|
|
3391
|
+
if (found?.origin === "document" && found.group === copy.group && found.id === copy.id) using.push({ index, reference });
|
|
3392
|
+
});
|
|
3393
|
+
return using;
|
|
3394
|
+
}
|
|
3395
|
+
function pinOperations(document, index, layout, before, next) {
|
|
3396
|
+
const names2 = layoutRegionNames(next);
|
|
3397
|
+
const blocks = slideAt(document, index).blocks;
|
|
3398
|
+
const ops = [];
|
|
3399
|
+
(Array.isArray(blocks) ? blocks : []).forEach((block, at2) => {
|
|
3400
|
+
const pin = rec2(block).region;
|
|
3401
|
+
if (typeof pin !== "string" || names2.has(pin) || !before.has(pin)) return;
|
|
3402
|
+
const renamed = renamedRegion(layout, pin);
|
|
3403
|
+
if (renamed !== void 0 && names2.has(renamed)) ops.push({ op: "replace", path: pointer3(["slides", index, "blocks", at2, "region"]), value: renamed });
|
|
3404
|
+
});
|
|
3405
|
+
return ops;
|
|
3406
|
+
}
|
|
3407
|
+
function titlePositionOperations(document, index, position) {
|
|
3408
|
+
if (position === void 0) return [];
|
|
3409
|
+
const design = slideAt(document, index).design;
|
|
3410
|
+
if (isRec2(design) && design.titlePosition !== void 0) return [];
|
|
3411
|
+
return isRec2(design) ? [{ op: "add", path: pointer3(["slides", index, "design", "titlePosition"]), value: position }] : [{ op: "add", path: pointer3(["slides", index, "design"]), value: { titlePosition: position } }];
|
|
3412
|
+
}
|
|
3413
|
+
function droppedCopyOperations(document, copy) {
|
|
3414
|
+
if (!copy.renamed) return [];
|
|
3415
|
+
const ops = [{ op: "remove", path: copy.path }];
|
|
3416
|
+
if (copy.renamed.current && !Object.hasOwn(embeddedLayouts(document, copy.group), copy.renamed.id)) ops.push({ op: "add", path: pointer3(["catalogs", copy.group, "layouts", copy.renamed.id]), value: copy.renamed.current });
|
|
3417
|
+
return ops;
|
|
3418
|
+
}
|
|
3419
|
+
function staleCopyUsers(document, copy, options2 = {}) {
|
|
3420
|
+
return slidesUsing(document, copy, options2).map((entry2) => entry2.index);
|
|
3421
|
+
}
|
|
3422
|
+
function staleCopyPatch(document, copy, options2 = {}) {
|
|
3423
|
+
const before = layoutRegionNames(embeddedLayouts(document, copy.group)[copy.id]);
|
|
3424
|
+
const using = slidesUsing(document, copy, options2);
|
|
3425
|
+
if (copy.current) return [{ op: "replace", path: copy.path, value: copy.current }, ...using.flatMap(({ index }) => pinOperations(document, index, copy.id, before, copy.current))];
|
|
3426
|
+
if (!copy.renamed) return void 0;
|
|
3427
|
+
const replacement = copy.renamed.current ?? embeddedLayouts(document, copy.group)[copy.renamed.id];
|
|
3428
|
+
const ops = [];
|
|
3429
|
+
for (const { index, reference } of using) {
|
|
3430
|
+
ops.push({ op: "replace", path: pointer3(["slides", index, "layout"]), value: renamedLayout("layouts", reference) ?? copy.renamed.id }, ...titlePositionOperations(document, index, copy.renamed.titlePosition));
|
|
3431
|
+
if (isRec2(replacement)) ops.push(...pinOperations(document, index, copy.id, before, replacement));
|
|
3432
|
+
}
|
|
3433
|
+
return [...ops, ...droppedCopyOperations(document, copy)];
|
|
3434
|
+
}
|
|
3435
|
+
var recordChanged = (document, copy, target) => !isRec2(target) || documentHash(embeddedLayouts(document, copy.group)[copy.id]) !== documentHash(target);
|
|
3436
|
+
var replacementOf = (document, copy) => copy.current ?? copy.renamed?.current ?? (copy.renamed ? embeddedLayouts(document, copy.group)[copy.renamed.id] : void 0);
|
|
3437
|
+
function staleCopyFix(document, copy, options2 = {}) {
|
|
3438
|
+
const patch2 = staleCopyPatch(document, copy, options2);
|
|
3439
|
+
if (!patch2) return void 0;
|
|
3440
|
+
const marks = { kind: "patch", safe: true, ...recordChanged(document, copy, replacementOf(document, copy)) ? { changesDrawing: true } : {}, patch: patch2 };
|
|
3441
|
+
return copy.renamed ? { id: "rename-layout", title: `Use layout ${copy.renamed.id} and drop the old copy of ${copy.id}`, ...marks } : { id: "use-current-record", title: `Take the current ${copy.id} record`, ...marks };
|
|
3442
|
+
}
|
|
3443
|
+
var applyOperation = (root, operation) => {
|
|
3444
|
+
const segmentsOf2 = (path) => path.slice(1).split("/").map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
3445
|
+
const parentOf2 = (segments2) => segments2.slice(0, -1).reduce((node, segment) => node[segment], root);
|
|
3446
|
+
const segments = segmentsOf2(operation.path);
|
|
3447
|
+
if (operation.op === "move") {
|
|
3448
|
+
const from = segmentsOf2(operation.from);
|
|
3449
|
+
const value = parentOf2(from)[from.at(-1)];
|
|
3450
|
+
delete parentOf2(from)[from.at(-1)];
|
|
3451
|
+
parentOf2(segments)[segments.at(-1)] = value;
|
|
3452
|
+
} else if (operation.op === "remove") delete parentOf2(segments)[segments.at(-1)];
|
|
3453
|
+
else if (operation.op === "add" || operation.op === "replace") parentOf2(segments)[segments.at(-1)] = structuredClone(operation.value);
|
|
3454
|
+
};
|
|
3455
|
+
function refreshStaleLayouts(document, options2 = {}) {
|
|
3456
|
+
const refreshed = [];
|
|
3457
|
+
for (const [group, value] of Object.entries(rec2(document.catalogs))) {
|
|
3458
|
+
if (group === "custom" || !isRec2(value) || !isRec2(value.layouts)) continue;
|
|
3459
|
+
for (const [id, record] of Object.entries(value.layouts)) {
|
|
3460
|
+
if (!layoutRecordIssues(id, record).length) continue;
|
|
3461
|
+
const copy = staleLayoutCopy(document, group, id, options2);
|
|
3462
|
+
if (!copy || !(copy.current || copy.renamed?.current)) continue;
|
|
3463
|
+
const patch2 = staleCopyPatch(document, copy, options2);
|
|
3464
|
+
if (!patch2) continue;
|
|
3465
|
+
const changed = recordChanged(document, copy, replacementOf(document, copy));
|
|
3466
|
+
for (const operation of patch2) applyOperation(document, operation);
|
|
3467
|
+
const source = catalogGroupSource(document, group, options2);
|
|
3468
|
+
refreshed.push({ group, kind: "layouts", id, ...source !== void 0 ? { source } : {}, how: copy.renamed ? "renamed" : "current", ...copy.renamed ? { renamedTo: copy.renamed.id } : {}, ...changed ? { changesDrawing: true } : {}, references: patch2.filter((operation) => operation.path.startsWith("/slides/")).map((operation) => operation.path) });
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
return refreshed;
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
// src/rules-layout-content.ts
|
|
3475
|
+
var PX_TO_PT2 = 0.75;
|
|
3476
|
+
var round2 = (value, places = 1) => Math.round(value * 10 ** places) / 10 ** places;
|
|
3477
|
+
var pointAnchorRule = ruleInfo("opf/shape-anchor-missing");
|
|
3478
|
+
var REGION_RULES = { "region-unknown": regionUnknownRule, "region-kind": regionKindRule, "region-full": regionFullRule, "layout-unplaced": unplacedRule };
|
|
3479
|
+
function renamedPin(context, slide, path, pin) {
|
|
3480
|
+
const reference = slide.slide.layout;
|
|
3481
|
+
if (typeof pin !== "string" || typeof reference !== "string") return void 0;
|
|
3482
|
+
const found = resolveReference(context.document, "layouts", reference, { ...context.options.catalogs ? { catalogs: context.options.catalogs } : {} });
|
|
3483
|
+
if (!found || found.group !== "default") return void 0;
|
|
3484
|
+
const next = renamedRegion(found.id, pin);
|
|
3485
|
+
if (next === void 0 || !layoutRegionNames(found.record).has(next)) return void 0;
|
|
3486
|
+
return {
|
|
3487
|
+
help: `OPF 0.35 renamed region '${pin}' of the built-in layout '${found.id}' to '${next}' (the built-in layouts use the standard region names). Rename the pin (fix rename-region), which puts the block back in that region.`,
|
|
3488
|
+
fix: { id: "rename-region", title: `Pin to ${next}`, kind: "patch", safe: true, patch: [{ op: "replace", path, value: next }] }
|
|
3489
|
+
};
|
|
3490
|
+
}
|
|
3491
|
+
var layoutRules = [
|
|
3492
|
+
{
|
|
3493
|
+
info: overflowRule,
|
|
3494
|
+
// Format validates anchor identities in schema-check without composition. Geometry may add
|
|
3495
|
+
// the same located finding during an enabled layout audit, but must not trigger one.
|
|
3496
|
+
also: [unresolvedRule, layoutFailedRule, minFontRule, regionUnknownRule, regionKindRule, regionFullRule, unplacedRule, iconDroppedRule, arrangementAdaptedRule, chartLabelCollisionRule, timelinePeriodShortRule, shapeOffSlideRule],
|
|
3497
|
+
run(context) {
|
|
3498
|
+
const deckLevel = /* @__PURE__ */ new Set();
|
|
3499
|
+
for (const slide of context.slides) {
|
|
3500
|
+
if (slide.layoutError)
|
|
3501
|
+
context.report(layoutFailedRule, { path: slide.path, slide, message: `Layout failed: ${slide.layoutError}`, help: "Fix the composition settings or content structure named in the message; geometry-based rules were skipped for this slide." });
|
|
3502
|
+
for (const { diagnostic } of slide.layoutDiagnostics) {
|
|
3503
|
+
const path = pointerOfDotted(diagnostic.path);
|
|
3504
|
+
if (!path.startsWith("/slides/")) {
|
|
3505
|
+
const key3 = `${diagnostic.code}|${path}|${diagnostic.message}`;
|
|
3506
|
+
if (deckLevel.has(key3)) continue;
|
|
3507
|
+
deckLevel.add(key3);
|
|
3508
|
+
}
|
|
3509
|
+
if (diagnostic.code === "text-overflow")
|
|
3510
|
+
context.report(overflowRule, { path, slide, message: diagnostic.message, help: "Shorten the text, give it more space (fewer blocks, a different composition) or split the slide (paginate); raising the readable minimum makes it worse." });
|
|
3511
|
+
else if (diagnostic.code === "shape-anchor-missing") context.report(pointAnchorRule, { path, slide, message: diagnostic.message, help: "Choose a plotted point in a qualified classic chart, or use a whole-block anchor." });
|
|
3512
|
+
else if (diagnostic.code === "small-cell") continue;
|
|
3513
|
+
else if (diagnostic.code === "icon-dropped")
|
|
3514
|
+
context.report(iconDroppedRule, { path, slide, message: diagnostic.message, help: "Give the block more room where the message says what bounds it (a larger share in `composition.weights`, a larger region, fewer blocks beside it), use fewer or shorter entries, or remove the icon: chips are drawn only where the text keeps its size. An icon draws on the first-level entries of an unnumbered list, on a metric and on a group." });
|
|
3515
|
+
else if (diagnostic.code === "arrangement-adapted")
|
|
3516
|
+
context.report(arrangementAdaptedRule, { path, slide, message: diagnostic.message, help: /four entries/.test(diagnostic.message) ? "Write four entries for the quadrants, or choose another layout for this many." : "Shorten the entries, write one level without descriptions, or choose another layout." });
|
|
3517
|
+
else if (diagnostic.code === "shape-off-slide")
|
|
3518
|
+
context.report(shapeOffSlideRule, { path, slide, message: diagnostic.message, help: "Write the position as fractions (0.2 for 20%), move the shape so part of it is on the slide, or remove it. A shape may hang over an edge; only one with nothing on the slide is reported." });
|
|
3519
|
+
else if (diagnostic.code === "chart-label-collision")
|
|
3520
|
+
context.report(chartLabelCollisionRule, { path, slide, message: diagnostic.message, help: "Put the label at the other end of its line (labelPosition 'start' or 'end'), shorten it, or give the chart more room. Its text and value are kept." });
|
|
3521
|
+
else if (diagnostic.code === "timeline-period-short")
|
|
3522
|
+
context.report(timelinePeriodShortRule, { path, slide, message: diagnostic.message, help: "Give the timeline more room, or make its shortest period longer relative to the others." });
|
|
3523
|
+
else if (Object.hasOwn(REGION_RULES, diagnostic.code)) {
|
|
3524
|
+
const renamed = diagnostic.code === "region-unknown" ? renamedPin(context, slide, path, diagnostic.region) : void 0;
|
|
3525
|
+
context.report(REGION_RULES[diagnostic.code], { path, slide, message: diagnostic.message, help: renamed?.help ?? (diagnostic.code === "layout-unplaced" ? "Paginate the slide, choose a layout with more room, pin the block to a region with room, or remove a block." : "Pin the block to a region of the layout that accepts it and has room, or remove the pin."), ...renamed ? { fixes: [renamed.fix] } : {} });
|
|
3526
|
+
} else if (diagnostic.message.startsWith("The diagram cannot be drawn"))
|
|
3527
|
+
context.report(unresolvedRule, { path, slide: path.startsWith("/slides/") ? slide : void 0, message: diagnostic.message, help: "Fix the diagram source where the message points. OPF refuses what it does not draw: write it in the form the diagrams guide lists for that syntax, or remove it." });
|
|
3528
|
+
else context.report(unresolvedRule, { path, slide: path.startsWith("/slides/") ? slide : void 0, message: diagnostic.message, help: "Supply what the message asks for, or remove the setting that cannot be honored." });
|
|
3529
|
+
}
|
|
3530
|
+
for (const tv of slide.texts)
|
|
3531
|
+
for (const run of runsOf(tv))
|
|
3532
|
+
if (typeof run.style.fontSize === "number" && run.style.fontSize < context.thresholds.minFontSizePt)
|
|
3533
|
+
context.report(minFontRule, {
|
|
3534
|
+
path: `${run.path}/fontSize`,
|
|
3535
|
+
slide,
|
|
3536
|
+
message: `Text run is set to ${run.style.fontSize} pt, below the ${context.thresholds.minFontSizePt} pt minimum.`,
|
|
3537
|
+
help: "Remove the size override so the text uses the fitted size, or raise it.",
|
|
3538
|
+
measured: { sizePt: run.style.fontSize, minimumPt: context.thresholds.minFontSizePt },
|
|
3539
|
+
fixes: [{ id: "focus-font-size", title: "Edit the size", kind: "focus", safe: true, focus: { path: `${run.path}/fontSize`, field: "fontSize" } }]
|
|
3540
|
+
});
|
|
3541
|
+
const composition = slide.composition;
|
|
3542
|
+
if (!composition) continue;
|
|
3543
|
+
const scale = Math.min(composition.width, composition.height) / 720;
|
|
3544
|
+
const limitPx = context.thresholds.minFontSizePt / PX_TO_PT2;
|
|
3545
|
+
const small = (path, sizes, label) => {
|
|
3546
|
+
const known = sizes.filter((size) => size !== void 0);
|
|
3547
|
+
const sizePx = known.length ? Math.min(...known) / scale : void 0;
|
|
3548
|
+
if (sizePx === void 0 || sizePx >= limitPx - 1e-6) return;
|
|
3549
|
+
context.report(minFontRule, {
|
|
3550
|
+
path,
|
|
3551
|
+
slide,
|
|
3552
|
+
message: `${label} is drawn at ${round2(sizePx * PX_TO_PT2)} pt${scale === 1 ? "" : " (reference slide size)"}, below the ${context.thresholds.minFontSizePt} pt minimum.`,
|
|
3553
|
+
help: "Shorten the text or give it more room so it can be drawn larger; check composition.minFontSize and run fontSize settings that force small type.",
|
|
3554
|
+
measured: { sizePt: round2(sizePx * PX_TO_PT2, 2), minimumPt: context.thresholds.minFontSizePt }
|
|
3555
|
+
});
|
|
3556
|
+
};
|
|
3557
|
+
for (const item of composition.items) {
|
|
3558
|
+
if (item.field === "code" || item.field === "table" || item.type === "code" || item.type === "table") continue;
|
|
3559
|
+
const layout = item.quoteLayout ?? item.metricLayout ?? item.timelineLayout;
|
|
3560
|
+
if (layout) small(pointerOfDotted(item.path), layout.parts.map((part2) => part2.visible === false ? void 0 : part2.fit?.fontSize), "The smallest text");
|
|
3561
|
+
else small(pointerOfDotted(item.path), [item.text?.fontSize], item.field === "title" ? "Title" : "Text");
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
},
|
|
3566
|
+
{
|
|
3567
|
+
info: furnitureWrapsRule,
|
|
3568
|
+
run(context) {
|
|
3569
|
+
const reported = /* @__PURE__ */ new Set();
|
|
3570
|
+
for (const slide of context.slides)
|
|
3571
|
+
for (const part2 of slide.composition?.furniture?.parts ?? []) {
|
|
3572
|
+
if (part2.type !== "text" || part2.fit.lines.length <= MAX_FURNITURE_LINES) continue;
|
|
3573
|
+
const path = pointerOfDotted(part2.sourcePath ?? part2.path);
|
|
3574
|
+
if (reported.has(path)) continue;
|
|
3575
|
+
reported.add(path);
|
|
3576
|
+
context.report(furnitureWrapsRule, {
|
|
3577
|
+
path,
|
|
3578
|
+
slide,
|
|
3579
|
+
message: `The ${part2.kind} ${part2.zone} text wraps onto ${part2.fit.lines.length} lines (at most ${MAX_FURNITURE_LINES}).`,
|
|
3580
|
+
help: "Shorten the text, or move sources and notes to a caption or the speaker notes; keep the footer for short repeated text.",
|
|
3581
|
+
measured: { lines: part2.fit.lines.length, maximumLines: MAX_FURNITURE_LINES }
|
|
3582
|
+
});
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
];
|
|
3587
|
+
var fontRules = [
|
|
3588
|
+
{
|
|
3589
|
+
info: outsideRule,
|
|
3590
|
+
run(context) {
|
|
3591
|
+
for (const slide of context.slides) {
|
|
3592
|
+
const allowed = new Set(
|
|
3593
|
+
[slide.design.fonts.heading, slide.design.fonts.body, slide.design.fonts.code, slide.design.fonts.accent, slide.design.fontScheme.major, slide.design.fontScheme.minor].filter((family) => typeof family === "string").map((family) => family.toLowerCase())
|
|
3594
|
+
);
|
|
3595
|
+
const reported = /* @__PURE__ */ new Set();
|
|
3596
|
+
for (const tv of slide.texts)
|
|
3597
|
+
for (const run of runsOf(tv)) {
|
|
3598
|
+
const family = run.style.fontFamily;
|
|
3599
|
+
if (typeof family !== "string" || !family.trim() || allowed.has(family.trim().toLowerCase()) || reported.has(family.toLowerCase())) continue;
|
|
3600
|
+
reported.add(family.toLowerCase());
|
|
3601
|
+
context.report(outsideRule, {
|
|
3602
|
+
path: `${run.path}/fontFamily`,
|
|
3603
|
+
slide,
|
|
3604
|
+
message: `Text uses ${JSON.stringify(family)}, which is not in the font scheme (${[.../* @__PURE__ */ new Set([slide.design.fonts.heading, slide.design.fonts.body])].join(" / ")}).`,
|
|
3605
|
+
help: "Remove the fontFamily override to use the scheme font, or change the deck's font scheme so the family is part of it.",
|
|
3606
|
+
fixes: [{ id: "remove-font-family", title: "Use the scheme font", kind: "patch", safe: false, patch: [{ op: "remove", path: `${run.path}/fontFamily` }] }]
|
|
3607
|
+
});
|
|
3110
3608
|
}
|
|
3111
3609
|
}
|
|
3112
3610
|
}
|
|
@@ -3243,7 +3741,7 @@ function setsRunSize(value, depth2 = 0) {
|
|
|
3243
3741
|
var ROLE_SIZE = { text: PROSE_NOMINAL_SIZE, items: LIST_NOMINAL_SIZE, bullets: LIST_NOMINAL_SIZE, table: TABLE_NOMINAL_SIZE, quote: QUOTE_NOMINAL_SIZE, code: CODE_NOMINAL_SIZE };
|
|
3244
3742
|
function fittedSize(item, slide, document) {
|
|
3245
3743
|
const body = (parts2) => {
|
|
3246
|
-
const fit = parts2?.find((
|
|
3744
|
+
const fit = parts2?.find((part2) => part2.role === "body")?.fit;
|
|
3247
3745
|
return fit && !fit.overflow ? fit.fontSize : void 0;
|
|
3248
3746
|
};
|
|
3249
3747
|
if (item.field === "quote") return body(item.quoteLayout?.parts);
|
|
@@ -3299,7 +3797,7 @@ function itemText(item) {
|
|
|
3299
3797
|
return value.map((entry2) => {
|
|
3300
3798
|
if (typeof entry2 === "string" || Array.isArray(entry2)) return plainText(entry2);
|
|
3301
3799
|
const text2 = rec(entry2).text, description = rec(entry2).description;
|
|
3302
|
-
return [text2, description].map((
|
|
3800
|
+
return [text2, description].map((part2) => typeof part2 === "string" || Array.isArray(part2) ? plainText(part2) : "").join(" ");
|
|
3303
3801
|
}).join("\n");
|
|
3304
3802
|
}
|
|
3305
3803
|
var centeredBody = {
|
|
@@ -3500,9 +3998,9 @@ var chartDualAxis = {
|
|
|
3500
3998
|
for (const payload of slidePayloads(slide.slide, slide.path)) {
|
|
3501
3999
|
const chart = rec(payload.node.chart);
|
|
3502
4000
|
if (String(chart.type ?? "").trim().toLowerCase() !== "combo") continue;
|
|
3503
|
-
const
|
|
3504
|
-
if (!
|
|
3505
|
-
const secondary =
|
|
4001
|
+
const resolved2 = resolveChartData(chart, context.document);
|
|
4002
|
+
if (!resolved2.ok || !resolved2.combo) continue;
|
|
4003
|
+
const secondary = resolved2.combo.flatMap((entry2, index) => entry2.axis === "secondary" ? [String(resolved2.columns[index + 1] ?? "")] : []);
|
|
3506
4004
|
if (!secondary.length) continue;
|
|
3507
4005
|
context.report(chartDualAxisRule, {
|
|
3508
4006
|
path: `${chartPath(payload.path, slide.path)}/secondaryAxis`,
|
|
@@ -3522,14 +4020,14 @@ var chartPieManySlices = {
|
|
|
3522
4020
|
const chart = rec(payload.node.chart);
|
|
3523
4021
|
const type = String(chart.type ?? "").trim().toLowerCase();
|
|
3524
4022
|
if (type !== "pie" && type !== "doughnut") continue;
|
|
3525
|
-
const
|
|
3526
|
-
if (!
|
|
4023
|
+
const resolved2 = resolveChartData(chart, context.document);
|
|
4024
|
+
if (!resolved2.ok || resolved2.rows.length <= PIE_MAX_SLICES) continue;
|
|
3527
4025
|
context.report(chartPieManySlicesRule, {
|
|
3528
4026
|
path: chartPath(payload.path, slide.path),
|
|
3529
4027
|
slide,
|
|
3530
|
-
message: `The ${type} chart has ${
|
|
4028
|
+
message: `The ${type} chart has ${resolved2.rows.length} slices, more than ${PIE_MAX_SLICES}; the small ones are hard to compare and to label.`,
|
|
3531
4029
|
help: 'Compare the parts with a bar chart (`type: "bar"`, sorted if the order carries no meaning), or group the smallest categories into one "Other" slice.',
|
|
3532
|
-
measured: { slices:
|
|
4030
|
+
measured: { slices: resolved2.rows.length, limit: PIE_MAX_SLICES }
|
|
3533
4031
|
});
|
|
3534
4032
|
}
|
|
3535
4033
|
}
|
|
@@ -3542,10 +4040,10 @@ var ruleImplementations = [...accessibilityRules, ...layoutContentRules, ...lang
|
|
|
3542
4040
|
// src/chart-shape.ts
|
|
3543
4041
|
var FOREIGN_CHART_KEYS = ["categories", "series", "labels", "datasets"];
|
|
3544
4042
|
var CHART_DEFINITION = "https://openpresentation.org/schema/opf/v1#/$defs/Chart";
|
|
3545
|
-
var
|
|
4043
|
+
var isRecord3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3546
4044
|
var isCell = (value) => value === null || ["string", "number", "boolean"].includes(typeof value);
|
|
3547
4045
|
function foreignChartKeys(chart) {
|
|
3548
|
-
if (!
|
|
4046
|
+
if (!isRecord3(chart) || Object.hasOwn(chart, "data")) return [];
|
|
3549
4047
|
return FOREIGN_CHART_KEYS.filter((key3) => Object.hasOwn(chart, key3));
|
|
3550
4048
|
}
|
|
3551
4049
|
function convertChartData(chart) {
|
|
@@ -3555,7 +4053,7 @@ function convertChartData(chart) {
|
|
|
3555
4053
|
const columns = ["Category"];
|
|
3556
4054
|
const values = [];
|
|
3557
4055
|
for (const [index, entry2] of series.entries()) {
|
|
3558
|
-
if (!
|
|
4056
|
+
if (!isRecord3(entry2)) return void 0;
|
|
3559
4057
|
const list = entry2.values ?? entry2.data;
|
|
3560
4058
|
const name = entry2.name ?? entry2.label;
|
|
3561
4059
|
if (!Array.isArray(list) || list.length !== labels.length || !list.every(isCell)) return void 0;
|
|
@@ -3566,7 +4064,7 @@ function convertChartData(chart) {
|
|
|
3566
4064
|
return { columns, rows: labels.map((label, row) => [label, ...values.map((list) => list[row])]) };
|
|
3567
4065
|
}
|
|
3568
4066
|
function chartShapePatch(chart, path) {
|
|
3569
|
-
if (!
|
|
4067
|
+
if (!isRecord3(chart)) return void 0;
|
|
3570
4068
|
const data = convertChartData(chart);
|
|
3571
4069
|
const keys = foreignChartKeys(chart);
|
|
3572
4070
|
if (!data || !keys.length) return void 0;
|
|
@@ -3582,7 +4080,7 @@ function dataExample(chart) {
|
|
|
3582
4080
|
}
|
|
3583
4081
|
function chartShapeHelp(chart) {
|
|
3584
4082
|
const keys = foreignChartKeys(chart);
|
|
3585
|
-
if (!keys.length || !
|
|
4083
|
+
if (!keys.length || !isRecord3(chart)) return void 0;
|
|
3586
4084
|
const names2 = keys.map((key3) => `"${key3}"`).join(" and ");
|
|
3587
4085
|
const example = dataExample(chart);
|
|
3588
4086
|
const next = `replace ${names2} with ${example}. The first column holds the category labels and each further column is one series.`;
|
|
@@ -3597,12 +4095,12 @@ function chartShapeHelp(chart) {
|
|
|
3597
4095
|
var own = (value, key3) => Object.hasOwn(value, key3);
|
|
3598
4096
|
var object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3599
4097
|
var primitive = (value) => value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
3600
|
-
var
|
|
4098
|
+
var pointer4 = (parts2) => parts2.length ? "/" + parts2.map((part2) => String(part2).replaceAll("~", "~0").replaceAll("/", "~1")).join("/") : "";
|
|
3601
4099
|
function parts(path) {
|
|
3602
4100
|
if (path === "") return [];
|
|
3603
4101
|
if (!path.startsWith("/") || /~(?![01])/.test(path))
|
|
3604
4102
|
throw new TypeError(`Invalid contract JSON Pointer: ${path}`);
|
|
3605
|
-
return path.slice(1).split("/").map((
|
|
4103
|
+
return path.slice(1).split("/").map((part2) => part2.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
3606
4104
|
}
|
|
3607
4105
|
function at(value, path) {
|
|
3608
4106
|
return parts(path).reduce(
|
|
@@ -3637,7 +4135,7 @@ function finding(ruleId, data) {
|
|
|
3637
4135
|
}
|
|
3638
4136
|
var issueRuleId = (issue2) => typeof issue2.params.code === "string" && issue2.keyword === "opf" ? `opf/${issue2.params.code}` : "opf/schema";
|
|
3639
4137
|
function issueFinding(issue2, ruleId = issueRuleId(issue2), schemaName = "presentation", prefix = "", scope = "document", severity) {
|
|
3640
|
-
const path = prefix + (issue2.path === "/" ? "" : issue2.path) + (issue2.keyword === "additionalProperties" && typeof issue2.params.additionalProperty === "string" ?
|
|
4138
|
+
const path = prefix + (issue2.path === "/" ? "" : issue2.path) + (issue2.keyword === "additionalProperties" && typeof issue2.params.additionalProperty === "string" ? pointer4([issue2.params.additionalProperty]) : ""), entry2 = schemaEntries.find((entry3) => entry3.name === schemaName);
|
|
3641
4139
|
if (!entry2) throw new TypeError(`Unknown schema ${schemaName}`);
|
|
3642
4140
|
const precise = validationDefinition(issue2);
|
|
3643
4141
|
const definition = precise?.uri ?? (issue2.keyword === "opf" ? "packages/javascript/src/schema-check.ts" : issue2.schemaPath.startsWith("#") ? entry2.schema.$id + issue2.schemaPath : issue2.schemaPath);
|
|
@@ -3648,7 +4146,9 @@ function issueFinding(issue2, ruleId = issueRuleId(issue2), schemaName = "presen
|
|
|
3648
4146
|
precise?.pointer ?? (issue2.keyword !== "opf" && issue2.schemaPath.startsWith("#") ? issue2.schemaPath.slice(1) : "")
|
|
3649
4147
|
];
|
|
3650
4148
|
let help = "Inspect this schema constraint and preserve unrelated content. Errors inside oneOf/anyOf branches may describe alternatives; retain the intended form.";
|
|
3651
|
-
if (issue2.keyword === "required")
|
|
4149
|
+
if (issue2.keyword === "required" && issue2.params.missingProperty === "id" && /^\/(organization|speaker)(\/\d+)?$/.test(issue2.path))
|
|
4150
|
+
help = `Add an "id" next to "name": organizations and speakers are found by id (speaker.organizationId, {{organization.<id>.name}}, the editor and the PPTX round trip), for example "id": "acme" (letters, digits, "-" and "_", unique in the deck).`;
|
|
4151
|
+
else if (issue2.keyword === "required")
|
|
3652
4152
|
help = `Add the required ${JSON.stringify(issue2.params.missingProperty)} field in this object, using the intended schema form.`;
|
|
3653
4153
|
else if (issue2.keyword === "additionalProperties")
|
|
3654
4154
|
help = `Review ${JSON.stringify(issue2.params.additionalProperty)} against this object's schema. Preserve custom metadata in document.extensions where appropriate; do not delete authored content to clear this error.`;
|
|
@@ -3658,6 +4158,7 @@ function issueFinding(issue2, ruleId = issueRuleId(issue2), schemaName = "presen
|
|
|
3658
4158
|
} else if (issue2.keyword === "dependentRequired")
|
|
3659
4159
|
help = `${JSON.stringify(issue2.params.property)} only applies together with ${JSON.stringify(issue2.params.missingProperty)}: add ${JSON.stringify(issue2.params.missingProperty)}, or remove ${JSON.stringify(issue2.params.property)}.`;
|
|
3660
4160
|
else if (issue2.keyword === "opf") help = semanticHelp(issue2);
|
|
4161
|
+
else if ((issue2.keyword === "oneOf" || issue2.keyword === "anyOf") && Array.isArray(issue2.params.properties)) help = foreignObjectHelp(issue2);
|
|
3661
4162
|
const allowed = Array.isArray(issue2.params.allowedValues) ? issue2.params.allowedValues.filter(primitive) : [];
|
|
3662
4163
|
const nearest2 = issue2.keyword === "additionalProperties" ? nearestProperties(issue2, entry2.schema, precise?.pointer, precise?.schemaName) : [];
|
|
3663
4164
|
const typedName = issue2.keyword === "additionalProperties" && typeof issue2.params.additionalProperty === "string" ? issue2.params.additionalProperty : void 0;
|
|
@@ -3686,8 +4187,17 @@ function issueFinding(issue2, ruleId = issueRuleId(issue2), schemaName = "presen
|
|
|
3686
4187
|
} : nearest2.length ? { suggestions: nearest2 } : {}
|
|
3687
4188
|
});
|
|
3688
4189
|
}
|
|
4190
|
+
function foreignObjectHelp(issue2) {
|
|
4191
|
+
const params2 = issue2.params;
|
|
4192
|
+
const many = params2.alsoAt?.length ? "each entry" : "it";
|
|
4193
|
+
if (params2.belongsTo?.length) {
|
|
4194
|
+
const kinds = params2.belongsTo.map((kind) => `"${kind}"`).join(" or ");
|
|
4195
|
+
return `To show these as ${kinds}, give each its own block whose ${kinds} holds these fields; to keep ${many} here, rewrite ${many} in one of the forms this place takes. Keep the authored content.`;
|
|
4196
|
+
}
|
|
4197
|
+
return `Rewrite ${many} in one of the forms this place takes, moving the authored content into the fields that form has; do not delete it to clear this error.`;
|
|
4198
|
+
}
|
|
3689
4199
|
var NEAREST_PROPERTIES = 3;
|
|
3690
|
-
var logicalName = (name) => name.split(":").map((
|
|
4200
|
+
var logicalName = (name) => name.split(":").map((part2) => part2.split("+").map((word) => word === "left" ? "start" : word === "right" ? "end" : word).join("+")).join(":");
|
|
3691
4201
|
function nearestProperties(issue2, fallbackRoot, pointerToKeyword, schemaName) {
|
|
3692
4202
|
const typed = issue2.params.additionalProperty;
|
|
3693
4203
|
if (typeof typed !== "string" || pointerToKeyword === void 0) return [];
|
|
@@ -3700,9 +4210,9 @@ function nearestProperties(issue2, fallbackRoot, pointerToKeyword, schemaName) {
|
|
|
3700
4210
|
else return [];
|
|
3701
4211
|
}
|
|
3702
4212
|
if (!isRecord(node) || !isRecord(node.properties)) return [];
|
|
3703
|
-
const root = rootEntry?.schema ?? fallbackRoot,
|
|
4213
|
+
const root = rootEntry?.schema ?? fallbackRoot, lower = typed.toLowerCase();
|
|
3704
4214
|
const declared = Object.keys(node.properties), logical = logicalName(typed), longer = typed.length >= 3 ? declared.filter((name) => name !== typed && name.toLowerCase().startsWith(lower)) : [], exact = logical !== typed && declared.includes(logical) ? [logical] : longer.length === 1 ? longer : [];
|
|
3705
|
-
const near =
|
|
4215
|
+
const near = respellings(typed, declared).filter((name) => !exact.includes(name));
|
|
3706
4216
|
return [...exact, ...near].slice(0, NEAREST_PROPERTIES).map((name) => ({
|
|
3707
4217
|
value: name,
|
|
3708
4218
|
label: name,
|
|
@@ -3720,12 +4230,12 @@ function resolve(cursor, seen = /* @__PURE__ */ new Set()) {
|
|
|
3720
4230
|
if (!root) return { ...cursor, schema: {} };
|
|
3721
4231
|
const target = at(root, fragment);
|
|
3722
4232
|
if (!object(target)) return { ...cursor, schema: {} };
|
|
3723
|
-
const
|
|
4233
|
+
const resolved2 = resolve(
|
|
3724
4234
|
{ schema: target, root, path: fragment },
|
|
3725
4235
|
seen
|
|
3726
4236
|
);
|
|
3727
4237
|
const { $ref, ...rest } = cursor.schema;
|
|
3728
|
-
return { ...
|
|
4238
|
+
return { ...resolved2, schema: { ...resolved2.schema, ...rest } };
|
|
3729
4239
|
}
|
|
3730
4240
|
function score(schema, value) {
|
|
3731
4241
|
const type = schema.type;
|
|
@@ -3746,21 +4256,21 @@ function score(schema, value) {
|
|
|
3746
4256
|
return result;
|
|
3747
4257
|
}
|
|
3748
4258
|
function active(cursor, value) {
|
|
3749
|
-
const
|
|
3750
|
-
if (!Array.isArray(alternatives)) return
|
|
3751
|
-
const keyword =
|
|
4259
|
+
const resolved2 = resolve(cursor), alternatives = resolved2.schema.oneOf ?? resolved2.schema.anyOf;
|
|
4260
|
+
if (!Array.isArray(alternatives)) return resolved2;
|
|
4261
|
+
const keyword = resolved2.schema.oneOf ? "oneOf" : "anyOf";
|
|
3752
4262
|
const candidates = alternatives.filter(object).map(
|
|
3753
4263
|
(schema, index) => active(
|
|
3754
4264
|
{
|
|
3755
4265
|
schema,
|
|
3756
|
-
root:
|
|
3757
|
-
path: `${
|
|
4266
|
+
root: resolved2.root,
|
|
4267
|
+
path: `${resolved2.path}/${keyword}/${index}`
|
|
3758
4268
|
},
|
|
3759
4269
|
value
|
|
3760
4270
|
)
|
|
3761
4271
|
);
|
|
3762
4272
|
const selected = candidates.sort((a, b) => score(b.schema, value) - score(a.schema, value))[0];
|
|
3763
|
-
return selected ? { ...selected, baseSchemas: [...selected.baseSchemas ?? [],
|
|
4273
|
+
return selected ? { ...selected, baseSchemas: [...selected.baseSchemas ?? [], resolved2] } : resolved2;
|
|
3764
4274
|
}
|
|
3765
4275
|
function childCursor(cursors, key3) {
|
|
3766
4276
|
for (const keyword of [
|
|
@@ -3779,7 +4289,7 @@ function childCursor(cursors, key3) {
|
|
|
3779
4289
|
return {
|
|
3780
4290
|
schema,
|
|
3781
4291
|
root: cursor.root,
|
|
3782
|
-
path: `${cursor.path}/${keyword}${name === void 0 ? "" :
|
|
4292
|
+
path: `${cursor.path}/${keyword}${name === void 0 ? "" : pointer4([name])}`
|
|
3783
4293
|
};
|
|
3784
4294
|
}
|
|
3785
4295
|
}
|
|
@@ -3802,20 +4312,20 @@ function fields(document) {
|
|
|
3802
4312
|
const entry2 = stack.pop();
|
|
3803
4313
|
if (!entry2) break;
|
|
3804
4314
|
if (entry2.ancestors.includes(entry2.value)) continue;
|
|
3805
|
-
const
|
|
3806
|
-
const assetReference2 = [
|
|
4315
|
+
const resolved2 = resolve(entry2.cursor), selected = active(entry2.cursor, entry2.value);
|
|
4316
|
+
const assetReference2 = [resolved2, selected].some(
|
|
3807
4317
|
(cursor) => cursor.root.$id === schemas.presentation.$id && (cursor.path === "/$defs/Asset" || cursor.path === "/$defs/Asset/oneOf/0" || cursor.path === "/$defs/Watermark/properties/src") || String(cursor.schema.description ?? "").includes("asset:") || Array.isArray(cursor.schema.examples) && cursor.schema.examples.some(
|
|
3808
4318
|
(example) => typeof example === "string" && example.startsWith("asset:")
|
|
3809
4319
|
)
|
|
3810
4320
|
);
|
|
3811
4321
|
result.push({
|
|
3812
|
-
path:
|
|
4322
|
+
path: pointer4(entry2.path),
|
|
3813
4323
|
value: entry2.value,
|
|
3814
|
-
cursor:
|
|
4324
|
+
cursor: resolved2,
|
|
3815
4325
|
assetReference: assetReference2
|
|
3816
4326
|
});
|
|
3817
4327
|
const ancestors = [...entry2.ancestors, entry2.value];
|
|
3818
|
-
const cursors = [selected, ...selected.baseSchemas ?? [],
|
|
4328
|
+
const cursors = [selected, ...selected.baseSchemas ?? [], resolved2];
|
|
3819
4329
|
const arrayCursor = cursors.find((cursor) => object(cursor.schema.items));
|
|
3820
4330
|
if (Array.isArray(entry2.value) && arrayCursor)
|
|
3821
4331
|
entry2.value.forEach((value, index) => {
|
|
@@ -3859,11 +4369,11 @@ function embeddedRecordFindings(document, options2, findings) {
|
|
|
3859
4369
|
for (const [id, record] of Object.entries(object(value.iconSets) ? value.iconSets : {})) {
|
|
3860
4370
|
if (object(record) && (Object.hasOwn(record, "$schema") || Object.hasOwn(record, "id"))) continue;
|
|
3861
4371
|
const validation = validateAgainstSchema(object(record) ? { $schema: schemas.iconSet.$id, id, ...record } : record, "iconSets");
|
|
3862
|
-
for (const issue2 of validation.errors) findings.push(issueFinding(issue2, "opf/catalog-record", "iconSet",
|
|
4372
|
+
for (const issue2 of validation.errors) findings.push(issueFinding(issue2, "opf/catalog-record", "iconSet", pointer4(["catalogs", group, "iconSets", id]), "document"));
|
|
3863
4373
|
}
|
|
3864
4374
|
for (const kind of catalogKinds)
|
|
3865
4375
|
for (const [id, record] of Object.entries(object(value[kind]) ? value[kind] : {})) {
|
|
3866
|
-
const path =
|
|
4376
|
+
const path = pointer4(["catalogs", group, kind, id]);
|
|
3867
4377
|
if (object(record) && (Object.hasOwn(record, "$schema") || Object.hasOwn(record, "id"))) continue;
|
|
3868
4378
|
const validation = recordIssues(kind, id, record);
|
|
3869
4379
|
for (const issue2 of validation.errors) findings.push(issueFinding(issue2, recordRuleId(issue2), catalogSchemaNames[kind], path, "document"));
|
|
@@ -3885,7 +4395,7 @@ function embeddedRecordFindings(document, options2, findings) {
|
|
|
3885
4395
|
}
|
|
3886
4396
|
return invalid;
|
|
3887
4397
|
}
|
|
3888
|
-
function
|
|
4398
|
+
function distance2(a, b) {
|
|
3889
4399
|
a = a.slice(0, 128);
|
|
3890
4400
|
b = b.slice(0, 128);
|
|
3891
4401
|
let row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
@@ -3921,7 +4431,7 @@ var HELP = {
|
|
|
3921
4431
|
"chart-value-not-numeric": 'Write chart values as numbers (or strict decimal strings such as "12.5" or "1e6"); put currency, percent and units in the column format ({ "name": "Revenue", "format": "$#,##0" }). The value is plotted as a gap.',
|
|
3922
4432
|
"chart-mapping-adapted": "Choose a compatible chart type or mapping for the selected data. The message explains how the mapping or drawing was adapted.",
|
|
3923
4433
|
"chart-series-dropped": "The chart type plots one series. Use a chart type that plots every series (column, bar, line), or one chart per series.",
|
|
3924
|
-
"chart-highlight-adapted": "The highlight is adapted by every engine. Name a series or category the chart type can
|
|
4434
|
+
"chart-highlight-adapted": "The highlight is adapted by every engine. Name a series or category the chart type can emphasize, or remove the entry.",
|
|
3925
4435
|
"slide-theme-dimensions": "A PPTX has one slide size. Set design.dimensions on the deck, or give every slide the same theme dimensions.",
|
|
3926
4436
|
"code-highlight-out-of-range": "Marked lines count from 1 by line break in code.source. The entry marks nothing past the last line; change it to a line the code has, or remove it.",
|
|
3927
4437
|
"code-highlight-range-reversed": "Write the range with the smaller line number first, or remove it. A reversed range marks nothing.",
|
|
@@ -3930,16 +4440,17 @@ var HELP = {
|
|
|
3930
4440
|
"variable-unknown-value": "Remove the supplied value, or declare the variable it belongs to.",
|
|
3931
4441
|
"variable-unused": "Reference the variable as {{id}} or var:id where it belongs, or remove its declaration.",
|
|
3932
4442
|
"variable-group-omitted": "Give one of the variables a value to draw the group, make one of them required, or move the content that should always show out of the group.",
|
|
3933
|
-
"variable-reference-unknown": "Declare the variable in the top-level variables map, or use another
|
|
3934
|
-
"run-color-unrecognized": "Use a #RRGGBB hex
|
|
4443
|
+
"variable-reference-unknown": "Declare the variable in the top-level variables map, or use another color.",
|
|
4444
|
+
"run-color-unrecognized": "Use a #RRGGBB hex color, a color-scheme name or a var: reference to a declared color variable.",
|
|
3935
4445
|
"numbering-start-ignored": "Add a 'numbering' field to the payload, or remove 'start'.",
|
|
3936
4446
|
"slide-size-out-of-range": "Use a custom widthInches and heightInches between 1 and 56, or a preset. PowerPoint stores the slide size in 914400 to 51206400 EMU per side."
|
|
3937
4447
|
};
|
|
3938
4448
|
function semanticHelp(issue2) {
|
|
3939
|
-
const params2 = issue2.params ?? {}, field = typeof params2.field === "string" ? params2.field : void 0,
|
|
3940
|
-
if (params2.code === "image-option-unsupported-payload" && field) return `Remove ${
|
|
4449
|
+
const params2 = issue2.params ?? {}, field = typeof params2.field === "string" ? params2.field : void 0, quoted3 = JSON.stringify(field);
|
|
4450
|
+
if (params2.code === "image-option-unsupported-payload" && field) return `Remove ${quoted3}, or put it on an image block ({ "image": ... }); it has no meaning on another kind of content.`;
|
|
3941
4451
|
if (params2.code === "shape-option-unsupported-payload" && field === "alt" && params2.type === "image") return `A picture's alt text goes inside its image object: { "image": { "src": "...", "alt": "..." } }.`;
|
|
3942
|
-
if (params2.code === "shape-option-unsupported-payload" && field) return `Remove ${
|
|
4452
|
+
if (params2.code === "shape-option-unsupported-payload" && field) return `Remove ${quoted3}, or draw this as a shape: a shape block ({ "shape": ... } with no "image") or an overlay shape in the slide's "shapes".`;
|
|
4453
|
+
if (params2.code === "number-format-invalid") return 'Write a pattern with a numeric part, such as "0%", "0.0", "#,##0" or "$#,##0.00", optionally followed by a negative and a zero section after ";" ("+0%;-0%", "0;(0);0"; at most three, each with a numeric part). A negative section prints no minus of its own. There is no text section, color or condition.';
|
|
3943
4454
|
if (params2.code === "caption-unsupported-payload") return "Put the caption on the image, chart, table, video or diagram it describes, or write it as a text block of its own.";
|
|
3944
4455
|
if (Array.isArray(params2.incompatible) && params2.incompatible.includes("bullets") && params2.type === "list") return 'For a list, write the entries under "items". To keep "bullets" (talking points, which belong to a text payload), remove "type" or write "type": "text".';
|
|
3945
4456
|
return "Resolve the reported structural conflict while preserving every content field. Preview the result after editing.";
|
|
@@ -4045,9 +4556,33 @@ function collapseAuthoringShapes(document, findings) {
|
|
|
4045
4556
|
const prefix = `${entry2.path}/`;
|
|
4046
4557
|
if (findings.some((other) => other !== entry2 && other.path.startsWith(prefix) && !other.path.slice(prefix.length).includes("/") && OPTION_RULES.includes(other.ruleId))) findings.splice(index, 1);
|
|
4047
4558
|
}
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4559
|
+
const payloadSlots = /* @__PURE__ */ new Map();
|
|
4560
|
+
for (const entry2 of findings) {
|
|
4561
|
+
if (!schema(entry2) || payloadSlots.has(entry2.path)) continue;
|
|
4562
|
+
if (!/^\/slides\/\d+\/blocks\/\d+$/.test(entry2.path)) continue;
|
|
4563
|
+
const value = valueAt(entry2.path);
|
|
4564
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value)) payloadSlots.set(entry2.path, value);
|
|
4565
|
+
}
|
|
4566
|
+
for (const [at2, value] of payloadSlots) {
|
|
4567
|
+
const first = findings.findIndex((entry2) => schema(entry2) && entry2.path === at2);
|
|
4568
|
+
const text2 = typeof value === "string";
|
|
4569
|
+
const write = text2 ? `{ "text": ${JSON.stringify(value)} }` : Array.isArray(value) ? '{ "items": [ ... ] } for a list, or { "blocks": [ ... ] } for several blocks' : '{ "text": "..." }';
|
|
4570
|
+
const { fixes: _fixes, suggestions: _suggestions, ...kept } = findings[first];
|
|
4571
|
+
const one = {
|
|
4572
|
+
...kept,
|
|
4573
|
+
message: `A block holds a content payload (an object), not ${text2 ? "a bare string" : Array.isArray(value) ? "a list" : "a " + typeof value}.`,
|
|
4574
|
+
help: `Write ${write}. A payload names its kind by its key: "text", "items" (a list), "image", "chart", "table", or "blocks" to stack several; see docs/dynamic-composition.md.`,
|
|
4575
|
+
...text2 ? { fixes: [{ id: "wrap-text", title: 'Write the string as { "text": ... }', kind: "patch", safe: false, patch: [{ op: "replace", path: at2, value: { text: value } }] }] } : {}
|
|
4576
|
+
};
|
|
4577
|
+
for (let index = findings.length - 1; index >= 0; index--) {
|
|
4578
|
+
const entry2 = findings[index];
|
|
4579
|
+
if (schema(entry2) && entry2.path === at2) findings.splice(index, 1);
|
|
4580
|
+
}
|
|
4581
|
+
findings.splice(first, 0, one);
|
|
4582
|
+
}
|
|
4583
|
+
}
|
|
4584
|
+
function collapseChartShape(document, findings) {
|
|
4585
|
+
const chartAt = (path) => {
|
|
4051
4586
|
let node = document;
|
|
4052
4587
|
for (const segment of splitPointer(path)) node = Array.isArray(node) ? node[Number(segment)] : isRecord(node) ? node[segment] : void 0;
|
|
4053
4588
|
return node;
|
|
@@ -4121,7 +4656,7 @@ function variableFindings(document, engine, schemaValid) {
|
|
|
4121
4656
|
for (const id of engine.unfilledVariables ?? [])
|
|
4122
4657
|
findings.push(
|
|
4123
4658
|
finding("opf/variable-unfilled", {
|
|
4124
|
-
path:
|
|
4659
|
+
path: pointer4(["variables", id]),
|
|
4125
4660
|
message: `Template variable ${JSON.stringify(id)} has no value.`,
|
|
4126
4661
|
help: "This document is a template: fill it with its values (opf fill, or resolveVariables) before using it as a deck.",
|
|
4127
4662
|
severity: "warning"
|
|
@@ -4146,7 +4681,7 @@ function variableFindings(document, engine, schemaValid) {
|
|
|
4146
4681
|
if (match2[1])
|
|
4147
4682
|
findings.push(
|
|
4148
4683
|
finding("opf/variable-unfilled", {
|
|
4149
|
-
path:
|
|
4684
|
+
path: pointer4(path),
|
|
4150
4685
|
message: `Template variable ${JSON.stringify(match2[0])} is still in the text.`,
|
|
4151
4686
|
help: "Declare the variable and fill it, or replace the token with the real value.",
|
|
4152
4687
|
severity: "warning"
|
|
@@ -4191,11 +4726,17 @@ function undeclaredCatalogFindings(document) {
|
|
|
4191
4726
|
return findings;
|
|
4192
4727
|
}
|
|
4193
4728
|
var KIND_PLURAL = { layouts: "layouts", themes: "themes", colorSchemes: "color schemes", fontSchemes: "font schemes", narratives: "narratives", audiences: "audiences", purposes: "purposes", tones: "tones" };
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4729
|
+
var KIND_SINGULAR = { layouts: "layout", themes: "theme", colorSchemes: "color scheme", fontSchemes: "font scheme", narratives: "narrative", audiences: "audience", purposes: "purpose", tones: "tone" };
|
|
4730
|
+
function nearMisses(reference, candidates) {
|
|
4731
|
+
return candidates.filter((value) => distance2(reference, value) <= Math.max(2, Math.floor(reference.length / 4)) && relatedName(reference, value));
|
|
4732
|
+
}
|
|
4733
|
+
function nearestRecords(kind, reference, candidates, registered) {
|
|
4734
|
+
if (!registered) return "";
|
|
4735
|
+
const close = nearMisses(reference, candidates).slice(0, 3);
|
|
4197
4736
|
const quote = (values) => values.map((value) => `'${value}'`).join(", ");
|
|
4198
|
-
|
|
4737
|
+
if (close.length) return `Did you mean ${quote(close)}? `;
|
|
4738
|
+
const listed = `search_catalog (the OPF MCP server), opf catalog ${kind} and pptx.gallery list the ${KIND_PLURAL[kind]} that exist.`;
|
|
4739
|
+
return kind === "layouts" ? `No layout is named like '${reference}'. Without the layout key the slide composes automatically from its content; ${listed} ` : `No ${KIND_SINGULAR[kind]} is named like '${reference}'; ${listed} `;
|
|
4199
4740
|
}
|
|
4200
4741
|
function contentReferenceFindings(document, options2, findings) {
|
|
4201
4742
|
const invalid = embeddedRecordFindings(document, options2, findings);
|
|
@@ -4208,16 +4749,72 @@ function contentReferenceFindings(document, options2, findings) {
|
|
|
4208
4749
|
if (found?.origin === "host" && !registeredChecked.has(recordKey(found.group, site.kind, found.id))) {
|
|
4209
4750
|
registeredChecked.add(recordKey(found.group, site.kind, found.id));
|
|
4210
4751
|
for (const issue2 of recordIssues(site.kind, found.id, found.record).errors)
|
|
4211
|
-
findings.push(issueFinding(issue2, recordRuleId(issue2), catalogSchemaNames[site.kind],
|
|
4752
|
+
findings.push(issueFinding(issue2, recordRuleId(issue2), catalogSchemaNames[site.kind], pointer4(["catalogs", found.group, site.kind, found.id]), "context"));
|
|
4212
4753
|
}
|
|
4213
4754
|
if (found && !(found.origin === "document" && invalid.has(recordKey(found.group, site.kind, found.id)))) continue;
|
|
4755
|
+
const embeddedInvalid = found?.origin === "document" ? found : void 0;
|
|
4756
|
+
const stale = embeddedInvalid && site.kind === "layouts" ? staleLayoutCopy(document, embeddedInvalid.group, embeddedInvalid.id, options2) : void 0;
|
|
4214
4757
|
const diagnostic = unresolvedReference(document, site.kind, site.reference, path, options2);
|
|
4215
|
-
|
|
4758
|
+
if (removedLayoutAuto(site.kind, site.reference)) {
|
|
4759
|
+
findings.push(
|
|
4760
|
+
finding("opf/unresolved-reference", {
|
|
4761
|
+
path,
|
|
4762
|
+
message: diagnostic.message,
|
|
4763
|
+
help: 'OPF 0.35 removed layout "auto". Delete the layout key: a slide without one is composed automatically, which is what "auto" did.',
|
|
4764
|
+
definition: `${schemas.presentation.$id}#/$defs/Slide`,
|
|
4765
|
+
lookup: ["opf", "catalog", site.kind],
|
|
4766
|
+
fixes: [{ id: "remove-layout-auto", title: "Delete layout (automatic composition)", kind: "patch", safe: true, patch: [{ op: "remove", path }] }]
|
|
4767
|
+
})
|
|
4768
|
+
);
|
|
4769
|
+
continue;
|
|
4770
|
+
}
|
|
4771
|
+
const renamed = renamedLayout(site.kind, site.reference);
|
|
4772
|
+
if (renamed !== void 0) {
|
|
4773
|
+
const position = renamedLayoutTitlePosition(site.kind, site.reference);
|
|
4774
|
+
const slideAt2 = site.path.slice(0, -1);
|
|
4775
|
+
const slide = slideAt2.reduce((value, key3) => isRecord(value) || Array.isArray(value) ? value[key3] : void 0, document);
|
|
4776
|
+
const design = slide && typeof slide.design === "object" && slide.design !== null && !Array.isArray(slide.design) ? slide.design : void 0;
|
|
4777
|
+
const setPosition = position !== void 0 && design?.titlePosition === void 0;
|
|
4778
|
+
const positionOp = !setPosition ? [] : design ? [{ op: "add", path: pointer4([...slideAt2, "design", "titlePosition"]), value: position }] : [{ op: "add", path: pointer4([...slideAt2, "design"]), value: { titlePosition: position } }];
|
|
4779
|
+
const dropCopy = stale?.renamed && staleCopyUsers(document, stale, options2).length <= 1 ? droppedCopyOperations(document, stale) : [];
|
|
4780
|
+
const what = renamed.endsWith("vertical-process") ? "" : renamed.endsWith("agenda") ? ' with its title beside the list (design.titlePosition "start")' : " (a short list as boxes joined by arrows, longer steps as numbered steps)";
|
|
4781
|
+
findings.push(
|
|
4782
|
+
finding("opf/unresolved-reference", {
|
|
4783
|
+
path,
|
|
4784
|
+
message: diagnostic.message,
|
|
4785
|
+
help: `OPF 0.35 removed layout "${site.reference}"; use "${renamed}", which draws the same content${what}.${position ? ` The fix sets the layout and${setPosition ? "" : " leaves"} the slide's design.titlePosition${setPosition ? ` to "${position}"` : " as the slide sets it"}.` : ""}`,
|
|
4786
|
+
definition: `${schemas.presentation.$id}#/$defs/Slide`,
|
|
4787
|
+
lookup: ["opf", "catalog", site.kind],
|
|
4788
|
+
fixes: [{ id: "rename-layout", title: setPosition ? `Use layout ${renamed} with the title beside it` : `Use layout ${renamed}`, kind: "patch", safe: true, ...stale || renamedLayoutChangesDrawing(site.kind, site.reference) ? { changesDrawing: true } : {}, patch: [{ op: "replace", path, value: renamed }, ...positionOp, ...dropCopy] }]
|
|
4789
|
+
})
|
|
4790
|
+
);
|
|
4791
|
+
continue;
|
|
4792
|
+
}
|
|
4793
|
+
if (embeddedInvalid) {
|
|
4794
|
+
const at2 = pointer4(["catalogs", embeddedInvalid.group, site.kind, embeddedInvalid.id]);
|
|
4795
|
+
const fix = stale ? staleCopyFix(document, stale, options2) : void 0;
|
|
4796
|
+
const noun = KIND_SINGULAR[site.kind];
|
|
4797
|
+
findings.push(
|
|
4798
|
+
finding("opf/unresolved-reference", {
|
|
4799
|
+
path,
|
|
4800
|
+
message: `${noun[0].toUpperCase()}${noun.slice(1)} '${site.reference}' is embedded in catalogs.${embeddedInvalid.group}, but the record fails the ${noun} schema: see the opf/catalog-record findings at ${at2}.`,
|
|
4801
|
+
help: stale ? staleCopyCause(stale) : `Fix the record with the fixes of its findings at ${at2}, then validate again.`,
|
|
4802
|
+
definition: `${schemas.presentation.$id}#/$defs/Catalogs`,
|
|
4803
|
+
lookup: ["opf", "catalog", site.kind],
|
|
4804
|
+
...fix ? { fixes: [fix] } : {}
|
|
4805
|
+
})
|
|
4806
|
+
);
|
|
4807
|
+
continue;
|
|
4808
|
+
}
|
|
4809
|
+
const records = catalogRecords(document, site.kind, options2);
|
|
4810
|
+
const near = new Set(nearMisses(site.reference, records.map((entry2) => entry2.reference)));
|
|
4811
|
+
const suggestions = records.filter((entry2) => near.has(entry2.reference)).map((entry2) => ({ value: entry2.reference, label: typeof entry2.record.name === "string" ? entry2.record.name : entry2.reference, origin: entry2.origin === "host" ? "registered" : "document", definition: entry2.origin === "document" ? `document#${pointer4(["catalogs", entry2.group, site.kind, entry2.id])}` : `${entry2.source ?? "context"}#/${site.kind}/${entry2.id}` })).sort((a, b) => distance2(site.reference, a.value) - distance2(site.reference, b.value) || (a.value < b.value ? -1 : a.value > b.value ? 1 : 0)).slice(0, 5);
|
|
4812
|
+
const suggested = suggestions.length > 0;
|
|
4216
4813
|
findings.push(
|
|
4217
4814
|
finding("opf/unresolved-reference", {
|
|
4218
4815
|
path,
|
|
4219
4816
|
message: diagnostic.message,
|
|
4220
|
-
help: `${nearestRecords(site.kind, site.reference, suggestions.map((entry2) => entry2.value))}${site.kind === "layouts" ? "Embed the layout record (embed(), or opf embed), register the catalog that defines it, choose one of the suggested layouts, or remove the reference to compose the slide automatically." : "Embed the record (embed(), or opf embed), register the catalog that defines it, or choose one of the suggested records."}`,
|
|
4817
|
+
help: `${nearestRecords(site.kind, site.reference, suggestions.map((entry2) => entry2.value), records.length > 0)}${!suggested && records.length ? `To keep this id, embed the ${site.kind === "layouts" ? "layout " : ""}record (embed(), or opf embed) or register the catalog that defines it.` : site.kind === "layouts" ? "Embed the layout record (embed(), or opf embed), register the catalog that defines it, choose one of the suggested layouts, or remove the reference to compose the slide automatically." : "Embed the record (embed(), or opf embed), register the catalog that defines it, or choose one of the suggested records."}`,
|
|
4221
4818
|
definition: `${schemas.presentation.$id}#/$defs/Catalogs`,
|
|
4222
4819
|
lookup: ["opf", "catalog", site.kind],
|
|
4223
4820
|
suggestions
|
|
@@ -4242,12 +4839,12 @@ function referenceFindings(document, engine, options2) {
|
|
|
4242
4839
|
definition: schemas.presentation.$id + "#/$defs/Assets",
|
|
4243
4840
|
lookup: ["opf", "schema", "presentation", "/$defs/Assets"],
|
|
4244
4841
|
suggestions: Object.keys(assetValues).sort(
|
|
4245
|
-
(a, b) =>
|
|
4842
|
+
(a, b) => distance2(id, a) - distance2(id, b) || (a < b ? -1 : a > b ? 1 : 0)
|
|
4246
4843
|
).slice(0, 5).map((id2) => ({
|
|
4247
4844
|
value: `asset:${id2}`,
|
|
4248
4845
|
label: id2,
|
|
4249
4846
|
origin: "document",
|
|
4250
|
-
definition: `document#${
|
|
4847
|
+
definition: `document#${pointer4(["assets", id2])}`
|
|
4251
4848
|
}))
|
|
4252
4849
|
})
|
|
4253
4850
|
);
|
|
@@ -4264,7 +4861,7 @@ function referenceFindings(document, engine, options2) {
|
|
|
4264
4861
|
for (const id2 of cycle) reportedCycles.add(id2);
|
|
4265
4862
|
findings.push(
|
|
4266
4863
|
finding("opf/asset-cycle", {
|
|
4267
|
-
path:
|
|
4864
|
+
path: pointer4(["assets", current]),
|
|
4268
4865
|
message: `Asset references form a cycle: ${[...cycle, current].map((id2) => JSON.stringify(id2)).join(" \u2192 ")}.`,
|
|
4269
4866
|
help: "Replace one link with the intended concrete source. Preserve the original asset metadata; no files or URLs were fetched."
|
|
4270
4867
|
})
|
|
@@ -4295,272 +4892,122 @@ function referenceFindings(document, engine, options2) {
|
|
|
4295
4892
|
finding("opf/unused-dataset", {
|
|
4296
4893
|
path: `/datasets/${id.replaceAll("~", "~0").replaceAll("/", "~1")}`,
|
|
4297
4894
|
message: `Dataset ${JSON.stringify(id)} is never referenced; reference it from a chart ("data": { "dataset": ${JSON.stringify(id)} }) or a table ({ "dataset": ${JSON.stringify(id)} }), or remove it.`,
|
|
4298
|
-
help: "Reference the dataset from chart.data or a table so it is drawn, or remove the entry. Nothing is drawn for an unreferenced dataset.",
|
|
4299
|
-
definition: schemas.presentation.$id + "#/$defs/Dataset",
|
|
4300
|
-
lookup: ["opf", "schema", "presentation", "/$defs/Dataset"]
|
|
4301
|
-
})
|
|
4302
|
-
);
|
|
4303
|
-
for (const { path, value } of documentIcons(document)) {
|
|
4304
|
-
const issue2 = iconIssue(document, value, catalogs);
|
|
4305
|
-
if (!issue2) continue;
|
|
4306
|
-
const unknown = issue2.code === "icon-unknown";
|
|
4307
|
-
findings.push(
|
|
4308
|
-
finding(unknown ? "opf/icon-unknown" : "opf/icon-invalid", {
|
|
4309
|
-
path: pointerPath(path.split(".")),
|
|
4310
|
-
message: issue2.message,
|
|
4311
|
-
help: unknown ? `${issue2.suggestions?.length ? `Did you mean ${issue2.suggestions.slice(0, 3).map((name) => `'${name}'`).join(", ")}? ` : ""}Use an icon the set has (the MCP's search_icons finds names by keyword), add the name to the deck's icons, or remove the icon. Nothing else changes: the text is drawn without the chip.` : "Give the icon SVG text with only shapes (path, circle, rect, line, polyline, polygon and groups), no script, event handler, external reference or raster, or remove the icon.",
|
|
4312
|
-
definition: `${schemas.presentation.$id}#/$defs/IconReference`,
|
|
4313
|
-
lookup: ["opf", "schema", "presentation", "/$defs/IconReference"],
|
|
4314
|
-
...issue2.suggestions?.length ? { suggestions: issue2.suggestions.map((value2) => ({ value: value2, label: value2, origin: "registered", definition: `${schemas.presentation.$id}#/$defs/IconReference` })) } : {}
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
return findings;
|
|
4319
|
-
}
|
|
4320
|
-
function narrativeFindings(document, options2) {
|
|
4321
|
-
const findings = [];
|
|
4322
|
-
if (!object(document)) return findings;
|
|
4323
|
-
const narrative = resolveNarrative(document, options2);
|
|
4324
|
-
if (narrative) {
|
|
4325
|
-
const id = String(document.narrative);
|
|
4326
|
-
const beatSuggestions = (beat) => narrative.beats.slice().sort((a, b) => distance(beat, a) - distance(beat, b) || (a < b ? -1 : a > b ? 1 : 0)).slice(0, 5).map((value) => ({ value, label: value, origin: narrative.origin, definition: `narratives/${id}#/beats` }));
|
|
4327
|
-
for (const reference of unknownBeatReferences(document, narrative))
|
|
4328
|
-
findings.push(
|
|
4329
|
-
finding("opf/unknown-beat", {
|
|
4330
|
-
path: reference.path,
|
|
4331
|
-
message: `Slide ${reference.slide + 1} names beat ${JSON.stringify(reference.beat)}, which narrative ${JSON.stringify(id)} does not define.`,
|
|
4332
|
-
help: `Use one of the narrative's beat ids (${narrative.beats.join(", ")}), add the beat to the narrative record (a record the document embeds or defines in catalogs.custom.narratives), or remove the beat link. Nothing is drawn from a beat.`,
|
|
4333
|
-
definition: schemas.presentation.$id + "#/$defs/Slide/properties/beat",
|
|
4334
|
-
lookup: ["opf", "catalog", "narratives"],
|
|
4335
|
-
suggestions: beatSuggestions(reference.beat)
|
|
4336
|
-
})
|
|
4337
|
-
);
|
|
4338
|
-
const outside = durationOutsideNarrative(document, narrative);
|
|
4339
|
-
if (outside)
|
|
4340
|
-
findings.push(
|
|
4341
|
-
finding("opf/duration-outside-narrative", {
|
|
4342
|
-
path: "/duration",
|
|
4343
|
-
message: `The target duration of ${outside.duration} minutes is outside the ${describeDurationRange(outside.range)} narrative ${JSON.stringify(id)} suits.`,
|
|
4344
|
-
help: "Change the target duration, choose a narrative that suits it, or widen the range of an inline narrative record. The range describes the narrative, so nothing is drawn or exported differently.",
|
|
4345
|
-
definition: schemas.presentation.$id + "#/properties/duration",
|
|
4346
|
-
lookup: ["opf", "catalog", "narratives"]
|
|
4347
|
-
})
|
|
4348
|
-
);
|
|
4349
|
-
}
|
|
4350
|
-
for (const [group, value] of Object.entries(object(document.catalogs) ? document.catalogs : {}))
|
|
4351
|
-
for (const [id, record] of Object.entries(object(value) && object(value.narratives) ? value.narratives : {})) {
|
|
4352
|
-
if (durationRangeInverted(record))
|
|
4353
|
-
findings.push(
|
|
4354
|
-
finding("opf/narrative-duration-range", {
|
|
4355
|
-
path: pointer3(["catalogs", group, "narratives", id, "duration"]),
|
|
4356
|
-
message: "The narrative duration range has min greater than max.",
|
|
4357
|
-
help: "Swap the bounds so min is the shortest and max the longest talk length, in minutes.",
|
|
4358
|
-
definition: schemas.narrative.$id + "#/properties/duration",
|
|
4359
|
-
lookup: ["opf", "schema", "narrative", "/properties/duration"]
|
|
4360
|
-
})
|
|
4361
|
-
);
|
|
4362
|
-
}
|
|
4363
|
-
return findings;
|
|
4364
|
-
}
|
|
4365
|
-
function contractFindings(document, contracts) {
|
|
4366
|
-
const findings = [];
|
|
4367
|
-
for (const [index, contract2] of contracts.entries()) {
|
|
4368
|
-
const pattern = parts(contract2.path), stack = [{ value: document, path: [], depth: 0 }];
|
|
4369
|
-
while (stack.length) {
|
|
4370
|
-
const entry2 = stack.pop();
|
|
4371
|
-
if (!entry2) break;
|
|
4372
|
-
if (entry2.depth === pattern.length) {
|
|
4373
|
-
if (contract2.allowedValues.some((value) => Object.is(value, entry2.value)))
|
|
4374
|
-
continue;
|
|
4375
|
-
const path = pointer3(entry2.path), definition = contract2.documentation ?? `context#/contracts/${index}`, values = {
|
|
4376
|
-
path,
|
|
4377
|
-
value: JSON.stringify(entry2.value),
|
|
4378
|
-
allowed: contract2.allowedValues.map((value) => JSON.stringify(value)).join(", "),
|
|
4379
|
-
file: definition
|
|
4380
|
-
};
|
|
4381
|
-
const message = (contract2.message ?? "This value is outside the allowed values for {{path}}.").replace(
|
|
4382
|
-
/\{\{(path|value|allowed|file)\}\}/g,
|
|
4383
|
-
(_, key3) => values[key3] ?? ""
|
|
4384
|
-
);
|
|
4385
|
-
findings.push(
|
|
4386
|
-
finding("opf/contract", {
|
|
4387
|
-
severity: contract2.severity ?? "error",
|
|
4388
|
-
path,
|
|
4389
|
-
message,
|
|
4390
|
-
help: `Use one of the configured values: ${values.allowed}. This is an explicit host policy; no source was changed.`,
|
|
4391
|
-
definition,
|
|
4392
|
-
suggestions: contract2.allowedValues.map((value) => ({
|
|
4393
|
-
value,
|
|
4394
|
-
label: String(value),
|
|
4395
|
-
origin: "contract",
|
|
4396
|
-
definition
|
|
4397
|
-
}))
|
|
4398
|
-
})
|
|
4399
|
-
);
|
|
4400
|
-
} else if (object(entry2.value) || Array.isArray(entry2.value)) {
|
|
4401
|
-
const key3 = pattern[entry2.depth];
|
|
4402
|
-
for (const [name, value] of Object.entries(entry2.value))
|
|
4403
|
-
if (key3 === "*" || key3 === name)
|
|
4404
|
-
stack.push({
|
|
4405
|
-
value,
|
|
4406
|
-
path: [...entry2.path, name],
|
|
4407
|
-
depth: entry2.depth + 1
|
|
4408
|
-
});
|
|
4409
|
-
}
|
|
4410
|
-
}
|
|
4411
|
-
}
|
|
4412
|
-
return findings;
|
|
4413
|
-
}
|
|
4414
|
-
|
|
4415
|
-
// src/document-hash.ts
|
|
4416
|
-
function canonicalJson(value) {
|
|
4417
|
-
const stack = [];
|
|
4418
|
-
const write = (item) => {
|
|
4419
|
-
if (item === null || typeof item === "boolean" || typeof item === "string") return JSON.stringify(item);
|
|
4420
|
-
if (typeof item === "number") return JSON.stringify(item);
|
|
4421
|
-
if (typeof item === "bigint") throw new TypeError("A BigInt is not JSON.");
|
|
4422
|
-
if (typeof item !== "object") return void 0;
|
|
4423
|
-
if (stack.includes(item)) throw new TypeError("A cyclic value has no canonical JSON.");
|
|
4424
|
-
stack.push(item);
|
|
4425
|
-
let text2;
|
|
4426
|
-
if (Array.isArray(item)) {
|
|
4427
|
-
text2 = `[${item.map((entry2) => write(entry2) ?? "null").join(",")}]`;
|
|
4428
|
-
} else {
|
|
4429
|
-
const record = item;
|
|
4430
|
-
const members = [];
|
|
4431
|
-
for (const key3 of Object.keys(record).sort()) {
|
|
4432
|
-
const member = write(record[key3]);
|
|
4433
|
-
if (member !== void 0) members.push(`${JSON.stringify(key3)}:${member}`);
|
|
4434
|
-
}
|
|
4435
|
-
text2 = `{${members.join(",")}}`;
|
|
4436
|
-
}
|
|
4437
|
-
stack.pop();
|
|
4438
|
-
return text2;
|
|
4439
|
-
};
|
|
4440
|
-
return write(value) ?? "null";
|
|
4441
|
-
}
|
|
4442
|
-
var K = new Uint32Array([
|
|
4443
|
-
1116352408,
|
|
4444
|
-
1899447441,
|
|
4445
|
-
3049323471,
|
|
4446
|
-
3921009573,
|
|
4447
|
-
961987163,
|
|
4448
|
-
1508970993,
|
|
4449
|
-
2453635748,
|
|
4450
|
-
2870763221,
|
|
4451
|
-
3624381080,
|
|
4452
|
-
310598401,
|
|
4453
|
-
607225278,
|
|
4454
|
-
1426881987,
|
|
4455
|
-
1925078388,
|
|
4456
|
-
2162078206,
|
|
4457
|
-
2614888103,
|
|
4458
|
-
3248222580,
|
|
4459
|
-
3835390401,
|
|
4460
|
-
4022224774,
|
|
4461
|
-
264347078,
|
|
4462
|
-
604807628,
|
|
4463
|
-
770255983,
|
|
4464
|
-
1249150122,
|
|
4465
|
-
1555081692,
|
|
4466
|
-
1996064986,
|
|
4467
|
-
2554220882,
|
|
4468
|
-
2821834349,
|
|
4469
|
-
2952996808,
|
|
4470
|
-
3210313671,
|
|
4471
|
-
3336571891,
|
|
4472
|
-
3584528711,
|
|
4473
|
-
113926993,
|
|
4474
|
-
338241895,
|
|
4475
|
-
666307205,
|
|
4476
|
-
773529912,
|
|
4477
|
-
1294757372,
|
|
4478
|
-
1396182291,
|
|
4479
|
-
1695183700,
|
|
4480
|
-
1986661051,
|
|
4481
|
-
2177026350,
|
|
4482
|
-
2456956037,
|
|
4483
|
-
2730485921,
|
|
4484
|
-
2820302411,
|
|
4485
|
-
3259730800,
|
|
4486
|
-
3345764771,
|
|
4487
|
-
3516065817,
|
|
4488
|
-
3600352804,
|
|
4489
|
-
4094571909,
|
|
4490
|
-
275423344,
|
|
4491
|
-
430227734,
|
|
4492
|
-
506948616,
|
|
4493
|
-
659060556,
|
|
4494
|
-
883997877,
|
|
4495
|
-
958139571,
|
|
4496
|
-
1322822218,
|
|
4497
|
-
1537002063,
|
|
4498
|
-
1747873779,
|
|
4499
|
-
1955562222,
|
|
4500
|
-
2024104815,
|
|
4501
|
-
2227730452,
|
|
4502
|
-
2361852424,
|
|
4503
|
-
2428436474,
|
|
4504
|
-
2756734187,
|
|
4505
|
-
3204031479,
|
|
4506
|
-
3329325298
|
|
4507
|
-
]);
|
|
4508
|
-
function sha256Hex(bytes) {
|
|
4509
|
-
const length = bytes.length;
|
|
4510
|
-
const padded = new Uint8Array(length + 9 + 63 >> 6 << 6);
|
|
4511
|
-
padded.set(bytes);
|
|
4512
|
-
padded[length] = 128;
|
|
4513
|
-
const view = new DataView(padded.buffer);
|
|
4514
|
-
view.setUint32(padded.length - 8, Math.floor(length / 536870912), false);
|
|
4515
|
-
view.setUint32(padded.length - 4, length << 3 >>> 0, false);
|
|
4516
|
-
const h = new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]);
|
|
4517
|
-
const w = new Uint32Array(64);
|
|
4518
|
-
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
4519
|
-
for (let i = 0; i < 16; i += 1) w[i] = view.getUint32(offset + i * 4, false);
|
|
4520
|
-
for (let i = 16; i < 64; i += 1) {
|
|
4521
|
-
const a2 = w[i - 15], b2 = w[i - 2];
|
|
4522
|
-
const s0 = (a2 >>> 7 | a2 << 25) ^ (a2 >>> 18 | a2 << 14) ^ a2 >>> 3;
|
|
4523
|
-
const s1 = (b2 >>> 17 | b2 << 15) ^ (b2 >>> 19 | b2 << 13) ^ b2 >>> 10;
|
|
4524
|
-
w[i] = w[i - 16] + s0 + w[i - 7] + s1 | 0;
|
|
4525
|
-
}
|
|
4526
|
-
let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];
|
|
4527
|
-
for (let i = 0; i < 64; i += 1) {
|
|
4528
|
-
const s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
4529
|
-
const choose = e & f ^ ~e & g;
|
|
4530
|
-
const t1 = hh + s1 + choose + K[i] + w[i] | 0;
|
|
4531
|
-
const s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
4532
|
-
const majority = a & b ^ a & c ^ b & c;
|
|
4533
|
-
const t2 = s0 + majority | 0;
|
|
4534
|
-
hh = g;
|
|
4535
|
-
g = f;
|
|
4536
|
-
f = e;
|
|
4537
|
-
e = d + t1 | 0;
|
|
4538
|
-
d = c;
|
|
4539
|
-
c = b;
|
|
4540
|
-
b = a;
|
|
4541
|
-
a = t1 + t2 | 0;
|
|
4542
|
-
}
|
|
4543
|
-
h[0] = h[0] + a | 0;
|
|
4544
|
-
h[1] = h[1] + b | 0;
|
|
4545
|
-
h[2] = h[2] + c | 0;
|
|
4546
|
-
h[3] = h[3] + d | 0;
|
|
4547
|
-
h[4] = h[4] + e | 0;
|
|
4548
|
-
h[5] = h[5] + f | 0;
|
|
4549
|
-
h[6] = h[6] + g | 0;
|
|
4550
|
-
h[7] = h[7] + hh | 0;
|
|
4895
|
+
help: "Reference the dataset from chart.data or a table so it is drawn, or remove the entry. Nothing is drawn for an unreferenced dataset.",
|
|
4896
|
+
definition: schemas.presentation.$id + "#/$defs/Dataset",
|
|
4897
|
+
lookup: ["opf", "schema", "presentation", "/$defs/Dataset"]
|
|
4898
|
+
})
|
|
4899
|
+
);
|
|
4900
|
+
for (const { path, value } of documentIcons(document)) {
|
|
4901
|
+
const issue2 = iconIssue(document, value, catalogs);
|
|
4902
|
+
if (!issue2) continue;
|
|
4903
|
+
const unknown = issue2.code === "icon-unknown";
|
|
4904
|
+
findings.push(
|
|
4905
|
+
finding(unknown ? "opf/icon-unknown" : "opf/icon-invalid", {
|
|
4906
|
+
path: pointerPath(path.split(".")),
|
|
4907
|
+
message: issue2.message,
|
|
4908
|
+
help: unknown ? `${issue2.suggestions?.length ? `Did you mean ${issue2.suggestions.slice(0, 3).map((name) => `'${name}'`).join(", ")}? ` : ""}Use an icon the set has (the MCP's search_icons finds names by keyword), add the name to the deck's icons, or remove the icon. Nothing else changes: the text is drawn without the chip.` : "Give the icon SVG text with only shapes (path, circle, rect, line, polyline, polygon and groups), no script, event handler, external reference or raster, or remove the icon.",
|
|
4909
|
+
definition: `${schemas.presentation.$id}#/$defs/IconReference`,
|
|
4910
|
+
lookup: ["opf", "schema", "presentation", "/$defs/IconReference"],
|
|
4911
|
+
...issue2.suggestions?.length ? { suggestions: issue2.suggestions.map((value2) => ({ value: value2, label: value2, origin: "registered", definition: `${schemas.presentation.$id}#/$defs/IconReference` })) } : {},
|
|
4912
|
+
...issue2.renamed ? { fixes: [{ id: "icon-renamed", title: "Use the new name", kind: "patch", safe: true, patch: [{ op: "replace", path: pointerPath(path.split(".")), value: issue2.renamed }] }] } : {}
|
|
4913
|
+
})
|
|
4914
|
+
);
|
|
4551
4915
|
}
|
|
4552
|
-
|
|
4553
|
-
for (const word of h) hex += word.toString(16).padStart(8, "0");
|
|
4554
|
-
return hex;
|
|
4916
|
+
return findings;
|
|
4555
4917
|
}
|
|
4556
|
-
function
|
|
4557
|
-
|
|
4918
|
+
function narrativeFindings(document, options2) {
|
|
4919
|
+
const findings = [];
|
|
4920
|
+
if (!object(document)) return findings;
|
|
4921
|
+
const narrative = resolveNarrative(document, options2);
|
|
4922
|
+
if (narrative) {
|
|
4923
|
+
const id = String(document.narrative);
|
|
4924
|
+
const beatSuggestions = (beat) => narrative.beats.slice().sort((a, b) => distance2(beat, a) - distance2(beat, b) || (a < b ? -1 : a > b ? 1 : 0)).slice(0, 5).map((value) => ({ value, label: value, origin: narrative.origin, definition: `narratives/${id}#/beats` }));
|
|
4925
|
+
for (const reference of unknownBeatReferences(document, narrative))
|
|
4926
|
+
findings.push(
|
|
4927
|
+
finding("opf/unknown-beat", {
|
|
4928
|
+
path: reference.path,
|
|
4929
|
+
message: `Slide ${reference.slide + 1} names beat ${JSON.stringify(reference.beat)}, which narrative ${JSON.stringify(id)} does not define.`,
|
|
4930
|
+
help: `Use one of the narrative's beat ids (${narrative.beats.join(", ")}), add the beat to the narrative record (a record the document embeds or defines in catalogs.custom.narratives), or remove the beat link. Nothing is drawn from a beat.`,
|
|
4931
|
+
definition: schemas.presentation.$id + "#/$defs/Slide/properties/beat",
|
|
4932
|
+
lookup: ["opf", "catalog", "narratives"],
|
|
4933
|
+
suggestions: beatSuggestions(reference.beat)
|
|
4934
|
+
})
|
|
4935
|
+
);
|
|
4936
|
+
const outside = durationOutsideNarrative(document, narrative);
|
|
4937
|
+
if (outside)
|
|
4938
|
+
findings.push(
|
|
4939
|
+
finding("opf/duration-outside-narrative", {
|
|
4940
|
+
path: "/duration",
|
|
4941
|
+
message: `The target duration of ${outside.duration} minutes is outside the ${describeDurationRange(outside.range)} narrative ${JSON.stringify(id)} suits.`,
|
|
4942
|
+
help: "Change the target duration, choose a narrative that suits it, or widen the range of an inline narrative record. The range describes the narrative, so nothing is drawn or exported differently.",
|
|
4943
|
+
definition: schemas.presentation.$id + "#/properties/duration",
|
|
4944
|
+
lookup: ["opf", "catalog", "narratives"]
|
|
4945
|
+
})
|
|
4946
|
+
);
|
|
4947
|
+
}
|
|
4948
|
+
for (const [group, value] of Object.entries(object(document.catalogs) ? document.catalogs : {}))
|
|
4949
|
+
for (const [id, record] of Object.entries(object(value) && object(value.narratives) ? value.narratives : {})) {
|
|
4950
|
+
if (durationRangeInverted(record))
|
|
4951
|
+
findings.push(
|
|
4952
|
+
finding("opf/narrative-duration-range", {
|
|
4953
|
+
path: pointer4(["catalogs", group, "narratives", id, "duration"]),
|
|
4954
|
+
message: "The narrative duration range has min greater than max.",
|
|
4955
|
+
help: "Swap the bounds so min is the shortest and max the longest talk length, in minutes.",
|
|
4956
|
+
definition: schemas.narrative.$id + "#/properties/duration",
|
|
4957
|
+
lookup: ["opf", "schema", "narrative", "/properties/duration"]
|
|
4958
|
+
})
|
|
4959
|
+
);
|
|
4960
|
+
}
|
|
4961
|
+
return findings;
|
|
4558
4962
|
}
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4963
|
+
function contractFindings(document, contracts) {
|
|
4964
|
+
const findings = [];
|
|
4965
|
+
for (const [index, contract2] of contracts.entries()) {
|
|
4966
|
+
const pattern = parts(contract2.path), stack = [{ value: document, path: [], depth: 0 }];
|
|
4967
|
+
while (stack.length) {
|
|
4968
|
+
const entry2 = stack.pop();
|
|
4969
|
+
if (!entry2) break;
|
|
4970
|
+
if (entry2.depth === pattern.length) {
|
|
4971
|
+
if (contract2.allowedValues.some((value) => Object.is(value, entry2.value)))
|
|
4972
|
+
continue;
|
|
4973
|
+
const path = pointer4(entry2.path), definition = contract2.documentation ?? `context#/contracts/${index}`, values = {
|
|
4974
|
+
path,
|
|
4975
|
+
value: JSON.stringify(entry2.value),
|
|
4976
|
+
allowed: contract2.allowedValues.map((value) => JSON.stringify(value)).join(", "),
|
|
4977
|
+
file: definition
|
|
4978
|
+
};
|
|
4979
|
+
const message = (contract2.message ?? "This value is outside the allowed values for {{path}}.").replace(
|
|
4980
|
+
/\{\{(path|value|allowed|file)\}\}/g,
|
|
4981
|
+
(_, key3) => values[key3] ?? ""
|
|
4982
|
+
);
|
|
4983
|
+
findings.push(
|
|
4984
|
+
finding("opf/contract", {
|
|
4985
|
+
severity: contract2.severity ?? "error",
|
|
4986
|
+
path,
|
|
4987
|
+
message,
|
|
4988
|
+
help: `Use one of the configured values: ${values.allowed}. This is an explicit host policy; no source was changed.`,
|
|
4989
|
+
definition,
|
|
4990
|
+
suggestions: contract2.allowedValues.map((value) => ({
|
|
4991
|
+
value,
|
|
4992
|
+
label: String(value),
|
|
4993
|
+
origin: "contract",
|
|
4994
|
+
definition
|
|
4995
|
+
}))
|
|
4996
|
+
})
|
|
4997
|
+
);
|
|
4998
|
+
} else if (object(entry2.value) || Array.isArray(entry2.value)) {
|
|
4999
|
+
const key3 = pattern[entry2.depth];
|
|
5000
|
+
for (const [name, value] of Object.entries(entry2.value))
|
|
5001
|
+
if (key3 === "*" || key3 === name)
|
|
5002
|
+
stack.push({
|
|
5003
|
+
value,
|
|
5004
|
+
path: [...entry2.path, name],
|
|
5005
|
+
depth: entry2.depth + 1
|
|
5006
|
+
});
|
|
5007
|
+
}
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
return findings;
|
|
4564
5011
|
}
|
|
4565
5012
|
|
|
4566
5013
|
// src/patch.ts
|
|
@@ -4602,7 +5049,7 @@ var OPFPatchHashError = class extends OPFPatchError {
|
|
|
4602
5049
|
}
|
|
4603
5050
|
};
|
|
4604
5051
|
var own2 = (value, key3) => Object.prototype.hasOwnProperty.call(value, key3);
|
|
4605
|
-
var
|
|
5052
|
+
var isObject2 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
4606
5053
|
var clone = (value) => structuredClone(value);
|
|
4607
5054
|
function jsonEqual(a, b) {
|
|
4608
5055
|
if (a === b) return true;
|
|
@@ -4622,11 +5069,11 @@ function escapePointerToken(token) {
|
|
|
4622
5069
|
function unescapePointerToken(token) {
|
|
4623
5070
|
return token.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
4624
5071
|
}
|
|
4625
|
-
function parsePointer(
|
|
4626
|
-
if (typeof
|
|
4627
|
-
throw new OPFPatchError("invalid-json-pointer", "Expected a JSON Pointer (empty string or /path with ~0 and ~1 escapes).", { path: typeof
|
|
5072
|
+
function parsePointer(pointer5) {
|
|
5073
|
+
if (typeof pointer5 !== "string" || pointer5 !== "" && !pointer5.startsWith("/") || /~(?![01])/u.test(pointer5)) {
|
|
5074
|
+
throw new OPFPatchError("invalid-json-pointer", "Expected a JSON Pointer (empty string or /path with ~0 and ~1 escapes).", { path: typeof pointer5 === "string" ? pointer5 : void 0 });
|
|
4628
5075
|
}
|
|
4629
|
-
return
|
|
5076
|
+
return pointer5 === "" ? [] : pointer5.slice(1).split("/").map(unescapePointerToken);
|
|
4630
5077
|
}
|
|
4631
5078
|
function formatPointer(tokens) {
|
|
4632
5079
|
return tokens.length ? `/${tokens.map(escapePointerToken).join("/")}` : "";
|
|
@@ -4641,9 +5088,9 @@ function pointerFromPath(path) {
|
|
|
4641
5088
|
}
|
|
4642
5089
|
return formatPointer(path.split(".").filter(Boolean));
|
|
4643
5090
|
}
|
|
4644
|
-
function splitPointer2(
|
|
4645
|
-
const tokens = parsePointer(
|
|
4646
|
-
if (!tokens.length) throw new OPFPatchError("invalid-json-pointer", "The root pointer has no parent.", { path:
|
|
5091
|
+
function splitPointer2(pointer5) {
|
|
5092
|
+
const tokens = parsePointer(pointer5);
|
|
5093
|
+
if (!tokens.length) throw new OPFPatchError("invalid-json-pointer", "The root pointer has no parent.", { path: pointer5 });
|
|
4647
5094
|
return { parent: formatPointer(tokens.slice(0, -1)), token: tokens[tokens.length - 1] };
|
|
4648
5095
|
}
|
|
4649
5096
|
var isIdToken = (token) => token.length > 1 && token.startsWith("@");
|
|
@@ -4653,7 +5100,7 @@ function indexOfId(array, id) {
|
|
|
4653
5100
|
let found = -1;
|
|
4654
5101
|
for (let i = 0; i < array.length; i += 1) {
|
|
4655
5102
|
const item = array[i];
|
|
4656
|
-
if (
|
|
5103
|
+
if (isObject2(item) && own2(item, "id") && item.id === id) {
|
|
4657
5104
|
if (found !== -1) return -2;
|
|
4658
5105
|
found = i;
|
|
4659
5106
|
}
|
|
@@ -4662,32 +5109,32 @@ function indexOfId(array, id) {
|
|
|
4662
5109
|
}
|
|
4663
5110
|
function uniqueIdAt(array, at2) {
|
|
4664
5111
|
const item = array[at2];
|
|
4665
|
-
if (!
|
|
5112
|
+
if (!isObject2(item) || !own2(item, "id") || typeof item.id !== "string" || item.id === "") return void 0;
|
|
4666
5113
|
return indexOfId(array, item.id) === at2 ? item.id : void 0;
|
|
4667
5114
|
}
|
|
4668
|
-
function resolveTokens(document, tokens,
|
|
5115
|
+
function resolveTokens(document, tokens, pointer5) {
|
|
4669
5116
|
const out = [];
|
|
4670
5117
|
let cursor = document, walking = true;
|
|
4671
5118
|
for (const token of tokens) {
|
|
4672
|
-
let
|
|
5119
|
+
let resolved2 = token;
|
|
4673
5120
|
if (walking && Array.isArray(cursor) && isIdToken(token)) {
|
|
4674
5121
|
const at2 = indexOfId(cursor, token.slice(1));
|
|
4675
|
-
if (at2 === -1) throw new OPFPatchError("patch-id-not-found", `No element of ${formatPointer(out) || "/"} has the id '${token.slice(1)}'.`, { path:
|
|
4676
|
-
if (at2 === -2) throw new OPFPatchError("patch-id-ambiguous", `More than one element of ${formatPointer(out) || "/"} has the id '${token.slice(1)}'.`, { path:
|
|
4677
|
-
|
|
5122
|
+
if (at2 === -1) throw new OPFPatchError("patch-id-not-found", `No element of ${formatPointer(out) || "/"} has the id '${token.slice(1)}'.`, { path: pointer5 });
|
|
5123
|
+
if (at2 === -2) throw new OPFPatchError("patch-id-ambiguous", `More than one element of ${formatPointer(out) || "/"} has the id '${token.slice(1)}'.`, { path: pointer5 });
|
|
5124
|
+
resolved2 = String(at2);
|
|
4678
5125
|
}
|
|
4679
|
-
out.push(
|
|
5126
|
+
out.push(resolved2);
|
|
4680
5127
|
if (walking) {
|
|
4681
|
-
const next = readPointer(cursor, [
|
|
5128
|
+
const next = readPointer(cursor, [resolved2]);
|
|
4682
5129
|
if (next.found) cursor = next.value;
|
|
4683
5130
|
else walking = false;
|
|
4684
5131
|
}
|
|
4685
5132
|
}
|
|
4686
5133
|
return out;
|
|
4687
5134
|
}
|
|
4688
|
-
function resolveIdPointer(document,
|
|
4689
|
-
const tokens = parsePointer(
|
|
4690
|
-
return tokens.some(isIdToken) ? formatPointer(resolveTokens(document, tokens,
|
|
5135
|
+
function resolveIdPointer(document, pointer5) {
|
|
5136
|
+
const tokens = parsePointer(pointer5);
|
|
5137
|
+
return tokens.some(isIdToken) ? formatPointer(resolveTokens(document, tokens, pointer5)) : pointer5;
|
|
4691
5138
|
}
|
|
4692
5139
|
function idTokens(document, tokens, convertLast) {
|
|
4693
5140
|
const out = [];
|
|
@@ -4707,11 +5154,11 @@ function idTokens(document, tokens, convertLast) {
|
|
|
4707
5154
|
});
|
|
4708
5155
|
return out;
|
|
4709
5156
|
}
|
|
4710
|
-
function toIdPointer(document,
|
|
4711
|
-
return formatPointer(idTokens(document, resolveTokens(document, parsePointer(
|
|
5157
|
+
function toIdPointer(document, pointer5, options2 = {}) {
|
|
5158
|
+
return formatPointer(idTokens(document, resolveTokens(document, parsePointer(pointer5), pointer5), !options2.keepLast));
|
|
4712
5159
|
}
|
|
4713
|
-
function readPointer(document,
|
|
4714
|
-
const tokens = typeof
|
|
5160
|
+
function readPointer(document, pointer5) {
|
|
5161
|
+
const tokens = typeof pointer5 === "string" ? parsePointer(pointer5) : pointer5;
|
|
4715
5162
|
let value = document;
|
|
4716
5163
|
for (const token of tokens) {
|
|
4717
5164
|
if (Array.isArray(value)) {
|
|
@@ -4730,15 +5177,15 @@ function readPointer(document, pointer4) {
|
|
|
4730
5177
|
}
|
|
4731
5178
|
return { found: true, value };
|
|
4732
5179
|
}
|
|
4733
|
-
function getAtPointer(document,
|
|
4734
|
-
const result = readPointer(document,
|
|
5180
|
+
function getAtPointer(document, pointer5) {
|
|
5181
|
+
const result = readPointer(document, pointer5);
|
|
4735
5182
|
if (!result.found) {
|
|
4736
|
-
const shown = typeof
|
|
5183
|
+
const shown = typeof pointer5 === "string" ? pointer5 : formatPointer(pointer5);
|
|
4737
5184
|
throw new OPFPatchError("patch-path-missing", `Patch path does not exist: ${shown || "/"}`, { path: shown });
|
|
4738
5185
|
}
|
|
4739
5186
|
return result.value;
|
|
4740
5187
|
}
|
|
4741
|
-
var hasPointer = (document,
|
|
5188
|
+
var hasPointer = (document, pointer5) => readPointer(document, pointer5).found;
|
|
4742
5189
|
function arrayIndex(token, length, allowEnd, path) {
|
|
4743
5190
|
if (allowEnd && token === "-") return length;
|
|
4744
5191
|
if (!INDEX_TOKEN.test(token)) throw new OPFPatchError("invalid-array-index", `Invalid array index: ${token}`, { path });
|
|
@@ -4752,7 +5199,7 @@ function normalizePatch(patch2) {
|
|
|
4752
5199
|
}
|
|
4753
5200
|
function normalizeOperation(operation, index) {
|
|
4754
5201
|
const fail = (code2, message, path) => new OPFPatchError(code2, index === void 0 ? message : `Operation ${index}: ${message}`, { index, operation, path });
|
|
4755
|
-
if (!
|
|
5202
|
+
if (!isObject2(operation)) throw fail("invalid-patch-operation", "Expected an operation object.");
|
|
4756
5203
|
const op = operation.op;
|
|
4757
5204
|
if (typeof op !== "string" || !["add", "remove", "replace", "move", "copy", "test"].includes(op)) {
|
|
4758
5205
|
throw fail("unsupported-patch-operation", `Unknown operation: ${String(op)}`);
|
|
@@ -4792,33 +5239,33 @@ function addAt(document, path, value) {
|
|
|
4792
5239
|
if (Array.isArray(parent)) {
|
|
4793
5240
|
const at2 = arrayIndex(key3, parent.length, true, path);
|
|
4794
5241
|
parent.splice(at2, 0, clone(value));
|
|
4795
|
-
const
|
|
4796
|
-
return { document, inverse: { op: "remove", path:
|
|
5242
|
+
const pointer6 = formatPointer([...tokens.slice(0, -1), at2]);
|
|
5243
|
+
return { document, inverse: { op: "remove", path: pointer6 }, pointer: pointer6 };
|
|
4797
5244
|
}
|
|
4798
5245
|
const record = parent;
|
|
4799
5246
|
const previous = own2(record, key3) ? record[key3] : NONE;
|
|
4800
5247
|
Object.defineProperty(record, key3, { value: clone(value), enumerable: true, configurable: true, writable: true });
|
|
4801
|
-
const
|
|
4802
|
-
return { document, inverse: previous === NONE ? { op: "remove", path:
|
|
5248
|
+
const pointer5 = formatPointer(tokens);
|
|
5249
|
+
return { document, inverse: previous === NONE ? { op: "remove", path: pointer5 } : { op: "replace", path: pointer5, value: clone(previous) }, pointer: pointer5 };
|
|
4803
5250
|
}
|
|
4804
5251
|
function replaceAt(document, path, value) {
|
|
4805
5252
|
const tokens = resolveTokens(document, parsePointer(path), path);
|
|
4806
5253
|
if (!tokens.length) return { document: clone(value), inverse: { op: "replace", path: "", value: clone(document) }, pointer: "" };
|
|
4807
5254
|
const { parent, key: key3 } = parentOf(document, tokens, path);
|
|
4808
5255
|
let previous;
|
|
4809
|
-
let
|
|
5256
|
+
let pointer5 = formatPointer(tokens);
|
|
4810
5257
|
if (Array.isArray(parent)) {
|
|
4811
5258
|
const at2 = arrayIndex(key3, parent.length, false, path);
|
|
4812
5259
|
previous = parent[at2];
|
|
4813
5260
|
parent[at2] = clone(value);
|
|
4814
|
-
|
|
5261
|
+
pointer5 = formatPointer([...tokens.slice(0, -1), at2]);
|
|
4815
5262
|
} else {
|
|
4816
5263
|
const record = parent;
|
|
4817
5264
|
if (!own2(record, key3)) throw new OPFPatchError("patch-path-missing", `Patch path does not exist: ${path}.`, { path });
|
|
4818
5265
|
previous = record[key3];
|
|
4819
5266
|
Object.defineProperty(record, key3, { value: clone(value), enumerable: true, configurable: true, writable: true });
|
|
4820
5267
|
}
|
|
4821
|
-
return { document, inverse: { op: "replace", path:
|
|
5268
|
+
return { document, inverse: { op: "replace", path: pointer5, value: clone(previous) }, pointer: pointer5 };
|
|
4822
5269
|
}
|
|
4823
5270
|
function removeAt(document, path) {
|
|
4824
5271
|
const tokens = resolveTokens(document, parsePointer(path), path);
|
|
@@ -4829,15 +5276,15 @@ function removeAt(document, path) {
|
|
|
4829
5276
|
const at2 = arrayIndex(key3, parent.length, false, path);
|
|
4830
5277
|
previous = parent[at2];
|
|
4831
5278
|
parent.splice(at2, 1);
|
|
4832
|
-
const
|
|
4833
|
-
return { document, inverse: { op: "add", path:
|
|
5279
|
+
const pointer6 = formatPointer([...tokens.slice(0, -1), at2]);
|
|
5280
|
+
return { document, inverse: { op: "add", path: pointer6, value: clone(previous) }, pointer: pointer6 };
|
|
4834
5281
|
}
|
|
4835
5282
|
const record = parent;
|
|
4836
5283
|
if (!own2(record, key3)) throw new OPFPatchError("patch-path-missing", `Patch path does not exist: ${path}.`, { path });
|
|
4837
5284
|
previous = record[key3];
|
|
4838
5285
|
delete record[key3];
|
|
4839
|
-
const
|
|
4840
|
-
return { document, inverse: { op: "add", path:
|
|
5286
|
+
const pointer5 = formatPointer(tokens);
|
|
5287
|
+
return { document, inverse: { op: "add", path: pointer5, value: clone(previous) }, pointer: pointer5 };
|
|
4841
5288
|
}
|
|
4842
5289
|
function applyOne(document, operation) {
|
|
4843
5290
|
switch (operation.op) {
|
|
@@ -4929,18 +5376,18 @@ function invertPatch(document, patch2) {
|
|
|
4929
5376
|
return applyPatchWithInverse(document, patch2).inverse;
|
|
4930
5377
|
}
|
|
4931
5378
|
function resolveIdPatch(document, patch2) {
|
|
4932
|
-
const
|
|
5379
|
+
const resolved2 = [];
|
|
4933
5380
|
walkPatch(document, patch2, { after: (step) => {
|
|
4934
|
-
|
|
5381
|
+
resolved2.push(step.resolved);
|
|
4935
5382
|
} });
|
|
4936
|
-
return
|
|
5383
|
+
return resolved2;
|
|
4937
5384
|
}
|
|
4938
5385
|
function toIdPatch(document, patch2) {
|
|
4939
5386
|
const out = [];
|
|
4940
5387
|
const pending = /* @__PURE__ */ new Map();
|
|
4941
5388
|
walkPatch(document, patch2, {
|
|
4942
5389
|
before: (index, operation, working) => {
|
|
4943
|
-
const named = (
|
|
5390
|
+
const named = (pointer5) => toIdPointer(working, pointer5);
|
|
4944
5391
|
switch (operation.op) {
|
|
4945
5392
|
case "replace":
|
|
4946
5393
|
case "remove":
|
|
@@ -5009,17 +5456,17 @@ function splitOpfPath(path) {
|
|
|
5009
5456
|
if (path.startsWith("/")) return parsePointer(path);
|
|
5010
5457
|
return path.split(".").filter(Boolean);
|
|
5011
5458
|
}
|
|
5012
|
-
function readSchemaPointer(target,
|
|
5459
|
+
function readSchemaPointer(target, pointer5) {
|
|
5013
5460
|
let current = target;
|
|
5014
|
-
for (const token of parsePointer(
|
|
5461
|
+
for (const token of parsePointer(pointer5)) {
|
|
5015
5462
|
if (current === null || typeof current !== "object" || !own3(current, token)) return void 0;
|
|
5016
5463
|
current = current[token];
|
|
5017
5464
|
}
|
|
5018
5465
|
return current;
|
|
5019
5466
|
}
|
|
5020
5467
|
for (const [key3, kind] of Object.entries(schemaCatalogKinds)) {
|
|
5021
|
-
const [name = "",
|
|
5022
|
-
const node = readSchemaPointer(schemas[name],
|
|
5468
|
+
const [name = "", pointer5 = ""] = key3.split("#");
|
|
5469
|
+
const node = readSchemaPointer(schemas[name], pointer5);
|
|
5023
5470
|
if (node === void 0 || node === null || typeof node !== "object") throw new Error(`schemaCatalogKinds: ${key3} is not a schema node.`);
|
|
5024
5471
|
catalogKindOfNode.set(node, kind);
|
|
5025
5472
|
}
|
|
@@ -5037,20 +5484,20 @@ function mergeAllOf(schema, root, seen) {
|
|
|
5037
5484
|
const { allOf, ...base } = schema;
|
|
5038
5485
|
let merged = base;
|
|
5039
5486
|
for (const member of allOf) {
|
|
5040
|
-
const
|
|
5041
|
-
if (!
|
|
5487
|
+
const resolved2 = resolveSchema(member, root, new Set(seen));
|
|
5488
|
+
if (!resolved2.properties && !resolved2.type && !resolved2.oneOf && !resolved2.anyOf) continue;
|
|
5042
5489
|
merged = {
|
|
5043
|
-
...
|
|
5490
|
+
...resolved2,
|
|
5044
5491
|
...merged,
|
|
5045
|
-
...
|
|
5492
|
+
...resolved2.properties || merged.properties ? { properties: { ...resolved2.properties, ...merged.properties } } : {}
|
|
5046
5493
|
};
|
|
5047
5494
|
}
|
|
5048
5495
|
return merged;
|
|
5049
5496
|
}
|
|
5050
5497
|
function resolveSchema(schema, root = presentationSchema, seen = /* @__PURE__ */ new Set()) {
|
|
5051
|
-
const
|
|
5498
|
+
const resolved2 = resolveNode(schema, root, seen);
|
|
5052
5499
|
const kind = schema && typeof schema === "object" ? kindOfNode(schema) : void 0;
|
|
5053
|
-
return kind === void 0 ?
|
|
5500
|
+
return kind === void 0 ? resolved2 : { ...resolved2, [CATALOG_KIND]: kind };
|
|
5054
5501
|
}
|
|
5055
5502
|
function resolveNode(schema, root, seen) {
|
|
5056
5503
|
if (!schema || typeof schema !== "object") return {};
|
|
@@ -5061,18 +5508,18 @@ function resolveNode(schema, root, seen) {
|
|
|
5061
5508
|
const [id = "", fragment = ""] = ref.split("#");
|
|
5062
5509
|
const target = id ? documents.get(id) : root;
|
|
5063
5510
|
if (!target) throw new Error(`Unresolved OPF schema: ${ref}`);
|
|
5064
|
-
let
|
|
5065
|
-
if (!
|
|
5066
|
-
if (id && target !== root)
|
|
5511
|
+
let resolved2 = fragment ? readSchemaPointer(target, fragment) : target;
|
|
5512
|
+
if (!resolved2) throw new Error(`Unresolved OPF schema: ${ref}`);
|
|
5513
|
+
if (id && target !== root) resolved2 = absolutize(resolved2, id);
|
|
5067
5514
|
const { $ref: _ref, ...rest } = schema;
|
|
5068
|
-
return mergeAllOf({ ...resolveSchema(
|
|
5515
|
+
return mergeAllOf({ ...resolveSchema(resolved2, target, seen), ...rest }, target, seen);
|
|
5069
5516
|
}
|
|
5070
5517
|
function schemaVariants(schema, root = presentationSchema) {
|
|
5071
|
-
const
|
|
5072
|
-
if (Array.isArray(
|
|
5073
|
-
const variants =
|
|
5074
|
-
if (!variants) return [
|
|
5075
|
-
const { $ref: _ref, oneOf: _oneOf, anyOf: _anyOf, ...base } =
|
|
5518
|
+
const resolved2 = resolveSchema(schema, root);
|
|
5519
|
+
if (Array.isArray(resolved2.type)) return resolved2.type.flatMap((type) => schemaVariants({ ...resolved2, type }, root));
|
|
5520
|
+
const variants = resolved2.oneOf ?? resolved2.anyOf;
|
|
5521
|
+
if (!variants) return [resolved2];
|
|
5522
|
+
const { $ref: _ref, oneOf: _oneOf, anyOf: _anyOf, ...base } = resolved2;
|
|
5076
5523
|
return variants.flatMap(
|
|
5077
5524
|
(child) => schemaVariants(child, root).map((variant) => {
|
|
5078
5525
|
const requiredOnly = !variant.type && !variant.properties && !variant.$ref && Array.isArray(variant.required);
|
|
@@ -5135,14 +5582,14 @@ function walk(presentation, parts2, rootSchema) {
|
|
|
5135
5582
|
let known = true;
|
|
5136
5583
|
for (let index = 0; index < parts2.length; index++) {
|
|
5137
5584
|
const key3 = parts2[index];
|
|
5138
|
-
const
|
|
5139
|
-
parent =
|
|
5585
|
+
const resolved2 = stepSchema(current, value, key3, root);
|
|
5586
|
+
parent = resolved2;
|
|
5140
5587
|
let next;
|
|
5141
5588
|
const recordSchema = parts2[0] === "catalogs" && index === 3 ? catalogSchemaNames[parts2[2]] : void 0;
|
|
5142
5589
|
if (recordSchema) {
|
|
5143
5590
|
next = schemas[recordSchema] ?? {};
|
|
5144
5591
|
root = next;
|
|
5145
|
-
} else next = childSchema(
|
|
5592
|
+
} else next = childSchema(resolved2, key3, value);
|
|
5146
5593
|
if (next === void 0) {
|
|
5147
5594
|
known = false;
|
|
5148
5595
|
next = {};
|
|
@@ -5223,10 +5670,6 @@ var COMMON_KEYS = Object.freeze({
|
|
|
5223
5670
|
var UNRANKED_PRIORITY = 1e6;
|
|
5224
5671
|
var DEFINITION_LISTS = { Slide: COMMON_KEYS.slide, Design: COMMON_KEYS.design, SlideDesign: COMMON_KEYS.design };
|
|
5225
5672
|
var ADVANCED_KEYS = /* @__PURE__ */ new Set(["extensions", "$schema"]);
|
|
5226
|
-
var REGION_KEY = /^(?:(?:top|middle|bottom)(?:\+(?:top|middle|bottom))*)?(?::)?(?:(?:start|center|end)(?:\+(?:start|center|end))*)?$/;
|
|
5227
|
-
function isPromotedRegionKey(key3) {
|
|
5228
|
-
return key3 !== "" && key3 !== ":" && REGION_KEY.test(key3);
|
|
5229
|
-
}
|
|
5230
5673
|
var uniq = (items) => [...new Set(items)];
|
|
5231
5674
|
function variantType(variant) {
|
|
5232
5675
|
if (typeof variant.type === "string") return variant.type;
|
|
@@ -5300,23 +5743,23 @@ function objectForm(variants, value) {
|
|
|
5300
5743
|
const required = used.length ? (used[0]?.required ?? []).filter((key3) => used.every((variant) => (variant.required ?? []).includes(key3))) : [];
|
|
5301
5744
|
return { properties, required };
|
|
5302
5745
|
}
|
|
5303
|
-
function childrenOf(form, list,
|
|
5746
|
+
function childrenOf(form, list, root) {
|
|
5304
5747
|
const children = [];
|
|
5305
5748
|
for (const [key3, raw] of form.properties) {
|
|
5306
|
-
const
|
|
5749
|
+
const resolved2 = resolveSchema(raw, root);
|
|
5307
5750
|
const variants = schemaVariants(raw, root);
|
|
5308
|
-
const description = firstParagraph(
|
|
5309
|
-
const catalogKind = catalogKindOf(
|
|
5751
|
+
const description = firstParagraph(resolved2.description);
|
|
5752
|
+
const catalogKind = catalogKindOf(resolved2, variants);
|
|
5310
5753
|
children.push({
|
|
5311
5754
|
key: key3,
|
|
5312
5755
|
types: uniq(variants.map(variantType)),
|
|
5313
5756
|
typeLabel: typeLabelOf(raw, variants, root),
|
|
5314
5757
|
required: form.required.includes(key3),
|
|
5315
|
-
advanced: ADVANCED_KEYS.has(key3)
|
|
5758
|
+
advanced: ADVANCED_KEYS.has(key3),
|
|
5316
5759
|
priority: priorityOf(list, key3),
|
|
5317
5760
|
...description ? { description } : {},
|
|
5318
5761
|
...catalogKind ? { catalogKind } : {},
|
|
5319
|
-
...
|
|
5762
|
+
...resolved2.deprecated === true ? { deprecated: true } : {},
|
|
5320
5763
|
hasEnum: variants.some((variant) => Array.isArray(variant.enum) || variant.const !== void 0)
|
|
5321
5764
|
});
|
|
5322
5765
|
}
|
|
@@ -5326,7 +5769,7 @@ function childrenOf(form, list, isSlide, root) {
|
|
|
5326
5769
|
}
|
|
5327
5770
|
function nodeSegments(path) {
|
|
5328
5771
|
const parts2 = splitOpfPath(path);
|
|
5329
|
-
const shown = Array.isArray(path) ? [...path] : parts2.map((
|
|
5772
|
+
const shown = Array.isArray(path) ? [...path] : parts2.map((part2) => /^(?:0|[1-9][0-9]*)$/.test(part2) ? Number(part2) : part2);
|
|
5330
5773
|
return { parts: parts2, shown };
|
|
5331
5774
|
}
|
|
5332
5775
|
var MAX_ITEM_DEPTH = 3;
|
|
@@ -5338,9 +5781,9 @@ function describeAt(presentation, path, depth2) {
|
|
|
5338
5781
|
} catch {
|
|
5339
5782
|
return unknownField(Array.isArray(path) ? [...path] : [], "");
|
|
5340
5783
|
}
|
|
5341
|
-
const
|
|
5784
|
+
const pointer5 = formatPointer(parts2);
|
|
5342
5785
|
const found = walk(presentation, parts2, presentationSchema);
|
|
5343
|
-
if (!found.known) return unknownField(shown,
|
|
5786
|
+
if (!found.known) return unknownField(shown, pointer5);
|
|
5344
5787
|
const { raw, schema, root, parent, value } = found;
|
|
5345
5788
|
const variants = schemaVariants(raw, root);
|
|
5346
5789
|
const inherited = schema.description;
|
|
@@ -5375,7 +5818,7 @@ function describeAt(presentation, path, depth2) {
|
|
|
5375
5818
|
const info = {
|
|
5376
5819
|
known: true,
|
|
5377
5820
|
path: shown,
|
|
5378
|
-
pointer:
|
|
5821
|
+
pointer: pointer5,
|
|
5379
5822
|
...key3 !== void 0 ? { key: key3 } : {},
|
|
5380
5823
|
types: uniq(infos2.map((variant) => variant.type)),
|
|
5381
5824
|
...description ? { description } : {},
|
|
@@ -5389,7 +5832,7 @@ function describeAt(presentation, path, depth2) {
|
|
|
5389
5832
|
...catalogKind ? { catalogKind } : {},
|
|
5390
5833
|
variants: infos2,
|
|
5391
5834
|
primary,
|
|
5392
|
-
children: childrenOf(form, list,
|
|
5835
|
+
children: childrenOf(form, list, root),
|
|
5393
5836
|
requiredChildren: form.required,
|
|
5394
5837
|
freeText
|
|
5395
5838
|
};
|
|
@@ -5404,8 +5847,8 @@ function describeAt(presentation, path, depth2) {
|
|
|
5404
5847
|
if (info.entryInfo) info.entryInfo.path = [...shown, "*"];
|
|
5405
5848
|
return info;
|
|
5406
5849
|
}
|
|
5407
|
-
function unknownField(path,
|
|
5408
|
-
return { known: false, path, pointer:
|
|
5850
|
+
function unknownField(path, pointer5) {
|
|
5851
|
+
return { known: false, path, pointer: pointer5, types: [], required: false, examples: [], variants: [], primary: 0, children: [], requiredChildren: [], freeText: false };
|
|
5409
5852
|
}
|
|
5410
5853
|
function describeField(path, document) {
|
|
5411
5854
|
return describeAt(document, path, 0);
|
|
@@ -5639,8 +6082,9 @@ var YAML_START = /^[A-Za-z_][\w.-]*\s*:(?:\s|$)/;
|
|
|
5639
6082
|
var MINIMAL_DECK = '{\n "slides": [\n { "title": "" }\n ]\n}\n';
|
|
5640
6083
|
var HINT_FORMS_LIMIT = 2;
|
|
5641
6084
|
var Analyzer = class {
|
|
5642
|
-
constructor(text2) {
|
|
6085
|
+
constructor(text2, editor = false) {
|
|
5643
6086
|
this.text = text2;
|
|
6087
|
+
this.editor = editor;
|
|
5644
6088
|
const lexed = tokenize(text2);
|
|
5645
6089
|
this.comments = lexed.tokens.filter((token) => token.kind === "comment");
|
|
5646
6090
|
this.tokens = lexed.tokens.filter((token) => token.kind !== "comment");
|
|
@@ -5648,6 +6092,7 @@ var Analyzer = class {
|
|
|
5648
6092
|
this.locate = createLocator(text2);
|
|
5649
6093
|
}
|
|
5650
6094
|
text;
|
|
6095
|
+
editor;
|
|
5651
6096
|
problems = [];
|
|
5652
6097
|
tokens;
|
|
5653
6098
|
comments;
|
|
@@ -6261,7 +6706,7 @@ var Analyzer = class {
|
|
|
6261
6706
|
range: this.range(keyToken.start, colon.end),
|
|
6262
6707
|
path,
|
|
6263
6708
|
message: `\`${key3}\` needs a value.`,
|
|
6264
|
-
next: `${hint.next} Press Ctrl+Space after the colon for options
|
|
6709
|
+
next: this.editor ? `${hint.next} Press Ctrl+Space after the colon for options.` : hint.next,
|
|
6265
6710
|
fixes
|
|
6266
6711
|
});
|
|
6267
6712
|
}
|
|
@@ -6473,7 +6918,7 @@ function valueHint(path) {
|
|
|
6473
6918
|
}
|
|
6474
6919
|
function analyzeJsonSyntax(text2, options2 = {}) {
|
|
6475
6920
|
const limit = Math.max(0, options2.limit ?? 5);
|
|
6476
|
-
const analyzer = new Analyzer(String(text2 ?? ""));
|
|
6921
|
+
const analyzer = new Analyzer(String(text2 ?? ""), options2.editor === true);
|
|
6477
6922
|
try {
|
|
6478
6923
|
analyzer.run();
|
|
6479
6924
|
} catch {
|
|
@@ -6534,7 +6979,7 @@ function parseSource(source) {
|
|
|
6534
6979
|
if (keys.has(key3.value))
|
|
6535
6980
|
duplicates.push(
|
|
6536
6981
|
finding("opf/duplicate-key", {
|
|
6537
|
-
path:
|
|
6982
|
+
path: pointer4(getNodePath(key3)),
|
|
6538
6983
|
message: `Duplicate JSON property ${JSON.stringify(key3.value)}.`,
|
|
6539
6984
|
help: "Resolve the duplicate explicitly, preserving the intended content from both occurrences. JSON.parse would otherwise hide an earlier value.",
|
|
6540
6985
|
location: location(key3.offset, key3.length)
|
|
@@ -6554,9 +6999,9 @@ function parseSource(source) {
|
|
|
6554
6999
|
let node = tree;
|
|
6555
7000
|
const found = [];
|
|
6556
7001
|
const wanted = parts(path);
|
|
6557
|
-
for (const
|
|
6558
|
-
const next = node?.type === "array" ? node.children?.[Number(
|
|
6559
|
-
(property) => property.children?.[0]?.value ===
|
|
7002
|
+
for (const part2 of wanted) {
|
|
7003
|
+
const next = node?.type === "array" ? node.children?.[Number(part2)] : node?.type === "object" ? node.children?.find(
|
|
7004
|
+
(property) => property.children?.[0]?.value === part2
|
|
6560
7005
|
)?.children?.[1] : void 0;
|
|
6561
7006
|
if (!next) break;
|
|
6562
7007
|
node = next;
|
|
@@ -6571,118 +7016,13 @@ function parseSource(source) {
|
|
|
6571
7016
|
};
|
|
6572
7017
|
}
|
|
6573
7018
|
|
|
6574
|
-
// src/finding-text-util.ts
|
|
6575
|
-
var WORDS = { object: "an object", array: "a list", string: "text", number: "a number", integer: "a whole number", boolean: "true or false", null: "null" };
|
|
6576
|
-
var KIND_WORDS = { layouts: "layout", themes: "theme", colorSchemes: "color scheme", fontSchemes: "font scheme", narratives: "narrative", audiences: "audience", purposes: "purpose", tones: "tone", languages: "language" };
|
|
6577
|
-
var KIND_EXAMPLES = { layouts: "`pillars` or `acme:hero`", themes: "`minimal` or `acme:bold`", colorSchemes: "`boost` or `acme:night`", fontSchemes: "`aptos` or `acme:brand`", narratives: "`classic-story`", audiences: "`board`", purposes: "`inform`", tones: "`formal`" };
|
|
6578
|
-
var ALIASES = { middle: "center", centre: "center", centered: "center", centred: "center", justify: "start", left: "start", right: "end", col: "column", cols: "column", pic: "image", picture: "image", photo: "image", paragraph: "text", bullets: "list", bullet: "list" };
|
|
6579
|
-
function segmentsOf(path) {
|
|
6580
|
-
if (Array.isArray(path)) return path.map(String);
|
|
6581
|
-
if (typeof path !== "string" || path === "" || path === "/") return [];
|
|
6582
|
-
return path.replace(/^\//, "").split("/").map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
6583
|
-
}
|
|
6584
|
-
function pointerOf(segments) {
|
|
6585
|
-
return segments.map((part) => `/${String(part).replaceAll("~", "~0").replaceAll("/", "~1")}`).join("");
|
|
6586
|
-
}
|
|
6587
|
-
var code = (value) => `\`${String(value)}\``;
|
|
6588
|
-
var isIndex = (segment) => /^\d+$/.test(String(segment));
|
|
6589
|
-
function cap(text2) {
|
|
6590
|
-
return text2.startsWith("`") ? text2 : text2.charAt(0).toUpperCase() + text2.slice(1);
|
|
6591
|
-
}
|
|
6592
|
-
function fieldLabel(segments) {
|
|
6593
|
-
if (!segments.length) return "the deck";
|
|
6594
|
-
const last = segments[segments.length - 1];
|
|
6595
|
-
if (isIndex(last)) {
|
|
6596
|
-
const owner = [...segments].reverse().find((segment) => !isIndex(segment));
|
|
6597
|
-
return owner === "slides" ? `slide ${Number(last) + 1}` : owner ? `${owner} entry ${Number(last) + 1}` : `entry ${Number(last) + 1}`;
|
|
6598
|
-
}
|
|
6599
|
-
return code(last);
|
|
6600
|
-
}
|
|
6601
|
-
function placeWords(segments) {
|
|
6602
|
-
if (!segments.length) return "at the top level";
|
|
6603
|
-
const slide = segments[0] === "slides" && segments.length >= 2 && isIndex(segments[1]) ? Number(segments[1]) + 1 : void 0;
|
|
6604
|
-
if (slide !== void 0 && segments.length === 2) return `in slide ${slide}`;
|
|
6605
|
-
const last = segments[segments.length - 1];
|
|
6606
|
-
const inner = isIndex(last) ? fieldLabel(segments) : code(last);
|
|
6607
|
-
return slide !== void 0 ? `in ${inner} of slide ${slide}` : `in ${inner}`;
|
|
6608
|
-
}
|
|
6609
|
-
function containerName(segments) {
|
|
6610
|
-
if (!segments.length) return "the deck";
|
|
6611
|
-
if (segments.length === 2 && segments[0] === "slides" && isIndex(segments[1])) return "a slide";
|
|
6612
|
-
const last = segments[segments.length - 1];
|
|
6613
|
-
return isIndex(last) ? fieldLabel(segments) : code(last);
|
|
6614
|
-
}
|
|
6615
|
-
function describeValue(value) {
|
|
6616
|
-
if (value === void 0) return "missing";
|
|
6617
|
-
if (value === null) return "null";
|
|
6618
|
-
if (Array.isArray(value)) return value.length ? `a list of ${value.length}` : "an empty list";
|
|
6619
|
-
if (typeof value === "object") return "an object";
|
|
6620
|
-
if (typeof value === "string") return value === "" ? "empty" : code(value.length > 30 ? `${value.slice(0, 29)}\u2026` : value);
|
|
6621
|
-
return `${typeof value === "number" ? "a number" : "true or false"} (${code(String(value))})`;
|
|
6622
|
-
}
|
|
6623
|
-
function describeKind(value) {
|
|
6624
|
-
if (typeof value === "string") return value === "" ? "empty text" : `text (${describeValue(value)})`;
|
|
6625
|
-
return describeValue(value);
|
|
6626
|
-
}
|
|
6627
|
-
function typeWords(type) {
|
|
6628
|
-
const list = (Array.isArray(type) ? type : [type]).filter(Boolean).map((entry2) => WORDS[String(entry2)] ?? String(entry2));
|
|
6629
|
-
return [...new Set(list)].join(" or ") || "a different kind of value";
|
|
6630
|
-
}
|
|
6631
|
-
function distance2(a, b) {
|
|
6632
|
-
const x = a.toLowerCase();
|
|
6633
|
-
const y = b.toLowerCase();
|
|
6634
|
-
if (x === y) return 0;
|
|
6635
|
-
const row = Array.from({ length: y.length + 1 }, (_, index) => index);
|
|
6636
|
-
for (let i = 1; i <= x.length; i++) {
|
|
6637
|
-
let previous = row[0];
|
|
6638
|
-
row[0] = i;
|
|
6639
|
-
for (let j = 1; j <= y.length; j++) {
|
|
6640
|
-
const keep3 = row[j];
|
|
6641
|
-
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (x[i - 1] === y[j - 1] ? 0 : 1));
|
|
6642
|
-
previous = keep3;
|
|
6643
|
-
}
|
|
6644
|
-
}
|
|
6645
|
-
return row[y.length];
|
|
6646
|
-
}
|
|
6647
|
-
function nearest(value, candidates, limit = 5) {
|
|
6648
|
-
const text2 = String(value ?? "");
|
|
6649
|
-
const alias = ALIASES[text2.toLowerCase()];
|
|
6650
|
-
const ranked = candidates.map((candidate) => ({ candidate, score: String(candidate).toLowerCase() === alias ? 0 : distance2(text2, String(candidate)) }));
|
|
6651
|
-
ranked.sort((a, b) => a.score - b.score);
|
|
6652
|
-
const close = ranked.filter((entry2) => entry2.score <= Math.max(2, Math.floor(text2.length / 4))).map((entry2) => entry2.candidate);
|
|
6653
|
-
return { close: close.slice(0, limit), all: ranked.map((entry2) => entry2.candidate) };
|
|
6654
|
-
}
|
|
6655
|
-
function valueList(values, max = 5) {
|
|
6656
|
-
const list = values.map((value) => typeof value === "string" ? value : JSON.stringify(value));
|
|
6657
|
-
if (list.length <= max) return list.length > 1 ? `${list.slice(0, -1).join(", ")} or ${list.at(-1)}` : list.join("");
|
|
6658
|
-
return `one of ${list.length} values (${list.slice(0, 3).join(", ")}, \u2026)`;
|
|
6659
|
-
}
|
|
6660
|
-
var firstSentence = (text2) => /^.*?[.!?](?=\s|$)/.exec(String(text2 ?? "").replace(/\s+/g, " ").trim())?.[0] ?? "";
|
|
6661
|
-
function asNext(text2) {
|
|
6662
|
-
const trimmed = text2.trim();
|
|
6663
|
-
return /^[A-Z][a-z]/.test(trimmed) ? trimmed.charAt(0).toLowerCase() + trimmed.slice(1) : trimmed;
|
|
6664
|
-
}
|
|
6665
|
-
var isRecord3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6666
|
-
function readAt(document, segments) {
|
|
6667
|
-
let value = document;
|
|
6668
|
-
for (const segment of segments) {
|
|
6669
|
-
if (Array.isArray(value)) value = value[Number(segment)];
|
|
6670
|
-
else if (isRecord3(value)) value = value[segment];
|
|
6671
|
-
else return void 0;
|
|
6672
|
-
}
|
|
6673
|
-
return value;
|
|
6674
|
-
}
|
|
6675
|
-
|
|
6676
7019
|
// src/finding-text-helpers.ts
|
|
6677
7020
|
var ENDS = /[.?!]$/;
|
|
6678
7021
|
function sentence(text2) {
|
|
6679
7022
|
const trimmed = text2.trim();
|
|
6680
7023
|
return ENDS.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
6681
7024
|
}
|
|
6682
|
-
|
|
6683
|
-
return text2.replace(/colour/g, "color").replace(/Colour/g, "Color");
|
|
6684
|
-
}
|
|
6685
|
-
var keep = (text2) => sentence(us(text2));
|
|
7025
|
+
var keep = (text2) => sentence(text2);
|
|
6686
7026
|
function match(text2, regex) {
|
|
6687
7027
|
return regex.exec(text2) ?? void 0;
|
|
6688
7028
|
}
|
|
@@ -6732,11 +7072,11 @@ function dotted(segments) {
|
|
|
6732
7072
|
}
|
|
6733
7073
|
function keysAt(helpers, path) {
|
|
6734
7074
|
const value = helpers.valueAt(path);
|
|
6735
|
-
return
|
|
7075
|
+
return isRecord2(value) ? Object.keys(value) : [];
|
|
6736
7076
|
}
|
|
6737
7077
|
function idsAt(helpers, path) {
|
|
6738
7078
|
const value = helpers.valueAt(path);
|
|
6739
|
-
return Array.isArray(value) ? value.flatMap((entry2) =>
|
|
7079
|
+
return Array.isArray(value) ? value.flatMap((entry2) => isRecord2(entry2) && typeof entry2.id === "string" ? [entry2.id] : []) : [];
|
|
6740
7080
|
}
|
|
6741
7081
|
function codeList(names2, max = 5, joiner = "and") {
|
|
6742
7082
|
const shown = names2.slice(0, max).map(code);
|
|
@@ -6777,7 +7117,7 @@ function freshName(base, taken = []) {
|
|
|
6777
7117
|
}
|
|
6778
7118
|
var BLOCK_KINDS = ["chart", "image", "video", "table", "code", "metric", "quote", "timeline", "diagram", "items", "bullets", "text"];
|
|
6779
7119
|
function blockKind(node) {
|
|
6780
|
-
if (!
|
|
7120
|
+
if (!isRecord2(node)) return void 0;
|
|
6781
7121
|
if (typeof node.type === "string" && node.type !== "group") return node.type;
|
|
6782
7122
|
const found = BLOCK_KINDS.find((key3) => node[key3] !== void 0);
|
|
6783
7123
|
if (found === "items" || found === "bullets") return "list";
|
|
@@ -6785,7 +7125,7 @@ function blockKind(node) {
|
|
|
6785
7125
|
}
|
|
6786
7126
|
function helpAsNext(finding2, fallback) {
|
|
6787
7127
|
const help = finding2.help?.trim();
|
|
6788
|
-
return help ? sentence(asNext(
|
|
7128
|
+
return help ? sentence(asNext(help)) : fallback;
|
|
6789
7129
|
}
|
|
6790
7130
|
var isText2 = (value) => typeof value === "string" && value !== "";
|
|
6791
7131
|
function brief(text2, max = 40) {
|
|
@@ -6809,8 +7149,8 @@ var textContrast = (finding2) => {
|
|
|
6809
7149
|
const foreground = measuredText(finding2, "textColor");
|
|
6810
7150
|
const background = measuredText(finding2, "backgroundColor");
|
|
6811
7151
|
if (ratio === void 0 || needed === void 0) return void 0;
|
|
6812
|
-
const label = match(finding2.message, /^(.+?)
|
|
6813
|
-
const subject = label && !/^(Text|
|
|
7152
|
+
const label = match(finding2.message, /^(.+?) color /)?.[1];
|
|
7153
|
+
const subject = label && !/^(Text|Colored text)$/.test(label) ? label : "Text";
|
|
6814
7154
|
const colors = foreground && background ? ` ${code(foreground)} on ${code(background)}` : "";
|
|
6815
7155
|
const large = finding2.measured?.large === true ? " for large text" : finding2.measured?.large === false ? " for normal-size text" : "";
|
|
6816
7156
|
const also = measuredNumber(finding2, "alsoAffected");
|
|
@@ -6867,7 +7207,7 @@ var poorAltText = (finding2) => {
|
|
|
6867
7207
|
const chart = found[1] === "Chart";
|
|
6868
7208
|
const problem = found[4].replace(/^is a generic word, not what the data shows$/, "is a generic word");
|
|
6869
7209
|
return {
|
|
6870
|
-
message: `Alt text ${code(brief(alt, 50))} ${
|
|
7210
|
+
message: `Alt text ${code(brief(alt, 50))} ${problem}, so it doesn't describe the ${chart ? "chart" : "picture"}.`,
|
|
6871
7211
|
next: chart ? "state what the chart shows: its point and the key numbers, in a sentence or two." : `describe what the picture shows, in plain words and without a leading "image of".`
|
|
6872
7212
|
};
|
|
6873
7213
|
};
|
|
@@ -6907,18 +7247,18 @@ var linkText = (finding2) => {
|
|
|
6907
7247
|
return { message, next: `say what is at ${destination}, for example the page or file name.` };
|
|
6908
7248
|
};
|
|
6909
7249
|
var chartColorOnly = (finding2) => {
|
|
6910
|
-
const parts2 = match(finding2.message, /^(Series|Slices) may be hard to tell apart without
|
|
7250
|
+
const parts2 = match(finding2.message, /^(Series|Slices) may be hard to tell apart without color/);
|
|
6911
7251
|
const noun = parts2?.[1] === "Slices" ? "slices" : "series";
|
|
6912
7252
|
const pairs = measuredNumber(finding2, "confusablePairs");
|
|
6913
|
-
const repeat = match(finding2.message, /(\d+) (?:series|slices) exceed the (\d+)-
|
|
7253
|
+
const repeat = match(finding2.message, /(\d+) (?:series|slices) exceed the (\d+)-color palette/);
|
|
6914
7254
|
const count = measuredNumber(finding2, "series");
|
|
6915
7255
|
const message = pairs !== void 0 ? `Some ${noun} differ by color only: ${pairs === 1 ? "one pair looks" : `${pairs} pairs look`} alike to color-blind viewers or in grayscale.${repeat ? ` ${repeat[1]} ${noun} exceed the ${repeat[2]}-color palette, so colors repeat.` : ""}` : `${cap(noun)} differ by color only${count !== void 0 ? ` (${count} ${noun})` : ""}.`;
|
|
6916
7256
|
return { message, next: `add data labels or a direct legend, choose more distinct ${code("colors")}, or show fewer ${noun}.` };
|
|
6917
7257
|
};
|
|
6918
7258
|
var chartColorsAdjusted = (finding2, _context, helpers) => {
|
|
6919
|
-
const index = match(finding2.message, /^Chart
|
|
7259
|
+
const index = match(finding2.message, /^Chart color (\d+) /)?.[1] ?? (isText2(helpers.segments.at(-1)) ? String(Number(helpers.segments.at(-1)) + 1) : void 0);
|
|
6920
7260
|
const value = helpers.valueAt(helpers.segments);
|
|
6921
|
-
const shown = typeof value === "string" ? value : unquote(match(finding2.message, /^Chart
|
|
7261
|
+
const shown = typeof value === "string" ? value : unquote(match(finding2.message, /^Chart color \d+ \((.+?)\) /)?.[1]);
|
|
6922
7262
|
const contrast = measuredNumber(finding2, "contrast");
|
|
6923
7263
|
const panel = measuredText(finding2, "panel");
|
|
6924
7264
|
const label = index ? `Chart color ${index}` : "A chart color";
|
|
@@ -6957,7 +7297,7 @@ var chartOptionAdapted = (finding2, _context, helpers) => {
|
|
|
6957
7297
|
if (!option) return void 0;
|
|
6958
7298
|
const type = at2 >= 0 ? helpers.valueAt([...helpers.segments.slice(0, at2 + 1), "type"]) : void 0;
|
|
6959
7299
|
const typeName = typeof type === "string" ? type : match(finding2.message, /^A '(.+?)' chart/)?.[1];
|
|
6960
|
-
const adaptation = finding2.message.includes(";") ? cap(
|
|
7300
|
+
const adaptation = finding2.message.includes(";") ? cap(finding2.message.slice(finding2.message.indexOf(";") + 1).trim()) : "";
|
|
6961
7301
|
return {
|
|
6962
7302
|
message: `${code(option)} isn't supported by ${typeName ? `a ${typeName}` : "this"} chart and is adapted.${adaptation ? ` ${sentence(adaptation)}` : ""}`,
|
|
6963
7303
|
next: `remove ${code(option)}, or choose a chart type that can show it.`
|
|
@@ -6978,7 +7318,7 @@ var unresolvedContent = (finding2) => ({
|
|
|
6978
7318
|
var layoutFailed = (finding2, _context, helpers) => {
|
|
6979
7319
|
const reason = match(finding2.message, /^Layout failed: (.+)$/)?.[1];
|
|
6980
7320
|
return {
|
|
6981
|
-
message: `${slideRef(finding2, helpers)} couldn't be laid out${reason ? `: ${sentence(
|
|
7321
|
+
message: `${slideRef(finding2, helpers)} couldn't be laid out${reason ? `: ${sentence(reason).replace(/\.$/, "")}` : ""}, so the geometry checks were skipped.`,
|
|
6982
7322
|
next: "fix the composition setting or content named above."
|
|
6983
7323
|
};
|
|
6984
7324
|
};
|
|
@@ -6989,7 +7329,7 @@ var minFontSize = (finding2) => {
|
|
|
6989
7329
|
const run = /^Text run is set to/.test(finding2.message);
|
|
6990
7330
|
const label = run ? "A text run" : match(finding2.message, /^(.+?) is drawn at/)?.[1] ?? "Text";
|
|
6991
7331
|
return {
|
|
6992
|
-
message: `${cap(
|
|
7332
|
+
message: `${cap(label)}${onSlide(finding2)} ${run ? "is set to" : "is drawn at"} ${num(size, 1)} pt, below the ${num(minimum, 1)} pt readable minimum.`,
|
|
6993
7333
|
next: run ? `raise ${code("fontSize")} to at least ${num(minimum, 1)}.` : "shorten the text, give it more room or split the slide, so it can be drawn larger."
|
|
6994
7334
|
};
|
|
6995
7335
|
};
|
|
@@ -6998,13 +7338,13 @@ function regionNamesOf(slideLayout, helpers) {
|
|
|
6998
7338
|
const colon = slideLayout.indexOf(":");
|
|
6999
7339
|
const group = colon > 0 ? slideLayout.slice(0, colon) : void 0;
|
|
7000
7340
|
const id = colon > 0 ? slideLayout.slice(colon + 1) : slideLayout;
|
|
7001
|
-
const record = (group ? [group] : ["custom", "default"]).map((name) => helpers.valueAt(["catalogs", name, "layouts", id])).find(
|
|
7341
|
+
const record = (group ? [group] : ["custom", "default"]).map((name) => helpers.valueAt(["catalogs", name, "layouts", id])).find(isRecord2);
|
|
7002
7342
|
if (!record) return void 0;
|
|
7003
7343
|
const names2 = [];
|
|
7004
7344
|
const walk2 = (list) => {
|
|
7005
7345
|
if (!Array.isArray(list)) return;
|
|
7006
7346
|
for (const entry2 of list) {
|
|
7007
|
-
if (!
|
|
7347
|
+
if (!isRecord2(entry2)) continue;
|
|
7008
7348
|
if (typeof entry2.name === "string" && !["title", "subtitle", "tag"].includes(entry2.name)) names2.push(entry2.name);
|
|
7009
7349
|
walk2(entry2.regions);
|
|
7010
7350
|
}
|
|
@@ -7018,6 +7358,16 @@ var regionUnknown = (finding2, _context, helpers) => {
|
|
|
7018
7358
|
const slide = slideNumber(finding2);
|
|
7019
7359
|
const layout = slide ? regionNamesOf(helpers.valueAt(["slides", String(slide - 1), "layout"]), helpers) : void 0;
|
|
7020
7360
|
const known = layout?.names ?? [];
|
|
7361
|
+
const renamed = (finding2.fixes ?? []).find((fix) => fix.id === "rename-region" && fix.kind === "patch");
|
|
7362
|
+
const next = renamed?.kind === "patch" ? renamed.patch?.[0]?.value : void 0;
|
|
7363
|
+
if (typeof next === "string") {
|
|
7364
|
+
const reference = slide ? helpers.valueAt(["slides", String(slide - 1), "layout"]) : void 0;
|
|
7365
|
+
const id = layout?.id ?? (typeof reference === "string" ? reference : void 0);
|
|
7366
|
+
return {
|
|
7367
|
+
message: `Block pinned to region ${code(region)}, which OPF 0.35 renamed ${code(next)}${id ? ` in layout ${code(id)}` : ""}.`,
|
|
7368
|
+
next: `pin it to ${code(next)} (the fix does).`
|
|
7369
|
+
};
|
|
7370
|
+
}
|
|
7021
7371
|
return {
|
|
7022
7372
|
message: layout ? `Block pinned to region ${code(region)}; layout ${code(layout.id)} has ${andList(known)}.` : `A block is pinned to region ${code(region)}, which the slide's layout doesn't have.`,
|
|
7023
7373
|
next: known.length ? chooseNext(region, known, `remove ${code("region")}`) : `pin it to a region the layout has, or remove ${code("region")}.`
|
|
@@ -7230,7 +7580,7 @@ var codeHighlightRangeReversed = (finding2) => {
|
|
|
7230
7580
|
};
|
|
7231
7581
|
var variableGroupOmitted = (finding2) => {
|
|
7232
7582
|
const ids = [...finding2.message.matchAll(/'([a-z][a-z0-9-]*)'/g)].map((found) => found[1]);
|
|
7233
|
-
const idParam =
|
|
7583
|
+
const idParam = isRecord2(finding2.validation?.params) ? finding2.validation.params.id : void 0;
|
|
7234
7584
|
const names2 = [...new Set(ids.length ? ids : typeof idParam === "string" ? [idParam] : [])];
|
|
7235
7585
|
if (!names2.length) return void 0;
|
|
7236
7586
|
const list = names2.length === 1 ? code(names2[0]) : `${names2.slice(0, -1).map((id) => code(id)).join(", ")} and ${code(names2.at(-1))}`;
|
|
@@ -7240,7 +7590,7 @@ var variableGroupOmitted = (finding2) => {
|
|
|
7240
7590
|
};
|
|
7241
7591
|
};
|
|
7242
7592
|
var variableBuiltinMissing = (finding2, _context, helpers) => {
|
|
7243
|
-
const idParam =
|
|
7593
|
+
const idParam = isRecord2(finding2.validation?.params) ? finding2.validation.params.id : void 0;
|
|
7244
7594
|
const id = (typeof idParam === "string" ? idParam : void 0) ?? match(finding2.message, /^Built-in '(.+?)' has no value/)?.[1] ?? match(finding2.message, /'\{\{(.+?)\}\}'/)?.[1];
|
|
7245
7595
|
if (!id) return void 0;
|
|
7246
7596
|
const root = id.split(".")[0];
|
|
@@ -7262,7 +7612,7 @@ var durationOutsideNarrative2 = (finding2) => {
|
|
|
7262
7612
|
};
|
|
7263
7613
|
var narrativeDurationRange = (_finding, _context, helpers) => {
|
|
7264
7614
|
const range = helpers.valueAt(helpers.segments);
|
|
7265
|
-
if (
|
|
7615
|
+
if (isRecord2(range) && typeof range.min === "number" && typeof range.max === "number") {
|
|
7266
7616
|
return {
|
|
7267
7617
|
message: `The duration range has min ${range.min} greater than max ${range.max}.`,
|
|
7268
7618
|
next: `swap them: ${code(`min: ${range.max}`)} and ${code(`max: ${range.min}`)}.`
|
|
@@ -7369,7 +7719,7 @@ var AUDIT_TEXT = {
|
|
|
7369
7719
|
};
|
|
7370
7720
|
|
|
7371
7721
|
// src/finding-text-format.ts
|
|
7372
|
-
var params = (finding2) =>
|
|
7722
|
+
var params = (finding2) => isRecord2(finding2.validation?.params) ? finding2.validation.params : {};
|
|
7373
7723
|
var text = (value) => typeof value === "string" ? value : void 0;
|
|
7374
7724
|
var jsonSyntax = (finding2) => ({
|
|
7375
7725
|
message: keep(finding2.message),
|
|
@@ -7501,7 +7851,7 @@ var imagePlacementInvalid = (finding2) => {
|
|
|
7501
7851
|
};
|
|
7502
7852
|
}
|
|
7503
7853
|
return {
|
|
7504
|
-
message: `${code("placement")} can't be used here: a block inside a group or a
|
|
7854
|
+
message: `${code("placement")} can't be used here: a block inside a group or in a cell of the slide's grid can't bleed to a slide edge.`,
|
|
7505
7855
|
next: `use ${code("placement")} on a top-level block of the slide, one per slide edge, or remove it.`
|
|
7506
7856
|
};
|
|
7507
7857
|
};
|
|
@@ -7546,7 +7896,7 @@ var dataColumnDuplicate = (finding2, _context, helpers) => {
|
|
|
7546
7896
|
const name = unquote(match(finding2.message, /^column name ("(?:[^"\\]|\\.)*") is used by an earlier column/)?.[1]);
|
|
7547
7897
|
if (!name) return void 0;
|
|
7548
7898
|
const columns = helpers.valueAt(helpers.segments.slice(0, -1));
|
|
7549
|
-
const taken = Array.isArray(columns) ? columns.map((entry2) =>
|
|
7899
|
+
const taken = Array.isArray(columns) ? columns.map((entry2) => isRecord2(entry2) ? String(entry2.name) : String(entry2)) : [];
|
|
7550
7900
|
return {
|
|
7551
7901
|
message: `Two columns are named ${code(name)}. Series and mappings address columns by name.`,
|
|
7552
7902
|
next: `rename the second one (for example ${code(freshName(name, taken))}).`
|
|
@@ -7578,7 +7928,7 @@ var numberFormatInvalid = (finding2, _context, helpers) => {
|
|
|
7578
7928
|
const reason = match(finding2.message, /^Number format '.*?' ((?:needs|scales|has|uses|asks|allows|is)\b.+)$/)?.[1];
|
|
7579
7929
|
const subject = typeof value === "string" && value ? `${code(value)} is not a number format OPF can read` : "This is not a number format OPF can read";
|
|
7580
7930
|
return {
|
|
7581
|
-
message: `${subject}.${reason ? ` It ${sentence(
|
|
7931
|
+
message: `${subject}.${reason ? ` It ${sentence(reason)}` : ""}`,
|
|
7582
7932
|
next: `write a format such as ${code("0.0")}, ${code("#,##0")}, ${code("0%")} or ${code("$#,##0.00")}.`
|
|
7583
7933
|
};
|
|
7584
7934
|
};
|
|
@@ -7626,7 +7976,7 @@ var variableInvalidValue = (finding2) => {
|
|
|
7626
7976
|
if (!id) return void 0;
|
|
7627
7977
|
const kind = found?.[2] ?? "";
|
|
7628
7978
|
return {
|
|
7629
|
-
message: `The value given for ${code(id)} does not fit its type${kind ? ` (${kind})` : ""}${found?.[3] ? `: ${
|
|
7979
|
+
message: `The value given for ${code(id)} does not fit its type${kind ? ` (${kind})` : ""}${found?.[3] ? `: ${found[3]}` : ""}.`,
|
|
7630
7980
|
next: `give it ${SAMPLE_BY_KIND[kind] ?? "a value of the declared type"}.`
|
|
7631
7981
|
};
|
|
7632
7982
|
};
|
|
@@ -7648,7 +7998,7 @@ var variableFormat = (finding2, _context, helpers) => {
|
|
|
7648
7998
|
const reason = match(finding2.message, /^(?:Number|Date) format '.*?' (.+)$/)?.[1];
|
|
7649
7999
|
const kind = id ? helpers.valueAt(["variables", id, "type"]) : void 0;
|
|
7650
8000
|
return {
|
|
7651
|
-
message: `The format${typeof declared === "string" ? ` ${code(declared)}` : ""} does not apply to ${kind ? `a ${String(kind)}` : "this"} value${id ? ` (${code(id)})` : ""}${reason ? `: it ${sentence(
|
|
8001
|
+
message: `The format${typeof declared === "string" ? ` ${code(declared)}` : ""} does not apply to ${kind ? `a ${String(kind)}` : "this"} value${id ? ` (${code(id)})` : ""}${reason ? `: it ${sentence(reason).replace(/\.$/, "")}` : ""}.`,
|
|
7652
8002
|
next: `change the ${code("format")} of ${id ? code(id) : "the variable"} to one that fits its values, such as ${kind === "date" ? code("MMMM d, yyyy") : code("#,##0.0")}.`
|
|
7653
8003
|
};
|
|
7654
8004
|
};
|
|
@@ -7776,20 +8126,20 @@ var assetCycle = (finding2) => {
|
|
|
7776
8126
|
next: "give one link a real source (an https:// address or embedded data) instead of an `asset:` reference."
|
|
7777
8127
|
};
|
|
7778
8128
|
};
|
|
7779
|
-
var
|
|
8129
|
+
var KIND_SINGULAR2 = (kind) => KIND_WORDS[kind] ?? kind.replace(/s$/, "");
|
|
7780
8130
|
var catalogRecord = (finding2, context) => {
|
|
7781
|
-
const [root, group, kind, id] = finding2.path.split("/").slice(1).map((
|
|
8131
|
+
const [root, group, kind, id] = finding2.path.split("/").slice(1).map((part2) => part2.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
7782
8132
|
if (root !== "catalogs" || !kind || !id) return void 0;
|
|
7783
8133
|
const inner = describeFinding({ ...finding2, ruleId: "opf/schema" }, context);
|
|
7784
8134
|
const registered = finding2.scope === "context";
|
|
7785
|
-
const record = `${registered ? "The registered" : "The embedded"} ${
|
|
8135
|
+
const record = `${registered ? "The registered" : "The embedded"} ${KIND_SINGULAR2(kind)} ${code(id)}`;
|
|
7786
8136
|
return {
|
|
7787
8137
|
message: `${record} is invalid: ${inner.message.charAt(0).toLowerCase()}${inner.message.slice(1)}`,
|
|
7788
8138
|
next: inner.next ?? `fix the record; references to it are reported too.`
|
|
7789
8139
|
};
|
|
7790
8140
|
};
|
|
7791
8141
|
function layoutSpot(finding2) {
|
|
7792
|
-
const parts2 = finding2.path.split("/").slice(1).map((
|
|
8142
|
+
const parts2 = finding2.path.split("/").slice(1).map((part2) => part2.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
7793
8143
|
if (parts2[0] === "catalogs" && parts2[2] === "layouts") return { id: parts2[3], spot: dotted(parts2.slice(4)) };
|
|
7794
8144
|
return { spot: dotted(parts2) };
|
|
7795
8145
|
}
|
|
@@ -7797,7 +8147,7 @@ var layoutTemplate2 = (finding2) => {
|
|
|
7797
8147
|
const { id, spot } = layoutSpot(finding2);
|
|
7798
8148
|
const detail = finding2.message.trim().replace(/\.$/, "");
|
|
7799
8149
|
return {
|
|
7800
|
-
message: `The layout's region list is malformed${spot ? ` at ${code(spot)}` : ""}${id ? ` (layout ${code(id)})` : ""}: ${
|
|
8150
|
+
message: `The layout's region list is malformed${spot ? ` at ${code(spot)}` : ""}${id ? ` (layout ${code(id)})` : ""}: ${detail}.`,
|
|
7801
8151
|
next: spot ? `correct ${code(spot)} as described; the layout is not used until it is valid.` : "correct the layout as described; it is not used until it is valid."
|
|
7802
8152
|
};
|
|
7803
8153
|
};
|
|
@@ -7827,7 +8177,7 @@ var layoutRegion = (finding2) => {
|
|
|
7827
8177
|
};
|
|
7828
8178
|
}
|
|
7829
8179
|
return {
|
|
7830
|
-
message: `A region of the layout is not valid${spot ? ` at ${code(spot)}` : ""}${id ? ` (layout ${code(id)})` : ""}: ${
|
|
8180
|
+
message: `A region of the layout is not valid${spot ? ` at ${code(spot)}` : ""}${id ? ` (layout ${code(id)})` : ""}: ${detail}.`,
|
|
7831
8181
|
next: spot ? `correct ${code(spot)} as described.` : "correct the layout as described."
|
|
7832
8182
|
};
|
|
7833
8183
|
};
|
|
@@ -7840,25 +8190,47 @@ var unresolvedReference2 = (finding2, _context, helpers) => {
|
|
|
7840
8190
|
return typeof value === "string" ? value : void 0;
|
|
7841
8191
|
})();
|
|
7842
8192
|
if (!reference) return void 0;
|
|
7843
|
-
|
|
8193
|
+
if (kind === "layouts" && reference === "auto" && /removed layout 'auto'/.test(finding2.message)) {
|
|
8194
|
+
return {
|
|
8195
|
+
message: `Layout ${code("auto")} was removed in OPF 0.35: a slide without ${code("layout")} composes automatically, which is what ${code("auto")} did.`,
|
|
8196
|
+
next: `delete the ${code("layout")} key (the fix does).`
|
|
8197
|
+
};
|
|
8198
|
+
}
|
|
8199
|
+
const replaced = kind === "layouts" ? /removed layout '.+?' \(use '(.+?)'(?: with design\.titlePosition '(.+?)')?\)/.exec(finding2.message) : void 0;
|
|
8200
|
+
const renamed = replaced?.[1], position = replaced?.[2];
|
|
8201
|
+
if (renamed && position) {
|
|
8202
|
+
return {
|
|
8203
|
+
message: `Layout ${code(reference)} was removed in OPF 0.35: ${code(renamed)} with the title beside the body (${code(`design.titlePosition: "${position}"`)}) replaced it.`,
|
|
8204
|
+
next: `change the layout to ${code(renamed)} and set the slide's ${code("design.titlePosition")} to ${code(position)} (the fix does both).`
|
|
8205
|
+
};
|
|
8206
|
+
}
|
|
8207
|
+
if (renamed) {
|
|
8208
|
+
return {
|
|
8209
|
+
message: `Layout ${code(reference)} was removed in OPF 0.35: ${code(renamed)} replaced it.`,
|
|
8210
|
+
next: `change the layout to ${code(renamed)} (the fix does).`
|
|
8211
|
+
};
|
|
8212
|
+
}
|
|
8213
|
+
const noun = cap(KIND_SINGULAR2(kind || (found?.[1] ?? "catalog record").toLowerCase()));
|
|
7844
8214
|
const colon = reference.indexOf(":");
|
|
7845
8215
|
const group = colon > 0 ? reference.slice(0, colon) : void 0;
|
|
7846
8216
|
const bare = colon > 0 ? reference.slice(colon + 1) : reference;
|
|
7847
8217
|
const embeddedIn = group ? [group] : ["custom", "default"];
|
|
7848
|
-
const embedded = kind && embeddedIn.some((name) =>
|
|
8218
|
+
const embedded = kind && embeddedIn.some((name) => isRecord2(helpers.valueAt(["catalogs", name, kind, bare])));
|
|
7849
8219
|
const suggestions = (finding2.suggestions ?? []).slice(0, 5).map((entry2) => String(entry2.value));
|
|
7850
8220
|
if (embedded) {
|
|
8221
|
+
const current = (finding2.fixes ?? []).some((fix) => fix.id === "use-current-record" || fix.id === "rename-layout");
|
|
7851
8222
|
return {
|
|
7852
|
-
message: `${noun} ${code(reference)} is embedded but
|
|
7853
|
-
next: `fix the record named in the other problems, or remove the reference.`
|
|
8223
|
+
message: `${noun} ${code(reference)} is embedded, but the record is invalid.`,
|
|
8224
|
+
next: current ? `take the current record (the fix does, as do ${code("opf fix -i")} and ${code("opf embed -i")}).` : `fix the record named in the other problems, or remove the reference.`
|
|
7854
8225
|
};
|
|
7855
8226
|
}
|
|
7856
8227
|
const message = group && /declares no catalogs\./.test(finding2.message) ? `${noun} ${code(reference)} uses catalog group ${code(group)}, which the deck does not declare, so ${FALLBACK(kind)}.` : `${noun} ${code(reference)} is not embedded or in a registered catalog, so ${FALLBACK(kind)}.`;
|
|
7857
8228
|
const { close } = nearest(reference, suggestions);
|
|
7858
8229
|
const remove = kind === "layouts" ? "remove the reference to let OPF pick" : "remove the reference";
|
|
8230
|
+
const listed = kind ? `${code("search_catalog")} and ${code(`opf catalog ${kind}`)} list the ${KIND_SINGULAR2(kind)} ids` : "";
|
|
7859
8231
|
return {
|
|
7860
8232
|
message,
|
|
7861
|
-
next: close.length ? `did you mean ${code(close[0])}?` : suggestions.length ? `choose one of ${codeList(suggestions, 5, "or")}, embed the record under ${code("catalogs.custom")}, or ${remove}.` : `embed the record under ${code("catalogs.custom")}, register the catalog that defines it, or ${remove}.`
|
|
8233
|
+
next: close.length ? `did you mean ${code(close[0])}?` : suggestions.length ? `choose one of ${codeList(suggestions, 5, "or")}, embed the record under ${code("catalogs.custom")}, or ${remove}.` : kind === "layouts" ? `remove ${code("layout")} and the slide composes automatically from its content, or use a layout that exists (${listed}); a record of your own goes under ${code("catalogs.custom")}.` : listed ? `use a ${KIND_SINGULAR2(kind)} that exists (${listed}), embed the record under ${code("catalogs.custom")}, or ${remove}.` : `embed the record under ${code("catalogs.custom")}, register the catalog that defines it, or ${remove}.`
|
|
7862
8234
|
};
|
|
7863
8235
|
};
|
|
7864
8236
|
var catalogRecordNotInSource = (finding2) => {
|
|
@@ -8029,12 +8401,12 @@ var LINE_KEYWORDS = ["Note:", "Notes:"];
|
|
|
8029
8401
|
var keep2 = (finding2, next) => next ? { message: finding2.message, next } : { message: finding2.message };
|
|
8030
8402
|
var wholeHelp = (finding2) => keep2(finding2, finding2.help ? asNext(finding2.help) : void 0);
|
|
8031
8403
|
var line = (finding2) => finding2.location?.line ?? 1;
|
|
8032
|
-
var
|
|
8404
|
+
var quoted2 = (text2, pattern) => pattern.exec(text2)?.[1];
|
|
8033
8405
|
var optionKeys = (kind) => kind === "block" ? BLOCK_OPTION_KEYS : SLIDE_OPTION_KEYS;
|
|
8034
8406
|
var options = {
|
|
8035
8407
|
"markdown/options-unknown-key": (finding2) => {
|
|
8036
|
-
const kind =
|
|
8037
|
-
const key3 =
|
|
8408
|
+
const kind = quoted2(finding2.message, /^Unknown (slide|block) option/) ?? "slide";
|
|
8409
|
+
const key3 = quoted2(finding2.message, /option "(.*)"\.$/) ?? "";
|
|
8038
8410
|
const guess = finding2.suggestions?.[0]?.value;
|
|
8039
8411
|
const keys = optionKeys(kind).join(", ");
|
|
8040
8412
|
return {
|
|
@@ -8044,14 +8416,14 @@ var options = {
|
|
|
8044
8416
|
},
|
|
8045
8417
|
"markdown/options-value": (finding2) => {
|
|
8046
8418
|
if (/^hidden takes/.test(finding2.message)) return keep2(finding2, "write `hidden=true`, `hidden=false` or just `hidden`.");
|
|
8047
|
-
const key3 =
|
|
8419
|
+
const key3 = quoted2(finding2.message, /^Option (\w+) needs a value/);
|
|
8048
8420
|
if (key3) return keep2(finding2, `write ${code(`${key3}=value`)}, for example ${code(key3 === "layout" ? "layout=title" : key3 === "id" ? "id=cover" : `${key3}=name`)}.`);
|
|
8049
8421
|
if (/^as takes/.test(finding2.message)) return keep2(finding2, "write `as=bullets` before a list or `as=video` before an image line.");
|
|
8050
8422
|
return keep2(finding2, "put `as=bullets` before a list and `as=video` before an image line, or remove `as`.");
|
|
8051
8423
|
},
|
|
8052
8424
|
"markdown/options-syntax": (finding2) => keep2(finding2, `write options as ${code("key=value")} pairs, with text in double quotes: ${code('<!-- slide: layout=title section="Part 1" -->')}.`),
|
|
8053
8425
|
"markdown/options-duplicate": (finding2) => {
|
|
8054
|
-
const key3 =
|
|
8426
|
+
const key3 = quoted2(finding2.message, /^Option (\w+) is given twice/);
|
|
8055
8427
|
if (key3) return keep2(finding2, `keep one ${code(`${key3}=`)} in the comment.`);
|
|
8056
8428
|
return keep2(finding2, "merge them into one.");
|
|
8057
8429
|
},
|
|
@@ -8084,7 +8456,7 @@ var markdown = {
|
|
|
8084
8456
|
"markdown/timeline-description": (finding2) => keep2(finding2, "put the event first, then its description indented below it."),
|
|
8085
8457
|
"markdown/timeline-events": (finding2) => keep2(finding2, "write one event per line, for example `2024 Q1 \u2014 Pilot`."),
|
|
8086
8458
|
"markdown/slide-property-conflict": (finding2) => {
|
|
8087
|
-
const field =
|
|
8459
|
+
const field = quoted2(finding2.message, /property "(.*)" is set twice/) ?? finding2.path.split("/").at(-1) ?? "field";
|
|
8088
8460
|
return { message: `${code(field)} is set both in the Markdown and in the \`opf-slide\` fence.`, next: "keep it in one of the two places." };
|
|
8089
8461
|
},
|
|
8090
8462
|
"markdown/duplicate-title": (finding2) => keep2(finding2, "use `---` to start a new slide, or `##` for the subtitle."),
|
|
@@ -8183,6 +8555,7 @@ var PATTERN_PHRASES = Object.freeze({
|
|
|
8183
8555
|
"\\S": { what: "a label with at least one non-whitespace character", next: "write a nonblank label, or omit it." },
|
|
8184
8556
|
"^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$": { what: "a hex color like `#1F4E79` (3, 6 or 8 hex digits)", next: "write the color as #RRGGBB." },
|
|
8185
8557
|
"^[a-z][a-z0-9-]*$": { what: ID, next: ID_NEXT },
|
|
8558
|
+
"^([a-z][a-z0-9-]*|(top|middle|bottom|top\\+middle|middle\\+bottom|top\\+middle\\+bottom)(:(start|center|end|start\\+center|center\\+end|start\\+center\\+end))?|start|center|end|start\\+center|center\\+end|start\\+center\\+end)$": { what: "a region of the slide's layout (lowercase letters, digits and hyphens, like `aside`) or, on a slide without a layout, a cell of its grid like `start`, `top:end` or `middle+bottom:center+end`", next: "name a region of the layout, or a cell: rows (top, middle, bottom) before the colon and columns (start, center, end) after it, each span in reading order." },
|
|
8186
8559
|
"^[a-z0-9][a-z0-9-]*$": { what: "an id of lowercase letters, digits and hyphens, like `my-chart`", next: ID_NEXT },
|
|
8187
8560
|
"^(?:[a-z][a-z0-9-]*:)?[a-z][a-z0-9-]*$": { what: "a catalog id like `pillars` or `acme:hero` (lowercase letters, digits and hyphens)", next: "use the id of a record, with the catalog group in front when it has one." },
|
|
8188
8561
|
"^[a-zA-Z0-9][a-zA-Z0-9._-]*$": { what: "an id of letters, digits, dots, hyphens and underscores that starts with a letter or digit, like `logo-2`", next: "use letters, digits, dots, hyphens and underscores, without spaces." },
|
|
@@ -8266,6 +8639,14 @@ function describeSchema(finding2, context, helpers) {
|
|
|
8266
8639
|
}
|
|
8267
8640
|
case "oneOf":
|
|
8268
8641
|
case "anyOf": {
|
|
8642
|
+
if (Array.isArray(params2.properties)) {
|
|
8643
|
+
const fields2 = params2.properties.map((name) => code(name)).join(", ");
|
|
8644
|
+
const kinds = Array.isArray(params2.belongsTo) ? params2.belongsTo.map((kind) => code(kind)).join(" or ") : "";
|
|
8645
|
+
return {
|
|
8646
|
+
message: `${cap(label)} has ${fields2}, which none of its forms has${kinds ? `; those are fields of ${kinds}` : ""}.`,
|
|
8647
|
+
next: kinds ? `put them in their own block's ${kinds}, or rewrite this value in one of its forms.` : `rewrite it as one of: ${(alternatives ?? []).join("; ")}.`
|
|
8648
|
+
};
|
|
8649
|
+
}
|
|
8269
8650
|
const forms = (alternatives ?? []).map((entry2) => String(entry2).split(":")[0]?.trim() ?? "");
|
|
8270
8651
|
const words = forms.length ? [...new Set(forms.map((form) => WORDS[form] ?? form))].slice(0, 3).join(" or ") : "a different kind of value";
|
|
8271
8652
|
return { message: `${cap(label)} should be ${words}, but it is ${describeKind(actual)}.`, next: forms.length ? `write ${words}.` : "check the schema reference for this field." };
|
|
@@ -8309,6 +8690,11 @@ function describeSchema(finding2, context, helpers) {
|
|
|
8309
8690
|
case "additionalProperties": {
|
|
8310
8691
|
const name = String(params2.additionalProperty ?? segments.at(-1) ?? "");
|
|
8311
8692
|
const parent = segments.slice(0, -1);
|
|
8693
|
+
const cell = parent.length === 2 && parent[0] === "slides" ? nearestGridCell(name) : void 0;
|
|
8694
|
+
if (cell) return {
|
|
8695
|
+
message: `${code(name)} is a slide key OPF 0.35 removed: a block of the slide's ${code("blocks")} names its cell with ${code("region")}.`,
|
|
8696
|
+
next: `apply the fix that moves it into a block, or write ${code(`{ "region": "${cell.cell ?? "top:start"}", ... }`)} in the slide's ${code("blocks")}.`
|
|
8697
|
+
};
|
|
8312
8698
|
const allowed = schemaKeys(parent, context);
|
|
8313
8699
|
const suggested = finding2.suggestions?.[0]?.value;
|
|
8314
8700
|
const hint = typeof suggested === "string" && allowed.includes(suggested) ? suggested : nearest(name, allowed).close[0];
|
|
@@ -8379,7 +8765,16 @@ function starterValue(document, segments, property) {
|
|
|
8379
8765
|
|
|
8380
8766
|
// src/schema-fixes.ts
|
|
8381
8767
|
var MAX_CHANGES = 5;
|
|
8382
|
-
var patch = (id, title, operations, safe2 = false) => ({ id, title, kind: "patch", safe: safe2, patch: operations });
|
|
8768
|
+
var patch = (id, title, operations, safe2 = false, changesDrawing = false) => ({ id, title, kind: "patch", safe: safe2, ...changesDrawing ? { changesDrawing: true } : {}, patch: operations });
|
|
8769
|
+
var REMOVED_DESIGN_KEY_FIXES = Object.freeze({
|
|
8770
|
+
contentDirection: { safe: true, changesDrawing: () => true },
|
|
8771
|
+
chartPrimary: { safe: true, changesDrawing: (segments) => !(segments[0] === "catalogs" && segments[2] === "layouts") }
|
|
8772
|
+
});
|
|
8773
|
+
function removedDesignKeyOperations(document, segments) {
|
|
8774
|
+
const parent = segments.slice(0, -1), design = readAt(document, parent);
|
|
8775
|
+
const alone = isRecord2(design) && Object.keys(design).length === 1;
|
|
8776
|
+
return [{ op: "remove", path: pointerOf(alone ? parent : segments) }];
|
|
8777
|
+
}
|
|
8383
8778
|
var allowsKey = (document, segments, key3) => {
|
|
8384
8779
|
try {
|
|
8385
8780
|
return schemaVariants(schemaAtPath(document, segments)).some((variant) => Object.hasOwn(variant.properties ?? {}, key3));
|
|
@@ -8395,7 +8790,7 @@ function schemaFixes(finding2, document) {
|
|
|
8395
8790
|
switch (validation.keyword) {
|
|
8396
8791
|
case "required": {
|
|
8397
8792
|
const property = String(params2.missingProperty ?? "");
|
|
8398
|
-
if (!property || !
|
|
8793
|
+
if (!property || !isRecord2(readAt(document, segments)) || Object.hasOwn(readAt(document, segments), property)) return [];
|
|
8399
8794
|
const value = starterValue(document, segments, property);
|
|
8400
8795
|
if (value === void 0) return [];
|
|
8401
8796
|
return [patch(`add:${property}`, `Add \`${property}\``, [{ op: "add", path: pointerOf([...segments, property]), value }])];
|
|
@@ -8411,7 +8806,7 @@ function schemaFixes(finding2, document) {
|
|
|
8411
8806
|
const name = String(params2.additionalProperty ?? segments.at(-1) ?? "");
|
|
8412
8807
|
const parent = segments.slice(0, -1);
|
|
8413
8808
|
const owner = readAt(document, parent);
|
|
8414
|
-
if (!name || !
|
|
8809
|
+
if (!name || !isRecord2(owner) || !Object.hasOwn(owner, name)) return [];
|
|
8415
8810
|
const fixes = [];
|
|
8416
8811
|
for (const suggestion of finding2.suggestions ?? []) {
|
|
8417
8812
|
const target = String(suggestion.value);
|
|
@@ -8420,14 +8815,14 @@ function schemaFixes(finding2, document) {
|
|
|
8420
8815
|
if (allowsKey(document, parent, "extensions") && name !== "extensions") {
|
|
8421
8816
|
const existing = owner.extensions;
|
|
8422
8817
|
if (existing === void 0) fixes.push(patch("move-to-extensions", "Move into extensions", [{ op: "add", path: pointerOf([...parent, "extensions"]), value: {} }, { op: "move", from: finding2.path, path: pointerOf([...parent, "extensions", name]) }]));
|
|
8423
|
-
else if (
|
|
8818
|
+
else if (isRecord2(existing) && !Object.hasOwn(existing, name)) fixes.push(patch("move-to-extensions", "Move into extensions", [{ op: "move", from: finding2.path, path: pointerOf([...parent, "extensions", name]) }]));
|
|
8424
8819
|
}
|
|
8425
8820
|
return fixes;
|
|
8426
8821
|
}
|
|
8427
8822
|
case "type": {
|
|
8428
8823
|
const current = readAt(document, segments);
|
|
8429
8824
|
if (current === void 0) return [];
|
|
8430
|
-
if (params2.type === "array" && (typeof current === "string" ||
|
|
8825
|
+
if (params2.type === "array" && (typeof current === "string" || isRecord2(current))) return [patch("wrap-in-list", "Wrap in a list", [{ op: "replace", path: finding2.path, value: [current] }], typeof current === "string")];
|
|
8431
8826
|
if (params2.type === "string" && (typeof current === "number" || typeof current === "boolean")) return [patch("convert-to-string", "Convert to string", [{ op: "replace", path: finding2.path, value: String(current) }], true)];
|
|
8432
8827
|
return [];
|
|
8433
8828
|
}
|
|
@@ -8445,6 +8840,101 @@ function schemaFixes(finding2, document) {
|
|
|
8445
8840
|
return [];
|
|
8446
8841
|
}
|
|
8447
8842
|
}
|
|
8843
|
+
function listColumnsChangeDrawing(region) {
|
|
8844
|
+
if (!isRecord2(region) || region.listColumns !== "auto") return true;
|
|
8845
|
+
const accepts = Array.isArray(region.accepts) ? region.accepts : [];
|
|
8846
|
+
const arrangement = region.arrangement ?? region.sequence;
|
|
8847
|
+
return !(accepts[0] === "list" && (arrangement === void 0 || arrangement === "numbered"));
|
|
8848
|
+
}
|
|
8849
|
+
var REMOVED_LIST_COLUMNS = `OPF 0.35 removed the region key listColumns. Delete it: a list of more than 6 entries flows into up to three columns in any region without an arrangement (or with the numbered one) when that sets it at least as large as one column; a list payload's own columns (1, 2, 3 or "auto") still chooses.`;
|
|
8850
|
+
function removedKeyRepair(finding2, document) {
|
|
8851
|
+
const validation = finding2.validation;
|
|
8852
|
+
if (!validation || finding2.ruleId !== "opf/schema" && finding2.ruleId !== "opf/catalog-record") return void 0;
|
|
8853
|
+
const segments = segmentsOf(finding2.path);
|
|
8854
|
+
if (validation.keyword === "additionalProperties" && segments.length === 3 && segments[0] === "slides" && readAt(document, segments) !== void 0 && nearestGridCell(segments[2]) !== void 0) return cellKeyRepair(document, segments.slice(0, 2), segments[2]);
|
|
8855
|
+
const inRegion = segments.at(-3) === "regions";
|
|
8856
|
+
if (validation.keyword === "additionalProperties" && inRegion && (segments.at(-1) === "sequence" || segments.at(-1) === "pyramidDirection")) {
|
|
8857
|
+
const parent = segments.slice(0, -1), region = readAt(document, parent), value = readAt(document, segments);
|
|
8858
|
+
if (!isRecord2(region) || value === void 0) return void 0;
|
|
8859
|
+
const arrangement = region.arrangement;
|
|
8860
|
+
if (segments.at(-1) === "sequence") {
|
|
8861
|
+
const help2 = `OPF 0.35 replaced the region key sequence with arrangement: a region has one arrangement, a sequence ("steps" or "numbered") or a diagram. Write "arrangement": ${JSON.stringify(value)} in its place.`;
|
|
8862
|
+
if (arrangement !== void 0 || value !== "steps" && value !== "numbered") return { help: `${help2}${arrangement !== void 0 ? ` This region also has "arrangement": ${JSON.stringify(arrangement)}; keep one of the two.` : ""}`, fixes: [] };
|
|
8863
|
+
return { help: help2, fixes: [patch("use-arrangement", `Write arrangement ${value}`, [{ op: "move", from: finding2.path, path: pointerOf([...parent, "arrangement"]) }], true)] };
|
|
8864
|
+
}
|
|
8865
|
+
const help = 'OPF 0.35 removed the region key pyramidDirection: "arrangement": "inverted-pyramid" draws the pyramid upside down (what "down" did), and "arrangement": "pyramid" draws it upright ("up", the default).';
|
|
8866
|
+
if (arrangement !== "pyramid") return { help, fixes: [] };
|
|
8867
|
+
if (value === "down") return { help, fixes: [patch("use-inverted-pyramid", "Write arrangement inverted-pyramid", [{ op: "remove", path: finding2.path }, { op: "replace", path: pointerOf([...parent, "arrangement"]), value: "inverted-pyramid" }], true)] };
|
|
8868
|
+
if (value === "up") return { help, fixes: [patch("use-pyramid", "Keep arrangement pyramid (upright)", [{ op: "remove", path: finding2.path }], true)] };
|
|
8869
|
+
return { help, fixes: [] };
|
|
8870
|
+
}
|
|
8871
|
+
if (validation.keyword === "enum" && inRegion && segments.at(-1) === "arrangement") {
|
|
8872
|
+
const value = readAt(document, segments), renamed = value === "flow" ? "process" : value === "vertical-flow" ? "vertical-process" : void 0;
|
|
8873
|
+
if (renamed === void 0) return void 0;
|
|
8874
|
+
return { help: `OPF 0.35 renamed the arrangement "${String(value)}" to "${renamed}", PowerPoint's name (${renamed === "process" ? "Basic Process" : "Vertical Process"}); it draws the same.`, fixes: [patch("rename-arrangement", `Write arrangement ${renamed}`, [{ op: "replace", path: finding2.path, value: renamed }], true)] };
|
|
8875
|
+
}
|
|
8876
|
+
const alignment = segments.at(-1);
|
|
8877
|
+
if (validation.keyword === "enum" && finding2.ruleId === "opf/catalog-record" && segments.at(-2) === "design" && (alignment === "titleAlignment" || alignment === "contentAlignment")) {
|
|
8878
|
+
const value = readAt(document, segments), next = value === "left" ? "start" : value === "right" ? "end" : void 0;
|
|
8879
|
+
if (next === void 0) return void 0;
|
|
8880
|
+
return { help: `OPF 0.34 renamed the alignment "${String(value)}" to "${next}" (the start and end of the reading direction; the left and right edges of a left-to-right deck).`, fixes: [patch(`change-to:${next}`, `Change to ${next}`, [{ op: "replace", path: finding2.path, value: next }], true)] };
|
|
8881
|
+
}
|
|
8882
|
+
if (validation.keyword === "enum" && inRegion && segments.at(-1) === "role" && readAt(document, segments) === "secondary") {
|
|
8883
|
+
return {
|
|
8884
|
+
help: `OPF 0.35 removed the role "secondary" (bound after primary, before supporting): a region's role is "primary" (the default), "media" or "supporting". Write "supporting" for a region that takes what the primary regions leave, or "primary".`,
|
|
8885
|
+
fixes: [patch("change-to:supporting", "Change to supporting", [{ op: "replace", path: finding2.path, value: "supporting" }]), patch("change-to:primary", "Change to primary", [{ op: "replace", path: finding2.path, value: "primary" }])]
|
|
8886
|
+
};
|
|
8887
|
+
}
|
|
8888
|
+
if (validation.keyword === "additionalProperties") {
|
|
8889
|
+
const name = segments.at(-1) ?? "";
|
|
8890
|
+
if (name === "listColumns" && segments.at(-3) === "regions" && readAt(document, segments) !== void 0) return { help: REMOVED_LIST_COLUMNS, fixes: [patch("remove:listColumns", "Delete listColumns", [{ op: "remove", path: finding2.path }], true, listColumnsChangeDrawing(readAt(document, segments.slice(0, -1))))] };
|
|
8891
|
+
if (segments.at(-2) !== "design" || !Object.hasOwn(REMOVED_DESIGN_KEYS, name) || readAt(document, segments) === void 0) return void 0;
|
|
8892
|
+
const marks = REMOVED_DESIGN_KEY_FIXES[name] ?? { safe: true, changesDrawing: () => true };
|
|
8893
|
+
return { help: REMOVED_DESIGN_KEYS[name], fixes: [patch(`remove:${name}`, `Delete design.${name}`, removedDesignKeyOperations(document, segments), marks.safe, marks.changesDrawing(segments))] };
|
|
8894
|
+
}
|
|
8895
|
+
if (validation.keyword === "pattern" && segments.at(-1) === "region" && segments.at(-3) === "blocks" && segments[0] === "slides" && segments.length === 5) {
|
|
8896
|
+
const typed = readAt(document, segments), near = typeof typed === "string" ? nearestGridCell(typed) : void 0;
|
|
8897
|
+
if (!near?.help) return void 0;
|
|
8898
|
+
return { help: `${JSON.stringify(typed)} is no cell of the slide's grid. ${near.help}`, fixes: near.cell ? [patch(`change-to:${near.cell}`, `Change to ${near.cell}`, [{ op: "replace", path: finding2.path, value: near.cell }])] : [] };
|
|
8899
|
+
}
|
|
8900
|
+
if (validation.keyword === "enum" && segments.at(-1) === "flow" && segments.at(-3) === "regions" && readAt(document, segments) === "none") {
|
|
8901
|
+
const parent = segments.slice(0, -1), region = readAt(document, parent);
|
|
8902
|
+
const help = 'OPF 0.35 removed flow "none": a region of one block says "max": 1 (blocks no region had room for still join it), and its flow is "auto", "grid", "row" or "column".';
|
|
8903
|
+
if (!isRecord2(region) || region.max !== void 0 && region.max !== 1) return { help, fixes: [] };
|
|
8904
|
+
return { help, fixes: [patch("use-max-1", "Write max 1 (a region of one block)", [{ op: "remove", path: finding2.path }, { op: "add", path: pointerOf([...parent, "max"]), value: 1 }], true)] };
|
|
8905
|
+
}
|
|
8906
|
+
return void 0;
|
|
8907
|
+
}
|
|
8908
|
+
var ROOT_CONTENT = ["type", "text", "items", "bullets", "image", "video", "chart", "table", "code", "metric", "quote", "timeline", "diagram", "shape", "path", "blocks"];
|
|
8909
|
+
function removedCellKeys(slide) {
|
|
8910
|
+
if (!isRecord2(slide)) return [];
|
|
8911
|
+
const found = Object.keys(slide).flatMap((key3) => {
|
|
8912
|
+
const cell = nearestGridCell(key3)?.cell;
|
|
8913
|
+
return cell ? [{ key: key3, cell }] : [];
|
|
8914
|
+
});
|
|
8915
|
+
const order2 = cellsInReadingOrder(found);
|
|
8916
|
+
return order2.flatMap((cell) => found.filter((entry2) => entry2.cell === cell));
|
|
8917
|
+
}
|
|
8918
|
+
function cellKeysAsBlocks(slide) {
|
|
8919
|
+
const keys = removedCellKeys(slide);
|
|
8920
|
+
if (!keys.length || !isRecord2(slide) || ROOT_CONTENT.some((field) => slide[field] !== void 0) || keys.some(({ key: key3 }) => !isRecord2(slide[key3]))) return void 0;
|
|
8921
|
+
const placed = slide.layout === void 0;
|
|
8922
|
+
const blocks = keys.map(({ key: key3, cell }) => {
|
|
8923
|
+
const { id, region: _ignored, ...rest } = slide[key3];
|
|
8924
|
+
return { ...id !== void 0 ? { id } : {}, ...placed ? { region: cell } : {}, ...rest };
|
|
8925
|
+
});
|
|
8926
|
+
return { keys: keys.map(({ key: key3 }) => key3), blocks };
|
|
8927
|
+
}
|
|
8928
|
+
function cellKeyRepair(document, slideSegments, key3) {
|
|
8929
|
+
const slide = readAt(document, slideSegments), near = nearestGridCell(key3);
|
|
8930
|
+
const layout = isRecord2(slide) && slide.layout !== void 0;
|
|
8931
|
+
const example = near.cell ? `{ "region": "${near.cell}", ... }` : '{ "region": "top:start", ... }';
|
|
8932
|
+
const help = `OPF 0.35 removed the slide keys that placed content in the cells of a slide's 3 x 3 grid (the promoted regions): a block of the slide's blocks names its cell with "region", as ${example}. Blocks that name the same cell stack in it, and a slide places every block in a cell or none.` + (layout ? " This slide also has a layout, and a cell word names no region of a layout: the fix keeps the layout and moves each cell's content into a block without region, which binds to the layout's regions by kind, so the slide draws on its layout. To keep a grid of cells instead, remove layout and name the cells on the blocks." : "") + (near.help ? ` ${near.help}` : "");
|
|
8933
|
+
const moved = near.cell ? cellKeysAsBlocks(slide) : void 0;
|
|
8934
|
+
if (!moved) return { help, fixes: [], dropSuggestions: true };
|
|
8935
|
+
const operations = [...moved.keys.map((name) => ({ op: "remove", path: pointerOf([...slideSegments, name]) })), { op: "add", path: pointerOf([...slideSegments, "blocks"]), value: moved.blocks }];
|
|
8936
|
+
return { help, fixes: [layout ? patch("cells-to-layout-blocks", "Move the regions into blocks of the layout", operations, true, true) : patch("cells-to-blocks", "Move the regions into blocks with region", operations, true)], dropSuggestions: true };
|
|
8937
|
+
}
|
|
8448
8938
|
|
|
8449
8939
|
// src/drawn-font-families.ts
|
|
8450
8940
|
function resolveDrawnFontFamilies(families, measurement, keepsName) {
|
|
@@ -8455,15 +8945,15 @@ function resolveDrawnFontFamilies(families, measurement, keepsName) {
|
|
|
8455
8945
|
const named = families[role];
|
|
8456
8946
|
if (typeof named !== "string" || !named) continue;
|
|
8457
8947
|
try {
|
|
8458
|
-
const
|
|
8948
|
+
const resolved2 = resolve2.call(measurement, { fontFamily: named, fontWeight: role === "heading" ? 700 : 400 });
|
|
8459
8949
|
let keep3;
|
|
8460
|
-
if (keepsName) keep3 = keepsName(named,
|
|
8950
|
+
if (keepsName) keep3 = keepsName(named, resolved2.fontFamily);
|
|
8461
8951
|
else {
|
|
8462
|
-
const regular = role === "heading" ? resolve2.call(measurement, { fontFamily: named, fontWeight: 400 }) :
|
|
8463
|
-
const encoded =
|
|
8464
|
-
keep3 = encoded || regular.fontWeight !== void 0 && regular.fontWeight !== 400 &&
|
|
8952
|
+
const regular = role === "heading" ? resolve2.call(measurement, { fontFamily: named, fontWeight: 400 }) : resolved2;
|
|
8953
|
+
const encoded = resolved2.symbolEncoding != null;
|
|
8954
|
+
keep3 = encoded || regular.fontWeight !== void 0 && regular.fontWeight !== 400 && resolved2.fontFamily.toLowerCase() !== named.toLowerCase();
|
|
8465
8955
|
}
|
|
8466
|
-
if (!keep3) drawn[role] =
|
|
8956
|
+
if (!keep3) drawn[role] = resolved2.fontFamily;
|
|
8467
8957
|
} catch {
|
|
8468
8958
|
}
|
|
8469
8959
|
}
|
|
@@ -8472,24 +8962,24 @@ function resolveDrawnFontFamilies(families, measurement, keepsName) {
|
|
|
8472
8962
|
|
|
8473
8963
|
// src/script-measurement.ts
|
|
8474
8964
|
function scriptProfile(presentation, slideIndex, options2, language) {
|
|
8475
|
-
let
|
|
8965
|
+
let resolved2;
|
|
8476
8966
|
try {
|
|
8477
|
-
|
|
8967
|
+
resolved2 = resolveScriptFonts(presentation, { slideIndex, ...options2.catalogs !== void 0 ? { catalogs: options2.catalogs } : {}, ...language === void 0 ? {} : { language } });
|
|
8478
8968
|
} catch {
|
|
8479
|
-
|
|
8969
|
+
resolved2 = void 0;
|
|
8480
8970
|
}
|
|
8481
8971
|
const slots = (role) => {
|
|
8482
8972
|
const latin = options2.fontFamilies[role];
|
|
8483
|
-
const slot = (key3) => !
|
|
8973
|
+
const slot = (key3) => !resolved2 || resolved2.sources[key3] === "latin" || resolved2.sources[key3] === "schemeFamily" ? latin : resolved2[role][key3] ?? latin;
|
|
8484
8974
|
return { latin, eastAsian: slot("eastAsian"), complexScript: slot("complexScript") };
|
|
8485
8975
|
};
|
|
8486
8976
|
return {
|
|
8487
8977
|
heading: slots("heading"),
|
|
8488
8978
|
body: slots("body"),
|
|
8489
|
-
...
|
|
8490
|
-
script:
|
|
8491
|
-
...
|
|
8492
|
-
rtl:
|
|
8979
|
+
...resolved2?.supplement ? { supplement: resolved2.supplement } : {},
|
|
8980
|
+
script: resolved2?.script ?? "Zzzz",
|
|
8981
|
+
...resolved2 ? { scriptRole: resolved2.scriptRole, bcp47: resolved2.bcp47, lang: resolved2.lang, languageSource: resolved2.languageSource, direction: resolved2.direction } : {},
|
|
8982
|
+
rtl: resolved2?.rtl === true,
|
|
8493
8983
|
serif: options2.serif
|
|
8494
8984
|
};
|
|
8495
8985
|
}
|
|
@@ -8526,13 +9016,13 @@ function slideScriptMeasurement(presentation, slideIndex, measurement, options2)
|
|
|
8526
9016
|
function resolveSlideScriptMeasurement(presentation, slideIndex, measurement, options2 = {}) {
|
|
8527
9017
|
if (typeof measurement.forScripts !== "function") return measurement;
|
|
8528
9018
|
const { fontScheme } = resolveDesignRecords(presentation, slideIndex, options2.catalogs !== void 0 ? { catalogs: options2.catalogs } : {});
|
|
8529
|
-
const
|
|
8530
|
-
const fontFamilies = { heading: options2.fontFamilies?.heading ??
|
|
9019
|
+
const resolved2 = resolveFontFamilies(fontScheme);
|
|
9020
|
+
const fontFamilies = { heading: options2.fontFamilies?.heading ?? resolved2.heading, body: options2.fontFamilies?.body ?? resolved2.body };
|
|
8531
9021
|
return slideScriptMeasurement(presentation, slideIndex, measurement, { ...options2.catalogs !== void 0 ? { catalogs: options2.catalogs } : {}, fontFamilies, serif: fontScheme.type === "serif" });
|
|
8532
9022
|
}
|
|
8533
9023
|
|
|
8534
9024
|
// src/message-surface.ts
|
|
8535
|
-
var
|
|
9025
|
+
var rec3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8536
9026
|
var MESSAGE_SURFACE_SLOT = "accent1";
|
|
8537
9027
|
var MESSAGE_SURFACE_CONTRAST = 4.5;
|
|
8538
9028
|
function messageKind(slide, layout) {
|
|
@@ -8545,7 +9035,7 @@ function messageKind(slide, layout) {
|
|
|
8545
9035
|
return void 0;
|
|
8546
9036
|
}
|
|
8547
9037
|
if (plan?.stack !== void 0 && statementMessage(slide, plan) !== void 0) return "statement-message";
|
|
8548
|
-
if (plan && (plan.regions.length > 1 || plan.regions.some((region) => region.role === "media" || region.flow === "grid"))) return void 0;
|
|
9038
|
+
if (plan && (plan.regions.length > 1 || plan.regions.some((region) => region.role === "media" || region.flow === "grid" || region.flow === "row"))) return void 0;
|
|
8549
9039
|
const value = lone.host.text;
|
|
8550
9040
|
const cited = Array.isArray(value) && value.some((run) => run && typeof run === "object" && (run.cite !== void 0 || run.footnote !== void 0));
|
|
8551
9041
|
return !cited && messageWords(value) > 0 && messageWords(value) <= SHORT_MESSAGE_WORDS ? "display-message" : void 0;
|
|
@@ -8564,7 +9054,7 @@ function lchOf(hex) {
|
|
|
8564
9054
|
var MESSAGE_SURFACE_MAX_LIGHTNESS = 60;
|
|
8565
9055
|
var MESSAGE_SURFACE_MAX_CHROMA = 80;
|
|
8566
9056
|
function resolveMessageSurface(presentation, slide, layout, context) {
|
|
8567
|
-
const deckDesign =
|
|
9057
|
+
const deckDesign = rec3(rec3(presentation).design);
|
|
8568
9058
|
const kind = messageKind(slide, layout), named = layoutVariantKind(layout);
|
|
8569
9059
|
if (kind === void 0 || !(named === void 0 || named === "surface") || deckBackgroundIsChosen(deckDesign, context.theme.background) || !layoutVariantApplies(slide.design, layout, deckDesign, context.theme.background, true)) return void 0;
|
|
8570
9060
|
const below = colorChoice([deckDesign, context.theme], context.colorScheme, context.variables);
|
|
@@ -8577,7 +9067,7 @@ function resolveMessageSurface(presentation, slide, layout, context) {
|
|
|
8577
9067
|
return { kind, variant };
|
|
8578
9068
|
}
|
|
8579
9069
|
function drawsAccentByDesign(presentation, host, record, theme) {
|
|
8580
|
-
const deckDesign =
|
|
9070
|
+
const deckDesign = rec3(rec3(presentation).design), own4 = normalizeColorVariant(rec3(host.design).variant), named = layoutColorVariant(record);
|
|
8581
9071
|
if (own4) return own4.background.startsWith("accent");
|
|
8582
9072
|
return named !== void 0 && layoutVariantApplies(host.design, record, deckDesign, theme.background) && named.background.startsWith("accent");
|
|
8583
9073
|
}
|
|
@@ -8589,7 +9079,7 @@ function messageDisplayed(result, kind) {
|
|
|
8589
9079
|
}
|
|
8590
9080
|
|
|
8591
9081
|
// src/slide-context.ts
|
|
8592
|
-
var
|
|
9082
|
+
var rec4 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8593
9083
|
function unpathed(measurement) {
|
|
8594
9084
|
const bare = (style) => ({ ...style, path: void 0 });
|
|
8595
9085
|
return {
|
|
@@ -8601,18 +9091,18 @@ function unpathed(measurement) {
|
|
|
8601
9091
|
};
|
|
8602
9092
|
}
|
|
8603
9093
|
function resolveSlideContext(presentation, index, options2 = {}) {
|
|
8604
|
-
const deck =
|
|
9094
|
+
const deck = rec4(presentation);
|
|
8605
9095
|
const slides = Array.isArray(deck.slides) ? deck.slides : [];
|
|
8606
9096
|
if (!Number.isInteger(index) || index < 0 || index >= slides.length) throw new RangeError(`Slide index ${String(index)} is outside the presentation's ${slides.length} slides.`);
|
|
8607
|
-
const slide =
|
|
9097
|
+
const slide = rec4(slides[index]);
|
|
8608
9098
|
const catalogs = { catalogs: checkCatalogsOption(options2.catalogs, "resolveSlideContext") };
|
|
8609
9099
|
const records = resolveDesignRecords(presentation, index, catalogs);
|
|
8610
9100
|
const diagnostics = [...records.diagnostics];
|
|
8611
9101
|
const { theme, colorScheme, fontScheme } = records;
|
|
8612
|
-
const design = { ...
|
|
9102
|
+
const design = { ...rec4(deck.design), ...rec4(slide.design) };
|
|
8613
9103
|
let layout;
|
|
8614
9104
|
let layoutProvenance;
|
|
8615
|
-
if (typeof slide.layout === "string"
|
|
9105
|
+
if (typeof slide.layout === "string") {
|
|
8616
9106
|
const found = resolveReference(presentation, "layouts", slide.layout, catalogs);
|
|
8617
9107
|
if (found) {
|
|
8618
9108
|
layout = { ...found.record };
|
|
@@ -8620,10 +9110,10 @@ function resolveSlideContext(presentation, index, options2 = {}) {
|
|
|
8620
9110
|
} else diagnostics.push(unresolvedReference(presentation, "layouts", slide.layout, `slides.${index}.layout`, catalogs));
|
|
8621
9111
|
}
|
|
8622
9112
|
if (options2.strictReferences && diagnostics.length) throw new OPFUnresolvedReferenceError(diagnostics);
|
|
8623
|
-
const candidate = resolveMessageSurface(presentation, slide, layout, { theme, colorScheme, variables:
|
|
9113
|
+
const candidate = resolveMessageSurface(presentation, slide, layout, { theme, colorScheme, variables: rec4(deck.variables), themeChosen: records.provenance.theme !== void 0 });
|
|
8624
9114
|
const build = (surface) => {
|
|
8625
|
-
const levels = colorLevels(
|
|
8626
|
-
const roles2 = resolveColorRoles(colorScheme, colorChoice(levels, colorScheme,
|
|
9115
|
+
const levels = colorLevels(rec4(slide.design), layout, rec4(deck.design), theme, colorScheme, rec4(deck.variables), surface?.variant);
|
|
9116
|
+
const roles2 = resolveColorRoles(colorScheme, colorChoice(levels, colorScheme, rec4(deck.variables)));
|
|
8627
9117
|
const layoutVariant2 = levels.length > 3 && layoutVariantApplies(slide.design, layout, deck.design, theme.background, surface) ? levels[1].variant : void 0;
|
|
8628
9118
|
const composeOptions2 = {
|
|
8629
9119
|
...resolveCanvasDimensions(design.dimensions ?? theme.dimensions),
|
|
@@ -8634,12 +9124,12 @@ function resolveSlideContext(presentation, index, options2 = {}) {
|
|
|
8634
9124
|
slideCount: options2.slideCount ?? slides.length,
|
|
8635
9125
|
fontFamilies: resolveFontFamilies(fontScheme),
|
|
8636
9126
|
darkBackground: roles2.dark,
|
|
8637
|
-
...surface ? { messageSurface: surface, resolveRunColor: (reference) => resolveColorRef(reference, { colorScheme, roles: roles2, variables:
|
|
9127
|
+
...surface ? { messageSurface: surface, resolveRunColor: (reference) => resolveColorRef(reference, { colorScheme, roles: roles2, variables: rec4(deck.variables), fallback: "" }) || void 0 } : {},
|
|
8638
9128
|
// LH-02: the colors the automatic scrim of a picture background is sized for.
|
|
8639
9129
|
roles: { text: roles2.text, textSecondary: roles2.textSecondary, primary: roles2.primary, background: roles2.background },
|
|
8640
9130
|
...theme.background !== void 0 ? { themeBackground: theme.background } : {},
|
|
8641
9131
|
// OPF 0.19: a theme may carry the shared design keys (between the deck's design and the layout record's).
|
|
8642
|
-
...theme.design !== void 0 &&
|
|
9132
|
+
...theme.design !== void 0 && rec4(theme.design) === theme.design ? { themeDesign: theme.design } : {},
|
|
8643
9133
|
...options2.fonts?.textMeasurement ? { textMeasurement: options2.fonts.textMeasurement } : {},
|
|
8644
9134
|
...options2.date !== void 0 ? { date: options2.date } : {}
|
|
8645
9135
|
};
|
|
@@ -8658,7 +9148,7 @@ function resolveSlideContext(presentation, index, options2 = {}) {
|
|
|
8658
9148
|
displayed = false;
|
|
8659
9149
|
}
|
|
8660
9150
|
if (displayed && index > 0) {
|
|
8661
|
-
const before =
|
|
9151
|
+
const before = rec4(slides[index - 1]), record = typeof before.layout === "string" ? resolveReference(presentation, "layouts", before.layout, catalogs)?.record : void 0;
|
|
8662
9152
|
if (drawsAccentByDesign(presentation, before, record, theme) || resolveSlideContext(presentation, index - 1, { ...options2, slideNumber: void 0 }).resolved.messageSurface !== void 0) displayed = false;
|
|
8663
9153
|
}
|
|
8664
9154
|
if (!displayed) {
|
|
@@ -8708,33 +9198,33 @@ function buildSlides(document, options2, memo) {
|
|
|
8708
9198
|
const measurement = lazy(() => {
|
|
8709
9199
|
const host = measurementFor(options2, index);
|
|
8710
9200
|
if (!host) return void 0;
|
|
8711
|
-
const { resolved:
|
|
8712
|
-
return slideScriptMeasurement(document, index, host, { catalogs: options2.catalogs, fontFamilies: resolveFontFamilies(
|
|
9201
|
+
const { resolved: resolved3 } = baseContext();
|
|
9202
|
+
return slideScriptMeasurement(document, index, host, { catalogs: options2.catalogs, fontFamilies: resolveFontFamilies(resolved3.fontScheme), serif: resolved3.fontScheme.type === "serif" });
|
|
8713
9203
|
});
|
|
8714
|
-
const
|
|
9204
|
+
const resolved2 = lazy(() => {
|
|
8715
9205
|
const textMeasurement = measurement();
|
|
8716
9206
|
const slideContext = baseContext();
|
|
8717
9207
|
return textMeasurement ? { ...slideContext, options: { ...slideContext.options, textMeasurement } } : slideContext;
|
|
8718
9208
|
});
|
|
8719
|
-
const design = lazy(() => resolveDesign(document, index,
|
|
8720
|
-
const layout = lazy(() =>
|
|
9209
|
+
const design = lazy(() => resolveDesign(document, index, resolved2()));
|
|
9210
|
+
const layout = lazy(() => resolved2().options.layout);
|
|
8721
9211
|
const compute = () => {
|
|
8722
9212
|
const result = { layoutDiagnostics: [] };
|
|
8723
9213
|
let fontFamilies;
|
|
8724
9214
|
const compose = (input, withLayout) => {
|
|
8725
|
-
const options3 =
|
|
9215
|
+
const options3 = resolved2().options;
|
|
8726
9216
|
fontFamilies ??= options3.fontFamilies && resolveDrawnFontFamilies(options3.fontFamilies, options3.textMeasurement);
|
|
8727
9217
|
return composeSlide(input, { ...options3, ...fontFamilies ? { fontFamilies } : {}, layout: withLayout });
|
|
8728
9218
|
};
|
|
8729
9219
|
try {
|
|
8730
|
-
result.composition = compose(
|
|
9220
|
+
result.composition = compose(resolved2().slide, layout());
|
|
8731
9221
|
result.layoutDiagnostics.push(...result.composition.diagnostics.map((diagnostic) => ({ diagnostic, strict: false })));
|
|
8732
9222
|
} catch (error) {
|
|
8733
9223
|
if (error instanceof OPFCompositionError) {
|
|
8734
9224
|
result.layoutDiagnostics.push(...error.diagnostics.map((diagnostic) => ({ diagnostic, strict: true })));
|
|
8735
9225
|
try {
|
|
8736
9226
|
const relaxedLayout = layout();
|
|
8737
|
-
result.composition = compose(relax(
|
|
9227
|
+
result.composition = compose(relax(resolved2().slide), relaxedLayout ? relax(relaxedLayout) : void 0);
|
|
8738
9228
|
} catch (second) {
|
|
8739
9229
|
result.layoutError = second instanceof Error ? second.message : String(second);
|
|
8740
9230
|
}
|
|
@@ -8774,28 +9264,28 @@ var MAX_KEY_BYTES = 2 * 1024 * 1024;
|
|
|
8774
9264
|
function key2(value, opaque) {
|
|
8775
9265
|
let bytes = 0;
|
|
8776
9266
|
const seen = /* @__PURE__ */ new Set();
|
|
8777
|
-
const
|
|
9267
|
+
const part2 = (text2) => {
|
|
8778
9268
|
bytes += text2.length * 2;
|
|
8779
9269
|
if (bytes > MAX_KEY_BYTES) throw new RangeError("Review cache key budget exceeded.");
|
|
8780
9270
|
return text2;
|
|
8781
9271
|
};
|
|
8782
9272
|
const walk2 = (node, depth2) => {
|
|
8783
9273
|
if (depth2 > 128) throw new RangeError("Review cache key depth exceeded.");
|
|
8784
|
-
if (node === null) return
|
|
8785
|
-
if (node === void 0) return
|
|
8786
|
-
if (typeof node === "string") return
|
|
8787
|
-
if (typeof node === "boolean") return
|
|
8788
|
-
if (typeof node === "number" && Number.isFinite(node)) return
|
|
9274
|
+
if (node === null) return part2("null;");
|
|
9275
|
+
if (node === void 0) return part2("undefined;");
|
|
9276
|
+
if (typeof node === "string") return part2(`s${JSON.stringify(node)}`);
|
|
9277
|
+
if (typeof node === "boolean") return part2(node ? "true;" : "false;");
|
|
9278
|
+
if (typeof node === "number" && Number.isFinite(node)) return part2(`n${Object.is(node, -0) ? "-0" : node};`);
|
|
8789
9279
|
if (typeof node === "function" && opaque) {
|
|
8790
9280
|
opaque.push(node);
|
|
8791
|
-
return
|
|
9281
|
+
return part2(`f${opaque.length};`);
|
|
8792
9282
|
}
|
|
8793
9283
|
if (typeof node !== "object" || seen.has(node) || !Array.isArray(node) && ![Object.prototype, null].includes(Object.getPrototypeOf(node))) throw new TypeError("Opaque review cache input.");
|
|
8794
9284
|
seen.add(node);
|
|
8795
9285
|
const descriptors = Object.getOwnPropertyDescriptors(node);
|
|
8796
9286
|
if (Array.isArray(node) ? Reflect.ownKeys(node).length !== node.length + 1 || Object.keys(node).some((name, i) => name !== String(i)) : Object.values(descriptors).some((descriptor) => !descriptor.enumerable)) throw new TypeError("Non-JSON review cache input.");
|
|
8797
9287
|
if (Reflect.ownKeys(node).some((name) => typeof name === "symbol") || Object.values(descriptors).some((descriptor) => !("value" in descriptor))) throw new TypeError("Opaque review cache input.");
|
|
8798
|
-
const result = Array.isArray(node) ?
|
|
9288
|
+
const result = Array.isArray(node) ? part2("a[") + Array.from({ length: node.length }, (_, i) => Object.hasOwn(node, i) ? walk2(node[i], depth2 + 1) : part2("hole;")).join("") + part2("]") : part2("o{") + Object.keys(node).map((name) => part2(JSON.stringify(name)) + walk2(node[name], depth2 + 1)).join("") + part2("}");
|
|
8799
9289
|
seen.delete(node);
|
|
8800
9290
|
return result;
|
|
8801
9291
|
};
|
|
@@ -8978,7 +9468,7 @@ var ValidationCompositionCache = class {
|
|
|
8978
9468
|
// src/validator.ts
|
|
8979
9469
|
var SEVERITIES = ["error", "warning", "info"];
|
|
8980
9470
|
var OPTION_KEYS = ["only", "ignore", "severity", "ignorePaths", "catalogs", "contracts", "thresholds", "fonts", "chartPalette", "template", "values"];
|
|
8981
|
-
var
|
|
9471
|
+
var isObject3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8982
9472
|
var OPFValidationError = class extends Error {
|
|
8983
9473
|
/** The full report that failed. */
|
|
8984
9474
|
report;
|
|
@@ -9011,14 +9501,14 @@ function names(list, what) {
|
|
|
9011
9501
|
return result;
|
|
9012
9502
|
}
|
|
9013
9503
|
function resolveOptions(options2) {
|
|
9014
|
-
if (!
|
|
9504
|
+
if (!isObject3(options2)) throw new TypeError("Validate options must be an object.");
|
|
9015
9505
|
for (const key3 of Object.keys(options2)) if (!OPTION_KEYS.includes(key3)) throw new TypeError(`Unknown validate option ${JSON.stringify(key3)}. Options: ${OPTION_KEYS.join(", ")}.`);
|
|
9016
9506
|
checkDocumentOptions(options2);
|
|
9017
9507
|
const only = names(options2.only, "only");
|
|
9018
9508
|
const ignore = names(options2.ignore, "ignore");
|
|
9019
9509
|
const severity = /* @__PURE__ */ new Map();
|
|
9020
9510
|
if (options2.severity !== void 0) {
|
|
9021
|
-
if (!
|
|
9511
|
+
if (!isObject3(options2.severity)) throw new TypeError('Validate severity must map rule ids or category names to a severity or "off".');
|
|
9022
9512
|
for (const [name, value] of Object.entries(options2.severity)) {
|
|
9023
9513
|
if (typeof value !== "string" || value !== "off" && !SEVERITIES.includes(value)) throw new TypeError(`Validate severity for ${JSON.stringify(name)} must be error, warning, info or off.`);
|
|
9024
9514
|
const found = ruleFor(name, "severity");
|
|
@@ -9029,7 +9519,7 @@ function resolveOptions(options2) {
|
|
|
9029
9519
|
if (options2.ignorePaths !== void 0) {
|
|
9030
9520
|
if (!Array.isArray(options2.ignorePaths)) throw new TypeError("Validate ignorePaths must be an array of {rule, path}.");
|
|
9031
9521
|
for (const entry2 of options2.ignorePaths) {
|
|
9032
|
-
if (!
|
|
9522
|
+
if (!isObject3(entry2) || typeof entry2.rule !== "string" || typeof entry2.path !== "string" || entry2.path !== "" && !entry2.path.startsWith("/"))
|
|
9033
9523
|
throw new TypeError('Each validate ignorePaths entry needs a rule id, category name or "*", and a JSON Pointer path.');
|
|
9034
9524
|
const found = entry2.rule === "*" ? "*" : ruleFor(entry2.rule, "ignorePaths");
|
|
9035
9525
|
ignorePaths.push({
|
|
@@ -9040,7 +9530,7 @@ function resolveOptions(options2) {
|
|
|
9040
9530
|
}
|
|
9041
9531
|
const thresholds = { ...DEFAULT_VALIDATION_THRESHOLDS };
|
|
9042
9532
|
if (options2.thresholds !== void 0) {
|
|
9043
|
-
if (!
|
|
9533
|
+
if (!isObject3(options2.thresholds)) throw new TypeError("Validate thresholds must be an object.");
|
|
9044
9534
|
for (const [key3, value] of Object.entries(options2.thresholds)) {
|
|
9045
9535
|
if (!(key3 in DEFAULT_VALIDATION_THRESHOLDS)) throw new TypeError(`Unknown validate threshold ${JSON.stringify(key3)}. Thresholds: ${Object.keys(DEFAULT_VALIDATION_THRESHOLDS).join(", ")}.`);
|
|
9046
9536
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) throw new TypeError(`Validate threshold ${key3} must be a positive number.`);
|
|
@@ -9048,14 +9538,14 @@ function resolveOptions(options2) {
|
|
|
9048
9538
|
}
|
|
9049
9539
|
}
|
|
9050
9540
|
if (options2.fonts !== void 0) {
|
|
9051
|
-
if (!
|
|
9541
|
+
if (!isObject3(options2.fonts)) throw new TypeError("Validate fonts must be a fonts object with a textMeasurement.");
|
|
9052
9542
|
const measurement = options2.fonts.textMeasurement;
|
|
9053
|
-
if (measurement !== void 0 && typeof measurement !== "function" && !
|
|
9543
|
+
if (measurement !== void 0 && typeof measurement !== "function" && !isObject3(measurement)) throw new TypeError("Validate fonts.textMeasurement must be a text measurement, or a function of the slide index.");
|
|
9054
9544
|
}
|
|
9055
9545
|
if (options2.chartPalette !== void 0 && (!Array.isArray(options2.chartPalette) || !options2.chartPalette.every((color) => typeof color === "string" && /^#[0-9a-fA-F]{6}$/.test(color))))
|
|
9056
|
-
throw new TypeError("Validate chartPalette must be an array of #RRGGBB
|
|
9546
|
+
throw new TypeError("Validate chartPalette must be an array of #RRGGBB colors.");
|
|
9057
9547
|
if (options2.template !== void 0 && typeof options2.template !== "boolean") throw new TypeError("Validate template must be true or false.");
|
|
9058
|
-
if (options2.values !== void 0 && !
|
|
9548
|
+
if (options2.values !== void 0 && !isObject3(options2.values)) throw new TypeError("Validate values must be an object keyed by variable id.");
|
|
9059
9549
|
const level = (info) => severity.get(info.id) ?? severity.get(info.category);
|
|
9060
9550
|
const off = (info) => level(info) === "off" || !!ignore?.rules.has(info.id) || !!ignore?.categories.has(info.category);
|
|
9061
9551
|
return {
|
|
@@ -9066,12 +9556,13 @@ function resolveOptions(options2) {
|
|
|
9066
9556
|
const value = level(info);
|
|
9067
9557
|
return value === "off" ? void 0 : value;
|
|
9068
9558
|
},
|
|
9069
|
-
ignored: (info, path) => ignorePaths.some((entry2) => entry2.match(info) && entry2.path.every((
|
|
9559
|
+
ignored: (info, path) => ignorePaths.some((entry2) => entry2.match(info) && entry2.path.every((part2, index) => path[index] === part2)),
|
|
9070
9560
|
thresholds,
|
|
9071
9561
|
chartPalette: options2.chartPalette
|
|
9072
9562
|
};
|
|
9073
9563
|
}
|
|
9074
9564
|
var order = new Map(validationRules.map((info, index) => [info.id, index]));
|
|
9565
|
+
var STALE_RECORD_RULES = /* @__PURE__ */ new Set(["opf/catalog-record", "opf/layout-template", "opf/layout-region"]);
|
|
9075
9566
|
var categoryOrder = (category) => {
|
|
9076
9567
|
const index = validationCategories.indexOf(category);
|
|
9077
9568
|
return index < 0 ? validationCategories.length : index;
|
|
@@ -9112,7 +9603,7 @@ function syntaxReport(parsed, run) {
|
|
|
9112
9603
|
function validateDocument(document, run, parsed, cache) {
|
|
9113
9604
|
const engine = validateAgainstSchema(document, "presentation", { template: run.options.template, values: run.options.values, ...run.options.catalogs ? { catalogs: run.options.catalogs } : {} });
|
|
9114
9605
|
const schemaValid = engine.errors.length === 0;
|
|
9115
|
-
const slides =
|
|
9606
|
+
const slides = isObject3(document) && Array.isArray(document.slides) ? document.slides : [];
|
|
9116
9607
|
const auditWanted = auditInfos.some((info) => run.enabled(info));
|
|
9117
9608
|
const explainFormat = !schemaValid && auditWanted;
|
|
9118
9609
|
const enabledRule = (info) => info ? run.enabled(info) || explainFormat && info.category === "format" && !run.off(info) : true;
|
|
@@ -9169,15 +9660,30 @@ function validateDocument(document, run, parsed, cache) {
|
|
|
9169
9660
|
entry2.run(context);
|
|
9170
9661
|
}
|
|
9171
9662
|
}
|
|
9663
|
+
const staleCopies = /* @__PURE__ */ new Map();
|
|
9664
|
+
const staleRepair = (entry2) => {
|
|
9665
|
+
if (!STALE_RECORD_RULES.has(entry2.ruleId) || entry2.scope === "context") return void 0;
|
|
9666
|
+
const match2 = /^\/catalogs\/([^/]+)\/layouts\/([^/]+)(?:\/|$)/.exec(entry2.path);
|
|
9667
|
+
if (!match2) return void 0;
|
|
9668
|
+
const [group, id] = [match2[1], match2[2]].map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
9669
|
+
let found = staleCopies.get(`${group}/${id}`);
|
|
9670
|
+
if (!found) {
|
|
9671
|
+
const copy = staleLayoutCopy(document, group, id, run.options);
|
|
9672
|
+
const fix = copy ? staleCopyFix(document, copy, run.options) : void 0;
|
|
9673
|
+
found = copy ? { copy, ...fix ? { fix } : {} } : {};
|
|
9674
|
+
staleCopies.set(`${group}/${id}`, found);
|
|
9675
|
+
}
|
|
9676
|
+
return found.copy ? { cause: staleCopyCause(found.copy), fix: found.fix } : void 0;
|
|
9677
|
+
};
|
|
9172
9678
|
const finished = [];
|
|
9173
9679
|
for (const entry2 of findings) {
|
|
9174
9680
|
const info = findValidationRule(entry2.ruleId);
|
|
9175
9681
|
const override = info ? run.severity(info) : void 0;
|
|
9176
|
-
|
|
9682
|
+
let next = override && override !== entry2.severity ? { ...entry2, severity: override } : entry2;
|
|
9177
9683
|
if (info && run.ignored(info, splitPointer(next.path))) continue;
|
|
9178
9684
|
const index = slideOf(next.path);
|
|
9179
9685
|
if (next.slide === void 0 && index !== void 0 && next.scope !== "context") {
|
|
9180
|
-
const id =
|
|
9686
|
+
const id = isObject3(slides[index]) ? slides[index].id : void 0;
|
|
9181
9687
|
next.slide = index;
|
|
9182
9688
|
if (typeof id === "string") next.slideId = id;
|
|
9183
9689
|
}
|
|
@@ -9185,10 +9691,14 @@ function validateDocument(document, run, parsed, cache) {
|
|
|
9185
9691
|
const location = parsed.locate(next.path);
|
|
9186
9692
|
if (location) next.location = location;
|
|
9187
9693
|
}
|
|
9694
|
+
const removed = next.scope !== "context" ? removedKeyRepair(next, document) : void 0;
|
|
9695
|
+
if (removed) next = withRepair(next, removed);
|
|
9188
9696
|
if (next.ruleId === "opf/schema" && next.fixes === void 0 && next.scope !== "context") {
|
|
9189
9697
|
const fixes = schemaFixes(next, document);
|
|
9190
9698
|
if (fixes.length) next.fixes = fixes;
|
|
9191
9699
|
}
|
|
9700
|
+
const stale = staleRepair(next);
|
|
9701
|
+
if (stale) next = { ...next, message: `${stale.cause.split("; ")[0]}: ${next.message}`, help: next.help ? `${stale.cause} ${next.help}` : stale.cause, ...stale.fix ? { fixes: [stale.fix] } : {} };
|
|
9192
9702
|
finished.push(next);
|
|
9193
9703
|
}
|
|
9194
9704
|
finished.sort(
|
|
@@ -9251,11 +9761,18 @@ function assertValid(value, options2 = {}) {
|
|
|
9251
9761
|
const report2 = validate(value, options2);
|
|
9252
9762
|
if (!report2.valid) throw new OPFValidationError(report2);
|
|
9253
9763
|
}
|
|
9764
|
+
function withRepair(finding2, removed) {
|
|
9765
|
+
const { suggestions, ...rest } = finding2;
|
|
9766
|
+
return { ...removed.dropSuggestions ? rest : { ...rest, ...suggestions ? { suggestions } : {} }, help: removed.help, ...removed.fixes.length ? { fixes: removed.fixes } : {} };
|
|
9767
|
+
}
|
|
9254
9768
|
function validateCatalogRecord(kind, value) {
|
|
9255
9769
|
const kinds = Object.keys(catalogSchemaNames);
|
|
9256
9770
|
if (!kinds.includes(kind)) throw new TypeError(`Unknown catalog kind ${JSON.stringify(kind)}. Kinds: ${kinds.join(", ")}.`);
|
|
9257
9771
|
const engine = validateAgainstSchema(value, kind);
|
|
9258
|
-
const findings = engine.errors.map((issue2) =>
|
|
9772
|
+
const findings = engine.errors.map((issue2) => {
|
|
9773
|
+
const found = issueFinding(issue2, issueRuleId(issue2), engine.schemaName), removed = removedKeyRepair(found, value);
|
|
9774
|
+
return removed ? withRepair(found, removed) : found;
|
|
9775
|
+
});
|
|
9259
9776
|
const tally = counts(findings);
|
|
9260
9777
|
const checks = {
|
|
9261
9778
|
syntax: "not-applicable",
|
|
@@ -9274,4 +9791,4 @@ function assertValidCatalogRecord(kind, value) {
|
|
|
9274
9791
|
if (!report2.valid) throw new OPFValidationError(report2);
|
|
9275
9792
|
}
|
|
9276
9793
|
|
|
9277
|
-
export { BLOCK_AS_VALUES, BLOCK_OPTION_KEYS, CATALOG_SCHEMA, COMMON_KEYS, DEFAULT_VALIDATION_THRESHOLDS, FENCE_ATTRIBUTES, FENCE_KINDS, LINE_KEYWORDS, METRIC_KEYS, OPFPatchError, OPFPatchHashError, OPFPatchValidationError, OPFValidationError, PATTERN_PHRASES, SLIDE_OPTION_KEYS, SOURCE_EXPLAIN, SPAN_FLAGS, SPAN_VALUES, UNRANKED_PRIORITY, activeSchema, analyzeJsonSyntax, applyPatch, applyPatchWithInverse, applyTextEdits, assertValid, assertValidCatalogRecord, catalogDisplayKinds, catalogIconKinds, catalogKindAt, catalogSchemaNames, createLocator, createSchemaValue, createValidator, describeField, describeFinding,
|
|
9794
|
+
export { BLOCK_AS_VALUES, BLOCK_OPTION_KEYS, CATALOG_SCHEMA, COMMON_KEYS, DEFAULT_VALIDATION_THRESHOLDS, FENCE_ATTRIBUTES, FENCE_KINDS, LINE_KEYWORDS, METRIC_KEYS, OPFPatchError, OPFPatchHashError, OPFPatchValidationError, OPFValidationError, PATTERN_PHRASES, SLIDE_OPTION_KEYS, SOURCE_EXPLAIN, SPAN_FLAGS, SPAN_VALUES, UNRANKED_PRIORITY, activeSchema, analyzeJsonSyntax, applyPatch, applyPatchWithInverse, applyTextEdits, assertValid, assertValidCatalogRecord, catalogDisplayKinds, catalogIconKinds, catalogKindAt, catalogSchemaNames, createLocator, createSchemaValue, createValidator, describeField, describeFinding, distance, documentHash, escapePointerToken, findValidationRule, formatPointer, getAtPointer, hasPointer, idToken, invertPatch, isIdToken, jsonEqual, listSchemaFields, nearest, normalizePatch, parsePointer, parseSource, pointerFromPath, readPointer, refreshStaleLayouts, rememberByText, resolveDrawnFontFamilies, resolveIdPatch, resolveIdPointer, resolveSchema, resolveSlideContext, resolveSlideScriptMeasurement, ruleDocumentation, schemaAtPath, schemaCatalogKinds, schemaLabel, schemaType, schemaVariants, segmentsOf, splitOpfPath, splitPointer2 as splitPointer, starterValue, toIdPatch, toIdPointer, unescapePointerToken, validate, validateCatalogRecord, validationCategories, validationRules, walkPatch };
|