json2pptx-schema 0.1.0 → 0.2.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 CHANGED
@@ -1,4 +1,4 @@
1
- # @json2pptx/schema
1
+ # json2pptx-schema
2
2
 
3
3
  Schema and parsing pipeline for json2pptx documents.
4
4
 
@@ -8,24 +8,38 @@ Schema and parsing pipeline for json2pptx documents.
8
8
  - `validateDocument(input)` (Ajv)
9
9
  - `normalizeDocument(input)`
10
10
  - `parseDocument(input)` -> `migrate -> validate -> normalize`
11
+ - explicit visual fill/background unions: `solid | gradient | image`
12
+ - legacy input compatibility through migration before validation
11
13
 
12
14
  ## Install
13
15
 
14
16
  ```bash
15
- npm i @json2pptx/schema
17
+ npm i json2pptx-schema
16
18
  ```
17
19
 
18
20
  ## Usage
19
21
 
20
22
  ```ts
21
- import { parseDocument } from '@json2pptx/schema'
22
-
23
- const doc = parseDocument(input)
23
+ import { parseDocument, type PresentationDocument } from 'json2pptx-schema'
24
+
25
+ const doc: PresentationDocument = parseDocument({
26
+ title: 'Demo',
27
+ width: 960,
28
+ height: 540,
29
+ slides: [
30
+ {
31
+ background: { type: 'solid', color: '#ffffff' },
32
+ elements: []
33
+ }
34
+ ]
35
+ })
24
36
  ```
25
37
 
38
+ `parseDocument` returns a normalized `PresentationDocument`, including normalized fill/background unions.
39
+
26
40
  ## Publish
27
41
 
28
42
  ```bash
29
- pnpm -C src/lib/schema build
30
- pnpm -C src/lib/schema publish --access public
43
+ pnpm -C src/lib/json2pptx-schema build
44
+ pnpm -C src/lib/json2pptx-schema publish --access public
31
45
  ```
package/dist/index.d.mts CHANGED
@@ -24,6 +24,40 @@ type V1Gradient = {
24
24
  colors: V1GradientStop[];
25
25
  [key: string]: unknown;
26
26
  };
