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