refactor: complete three-layer serial refactoring (knowledge→schema→renderer)
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>
This commit is contained in:
@@ -1,5 +1,35 @@
|
||||
var { normalizePosition, normalizeColorInOptions, validateEnum } = require('./index');
|
||||
|
||||
function renderShape(slide, shapeData) {
|
||||
slide.addShape(shapeData.shapeName, shapeData.options);
|
||||
var opts = {};
|
||||
if (shapeData.options) {
|
||||
for (var k in shapeData.options) {
|
||||
if (shapeData.options.hasOwnProperty(k)) opts[k] = shapeData.options[k];
|
||||
}
|
||||
}
|
||||
|
||||
normalizePosition(opts);
|
||||
|
||||
if (opts.fill && typeof opts.fill === 'object') {
|
||||
normalizeColorInOptions(opts.fill, 'color');
|
||||
validateEnum(opts.fill.type, ['none', 'solid'], 'fill.type');
|
||||
}
|
||||
|
||||
if (opts.line && typeof opts.line === 'object') {
|
||||
normalizeColorInOptions(opts.line, 'color');
|
||||
validateEnum(opts.line.dashType, ['solid', 'dash', 'dashDot', 'lgDash', 'lgDashDot', 'lgDashDotDot', 'sysDash', 'sysDot'], 'line.dashType');
|
||||
validateEnum(opts.line.beginArrowType, ['none', 'arrow', 'diamond', 'oval', 'stealth', 'triangle'], 'line.beginArrowType');
|
||||
validateEnum(opts.line.endArrowType, ['none', 'arrow', 'diamond', 'oval', 'stealth', 'triangle'], 'line.endArrowType');
|
||||
}
|
||||
|
||||
if (opts.shadow && typeof opts.shadow === 'object') {
|
||||
normalizeColorInOptions(opts.shadow, 'color');
|
||||
validateEnum(opts.shadow.type, ['outer', 'inner', 'none'], 'shadow.type');
|
||||
}
|
||||
|
||||
validateEnum(opts.align, ['left', 'center', 'right', 'justify'], 'align');
|
||||
|
||||
slide.addShape(shapeData.shapeName, opts);
|
||||
}
|
||||
|
||||
module.exports = { renderShape };
|
||||
|
||||
Reference in New Issue
Block a user