modern-idoc 0.0.2 → 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 CHANGED
@@ -21,47 +21,68 @@
21
21
  ## Usage
22
22
 
23
23
  ```ts
24
- import type { IDoc } from 'modern-idoc'
24
+ import type { IDOCDocument } from 'modern-idoc'
25
25
 
26
- const doc: IDoc = {
27
- name: 'example.pptx',
26
+ const pdf: IDOCDocument = {
28
27
  children: [
29
28
  {
30
- name: 'ppt/slides/slide1.xml',
31
- type: 'group',
32
29
  style: {
33
- width: 960,
34
- height: 540,
35
- },
36
- meta: {
37
- layout: 'ppt/slideLayous/slideLayout1.xml',
30
+ width: 300,
31
+ height: 600,
38
32
  },
39
33
  children: [
40
34
  {
41
- type: 'image',
42
35
  style: {
43
- left: 100,
44
- top: 100,
45
- width: 300,
46
- height: 400,
36
+ rotate: 60,
37
+ width: 50,
38
+ height: 50,
47
39
  },
48
- src: '/example.png',
40
+ image: '/example.png',
49
41
  },
50
42
  {
51
- type: 'text',
52
43
  style: {
44
+ rotate: 40,
53
45
  left: 100,
54
46
  top: 100,
47
+ fontSize: 20,
48
+ color: '#FF00FF',
55
49
  },
56
- content: 'TEXT',
50
+ text: 'test',
57
51
  },
58
52
  {
59
- type: 'shape',
60
- paths: [
61
- { fill: '#000', data: 'M 0 0 L 100 100' },
53
+ style: {
54
+ left: 200,
55
+ top: 100,
56
+ width: 100,
57
+ height: 200,
58
+ fontSize: 22,
59
+ },
60
+ text: [
61
+ {
62
+ letterSpacing: 3,
63
+ fragments: [
64
+ {
65
+ content: 'He',
66
+ color: '#00FF00',
67
+ fontSize: 12,
68
+ },
69
+ {
70
+ content: 'llo',
71
+ color: '#000000',
72
+ },
73
+ ],
74
+ },
75
+ {
76
+ content: ', ',
77
+ color: '#FF0000',
78
+ },
79
+ {
80
+ content: 'World!',
81
+ color: '#0000FF',
82
+ },
62
83
  ],
63
84
  },
64
- ]
85
+ ],
65
86
  },
66
87
  ],
67
88
  }
package/dist/index.cjs CHANGED
@@ -1,14 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var IElementType = /* @__PURE__ */ ((IElementType2) => {
4
- IElementType2["text"] = "text";
5
- IElementType2["image"] = "image";
6
- IElementType2["group"] = "group";
7
- IElementType2["shape"] = "shape";
8
- IElementType2["video"] = "video";
9
- return IElementType2;
10
- })(IElementType || {});
11
-
12
3
  function getDefaultElementStyle() {
13
4
  return {
14
5
  overflow: "visible",
@@ -57,11 +48,11 @@ function getDefaultElementStyle() {
57
48
 
58
49
  function getDefaultTextStyle() {
59
50
  return {
60
- ...getDefaultElementStyle(),
61
51
  writingMode: "horizontal-tb",
62
52
  verticalAlign: "baseline",
63
53
  lineHeight: 1.2,
64
54
  letterSpacing: 0,
55
+ wordSpacing: 0,
65
56
  // font
66
57
  fontSize: 14,
67
58
  fontWeight: "normal",
@@ -86,16 +77,205 @@ function getDefaultTextStyle() {
86
77
  listStyleColormap: "none",
87
78
  listStyleSize: "cover",
88
79
  listStylePosition: "outside",
89
- // listStyle
80
+ // highlight
90
81
  highlightImage: "none",
91
82
  highlightReferImage: "none",
92
83
  highlightColormap: "none",
93
84
  highlightLine: "none",
94
85
  highlightSize: "cover",
95
- highlightThickness: "100%"
86
+ highlightThickness: "100%",
87
+ // transform
88
+ scaleX: 1,
89
+ scaleY: 1,
90
+ skewX: 0,
91
+ skewY: 0,
92
+ translateX: 0,
93
+ translateY: 0,
94
+ transform: "none",
95
+ transformOrigin: "50% 50%",
96
+ // shadow
97
+ shadowColor: "transparent",
98
+ shadowOffsetX: 0,
99
+ shadowOffsetY: 0,
100
+ shadowBlur: 0
101
+ };
102
+ }
103
+
104
+ function getDefaultStyle() {
105
+ return {
106
+ ...getDefaultElementStyle(),
107
+ ...getDefaultTextStyle()
108
+ };
109
+ }
110
+
111
+ function normalizeFill(fill) {
112
+ if (!fill || fill === "none") {
113
+ return void 0;
114
+ } else if (typeof fill === "string") {
115
+ return {
116
+ color: fill
117
+ };
118
+ } else {
119
+ return fill;
120
+ }
121
+ }
122
+
123
+ function normalizeGeometry(geometry) {
124
+ if (!geometry || geometry === "none") {
125
+ return void 0;
126
+ } else if (typeof geometry === "string") {
127
+ return {
128
+ data: [
129
+ { data: geometry }
130
+ ]
131
+ };
132
+ } else if (Array.isArray(geometry)) {
133
+ return {
134
+ data: geometry.map((data) => {
135
+ return {
136
+ data
137
+ };
138
+ })
139
+ };
140
+ } else {
141
+ return {
142
+ ...geometry,
143
+ data: geometry.data.map((data) => {
144
+ if (typeof data === "string") {
145
+ return {
146
+ data
147
+ };
148
+ }
149
+ return data;
150
+ })
151
+ };
152
+ }
153
+ }
154
+
155
+ function normalizeImage(image) {
156
+ if (!image || image === "none") {
157
+ return void 0;
158
+ } else if (typeof image === "string") {
159
+ return {
160
+ src: image
161
+ };
162
+ } else {
163
+ return image;
164
+ }
165
+ }
166
+
167
+ function normalizeStroke(stroke) {
168
+ if (!stroke || stroke === "none") {
169
+ return void 0;
170
+ } else if (typeof stroke === "string") {
171
+ return {
172
+ color: stroke
173
+ };
174
+ } else {
175
+ return stroke;
176
+ }
177
+ }
178
+
179
+ function normalizeTextContent(content = "") {
180
+ const list = Array.isArray(content) ? content : [content];
181
+ return list.map((p) => {
182
+ if (typeof p === "string") {
183
+ return {
184
+ fragments: [
185
+ { content: p }
186
+ ]
187
+ };
188
+ } else if ("content" in p) {
189
+ return {
190
+ fragments: [
191
+ { ...p }
192
+ ]
193
+ };
194
+ } else if ("fragments" in p) {
195
+ return {
196
+ ...p,
197
+ fragments: p.fragments.map((f) => ({ ...f }))
198
+ };
199
+ } else if (Array.isArray(p)) {
200
+ return {
201
+ fragments: p.map((f) => {
202
+ if (typeof f === "string") {
203
+ return {
204
+ content: f
205
+ };
206
+ } else {
207
+ return { ...f };
208
+ }
209
+ })
210
+ };
211
+ } else {
212
+ return {
213
+ fragments: []
214
+ };
215
+ }
216
+ });
217
+ }
218
+
219
+ function normalizeText(text) {
220
+ if (!text || text === "none") {
221
+ return void 0;
222
+ } else if (typeof text === "string") {
223
+ return {
224
+ content: [
225
+ {
226
+ fragments: [
227
+ { content: text }
228
+ ]
229
+ }
230
+ ]
231
+ };
232
+ } else if ("content" in text) {
233
+ return {
234
+ ...text,
235
+ content: normalizeTextContent(text.content)
236
+ };
237
+ } else {
238
+ return {
239
+ content: normalizeTextContent(text)
240
+ };
241
+ }
242
+ }
243
+
244
+ function normalizeVideo(video) {
245
+ if (!video || video === "none") {
246
+ return void 0;
247
+ } else if (typeof video === "string") {
248
+ return {
249
+ src: video
250
+ };
251
+ } else {
252
+ return {
253
+ ...video
254
+ };
255
+ }
256
+ }
257
+
258
+ function normalizeElement(element) {
259
+ return {
260
+ ...element,
261
+ image: normalizeImage(element.image),
262
+ video: normalizeVideo(element.video),
263
+ text: normalizeText(element.text),
264
+ geometry: normalizeGeometry(element.geometry),
265
+ fill: normalizeFill(element.fill),
266
+ stroke: normalizeStroke(element.stroke),
267
+ children: element.children?.map((child) => normalizeElement(child))
96
268
  };
97
269
  }
98
270
 
99
- exports.IElementType = IElementType;
100
271
  exports.getDefaultElementStyle = getDefaultElementStyle;
272
+ exports.getDefaultStyle = getDefaultStyle;
101
273
  exports.getDefaultTextStyle = getDefaultTextStyle;
274
+ exports.normalizeElement = normalizeElement;
275
+ exports.normalizeFill = normalizeFill;
276
+ exports.normalizeGeometry = normalizeGeometry;
277
+ exports.normalizeImage = normalizeImage;
278
+ exports.normalizeStroke = normalizeStroke;
279
+ exports.normalizeText = normalizeText;
280
+ exports.normalizeTextContent = normalizeTextContent;
281
+ exports.normalizeVideo = normalizeVideo;