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/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @json2pptx/schema
2
+
3
+ Schema and parsing pipeline for json2pptx documents.
4
+
5
+ ## Features
6
+
7
+ - `migrateDocument(input)`
8
+ - `validateDocument(input)` (Ajv)
9
+ - `normalizeDocument(input)`
10
+ - `parseDocument(input)` -> `migrate -> validate -> normalize`
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm i @json2pptx/schema
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ import { parseDocument } from '@json2pptx/schema'
22
+
23
+ const doc = parseDocument(input)
24
+ ```
25
+
26
+ ## Publish
27
+
28
+ ```bash
29
+ pnpm -C src/lib/schema build
30
+ pnpm -C src/lib/schema publish --access public
31
+ ```
@@ -0,0 +1,269 @@
1
+ declare const V1_SCHEMA_VERSION: "1.0.0";
2
+ type V1SchemaVersion = typeof V1_SCHEMA_VERSION;
3
+ type V1Outline = {
4
+ width: number;
5
+ color: string;
6
+ style: string;
7
+ [key: string]: unknown;
8
+ };
9
+ type V1Shadow = {
10
+ h: number;
11
+ v: number;
12
+ blur: number;
13
+ color: string;
14
+ [key: string]: unknown;
15
+ };
16
+ type V1GradientStop = {
17
+ pos: number;
18
+ color: string;
19
+ [key: string]: unknown;
20
+ };
21
+ type V1Gradient = {
22
+ type: string;
23
+ rotate: number;
24
+ colors: V1GradientStop[];
25
+ [key: string]: unknown;
26
+ };
27
+ type V1ThemeInput = {
28
+ themeColors?: string[];
29
+ fontColor?: string;
30
+ fontName?: string;
31
+ backgroundColor?: string;
32
+ shadow?: Partial<V1Shadow>;
33
+ outline?: Partial<V1Outline>;
34
+ [key: string]: unknown;
35
+ };
36
+ type V1Theme = {
37
+ themeColors: string[];
38
+ fontColor: string;
39
+ fontName: string;
40
+ backgroundColor: string;
41
+ shadow: V1Shadow;
42
+ outline: V1Outline;
43
+ [key: string]: unknown;
44
+ };
45
+ type V1SlideBackgroundInput = {
46
+ type?: string;
47
+ color?: string;
48
+ src?: string;
49
+ gradient?: V1Gradient;
50
+ [key: string]: unknown;
51
+ };
52
+ type V1SlideBackground = {
53
+ type: string;
54
+ color?: string;
55
+ src?: string;
56
+ gradient?: V1Gradient;
57
+ [key: string]: unknown;
58
+ };
59
+ type V1ElementBaseInput<T extends string = string> = {
60
+ type: T;
61
+ id?: string;
62
+ groupId?: string;
63
+ left?: number;
64
+ top?: number;
65
+ width?: number;
66
+ height?: number;
67
+ rotate?: number;
68
+ lock?: boolean;
69
+ opacity?: number;
70
+ flipH?: boolean;
71
+ flipV?: boolean;
72
+ outline?: Partial<V1Outline>;
73
+ shadow?: Partial<V1Shadow>;
74
+ [key: string]: unknown;
75
+ };
76
+ type V1ElementBase<T extends string = string> = V1ElementBaseInput<T> & {
77
+ id: string;
78
+ left: number;
79
+ top: number;
80
+ rotate: number;
81
+ };
82
+ type V1ShapeText = {
83
+ content: string;
84
+ defaultColor?: string;
85
+ defaultFontName?: string;
86
+ align?: string;
87
+ lineHeight?: number;
88
+ type?: string;
89
+ [key: string]: unknown;
90
+ };
91
+ type V1TextElementInput = V1ElementBaseInput<'text'> & {
92
+ content?: string;
93
+ defaultColor?: string;
94
+ defaultFontName?: string;
95
+ fill?: string;
96
+ lineHeight?: number;
97
+ paragraphSpace?: number;
98
+ textType?: string;
99
+ vertical?: boolean;
100
+ wordSpace?: number;
101
+ };
102
+ type V1TextElement = V1ElementBase<'text'> & {
103
+ width: number;
104
+ height: number;
105
+ content: string;
106
+ defaultColor: string;
107
+ defaultFontName: string;
108
+ fill?: string;
109
+ lineHeight?: number;
110
+ paragraphSpace?: number;
111
+ textType?: string;
112
+ vertical: boolean;
113
+ wordSpace?: number;
114
+ };
115
+ type V1ShapeElementInput = V1ElementBaseInput<'shape'> & {
116
+ path?: string;
117
+ viewBox?: [number, number];
118
+ fill?: string;
119
+ fixedRatio?: boolean;
120
+ keypoints?: number[];
121
+ pathFormula?: string;
122
+ gradient?: V1Gradient;
123
+ special?: boolean;
124
+ text?: V1ShapeText;
125
+ };
126
+ type V1ShapeElement = V1ElementBase<'shape'> & {
127
+ width: number;
128
+ height: number;
129
+ path: string;
130
+ viewBox: [number, number];
131
+ fill: string;
132
+ fixedRatio: boolean;
133
+ keypoints?: number[];
134
+ pathFormula?: string;
135
+ gradient?: V1Gradient;
136
+ special?: boolean;
137
+ text?: V1ShapeText;
138
+ };
139
+ type V1LineElementInput = V1ElementBaseInput<'line'> & {
140
+ start?: [number, number];
141
+ end?: [number, number];
142
+ points?: string[];
143
+ broken?: [number, number];
144
+ color?: string;
145
+ style?: string;
146
+ width?: number;
147
+ };
148
+ type V1LineElement = V1ElementBase<'line'> & {
149
+ start: [number, number];
150
+ end: [number, number];
151
+ points: [string, string];
152
+ broken?: [number, number];
153
+ color: string;
154
+ style: string;
155
+ width: number;
156
+ };
157
+ type V1ImageClip = {
158
+ shape: string;
159
+ range: [[number, number], [number, number]];
160
+ [key: string]: unknown;
161
+ };
162
+ type V1ImageFilters = {
163
+ opacity?: string | number;
164
+ grayscale?: string | number;
165
+ blur?: string | number;
166
+ sepia?: string | number;
167
+ saturate?: string | number;
168
+ [key: string]: unknown;
169
+ };
170
+ type V1ImageElementInput = V1ElementBaseInput<'image'> & {
171
+ src?: string;
172
+ fixedRatio?: boolean;
173
+ clip?: V1ImageClip;
174
+ filters?: V1ImageFilters;
175
+ imageType?: string;
176
+ radius?: number;
177
+ colorMask?: string;
178
+ };
179
+ type V1ImageElement = V1ElementBase<'image'> & {
180
+ width: number;
181
+ height: number;
182
+ src: string;
183
+ fixedRatio: boolean;
184
+ clip?: V1ImageClip;
185
+ filters?: V1ImageFilters;
186
+ imageType?: string;
187
+ radius?: number;
188
+ colorMask?: string;
189
+ };
190
+ type V1UnknownElementInput = V1ElementBaseInput<string>;
191
+ type V1UnknownElement = V1ElementBase<string>;
192
+ type V1ElementInput = V1TextElementInput | V1ShapeElementInput | V1LineElementInput | V1ImageElementInput | V1UnknownElementInput;
193
+ type V1Element = V1TextElement | V1ShapeElement | V1LineElement | V1ImageElement | V1UnknownElement;
194
+ type V1SlideInput = {
195
+ id?: string;
196
+ type?: string;
197
+ remark?: string;
198
+ background?: V1SlideBackgroundInput;
199
+ elements?: V1ElementInput[];
200
+ [key: string]: unknown;
201
+ };
202
+ type V1Slide = {
203
+ id: string;
204
+ type: string;
205
+ remark: string;
206
+ background?: V1SlideBackground;
207
+ elements: V1Element[];
208
+ [key: string]: unknown;
209
+ };
210
+ type V1DocumentInput = {
211
+ schemaVersion?: string;
212
+ version?: string | number;
213
+ title?: string;
214
+ width?: number;
215
+ height?: number;
216
+ theme?: V1ThemeInput;
217
+ slides: V1SlideInput[];
218
+ [key: string]: unknown;
219
+ };
220
+ type V1Document = {
221
+ schemaVersion: V1SchemaVersion;
222
+ title: string;
223
+ width: number;
224
+ height: number;
225
+ theme: V1Theme;
226
+ slides: V1Slide[];
227
+ [key: string]: unknown;
228
+ };
229
+
230
+ declare function parseDocument(input: unknown): V1Document;
231
+
232
+ declare function migrateDocument(input: unknown, toVersion?: V1SchemaVersion): unknown;
233
+
234
+ declare function validateDocument(input: unknown): V1DocumentInput;
235
+
236
+ declare function normalizeDocument(input: V1DocumentInput): V1Document;
237
+
238
+ type SchemaValidationIssue = {
239
+ code: string;
240
+ path: string;
241
+ message: string;
242
+ keyword?: string;
243
+ params?: Record<string, unknown>;
244
+ };
245
+ declare class SchemaValidationError extends Error {
246
+ readonly issues: SchemaValidationIssue[];
247
+ constructor(issues: SchemaValidationIssue[], message?: string);
248
+ }
249
+ declare class UnsupportedSchemaVersionError extends Error {
250
+ readonly code = "UNSUPPORTED_SCHEMA_VERSION";
251
+ readonly supportedVersion: string;
252
+ readonly receivedVersion?: string;
253
+ constructor(receivedVersion: unknown, supportedVersion: string);
254
+ }
255
+
256
+ declare const DEFAULT_SCHEMA_VERSION: V1SchemaVersion;
257
+ declare const DEFAULT_TITLE = "\u672A\u547D\u540D\u6F14\u793A\u6587\u7A3F";
258
+ declare const DEFAULT_WIDTH = 1000;
259
+ declare const DEFAULT_HEIGHT = 562.5;
260
+ declare const DEFAULT_THEME_SHADOW: V1Shadow;
261
+ declare const DEFAULT_THEME_OUTLINE: V1Outline;
262
+ declare const DEFAULT_THEME: V1Theme;
263
+ declare const DEFAULT_SLIDE_TYPE = "content";
264
+ declare const DEFAULT_SLIDE_REMARK = "";
265
+ declare const V1_DEFAULTS: Pick<V1Document, 'schemaVersion' | 'title' | 'width' | 'height'> & {
266
+ theme: V1Theme;
267
+ };
268
+
269
+ export { DEFAULT_HEIGHT, DEFAULT_SCHEMA_VERSION, DEFAULT_SLIDE_REMARK, DEFAULT_SLIDE_TYPE, DEFAULT_THEME, DEFAULT_THEME_OUTLINE, DEFAULT_THEME_SHADOW, DEFAULT_TITLE, DEFAULT_WIDTH, SchemaValidationError, type SchemaValidationIssue, UnsupportedSchemaVersionError, type V1Document, type V1DocumentInput, type V1Element, type V1ElementInput, type V1Gradient, type V1ImageElement, type V1LineElement, type V1Outline, type V1SchemaVersion, type V1Shadow, type V1ShapeElement, type V1Slide, type V1SlideBackground, type V1SlideInput, type V1TextElement, type V1Theme, type V1ThemeInput, V1_DEFAULTS, V1_SCHEMA_VERSION, migrateDocument, normalizeDocument, parseDocument, validateDocument };
@@ -0,0 +1,269 @@
1
+ declare const V1_SCHEMA_VERSION: "1.0.0";
2
+ type V1SchemaVersion = typeof V1_SCHEMA_VERSION;
3
+ type V1Outline = {
4
+ width: number;
5
+ color: string;
6
+ style: string;
7
+ [key: string]: unknown;
8
+ };
9
+ type V1Shadow = {
10
+ h: number;
11
+ v: number;
12
+ blur: number;
13
+ color: string;
14
+ [key: string]: unknown;
15
+ };
16
+ type V1GradientStop = {
17
+ pos: number;
18
+ color: string;
19
+ [key: string]: unknown;
20
+ };
21
+ type V1Gradient = {
22
+ type: string;
23
+ rotate: number;
24
+ colors: V1GradientStop[];
25
+ [key: string]: unknown;
26
+ };
27
+ type V1ThemeInput = {
28
+ themeColors?: string[];
29
+ fontColor?: string;
30
+ fontName?: string;
31
+ backgroundColor?: string;
32
+ shadow?: Partial<V1Shadow>;
33
+ outline?: Partial<V1Outline>;
34
+ [key: string]: unknown;
35
+ };
36
+ type V1Theme = {
37
+ themeColors: string[];
38
+ fontColor: string;
39
+ fontName: string;
40
+ backgroundColor: string;
41
+ shadow: V1Shadow;
42
+ outline: V1Outline;
43
+ [key: string]: unknown;
44
+ };
45
+ type V1SlideBackgroundInput = {
46
+ type?: string;
47
+ color?: string;
48
+ src?: string;
49
+ gradient?: V1Gradient;
50
+ [key: string]: unknown;
51
+ };
52
+ type V1SlideBackground = {
53
+ type: string;
54
+ color?: string;
55
+ src?: string;
56
+ gradient?: V1Gradient;
57
+ [key: string]: unknown;
58
+ };
59
+ type V1ElementBaseInput<T extends string = string> = {
60
+ type: T;
61
+ id?: string;
62
+ groupId?: string;
63
+ left?: number;
64
+ top?: number;
65
+ width?: number;
66
+ height?: number;
67
+ rotate?: number;
68
+ lock?: boolean;
69
+ opacity?: number;
70
+ flipH?: boolean;
71
+ flipV?: boolean;
72
+ outline?: Partial<V1Outline>;
73
+ shadow?: Partial<V1Shadow>;
74
+ [key: string]: unknown;
75
+ };
76
+ type V1ElementBase<T extends string = string> = V1ElementBaseInput<T> & {
77
+ id: string;
78
+ left: number;
79
+ top: number;
80
+ rotate: number;
81
+ };
82
+ type V1ShapeText = {
83
+ content: string;
84
+ defaultColor?: string;
85
+ defaultFontName?: string;
86
+ align?: string;
87
+ lineHeight?: number;
88
+ type?: string;
89
+ [key: string]: unknown;
90
+ };
91
+ type V1TextElementInput = V1ElementBaseInput<'text'> & {
92
+ content?: string;
93
+ defaultColor?: string;
94
+ defaultFontName?: string;
95
+ fill?: string;
96
+ lineHeight?: number;
97
+ paragraphSpace?: number;
98
+ textType?: string;
99
+ vertical?: boolean;
100
+ wordSpace?: number;
101
+ };
102
+ type V1TextElement = V1ElementBase<'text'> & {
103
+ width: number;
104
+ height: number;
105
+ content: string;
106
+ defaultColor: string;
107
+ defaultFontName: string;
108
+ fill?: string;
109
+ lineHeight?: number;
110
+ paragraphSpace?: number;
111
+ textType?: string;
112
+ vertical: boolean;
113
+ wordSpace?: number;
114
+ };
115
+ type V1ShapeElementInput = V1ElementBaseInput<'shape'> & {
116
+ path?: string;
117
+ viewBox?: [number, number];
118
+ fill?: string;
119
+ fixedRatio?: boolean;
120
+ keypoints?: number[];
121
+ pathFormula?: string;
122
+ gradient?: V1Gradient;
123
+ special?: boolean;
124
+ text?: V1ShapeText;
125
+ };
126
+ type V1ShapeElement = V1ElementBase<'shape'> & {
127
+ width: number;
128
+ height: number;
129
+ path: string;
130
+ viewBox: [number, number];
131
+ fill: string;
132
+ fixedRatio: boolean;
133
+ keypoints?: number[];
134
+ pathFormula?: string;
135
+ gradient?: V1Gradient;
136
+ special?: boolean;
137
+ text?: V1ShapeText;
138
+ };
139
+ type V1LineElementInput = V1ElementBaseInput<'line'> & {
140
+ start?: [number, number];
141
+ end?: [number, number];
142
+ points?: string[];
143
+ broken?: [number, number];
144
+ color?: string;
145
+ style?: string;
146
+ width?: number;
147
+ };
148
+ type V1LineElement = V1ElementBase<'line'> & {
149
+ start: [number, number];
150
+ end: [number, number];
151
+ points: [string, string];
152
+ broken?: [number, number];
153
+ color: string;
154
+ style: string;
155
+ width: number;
156
+ };
157
+ type V1ImageClip = {
158
+ shape: string;
159
+ range: [[number, number], [number, number]];
160
+ [key: string]: unknown;
161
+ };
162
+ type V1ImageFilters = {
163
+ opacity?: string | number;
164
+ grayscale?: string | number;
165
+ blur?: string | number;
166
+ sepia?: string | number;
167
+ saturate?: string | number;
168
+ [key: string]: unknown;
169
+ };
170
+ type V1ImageElementInput = V1ElementBaseInput<'image'> & {
171
+ src?: string;
172
+ fixedRatio?: boolean;
173
+ clip?: V1ImageClip;
174
+ filters?: V1ImageFilters;
175
+ imageType?: string;
176
+ radius?: number;
177
+ colorMask?: string;
178
+ };
179
+ type V1ImageElement = V1ElementBase<'image'> & {
180
+ width: number;
181
+ height: number;
182
+ src: string;
183
+ fixedRatio: boolean;
184
+ clip?: V1ImageClip;
185
+ filters?: V1ImageFilters;
186
+ imageType?: string;
187
+ radius?: number;
188
+ colorMask?: string;
189
+ };
190
+ type V1UnknownElementInput = V1ElementBaseInput<string>;
191
+ type V1UnknownElement = V1ElementBase<string>;
192
+ type V1ElementInput = V1TextElementInput | V1ShapeElementInput | V1LineElementInput | V1ImageElementInput | V1UnknownElementInput;
193
+ type V1Element = V1TextElement | V1ShapeElement | V1LineElement | V1ImageElement | V1UnknownElement;
194
+ type V1SlideInput = {
195
+ id?: string;
196
+ type?: string;
197
+ remark?: string;
198
+ background?: V1SlideBackgroundInput;
199
+ elements?: V1ElementInput[];
200
+ [key: string]: unknown;
201
+ };
202
+ type V1Slide = {
203
+ id: string;
204
+ type: string;
205
+ remark: string;
206
+ background?: V1SlideBackground;
207
+ elements: V1Element[];
208
+ [key: string]: unknown;
209
+ };
210
+ type V1DocumentInput = {
211
+ schemaVersion?: string;
212
+ version?: string | number;
213
+ title?: string;
214
+ width?: number;
215
+ height?: number;
216
+ theme?: V1ThemeInput;
217
+ slides: V1SlideInput[];
218
+ [key: string]: unknown;
219
+ };
220
+ type V1Document = {
221
+ schemaVersion: V1SchemaVersion;
222
+ title: string;
223
+ width: number;
224
+ height: number;
225
+ theme: V1Theme;
226
+ slides: V1Slide[];
227
+ [key: string]: unknown;
228
+ };
229
+
230
+ declare function parseDocument(input: unknown): V1Document;
231
+
232
+ declare function migrateDocument(input: unknown, toVersion?: V1SchemaVersion): unknown;
233
+
234
+ declare function validateDocument(input: unknown): V1DocumentInput;
235
+
236
+ declare function normalizeDocument(input: V1DocumentInput): V1Document;
237
+
238
+ type SchemaValidationIssue = {
239
+ code: string;
240
+ path: string;
241
+ message: string;
242
+ keyword?: string;
243
+ params?: Record<string, unknown>;
244
+ };
245
+ declare class SchemaValidationError extends Error {
246
+ readonly issues: SchemaValidationIssue[];
247
+ constructor(issues: SchemaValidationIssue[], message?: string);
248
+ }
249
+ declare class UnsupportedSchemaVersionError extends Error {
250
+ readonly code = "UNSUPPORTED_SCHEMA_VERSION";
251
+ readonly supportedVersion: string;
252
+ readonly receivedVersion?: string;
253
+ constructor(receivedVersion: unknown, supportedVersion: string);
254
+ }
255
+
256
+ declare const DEFAULT_SCHEMA_VERSION: V1SchemaVersion;
257
+ declare const DEFAULT_TITLE = "\u672A\u547D\u540D\u6F14\u793A\u6587\u7A3F";
258
+ declare const DEFAULT_WIDTH = 1000;
259
+ declare const DEFAULT_HEIGHT = 562.5;
260
+ declare const DEFAULT_THEME_SHADOW: V1Shadow;
261
+ declare const DEFAULT_THEME_OUTLINE: V1Outline;
262
+ declare const DEFAULT_THEME: V1Theme;
263
+ declare const DEFAULT_SLIDE_TYPE = "content";
264
+ declare const DEFAULT_SLIDE_REMARK = "";
265
+ declare const V1_DEFAULTS: Pick<V1Document, 'schemaVersion' | 'title' | 'width' | 'height'> & {
266
+ theme: V1Theme;
267
+ };
268
+
269
+ export { DEFAULT_HEIGHT, DEFAULT_SCHEMA_VERSION, DEFAULT_SLIDE_REMARK, DEFAULT_SLIDE_TYPE, DEFAULT_THEME, DEFAULT_THEME_OUTLINE, DEFAULT_THEME_SHADOW, DEFAULT_TITLE, DEFAULT_WIDTH, SchemaValidationError, type SchemaValidationIssue, UnsupportedSchemaVersionError, type V1Document, type V1DocumentInput, type V1Element, type V1ElementInput, type V1Gradient, type V1ImageElement, type V1LineElement, type V1Outline, type V1SchemaVersion, type V1Shadow, type V1ShapeElement, type V1Slide, type V1SlideBackground, type V1SlideInput, type V1TextElement, type V1Theme, type V1ThemeInput, V1_DEFAULTS, V1_SCHEMA_VERSION, migrateDocument, normalizeDocument, parseDocument, validateDocument };