modern-idoc 0.2.13 → 0.3.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
@@ -26,10 +26,7 @@ import type { IDOCDocument } from 'modern-idoc'
26
26
  const pdf: IDOCDocument = {
27
27
  children: [
28
28
  {
29
- style: {
30
- width: 300,
31
- height: 600,
32
- },
29
+ style: { width: 300, height: 600 },
33
30
  children: [
34
31
  {
35
32
  style: {
@@ -37,7 +34,7 @@ const pdf: IDOCDocument = {
37
34
  width: 50,
38
35
  height: 50,
39
36
  },
40
- image: '/example.png',
37
+ background: '/example.png',
41
38
  },
42
39
  {
43
40
  style: {
@@ -66,20 +63,11 @@ const pdf: IDOCDocument = {
66
63
  color: '#00FF00',
67
64
  fontSize: 12,
68
65
  },
69
- {
70
- content: 'llo',
71
- color: '#000000',
72
- },
66
+ { content: 'llo', color: '#000000' },
73
67
  ],
74
68
  },
75
- {
76
- content: ', ',
77
- color: '#FF0000',
78
- },
79
- {
80
- content: 'World!',
81
- color: '#0000FF',
82
- },
69
+ { content: ', ', color: '#FF0000' },
70
+ { content: 'World!', color: '#0000FF' },
83
71
  ],
84
72
  },
85
73
  ],
package/dist/index.cjs CHANGED
@@ -1,192 +1,16 @@
1
1
  'use strict';
2
2
 
3
- function getDefaultLayoutStyle() {
4
- return {
5
- // box
6
- overflow: "visible",
7
- direction: void 0,
8
- display: void 0,
9
- boxSizing: void 0,
10
- width: void 0,
11
- height: void 0,
12
- maxHeight: void 0,
13
- maxWidth: void 0,
14
- minHeight: void 0,
15
- minWidth: void 0,
16
- // position
17
- position: void 0,
18
- left: 0,
19
- top: 0,
20
- right: void 0,
21
- bottom: void 0,
22
- // border
23
- borderTop: void 0,
24
- borderLeft: void 0,
25
- borderRight: void 0,
26
- borderBottom: void 0,
27
- borderWidth: 0,
28
- border: void 0,
29
- // flex
30
- flex: void 0,
31
- flexBasis: void 0,
32
- flexDirection: void 0,
33
- flexGrow: void 0,
34
- flexShrink: void 0,
35
- flexWrap: void 0,
36
- justifyContent: void 0,
37
- gap: void 0,
38
- alignContent: void 0,
39
- alignItems: void 0,
40
- alignSelf: void 0,
41
- // margin
42
- marginTop: void 0,
43
- marginLeft: void 0,
44
- marginRight: void 0,
45
- marginBottom: void 0,
46
- margin: void 0,
47
- // padding
48
- paddingTop: void 0,
49
- paddingLeft: void 0,
50
- paddingRight: void 0,
51
- paddingBottom: void 0,
52
- padding: void 0
53
- };
54
- }
55
-
56
- function getDefaultShadowStyle() {
57
- return {
58
- boxShadow: "none"
59
- };
60
- }
61
-
62
- function getDefaultTransformStyle() {
63
- return {
64
- rotate: 0,
65
- scaleX: 1,
66
- scaleY: 1,
67
- skewX: 0,
68
- skewY: 0,
69
- translateX: 0,
70
- translateY: 0,
71
- transform: "none",
72
- transformOrigin: "center"
73
- };
74
- }
75
-
76
- function getDefaultElementStyle() {
77
- return {
78
- ...getDefaultLayoutStyle(),
79
- ...getDefaultTransformStyle(),
80
- ...getDefaultShadowStyle(),
81
- // background
82
- backgroundImage: "none",
83
- backgroundColor: "none",
84
- // border
85
- borderRadius: 0,
86
- borderColor: "none",
87
- borderStyle: "solid",
88
- // outline
89
- outlineWidth: 0,
90
- outlineOffset: 0,
91
- outlineColor: "#000000",
92
- outlineStyle: "none",
93
- // other
94
- visibility: "visible",
95
- filter: "none",
96
- opacity: 1,
97
- pointerEvents: "auto",
98
- maskImage: "none"
99
- };
100
- }
101
-
102
- function getDefaultTextStyle() {
103
- return {
104
- writingMode: "horizontal-tb",
105
- verticalAlign: "baseline",
106
- lineHeight: 1.2,
107
- letterSpacing: 0,
108
- wordSpacing: 0,
109
- // font
110
- fontSize: 14,
111
- fontWeight: "normal",
112
- fontFamily: "",
113
- fontStyle: "normal",
114
- fontKerning: "normal",
115
- // text
116
- textWrap: "wrap",
117
- textAlign: "start",
118
- textIndent: 0,
119
- textTransform: "none",
120
- textOrientation: "mixed",
121
- textDecoration: "none",
122
- // textStroke
123
- textStrokeWidth: 0,
124
- textStrokeColor: "black",
125
- // color
126
- color: "black",
127
- // listStyle
128
- listStyleType: "none",
129
- listStyleImage: "none",
130
- listStyleColormap: "none",
131
- listStyleSize: "cover",
132
- listStylePosition: "outside",
133
- // highlight
134
- highlightImage: "none",
135
- highlightReferImage: "none",
136
- highlightColormap: "none",
137
- highlightLine: "none",
138
- highlightSize: "cover",
139
- highlightThickness: "100%"
140
- };
141
- }
142
-
143
- function getDefaultStyle() {
144
- return {
145
- ...getDefaultElementStyle(),
146
- ...getDefaultTextStyle()
147
- };
148
- }
149
-
150
- function clearUndef(obj, deep = false) {
151
- if (typeof obj !== "object" || !obj) {
152
- return obj;
153
- }
154
- if (Array.isArray(obj)) {
155
- if (deep) {
156
- return obj.map((v) => clearUndef(v, deep));
157
- } else {
158
- return obj;
159
- }
160
- }
161
- const newObj = {};
162
- for (const key in obj) {
163
- const value = obj[key];
164
- if (value === void 0 || value === null) {
165
- continue;
166
- }
167
- if (deep) {
168
- newObj[key] = clearUndef(value, deep);
169
- } else {
170
- newObj[key] = value;
171
- }
172
- }
173
- return newObj;
174
- }
175
- function deepClearUndef(obj) {
176
- return clearUndef(obj, true);
177
- }
178
-
179
- function normalizeAudio(audio) {
180
- if (!audio || audio === "none") {
3
+ function normalizeBackground(background) {
4
+ if (!background || background === "none") {
181
5
  return void 0;
182
- } else if (typeof audio === "string") {
183
- return {
184
- src: audio
185
- };
6
+ } else if (typeof background === "string") {
7
+ return [
8
+ { type: "texture", src: background }
9
+ ];
10
+ } else if (!Array.isArray(background)) {
11
+ return [background];
186
12
  } else {
187
- return {
188
- ...audio
189
- };
13
+ return background;
190
14
  }
191
15
  }
192
16
 
@@ -194,10 +18,11 @@ function normalizeFill(fill) {
194
18
  if (!fill || fill === "none") {
195
19
  return void 0;
196
20
  } else if (typeof fill === "string") {
197
- return {
198
- type: "color",
199
- color: fill
200
- };
21
+ return [
22
+ { type: "solid", color: fill }
23
+ ];
24
+ } else if (!Array.isArray(fill)) {
25
+ return [fill];
201
26
  } else {
202
27
  return fill;
203
28
  }
@@ -208,13 +33,13 @@ function normalizeGeometry(geometry) {
208
33
  return void 0;
209
34
  } else if (typeof geometry === "string") {
210
35
  return {
211
- data: [
36
+ paths: [
212
37
  { data: geometry }
213
38
  ]
214
39
  };
215
40
  } else if (Array.isArray(geometry)) {
216
41
  return {
217
- data: geometry.map((data) => {
42
+ paths: geometry.map((data) => {
218
43
  if (typeof data === "string") {
219
44
  return {
220
45
  data
@@ -228,18 +53,6 @@ function normalizeGeometry(geometry) {
228
53
  }
229
54
  }
230
55
 
231
- function normalizeImage(image) {
232
- if (!image || image === "none") {
233
- return void 0;
234
- } else if (typeof image === "string") {
235
- return {
236
- src: image
237
- };
238
- } else {
239
- return image;
240
- }
241
- }
242
-
243
56
  function normalizeOutline(outline) {
244
57
  if (!outline || outline === "none") {
245
58
  return void 0;
@@ -252,6 +65,11 @@ function normalizeOutline(outline) {
252
65
  }
253
66
  }
254
67
 
68
+ function getDefaultShadowStyle() {
69
+ return {
70
+ boxShadow: "none"
71
+ };
72
+ }
255
73
  function normalizeShadow(shadow) {
256
74
  if (!shadow || shadow === "none") {
257
75
  return void 0;
@@ -303,7 +121,6 @@ function normalizeTextContent(content = "") {
303
121
  }
304
122
  });
305
123
  }
306
-
307
124
  function normalizeText(text) {
308
125
  if (!text || text === "none") {
309
126
  return void 0;
@@ -329,26 +146,36 @@ function normalizeText(text) {
329
146
  }
330
147
  }
331
148
 
332
- function normalizeVideo(video) {
333
- if (!video || video === "none") {
334
- return void 0;
335
- } else if (typeof video === "string") {
336
- return {
337
- src: video
338
- };
339
- } else {
340
- return {
341
- ...video
342
- };
149
+ function clearUndef(obj, deep = false) {
150
+ if (typeof obj !== "object" || !obj) {
151
+ return obj;
152
+ }
153
+ if (Array.isArray(obj)) {
154
+ if (deep) {
155
+ return obj.map((v) => clearUndef(v, deep));
156
+ } else {
157
+ return obj;
158
+ }
159
+ }
160
+ const newObj = {};
161
+ for (const key in obj) {
162
+ const value = obj[key];
163
+ if (value === void 0 || value === null) {
164
+ continue;
165
+ }
166
+ if (deep) {
167
+ newObj[key] = clearUndef(value, deep);
168
+ } else {
169
+ newObj[key] = value;
170
+ }
343
171
  }
172
+ return newObj;
344
173
  }
345
174
 
346
175
  function normalizeElement(element) {
347
176
  return clearUndef({
348
177
  ...element,
349
- image: normalizeImage(element.image),
350
- video: normalizeVideo(element.video),
351
- audio: normalizeAudio(element.audio),
178
+ background: normalizeBackground(element.background),
352
179
  text: normalizeText(element.text),
353
180
  geometry: normalizeGeometry(element.geometry),
354
181
  fill: normalizeFill(element.fill),
@@ -358,21 +185,188 @@ function normalizeElement(element) {
358
185
  });
359
186
  }
360
187
 
188
+ function normalizeDocument(doc) {
189
+ return normalizeElement(doc);
190
+ }
191
+
192
+ function getDefaultLayoutStyle() {
193
+ return {
194
+ // box
195
+ overflow: "visible",
196
+ direction: void 0,
197
+ display: void 0,
198
+ boxSizing: void 0,
199
+ width: void 0,
200
+ height: void 0,
201
+ maxHeight: void 0,
202
+ maxWidth: void 0,
203
+ minHeight: void 0,
204
+ minWidth: void 0,
205
+ // position
206
+ position: void 0,
207
+ left: 0,
208
+ top: 0,
209
+ right: void 0,
210
+ bottom: void 0,
211
+ // border
212
+ borderTop: void 0,
213
+ borderLeft: void 0,
214
+ borderRight: void 0,
215
+ borderBottom: void 0,
216
+ borderWidth: 0,
217
+ border: void 0,
218
+ // flex
219
+ flex: void 0,
220
+ flexBasis: void 0,
221
+ flexDirection: void 0,
222
+ flexGrow: void 0,
223
+ flexShrink: void 0,
224
+ flexWrap: void 0,
225
+ justifyContent: void 0,
226
+ gap: void 0,
227
+ alignContent: void 0,
228
+ alignItems: void 0,
229
+ alignSelf: void 0,
230
+ // margin
231
+ marginTop: void 0,
232
+ marginLeft: void 0,
233
+ marginRight: void 0,
234
+ marginBottom: void 0,
235
+ margin: void 0,
236
+ // padding
237
+ paddingTop: void 0,
238
+ paddingLeft: void 0,
239
+ paddingRight: void 0,
240
+ paddingBottom: void 0,
241
+ padding: void 0
242
+ };
243
+ }
244
+
245
+ function getDefaultTransformStyle() {
246
+ return {
247
+ rotate: 0,
248
+ scaleX: 1,
249
+ scaleY: 1,
250
+ skewX: 0,
251
+ skewY: 0,
252
+ translateX: 0,
253
+ translateY: 0,
254
+ transform: "none",
255
+ transformOrigin: "center"
256
+ };
257
+ }
258
+
259
+ function getDefaultElementStyle() {
260
+ return {
261
+ ...getDefaultLayoutStyle(),
262
+ ...getDefaultTransformStyle(),
263
+ ...getDefaultShadowStyle(),
264
+ // background
265
+ backgroundImage: "none",
266
+ backgroundColor: "none",
267
+ // border
268
+ borderRadius: 0,
269
+ borderColor: "none",
270
+ borderStyle: "solid",
271
+ // outline
272
+ outlineWidth: 0,
273
+ outlineOffset: 0,
274
+ outlineColor: "#000000",
275
+ outlineStyle: "none",
276
+ // other
277
+ visibility: "visible",
278
+ filter: "none",
279
+ opacity: 1,
280
+ pointerEvents: "auto",
281
+ maskImage: "none"
282
+ };
283
+ }
284
+
285
+ function getDefaultHighlightStyle() {
286
+ return {
287
+ highlightImage: "none",
288
+ highlightReferImage: "none",
289
+ highlightColormap: "none",
290
+ highlightLine: "none",
291
+ highlightSize: "cover",
292
+ highlightThickness: "100%"
293
+ };
294
+ }
295
+
296
+ function getDefaultListStyleStyle() {
297
+ return {
298
+ listStyleType: "none",
299
+ listStyleImage: "none",
300
+ listStyleColormap: "none",
301
+ listStyleSize: "cover",
302
+ listStylePosition: "outside"
303
+ };
304
+ }
305
+
306
+ function getDefaultTextInlineStyle() {
307
+ return {
308
+ ...getDefaultHighlightStyle(),
309
+ color: "black",
310
+ verticalAlign: "baseline",
311
+ letterSpacing: 0,
312
+ wordSpacing: 0,
313
+ // font
314
+ fontSize: 14,
315
+ fontWeight: "normal",
316
+ fontFamily: "",
317
+ fontStyle: "normal",
318
+ fontKerning: "normal",
319
+ // text
320
+ textTransform: "none",
321
+ textOrientation: "mixed",
322
+ textDecoration: "none"
323
+ };
324
+ }
325
+
326
+ function getDefaultTextLineStyle() {
327
+ return {
328
+ ...getDefaultListStyleStyle(),
329
+ writingMode: "horizontal-tb",
330
+ textWrap: "wrap",
331
+ textAlign: "start",
332
+ textIndent: 0,
333
+ lineHeight: 1.2
334
+ };
335
+ }
336
+
337
+ function getDefaultTextStyle() {
338
+ return {
339
+ ...getDefaultTextLineStyle(),
340
+ ...getDefaultTextInlineStyle(),
341
+ // textStroke
342
+ textStrokeWidth: 0,
343
+ textStrokeColor: "black"
344
+ };
345
+ }
346
+
347
+ function getDefaultStyle() {
348
+ return {
349
+ ...getDefaultElementStyle(),
350
+ ...getDefaultTextStyle()
351
+ };
352
+ }
353
+
361
354
  exports.clearUndef = clearUndef;
362
- exports.deepClearUndef = deepClearUndef;
363
355
  exports.getDefaultElementStyle = getDefaultElementStyle;
356
+ exports.getDefaultHighlightStyle = getDefaultHighlightStyle;
364
357
  exports.getDefaultLayoutStyle = getDefaultLayoutStyle;
358
+ exports.getDefaultListStyleStyle = getDefaultListStyleStyle;
365
359
  exports.getDefaultShadowStyle = getDefaultShadowStyle;
366
360
  exports.getDefaultStyle = getDefaultStyle;
361
+ exports.getDefaultTextInlineStyle = getDefaultTextInlineStyle;
362
+ exports.getDefaultTextLineStyle = getDefaultTextLineStyle;
367
363
  exports.getDefaultTextStyle = getDefaultTextStyle;
368
364
  exports.getDefaultTransformStyle = getDefaultTransformStyle;
369
- exports.normalizeAudio = normalizeAudio;
365
+ exports.normalizeDocument = normalizeDocument;
370
366
  exports.normalizeElement = normalizeElement;
371
367
  exports.normalizeFill = normalizeFill;
372
368
  exports.normalizeGeometry = normalizeGeometry;
373
- exports.normalizeImage = normalizeImage;
374
369
  exports.normalizeOutline = normalizeOutline;
375
370
  exports.normalizeShadow = normalizeShadow;
376
371
  exports.normalizeText = normalizeText;
377
372
  exports.normalizeTextContent = normalizeTextContent;
378
- exports.normalizeVideo = normalizeVideo;