json2pptx-schema 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,818 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ DEFAULT_HEIGHT: () => DEFAULT_HEIGHT,
34
+ DEFAULT_SCHEMA_VERSION: () => DEFAULT_SCHEMA_VERSION,
35
+ DEFAULT_SLIDE_REMARK: () => DEFAULT_SLIDE_REMARK,
36
+ DEFAULT_SLIDE_TYPE: () => DEFAULT_SLIDE_TYPE,
37
+ DEFAULT_THEME: () => DEFAULT_THEME,
38
+ DEFAULT_THEME_OUTLINE: () => DEFAULT_THEME_OUTLINE,
39
+ DEFAULT_THEME_SHADOW: () => DEFAULT_THEME_SHADOW,
40
+ DEFAULT_TITLE: () => DEFAULT_TITLE,
41
+ DEFAULT_WIDTH: () => DEFAULT_WIDTH,
42
+ SchemaValidationError: () => SchemaValidationError,
43
+ UnsupportedSchemaVersionError: () => UnsupportedSchemaVersionError,
44
+ V1_DEFAULTS: () => V1_DEFAULTS,
45
+ V1_SCHEMA_VERSION: () => V1_SCHEMA_VERSION,
46
+ migrateDocument: () => migrateDocument,
47
+ normalizeDocument: () => normalizeDocument,
48
+ parseDocument: () => parseDocument,
49
+ validateDocument: () => validateDocument
50
+ });
51
+ module.exports = __toCommonJS(index_exports);
52
+
53
+ // versions/v1/defaults.ts
54
+ var DEFAULT_SCHEMA_VERSION = "1.0.0";
55
+ var DEFAULT_TITLE = "\u672A\u547D\u540D\u6F14\u793A\u6587\u7A3F";
56
+ var DEFAULT_WIDTH = 1e3;
57
+ var DEFAULT_HEIGHT = 562.5;
58
+ var DEFAULT_THEME_SHADOW = {
59
+ h: 3,
60
+ v: 3,
61
+ blur: 2,
62
+ color: "#808080"
63
+ };
64
+ var DEFAULT_THEME_OUTLINE = {
65
+ width: 2,
66
+ color: "#525252",
67
+ style: "solid"
68
+ };
69
+ var DEFAULT_THEME = {
70
+ themeColors: [],
71
+ fontColor: "#333",
72
+ fontName: "",
73
+ backgroundColor: "#fff",
74
+ shadow: DEFAULT_THEME_SHADOW,
75
+ outline: DEFAULT_THEME_OUTLINE
76
+ };
77
+ var DEFAULT_SLIDE_TYPE = "content";
78
+ var DEFAULT_SLIDE_REMARK = "";
79
+ var DEFAULT_TEXT_COLOR = "#333";
80
+ var DEFAULT_ELEMENT_ROTATE = 0;
81
+ var DEFAULT_IMAGE_FIXED_RATIO = true;
82
+ var DEFAULT_SHAPE_FIXED_RATIO = false;
83
+ var DEFAULT_LINE_STYLE = "solid";
84
+ var DEFAULT_LINE_WIDTH = 2;
85
+ var LEGACY_SLIDE_TYPE_MAP = {
86
+ agenda: "contents",
87
+ section: "transition",
88
+ ending: "end"
89
+ };
90
+ var V1_DEFAULTS = {
91
+ schemaVersion: DEFAULT_SCHEMA_VERSION,
92
+ title: DEFAULT_TITLE,
93
+ width: DEFAULT_WIDTH,
94
+ height: DEFAULT_HEIGHT,
95
+ theme: DEFAULT_THEME
96
+ };
97
+
98
+ // runtime/errors.ts
99
+ var SchemaValidationError = class extends Error {
100
+ constructor(issues, message = "Schema validation failed") {
101
+ super(message);
102
+ this.name = "SchemaValidationError";
103
+ this.issues = issues;
104
+ }
105
+ };
106
+ var UnsupportedSchemaVersionError = class extends Error {
107
+ constructor(receivedVersion, supportedVersion) {
108
+ const received = receivedVersion === void 0 || receivedVersion === null ? void 0 : String(receivedVersion);
109
+ super(
110
+ received ? `Unsupported schema version: ${received}. Supported version: ${supportedVersion}.` : `Unsupported schema version. Supported version: ${supportedVersion}.`
111
+ );
112
+ this.code = "UNSUPPORTED_SCHEMA_VERSION";
113
+ this.name = "UnsupportedSchemaVersionError";
114
+ this.supportedVersion = supportedVersion;
115
+ this.receivedVersion = received;
116
+ }
117
+ };
118
+
119
+ // runtime/migrate.ts
120
+ var V1_VERSION_EQUIVALENTS = /* @__PURE__ */ new Set(["1", "1.0", "1.0.0"]);
121
+ function isRecord(value) {
122
+ return typeof value === "object" && value !== null && !Array.isArray(value);
123
+ }
124
+ function cloneValue(value) {
125
+ if (typeof structuredClone === "function") {
126
+ return structuredClone(value);
127
+ }
128
+ return JSON.parse(JSON.stringify(value));
129
+ }
130
+ function normalizeVersion(value) {
131
+ if (typeof value === "number" && Number.isFinite(value)) {
132
+ if (value === 1) return DEFAULT_SCHEMA_VERSION;
133
+ return null;
134
+ }
135
+ if (typeof value !== "string") return null;
136
+ const trimmed = value.trim();
137
+ if (!trimmed) return null;
138
+ if (V1_VERSION_EQUIVALENTS.has(trimmed)) return DEFAULT_SCHEMA_VERSION;
139
+ return null;
140
+ }
141
+ function migrateSlideType(type) {
142
+ if (typeof type !== "string") return type;
143
+ const normalized = type.trim().toLowerCase();
144
+ return LEGACY_SLIDE_TYPE_MAP[normalized] ?? type;
145
+ }
146
+ function migrateDocument(input, toVersion = DEFAULT_SCHEMA_VERSION) {
147
+ if (!isRecord(input)) return input;
148
+ const migrated = cloneValue(input);
149
+ const incomingVersion = migrated.schemaVersion ?? migrated.version;
150
+ if (incomingVersion === void 0) {
151
+ migrated.schemaVersion = toVersion;
152
+ } else {
153
+ const normalizedVersion = normalizeVersion(incomingVersion);
154
+ if (!normalizedVersion || normalizedVersion !== toVersion) {
155
+ throw new UnsupportedSchemaVersionError(incomingVersion, toVersion);
156
+ }
157
+ migrated.schemaVersion = toVersion;
158
+ }
159
+ delete migrated.version;
160
+ if (isRecord(migrated.theme)) {
161
+ const theme = migrated.theme;
162
+ if (typeof theme.fontname === "string" && theme.fontName === void 0) {
163
+ theme.fontName = theme.fontname;
164
+ delete theme.fontname;
165
+ }
166
+ }
167
+ if (Array.isArray(migrated.slides)) {
168
+ migrated.slides = migrated.slides.map((slide) => {
169
+ if (!isRecord(slide)) return slide;
170
+ const nextSlide = cloneValue(slide);
171
+ nextSlide.type = migrateSlideType(nextSlide.type);
172
+ return nextSlide;
173
+ });
174
+ }
175
+ return migrated;
176
+ }
177
+
178
+ // runtime/normalize.ts
179
+ function isRecord2(value) {
180
+ return typeof value === "object" && value !== null && !Array.isArray(value);
181
+ }
182
+ function cloneValue2(value) {
183
+ if (typeof structuredClone === "function") {
184
+ return structuredClone(value);
185
+ }
186
+ return JSON.parse(JSON.stringify(value));
187
+ }
188
+ function asString(value, fallback) {
189
+ return typeof value === "string" ? value : fallback;
190
+ }
191
+ function asNumber(value, fallback) {
192
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
193
+ }
194
+ function asBoolean(value, fallback) {
195
+ return typeof value === "boolean" ? value : fallback;
196
+ }
197
+ function asPair(value, fallback) {
198
+ if (!Array.isArray(value) || value.length < 2) return fallback;
199
+ return [asNumber(value[0], fallback[0]), asNumber(value[1], fallback[1])];
200
+ }
201
+ function asLinePoints(value) {
202
+ if (!Array.isArray(value)) return ["", ""];
203
+ const first = typeof value[0] === "string" ? value[0] : "";
204
+ const second = typeof value[1] === "string" ? value[1] : "";
205
+ return [first, second];
206
+ }
207
+ function normalizeShadow(value) {
208
+ const source = isRecord2(value) ? value : {};
209
+ return {
210
+ ...source,
211
+ h: asNumber(source.h, DEFAULT_THEME_SHADOW.h),
212
+ v: asNumber(source.v, DEFAULT_THEME_SHADOW.v),
213
+ blur: asNumber(source.blur, DEFAULT_THEME_SHADOW.blur),
214
+ color: asString(source.color, DEFAULT_THEME_SHADOW.color)
215
+ };
216
+ }
217
+ function normalizeOutline(value) {
218
+ const source = isRecord2(value) ? value : {};
219
+ return {
220
+ ...source,
221
+ width: asNumber(source.width, DEFAULT_THEME_OUTLINE.width),
222
+ color: asString(source.color, DEFAULT_THEME_OUTLINE.color),
223
+ style: asString(source.style, DEFAULT_THEME_OUTLINE.style)
224
+ };
225
+ }
226
+ function normalizeTheme(value) {
227
+ const source = isRecord2(value) ? value : {};
228
+ const themeColors = Array.isArray(source.themeColors) ? source.themeColors.filter((item) => typeof item === "string") : DEFAULT_THEME.themeColors.slice();
229
+ return {
230
+ ...source,
231
+ themeColors,
232
+ fontColor: asString(source.fontColor, DEFAULT_THEME.fontColor),
233
+ fontName: asString(source.fontName, DEFAULT_THEME.fontName),
234
+ backgroundColor: asString(source.backgroundColor, DEFAULT_THEME.backgroundColor),
235
+ shadow: normalizeShadow(source.shadow),
236
+ outline: normalizeOutline(source.outline)
237
+ };
238
+ }
239
+ function normalizeBackground(value, fallbackColor) {
240
+ if (!isRecord2(value)) return void 0;
241
+ const type = typeof value.type === "string" && value.type.trim().length > 0 ? value.type : "solid";
242
+ const normalized = {
243
+ ...value,
244
+ type
245
+ };
246
+ if (type === "solid" && typeof normalized.color !== "string") {
247
+ normalized.color = fallbackColor;
248
+ }
249
+ return normalized;
250
+ }
251
+ function normalizeElement(value, slideIndex, elementIndex, theme) {
252
+ const fallbackId = `slide-${slideIndex + 1}-element-${elementIndex + 1}`;
253
+ if (!isRecord2(value)) {
254
+ return {
255
+ type: "unknown",
256
+ id: fallbackId,
257
+ left: 0,
258
+ top: 0,
259
+ rotate: DEFAULT_ELEMENT_ROTATE
260
+ };
261
+ }
262
+ const type = typeof value.type === "string" && value.type.trim().length > 0 ? value.type : "unknown";
263
+ const base = {
264
+ ...value,
265
+ type,
266
+ id: asString(value.id, fallbackId),
267
+ left: asNumber(value.left, 0),
268
+ top: asNumber(value.top, 0),
269
+ rotate: asNumber(value.rotate, DEFAULT_ELEMENT_ROTATE)
270
+ };
271
+ if (type === "text") {
272
+ const textElement = {
273
+ ...base,
274
+ type: "text",
275
+ width: asNumber(value.width, 0),
276
+ height: asNumber(value.height, 0),
277
+ content: asString(value.content, ""),
278
+ defaultColor: asString(value.defaultColor, theme.fontColor || DEFAULT_TEXT_COLOR),
279
+ defaultFontName: asString(value.defaultFontName, theme.fontName),
280
+ vertical: asBoolean(value.vertical, false)
281
+ };
282
+ return textElement;
283
+ }
284
+ if (type === "shape") {
285
+ const width = asNumber(value.width, 0);
286
+ const height = asNumber(value.height, 0);
287
+ const shapeElement = {
288
+ ...base,
289
+ type: "shape",
290
+ width,
291
+ height,
292
+ path: asString(value.path, ""),
293
+ viewBox: asPair(value.viewBox, [width, height]),
294
+ fill: asString(value.fill, ""),
295
+ fixedRatio: asBoolean(value.fixedRatio, DEFAULT_SHAPE_FIXED_RATIO)
296
+ };
297
+ return shapeElement;
298
+ }
299
+ if (type === "line") {
300
+ const lineElement = {
301
+ ...base,
302
+ type: "line",
303
+ width: asNumber(value.width, DEFAULT_LINE_WIDTH),
304
+ start: asPair(value.start, [0, 0]),
305
+ end: asPair(value.end, [0, 0]),
306
+ points: asLinePoints(value.points),
307
+ color: asString(value.color, "#000000"),
308
+ style: asString(value.style, DEFAULT_LINE_STYLE)
309
+ };
310
+ return lineElement;
311
+ }
312
+ if (type === "image") {
313
+ const imageElement = {
314
+ ...base,
315
+ type: "image",
316
+ width: asNumber(value.width, 0),
317
+ height: asNumber(value.height, 0),
318
+ src: asString(value.src, ""),
319
+ fixedRatio: asBoolean(value.fixedRatio, DEFAULT_IMAGE_FIXED_RATIO)
320
+ };
321
+ return imageElement;
322
+ }
323
+ return base;
324
+ }
325
+ function normalizeSlide(value, index, theme) {
326
+ if (!isRecord2(value)) {
327
+ return {
328
+ id: `slide-${index + 1}`,
329
+ type: DEFAULT_SLIDE_TYPE,
330
+ remark: DEFAULT_SLIDE_REMARK,
331
+ elements: []
332
+ };
333
+ }
334
+ const rawType = typeof value.type === "string" ? value.type.trim() : "";
335
+ const normalizedType = rawType && LEGACY_SLIDE_TYPE_MAP[rawType.toLowerCase()] ? LEGACY_SLIDE_TYPE_MAP[rawType.toLowerCase()] : rawType || DEFAULT_SLIDE_TYPE;
336
+ const sourceElements = Array.isArray(value.elements) ? value.elements : [];
337
+ const elements = sourceElements.map(
338
+ (element, elementIndex) => normalizeElement(element, index, elementIndex, theme)
339
+ );
340
+ const background = normalizeBackground(value.background, theme.backgroundColor);
341
+ return {
342
+ ...value,
343
+ id: asString(value.id, `slide-${index + 1}`),
344
+ type: normalizedType,
345
+ remark: asString(value.remark, DEFAULT_SLIDE_REMARK),
346
+ background,
347
+ elements
348
+ };
349
+ }
350
+ function normalizeDocument(input) {
351
+ const source = cloneValue2(input);
352
+ if (!isRecord2(source)) {
353
+ return {
354
+ schemaVersion: DEFAULT_SCHEMA_VERSION,
355
+ title: DEFAULT_TITLE,
356
+ width: DEFAULT_WIDTH,
357
+ height: DEFAULT_HEIGHT,
358
+ theme: normalizeTheme(void 0),
359
+ slides: []
360
+ };
361
+ }
362
+ const theme = normalizeTheme(source.theme);
363
+ const sourceSlides = Array.isArray(source.slides) ? source.slides : [];
364
+ const slides = sourceSlides.map((slide, index) => normalizeSlide(slide, index, theme));
365
+ const normalized = {
366
+ ...source,
367
+ schemaVersion: DEFAULT_SCHEMA_VERSION,
368
+ title: asString(source.title, DEFAULT_TITLE),
369
+ width: asNumber(source.width, DEFAULT_WIDTH),
370
+ height: asNumber(source.height, DEFAULT_HEIGHT),
371
+ theme,
372
+ slides
373
+ };
374
+ delete normalized.version;
375
+ return normalized;
376
+ }
377
+
378
+ // runtime/validate.ts
379
+ var import_ajv = __toESM(require("ajv"));
380
+
381
+ // versions/v1/schema.json
382
+ var schema_default = {
383
+ $schema: "http://json-schema.org/draft-07/schema#",
384
+ $id: "https://json2pptx.dev/schema/v1",
385
+ title: "json2pptx document schema v1",
386
+ type: "object",
387
+ required: ["slides"],
388
+ properties: {
389
+ schemaVersion: {
390
+ const: "1.0.0"
391
+ },
392
+ version: {
393
+ oneOf: [
394
+ { type: "string" },
395
+ { type: "number" }
396
+ ]
397
+ },
398
+ title: {
399
+ type: "string"
400
+ },
401
+ width: {
402
+ type: "number",
403
+ exclusiveMinimum: 0
404
+ },
405
+ height: {
406
+ type: "number",
407
+ exclusiveMinimum: 0
408
+ },
409
+ theme: {
410
+ $ref: "#/definitions/theme"
411
+ },
412
+ slides: {
413
+ type: "array",
414
+ items: {
415
+ $ref: "#/definitions/slide"
416
+ }
417
+ }
418
+ },
419
+ additionalProperties: true,
420
+ definitions: {
421
+ shadow: {
422
+ type: "object",
423
+ required: ["h", "v", "blur", "color"],
424
+ properties: {
425
+ h: { type: "number" },
426
+ v: { type: "number" },
427
+ blur: { type: "number" },
428
+ color: { type: "string" }
429
+ },
430
+ additionalProperties: true
431
+ },
432
+ outline: {
433
+ type: "object",
434
+ required: ["width", "color", "style"],
435
+ properties: {
436
+ width: { type: "number" },
437
+ color: { type: "string" },
438
+ style: { type: "string" }
439
+ },
440
+ additionalProperties: true
441
+ },
442
+ gradientStop: {
443
+ type: "object",
444
+ required: ["pos", "color"],
445
+ properties: {
446
+ pos: { type: "number" },
447
+ color: { type: "string" }
448
+ },
449
+ additionalProperties: true
450
+ },
451
+ gradient: {
452
+ type: "object",
453
+ required: ["type", "rotate", "colors"],
454
+ properties: {
455
+ type: { type: "string" },
456
+ rotate: { type: "number" },
457
+ colors: {
458
+ type: "array",
459
+ minItems: 2,
460
+ items: {
461
+ $ref: "#/definitions/gradientStop"
462
+ }
463
+ }
464
+ },
465
+ additionalProperties: true
466
+ },
467
+ theme: {
468
+ type: "object",
469
+ properties: {
470
+ themeColors: {
471
+ type: "array",
472
+ items: { type: "string" }
473
+ },
474
+ fontColor: { type: "string" },
475
+ fontName: { type: "string" },
476
+ backgroundColor: { type: "string" },
477
+ shadow: { $ref: "#/definitions/shadow" },
478
+ outline: { $ref: "#/definitions/outline" }
479
+ },
480
+ additionalProperties: true
481
+ },
482
+ pair: {
483
+ type: "array",
484
+ minItems: 2,
485
+ maxItems: 2,
486
+ items: { type: "number" }
487
+ },
488
+ linePoints: {
489
+ type: "array",
490
+ minItems: 2,
491
+ maxItems: 2,
492
+ items: { type: "string" }
493
+ },
494
+ shapeText: {
495
+ type: "object",
496
+ required: ["content"],
497
+ properties: {
498
+ content: { type: "string" },
499
+ defaultColor: { type: "string" },
500
+ defaultFontName: { type: "string" },
501
+ align: { type: "string" },
502
+ lineHeight: { type: "number" },
503
+ type: { type: "string" }
504
+ },
505
+ additionalProperties: true
506
+ },
507
+ clip: {
508
+ type: "object",
509
+ required: ["shape", "range"],
510
+ properties: {
511
+ shape: { type: "string" },
512
+ range: {
513
+ type: "array",
514
+ minItems: 2,
515
+ maxItems: 2,
516
+ items: {
517
+ $ref: "#/definitions/pair"
518
+ }
519
+ }
520
+ },
521
+ additionalProperties: true
522
+ },
523
+ filters: {
524
+ type: "object",
525
+ properties: {
526
+ opacity: {
527
+ oneOf: [
528
+ { type: "string" },
529
+ { type: "number" }
530
+ ]
531
+ },
532
+ grayscale: {
533
+ oneOf: [
534
+ { type: "string" },
535
+ { type: "number" }
536
+ ]
537
+ },
538
+ blur: {
539
+ oneOf: [
540
+ { type: "string" },
541
+ { type: "number" }
542
+ ]
543
+ },
544
+ sepia: {
545
+ oneOf: [
546
+ { type: "string" },
547
+ { type: "number" }
548
+ ]
549
+ },
550
+ saturate: {
551
+ oneOf: [
552
+ { type: "string" },
553
+ { type: "number" }
554
+ ]
555
+ }
556
+ },
557
+ additionalProperties: true
558
+ },
559
+ tableCellStyle: {
560
+ type: "object",
561
+ properties: {
562
+ fontname: { type: "string" },
563
+ color: { type: "string" },
564
+ align: { type: "string" },
565
+ fontsize: { type: "string" },
566
+ backcolor: { type: "string" }
567
+ },
568
+ additionalProperties: true
569
+ },
570
+ tableCell: {
571
+ type: "object",
572
+ properties: {
573
+ id: { type: "string" },
574
+ colspan: { type: "number" },
575
+ rowspan: { type: "number" },
576
+ text: { type: "string" },
577
+ style: { $ref: "#/definitions/tableCellStyle" }
578
+ },
579
+ additionalProperties: true
580
+ },
581
+ element: {
582
+ type: "object",
583
+ required: ["type"],
584
+ properties: {
585
+ type: { type: "string" },
586
+ id: { type: "string" },
587
+ groupId: { type: "string" },
588
+ left: { type: "number" },
589
+ top: { type: "number" },
590
+ width: { type: "number" },
591
+ height: { type: "number" },
592
+ rotate: { type: "number" },
593
+ lock: { type: "boolean" },
594
+ opacity: { type: "number" },
595
+ flipH: { type: "boolean" },
596
+ flipV: { type: "boolean" },
597
+ shadow: { $ref: "#/definitions/shadow" },
598
+ outline: { $ref: "#/definitions/outline" }
599
+ },
600
+ allOf: [
601
+ {
602
+ if: {
603
+ required: ["type"],
604
+ properties: {
605
+ type: { const: "text" }
606
+ }
607
+ },
608
+ then: {
609
+ required: ["content", "left", "top", "width", "height"],
610
+ properties: {
611
+ content: { type: "string" },
612
+ defaultColor: { type: "string" },
613
+ defaultFontName: { type: "string" },
614
+ fill: { type: "string" },
615
+ lineHeight: { type: "number" },
616
+ paragraphSpace: { type: "number" },
617
+ textType: { type: "string" },
618
+ vertical: { type: "boolean" },
619
+ wordSpace: { type: "number" }
620
+ }
621
+ }
622
+ },
623
+ {
624
+ if: {
625
+ required: ["type"],
626
+ properties: {
627
+ type: { const: "shape" }
628
+ }
629
+ },
630
+ then: {
631
+ required: [
632
+ "path",
633
+ "viewBox",
634
+ "fill",
635
+ "left",
636
+ "top",
637
+ "width",
638
+ "height"
639
+ ],
640
+ properties: {
641
+ path: { type: "string" },
642
+ viewBox: { $ref: "#/definitions/pair" },
643
+ fill: { type: "string" },
644
+ fixedRatio: { type: "boolean" },
645
+ keypoints: {
646
+ type: "array",
647
+ items: { type: "number" }
648
+ },
649
+ pathFormula: { type: "string" },
650
+ gradient: { $ref: "#/definitions/gradient" },
651
+ special: { type: "boolean" },
652
+ text: { $ref: "#/definitions/shapeText" }
653
+ }
654
+ }
655
+ },
656
+ {
657
+ if: {
658
+ required: ["type"],
659
+ properties: {
660
+ type: { const: "line" }
661
+ }
662
+ },
663
+ then: {
664
+ required: [
665
+ "start",
666
+ "end",
667
+ "points",
668
+ "color",
669
+ "width",
670
+ "left",
671
+ "top"
672
+ ],
673
+ properties: {
674
+ start: { $ref: "#/definitions/pair" },
675
+ end: { $ref: "#/definitions/pair" },
676
+ points: { $ref: "#/definitions/linePoints" },
677
+ broken: { $ref: "#/definitions/pair" },
678
+ color: { type: "string" },
679
+ style: { type: "string" },
680
+ width: { type: "number" }
681
+ }
682
+ }
683
+ },
684
+ {
685
+ if: {
686
+ required: ["type"],
687
+ properties: {
688
+ type: { const: "image" }
689
+ }
690
+ },
691
+ then: {
692
+ required: ["src", "left", "top", "width", "height"],
693
+ properties: {
694
+ src: { type: "string" },
695
+ fixedRatio: { type: "boolean" },
696
+ clip: { $ref: "#/definitions/clip" },
697
+ filters: { $ref: "#/definitions/filters" },
698
+ imageType: { type: "string" },
699
+ radius: { type: "number" },
700
+ colorMask: { type: "string" }
701
+ }
702
+ }
703
+ },
704
+ {
705
+ if: {
706
+ required: ["type"],
707
+ properties: {
708
+ type: { const: "table" }
709
+ }
710
+ },
711
+ then: {
712
+ required: ["left", "top", "width", "height"],
713
+ properties: {
714
+ colWidths: {
715
+ type: "array",
716
+ items: { type: "number" }
717
+ },
718
+ data: {
719
+ type: "array",
720
+ items: {
721
+ type: "array",
722
+ items: {
723
+ $ref: "#/definitions/tableCell"
724
+ }
725
+ }
726
+ },
727
+ cellMinHeight: { type: "number" }
728
+ }
729
+ }
730
+ }
731
+ ],
732
+ additionalProperties: true
733
+ },
734
+ slideBackground: {
735
+ type: "object",
736
+ properties: {
737
+ type: { type: "string" },
738
+ color: { type: "string" },
739
+ src: { type: "string" },
740
+ gradient: { $ref: "#/definitions/gradient" }
741
+ },
742
+ additionalProperties: true
743
+ },
744
+ slide: {
745
+ type: "object",
746
+ required: ["elements"],
747
+ properties: {
748
+ id: { type: "string" },
749
+ type: { type: "string" },
750
+ remark: { type: "string" },
751
+ background: { $ref: "#/definitions/slideBackground" },
752
+ elements: {
753
+ type: "array",
754
+ items: {
755
+ $ref: "#/definitions/element"
756
+ }
757
+ }
758
+ },
759
+ additionalProperties: true
760
+ }
761
+ }
762
+ };
763
+
764
+ // runtime/validate.ts
765
+ var ajv = new import_ajv.default({
766
+ allErrors: true,
767
+ strict: false,
768
+ allowUnionTypes: true
769
+ });
770
+ var validateV1 = ajv.compile(schema_default);
771
+ function mapError(error) {
772
+ return {
773
+ code: "SCHEMA_VALIDATION_ERROR",
774
+ path: error.instancePath || "/",
775
+ message: error.message ?? "Invalid value",
776
+ keyword: error.keyword,
777
+ params: error.params && typeof error.params === "object" ? error.params : void 0
778
+ };
779
+ }
780
+ function validateDocument(input) {
781
+ const valid = validateV1(input);
782
+ if (!valid) {
783
+ const issues = (validateV1.errors ?? []).map(mapError);
784
+ throw new SchemaValidationError(issues);
785
+ }
786
+ return input;
787
+ }
788
+
789
+ // runtime/parse.ts
790
+ function parseDocument(input) {
791
+ const migrated = migrateDocument(input);
792
+ const validated = validateDocument(migrated);
793
+ return normalizeDocument(validated);
794
+ }
795
+
796
+ // versions/v1/types.ts
797
+ var V1_SCHEMA_VERSION = "1.0.0";
798
+ // Annotate the CommonJS export names for ESM import in node:
799
+ 0 && (module.exports = {
800
+ DEFAULT_HEIGHT,
801
+ DEFAULT_SCHEMA_VERSION,
802
+ DEFAULT_SLIDE_REMARK,
803
+ DEFAULT_SLIDE_TYPE,
804
+ DEFAULT_THEME,
805
+ DEFAULT_THEME_OUTLINE,
806
+ DEFAULT_THEME_SHADOW,
807
+ DEFAULT_TITLE,
808
+ DEFAULT_WIDTH,
809
+ SchemaValidationError,
810
+ UnsupportedSchemaVersionError,
811
+ V1_DEFAULTS,
812
+ V1_SCHEMA_VERSION,
813
+ migrateDocument,
814
+ normalizeDocument,
815
+ parseDocument,
816
+ validateDocument
817
+ });
818
+ //# sourceMappingURL=index.js.map