@openpresentation/opf 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -0
  3. package/dist/catalogs-x1oFFQnd.d.ts +1198 -0
  4. package/dist/catalogs.d.ts +2 -32413
  5. package/dist/catalogs.js +1 -18505
  6. package/dist/chunk-75N5I6M4.js +229 -0
  7. package/dist/chunk-EMTMQRX4.js +1007 -0
  8. package/dist/chunk-GCXOU5MZ.js +6515 -0
  9. package/dist/chunk-HJNJHB5H.js +454 -0
  10. package/dist/chunk-OZULJBSG.js +3368 -0
  11. package/dist/chunk-PIQXLBBJ.js +445 -0
  12. package/dist/chunk-SOSOBKQ2.js +145 -0
  13. package/dist/chunk-TWMRZ43O.js +18576 -0
  14. package/dist/composition.d.ts +190 -0
  15. package/dist/composition.js +1 -0
  16. package/dist/data.d.ts +32 -0
  17. package/dist/data.js +1 -0
  18. package/dist/docs.js +69 -5
  19. package/dist/examples.d.ts +1 -1
  20. package/dist/examples.js +113 -3
  21. package/dist/index.d.ts +6 -4
  22. package/dist/index.js +8 -29555
  23. package/dist/pagination.d.ts +52 -0
  24. package/dist/pagination.js +5 -0
  25. package/dist/{presentation-C8BOK0-5.d.ts → presentation-BjP4yTQ1.d.ts} +86 -3
  26. package/dist/previews.js +1 -447
  27. package/dist/repo-readme.js +1 -3
  28. package/dist/schemas-C1DxapX2.d.ts +206 -0
  29. package/dist/schemas.d.ts +1 -12373
  30. package/dist/schemas.js +1 -6275
  31. package/dist/spec/README.md +18 -3
  32. package/dist/spec/catalogs/audiences/index.json +1 -1
  33. package/dist/spec/catalogs/chart-types/index.json +1 -1
  34. package/dist/spec/catalogs/color-schemes/index.json +1 -1
  35. package/dist/spec/catalogs/font-schemes/index.json +1 -1
  36. package/dist/spec/catalogs/languages/index.json +1 -1
  37. package/dist/spec/catalogs/layouts/chart-1x.json +4 -1
  38. package/dist/spec/catalogs/layouts/chart-2x.json +5 -1
  39. package/dist/spec/catalogs/layouts/chart-3x.json +5 -1
  40. package/dist/spec/catalogs/layouts/code-1x.json +4 -1
  41. package/dist/spec/catalogs/layouts/extract/canonical.json +94 -21
  42. package/dist/spec/catalogs/layouts/image-1x.json +4 -1
  43. package/dist/spec/catalogs/layouts/image-2x.json +5 -1
  44. package/dist/spec/catalogs/layouts/image-3x.json +5 -1
  45. package/dist/spec/catalogs/layouts/index.json +1 -1
  46. package/dist/spec/catalogs/layouts/list-2x.json +4 -1
  47. package/dist/spec/catalogs/layouts/list-3x.json +4 -1
  48. package/dist/spec/catalogs/layouts/list-4x.json +5 -1
  49. package/dist/spec/catalogs/layouts/list-5x.json +5 -1
  50. package/dist/spec/catalogs/layouts/list-6x.json +5 -1
  51. package/dist/spec/catalogs/layouts/media-1x.json +4 -1
  52. package/dist/spec/catalogs/layouts/number-2x.json +4 -1
  53. package/dist/spec/catalogs/layouts/number-3x.json +4 -1
  54. package/dist/spec/catalogs/layouts/number-4x.json +5 -1
  55. package/dist/spec/catalogs/layouts/number-5x.json +5 -1
  56. package/dist/spec/catalogs/layouts/number-6x.json +5 -1
  57. package/dist/spec/catalogs/layouts/table-1x.json +4 -1
  58. package/dist/spec/catalogs/layouts/text-2x.json +4 -1
  59. package/dist/spec/catalogs/layouts/text-3x.json +4 -1
  60. package/dist/spec/catalogs/narratives/index.json +2 -2
  61. package/dist/spec/catalogs/purposes/index.json +1 -1
  62. package/dist/spec/catalogs/social-platforms/index.json +1 -1
  63. package/dist/spec/catalogs/themes/index.json +1 -1
  64. package/dist/spec/catalogs/tones/index.json +1 -1
  65. package/dist/spec/openapi.yaml +54 -14
  66. package/dist/spec/previews/layouts/index.json +71 -71
  67. package/dist/spec/schemas/catalog-index.schema.json +53 -0
  68. package/dist/spec/schemas/layout-preview-index.schema.json +54 -0
  69. package/dist/spec/schemas/layout.schema.json +63 -0
  70. package/dist/spec/schemas/opf.schema.json +182 -3
  71. package/dist/spec-files.d.ts +14 -2391
  72. package/dist/spec-files.js +1 -3356
  73. package/dist/types.d.ts +3 -1102
  74. package/dist/types.js +0 -2
  75. package/dist/validator.d.ts +3 -10
  76. package/dist/validator.js +4 -7243
  77. package/package.json +16 -3
  78. package/dist/catalogs.js.map +0 -1
  79. package/dist/docs.js.map +0 -1
  80. package/dist/examples.js.map +0 -1
  81. package/dist/index.js.map +0 -1
  82. package/dist/previews.js.map +0 -1
  83. package/dist/repo-readme.js.map +0 -1
  84. package/dist/schemas.js.map +0 -1
  85. package/dist/spec-files.js.map +0 -1
  86. package/dist/types.js.map +0 -1
  87. package/dist/validator.js.map +0 -1
