modern-idoc 0.2.2 → 0.2.4
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.cjs +71 -13
- package/dist/index.d.cts +44 -42
- package/dist/index.d.mts +44 -42
- package/dist/index.d.ts +44 -42
- package/dist/index.js +1 -1
- package/dist/index.mjs +67 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -49,10 +49,6 @@ function getDefaultLayoutStyle() {
|
|
|
49
49
|
|
|
50
50
|
function getDefaultShadowStyle() {
|
|
51
51
|
return {
|
|
52
|
-
shadowColor: "transparent",
|
|
53
|
-
shadowOffsetX: 0,
|
|
54
|
-
shadowOffsetY: 0,
|
|
55
|
-
shadowBlur: 0,
|
|
56
52
|
boxShadow: "none"
|
|
57
53
|
};
|
|
58
54
|
}
|
|
@@ -136,11 +132,55 @@ function getDefaultStyle() {
|
|
|
136
132
|
};
|
|
137
133
|
}
|
|
138
134
|
|
|
135
|
+
function clearUndef(obj, deep = false) {
|
|
136
|
+
if (typeof obj !== "object" || !obj) {
|
|
137
|
+
return obj;
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(obj)) {
|
|
140
|
+
if (deep) {
|
|
141
|
+
return obj.map((v) => clearUndef(v, deep));
|
|
142
|
+
} else {
|
|
143
|
+
return obj;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const newObj = {};
|
|
147
|
+
for (const key in obj) {
|
|
148
|
+
const value = obj[key];
|
|
149
|
+
if (value === void 0 || value === null) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (deep) {
|
|
153
|
+
newObj[key] = clearUndef(value, deep);
|
|
154
|
+
} else {
|
|
155
|
+
newObj[key] = value;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return newObj;
|
|
159
|
+
}
|
|
160
|
+
function deepClearUndef(obj) {
|
|
161
|
+
return clearUndef(obj, true);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function normalizeAudio(audio) {
|
|
165
|
+
if (!audio || audio === "none") {
|
|
166
|
+
return void 0;
|
|
167
|
+
} else if (typeof audio === "string") {
|
|
168
|
+
return {
|
|
169
|
+
url: audio
|
|
170
|
+
};
|
|
171
|
+
} else {
|
|
172
|
+
return {
|
|
173
|
+
...audio
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
139
178
|
function normalizeFill(fill) {
|
|
140
179
|
if (!fill || fill === "none") {
|
|
141
180
|
return void 0;
|
|
142
181
|
} else if (typeof fill === "string") {
|
|
143
182
|
return {
|
|
183
|
+
type: "color",
|
|
144
184
|
color: fill
|
|
145
185
|
};
|
|
146
186
|
} else {
|
|
@@ -185,15 +225,27 @@ function normalizeImage(image) {
|
|
|
185
225
|
}
|
|
186
226
|
}
|
|
187
227
|
|
|
188
|
-
function
|
|
189
|
-
if (!
|
|
228
|
+
function normalizeOutline(outline) {
|
|
229
|
+
if (!outline || outline === "none") {
|
|
190
230
|
return void 0;
|
|
191
|
-
} else if (typeof
|
|
231
|
+
} else if (typeof outline === "string") {
|
|
192
232
|
return {
|
|
193
|
-
color:
|
|
233
|
+
color: outline
|
|
194
234
|
};
|
|
195
235
|
} else {
|
|
196
|
-
return
|
|
236
|
+
return outline;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function normalizeShadow(shadow) {
|
|
241
|
+
if (!shadow || shadow === "none") {
|
|
242
|
+
return void 0;
|
|
243
|
+
} else if (typeof shadow === "string") {
|
|
244
|
+
return {
|
|
245
|
+
color: shadow
|
|
246
|
+
};
|
|
247
|
+
} else {
|
|
248
|
+
return shadow;
|
|
197
249
|
}
|
|
198
250
|
}
|
|
199
251
|
|
|
@@ -277,28 +329,34 @@ function normalizeVideo(video) {
|
|
|
277
329
|
}
|
|
278
330
|
|
|
279
331
|
function normalizeElement(element) {
|
|
280
|
-
return {
|
|
332
|
+
return clearUndef({
|
|
281
333
|
...element,
|
|
282
334
|
image: normalizeImage(element.image),
|
|
283
335
|
video: normalizeVideo(element.video),
|
|
336
|
+
audio: normalizeAudio(element.audio),
|
|
284
337
|
text: normalizeText(element.text),
|
|
285
338
|
geometry: normalizeGeometry(element.geometry),
|
|
286
339
|
fill: normalizeFill(element.fill),
|
|
287
|
-
|
|
340
|
+
outline: normalizeOutline(element.outline),
|
|
341
|
+
shadow: normalizeShadow(element.shadow),
|
|
288
342
|
children: element.children?.map((child) => normalizeElement(child))
|
|
289
|
-
};
|
|
343
|
+
});
|
|
290
344
|
}
|
|
291
345
|
|
|
346
|
+
exports.clearUndef = clearUndef;
|
|
347
|
+
exports.deepClearUndef = deepClearUndef;
|
|
292
348
|
exports.getDefaultElementStyle = getDefaultElementStyle;
|
|
293
349
|
exports.getDefaultShadowStyle = getDefaultShadowStyle;
|
|
294
350
|
exports.getDefaultStyle = getDefaultStyle;
|
|
295
351
|
exports.getDefaultTextStyle = getDefaultTextStyle;
|
|
296
352
|
exports.getDefaultTransformStyle = getDefaultTransformStyle;
|
|
353
|
+
exports.normalizeAudio = normalizeAudio;
|
|
297
354
|
exports.normalizeElement = normalizeElement;
|
|
298
355
|
exports.normalizeFill = normalizeFill;
|
|
299
356
|
exports.normalizeGeometry = normalizeGeometry;
|
|
300
357
|
exports.normalizeImage = normalizeImage;
|
|
301
|
-
exports.
|
|
358
|
+
exports.normalizeOutline = normalizeOutline;
|
|
359
|
+
exports.normalizeShadow = normalizeShadow;
|
|
302
360
|
exports.normalizeText = normalizeText;
|
|
303
361
|
exports.normalizeTextContent = normalizeTextContent;
|
|
304
362
|
exports.normalizeVideo = normalizeVideo;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
type Noneable = 'none';
|
|
2
|
+
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
3
|
+
|
|
4
|
+
interface AudioDeclaration {
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
type AudioProp = Noneable | string | AudioDeclaration;
|
|
8
|
+
|
|
1
9
|
interface ImageFillRect {
|
|
2
10
|
left?: number;
|
|
3
11
|
top?: number;
|
|
@@ -16,7 +24,8 @@ interface CommonFillDeclaration {
|
|
|
16
24
|
opacity?: number;
|
|
17
25
|
}
|
|
18
26
|
interface ImageFillDeclaration extends CommonFillDeclaration {
|
|
19
|
-
image
|
|
27
|
+
type: 'image';
|
|
28
|
+
image: string;
|
|
20
29
|
dpi?: number;
|
|
21
30
|
rotateWithShape?: boolean;
|
|
22
31
|
srcRect?: ImageFillRect;
|
|
@@ -24,10 +33,11 @@ interface ImageFillDeclaration extends CommonFillDeclaration {
|
|
|
24
33
|
tile?: ImageFillTile;
|
|
25
34
|
}
|
|
26
35
|
interface ColorFillDeclaration extends CommonFillDeclaration {
|
|
27
|
-
color
|
|
28
|
-
|
|
29
|
-
interface FillDeclaration extends ImageFillDeclaration, ColorFillDeclaration {
|
|
36
|
+
type: 'color';
|
|
37
|
+
color: string;
|
|
30
38
|
}
|
|
39
|
+
type FillDeclaration = ImageFillDeclaration | ColorFillDeclaration;
|
|
40
|
+
type FillProp = Noneable | string | FillDeclaration;
|
|
31
41
|
|
|
32
42
|
type SVGPathData = string;
|
|
33
43
|
type FillRule = 'nonzero' | 'evenodd';
|
|
@@ -59,12 +69,6 @@ interface Path2DDeclaration extends Partial<Path2DStyle> {
|
|
|
59
69
|
interface GeometryDeclaration {
|
|
60
70
|
data: Path2DDeclaration[];
|
|
61
71
|
}
|
|
62
|
-
|
|
63
|
-
type Noneable = 'none';
|
|
64
|
-
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
65
|
-
|
|
66
|
-
type FillProp = Noneable | string | FillDeclaration;
|
|
67
|
-
|
|
68
72
|
type GeometryProp = Noneable | SVGPathData | SVGPathData[] | Path2DDeclaration[] | GeometryDeclaration;
|
|
69
73
|
|
|
70
74
|
interface MetaProp {
|
|
@@ -81,18 +85,27 @@ interface ImageDeclaration {
|
|
|
81
85
|
url: string;
|
|
82
86
|
opacity?: number;
|
|
83
87
|
}
|
|
84
|
-
|
|
85
88
|
type ImageProp = Noneable | string | ImageDeclaration;
|
|
86
89
|
|
|
87
|
-
interface
|
|
90
|
+
interface OutlineDeclaration {
|
|
88
91
|
width?: number;
|
|
89
92
|
style?: 'dashed' | 'solid' | string;
|
|
90
93
|
image?: string;
|
|
91
94
|
color?: string;
|
|
92
95
|
opacity?: number;
|
|
93
96
|
}
|
|
97
|
+
type OutlineProp = Noneable | string | Partial<OutlineDeclaration>;
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
interface ShadowDeclaration {
|
|
100
|
+
color: string;
|
|
101
|
+
offsetX?: number;
|
|
102
|
+
offsetY?: number;
|
|
103
|
+
blur?: number;
|
|
104
|
+
}
|
|
105
|
+
type ShadowProp = Noneable | string | ShadowDeclaration;
|
|
106
|
+
interface ShadowStyleDeclaration {
|
|
107
|
+
boxShadow: Noneable | string;
|
|
108
|
+
}
|
|
96
109
|
|
|
97
110
|
type Overflow = 'hidden' | 'visible';
|
|
98
111
|
type Visibility = 'hidden' | 'visible';
|
|
@@ -169,22 +182,6 @@ interface LayoutStyleDeclaration {
|
|
|
169
182
|
width: number | 'auto' | `${number}%`;
|
|
170
183
|
}
|
|
171
184
|
|
|
172
|
-
interface ShadowDeclaration {
|
|
173
|
-
color: string;
|
|
174
|
-
offsetX: number;
|
|
175
|
-
offsetY: number;
|
|
176
|
-
blur: number;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
interface ShadowStyleDeclaration {
|
|
180
|
-
shadow?: Partial<ShadowDeclaration>;
|
|
181
|
-
shadowColor: string;
|
|
182
|
-
shadowOffsetX: number;
|
|
183
|
-
shadowOffsetY: number;
|
|
184
|
-
shadowBlur: number;
|
|
185
|
-
boxShadow: 'none' | string;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
185
|
interface TransformStyleDeclaration {
|
|
189
186
|
rotate: number;
|
|
190
187
|
scaleX: number;
|
|
@@ -215,7 +212,6 @@ interface HighlightDeclaration {
|
|
|
215
212
|
size: HighlightSize;
|
|
216
213
|
thickness: HighlightThickness;
|
|
217
214
|
}
|
|
218
|
-
|
|
219
215
|
interface HighlightStyleDeclaration {
|
|
220
216
|
highlight?: Partial<HighlightDeclaration>;
|
|
221
217
|
highlightImage: HighlightImage;
|
|
@@ -233,7 +229,6 @@ interface ListStyleDeclaration {
|
|
|
233
229
|
size: ListStyleSize;
|
|
234
230
|
position: ListStylePosition;
|
|
235
231
|
}
|
|
236
|
-
|
|
237
232
|
interface ListStyleStyleDeclaration {
|
|
238
233
|
listStyle?: Partial<ListStyleDeclaration>;
|
|
239
234
|
listStyleType: ListStyleType;
|
|
@@ -275,7 +270,6 @@ interface TextStyleDeclaration extends TextLineStyleDeclaration, TextInlineStyle
|
|
|
275
270
|
|
|
276
271
|
interface StyleDeclaration extends TextStyleDeclaration, ElementStyleDeclaration {
|
|
277
272
|
}
|
|
278
|
-
|
|
279
273
|
type StyleProp = Partial<StyleDeclaration>;
|
|
280
274
|
|
|
281
275
|
interface FragmentContent extends Partial<StyleDeclaration> {
|
|
@@ -293,7 +287,6 @@ interface TextDeclaration {
|
|
|
293
287
|
measureDom?: any;
|
|
294
288
|
fonts?: any;
|
|
295
289
|
}
|
|
296
|
-
|
|
297
290
|
type TextProp = string | TextContent | (TextDeclaration & {
|
|
298
291
|
content: TextContent;
|
|
299
292
|
}) | TextDeclaration;
|
|
@@ -302,28 +295,30 @@ interface VideoDeclaration {
|
|
|
302
295
|
url: string;
|
|
303
296
|
opacity?: number;
|
|
304
297
|
}
|
|
305
|
-
|
|
306
298
|
type VideoProp = Noneable | string | VideoDeclaration;
|
|
307
299
|
|
|
308
300
|
interface IDOCElement extends IDOCNode {
|
|
309
301
|
style?: StyleProp;
|
|
310
302
|
image?: ImageProp;
|
|
311
303
|
video?: VideoProp;
|
|
304
|
+
audio?: AudioProp;
|
|
312
305
|
text?: TextProp;
|
|
313
306
|
geometry?: GeometryProp;
|
|
314
307
|
fill?: FillProp;
|
|
315
|
-
|
|
308
|
+
outline?: OutlineProp;
|
|
309
|
+
shadow?: ShadowProp;
|
|
316
310
|
children?: IDOCElement[];
|
|
317
311
|
}
|
|
318
|
-
|
|
319
|
-
interface ElementDeclaration extends IDOCElement {
|
|
312
|
+
interface IDOCElementDeclaration extends IDOCElement {
|
|
320
313
|
image?: ImageDeclaration;
|
|
321
314
|
video?: VideoDeclaration;
|
|
315
|
+
audio?: AudioDeclaration;
|
|
322
316
|
text?: TextDeclaration;
|
|
323
317
|
geometry?: GeometryDeclaration;
|
|
324
318
|
fill?: FillDeclaration;
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
outline?: OutlineDeclaration;
|
|
320
|
+
shadow?: ShadowDeclaration;
|
|
321
|
+
children?: IDOCElementDeclaration[];
|
|
327
322
|
}
|
|
328
323
|
|
|
329
324
|
interface IDOCDocument extends IDOCElement {
|
|
@@ -340,7 +335,12 @@ declare function getDefaultTextStyle(): TextStyleDeclaration;
|
|
|
340
335
|
|
|
341
336
|
declare function getDefaultTransformStyle(): TransformStyleDeclaration;
|
|
342
337
|
|
|
343
|
-
declare function
|
|
338
|
+
declare function clearUndef<T>(obj: T, deep?: boolean): T;
|
|
339
|
+
declare function deepClearUndef<T>(obj: T): T;
|
|
340
|
+
|
|
341
|
+
declare function normalizeAudio(audio?: AudioProp): AudioDeclaration | undefined;
|
|
342
|
+
|
|
343
|
+
declare function normalizeElement(element: IDOCElement): IDOCElementDeclaration;
|
|
344
344
|
|
|
345
345
|
declare function normalizeFill(fill?: FillProp): FillDeclaration | undefined;
|
|
346
346
|
|
|
@@ -348,7 +348,9 @@ declare function normalizeGeometry(geometry?: GeometryProp): GeometryDeclaration
|
|
|
348
348
|
|
|
349
349
|
declare function normalizeImage(image?: ImageProp): ImageDeclaration | undefined;
|
|
350
350
|
|
|
351
|
-
declare function
|
|
351
|
+
declare function normalizeOutline(outline?: OutlineProp): OutlineDeclaration | undefined;
|
|
352
|
+
|
|
353
|
+
declare function normalizeShadow(shadow?: ShadowProp): ShadowDeclaration | undefined;
|
|
352
354
|
|
|
353
355
|
declare function normalizeText(text?: TextProp): TextDeclaration | undefined;
|
|
354
356
|
|
|
@@ -356,4 +358,4 @@ declare function normalizeTextContent(content?: TextContent): TextContentDeclara
|
|
|
356
358
|
|
|
357
359
|
declare function normalizeVideo(video?: VideoProp): VideoDeclaration | undefined;
|
|
358
360
|
|
|
359
|
-
export { type
|
|
361
|
+
export { type Align, type AudioDeclaration, type AudioProp, type BoxSizing, type ColorFillDeclaration, type CommonFillDeclaration, type ElementStyleDeclaration, type FillDeclaration, type FillProp, type FillRule, type FlexDirection, type FlexWrap, type FontKerning, type FontStyle, type FontWeight, type FragmentContent, type GeometryDeclaration, type GeometryProp, type HighlightColormap, type HighlightDeclaration, type HighlightImage, type HighlightLine, type HighlightReferImage, type HighlightSize, type HighlightStyleDeclaration, type HighlightThickness, type IDOCDocument, type IDOCElement, type IDOCElementDeclaration, type IDOCNode, type ImageDeclaration, type ImageFillDeclaration, type ImageFillRect, type ImageFillTile, type ImageProp, type Justify, type LayoutStyleDeclaration, type ListStyleColormap, type ListStyleDeclaration, type ListStyleImage, type ListStylePosition, type ListStyleSize, type ListStyleStyleDeclaration, type ListStyleType, type MetaProp, type OutlineDeclaration, type OutlineProp, type Overflow, type ParagraphContent, type Path2DDeclaration, type Path2DStyle, type Position, type SVGPathData, type ShadowDeclaration, type ShadowProp, type ShadowStyleDeclaration, type StrokeLinecap, type StrokeLinejoin, type StyleDeclaration, type StyleProp, type TextAlign, type TextContent, type TextContentDeclaration, type TextContentFlat, type TextDeclaration, type TextDecoration, type TextDrawStyleDeclaration, type TextInlineStyleDeclaration, type TextLineStyleDeclaration, type TextOrientation, type TextProp, type TextStyleDeclaration, type TextTransform, type TextWrap, type TransformStyleDeclaration, type VerticalAlign, type VideoDeclaration, type VideoProp, type Visibility, type WritingMode, clearUndef, deepClearUndef, getDefaultElementStyle, getDefaultShadowStyle, getDefaultStyle, getDefaultTextStyle, getDefaultTransformStyle, normalizeAudio, normalizeElement, normalizeFill, normalizeGeometry, normalizeImage, normalizeOutline, normalizeShadow, normalizeText, normalizeTextContent, normalizeVideo };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
type Noneable = 'none';
|
|
2
|
+
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
3
|
+
|
|
4
|
+
interface AudioDeclaration {
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
type AudioProp = Noneable | string | AudioDeclaration;
|
|
8
|
+
|
|
1
9
|
interface ImageFillRect {
|
|
2
10
|
left?: number;
|
|
3
11
|
top?: number;
|
|
@@ -16,7 +24,8 @@ interface CommonFillDeclaration {
|
|
|
16
24
|
opacity?: number;
|
|
17
25
|
}
|
|
18
26
|
interface ImageFillDeclaration extends CommonFillDeclaration {
|
|
19
|
-
image
|
|
27
|
+
type: 'image';
|
|
28
|
+
image: string;
|
|
20
29
|
dpi?: number;
|
|
21
30
|
rotateWithShape?: boolean;
|
|
22
31
|
srcRect?: ImageFillRect;
|
|
@@ -24,10 +33,11 @@ interface ImageFillDeclaration extends CommonFillDeclaration {
|
|
|
24
33
|
tile?: ImageFillTile;
|
|
25
34
|
}
|
|
26
35
|
interface ColorFillDeclaration extends CommonFillDeclaration {
|
|
27
|
-
color
|
|
28
|
-
|
|
29
|
-
interface FillDeclaration extends ImageFillDeclaration, ColorFillDeclaration {
|
|
36
|
+
type: 'color';
|
|
37
|
+
color: string;
|
|
30
38
|
}
|
|
39
|
+
type FillDeclaration = ImageFillDeclaration | ColorFillDeclaration;
|
|
40
|
+
type FillProp = Noneable | string | FillDeclaration;
|
|
31
41
|
|
|
32
42
|
type SVGPathData = string;
|
|
33
43
|
type FillRule = 'nonzero' | 'evenodd';
|
|
@@ -59,12 +69,6 @@ interface Path2DDeclaration extends Partial<Path2DStyle> {
|
|
|
59
69
|
interface GeometryDeclaration {
|
|
60
70
|
data: Path2DDeclaration[];
|
|
61
71
|
}
|
|
62
|
-
|
|
63
|
-
type Noneable = 'none';
|
|
64
|
-
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
65
|
-
|
|
66
|
-
type FillProp = Noneable | string | FillDeclaration;
|
|
67
|
-
|
|
68
72
|
type GeometryProp = Noneable | SVGPathData | SVGPathData[] | Path2DDeclaration[] | GeometryDeclaration;
|
|
69
73
|
|
|
70
74
|
interface MetaProp {
|
|
@@ -81,18 +85,27 @@ interface ImageDeclaration {
|
|
|
81
85
|
url: string;
|
|
82
86
|
opacity?: number;
|
|
83
87
|
}
|
|
84
|
-
|
|
85
88
|
type ImageProp = Noneable | string | ImageDeclaration;
|
|
86
89
|
|
|
87
|
-
interface
|
|
90
|
+
interface OutlineDeclaration {
|
|
88
91
|
width?: number;
|
|
89
92
|
style?: 'dashed' | 'solid' | string;
|
|
90
93
|
image?: string;
|
|
91
94
|
color?: string;
|
|
92
95
|
opacity?: number;
|
|
93
96
|
}
|
|
97
|
+
type OutlineProp = Noneable | string | Partial<OutlineDeclaration>;
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
interface ShadowDeclaration {
|
|
100
|
+
color: string;
|
|
101
|
+
offsetX?: number;
|
|
102
|
+
offsetY?: number;
|
|
103
|
+
blur?: number;
|
|
104
|
+
}
|
|
105
|
+
type ShadowProp = Noneable | string | ShadowDeclaration;
|
|
106
|
+
interface ShadowStyleDeclaration {
|
|
107
|
+
boxShadow: Noneable | string;
|
|
108
|
+
}
|
|
96
109
|
|
|
97
110
|
type Overflow = 'hidden' | 'visible';
|
|
98
111
|
type Visibility = 'hidden' | 'visible';
|
|
@@ -169,22 +182,6 @@ interface LayoutStyleDeclaration {
|
|
|
169
182
|
width: number | 'auto' | `${number}%`;
|
|
170
183
|
}
|
|
171
184
|
|
|
172
|
-
interface ShadowDeclaration {
|
|
173
|
-
color: string;
|
|
174
|
-
offsetX: number;
|
|
175
|
-
offsetY: number;
|
|
176
|
-
blur: number;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
interface ShadowStyleDeclaration {
|
|
180
|
-
shadow?: Partial<ShadowDeclaration>;
|
|
181
|
-
shadowColor: string;
|
|
182
|
-
shadowOffsetX: number;
|
|
183
|
-
shadowOffsetY: number;
|
|
184
|
-
shadowBlur: number;
|
|
185
|
-
boxShadow: 'none' | string;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
185
|
interface TransformStyleDeclaration {
|
|
189
186
|
rotate: number;
|
|
190
187
|
scaleX: number;
|
|
@@ -215,7 +212,6 @@ interface HighlightDeclaration {
|
|
|
215
212
|
size: HighlightSize;
|
|
216
213
|
thickness: HighlightThickness;
|
|
217
214
|
}
|
|
218
|
-
|
|
219
215
|
interface HighlightStyleDeclaration {
|
|
220
216
|
highlight?: Partial<HighlightDeclaration>;
|
|
221
217
|
highlightImage: HighlightImage;
|
|
@@ -233,7 +229,6 @@ interface ListStyleDeclaration {
|
|
|
233
229
|
size: ListStyleSize;
|
|
234
230
|
position: ListStylePosition;
|
|
235
231
|
}
|
|
236
|
-
|
|
237
232
|
interface ListStyleStyleDeclaration {
|
|
238
233
|
listStyle?: Partial<ListStyleDeclaration>;
|
|
239
234
|
listStyleType: ListStyleType;
|
|
@@ -275,7 +270,6 @@ interface TextStyleDeclaration extends TextLineStyleDeclaration, TextInlineStyle
|
|
|
275
270
|
|
|
276
271
|
interface StyleDeclaration extends TextStyleDeclaration, ElementStyleDeclaration {
|
|
277
272
|
}
|
|
278
|
-
|
|
279
273
|
type StyleProp = Partial<StyleDeclaration>;
|
|
280
274
|
|
|
281
275
|
interface FragmentContent extends Partial<StyleDeclaration> {
|
|
@@ -293,7 +287,6 @@ interface TextDeclaration {
|
|
|
293
287
|
measureDom?: any;
|
|
294
288
|
fonts?: any;
|
|
295
289
|
}
|
|
296
|
-
|
|
297
290
|
type TextProp = string | TextContent | (TextDeclaration & {
|
|
298
291
|
content: TextContent;
|
|
299
292
|
}) | TextDeclaration;
|
|
@@ -302,28 +295,30 @@ interface VideoDeclaration {
|
|
|
302
295
|
url: string;
|
|
303
296
|
opacity?: number;
|
|
304
297
|
}
|
|
305
|
-
|
|
306
298
|
type VideoProp = Noneable | string | VideoDeclaration;
|
|
307
299
|
|
|
308
300
|
interface IDOCElement extends IDOCNode {
|
|
309
301
|
style?: StyleProp;
|
|
310
302
|
image?: ImageProp;
|
|
311
303
|
video?: VideoProp;
|
|
304
|
+
audio?: AudioProp;
|
|
312
305
|
text?: TextProp;
|
|
313
306
|
geometry?: GeometryProp;
|
|
314
307
|
fill?: FillProp;
|
|
315
|
-
|
|
308
|
+
outline?: OutlineProp;
|
|
309
|
+
shadow?: ShadowProp;
|
|
316
310
|
children?: IDOCElement[];
|
|
317
311
|
}
|
|
318
|
-
|
|
319
|
-
interface ElementDeclaration extends IDOCElement {
|
|
312
|
+
interface IDOCElementDeclaration extends IDOCElement {
|
|
320
313
|
image?: ImageDeclaration;
|
|
321
314
|
video?: VideoDeclaration;
|
|
315
|
+
audio?: AudioDeclaration;
|
|
322
316
|
text?: TextDeclaration;
|
|
323
317
|
geometry?: GeometryDeclaration;
|
|
324
318
|
fill?: FillDeclaration;
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
outline?: OutlineDeclaration;
|
|
320
|
+
shadow?: ShadowDeclaration;
|
|
321
|
+
children?: IDOCElementDeclaration[];
|
|
327
322
|
}
|
|
328
323
|
|
|
329
324
|
interface IDOCDocument extends IDOCElement {
|
|
@@ -340,7 +335,12 @@ declare function getDefaultTextStyle(): TextStyleDeclaration;
|
|
|
340
335
|
|
|
341
336
|
declare function getDefaultTransformStyle(): TransformStyleDeclaration;
|
|
342
337
|
|
|
343
|
-
declare function
|
|
338
|
+
declare function clearUndef<T>(obj: T, deep?: boolean): T;
|
|
339
|
+
declare function deepClearUndef<T>(obj: T): T;
|
|
340
|
+
|
|
341
|
+
declare function normalizeAudio(audio?: AudioProp): AudioDeclaration | undefined;
|
|
342
|
+
|
|
343
|
+
declare function normalizeElement(element: IDOCElement): IDOCElementDeclaration;
|
|
344
344
|
|
|
345
345
|
declare function normalizeFill(fill?: FillProp): FillDeclaration | undefined;
|
|
346
346
|
|
|
@@ -348,7 +348,9 @@ declare function normalizeGeometry(geometry?: GeometryProp): GeometryDeclaration
|
|
|
348
348
|
|
|
349
349
|
declare function normalizeImage(image?: ImageProp): ImageDeclaration | undefined;
|
|
350
350
|
|
|
351
|
-
declare function
|
|
351
|
+
declare function normalizeOutline(outline?: OutlineProp): OutlineDeclaration | undefined;
|
|
352
|
+
|
|
353
|
+
declare function normalizeShadow(shadow?: ShadowProp): ShadowDeclaration | undefined;
|
|
352
354
|
|
|
353
355
|
declare function normalizeText(text?: TextProp): TextDeclaration | undefined;
|
|
354
356
|
|
|
@@ -356,4 +358,4 @@ declare function normalizeTextContent(content?: TextContent): TextContentDeclara
|
|
|
356
358
|
|
|
357
359
|
declare function normalizeVideo(video?: VideoProp): VideoDeclaration | undefined;
|
|
358
360
|
|
|
359
|
-
export { type
|
|
361
|
+
export { type Align, type AudioDeclaration, type AudioProp, type BoxSizing, type ColorFillDeclaration, type CommonFillDeclaration, type ElementStyleDeclaration, type FillDeclaration, type FillProp, type FillRule, type FlexDirection, type FlexWrap, type FontKerning, type FontStyle, type FontWeight, type FragmentContent, type GeometryDeclaration, type GeometryProp, type HighlightColormap, type HighlightDeclaration, type HighlightImage, type HighlightLine, type HighlightReferImage, type HighlightSize, type HighlightStyleDeclaration, type HighlightThickness, type IDOCDocument, type IDOCElement, type IDOCElementDeclaration, type IDOCNode, type ImageDeclaration, type ImageFillDeclaration, type ImageFillRect, type ImageFillTile, type ImageProp, type Justify, type LayoutStyleDeclaration, type ListStyleColormap, type ListStyleDeclaration, type ListStyleImage, type ListStylePosition, type ListStyleSize, type ListStyleStyleDeclaration, type ListStyleType, type MetaProp, type OutlineDeclaration, type OutlineProp, type Overflow, type ParagraphContent, type Path2DDeclaration, type Path2DStyle, type Position, type SVGPathData, type ShadowDeclaration, type ShadowProp, type ShadowStyleDeclaration, type StrokeLinecap, type StrokeLinejoin, type StyleDeclaration, type StyleProp, type TextAlign, type TextContent, type TextContentDeclaration, type TextContentFlat, type TextDeclaration, type TextDecoration, type TextDrawStyleDeclaration, type TextInlineStyleDeclaration, type TextLineStyleDeclaration, type TextOrientation, type TextProp, type TextStyleDeclaration, type TextTransform, type TextWrap, type TransformStyleDeclaration, type VerticalAlign, type VideoDeclaration, type VideoProp, type Visibility, type WritingMode, clearUndef, deepClearUndef, getDefaultElementStyle, getDefaultShadowStyle, getDefaultStyle, getDefaultTextStyle, getDefaultTransformStyle, normalizeAudio, normalizeElement, normalizeFill, normalizeGeometry, normalizeImage, normalizeOutline, normalizeShadow, normalizeText, normalizeTextContent, normalizeVideo };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
type Noneable = 'none';
|
|
2
|
+
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
3
|
+
|
|
4
|
+
interface AudioDeclaration {
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
type AudioProp = Noneable | string | AudioDeclaration;
|
|
8
|
+
|
|
1
9
|
interface ImageFillRect {
|
|
2
10
|
left?: number;
|
|
3
11
|
top?: number;
|
|
@@ -16,7 +24,8 @@ interface CommonFillDeclaration {
|
|
|
16
24
|
opacity?: number;
|
|
17
25
|
}
|
|
18
26
|
interface ImageFillDeclaration extends CommonFillDeclaration {
|
|
19
|
-
image
|
|
27
|
+
type: 'image';
|
|
28
|
+
image: string;
|
|
20
29
|
dpi?: number;
|
|
21
30
|
rotateWithShape?: boolean;
|
|
22
31
|
srcRect?: ImageFillRect;
|
|
@@ -24,10 +33,11 @@ interface ImageFillDeclaration extends CommonFillDeclaration {
|
|
|
24
33
|
tile?: ImageFillTile;
|
|
25
34
|
}
|
|
26
35
|
interface ColorFillDeclaration extends CommonFillDeclaration {
|
|
27
|
-
color
|
|
28
|
-
|
|
29
|
-
interface FillDeclaration extends ImageFillDeclaration, ColorFillDeclaration {
|
|
36
|
+
type: 'color';
|
|
37
|
+
color: string;
|
|
30
38
|
}
|
|
39
|
+
type FillDeclaration = ImageFillDeclaration | ColorFillDeclaration;
|
|
40
|
+
type FillProp = Noneable | string | FillDeclaration;
|
|
31
41
|
|
|
32
42
|
type SVGPathData = string;
|
|
33
43
|
type FillRule = 'nonzero' | 'evenodd';
|
|
@@ -59,12 +69,6 @@ interface Path2DDeclaration extends Partial<Path2DStyle> {
|
|
|
59
69
|
interface GeometryDeclaration {
|
|
60
70
|
data: Path2DDeclaration[];
|
|
61
71
|
}
|
|
62
|
-
|
|
63
|
-
type Noneable = 'none';
|
|
64
|
-
type Sizeable = `${number}%` | `${number}rem` | number;
|
|
65
|
-
|
|
66
|
-
type FillProp = Noneable | string | FillDeclaration;
|
|
67
|
-
|
|
68
72
|
type GeometryProp = Noneable | SVGPathData | SVGPathData[] | Path2DDeclaration[] | GeometryDeclaration;
|
|
69
73
|
|
|
70
74
|
interface MetaProp {
|
|
@@ -81,18 +85,27 @@ interface ImageDeclaration {
|
|
|
81
85
|
url: string;
|
|
82
86
|
opacity?: number;
|
|
83
87
|
}
|
|
84
|
-
|
|
85
88
|
type ImageProp = Noneable | string | ImageDeclaration;
|
|
86
89
|
|
|
87
|
-
interface
|
|
90
|
+
interface OutlineDeclaration {
|
|
88
91
|
width?: number;
|
|
89
92
|
style?: 'dashed' | 'solid' | string;
|
|
90
93
|
image?: string;
|
|
91
94
|
color?: string;
|
|
92
95
|
opacity?: number;
|
|
93
96
|
}
|
|
97
|
+
type OutlineProp = Noneable | string | Partial<OutlineDeclaration>;
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
interface ShadowDeclaration {
|
|
100
|
+
color: string;
|
|
101
|
+
offsetX?: number;
|
|
102
|
+
offsetY?: number;
|
|
103
|
+
blur?: number;
|
|
104
|
+
}
|
|
105
|
+
type ShadowProp = Noneable | string | ShadowDeclaration;
|
|
106
|
+
interface ShadowStyleDeclaration {
|
|
107
|
+
boxShadow: Noneable | string;
|
|
108
|
+
}
|
|
96
109
|
|
|
97
110
|
type Overflow = 'hidden' | 'visible';
|
|
98
111
|
type Visibility = 'hidden' | 'visible';
|
|
@@ -169,22 +182,6 @@ interface LayoutStyleDeclaration {
|
|
|
169
182
|
width: number | 'auto' | `${number}%`;
|
|
170
183
|
}
|
|
171
184
|
|
|
172
|
-
interface ShadowDeclaration {
|
|
173
|
-
color: string;
|
|
174
|
-
offsetX: number;
|
|
175
|
-
offsetY: number;
|
|
176
|
-
blur: number;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
interface ShadowStyleDeclaration {
|
|
180
|
-
shadow?: Partial<ShadowDeclaration>;
|
|
181
|
-
shadowColor: string;
|
|
182
|
-
shadowOffsetX: number;
|
|
183
|
-
shadowOffsetY: number;
|
|
184
|
-
shadowBlur: number;
|
|
185
|
-
boxShadow: 'none' | string;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
185
|
interface TransformStyleDeclaration {
|
|
189
186
|
rotate: number;
|
|
190
187
|
scaleX: number;
|
|
@@ -215,7 +212,6 @@ interface HighlightDeclaration {
|
|
|
215
212
|
size: HighlightSize;
|
|
216
213
|
thickness: HighlightThickness;
|
|
217
214
|
}
|
|
218
|
-
|
|
219
215
|
interface HighlightStyleDeclaration {
|
|
220
216
|
highlight?: Partial<HighlightDeclaration>;
|
|
221
217
|
highlightImage: HighlightImage;
|
|
@@ -233,7 +229,6 @@ interface ListStyleDeclaration {
|
|
|
233
229
|
size: ListStyleSize;
|
|
234
230
|
position: ListStylePosition;
|
|
235
231
|
}
|
|
236
|
-
|
|
237
232
|
interface ListStyleStyleDeclaration {
|
|
238
233
|
listStyle?: Partial<ListStyleDeclaration>;
|
|
239
234
|
listStyleType: ListStyleType;
|
|
@@ -275,7 +270,6 @@ interface TextStyleDeclaration extends TextLineStyleDeclaration, TextInlineStyle
|
|
|
275
270
|
|
|
276
271
|
interface StyleDeclaration extends TextStyleDeclaration, ElementStyleDeclaration {
|
|
277
272
|
}
|
|
278
|
-
|
|
279
273
|
type StyleProp = Partial<StyleDeclaration>;
|
|
280
274
|
|
|
281
275
|
interface FragmentContent extends Partial<StyleDeclaration> {
|
|
@@ -293,7 +287,6 @@ interface TextDeclaration {
|
|
|
293
287
|
measureDom?: any;
|
|
294
288
|
fonts?: any;
|
|
295
289
|
}
|
|
296
|
-
|
|
297
290
|
type TextProp = string | TextContent | (TextDeclaration & {
|
|
298
291
|
content: TextContent;
|
|
299
292
|
}) | TextDeclaration;
|
|
@@ -302,28 +295,30 @@ interface VideoDeclaration {
|
|
|
302
295
|
url: string;
|
|
303
296
|
opacity?: number;
|
|
304
297
|
}
|
|
305
|
-
|
|
306
298
|
type VideoProp = Noneable | string | VideoDeclaration;
|
|
307
299
|
|
|
308
300
|
interface IDOCElement extends IDOCNode {
|
|
309
301
|
style?: StyleProp;
|
|
310
302
|
image?: ImageProp;
|
|
311
303
|
video?: VideoProp;
|
|
304
|
+
audio?: AudioProp;
|
|
312
305
|
text?: TextProp;
|
|
313
306
|
geometry?: GeometryProp;
|
|
314
307
|
fill?: FillProp;
|
|
315
|
-
|
|
308
|
+
outline?: OutlineProp;
|
|
309
|
+
shadow?: ShadowProp;
|
|
316
310
|
children?: IDOCElement[];
|
|
317
311
|
}
|
|
318
|
-
|
|
319
|
-
interface ElementDeclaration extends IDOCElement {
|
|
312
|
+
interface IDOCElementDeclaration extends IDOCElement {
|
|
320
313
|
image?: ImageDeclaration;
|
|
321
314
|
video?: VideoDeclaration;
|
|
315
|
+
audio?: AudioDeclaration;
|
|
322
316
|
text?: TextDeclaration;
|
|
323
317
|
geometry?: GeometryDeclaration;
|
|
324
318
|
fill?: FillDeclaration;
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
outline?: OutlineDeclaration;
|
|
320
|
+
shadow?: ShadowDeclaration;
|
|
321
|
+
children?: IDOCElementDeclaration[];
|
|
327
322
|
}
|
|
328
323
|
|
|
329
324
|
interface IDOCDocument extends IDOCElement {
|
|
@@ -340,7 +335,12 @@ declare function getDefaultTextStyle(): TextStyleDeclaration;
|
|
|
340
335
|
|
|
341
336
|
declare function getDefaultTransformStyle(): TransformStyleDeclaration;
|
|
342
337
|
|
|
343
|
-
declare function
|
|
338
|
+
declare function clearUndef<T>(obj: T, deep?: boolean): T;
|
|
339
|
+
declare function deepClearUndef<T>(obj: T): T;
|
|
340
|
+
|
|
341
|
+
declare function normalizeAudio(audio?: AudioProp): AudioDeclaration | undefined;
|
|
342
|
+
|
|
343
|
+
declare function normalizeElement(element: IDOCElement): IDOCElementDeclaration;
|
|
344
344
|
|
|
345
345
|
declare function normalizeFill(fill?: FillProp): FillDeclaration | undefined;
|
|
346
346
|
|
|
@@ -348,7 +348,9 @@ declare function normalizeGeometry(geometry?: GeometryProp): GeometryDeclaration
|
|
|
348
348
|
|
|
349
349
|
declare function normalizeImage(image?: ImageProp): ImageDeclaration | undefined;
|
|
350
350
|
|
|
351
|
-
declare function
|
|
351
|
+
declare function normalizeOutline(outline?: OutlineProp): OutlineDeclaration | undefined;
|
|
352
|
+
|
|
353
|
+
declare function normalizeShadow(shadow?: ShadowProp): ShadowDeclaration | undefined;
|
|
352
354
|
|
|
353
355
|
declare function normalizeText(text?: TextProp): TextDeclaration | undefined;
|
|
354
356
|
|
|
@@ -356,4 +358,4 @@ declare function normalizeTextContent(content?: TextContent): TextContentDeclara
|
|
|
356
358
|
|
|
357
359
|
declare function normalizeVideo(video?: VideoProp): VideoDeclaration | undefined;
|
|
358
360
|
|
|
359
|
-
export { type
|
|
361
|
+
export { type Align, type AudioDeclaration, type AudioProp, type BoxSizing, type ColorFillDeclaration, type CommonFillDeclaration, type ElementStyleDeclaration, type FillDeclaration, type FillProp, type FillRule, type FlexDirection, type FlexWrap, type FontKerning, type FontStyle, type FontWeight, type FragmentContent, type GeometryDeclaration, type GeometryProp, type HighlightColormap, type HighlightDeclaration, type HighlightImage, type HighlightLine, type HighlightReferImage, type HighlightSize, type HighlightStyleDeclaration, type HighlightThickness, type IDOCDocument, type IDOCElement, type IDOCElementDeclaration, type IDOCNode, type ImageDeclaration, type ImageFillDeclaration, type ImageFillRect, type ImageFillTile, type ImageProp, type Justify, type LayoutStyleDeclaration, type ListStyleColormap, type ListStyleDeclaration, type ListStyleImage, type ListStylePosition, type ListStyleSize, type ListStyleStyleDeclaration, type ListStyleType, type MetaProp, type OutlineDeclaration, type OutlineProp, type Overflow, type ParagraphContent, type Path2DDeclaration, type Path2DStyle, type Position, type SVGPathData, type ShadowDeclaration, type ShadowProp, type ShadowStyleDeclaration, type StrokeLinecap, type StrokeLinejoin, type StyleDeclaration, type StyleProp, type TextAlign, type TextContent, type TextContentDeclaration, type TextContentFlat, type TextDeclaration, type TextDecoration, type TextDrawStyleDeclaration, type TextInlineStyleDeclaration, type TextLineStyleDeclaration, type TextOrientation, type TextProp, type TextStyleDeclaration, type TextTransform, type TextWrap, type TransformStyleDeclaration, type VerticalAlign, type VideoDeclaration, type VideoProp, type Visibility, type WritingMode, clearUndef, deepClearUndef, getDefaultElementStyle, getDefaultShadowStyle, getDefaultStyle, getDefaultTextStyle, getDefaultTransformStyle, normalizeAudio, normalizeElement, normalizeFill, normalizeGeometry, normalizeImage, normalizeOutline, normalizeShadow, normalizeText, normalizeTextContent, normalizeVideo };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(n,
|
|
1
|
+
(function(n,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(n=typeof globalThis<"u"?globalThis:n||self,o(n.modernIdoc={}))})(this,function(n){"use strict";function o(){return{overflow:"visible",alignContent:"stretch",alignItems:"stretch",alignSelf:"auto",borderTop:"none",borderLeft:"none",borderRight:"none",borderBottom:"none",borderWidth:0,border:"none",direction:"inherit",display:"flex",flex:0,flexBasis:"auto",flexDirection:"row",flexGrow:0,flexShrink:1,flexWrap:"nowrap",height:"auto",justifyContent:"flex-start",gap:0,marginTop:0,marginLeft:0,marginRight:0,marginBottom:0,margin:0,maxHeight:0,maxWidth:0,minHeight:0,minWidth:0,paddingTop:0,paddingLeft:0,paddingRight:0,paddingBottom:0,padding:0,top:0,bottom:0,left:0,right:0,position:"static",boxSizing:"content-box",width:"auto"}}function u(){return{boxShadow:"none"}}function s(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function g(){return{...s(),...o(),...u(),visibility:"visible",filter:"none",opacity:1,backgroundImage:"none",backgroundColor:"transparent",borderRadius:0,borderColor:"transparent"}}function c(){return{writingMode:"horizontal-tb",verticalAlign:"baseline",lineHeight:1.2,letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:"normal",fontFamily:"",fontStyle:"normal",fontKerning:"normal",textWrap:"wrap",textAlign:"start",textIndent:0,textTransform:"none",textOrientation:"mixed",textDecoration:"none",textStrokeWidth:0,textStrokeColor:"black",color:"black",listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside",highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function v(){return{...g(),...c()}}function l(e,r=!1){if(typeof e!="object"||!e)return e;if(Array.isArray(e))return r?e.map(i=>l(i,r)):e;const t={};for(const i in e){const a=e[i];a!=null&&(r?t[i]=l(a,r):t[i]=a)}return t}function w(e){return l(e,!0)}function d(e){if(!(!e||e==="none"))return typeof e=="string"?{url:e}:{...e}}function m(e){if(!(!e||e==="none"))return typeof e=="string"?{type:"color",color:e}:e}function y(e){if(!(!e||e==="none"))return typeof e=="string"?{data:[{data:e}]}:Array.isArray(e)?{data:e.map(r=>typeof r=="string"?{data:r}:r)}:e}function h(e){if(!(!e||e==="none"))return typeof e=="string"?{url:e}:e}function S(e){if(!(!e||e==="none"))return typeof e=="string"?{color:e}:e}function p(e){if(!(!e||e==="none"))return typeof e=="string"?{color:e}:e}function f(e=""){return(Array.isArray(e)?e:[e]).map(t=>typeof t=="string"?{fragments:[{content:t}]}:"content"in t?{fragments:[{...t}]}:"fragments"in t?{...t,fragments:t.fragments.map(i=>({...i}))}:Array.isArray(t)?{fragments:t.map(i=>typeof i=="string"?{content:i}:{...i})}:{fragments:[]})}function z(e){if(!(!e||e==="none"))return typeof e=="string"?{content:[{fragments:[{content:e}]}]}:"content"in e?{...e,content:f(e.content)}:{content:f(e)}}function b(e){if(!(!e||e==="none"))return typeof e=="string"?{url:e}:{...e}}function T(e){var r;return l({...e,image:h(e.image),video:b(e.video),audio:d(e.audio),text:z(e.text),geometry:y(e.geometry),fill:m(e.fill),outline:S(e.outline),shadow:p(e.shadow),children:(r=e.children)==null?void 0:r.map(t=>T(t))})}n.clearUndef=l,n.deepClearUndef=w,n.getDefaultElementStyle=g,n.getDefaultShadowStyle=u,n.getDefaultStyle=v,n.getDefaultTextStyle=c,n.getDefaultTransformStyle=s,n.normalizeAudio=d,n.normalizeElement=T,n.normalizeFill=m,n.normalizeGeometry=y,n.normalizeImage=h,n.normalizeOutline=S,n.normalizeShadow=p,n.normalizeText=z,n.normalizeTextContent=f,n.normalizeVideo=b,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.mjs
CHANGED
|
@@ -47,10 +47,6 @@ function getDefaultLayoutStyle() {
|
|
|
47
47
|
|
|
48
48
|
function getDefaultShadowStyle() {
|
|
49
49
|
return {
|
|
50
|
-
shadowColor: "transparent",
|
|
51
|
-
shadowOffsetX: 0,
|
|
52
|
-
shadowOffsetY: 0,
|
|
53
|
-
shadowBlur: 0,
|
|
54
50
|
boxShadow: "none"
|
|
55
51
|
};
|
|
56
52
|
}
|
|
@@ -134,11 +130,55 @@ function getDefaultStyle() {
|
|
|
134
130
|
};
|
|
135
131
|
}
|
|
136
132
|
|
|
133
|
+
function clearUndef(obj, deep = false) {
|
|
134
|
+
if (typeof obj !== "object" || !obj) {
|
|
135
|
+
return obj;
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(obj)) {
|
|
138
|
+
if (deep) {
|
|
139
|
+
return obj.map((v) => clearUndef(v, deep));
|
|
140
|
+
} else {
|
|
141
|
+
return obj;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const newObj = {};
|
|
145
|
+
for (const key in obj) {
|
|
146
|
+
const value = obj[key];
|
|
147
|
+
if (value === void 0 || value === null) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (deep) {
|
|
151
|
+
newObj[key] = clearUndef(value, deep);
|
|
152
|
+
} else {
|
|
153
|
+
newObj[key] = value;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return newObj;
|
|
157
|
+
}
|
|
158
|
+
function deepClearUndef(obj) {
|
|
159
|
+
return clearUndef(obj, true);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function normalizeAudio(audio) {
|
|
163
|
+
if (!audio || audio === "none") {
|
|
164
|
+
return void 0;
|
|
165
|
+
} else if (typeof audio === "string") {
|
|
166
|
+
return {
|
|
167
|
+
url: audio
|
|
168
|
+
};
|
|
169
|
+
} else {
|
|
170
|
+
return {
|
|
171
|
+
...audio
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
137
176
|
function normalizeFill(fill) {
|
|
138
177
|
if (!fill || fill === "none") {
|
|
139
178
|
return void 0;
|
|
140
179
|
} else if (typeof fill === "string") {
|
|
141
180
|
return {
|
|
181
|
+
type: "color",
|
|
142
182
|
color: fill
|
|
143
183
|
};
|
|
144
184
|
} else {
|
|
@@ -183,15 +223,27 @@ function normalizeImage(image) {
|
|
|
183
223
|
}
|
|
184
224
|
}
|
|
185
225
|
|
|
186
|
-
function
|
|
187
|
-
if (!
|
|
226
|
+
function normalizeOutline(outline) {
|
|
227
|
+
if (!outline || outline === "none") {
|
|
188
228
|
return void 0;
|
|
189
|
-
} else if (typeof
|
|
229
|
+
} else if (typeof outline === "string") {
|
|
190
230
|
return {
|
|
191
|
-
color:
|
|
231
|
+
color: outline
|
|
192
232
|
};
|
|
193
233
|
} else {
|
|
194
|
-
return
|
|
234
|
+
return outline;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function normalizeShadow(shadow) {
|
|
239
|
+
if (!shadow || shadow === "none") {
|
|
240
|
+
return void 0;
|
|
241
|
+
} else if (typeof shadow === "string") {
|
|
242
|
+
return {
|
|
243
|
+
color: shadow
|
|
244
|
+
};
|
|
245
|
+
} else {
|
|
246
|
+
return shadow;
|
|
195
247
|
}
|
|
196
248
|
}
|
|
197
249
|
|
|
@@ -275,16 +327,18 @@ function normalizeVideo(video) {
|
|
|
275
327
|
}
|
|
276
328
|
|
|
277
329
|
function normalizeElement(element) {
|
|
278
|
-
return {
|
|
330
|
+
return clearUndef({
|
|
279
331
|
...element,
|
|
280
332
|
image: normalizeImage(element.image),
|
|
281
333
|
video: normalizeVideo(element.video),
|
|
334
|
+
audio: normalizeAudio(element.audio),
|
|
282
335
|
text: normalizeText(element.text),
|
|
283
336
|
geometry: normalizeGeometry(element.geometry),
|
|
284
337
|
fill: normalizeFill(element.fill),
|
|
285
|
-
|
|
338
|
+
outline: normalizeOutline(element.outline),
|
|
339
|
+
shadow: normalizeShadow(element.shadow),
|
|
286
340
|
children: element.children?.map((child) => normalizeElement(child))
|
|
287
|
-
};
|
|
341
|
+
});
|
|
288
342
|
}
|
|
289
343
|
|
|
290
|
-
export { getDefaultElementStyle, getDefaultShadowStyle, getDefaultStyle, getDefaultTextStyle, getDefaultTransformStyle, normalizeElement, normalizeFill, normalizeGeometry, normalizeImage,
|
|
344
|
+
export { clearUndef, deepClearUndef, getDefaultElementStyle, getDefaultShadowStyle, getDefaultStyle, getDefaultTextStyle, getDefaultTransformStyle, normalizeAudio, normalizeElement, normalizeFill, normalizeGeometry, normalizeImage, normalizeOutline, normalizeShadow, normalizeText, normalizeTextContent, normalizeVideo };
|