Step 1 — Knowledge base: perfect all reference/*.md with type, range, default, unit - text.md: add DataOrPathProps, path/data, bullet deprecated params - chart.md: add deprecated section, fix 19 params with missing elements - slide.md: add bkgd→background deprecated mapping - output.md: add masterSlide, presLayout Step 2 — Schema: align schema/presentation.schema.json with KB - Add catAxisItem and valAxisItem definitions with full sub-property constraints - Fix 7 enum constraints (barDir, displayBlanksAs, bar3DShape, etc.) - Add 4 missing fields (verbose, autoPageCharWeight, autoPageLineWeight, notes, masterSlide, presLayout) Step 3 — Translation engine: transform renderers from passthrough to validation - index.js: add normalizePosition, normalizeColor, validateEnum shared utilities - All renderers: position validation, color hex normalization, enum validation - Image: graceful failure handling (catch load errors, warn, continue) - Chart: chartType enum validation, data parity check - Table: colspan/rowspan integer validation, border array check - Full verification: basic.json and full.json generate valid PPTX Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
29 lines
824 B
JavaScript
29 lines
824 B
JavaScript
var { normalizePosition, normalizeColorInOptions, validateEnum } = require('./index');
|
|
|
|
function renderImage(slide, imageData) {
|
|
var opts = {};
|
|
if (imageData.options) {
|
|
for (var k in imageData.options) {
|
|
if (imageData.options.hasOwnProperty(k)) opts[k] = imageData.options[k];
|
|
}
|
|
}
|
|
|
|
normalizePosition(opts);
|
|
|
|
if (opts.sizing && typeof opts.sizing === 'object') {
|
|
validateEnum(opts.sizing.type, ['contain', 'cover', 'crop'], 'sizing.type');
|
|
}
|
|
if (opts.shadow && typeof opts.shadow === 'object') {
|
|
normalizeColorInOptions(opts.shadow, 'color');
|
|
validateEnum(opts.shadow.type, ['outer', 'inner', 'none'], 'shadow.type');
|
|
}
|
|
|
|
try {
|
|
slide.addImage(opts);
|
|
} catch (e) {
|
|
console.warn('Failed to load image: ' + (opts.path || 'unknown'));
|
|
}
|
|
}
|
|
|
|
module.exports = { renderImage };
|