27
+ type V1SolidFillInput = {
28
+ type?: 'solid';
29
+ color?: string;
30
+ [key: string]: unknown;
31
+ };
32
+ type V1SolidFill = {
33
+ type: 'solid';
34
+ color: string;
35
+ [key: string]: unknown;
36
+ };
37
+ type V1GradientFillInput = {
38
+ type: 'gradient';
39
+ gradient?: V1Gradient;
40
+ [key: string]: unknown;
41
+ };
42
+ type V1GradientFill = {
43
+ type: 'gradient';
44
+ gradient: V1Gradient;
45
+ [key: string]: unknown;
46
+ };
47
+ type V1ImageFillInput = {
48
+ type: 'image';
49
+ src?: string;
50
+ opacity?: number;
51
+ [key: string]: unknown;
52
+ };
53
+ type V1ImageFill = {
54
+ type: 'image';
55
+ src: string;
56
+ opacity?: number;
57
+ [key: string]: unknown;
58
+ };
59
+ type V1FillInput = V1SolidFillInput | V1GradientFillInput | V1ImageFillInput;
60
+ type V1Fill = V1SolidFill | V1GradientFill | V1ImageFill;
27
61
  type V1ThemeInput = {
28
62
  themeColors?: string[];
29
63
  fontColor?: string;
@@ -42,20 +76,8 @@ type V1Theme = {
42
76
  outline: V1Outline;
43
77
  [key: string]: unknown;
44
78
  };
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
- };
79
+ type V1SlideBackgroundInput = V1FillInput;
80
+ type V1SlideBackground = V1Fill;
59
81
  type V1ElementBaseInput<T extends string = string> = {
60
82
  type: T;
61
83
  id?: string;
@@ -92,7 +114,7 @@ type V1TextElementInput = V1ElementBaseInput<'text'> & {
92
114
  content?: string;
93
115
  defaultColor?: string;
94
116
  defaultFontName?: string;
95
- fill?: string;
117
+ fill?: V1FillInput;
96
118
  lineHeight?: number;
97
119
  paragraphSpace?: number;
98
120
  textType?: string;
@@ -105,7 +127,7 @@ type V1TextElement = V1ElementBase<'text'> & {
105
127
  content: string;
106
128
  defaultColor: string;
107
129
  defaultFontName: string;
108
- fill?: string;
130
+ fill?: V1Fill;
109
131
  lineHeight?: number;
110
132
  paragraphSpace?: number;
111
133
  textType?: string;
@@ -115,11 +137,10 @@ type V1TextElement = V1ElementBase<'text'> & {
115
137
  type V1ShapeElementInput = V1ElementBaseInput<'shape'> & {
116
138
  path?: string;
117
139
  viewBox?: [number, number];
118
- fill?: string;
140
+ fill?: V1FillInput;
119
141
  fixedRatio?: boolean;
120
142
  keypoints?: number[];
121
143
  pathFormula?: string;
122
- gradient?: V1Gradient;
123
144
  special?: boolean;
124
145
  text?: V1ShapeText;
125
146
  };
@@ -128,11 +149,10 @@ type V1ShapeElement = V1ElementBase<'shape'> & {
128
149
  height: number;
129
150
  path: string;
130
151
  viewBox: [number, number];
131
- fill: string;
152
+ fill: V1Fill;
132
153
  fixedRatio: boolean;
133
154
  keypoints?: number[];
134
155
  pathFormula?: string;
135
- gradient?: V1Gradient;
136
156
  special?: boolean;
137
157
  text?: V1ShapeText;
138
158
  };
@@ -226,8 +246,10 @@ type V1Document = {
226
246
  slides: V1Slide[];
227
247
  [key: string]: unknown;
228
248
  };
249
+ type PresentationDocumentInput = V1DocumentInput;
250
+ type PresentationDocument = V1Document;
229
251
 
230
- declare function parseDocument(input: unknown): V1Document;
252
+ declare function parseDocument(input: unknown): PresentationDocument;
231
253
 
232
254
  declare function migrateDocument(input: unknown, toVersion?: V1SchemaVersion): unknown;
233
255
 
@@ -266,4 +288,4 @@ declare const V1_DEFAULTS: Pick<V1Document, 'schemaVersion' | 'title' | 'width'
266
288
  theme: V1Theme;
267
289
  };
268
290
 
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 };
291
+ export { DEFAULT_HEIGHT, DEFAULT_SCHEMA_VERSION, DEFAULT_SLIDE_REMARK, DEFAULT_SLIDE_TYPE, DEFAULT_THEME, DEFAULT_THEME_OUTLINE, DEFAULT_THEME_SHADOW, DEFAULT_TITLE, DEFAULT_WIDTH, type PresentationDocument, type PresentationDocumentInput, SchemaValidationError, type SchemaValidationIssue, UnsupportedSchemaVersionError, type V1Document, type V1DocumentInput, type V1Element, type V1ElementInput, type V1Fill, type V1FillInput, 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 };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,40 @@ type V1Gradient = {
24
24
  colors: V1GradientStop[];
25
25
  [key: string]: unknown;
26
26
  };
27
+ type V1SolidFillInput = {
28
+ type?: 'solid';
29
+ color?: string;
30
+ [key: string]: unknown;
31
+ };
32
+ type V1SolidFill = {
33
+ type: 'solid';
34
+ color: string;
35
+ [key: string]: unknown;
36
+ };
37
+ type V1GradientFillInput = {
38
+ type: 'gradient';
39
+ gradient?: V1Gradient;
40
+ [key: string]: unknown;
41
+ };
42
+ type V1GradientFill = {
43
+ type: 'gradient';
44
+ gradient: V1Gradient;
45
+ [key: string]: unknown;
46
+ };
47
+ type V1ImageFillInput = {
48
+ type: 'image';
49
+ src?: string;
50
+ opacity?: number;
51
+ [key: string]: unknown;
52
+ };
53
+ type V1ImageFill = {
54
+ type: 'image';
55
+ src: string;
56
+ opacity?: number;
57
+ [key: string]: unknown;
58
+ };
59
+ type V1FillInput = V1SolidFillInput | V1GradientFillInput | V1ImageFillInput;
60
+ type V1Fill = V1SolidFill | V1GradientFill | V1ImageFill;
27
61
  type V1ThemeInput = {
28
62
  themeColors?: string[];
29
63
  fontColor?: string;
@@ -42,20 +76,8 @@ type V1Theme = {
42
76
  outline: V1Outline;
43
77
  [key: string]: unknown;
44
78
  };
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
- };
79
+ type V1SlideBackgroundInput = V1FillInput;
80
+ type V1SlideBackground = V1Fill;
59
81
  type V1ElementBaseInput<T extends string = string> = {
60
82
  type: T;
61
83
  id?: string;
@@ -92,7 +114,7 @@ type V1TextElementInput = V1ElementBaseInput<'text'> & {
92
114
  content?: string;
93
115
  defaultColor?: string;
94
116
  defaultFontName?: string;
95
- fill?: string;
117
+ fill?: V1FillInput;
96
118
  lineHeight?: number;
97
119
  paragraphSpace?: number;
98
120
  textType?: string;
@@ -105,7 +127,7 @@ type V1TextElement = V1ElementBase<'text'> & {
105
127
  content: string;
106
128
  defaultColor: string;
107
129
  defaultFontName: string;
108
- fill?: string;
130
+ fill?: V1Fill;
109
131
  lineHeight?: number;
110
132
  paragraphSpace?: number;
111
133
  textType?: string;
@@ -115,11 +137,10 @@ type V1TextElement = V1ElementBase<'text'> & {
115
137
  type V1ShapeElementInput = V1ElementBaseInput<'shape'> & {
116
138
  path?: string;
117
139
  viewBox?: [number, number];
118
- fill?: string;
140
+ fill?: V1FillInput;
119
141
  fixedRatio?: boolean;
120
142
  keypoints?: number[];
121
143
  pathFormula?: string;
122
- gradient?: V1Gradient;
123
144
  special?: boolean;
124
145
  text?: V1ShapeText;
125
146
  };
@@ -128,11 +149,10 @@ type V1ShapeElement = V1ElementBase<'shape'> & {
128
149
  height: number;
129
150
  path: string;
130
151
  viewBox: [number, number];
131
- fill: string;
152
+ fill: V1Fill;
132
153
  fixedRatio: boolean;
133
154
  keypoints?: number[];
134
155
  pathFormula?: string;
135
- gradient?: V1Gradient;
136
156
  special?: boolean;
137
157
  text?: V1ShapeText;
138
158
  };
@@ -226,8 +246,10 @@ type V1Document = {
226
246
  slides: V1Slide[];
227
247
  [key: string]: unknown;
228
248
  };
249
+ type PresentationDocumentInput = V1DocumentInput;
250
+ type PresentationDocument = V1Document;
229
251
 
230
- declare function parseDocument(input: unknown): V1Document;
252
+ declare function parseDocument(input: unknown): PresentationDocument;
231
253
 
232
254
  declare function migrateDocument(input: unknown, toVersion?: V1SchemaVersion): unknown;
233
255
 
@@ -266,4 +288,4 @@ declare const V1_DEFAULTS: Pick<V1Document, 'schemaVersion' | 'title' | 'width'
266
288
  theme: V1Theme;
267
289
  };
268
290
 
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 };
291
+ export { DEFAULT_HEIGHT, DEFAULT_SCHEMA_VERSION, DEFAULT_SLIDE_REMARK, DEFAULT_SLIDE_TYPE, DEFAULT_THEME, DEFAULT_THEME_OUTLINE, DEFAULT_THEME_SHADOW, DEFAULT_TITLE, DEFAULT_WIDTH, type PresentationDocument, type PresentationDocumentInput, SchemaValidationError, type SchemaValidationIssue, UnsupportedSchemaVersionError, type V1Document, type V1DocumentInput, type V1Element, type V1ElementInput, type V1Fill, type V1FillInput, 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 };