@json-to-office/core-pptx 0.7.0 → 0.8.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/core/render.d.ts.map +1 -1
- package/dist/core/structure.d.ts.map +1 -1
- package/dist/index.js +121 -10
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/componentDefaults.d.ts +28 -0
- package/dist/utils/componentDefaults.d.ts.map +1 -0
- package/dist/utils/resolveComponentTree.d.ts +18 -0
- package/dist/utils/resolveComponentTree.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/core/render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAEhB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/core/render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAEhB,MAAM,UAAU,CAAC;AAUlB,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,qBAAqB,EAChC,QAAQ,CAAC,EAAE,eAAe,EAAE,GAC3B,OAAO,CAAC,SAAS,CAAC,CAuOpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../../src/core/structure.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAEV,+BAA+B,EAC/B,qBAAqB,EAGtB,MAAM,UAAU,CAAC;AAQlB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../../src/core/structure.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAEV,+BAA+B,EAC/B,qBAAqB,EAGtB,MAAM,UAAU,CAAC;AAQlB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,+BAA+B,EACzC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,qBAAqB,CA6GvB"}
|
package/dist/index.js
CHANGED
|
@@ -212,11 +212,113 @@ function getPptxTheme(name) {
|
|
|
212
212
|
}
|
|
213
213
|
var pptxThemes = PPTX_THEMES;
|
|
214
214
|
|
|
215
|
+
// src/utils/componentDefaults.ts
|
|
216
|
+
import { mergeWithDefaults } from "@json-to-office/shared";
|
|
217
|
+
function getComponentDefaults(theme) {
|
|
218
|
+
return theme.componentDefaults || {};
|
|
219
|
+
}
|
|
220
|
+
function getTextDefaults(theme) {
|
|
221
|
+
return getComponentDefaults(theme).text || {};
|
|
222
|
+
}
|
|
223
|
+
function getImageDefaults(theme) {
|
|
224
|
+
return getComponentDefaults(theme).image || {};
|
|
225
|
+
}
|
|
226
|
+
function getShapeDefaults(theme) {
|
|
227
|
+
return getComponentDefaults(theme).shape || {};
|
|
228
|
+
}
|
|
229
|
+
function getTableDefaults(theme) {
|
|
230
|
+
return getComponentDefaults(theme).table || {};
|
|
231
|
+
}
|
|
232
|
+
function getHighchartsDefaults(theme) {
|
|
233
|
+
return getComponentDefaults(theme).highcharts || {};
|
|
234
|
+
}
|
|
235
|
+
function getChartDefaults(theme) {
|
|
236
|
+
return getComponentDefaults(theme).chart || {};
|
|
237
|
+
}
|
|
238
|
+
function getCustomComponentDefaults(theme, componentName) {
|
|
239
|
+
const defaults = getComponentDefaults(theme);
|
|
240
|
+
return defaults?.[componentName] || {};
|
|
241
|
+
}
|
|
242
|
+
function resolveTextProps(props, theme) {
|
|
243
|
+
return mergeWithDefaults(props, getTextDefaults(theme));
|
|
244
|
+
}
|
|
245
|
+
function resolveImageProps(props, theme) {
|
|
246
|
+
return mergeWithDefaults(props, getImageDefaults(theme));
|
|
247
|
+
}
|
|
248
|
+
function resolveShapeProps(props, theme) {
|
|
249
|
+
return mergeWithDefaults(props, getShapeDefaults(theme));
|
|
250
|
+
}
|
|
251
|
+
function resolveTableProps(props, theme) {
|
|
252
|
+
return mergeWithDefaults(props, getTableDefaults(theme));
|
|
253
|
+
}
|
|
254
|
+
function resolveHighchartsProps(props, theme) {
|
|
255
|
+
return mergeWithDefaults(props, getHighchartsDefaults(theme));
|
|
256
|
+
}
|
|
257
|
+
function resolveChartProps(props, theme) {
|
|
258
|
+
return mergeWithDefaults(props, getChartDefaults(theme));
|
|
259
|
+
}
|
|
260
|
+
function resolveCustomComponentProps(props, theme, componentName) {
|
|
261
|
+
const defaults = getCustomComponentDefaults(theme, componentName);
|
|
262
|
+
return mergeWithDefaults(props, defaults);
|
|
263
|
+
}
|
|
264
|
+
var TYPE_GETTERS = {
|
|
265
|
+
text: getTextDefaults,
|
|
266
|
+
image: getImageDefaults,
|
|
267
|
+
shape: getShapeDefaults,
|
|
268
|
+
table: getTableDefaults,
|
|
269
|
+
highcharts: getHighchartsDefaults,
|
|
270
|
+
chart: getChartDefaults
|
|
271
|
+
};
|
|
272
|
+
function getDefaultsForType(componentName, theme) {
|
|
273
|
+
const getter = TYPE_GETTERS[componentName];
|
|
274
|
+
return getter ? getter(theme) : getCustomComponentDefaults(theme, componentName);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/utils/resolveComponentTree.ts
|
|
278
|
+
var RESOLVER_MAP = {
|
|
279
|
+
text: resolveTextProps,
|
|
280
|
+
image: resolveImageProps,
|
|
281
|
+
shape: resolveShapeProps,
|
|
282
|
+
table: resolveTableProps,
|
|
283
|
+
highcharts: resolveHighchartsProps,
|
|
284
|
+
chart: resolveChartProps
|
|
285
|
+
};
|
|
286
|
+
function resolveComponentDefaults(component, theme) {
|
|
287
|
+
const resolver = RESOLVER_MAP[component.name];
|
|
288
|
+
const resolvedProps = resolver ? resolver(component.props, theme) : resolveCustomComponentProps(
|
|
289
|
+
component.props,
|
|
290
|
+
theme,
|
|
291
|
+
component.name
|
|
292
|
+
);
|
|
293
|
+
return { ...component, props: resolvedProps };
|
|
294
|
+
}
|
|
295
|
+
function resolveComponentTree(components, theme) {
|
|
296
|
+
return components.map((component) => {
|
|
297
|
+
const resolved = resolveComponentDefaults(component, theme);
|
|
298
|
+
if (resolved.children && resolved.children.length > 0) {
|
|
299
|
+
return {
|
|
300
|
+
...resolved,
|
|
301
|
+
children: resolveComponentTree(resolved.children, theme)
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return resolved;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
215
308
|
// src/core/structure.ts
|
|
309
|
+
import { mergeWithDefaults as mergeWithDefaults2 } from "@json-to-office/shared";
|
|
216
310
|
function processPresentation(document, options) {
|
|
217
311
|
const { props, children = [] } = document;
|
|
218
312
|
const themeName = props.theme ?? "default";
|
|
219
|
-
const
|
|
313
|
+
const baseTheme = options?.customThemes?.[themeName] ?? getPptxTheme(themeName);
|
|
314
|
+
const presDefaults = props.componentDefaults;
|
|
315
|
+
const theme = presDefaults ? {
|
|
316
|
+
...baseTheme,
|
|
317
|
+
componentDefaults: mergeWithDefaults2(
|
|
318
|
+
presDefaults,
|
|
319
|
+
baseTheme.componentDefaults || {}
|
|
320
|
+
)
|
|
321
|
+
} : baseTheme;
|
|
220
322
|
const slideWidth = props.slideWidth ?? 10;
|
|
221
323
|
const slideHeight = props.slideHeight ?? 7.5;
|
|
222
324
|
let templates;
|
|
@@ -240,7 +342,8 @@ function processPresentation(document, options) {
|
|
|
240
342
|
grid: void 0
|
|
241
343
|
};
|
|
242
344
|
});
|
|
243
|
-
const
|
|
345
|
+
const defaultedObjects = m.objects ? resolveComponentTree(m.objects, theme) : void 0;
|
|
346
|
+
const resolvedObjects = defaultedObjects?.map(
|
|
244
347
|
(obj) => resolveComponentGridPosition(
|
|
245
348
|
obj,
|
|
246
349
|
effectiveGrid,
|
|
@@ -260,8 +363,9 @@ function processPresentation(document, options) {
|
|
|
260
363
|
slideComponents.push(slideChild);
|
|
261
364
|
}
|
|
262
365
|
}
|
|
366
|
+
const resolvedComponents = resolveComponentTree(slideComponents, theme);
|
|
263
367
|
slides.push({
|
|
264
|
-
components:
|
|
368
|
+
components: resolvedComponents,
|
|
265
369
|
background: child.props.background,
|
|
266
370
|
notes: child.props.notes,
|
|
267
371
|
layout: child.props.layout,
|
|
@@ -1014,6 +1118,7 @@ function buildSlideTemplateProps(def, theme, warnings) {
|
|
|
1014
1118
|
}
|
|
1015
1119
|
|
|
1016
1120
|
// src/core/render.ts
|
|
1121
|
+
import { mergeWithDefaults as mergeWithDefaults3 } from "@json-to-office/shared";
|
|
1017
1122
|
async function renderPresentation(processed, warnings) {
|
|
1018
1123
|
const pptx = new PptxGenJS();
|
|
1019
1124
|
if (processed.metadata.title) pptx.title = processed.metadata.title;
|
|
@@ -1141,16 +1246,18 @@ async function renderPresentation(processed, warnings) {
|
|
|
1141
1246
|
processed.slideHeight,
|
|
1142
1247
|
warnings
|
|
1143
1248
|
);
|
|
1249
|
+
const typeDefaults = getDefaultsForType(
|
|
1250
|
+
component.name,
|
|
1251
|
+
processed.theme
|
|
1252
|
+
);
|
|
1144
1253
|
const posDefaults = {};
|
|
1145
1254
|
if (phDef.x != null) posDefaults.x = phDef.x;
|
|
1146
1255
|
if (phDef.y != null) posDefaults.y = phDef.y;
|
|
1147
1256
|
if (phDef.w != null) posDefaults.w = phDef.w;
|
|
1148
1257
|
if (phDef.h != null) posDefaults.h = phDef.h;
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
...gridResolved.props
|
|
1153
|
-
};
|
|
1258
|
+
let props = mergeWithDefaults3(posDefaults, typeDefaults);
|
|
1259
|
+
props = mergeWithDefaults3(phDef.defaults?.props ?? {}, props);
|
|
1260
|
+
props = mergeWithDefaults3(gridResolved.props, props);
|
|
1154
1261
|
await renderComponent(
|
|
1155
1262
|
slide,
|
|
1156
1263
|
{ ...gridResolved, props },
|
|
@@ -1165,10 +1272,14 @@ async function renderPresentation(processed, warnings) {
|
|
|
1165
1272
|
for (const [phName, component] of Object.entries(
|
|
1166
1273
|
slideData.placeholders
|
|
1167
1274
|
)) {
|
|
1168
|
-
const
|
|
1275
|
+
const defaulted = resolveComponentDefaults(
|
|
1276
|
+
component,
|
|
1277
|
+
processed.theme
|
|
1278
|
+
);
|
|
1279
|
+
const hasPosition = defaulted.props.x != null || defaulted.props.y != null || defaulted.props.grid;
|
|
1169
1280
|
if (hasPosition) {
|
|
1170
1281
|
const resolved = resolveComponentGridPosition(
|
|
1171
|
-
|
|
1282
|
+
defaulted,
|
|
1172
1283
|
effectiveGrid,
|
|
1173
1284
|
processed.slideWidth,
|
|
1174
1285
|
processed.slideHeight,
|