@@ -0,0 +1,1007 @@
1
+ import { MAX_COMPOSITION_DEPTH } from './chunk-HJNJHB5H.js';
2
+ import { schemas } from './chunk-GCXOU5MZ.js';
3
+ import { catalogSchemaNames } from './chunk-TWMRZ43O.js';
4
+ import Ajv2020 from 'ajv/dist/2020.js';
5
+ import addFormats from 'ajv-formats';
6
+
7
+ // src/generated/catalog-ids.ts
8
+ var catalogIds = {
9
+ audiences: [
10
+ "executives",
11
+ "board",
12
+ "engineering-team",
13
+ "investors",
14
+ "customers",
15
+ "sales-team",
16
+ "marketing-team",
17
+ "all-hands",
18
+ "candidates",
19
+ "regulators"
20
+ ],
21
+ purposes: [
22
+ "inform",
23
+ "decide",
24
+ "align",
25
+ "persuade",
26
+ "educate",
27
+ "report",
28
+ "pitch",
29
+ "sell",
30
+ "plan"
31
+ ],
32
+ tones: [
33
+ "formal",
34
+ "casual",
35
+ "inspirational",
36
+ "technical",
37
+ "persuasive",
38
+ "authoritative",
39
+ "conversational"
40
+ ],
41
+ themes: [
42
+ "bold",
43
+ "classic",
44
+ "dark",
45
+ "minimal"
46
+ ],
47
+ layouts: [
48
+ "blank",
49
+ "chart-1x",
50
+ "chart-2x",
51
+ "chart-3x",
52
+ "code-1x",
53
+ "image-1x",
54
+ "image-2x",
55
+ "image-3x",
56
+ "image-bleed",
57
+ "list-1x",
58
+ "list-2x",
59
+ "list-3x",
60
+ "list-4x",
61
+ "list-5x",
62
+ "list-6x",
63
+ "media-1x",
64
+ "number-1x",
65
+ "number-2x",
66
+ "number-3x",
67
+ "number-4x",
68
+ "number-5x",
69
+ "number-6x",
70
+ "table-1x",
71
+ "text-1x",
72
+ "text-2x",
73
+ "text-3x",
74
+ "title",
75
+ "title-subtitle"
76
+ ],
77
+ chartTypes: [
78
+ "100pct-bullet-bar",
79
+ "100pct-bullet-bar-2x",
80
+ "100pct-bullet-bar-3x",
81
+ "100pct-bullet-column",
82
+ "100pct-bullet-column-2x",
83
+ "100pct-bullet-column-3x",
84
+ "100pct-progress-bar",
85
+ "100pct-stacked-area-2x",
86
+ "100pct-stacked-area-3x",
87
+ "100pct-stacked-bar-2x",
88
+ "100pct-stacked-bar-3x",
89
+ "100pct-stacked-column-2x",
90
+ "100pct-stacked-column-3x",
91
+ "area",
92
+ "australia",
93
+ "bar",
94
+ "box-and-whisker",
95
+ "box-and-whisker-2x",
96
+ "box-and-whisker-3x",
97
+ "bullet-bar",
98
+ "bullet-bar-2x",
99
+ "bullet-bar-3x",
100
+ "bullet-column",
101
+ "bullet-column-2x",
102
+ "bullet-column-3x",
103
+ "canada",
104
+ "clustered-bar-2x",
105
+ "clustered-column",
106
+ "column",
107
+ "dot-plot",
108
+ "dot-plot-2x",
109
+ "dot-plot-3x",
110
+ "dot-plot-4x",
111
+ "dot-plot-5x",
112
+ "dot-plot-6x",
113
+ "doughnut",
114
+ "dumbbell",
115
+ "filled-radar",
116
+ "funnel",
117
+ "histogram",
118
+ "line",
119
+ "line-2x",
120
+ "line-3x",
121
+ "line-with-high-low",
122
+ "line-with-high-low-and-markers",
123
+ "line-with-markers",
124
+ "line-with-markers-2x",
125
+ "line-with-markers-3x",
126
+ "pareto",
127
+ "pie",
128
+ "radar",
129
+ "radar-with-markers",
130
+ "scatter",
131
+ "sparkline",
132
+ "sparkline-2x",
133
+ "sparkline-3x",
134
+ "sparkline-4x",
135
+ "sparkline-5x",
136
+ "sparkline-6x",
137
+ "stacked-area-2x",
138
+ "stacked-area-3x",
139
+ "stacked-bar-2x",
140
+ "stacked-bar-3x",
141
+ "stacked-column-2x",
142
+ "stacked-column-3x",
143
+ "stacked-line-2x",
144
+ "stacked-line-3x",
145
+ "stacked-line-with-markers-2x",
146
+ "stacked-line-with-markers-3x",
147
+ "treemap",
148
+ "treemap-2x",
149
+ "treemap-3x",
150
+ "united-kingdom",
151
+ "united-states",
152
+ "waterfall",
153
+ "world"
154
+ ],
155
+ narratives: [
156
+ "problem-solution",
157
+ "scqa",
158
+ "strategic-narrative",
159
+ "golden-circle",
160
+ "conference-talk",
161
+ "transformation-arc",
162
+ "pitch-deck",
163
+ "early-startup-pitch",
164
+ "venture-pitch",
165
+ "persuasive-sales",
166
+ "company-intro",
167
+ "marketing-strategy",
168
+ "product-launch",
169
+ "strategic-advisory",
170
+ "challenge-resolution",
171
+ "project-proposal",
172
+ "failure-analysis",
173
+ "classic-story",
174
+ "business-narrative",
175
+ "rags-to-riches",
176
+ "underdog-victory",
177
+ "survival-story",
178
+ "educate",
179
+ "persuade",
180
+ "reveal",
181
+ "justice",
182
+ "innovation",
183
+ "focus",
184
+ "qbr",
185
+ "business-review",
186
+ "board-meeting",
187
+ "weekly-progress",
188
+ "status-update",
189
+ "performance-review",
190
+ "survey-analysis",
191
+ "trend-analysis",
192
+ "employee-review",
193
+ "performance-improvement-plan",
194
+ "capacity-planning"
195
+ ],
196
+ socialPlatforms: [
197
+ "linkedin",
198
+ "x",
199
+ "github",
200
+ "youtube",
201
+ "instagram",
202
+ "facebook",
203
+ "tiktok",
204
+ "threads",
205
+ "mastodon",
206
+ "bluesky"
207
+ ],
208
+ languages: [
209
+ "afrikaans",
210
+ "albanian",
211
+ "amharic",
212
+ "arabic",
213
+ "armenian",
214
+ "aymara",
215
+ "azerbaijani",
216
+ "bengali",
217
+ "berber-latin",
218
+ "bosnian-latin",
219
+ "bulgarian",
220
+ "catalan",
221
+ "cebuano",
222
+ "chinese-simplified",
223
+ "chinese-traditional",
224
+ "chittagonian",
225
+ "croatian",
226
+ "czech",
227
+ "danish",
228
+ "dutch",
229
+ "english",
230
+ "english-au",
231
+ "english-ca",
232
+ "english-gb",
233
+ "english-in",
234
+ "english-us",
235
+ "estonian",
236
+ "filipino",
237
+ "finnish",
238
+ "french",
239
+ "fulfulde",
240
+ "galician",
241
+ "georgian",
242
+ "german",
243
+ "greek",
244
+ "gujarati",
245
+ "hausa",
246
+ "hebrew",
247
+ "hindi",
248
+ "hungarian",
249
+ "igbo",
250
+ "indonesian",
251
+ "italian",
252
+ "japanese",
253
+ "kannada",
254
+ "kazakh",
255
+ "khmer",
256
+ "kinyarwanda",
257
+ "korean",
258
+ "kurmanji",
259
+ "latvian",
260
+ "lithuanian",
261
+ "macedonian",
262
+ "malagasy",
263
+ "malay",
264
+ "malayalam",
265
+ "maori",
266
+ "marathi",
267
+ "mongolian",
268
+ "nepali",
269
+ "norwegian",
270
+ "odia",
271
+ "oromo",
272
+ "pashto",
273
+ "persian",
274
+ "polish",
275
+ "portuguese",
276
+ "punjabi-gurmukhi",
277
+ "punjabi-shahmukhi",
278
+ "romanian",
279
+ "russian",
280
+ "serbian-cyrillic",
281
+ "serbian-latin",
282
+ "shona",
283
+ "slovak",
284
+ "slovenian",
285
+ "somali",
286
+ "spanish",
287
+ "swahili",
288
+ "swedish",
289
+ "tagalog",
290
+ "tajik",
291
+ "tamil",
292
+ "telugu",
293
+ "thai",
294
+ "turkish",
295
+ "ukrainian",
296
+ "urdu",
297
+ "uzbek-latin",
298
+ "vietnamese-quoc-ngu",
299
+ "xhosa",
300
+ "yoruba",
301
+ "zulu"
302
+ ],
303
+ colorSchemes: [
304
+ "black-and-white",
305
+ "bold-red",
306
+ "boost",
307
+ "burnt-orange",
308
+ "cool-horizon",
309
+ "corporate-blue",
310
+ "deep-purple",
311
+ "forest-green",
312
+ "golden-yellow",
313
+ "luxury",
314
+ "pastel-red",
315
+ "slate-gray",
316
+ "steel-blue",
317
+ "vibes"
318
+ ],
319
+ fontSchemes: [
320
+ "angsana-new",
321
+ "aparajita",
322
+ "aptos",
323
+ "arabic-typesetting",
324
+ "arial",
325
+ "batang",
326
+ "bookman",
327
+ "calibri",
328
+ "century-schoolbook",
329
+ "consolas",
330
+ "constantia",
331
+ "courier-new",
332
+ "daunpenh",
333
+ "david",
334
+ "dilleniaupc",
335
+ "fangsong",
336
+ "garamond",
337
+ "gautami",
338
+ "georgia",
339
+ "gisha",
340
+ "grandview",
341
+ "gungsuh",
342
+ "impact",
343
+ "kalinga",
344
+ "kartika",
345
+ "khmer-ui",
346
+ "latha",
347
+ "lucida-sans",
348
+ "malgun-gothic",
349
+ "mangal",
350
+ "meiryo",
351
+ "microsoft-jhenghei",
352
+ "microsoft-yahei",
353
+ "mingliu",
354
+ "miriam",
355
+ "montserrat",
356
+ "ms-mincho",
357
+ "nirmala-ui",
358
+ "noto-naksh-arabic",
359
+ "noto-nastaliq-urdu",
360
+ "noto-sans",
361
+ "noto-sans-arabic",
362
+ "noto-sans-armenian",
363
+ "noto-sans-bengali",
364
+ "noto-sans-devangari",
365
+ "noto-sans-ethiopic",
366
+ "noto-sans-georgian",
367
+ "noto-sans-gujarati",
368
+ "noto-sans-gurmukhi",
369
+ "noto-sans-hebrew",
370
+ "noto-sans-jp",
371
+ "noto-sans-kannada",
372
+ "noto-sans-khmer",
373
+ "noto-sans-kr",
374
+ "noto-sans-malayalam",
375
+ "noto-sans-mongolian",
376
+ "noto-sans-oriya",
377
+ "noto-sans-sc",
378
+ "noto-sans-tamil",
379
+ "noto-sans-tc",
380
+ "noto-sans-telugu",
381
+ "noto-sans-thai",
382
+ "nyala",
383
+ "open-sans",
384
+ "pmingliu",
385
+ "poppins",
386
+ "pt-serif",
387
+ "raavi",
388
+ "raleway",
389
+ "roboto",
390
+ "rockwell",
391
+ "sakkal-majalla",
392
+ "seaford",
393
+ "segoe-ui",
394
+ "segoe-ui-light",
395
+ "shonar-bangla",
396
+ "shruti",
397
+ "simsun",
398
+ "skeena",
399
+ "sylfaen",
400
+ "tahoma",
401
+ "tenorite",
402
+ "times-new-roman",
403
+ "traditional-arabic",
404
+ "trebuchet-ms",
405
+ "tunga",
406
+ "verdana",
407
+ "vrinda",
408
+ "yu-gothic"
409
+ ]
410
+ };
411
+
412
+ // src/validator.ts
413
+ var OPFValidationError = class extends Error {
414
+ issues;
415
+ result;
416
+ constructor(result) {
417
+ const first = result.errors[0];
418
+ super(first ? `OPF validation failed at ${first.path}: ${first.message}` : "OPF validation failed");
419
+ this.name = "OPFValidationError";
420
+ this.issues = result.errors;
421
+ this.result = result;
422
+ }
423
+ };
424
+ var schemaNameByCatalogKind = catalogSchemaNames;
425
+ var ajv;
426
+ var dynamicSchemaCache = /* @__PURE__ */ new WeakMap();
427
+ var promotedRegionKeys = [
428
+ "left",
429
+ "center",
430
+ "right",
431
+ "left+center",
432
+ "center+right",
433
+ "left+center+right",
434
+ "top",
435
+ "middle",
436
+ "bottom",
437
+ "top+middle",
438
+ "middle+bottom",
439
+ "top+middle+bottom",
440
+ "top:left",
441
+ "top:center",
442
+ "top:right",
443
+ "top:left+center",
444
+ "top:center+right",
445
+ "top:left+center+right",
446
+ "middle:left",
447
+ "middle:center",
448
+ "middle:right",
449
+ "middle:left+center",
450
+ "middle:center+right",
451
+ "middle:left+center+right",
452
+ "bottom:left",
453
+ "bottom:center",
454
+ "bottom:right",
455
+ "bottom:left+center",
456
+ "bottom:center+right",
457
+ "bottom:left+center+right",
458
+ "top+middle:left",
459
+ "top+middle:center",
460
+ "top+middle:right",
461
+ "top+middle:left+center",
462
+ "top+middle:center+right",
463
+ "top+middle:left+center+right",
464
+ "middle+bottom:left",
465
+ "middle+bottom:center",
466
+ "middle+bottom:right",
467
+ "middle+bottom:left+center",
468
+ "middle+bottom:center+right",
469
+ "middle+bottom:left+center+right",
470
+ "top+middle+bottom:left",
471
+ "top+middle+bottom:center",
472
+ "top+middle+bottom:right",
473
+ "top+middle+bottom:left+center",
474
+ "top+middle+bottom:center+right",
475
+ "top+middle+bottom:left+center+right"
476
+ ];
477
+ var promotedRegionKeySet = new Set(promotedRegionKeys);
478
+ var rootPayloadFields = [
479
+ "type",
480
+ "text",
481
+ "items",
482
+ "bullets",
483
+ "image",
484
+ "video",
485
+ "chart",
486
+ "table",
487
+ "code",
488
+ "metric",
489
+ "quote",
490
+ "timeline",
491
+ "blocks"
492
+ ];
493
+ var contentKindSpecs = {
494
+ text: {
495
+ fields: ["text", "bullets"],
496
+ required: [],
497
+ requireAny: ["text", "bullets"]
498
+ },
499
+ list: {
500
+ fields: ["items"],
501
+ required: ["items"]
502
+ },
503
+ image: {
504
+ fields: ["image"],
505
+ required: ["image"]
506
+ },
507
+ chart: {
508
+ fields: ["chart"],
509
+ required: ["chart"]
510
+ },
511
+ table: {
512
+ fields: ["table"],
513
+ required: ["table"]
514
+ },
515
+ video: {
516
+ fields: ["video"],
517
+ required: ["video"]
518
+ },
519
+ code: {
520
+ fields: ["code"],
521
+ required: ["code"]
522
+ },
523
+ metric: {
524
+ fields: ["metric"],
525
+ required: ["metric"]
526
+ },
527
+ quote: {
528
+ fields: ["quote"],
529
+ required: ["quote"]
530
+ },
531
+ timeline: {
532
+ fields: ["timeline"],
533
+ required: ["timeline"]
534
+ }
535
+ };
536
+ var columnSpans = {
537
+ left: [0],
538
+ center: [1],
539
+ right: [2],
540
+ "left+center": [0, 1],
541
+ "center+right": [1, 2],
542
+ "left+center+right": [0, 1, 2]
543
+ };
544
+ var rowSpans = {
545
+ top: [0],
546
+ middle: [1],
547
+ bottom: [2],
548
+ "top+middle": [0, 1],
549
+ "middle+bottom": [1, 2],
550
+ "top+middle+bottom": [0, 1, 2]
551
+ };
552
+ function getAjv() {
553
+ if (ajv) {
554
+ return ajv;
555
+ }
556
+ const instance = new Ajv2020({
557
+ allErrors: true,
558
+ strict: false,
559
+ allowUnionTypes: true
560
+ });
561
+ addFormats(instance);
562
+ for (const schema of Object.values(schemas)) {
563
+ instance.addSchema(schema);
564
+ }
565
+ ajv = instance;
566
+ return instance;
567
+ }
568
+ function isSchemaName(value) {
569
+ return typeof value === "string" && value in schemas;
570
+ }
571
+ function isCatalogKind(value) {
572
+ return typeof value === "string" && value in schemaNameByCatalogKind;
573
+ }
574
+ function resolveValidator(schemaOrKind) {
575
+ const instance = getAjv();
576
+ if (isSchemaName(schemaOrKind)) {
577
+ const schema = schemas[schemaOrKind];
578
+ const validator2 = instance.getSchema(schema.$id) ?? instance.compile(schema);
579
+ return { validate: validator2, schemaName: schemaOrKind };
580
+ }
581
+ if (isCatalogKind(schemaOrKind)) {
582
+ const schemaName = schemaNameByCatalogKind[schemaOrKind];
583
+ const schema = schemas[schemaName];
584
+ const validator2 = instance.getSchema(schema.$id) ?? instance.compile(schema);
585
+ return { validate: validator2, schemaName, catalogKind: schemaOrKind };
586
+ }
587
+ const cached = dynamicSchemaCache.get(schemaOrKind);
588
+ if (cached) {
589
+ return { validate: cached };
590
+ }
591
+ const validator = instance.compile(schemaOrKind);
592
+ dynamicSchemaCache.set(schemaOrKind, validator);
593
+ return { validate: validator };
594
+ }
595
+ function toIssue(error) {
596
+ return {
597
+ path: error.instancePath || "/",
598
+ message: error.message ?? "failed validation",
599
+ keyword: error.keyword,
600
+ schemaPath: error.schemaPath,
601
+ params: error.params
602
+ };
603
+ }
604
+ function semanticIssue(path, message, params = {}) {
605
+ return {
606
+ path,
607
+ message,
608
+ keyword: "opf",
609
+ schemaPath: "#/x-opf-semantics",
610
+ params
611
+ };
612
+ }
613
+ function isRecord(value) {
614
+ return typeof value === "object" && value !== null && !Array.isArray(value);
615
+ }
616
+ function hasOwn(value, key) {
617
+ return Object.hasOwn(value, key);
618
+ }
619
+ function isEnUkTag(value) {
620
+ return typeof value === "string" && value.toLowerCase() === "en-uk";
621
+ }
622
+ function pathFor(parentPath, key) {
623
+ return parentPath === "/" ? `/${key}` : `${parentPath}/${key.replaceAll("~", "~0").replaceAll("/", "~1")}`;
624
+ }
625
+ function presentFields(value, fields) {
626
+ return fields.filter((field) => hasOwn(value, field));
627
+ }
628
+ function isContentKind(value) {
629
+ return typeof value === "string" && value in contentKindSpecs;
630
+ }
631
+ function inferredKinds(value) {
632
+ const kinds = [];
633
+ if (presentFields(value, contentKindSpecs.text.fields).length > 0) kinds.push("text");
634
+ if (hasOwn(value, "items")) kinds.push("list");
635
+ if (hasOwn(value, "image")) kinds.push("image");
636
+ if (hasOwn(value, "video")) kinds.push("video");
637
+ if (hasOwn(value, "chart")) kinds.push("chart");
638
+ if (hasOwn(value, "table")) kinds.push("table");
639
+ if (hasOwn(value, "code")) kinds.push("code");
640
+ if (hasOwn(value, "metric")) kinds.push("metric");
641
+ if (hasOwn(value, "quote")) kinds.push("quote");
642
+ if (hasOwn(value, "timeline")) kinds.push("timeline");
643
+ return kinds;
644
+ }
645
+ function isImplicitBlocksComposition(value, inferred, options) {
646
+ if (options.slideRoot !== true || hasOwn(value, "blocks")) {
647
+ return false;
648
+ }
649
+ return inferred.length > 1;
650
+ }
651
+ function validateContentPayload(value, path, options = {}) {
652
+ const issues = [];
653
+ const explicitType = value.type;
654
+ const payloadFields = presentFields(value, rootPayloadFields);
655
+ const hasBlocks = hasOwn(value, "blocks");
656
+ if (hasBlocks || explicitType === "group") {
657
+ if (explicitType !== void 0 && explicitType !== "group") issues.push(semanticIssue(path, "a group must use type 'group' or omit type"));
658
+ const incompatible2 = payloadFields.filter((field) => field !== "blocks" && field !== "type");
659
+ if (incompatible2.length) issues.push(semanticIssue(path, "blocks cannot be mixed with leaf payload fields", { fields: incompatible2 }));
660
+ if (!Array.isArray(value.blocks) || value.blocks.length === 0 && !options.slideRoot) issues.push(semanticIssue(pathFor(path, "blocks"), "a group requires at least one block"));
661
+ if (Array.isArray(value.blocks)) value.blocks.forEach((block, index) => {
662
+ if (isRecord(block)) issues.push(...validateContentPayload(block, `${pathFor(path, "blocks")}/${index}`));
663
+ });
664
+ return issues;
665
+ }
666
+ if (hasOwn(value, "composition") && !options.slideRoot) issues.push(semanticIssue(pathFor(path, "composition"), "composition is only valid on a group containing blocks"));
667
+ if (explicitType !== void 0 && !isContentKind(explicitType)) {
668
+ return issues;
669
+ }
670
+ const kind = isContentKind(explicitType) ? explicitType : void 0;
671
+ const inferred = kind ? [kind] : inferredKinds(value);
672
+ if (!kind && inferred.length === 0) {
673
+ if (payloadFields.length > 0 || path !== "/") {
674
+ issues.push(semanticIssue(path, "content payload must include concrete content fields", {
675
+ fields: payloadFields
676
+ }));
677
+ }
678
+ return issues;
679
+ }
680
+ if (!kind && inferred.length > 1) {
681
+ if (isImplicitBlocksComposition(value, inferred, options)) {
682
+ return issues;
683
+ }
684
+ issues.push(semanticIssue(path, "content payload mixes fields from incompatible content types", {
685
+ inferredTypes: inferred
686
+ }));
687
+ return issues;
688
+ }
689
+ const resolvedKind = inferred[0];
690
+ if (!resolvedKind) {
691
+ return issues;
692
+ }
693
+ const spec = contentKindSpecs[resolvedKind];
694
+ const allowedFields = /* @__PURE__ */ new Set([
695
+ "type",
696
+ ...spec.fields
697
+ ]);
698
+ for (const required of spec.required) {
699
+ if (!hasOwn(value, required)) {
700
+ issues.push(semanticIssue(path, `content payload type '${resolvedKind}' requires '${required}'`, {
701
+ type: resolvedKind,
702
+ required
703
+ }));
704
+ }
705
+ }
706
+ if (spec.requireAny && presentFields(value, spec.requireAny).length === 0) {
707
+ issues.push(semanticIssue(path, `content payload type '${resolvedKind}' requires one of: ${spec.requireAny.join(", ")}`, {
708
+ type: resolvedKind,
709
+ requiredAny: spec.requireAny
710
+ }));
711
+ }
712
+ const incompatible = payloadFields.filter((field) => !allowedFields.has(field));
713
+ if (incompatible.length > 0) {
714
+ issues.push(semanticIssue(path, `content payload type '${resolvedKind}' cannot include incompatible fields: ${incompatible.join(", ")}`, {
715
+ type: resolvedKind,
716
+ incompatible
717
+ }));
718
+ }
719
+ return issues;
720
+ }
721
+ function slideRegion(key) {
722
+ if (key.includes(":")) {
723
+ const [rowPart, columnPart] = key.split(":");
724
+ if (!rowPart || !columnPart) return void 0;
725
+ const rows = rowSpans[rowPart];
726
+ const columns = columnSpans[columnPart];
727
+ return rows && columns ? { rows, columns } : void 0;
728
+ }
729
+ if (key in columnSpans) {
730
+ const columns = columnSpans[key];
731
+ return columns ? { rows: [0, 1, 2], columns } : void 0;
732
+ }
733
+ if (key in rowSpans) {
734
+ const rows = rowSpans[key];
735
+ return rows ? { rows, columns: [0, 1, 2] } : void 0;
736
+ }
737
+ return void 0;
738
+ }
739
+ function intersects(left, right) {
740
+ return left.some((value) => right.includes(value));
741
+ }
742
+ function regionsOverlap(left, right) {
743
+ return intersects(left.rows, right.rows) && intersects(left.columns, right.columns);
744
+ }
745
+ function validateSlideRegions(slide, slidePath) {
746
+ const issues = [];
747
+ const regionKeys = Object.keys(slide).filter((key) => promotedRegionKeySet.has(key));
748
+ const rootFields = presentFields(slide, rootPayloadFields);
749
+ if (regionKeys.length > 0 && rootFields.length > 0) {
750
+ issues.push(semanticIssue(slidePath, "root content payload fields cannot be mixed with promoted region keys", {
751
+ rootFields,
752
+ regionKeys
753
+ }));
754
+ }
755
+ if (regionKeys.length === 0 && rootFields.length > 0) {
756
+ issues.push(...validateContentPayload(slide, slidePath, { slideRoot: true }));
757
+ }
758
+ for (const key of regionKeys) {
759
+ const value = slide[key];
760
+ if (isRecord(value)) {
761
+ issues.push(...validateContentPayload(value, pathFor(slidePath, key)));
762
+ }
763
+ }
764
+ for (let leftIndex = 0; leftIndex < regionKeys.length; leftIndex += 1) {
765
+ const leftKey = regionKeys[leftIndex];
766
+ if (!leftKey) continue;
767
+ const leftRegion = slideRegion(leftKey);
768
+ if (!leftRegion) continue;
769
+ for (let rightIndex = leftIndex + 1; rightIndex < regionKeys.length; rightIndex += 1) {
770
+ const rightKey = regionKeys[rightIndex];
771
+ if (!rightKey) continue;
772
+ const rightRegion = slideRegion(rightKey);
773
+ if (!rightRegion) continue;
774
+ if (regionsOverlap(leftRegion, rightRegion)) {
775
+ issues.push(semanticIssue(slidePath, `promoted region keys '${leftKey}' and '${rightKey}' overlap`, {
776
+ regionKeys: [leftKey, rightKey]
777
+ }));
778
+ }
779
+ }
780
+ }
781
+ return issues;
782
+ }
783
+ function validatePresentationSemantics(value) {
784
+ if (!isRecord(value) || !Array.isArray(value.slides)) {
785
+ return [];
786
+ }
787
+ const issues = [];
788
+ if (isEnUkTag(value.language)) {
789
+ issues.push(semanticIssue("/language", "Use 'en-GB' for UK English; 'en-UK' is not a valid BCP-47 region tag", {
790
+ replacement: "en-GB"
791
+ }));
792
+ } else if (isRecord(value.language) && isEnUkTag(value.language.bcp47)) {
793
+ issues.push(semanticIssue("/language/bcp47", "Use 'en-GB' for UK English; 'en-UK' is not a valid BCP-47 region tag", {
794
+ replacement: "en-GB"
795
+ }));
796
+ }
797
+ const slideIds = /* @__PURE__ */ new Set();
798
+ value.slides.forEach((slide, index) => {
799
+ if (isRecord(slide)) {
800
+ if (typeof slide.id === "string") {
801
+ if (slideIds.has(slide.id)) issues.push(semanticIssue(`/slides/${index}/id`, "slide ids must be unique within a presentation", { id: slide.id }));
802
+ slideIds.add(slide.id);
803
+ }
804
+ issues.push(...validateSlideRegions(slide, `/slides/${index}`));
805
+ }
806
+ });
807
+ return issues;
808
+ }
809
+ var bareIdPattern = /^[a-z0-9][a-z0-9-]*$/;
810
+ function inlineCatalogEntry(context, kind) {
811
+ const catalogsField = context.document.catalogs;
812
+ if (!isRecord(catalogsField)) {
813
+ return void 0;
814
+ }
815
+ const entry = catalogsField[kind];
816
+ return isRecord(entry) ? entry : void 0;
817
+ }
818
+ function unknownIdWarning(kind, value, path, context) {
819
+ if (typeof value !== "string" || !bareIdPattern.test(value)) {
820
+ return void 0;
821
+ }
822
+ if (context) {
823
+ const entry = inlineCatalogEntry(context, kind);
824
+ if (entry) {
825
+ if (Array.isArray(entry.records) && entry.records.some((record) => isRecord(record) && record.id === value)) {
826
+ return void 0;
827
+ }
828
+ if (typeof entry.source === "string") {
829
+ return void 0;
830
+ }
831
+ }
832
+ }
833
+ if (catalogIds[kind].includes(value)) {
834
+ return void 0;
835
+ }
836
+ return semanticIssue(path, `unknown ${kind} catalog id '${value}'`, { kind, id: value });
837
+ }
838
+ function referenceObjectWarning(kind, value, path, context) {
839
+ if (typeof value === "string") {
840
+ return unknownIdWarning(kind, value, path, context);
841
+ }
842
+ if (isRecord(value)) {
843
+ return unknownIdWarning(kind, value.id, pathFor(path, "id"), context);
844
+ }
845
+ return void 0;
846
+ }
847
+ function pushIfDefined(issues, issue) {
848
+ if (issue) {
849
+ issues.push(issue);
850
+ }
851
+ }
852
+ function designReferenceWarnings(design, path, context) {
853
+ if (!isRecord(design)) {
854
+ return [];
855
+ }
856
+ const issues = [];
857
+ pushIfDefined(issues, referenceObjectWarning("themes", design.theme, pathFor(path, "theme"), context));
858
+ pushIfDefined(issues, referenceObjectWarning("colorSchemes", design.colorScheme, pathFor(path, "colorScheme"), context));
859
+ pushIfDefined(issues, referenceObjectWarning("fontSchemes", design.fontScheme, pathFor(path, "fontScheme"), context));
860
+ if (isRecord(design.theme)) {
861
+ const themePath = pathFor(path, "theme");
862
+ pushIfDefined(issues, referenceObjectWarning("colorSchemes", design.theme.colorScheme, pathFor(themePath, "colorScheme"), context));
863
+ pushIfDefined(issues, referenceObjectWarning("fontSchemes", design.theme.fontScheme, pathFor(themePath, "fontScheme"), context));
864
+ }
865
+ return issues;
866
+ }
867
+ function chartTypeWarnings(payload, path, context) {
868
+ if (!isRecord(payload)) {
869
+ return [];
870
+ }
871
+ const issues = [];
872
+ if (isRecord(payload.chart)) {
873
+ pushIfDefined(issues, unknownIdWarning("chartTypes", payload.chart.type, `${pathFor(path, "chart")}/type`, context));
874
+ }
875
+ if (Array.isArray(payload.blocks)) {
876
+ payload.blocks.forEach((block, index) => {
877
+ issues.push(...chartTypeWarnings(block, `${pathFor(path, "blocks")}/${index}`, context));
878
+ });
879
+ }
880
+ return issues;
881
+ }
882
+ function presentationReferenceWarnings(value) {
883
+ if (!isRecord(value) || !Array.isArray(value.slides)) {
884
+ return [];
885
+ }
886
+ const context = { document: value };
887
+ const issues = [];
888
+ if (typeof value.narrative === "string") {
889
+ pushIfDefined(issues, unknownIdWarning("narratives", value.narrative, "/narrative", context));
890
+ }
891
+ issues.push(...designReferenceWarnings(value.design, "/design", context));
892
+ value.slides.forEach((slide, index) => {
893
+ if (!isRecord(slide)) {
894
+ return;
895
+ }
896
+ const slidePath = `/slides/${index}`;
897
+ issues.push(...designReferenceWarnings(slide.design, pathFor(slidePath, "design"), context));
898
+ issues.push(...chartTypeWarnings(slide, slidePath, context));
899
+ for (const key of Object.keys(slide)) {
900
+ if (promotedRegionKeySet.has(key)) {
901
+ issues.push(...chartTypeWarnings(slide[key], pathFor(slidePath, key), context));
902
+ }
903
+ }
904
+ });
905
+ return issues;
906
+ }
907
+ var catalogCrossLinkFields = {
908
+ audience: { recommendedNarratives: "narratives", recommendedTones: "tones" },
909
+ purpose: { recommendedNarratives: "narratives", recommendedTones: "tones" },
910
+ tone: { recommendedNarratives: "narratives" }
911
+ };
912
+ function catalogCrossLinkWarnings(schemaName, value) {
913
+ const fields = catalogCrossLinkFields[schemaName];
914
+ if (!fields || !isRecord(value)) {
915
+ return [];
916
+ }
917
+ const issues = [];
918
+ for (const [field, kind] of Object.entries(fields)) {
919
+ const links = value[field];
920
+ if (!Array.isArray(links)) {
921
+ continue;
922
+ }
923
+ links.forEach((link, index) => {
924
+ pushIfDefined(issues, unknownIdWarning(kind, link, `${pathFor("/", field)}/${index}`));
925
+ });
926
+ }
927
+ return issues;
928
+ }
929
+ function validateLanguageSemantics(value) {
930
+ if (!isRecord(value)) {
931
+ return [];
932
+ }
933
+ if (isEnUkTag(value.bcp47)) {
934
+ return [semanticIssue("/bcp47", "Use 'en-GB' for UK English; 'en-UK' is not a valid BCP-47 region tag", {
935
+ replacement: "en-GB"
936
+ })];
937
+ }
938
+ return [];
939
+ }
940
+ function contentDepthIssues(value) {
941
+ if (!isRecord(value) || !Array.isArray(value.slides)) return [];
942
+ const stack = [];
943
+ value.slides.forEach((slide, index) => {
944
+ if (!isRecord(slide)) return;
945
+ if (Array.isArray(slide.blocks)) slide.blocks.forEach((block, i) => {
946
+ stack.push({ value: block, path: `/slides/${index}/blocks/${i}`, depth: 0, ancestors: [] });
947
+ });
948
+ for (const key of promotedRegionKeys) if (hasOwn(slide, key)) stack.push({ value: slide[key], path: `/slides/${index}/${key}`, depth: 0, ancestors: [] });
949
+ });
950
+ while (stack.length) {
951
+ const entry = stack.pop();
952
+ if (!isRecord(entry.value) || !Array.isArray(entry.value.blocks)) continue;
953
+ if (entry.ancestors.includes(entry.value) || entry.depth >= MAX_COMPOSITION_DEPTH) return [semanticIssue(entry.path, `content groups must be acyclic and nest at most ${MAX_COMPOSITION_DEPTH} levels`)];
954
+ const ancestors = [...entry.ancestors, entry.value];
955
+ entry.value.blocks.forEach((block, i) => {
956
+ stack.push({ value: block, path: `${entry.path}/blocks/${i}`, depth: entry.depth + 1, ancestors });
957
+ });
958
+ }
959
+ return [];
960
+ }
961
+ function validate(value, schemaOrKind = "presentation") {
962
+ const resolved = resolveValidator(schemaOrKind);
963
+ if (resolved.schemaName === "presentation") {
964
+ const errors2 = contentDepthIssues(value);
965
+ if (errors2.length) return { valid: false, errors: errors2, warnings: [], schemaName: resolved.schemaName };
966
+ }
967
+ const valid = resolved.validate(value) === true;
968
+ const errors = valid ? [] : (resolved.validate.errors ?? []).map(toIssue);
969
+ const warnings = [];
970
+ if (resolved.schemaName === "presentation") {
971
+ errors.push(...validatePresentationSemantics(value));
972
+ warnings.push(...presentationReferenceWarnings(value));
973
+ } else if (resolved.schemaName === "language") {
974
+ errors.push(...validateLanguageSemantics(value));
975
+ }
976
+ if (resolved.schemaName) {
977
+ warnings.push(...catalogCrossLinkWarnings(resolved.schemaName, value));
978
+ }
979
+ return {
980
+ valid: errors.length === 0,
981
+ errors,
982
+ warnings,
983
+ schemaName: resolved.schemaName,
984
+ catalogKind: resolved.catalogKind
985
+ };
986
+ }
987
+ function assertValid(value, schemaOrKind = "presentation") {
988
+ const result = validate(value, schemaOrKind);
989
+ if (!result.valid) {
990
+ throw new OPFValidationError(result);
991
+ }
992
+ return value;
993
+ }
994
+ function validatePresentation(value) {
995
+ return validate(value, "presentation");
996
+ }
997
+ function assertValidPresentation(value) {
998
+ assertValid(value, "presentation");
999
+ }
1000
+ function validateCatalogRecord(kind, value) {
1001
+ return validate(value, kind);
1002
+ }
1003
+ function assertValidCatalogRecord(kind, value) {
1004
+ assertValid(value, kind);
1005
+ }
1006
+
1007
+ export { OPFValidationError, assertValid, assertValidCatalogRecord, assertValidPresentation, validate, validateCatalogRecord, validatePresentation };