@json-to-office/shared-docx 0.14.0 → 0.16.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/{chunk-6IXK54YE.js → chunk-5C7XT6LW.js} +6 -2
- package/dist/{chunk-6IXK54YE.js.map → chunk-5C7XT6LW.js.map} +1 -1
- package/dist/{chunk-52PV5JQK.js → chunk-M6LVAHZB.js} +2 -2
- package/dist/chunk-M6LVAHZB.js.map +1 -0
- package/dist/{chunk-HJIS6RRQ.js → chunk-NZKLNPBZ.js} +4 -4
- package/dist/{chunk-5BKZFYJL.js → chunk-P4CGTP5W.js} +4 -4
- package/dist/chunk-P4CGTP5W.js.map +1 -0
- package/dist/{chunk-QUA2GDH7.js → chunk-PVQV2RS4.js} +2 -2
- package/dist/{chunk-FA6FKO3L.js → chunk-SMIG3LSE.js} +2 -2
- package/dist/{chunk-PQGT7BU5.js → chunk-YRRBEJPB.js} +2 -2
- package/dist/{chunk-CY6IVMEZ.js → chunk-YZYUY2VH.js} +147 -10
- package/dist/chunk-YZYUY2VH.js.map +1 -0
- package/dist/index.d.ts +17 -5
- package/dist/index.js +21 -10
- package/dist/index.js.map +1 -1
- package/dist/schemas/api.js +3 -3
- package/dist/schemas/component-registry.js +1 -1
- package/dist/schemas/components.d.ts +89 -1
- package/dist/schemas/components.js +8 -2
- package/dist/schemas/document.js +4 -4
- package/dist/schemas/export.js +2 -2
- package/dist/schemas/generator.js +2 -2
- package/dist/validation/unified/index.js +4 -4
- package/package.json +3 -2
- package/dist/chunk-52PV5JQK.js.map +0 -1
- package/dist/chunk-5BKZFYJL.js.map +0 -1
- package/dist/chunk-CY6IVMEZ.js.map +0 -1
- /package/dist/{chunk-HJIS6RRQ.js.map → chunk-NZKLNPBZ.js.map} +0 -0
- /package/dist/{chunk-QUA2GDH7.js.map → chunk-PVQV2RS4.js.map} +0 -0
- /package/dist/{chunk-FA6FKO3L.js.map → chunk-SMIG3LSE.js.map} +0 -0
- /package/dist/{chunk-PQGT7BU5.js.map → chunk-YRRBEJPB.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getContainerComponents
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YZYUY2VH.js";
|
|
4
4
|
|
|
5
5
|
// src/schemas/export.ts
|
|
6
6
|
function fixSchemaReferences(schema, rootDefinitionName = "ComponentDefinition") {
|
|
@@ -208,6 +208,10 @@ var COMPONENT_METADATA = {
|
|
|
208
208
|
highcharts: {
|
|
209
209
|
title: "Highcharts Component",
|
|
210
210
|
description: "Charts powered by Highcharts (line, bar, pie, heatmap, etc.) with rich configuration"
|
|
211
|
+
},
|
|
212
|
+
visual: {
|
|
213
|
+
title: "Visual Component",
|
|
214
|
+
description: "Free-canvas graphic authored as a single pptx slide and embedded as a rasterized PNG"
|
|
211
215
|
}
|
|
212
216
|
};
|
|
213
217
|
var BASE_SCHEMA_METADATA = {
|
|
@@ -268,4 +272,4 @@ export {
|
|
|
268
272
|
BASE_SCHEMA_METADATA,
|
|
269
273
|
THEME_SCHEMA_METADATA
|
|
270
274
|
};
|
|
271
|
-
//# sourceMappingURL=chunk-
|
|
275
|
+
//# sourceMappingURL=chunk-5C7XT6LW.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas/export.ts"],"sourcesContent":["/**\n * Unified Schema Export Utility\n *\n * Single source of truth for converting TypeBox schemas to JSON Schema format.\n * Eliminates duplication between generate-schemas.mjs and plugin/schema.ts\n */\n\nimport { TSchema } from '@sinclair/typebox';\nimport { getContainerComponents } from './component-registry';\n\n/**\n * Configuration for a component schema\n */\nexport interface ComponentSchemaConfig {\n schema: TSchema;\n title: string;\n description: string;\n requiresName?: boolean;\n enhanceForRichContent?: boolean;\n}\n\n/**\n * Fix TypeBox recursive references in a schema\n * Handles both \"T0\" and \"ComponentDefinition\" reference patterns\n */\nexport function fixSchemaReferences(\n schema: Record<string, unknown>,\n rootDefinitionName = 'ComponentDefinition'\n): void {\n function traverse(obj: Record<string, unknown>, path = ''): void {\n if (typeof obj !== 'object' || obj === null) return;\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = path ? `${path}.${key}` : key;\n\n if (value && typeof value === 'object') {\n // Type guard to check if value has expected properties\n const schemaValue = value as Record<string, unknown>;\n\n // Fix arrays with empty items\n if (\n schemaValue.type === 'array' &&\n schemaValue.items &&\n Object.keys(schemaValue.items).length === 0\n ) {\n schemaValue.items = {\n $ref: `#/definitions/${rootDefinitionName}`,\n };\n }\n\n // Fix arrays with items that reference broken \"T0\"\n if (\n schemaValue.type === 'array' &&\n schemaValue.items &&\n typeof schemaValue.items === 'object' &&\n '$ref' in schemaValue.items &&\n (schemaValue.items as Record<string, unknown>).$ref === 'T0'\n ) {\n schemaValue.items = {\n $ref: `#/definitions/${rootDefinitionName}`,\n };\n }\n\n // Fix direct $ref properties that point to \"T0\" or bare definition names\n if (\n schemaValue.$ref === 'T0' ||\n schemaValue.$ref === rootDefinitionName\n ) {\n schemaValue.$ref = `#/definitions/${rootDefinitionName}`;\n }\n\n // Remove problematic $id properties that reference \"T0\"\n if (\n key === '$id' &&\n typeof value === 'string' &&\n (value === 'T0' || value === rootDefinitionName) &&\n currentPath !== `definitions.${rootDefinitionName}.$id`\n ) {\n delete obj[key];\n continue;\n }\n\n traverse(value as Record<string, unknown>, currentPath);\n }\n }\n }\n\n traverse(schema);\n}\n\n/**\n * Convert TypeBox schema to JSON Schema format with proper definitions\n */\nexport function convertToJsonSchema(\n schema: TSchema,\n options: {\n $schema?: string;\n $id?: string;\n title?: string;\n description?: string;\n definitions?: Record<string, unknown>;\n } = {}\n): Record<string, unknown> {\n const {\n $schema = 'https://json-schema.org/draft-07/schema#',\n $id,\n title,\n description,\n definitions = {},\n } = options;\n\n // Clone the schema to avoid mutations\n const schemaJson = JSON.parse(JSON.stringify(schema));\n\n // Extract recursive schemas to definitions\n const extractedDefinitions: Record<string, unknown> = { ...definitions };\n\n function extractRecursiveSchemas(\n obj: Record<string, unknown>,\n path = ''\n ): void {\n if (typeof obj !== 'object' || obj === null) return;\n\n for (const [key, value] of Object.entries(obj)) {\n if (value && typeof value === 'object') {\n const schemaValue = value as Record<string, unknown>;\n\n // If this schema has an $id, extract it to definitions\n if (schemaValue.$id && typeof schemaValue.$id === 'string') {\n const definitionName = schemaValue.$id;\n\n // Don't extract if it's already in the root definitions section\n if (path !== `definitions.${definitionName}`) {\n // Clone the schema without the $id\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $id: _, ...schemaWithoutId } = schemaValue;\n extractedDefinitions[definitionName] = schemaWithoutId;\n\n // Replace the inline schema with a $ref\n obj[key] = { $ref: `#/definitions/${definitionName}` };\n\n // Continue processing the extracted schema for nested recursions\n extractRecursiveSchemas(\n schemaWithoutId,\n `definitions.${definitionName}`\n );\n continue;\n }\n }\n\n extractRecursiveSchemas(\n value as Record<string, unknown>,\n path ? `${path}.${key}` : key\n );\n }\n }\n }\n\n // Extract recursive schemas from the main schema\n extractRecursiveSchemas(schemaJson);\n\n // Build the final JSON Schema\n const jsonSchema: Record<string, unknown> = {\n $schema,\n };\n\n if ($id) jsonSchema.$id = $id;\n\n // Merge schema properties first to preserve original metadata\n Object.assign(jsonSchema, schemaJson);\n\n // Only override title and description if explicitly provided\n if (title !== undefined) jsonSchema.title = title;\n if (description !== undefined) jsonSchema.description = description;\n\n // Add definitions section if we have any\n if (Object.keys(extractedDefinitions).length > 0) {\n jsonSchema.definitions = extractedDefinitions;\n }\n\n // Fix any remaining recursive references\n fixSchemaReferences(jsonSchema);\n\n return jsonSchema;\n}\n\n/**\n * Create a component schema with proper structure\n */\nexport function createComponentSchema(\n name: string,\n config: ComponentSchemaConfig,\n componentDefinitionSchema?: TSchema\n): Record<string, unknown> {\n const componentStructure: Record<string, unknown> = {\n $schema: 'https://json-schema.org/draft-07/schema#',\n $id: `${name}.schema.json`,\n title: config.title,\n description: config.description,\n type: 'object',\n required: ['name', 'props'],\n properties: {\n name: {\n type: 'string',\n const: name,\n description: `Component name identifier (must be \"${name}\")`,\n },\n id: {\n type: 'string',\n description: 'Optional unique identifier for the component',\n },\n props: JSON.parse(JSON.stringify(config.schema)),\n },\n };\n\n // Add children array for container types\n const containerNames = getContainerComponents().map((c) => c.name);\n if (containerNames.includes(name)) {\n (componentStructure.properties as Record<string, unknown>).children = {\n type: 'array',\n description: 'Children within this container',\n items: {\n $ref: '#/definitions/ComponentDefinition',\n },\n };\n\n // Add the ComponentDefinition for recursive references\n if (componentDefinitionSchema) {\n componentStructure.definitions = {\n ComponentDefinition: JSON.parse(\n JSON.stringify(componentDefinitionSchema)\n ),\n };\n }\n }\n\n // Enhance table component to support rich content in cells\n if (config.enhanceForRichContent && name === 'table') {\n // Add ComponentDefinition to support rich content in table cells\n const componentStructureWithDefs = componentStructure as Record<\n string,\n unknown\n > & {\n definitions?: Record<string, unknown>;\n };\n if (!componentStructureWithDefs.definitions) {\n componentStructureWithDefs.definitions = {};\n }\n if (componentDefinitionSchema) {\n componentStructureWithDefs.definitions.ComponentDefinition = JSON.parse(\n JSON.stringify(componentDefinitionSchema)\n );\n }\n\n // Enhance the rows.items.items to support components\n const properties = componentStructure.properties as Record<string, unknown>;\n const propsProp = properties.props as Record<string, unknown> | undefined;\n if (\n propsProp?.properties &&\n typeof propsProp.properties === 'object' &&\n propsProp.properties !== null\n ) {\n const propsProps = propsProp.properties as Record<string, unknown>;\n const rowsProp = propsProps.rows as Record<string, unknown> | undefined;\n if (\n rowsProp?.items &&\n typeof rowsProp.items === 'object' &&\n rowsProp.items !== null\n ) {\n const rowsItems = rowsProp.items as Record<string, unknown>;\n const cellSchema = rowsItems.items as\n | Record<string, unknown>\n | undefined;\n\n // If it has anyOf, add component reference as an option\n if (cellSchema?.anyOf && Array.isArray(cellSchema.anyOf)) {\n // Check if component reference isn't already there\n const hasComponentRef = cellSchema.anyOf.some((item: unknown) => {\n const itemObj = item as Record<string, unknown>;\n return itemObj.$ref === '#/definitions/ComponentDefinition';\n });\n if (!hasComponentRef) {\n cellSchema.anyOf.push({\n description:\n 'Rich content cell with component (e.g., image, paragraph)',\n $ref: '#/definitions/ComponentDefinition',\n });\n }\n }\n }\n }\n }\n\n // Fix empty items in arrays and broken references\n fixSchemaReferences(componentStructure);\n\n componentStructure.additionalProperties = false;\n\n return componentStructure;\n}\n\n/**\n * Export schema to file with proper formatting\n */\nexport async function exportSchemaToFile(\n schema: Record<string, unknown>,\n outputPath: string,\n options: {\n prettyPrint?: boolean;\n } = {}\n): Promise<void> {\n const { prettyPrint = true } = options;\n\n // Convert to JSON string\n const jsonSchema = prettyPrint\n ? JSON.stringify(schema, null, 2)\n : JSON.stringify(schema);\n\n // Write to file\n const fs = await import('fs/promises');\n await fs.writeFile(outputPath, jsonSchema, 'utf-8');\n}\n\n/**\n * Component metadata registry\n * Single source of truth for component titles and descriptions\n */\nexport const COMPONENT_METADATA: Record<\n string,\n Omit<ComponentSchemaConfig, 'schema'>\n> = {\n report: {\n title: 'Report Component',\n description:\n 'Top-level report container component with document-wide settings',\n },\n section: {\n title: 'Section Component',\n description: 'Section container for organizing document content',\n },\n columns: {\n title: 'Columns Component',\n description: 'Multi-column layout container',\n },\n heading: {\n title: 'Heading Component',\n description: 'Heading text with configurable levels and styling',\n },\n paragraph: {\n title: 'Paragraph Component',\n description: 'Rich paragraph text content with formatting options',\n },\n 'text-box': {\n title: 'Text Box Component',\n description:\n 'Inline or floating container that groups text and image components with shared positioning',\n },\n image: {\n title: 'Image Component',\n description: 'Image content with positioning and sizing options',\n },\n statistic: {\n title: 'Statistic Component',\n description: 'Statistical display with value and label',\n },\n table: {\n title: 'Table Component',\n description: 'Tabular data display with headers and rows',\n enhanceForRichContent: true,\n },\n list: {\n title: 'List Component',\n description: 'Ordered or unordered list with nested items',\n },\n highcharts: {\n title: 'Highcharts Component',\n description:\n 'Charts powered by Highcharts (line, bar, pie, heatmap, etc.) with rich configuration',\n },\n};\n\n/**\n * Base schema metadata registry\n */\nexport const BASE_SCHEMA_METADATA: Record<\n string,\n { title: string; description: string }\n> = {\n alignment: {\n title: 'Alignment',\n description: 'Text alignment options',\n },\n 'base-component': {\n title: 'Base Component Props',\n description: 'Common props for all components',\n },\n border: {\n title: 'Border',\n description: 'Border styling configuration',\n },\n spacing: {\n title: 'Spacing',\n description: 'Spacing configuration for before and after elements',\n },\n margins: {\n title: 'Margins',\n description: 'Margin configuration for all sides',\n },\n indent: {\n title: 'Indent',\n description: 'Indentation configuration',\n },\n 'line-spacing': {\n title: 'Line Spacing',\n description: 'Line height and spacing configuration',\n },\n 'heading-level': {\n title: 'Heading Level',\n description: 'Heading level from 1 to 6',\n },\n numbering: {\n title: 'Numbering',\n description: 'Numbering configuration for ordered lists',\n },\n 'justified-alignment': {\n title: 'Justified Alignment',\n description: 'Justified text alignment options',\n },\n};\n\n/**\n * Theme schema metadata\n */\nexport const THEME_SCHEMA_METADATA = {\n theme: {\n title: 'Theme Configuration',\n description: 'JSON theme configuration for document styling and appearance',\n },\n};\n"],"mappings":";;;;;AAyBO,SAAS,oBACd,QACA,qBAAqB,uBACf;AACN,WAAS,SAAS,KAA8B,OAAO,IAAU;AAC/D,QAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM;AAE7C,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,YAAM,cAAc,OAAO,GAAG,IAAI,IAAI,GAAG,KAAK;AAE9C,UAAI,SAAS,OAAO,UAAU,UAAU;AAEtC,cAAM,cAAc;AAGpB,YACE,YAAY,SAAS,WACrB,YAAY,SACZ,OAAO,KAAK,YAAY,KAAK,EAAE,WAAW,GAC1C;AACA,sBAAY,QAAQ;AAAA,YAClB,MAAM,iBAAiB,kBAAkB;AAAA,UAC3C;AAAA,QACF;AAGA,YACE,YAAY,SAAS,WACrB,YAAY,SACZ,OAAO,YAAY,UAAU,YAC7B,UAAU,YAAY,SACrB,YAAY,MAAkC,SAAS,MACxD;AACA,sBAAY,QAAQ;AA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A,IACP,aAAa;AAAA,EACf;AACF;AAKO,IAAM,wBAAwB;AAAA,EACnC,OAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/schemas/export.ts"],"sourcesContent":["/**\n * Unified Schema Export Utility\n *\n * Single source of truth for converting TypeBox schemas to JSON Schema format.\n * Eliminates duplication between generate-schemas.mjs and plugin/schema.ts\n */\n\nimport { TSchema } from '@sinclair/typebox';\nimport { getContainerComponents } from './component-registry';\n\n/**\n * Configuration for a component schema\n */\nexport interface ComponentSchemaConfig {\n schema: TSchema;\n title: string;\n description: string;\n requiresName?: boolean;\n enhanceForRichContent?: boolean;\n}\n\n/**\n * Fix TypeBox recursive references in a schema\n * Handles both \"T0\" and \"ComponentDefinition\" reference patterns\n */\nexport function fixSchemaReferences(\n schema: Record<string, unknown>,\n rootDefinitionName = 'ComponentDefinition'\n): void {\n function traverse(obj: Record<string, unknown>, path = ''): void {\n if (typeof obj !== 'object' || obj === null) return;\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = path ? `${path}.${key}` : key;\n\n if (value && typeof value === 'object') {\n // Type guard to check if value has expected properties\n const schemaValue = value as Record<string, unknown>;\n\n // Fix arrays with empty items\n if (\n schemaValue.type === 'array' &&\n schemaValue.items &&\n Object.keys(schemaValue.items).length === 0\n ) {\n schemaValue.items = {\n $ref: `#/definitions/${rootDefinitionName}`,\n };\n }\n\n // Fix arrays with items that reference broken \"T0\"\n if (\n schemaValue.type === 'array' &&\n schemaValue.items &&\n typeof schemaValue.items === 'object' &&\n '$ref' in schemaValue.items &&\n (schemaValue.items as Record<string, unknown>).$ref === 'T0'\n ) {\n schemaValue.items = {\n $ref: `#/definitions/${rootDefinitionName}`,\n };\n }\n\n // Fix direct $ref properties that point to \"T0\" or bare definition names\n if (\n schemaValue.$ref === 'T0' ||\n schemaValue.$ref === rootDefinitionName\n ) {\n schemaValue.$ref = `#/definitions/${rootDefinitionName}`;\n }\n\n // Remove problematic $id properties that reference \"T0\"\n if (\n key === '$id' &&\n typeof value === 'string' &&\n (value === 'T0' || value === rootDefinitionName) &&\n currentPath !== `definitions.${rootDefinitionName}.$id`\n ) {\n delete obj[key];\n continue;\n }\n\n traverse(value as Record<string, unknown>, currentPath);\n }\n }\n }\n\n traverse(schema);\n}\n\n/**\n * Convert TypeBox schema to JSON Schema format with proper definitions\n */\nexport function convertToJsonSchema(\n schema: TSchema,\n options: {\n $schema?: string;\n $id?: string;\n title?: string;\n description?: string;\n definitions?: Record<string, unknown>;\n } = {}\n): Record<string, unknown> {\n const {\n $schema = 'https://json-schema.org/draft-07/schema#',\n $id,\n title,\n description,\n definitions = {},\n } = options;\n\n // Clone the schema to avoid mutations\n const schemaJson = JSON.parse(JSON.stringify(schema));\n\n // Extract recursive schemas to definitions\n const extractedDefinitions: Record<string, unknown> = { ...definitions };\n\n function extractRecursiveSchemas(\n obj: Record<string, unknown>,\n path = ''\n ): void {\n if (typeof obj !== 'object' || obj === null) return;\n\n for (const [key, value] of Object.entries(obj)) {\n if (value && typeof value === 'object') {\n const schemaValue = value as Record<string, unknown>;\n\n // If this schema has an $id, extract it to definitions\n if (schemaValue.$id && typeof schemaValue.$id === 'string') {\n const definitionName = schemaValue.$id;\n\n // Don't extract if it's already in the root definitions section\n if (path !== `definitions.${definitionName}`) {\n // Clone the schema without the $id\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $id: _, ...schemaWithoutId } = schemaValue;\n extractedDefinitions[definitionName] = schemaWithoutId;\n\n // Replace the inline schema with a $ref\n obj[key] = { $ref: `#/definitions/${definitionName}` };\n\n // Continue processing the extracted schema for nested recursions\n extractRecursiveSchemas(\n schemaWithoutId,\n `definitions.${definitionName}`\n );\n continue;\n }\n }\n\n extractRecursiveSchemas(\n value as Record<string, unknown>,\n path ? `${path}.${key}` : key\n );\n }\n }\n }\n\n // Extract recursive schemas from the main schema\n extractRecursiveSchemas(schemaJson);\n\n // Build the final JSON Schema\n const jsonSchema: Record<string, unknown> = {\n $schema,\n };\n\n if ($id) jsonSchema.$id = $id;\n\n // Merge schema properties first to preserve original metadata\n Object.assign(jsonSchema, schemaJson);\n\n // Only override title and description if explicitly provided\n if (title !== undefined) jsonSchema.title = title;\n if (description !== undefined) jsonSchema.description = description;\n\n // Add definitions section if we have any\n if (Object.keys(extractedDefinitions).length > 0) {\n jsonSchema.definitions = extractedDefinitions;\n }\n\n // Fix any remaining recursive references\n fixSchemaReferences(jsonSchema);\n\n return jsonSchema;\n}\n\n/**\n * Create a component schema with proper structure\n */\nexport function createComponentSchema(\n name: string,\n config: ComponentSchemaConfig,\n componentDefinitionSchema?: TSchema\n): Record<string, unknown> {\n const componentStructure: Record<string, unknown> = {\n $schema: 'https://json-schema.org/draft-07/schema#',\n $id: `${name}.schema.json`,\n title: config.title,\n description: config.description,\n type: 'object',\n required: ['name', 'props'],\n properties: {\n name: {\n type: 'string',\n const: name,\n description: `Component name identifier (must be \"${name}\")`,\n },\n id: {\n type: 'string',\n description: 'Optional unique identifier for the component',\n },\n props: JSON.parse(JSON.stringify(config.schema)),\n },\n };\n\n // Add children array for container types\n const containerNames = getContainerComponents().map((c) => c.name);\n if (containerNames.includes(name)) {\n (componentStructure.properties as Record<string, unknown>).children = {\n type: 'array',\n description: 'Children within this container',\n items: {\n $ref: '#/definitions/ComponentDefinition',\n },\n };\n\n // Add the ComponentDefinition for recursive references\n if (componentDefinitionSchema) {\n componentStructure.definitions = {\n ComponentDefinition: JSON.parse(\n JSON.stringify(componentDefinitionSchema)\n ),\n };\n }\n }\n\n // Enhance table component to support rich content in cells\n if (config.enhanceForRichContent && name === 'table') {\n // Add ComponentDefinition to support rich content in table cells\n const componentStructureWithDefs = componentStructure as Record<\n string,\n unknown\n > & {\n definitions?: Record<string, unknown>;\n };\n if (!componentStructureWithDefs.definitions) {\n componentStructureWithDefs.definitions = {};\n }\n if (componentDefinitionSchema) {\n componentStructureWithDefs.definitions.ComponentDefinition = JSON.parse(\n JSON.stringify(componentDefinitionSchema)\n );\n }\n\n // Enhance the rows.items.items to support components\n const properties = componentStructure.properties as Record<string, unknown>;\n const propsProp = properties.props as Record<string, unknown> | undefined;\n if (\n propsProp?.properties &&\n typeof propsProp.properties === 'object' &&\n propsProp.properties !== null\n ) {\n const propsProps = propsProp.properties as Record<string, unknown>;\n const rowsProp = propsProps.rows as Record<string, unknown> | undefined;\n if (\n rowsProp?.items &&\n typeof rowsProp.items === 'object' &&\n rowsProp.items !== null\n ) {\n const rowsItems = rowsProp.items as Record<string, unknown>;\n const cellSchema = rowsItems.items as\n | Record<string, unknown>\n | undefined;\n\n // If it has anyOf, add component reference as an option\n if (cellSchema?.anyOf && Array.isArray(cellSchema.anyOf)) {\n // Check if component reference isn't already there\n const hasComponentRef = cellSchema.anyOf.some((item: unknown) => {\n const itemObj = item as Record<string, unknown>;\n return itemObj.$ref === '#/definitions/ComponentDefinition';\n });\n if (!hasComponentRef) {\n cellSchema.anyOf.push({\n description:\n 'Rich content cell with component (e.g., image, paragraph)',\n $ref: '#/definitions/ComponentDefinition',\n });\n }\n }\n }\n }\n }\n\n // Fix empty items in arrays and broken references\n fixSchemaReferences(componentStructure);\n\n componentStructure.additionalProperties = false;\n\n return componentStructure;\n}\n\n/**\n * Export schema to file with proper formatting\n */\nexport async function exportSchemaToFile(\n schema: Record<string, unknown>,\n outputPath: string,\n options: {\n prettyPrint?: boolean;\n } = {}\n): Promise<void> {\n const { prettyPrint = true } = options;\n\n // Convert to JSON string\n const jsonSchema = prettyPrint\n ? JSON.stringify(schema, null, 2)\n : JSON.stringify(schema);\n\n // Write to file\n const fs = await import('fs/promises');\n await fs.writeFile(outputPath, jsonSchema, 'utf-8');\n}\n\n/**\n * Component metadata registry\n * Single source of truth for component titles and descriptions\n */\nexport const COMPONENT_METADATA: Record<\n string,\n Omit<ComponentSchemaConfig, 'schema'>\n> = {\n report: {\n title: 'Report Component',\n description:\n 'Top-level report container component with document-wide settings',\n },\n section: {\n title: 'Section Component',\n description: 'Section container for organizing document content',\n },\n columns: {\n title: 'Columns Component',\n description: 'Multi-column layout container',\n },\n heading: {\n title: 'Heading Component',\n description: 'Heading text with configurable levels and styling',\n },\n paragraph: {\n title: 'Paragraph Component',\n description: 'Rich paragraph text content with formatting options',\n },\n 'text-box': {\n title: 'Text Box Component',\n description:\n 'Inline or floating container that groups text and image components with shared positioning',\n },\n image: {\n title: 'Image Component',\n description: 'Image content with positioning and sizing options',\n },\n statistic: {\n title: 'Statistic Component',\n description: 'Statistical display with value and label',\n },\n table: {\n title: 'Table Component',\n description: 'Tabular data display with headers and rows',\n enhanceForRichContent: true,\n },\n list: {\n title: 'List Component',\n description: 'Ordered or unordered list with nested items',\n },\n highcharts: {\n title: 'Highcharts Component',\n description:\n 'Charts powered by Highcharts (line, bar, pie, heatmap, etc.) with rich configuration',\n },\n visual: {\n title: 'Visual Component',\n description:\n 'Free-canvas graphic authored as a single pptx slide and embedded as a rasterized PNG',\n },\n};\n\n/**\n * Base schema metadata registry\n */\nexport const BASE_SCHEMA_METADATA: Record<\n string,\n { title: string; description: string }\n> = {\n alignment: {\n title: 'Alignment',\n description: 'Text alignment options',\n },\n 'base-component': {\n title: 'Base Component Props',\n description: 'Common props for all components',\n },\n border: {\n title: 'Border',\n description: 'Border styling configuration',\n },\n spacing: {\n title: 'Spacing',\n description: 'Spacing configuration for before and after elements',\n },\n margins: {\n title: 'Margins',\n description: 'Margin configuration for all sides',\n },\n indent: {\n title: 'Indent',\n description: 'Indentation configuration',\n },\n 'line-spacing': {\n title: 'Line Spacing',\n description: 'Line height and spacing configuration',\n },\n 'heading-level': {\n title: 'Heading Level',\n description: 'Heading level from 1 to 6',\n },\n numbering: {\n title: 'Numbering',\n description: 'Numbering configuration for ordered lists',\n },\n 'justified-alignment': {\n title: 'Justified Alignment',\n description: 'Justified text alignment options',\n },\n};\n\n/**\n * Theme schema metadata\n */\nexport const THEME_SCHEMA_METADATA = {\n theme: {\n title: 'Theme Configuration',\n description: 'JSON theme configu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AA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,aACE;AAAA,EACJ;AACF;AAKO,IAAM,uBAGT;AAAA,EACF,WAAW;AAAA,IACT,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,kBAAkB;AAAA,IAChB,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,SAAS;AAAA,IACP,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,SAAS;AAAA,IACP,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,gBAAgB;AAAA,IACd,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,iBAAiB;AAAA,IACf,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,WAAW;AAAA,IACT,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA,uBAAuB;AAAA,IACrB,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AACF;AAKO,IAAM,wBAAwB;AAAA,EACnC,OAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAllComponentSchemas,
|
|
3
3
|
createAllComponentSchemasNarrowed
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YZYUY2VH.js";
|
|
5
5
|
|
|
6
6
|
// src/schemas/components.ts
|
|
7
7
|
import { Type } from "@sinclair/typebox";
|
|
@@ -31,4 +31,4 @@ export {
|
|
|
31
31
|
StandardComponentDefinitionSchema,
|
|
32
32
|
ComponentDefinitionSchema
|
|
33
33
|
};
|
|
34
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-M6LVAHZB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/components.ts"],"sourcesContent":["/**\n * TypeBox Component Schemas\n *\n * Complete component definitions with discriminated unions for perfect\n * JSON schema autocompletion and validation.\n *\n * IMPORTANT: Standard components are defined in component-registry.ts (SINGLE SOURCE OF TRUTH).\n * This file uses that registry to generate TypeBox schemas.\n */\n\nimport { Type, Static } from '@sinclair/typebox';\nimport {\n createAllComponentSchemas,\n createAllComponentSchemasNarrowed,\n} from './component-registry';\n\n// Re-export all schemas from individual component files\nexport * from './components/common';\nexport * from './components/revision';\nexport * from './components/report';\nexport * from './components/section';\nexport * from './components/columns';\nexport * from './components/heading';\nexport * from './components/paragraph';\nexport * from './components/image';\nexport * from './components/highcharts';\nexport * from './components/visual';\nexport * from './components/statistic';\nexport * from './components/table';\nexport * from './components/list';\nexport * from './components/toc';\nexport * from './components/text-box';\n\n// ============================================================================\n// Component Definitions with Discriminated Union\n// ============================================================================\n\n// StandardComponentDefinitionSchema - Union of all standard component types\n// Generated from the component registry (SINGLE SOURCE OF TRUTH)\nexport const StandardComponentDefinitionSchema = Type.Union(\n // Use Type.Any() for non-recursive standard components\n // Convert readonly array to mutable array for Type.Union\n [...createAllComponentSchemas(Type.Any())],\n {\n discriminator: { propertyName: 'name' },\n description: 'Standard component definition with discriminated union',\n }\n);\n\nexport const ComponentDefinitionSchema = Type.Recursive((This) =>\n Type.Union(\n [\n // Standard components from registry with per-container narrowed children\n ...createAllComponentSchemasNarrowed(This).schemas,\n ],\n {\n discriminator: { propertyName: 'name' },\n description: 'Component definition with discriminated union',\n }\n )\n);\n\n// ============================================================================\n// TypeScript Types\n// ============================================================================\n\nexport type ComponentDefinition = Static<typeof ComponentDefinitionSchema>;\n"],"mappings":";;;;;;AAUA,SAAS,YAAoB;AA6BtB,IAAM,oCAAoC,KAAK;AAAA;AAAA;AAAA,EAGpD,CAAC,GAAG,0BAA0B,KAAK,IAAI,CAAC,CAAC;AAAA,EACzC;AAAA,IACE,eAAe,EAAE,cAAc,OAAO;AAAA,IACtC,aAAa;AAAA,EACf;AACF;AAEO,IAAM,4BAA4B,KAAK;AAAA,EAAU,CAAC,SACvD,KAAK;AAAA,IACH;AAAA;AAAA,MAEE,GAAG,kCAAkC,IAAI,EAAE;AAAA,IAC7C;AAAA,IACA;AAAA,MACE,eAAe,EAAE,cAAc,OAAO;AAAA,MACtC,aAAa;AAAA,IACf;AAAA,EACF;AACF;","names":[]}
|
|
@@ -6,16 +6,16 @@ import {
|
|
|
6
6
|
strictDocumentValidator,
|
|
7
7
|
validateAgainstSchema,
|
|
8
8
|
validateJson
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-P4CGTP5W.js";
|
|
10
10
|
import {
|
|
11
11
|
ComponentDefinitionSchema
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-M6LVAHZB.js";
|
|
13
13
|
import {
|
|
14
14
|
CustomComponentDefinitionSchema
|
|
15
15
|
} from "./chunk-7GGTZ4TA.js";
|
|
16
16
|
import {
|
|
17
17
|
ReportPropsSchema
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-YZYUY2VH.js";
|
|
19
19
|
import {
|
|
20
20
|
ColumnsPropsSchema,
|
|
21
21
|
HeadingPropsSchema,
|
|
@@ -416,4 +416,4 @@ export {
|
|
|
416
416
|
createErrorConfig,
|
|
417
417
|
formatErrorMessage
|
|
418
418
|
};
|
|
419
|
-
//# sourceMappingURL=chunk-
|
|
419
|
+
//# sourceMappingURL=chunk-NZKLNPBZ.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ComponentDefinitionSchema,
|
|
3
3
|
StandardComponentDefinitionSchema
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-M6LVAHZB.js";
|
|
5
5
|
import {
|
|
6
6
|
CustomComponentDefinitionSchema
|
|
7
7
|
} from "./chunk-7GGTZ4TA.js";
|
|
8
8
|
import {
|
|
9
9
|
ReportPropsSchema,
|
|
10
10
|
STANDARD_COMPONENTS_REGISTRY
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-YZYUY2VH.js";
|
|
12
12
|
|
|
13
13
|
// src/validation/unified/error-transformer.ts
|
|
14
14
|
import {
|
|
@@ -275,7 +275,7 @@ function getSuggestion(error, config) {
|
|
|
275
275
|
return "Ensure the value matches the required format";
|
|
276
276
|
}
|
|
277
277
|
if (path?.includes("name") || path?.includes("type")) {
|
|
278
|
-
return "Use a valid component name: docx, section, columns, heading, paragraph, image, statistic, table, list, toc, text-box, or
|
|
278
|
+
return "Use a valid component name: docx, section, columns, heading, paragraph, image, statistic, table, list, toc, text-box, highcharts, or visual";
|
|
279
279
|
}
|
|
280
280
|
return void 0;
|
|
281
281
|
}
|
|
@@ -755,4 +755,4 @@ export {
|
|
|
755
755
|
validateJsonComponent,
|
|
756
756
|
validateDocumentWithSchema
|
|
757
757
|
};
|
|
758
|
-
//# sourceMappingURL=chunk-
|
|
758
|
+
//# sourceMappingURL=chunk-P4CGTP5W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/validation/unified/error-transformer.ts","../src/validation/unified/deep-validator.ts","../src/validation/unified/base-validator.ts","../src/validation/unified/document-validator.ts"],"sourcesContent":["/**\n * Unified error transformation utilities\n * Converts TypeBox ValueError objects to standardized ValidationError format\n */\n\nimport type { ValueError } from '@sinclair/typebox/value';\nimport type { ValidationError } from '@json-to-office/shared';\nimport { ReportPropsSchema } from '../../schemas/components/report';\nimport {\n isObjectSchema,\n getObjectSchemaPropertyNames,\n getLiteralValue,\n type ErrorFormatterConfig,\n createErrorConfig,\n formatErrorMessage,\n ERROR_EMOJIS,\n} from '@json-to-office/shared';\n\n/**\n * Generate enhanced error message based on error type and context\n */\nfunction generateEnhancedMessage(\n error: ValueError,\n _config: Required<ErrorFormatterConfig>\n): string {\n const typeStr = String(error.type || '');\n const path = error.path || 'root';\n\n // Handle union errors specially - these are the most common and least helpful\n if (typeStr === '62' || typeStr === 'union') {\n return generateUnionErrorMessage(error);\n }\n\n // Handle additional properties error\n if (error.message?.includes('additionalProperties')) {\n return generateAdditionalPropertiesMessage(error);\n }\n\n // Handle missing required properties\n if (error.message?.includes('Required property')) {\n return generateRequiredPropertyMessage(error);\n }\n\n // Handle type mismatches\n if (\n typeStr === 'string' ||\n typeStr === 'number' ||\n typeStr === 'boolean' ||\n typeStr === 'array' ||\n typeStr === 'object'\n ) {\n return generateTypeMismatchMessage(error);\n }\n\n // Handle literal value errors\n if (typeStr === 'literal') {\n return generateLiteralErrorMessage(error);\n }\n\n // Handle pattern/regex errors\n if (typeStr === 'pattern' || typeStr === 'RegExp') {\n return generatePatternErrorMessage(error);\n }\n\n // Default to original message with some context\n return `At ${path}: ${error.message}`;\n}\n\n/**\n * Generate message for union validation errors\n */\nfunction generateUnionErrorMessage(error: ValueError): string {\n const path = error.path || 'root';\n const value = error.value;\n\n // Try to determine what the user was attempting\n if (path === 'root' || path === '/' || path === '/jsonDefinition') {\n // Root level or jsonDefinition union error - likely a document type issue\n if (value && typeof value === 'object') {\n if ('name' in value) {\n const name = value.name;\n if (name === 'docx') {\n return 'Document structure appears valid but contains invalid component configurations. Check each component for errors.';\n }\n return `Unknown document name '${name}'. Expected 'docx'.`;\n }\n\n // Missing name field\n const valueAny = value as Record<string, unknown>;\n if ('children' in value && Array.isArray(valueAny.children)) {\n return 'Document is missing required \\'name\\' field. Add \"name\": \"docx\" at the root level.';\n }\n\n // Check if it might be a theme\n if ('name' in value || 'styles' in value) {\n return 'This appears to be a theme configuration. Use --type theme or ensure proper document structure.';\n }\n }\n return 'Invalid document structure. Expected a document with name=\"docx\" or a theme configuration.';\n }\n\n // Component-level union error\n if (path.includes('/children/')) {\n if (value && typeof value === 'object' && 'name' in value) {\n const componentType = (value as any).name;\n return `Invalid component configuration for type '${componentType}'. Check that all required fields are present and correctly formatted.`;\n }\n return 'Invalid component structure. Each component must have a \"name\" field and valid configuration.';\n }\n\n // Default union error message\n return `Value at ${path} doesn't match any of the expected formats. Check the structure and required fields.`;\n}\n\n/**\n * Generate message for additional properties errors\n */\nfunction generateAdditionalPropertiesMessage(error: ValueError): string {\n const path = error.path || 'root';\n const value = error.value;\n\n if (typeof value === 'object' && value !== null) {\n // Try to identify the unknown properties\n const schema = error.schema;\n if (schema && isObjectSchema(schema)) {\n const knownProps = getObjectSchemaPropertyNames(schema);\n const actualProps = Object.keys(value);\n const unknownProps = actualProps.filter((p) => !knownProps.includes(p));\n\n if (unknownProps.length > 0) {\n return (\n `Unknown properties at ${path}: ${unknownProps.join(', ')}. ` +\n `Allowed properties are: ${knownProps.join(', ')}`\n );\n }\n }\n }\n\n return `Additional properties not allowed at ${path}. Check for typos or unsupported fields.`;\n}\n\n/**\n * Generate message for required property errors\n */\nfunction generateRequiredPropertyMessage(error: ValueError): string {\n const path = error.path || 'root';\n const match = error.message?.match(/Required property '([^']+)'/);\n\n if (match) {\n const propName = match[1];\n return `Missing required field '${propName}' at ${path}. This field is mandatory for this configuration.`;\n }\n\n return `Missing required property at ${path}. Check that all mandatory fields are present.`;\n}\n\n/**\n * Generate message for type mismatch errors\n */\nfunction generateTypeMismatchMessage(error: ValueError): string {\n const path = error.path || 'root';\n const expectedType = String(error.type);\n const actualType = Array.isArray(error.value) ? 'array' : typeof error.value;\n\n // Provide context-specific messages\n if (path.includes('alignment')) {\n return `Invalid alignment value at ${path}. Expected one of: left, center, right, justify`;\n }\n\n if (path.includes('color')) {\n return `Invalid color value at ${path}. Use hex format (#RRGGBB), rgb(r,g,b), or a named color`;\n }\n\n if (path.includes('fontSize') || path.includes('size')) {\n return `Invalid size value at ${path}. Expected a number (in points)`;\n }\n\n if (\n path.includes('margin') ||\n path.includes('padding') ||\n path.includes('spacing')\n ) {\n return `Invalid spacing value at ${path}. Expected a number or spacing object with top/bottom/left/right`;\n }\n\n return `Type mismatch at ${path}: Expected ${expectedType} but got ${actualType}`;\n}\n\n/**\n * Generate message for literal value errors\n */\nfunction generateLiteralErrorMessage(error: ValueError): string {\n const path = error.path || 'root';\n const expected = error.schema\n ? JSON.stringify(getLiteralValue(error.schema))\n : 'specific value';\n const actual = JSON.stringify(error.value);\n\n return `Invalid value at ${path}: Expected exactly ${expected} but got ${actual}`;\n}\n\n/**\n * Generate message for pattern/regex errors\n */\nfunction generatePatternErrorMessage(error: ValueError): string {\n const path = error.path || 'root';\n\n // Try to provide helpful context based on the path\n if (path.includes('email')) {\n return `Invalid email format at ${path}. Use format: user@example.com`;\n }\n\n if (path.includes('url') || path.includes('link')) {\n return `Invalid URL format at ${path}. Use format: https://example.com`;\n }\n\n if (path.includes('date')) {\n return `Invalid date format at ${path}. Use ISO format: YYYY-MM-DD`;\n }\n\n if (path.includes('phone')) {\n return `Invalid phone number format at ${path}`;\n }\n\n return `Value at ${path} doesn't match the required pattern`;\n}\n\n/**\n * Transform TypeBox ValueError to standardized ValidationError\n */\nexport function transformValueError(\n error: ValueError,\n jsonString?: string,\n config?: ErrorFormatterConfig\n): ValidationError {\n const formatterConfig = createErrorConfig(config);\n\n // Generate enhanced message based on error type\n const enhancedMessage = generateEnhancedMessage(error, formatterConfig);\n\n const baseError: ValidationError = {\n path: error.path || 'root',\n message: formatErrorMessage(\n enhancedMessage || error.message,\n formatterConfig\n ),\n code: String(error.type || 'validation_error'),\n value: error.value,\n };\n\n // Add suggestion if available and configured\n if (formatterConfig.includeSuggestions) {\n const suggestion = getSuggestion(error, formatterConfig);\n if (suggestion) {\n baseError.suggestion = formatErrorMessage(suggestion, formatterConfig);\n }\n }\n\n // Calculate line and column if JSON string is provided\n if (jsonString && error.path) {\n const position = calculatePosition(jsonString, error.path);\n if (position) {\n baseError.line = position.line;\n baseError.column = position.column;\n }\n }\n\n return baseError;\n}\n\n/**\n * Transform multiple TypeBox errors to ValidationError array\n * Enhanced to collect ALL errors, not just stopping at union failures\n */\nexport function transformValueErrors(\n errors: ValueError[],\n options?: {\n jsonString?: string;\n maxErrors?: number;\n }\n): ValidationError[] {\n const maxErrors = options?.maxErrors ?? Number.MAX_SAFE_INTEGER;\n const result: ValidationError[] = [];\n const seenPaths = new Set<string>();\n\n // Collect all errors, but avoid duplicates at the same path\n for (const error of errors) {\n if (result.length >= maxErrors) break;\n\n // Create a unique key for this error based on path and type\n const errorKey = `${error.path}:${error.type}`;\n\n // Skip if we've already seen an error at this exact path and type\n // This helps avoid duplicate union errors while still showing all unique issues\n if (!seenPaths.has(errorKey)) {\n seenPaths.add(errorKey);\n result.push(transformValueError(error, options?.jsonString, undefined));\n }\n }\n\n return result;\n}\n\n/**\n * Calculate line and column position in JSON string\n */\nexport function calculatePosition(\n jsonString: string,\n path: string\n): { line: number; column: number } | null {\n try {\n // Convert path like \"/children/0/props/title\" to searchable parts\n const pathParts = path.split('/').filter(Boolean);\n if (pathParts.length === 0) {\n return { line: 1, column: 1 };\n }\n\n // Try to find the last part of the path in the JSON\n const lastPart = pathParts[pathParts.length - 1];\n const searchPattern = `\"${lastPart}\"`;\n const index = jsonString.indexOf(searchPattern);\n\n if (index === -1) {\n // Try to find just the value if it's a property name\n return { line: 1, column: 1 };\n }\n\n // Calculate line and column from index\n const beforeError = jsonString.substring(0, index);\n const lines = beforeError.split('\\n');\n const line = lines.length;\n const column = lines[lines.length - 1].length + 1;\n\n return { line, column };\n } catch {\n return null;\n }\n}\n\n/**\n * Get helpful suggestion based on error type and context\n */\nfunction getSuggestion(\n error: ValueError,\n config: Required<ErrorFormatterConfig>\n): string | undefined {\n const { type, path, value } = error;\n const typeStr = String(type);\n\n // Enhanced suggestions for union errors\n if (typeStr === '62' || typeStr === 'union') {\n if (path === 'root' || path === '/') {\n if (value && typeof value === 'object') {\n if (!('name' in value)) {\n const msg = 'Add a \"name\" field with value \"docx\" for documents';\n return config.includeEmojis ? `${ERROR_EMOJIS.FIX} ${msg}` : msg;\n }\n if ('props' in value && typeof value.props === 'object') {\n const knownFields = getObjectSchemaPropertyNames(ReportPropsSchema);\n return `Review the props section for unsupported fields. Allowed fields: ${knownFields.join(', ')}`;\n }\n }\n return 'Ensure the document has proper structure: { \"name\": \"docx\", \"props\": {...}, \"children\": [...] }';\n }\n if (path?.includes('/children/')) {\n return 'Check that the component has a valid \"name\" and all required fields for that component type';\n }\n return 'Review the structure and ensure all required fields are present with correct types';\n }\n\n // Suggestions for additional properties errors\n if (error.message?.includes('additionalProperties')) {\n return 'Remove any unknown or unsupported fields. Check documentation for allowed properties.';\n }\n\n // Suggestions for required properties\n if (error.message?.includes('Required property')) {\n return 'Add the missing required field to fix this error';\n }\n\n // Type-specific suggestions\n if (typeStr === 'string') {\n if (path?.includes('alignment')) {\n return 'Use one of: left, center, right, justify';\n }\n if (path?.includes('color')) {\n return 'Use a valid color format (hex: #RRGGBB, rgb: rgb(r,g,b), or named color)';\n }\n return 'Provide a text string value';\n }\n\n if (typeStr === 'number') {\n if (path?.includes('fontSize') || path?.includes('size')) {\n return 'Use a number in points (e.g., 12, 14, 16)';\n }\n if (path?.includes('margin') || path?.includes('padding')) {\n return 'Use a number for spacing in points';\n }\n return 'Provide a numeric value';\n }\n\n if (typeStr === 'boolean') {\n return 'Use true or false (without quotes)';\n }\n\n if (typeStr === 'array') {\n if (path?.includes('children') || path?.includes('modules')) {\n return 'Provide an array of component objects, each with a \"name\" field';\n }\n return 'Provide an array/list of values using square brackets []';\n }\n\n if (typeStr === 'object') {\n return 'Provide an object with key-value pairs using curly braces {}';\n }\n\n if (typeStr === 'literal') {\n const expected = error.schema\n ? JSON.stringify(getLiteralValue(error.schema))\n : 'specific value';\n return `Use exactly this value: ${expected}`;\n }\n\n if (typeStr === 'pattern' || typeStr === 'RegExp') {\n if (path?.includes('email')) {\n return 'Use valid email format: user@example.com';\n }\n if (path?.includes('url')) {\n return 'Use valid URL format: https://example.com';\n }\n if (path?.includes('date')) {\n return 'Use ISO date format: YYYY-MM-DD';\n }\n return 'Ensure the value matches the required format';\n }\n\n // Path-based suggestions\n if (path?.includes('name') || path?.includes('type')) {\n return 'Use a valid component name: docx, section, columns, heading, paragraph, image, statistic, table, list, toc, text-box, highcharts, or visual';\n }\n\n return undefined;\n}\n\n/**\n * Format validation errors as a summary string\n */\nexport function formatErrorSummary(errors: ValidationError[]): string {\n if (errors.length === 0) return 'No errors';\n\n if (errors.length === 1) {\n return errors[0].message;\n }\n\n const summary = errors\n .slice(0, 3)\n .map((e) => `${e.path}: ${e.message}`)\n .join(', ');\n\n if (errors.length > 3) {\n return `${summary} and ${errors.length - 3} more...`;\n }\n\n return summary;\n}\n\n/**\n * Group errors by path for better reporting\n */\nexport function groupErrorsByPath(\n errors: ValidationError[]\n): Map<string, ValidationError[]> {\n const grouped = new Map<string, ValidationError[]>();\n\n for (const error of errors) {\n const path = error.path || 'root';\n const group = grouped.get(path) || [];\n group.push(error);\n grouped.set(path, group);\n }\n\n return grouped;\n}\n\n/**\n * Create a JSON parse error\n */\nexport function createJsonParseError(\n error: Error,\n jsonString: string\n): ValidationError {\n // Try to extract position from error message\n const match = error.message.match(/position (\\d+)/);\n const position = match ? parseInt(match[1], 10) : 0;\n\n let line = 1;\n let column = 1;\n\n if (position > 0) {\n const lines = jsonString.substring(0, position).split('\\n');\n line = lines.length;\n column = lines[lines.length - 1].length + 1;\n }\n\n return {\n path: 'root',\n message: `JSON Parse Error: ${error.message}`,\n code: 'json_parse_error',\n line,\n column,\n suggestion: 'Check for missing commas, quotes, or brackets',\n };\n}\n","/**\n * Deep validation utilities for collecting ALL errors in nested structures\n * This bypasses TypeBox's union short-circuiting to provide comprehensive error reporting\n */\n\nimport { Value } from '@sinclair/typebox/value';\nimport type { TSchema } from '@sinclair/typebox';\nimport type { ValidationError } from '@json-to-office/shared';\nimport { STANDARD_COMPONENTS_REGISTRY } from '../../schemas/component-registry';\nimport { CustomComponentDefinitionSchema } from '../../schemas/custom-components';\nimport { transformValueErrors } from './error-transformer';\n\n// Map of component names to their props schemas, sourced from the registry.\n// This stays in sync as new standard components are added, so the document\n// root ('docx') and every standard child component are recognized here.\nconst COMPONENT_SCHEMAS: Record<string, TSchema> = Object.fromEntries([\n ...STANDARD_COMPONENTS_REGISTRY.map((c) => [c.name, c.propsSchema]),\n ['custom', CustomComponentDefinitionSchema],\n]);\n\n// Root component names that may appear at the top of a document.\nconst ROOT_COMPONENT_NAMES = new Set(\n STANDARD_COMPONENTS_REGISTRY.filter((c) =>\n Boolean(c.special?.hasSchemaField)\n ).map((c) => c.name)\n);\n\n/**\n * Deep validate a document to collect ALL errors, not just union-level errors\n */\nexport function deepValidateDocument(data: any): ValidationError[] {\n const allErrors: ValidationError[] = [];\n\n // Validate the document structure\n if (!data || typeof data !== 'object') {\n allErrors.push({\n path: 'root',\n message: 'Document must be an object',\n code: 'invalid_type',\n });\n return allErrors;\n }\n\n // Check name field\n if (!data.name) {\n allErrors.push({\n path: '/name',\n message: 'Missing required field \"name\"',\n code: 'required_property',\n });\n } else if (!ROOT_COMPONENT_NAMES.has(data.name)) {\n const expected = [...ROOT_COMPONENT_NAMES].map((n) => `\"${n}\"`).join(', ');\n allErrors.push({\n path: '/name',\n message: `Invalid name \"${data.name}\". Expected ${expected}`,\n code: 'invalid_value',\n });\n }\n\n // Validate props section when the key is present so explicit `null` (or any\n // falsy non-object) is checked against the component's schema instead of\n // silently passing.\n if (ROOT_COMPONENT_NAMES.has(data.name) && 'props' in data) {\n const propsErrors = validateComponentProps(data.name, data.props, '/props');\n allErrors.push(...propsErrors);\n }\n\n // Validate children array\n if (!data.children) {\n allErrors.push({\n path: '/children',\n message: 'Missing required field \"children\"',\n code: 'required_property',\n });\n } else if (!Array.isArray(data.children)) {\n allErrors.push({\n path: '/children',\n message: 'Field \"children\" must be an array',\n code: 'invalid_type',\n });\n } else {\n // Validate each child component\n data.children.forEach((child: any, index: number) => {\n const childPath = `/children/${index}`;\n\n if (!child || typeof child !== 'object') {\n allErrors.push({\n path: childPath,\n message: 'Component must be an object',\n code: 'invalid_type',\n });\n return;\n }\n\n // Check component name\n if (!child.name) {\n allErrors.push({\n path: `${childPath}/name`,\n message: 'Component missing required field \"name\"',\n code: 'required_property',\n });\n return;\n }\n\n // Validate component props based on name\n if (child.props) {\n const componentErrors = validateComponentProps(\n child.name,\n child.props,\n `${childPath}/props`\n );\n allErrors.push(...componentErrors);\n } else if (child.name !== 'custom') {\n // Most components require props\n allErrors.push({\n path: `${childPath}/props`,\n message: 'Component missing required field \"props\"',\n code: 'required_property',\n });\n }\n\n // Special handling for section components (recursive)\n if (child.name === 'section' && child.children) {\n if (!Array.isArray(child.children)) {\n allErrors.push({\n path: `${childPath}/children`,\n message: 'Section children must be an array',\n code: 'invalid_type',\n });\n } else {\n // Recursively validate nested components\n child.children.forEach((nestedChild: any, nestedIndex: number) => {\n const nestedChildPath = `${childPath}/children/${nestedIndex}`;\n if (!nestedChild || typeof nestedChild !== 'object') {\n allErrors.push({\n path: nestedChildPath,\n message: 'Nested component must be an object',\n code: 'invalid_type',\n });\n return;\n }\n\n if (!nestedChild.name) {\n allErrors.push({\n path: `${nestedChildPath}/name`,\n message: 'Nested component missing required field \"name\"',\n code: 'required_property',\n });\n } else {\n if (nestedChild.props) {\n const nestedErrors = validateComponentProps(\n nestedChild.name,\n nestedChild.props,\n `${nestedChildPath}/props`\n );\n allErrors.push(...nestedErrors);\n } else if (nestedChild.name !== 'custom') {\n // Most components require props\n allErrors.push({\n path: `${nestedChildPath}/props`,\n message: 'Component missing required field \"props\"',\n code: 'required_property',\n });\n }\n }\n });\n }\n }\n });\n }\n\n return allErrors;\n}\n\n/**\n * Validate a component's props against its schema\n */\nfunction validateComponentProps(\n componentName: string,\n props: any,\n basePath: string\n): ValidationError[] {\n const errors: ValidationError[] = [];\n\n // Get the schema for this component\n const schema = COMPONENT_SCHEMAS[componentName];\n if (!schema) {\n // Unknown component type\n errors.push({\n path: basePath.replace('/props', '/name'),\n message: `Unknown component \"${componentName}\"`,\n code: 'unknown_component',\n });\n return errors;\n }\n\n // Use TypeBox to validate against the specific schema\n if (!Value.Check(schema, props)) {\n const valueErrors = [...Value.Errors(schema, props)];\n const transformedErrors = transformValueErrors(valueErrors, {\n maxErrors: 100,\n });\n\n // Adjust paths to be relative to the document root\n transformedErrors.forEach((error) => {\n // Combine base path with error path\n const fullPath =\n error.path === 'root'\n ? basePath\n : `${basePath}${error.path.startsWith('/') ? error.path : '/' + error.path}`;\n\n errors.push({\n ...error,\n path: fullPath,\n });\n });\n }\n\n return errors;\n}\n\n/**\n * Combine deep validation with standard validation.\n *\n * Deep validation produces precise, path-aware errors. TypeBox's discriminated-\n * union check, by contrast, often collapses any failure under the root document\n * into a single generic \"Invalid component configuration for 'docx'\" message at\n * `root` — useful as a signal that something is wrong, but actionable only via\n * the deep-validator's output. We always strip that catch-all so it doesn't\n * appear alongside (or, worse, instead of) the real diagnostics.\n */\nexport function comprehensiveValidateDocument(\n data: any,\n existingErrors: ValidationError[] = []\n): ValidationError[] {\n const deepErrors = deepValidateDocument(data);\n\n const filteredExisting = existingErrors.filter(\n (e) => !isGenericUnionCatchAll(e)\n );\n\n return deduplicateErrors([...filteredExisting, ...deepErrors]);\n}\n\n/**\n * Detect TypeBox's generic union/discriminator catch-all error at the document\n * root. These messages name the component type ('docx') but give no actionable\n * detail — the deep validator emits the actual path-level errors instead.\n */\nfunction isGenericUnionCatchAll(error: ValidationError): boolean {\n const atRoot = !error.path || error.path === 'root' || error.path === '/';\n if (!atRoot) return false;\n const msg = error.message || '';\n return (\n /invalid (component|module) configurations?/i.test(msg) ||\n /invalid document structure/i.test(msg)\n );\n}\n\n/**\n * Deduplicate errors by path and message\n */\nfunction deduplicateErrors(errors: ValidationError[]): ValidationError[] {\n const seen = new Set<string>();\n const unique: ValidationError[] = [];\n\n for (const error of errors) {\n const key = `${error.path}:${error.message}`;\n if (!seen.has(key)) {\n seen.add(key);\n unique.push(error);\n }\n }\n\n return unique;\n}\n","/**\n * Base validator implementation\n * Core validation logic that eliminates duplication across the codebase\n */\n\nimport { Value } from '@sinclair/typebox/value';\nimport type { Static, TSchema } from '@sinclair/typebox';\nimport type {\n ValidationResult,\n ValidationOptions,\n JsonValidationResult,\n} from './types';\nimport {\n transformValueErrors,\n createJsonParseError,\n formatErrorSummary,\n} from '@json-to-office/shared';\n\n/**\n * Base validation function that all specific validators use\n * This eliminates the repeated Value.Check -> Value.Errors -> map pattern\n */\nexport function validateAgainstSchema<T extends TSchema>(\n schema: T,\n data: unknown,\n options?: ValidationOptions\n): ValidationResult<Static<T>> {\n try {\n // Check if data matches the schema\n if (!Value.Check(schema, data)) {\n // Collect ALL errors (not just the first one)\n const errors = [...Value.Errors(schema, data)];\n const transformedErrors = transformValueErrors(errors, {\n jsonString: options?.jsonString,\n maxErrors: options?.maxErrors || 100, // Default to 100 if not specified\n });\n\n return {\n valid: false,\n errors: transformedErrors,\n };\n }\n\n // Data is valid, apply transformations if requested\n let processedData = data;\n\n if (options?.clean) {\n // Remove unknown properties\n processedData = Value.Clean(schema, Value.Clone(processedData));\n }\n\n if (options?.applyDefaults) {\n // Apply default values\n processedData = Value.Default(schema, processedData);\n }\n\n return {\n valid: true,\n data: processedData as Static<T>,\n };\n } catch (error) {\n // Handle unexpected errors\n return {\n valid: false,\n errors: [\n {\n path: 'root',\n message:\n error instanceof Error ? error.message : 'Unknown validation error',\n code: 'validation_exception',\n },\n ],\n };\n }\n}\n\n/**\n * Validate JSON string or object with schema\n */\nexport function validateJson<T extends TSchema>(\n schema: T,\n jsonInput: string | object,\n options?: ValidationOptions\n): JsonValidationResult<Static<T>> {\n // Handle string input\n if (typeof jsonInput === 'string') {\n // Basic input validation\n if (!jsonInput.trim()) {\n return {\n valid: false,\n errors: [\n {\n path: 'root',\n message: 'Input must be a non-empty string',\n code: 'empty_input',\n },\n ],\n isJsonError: true,\n };\n }\n\n // Try to parse JSON\n let parsed: unknown;\n try {\n parsed = JSON.parse(jsonInput);\n } catch (error) {\n if (error instanceof Error) {\n return {\n valid: false,\n errors: [createJsonParseError(error, jsonInput)],\n isJsonError: true,\n };\n }\n return {\n valid: false,\n errors: [\n {\n path: 'root',\n message: 'Failed to parse JSON',\n code: 'json_parse_error',\n },\n ],\n isJsonError: true,\n };\n }\n\n // Validate parsed object with position calculation\n const result = validateAgainstSchema(schema, parsed, {\n ...options,\n jsonString: jsonInput,\n calculatePosition: true,\n });\n\n return {\n ...result,\n parsed,\n isJsonError: false,\n };\n }\n\n // Handle object input directly\n const result = validateAgainstSchema(schema, jsonInput, options);\n return {\n ...result,\n parsed: jsonInput,\n isJsonError: false,\n };\n}\n\n/**\n * Batch validate multiple items\n */\nexport function validateBatch<T extends TSchema>(\n schema: T,\n items: unknown[],\n options?: ValidationOptions\n): ValidationResult<Static<T>[]> {\n const results: Static<T>[] = [];\n const allErrors: any[] = [];\n let hasErrors = false;\n\n for (let i = 0; i < items.length; i++) {\n const result = validateAgainstSchema(schema, items[i], options);\n\n if (result.valid && result.data) {\n results.push(result.data);\n } else {\n hasErrors = true;\n if (result.errors) {\n // Prefix errors with item index\n const prefixedErrors = result.errors.map((e) => ({\n ...e,\n path: `[${i}]${e.path ? '/' + e.path : ''}`,\n }));\n allErrors.push(...prefixedErrors);\n }\n }\n\n // Stop if we've hit the max errors\n if (options?.maxErrors && allErrors.length >= options.maxErrors) {\n break;\n }\n }\n\n if (hasErrors) {\n return {\n valid: false,\n errors: allErrors.slice(0, options?.maxErrors),\n };\n }\n\n return {\n valid: true,\n data: results,\n };\n}\n\n/**\n * Validate with custom error enhancement\n */\nexport function validateWithEnhancement<T extends TSchema>(\n schema: T,\n data: unknown,\n enhancer: (errors: any[]) => any[],\n options?: ValidationOptions\n): ValidationResult<Static<T>> {\n const result = validateAgainstSchema(schema, data, options);\n\n if (!result.valid && result.errors) {\n result.errors = enhancer(result.errors);\n }\n\n return result;\n}\n\n/**\n * Create a validator function for a specific schema\n */\nexport function createValidator<T extends TSchema>(\n schema: T,\n defaultOptions?: ValidationOptions\n) {\n return (data: unknown, options?: ValidationOptions) => {\n return validateAgainstSchema(schema, data, {\n ...defaultOptions,\n ...options,\n });\n };\n}\n\n/**\n * Create a JSON validator function for a specific schema\n */\nexport function createJsonValidator<T extends TSchema>(\n schema: T,\n defaultOptions?: ValidationOptions\n) {\n return (jsonInput: string | object, options?: ValidationOptions) => {\n return validateJson(schema, jsonInput, {\n ...defaultOptions,\n ...options,\n });\n };\n}\n\n/**\n * Utility to check if validation result is successful with type guard\n */\nexport function isValidationSuccess<T>(\n result: ValidationResult<T>\n): result is ValidationResult<T> & { valid: true; data: T } {\n return result.valid === true && result.data !== undefined;\n}\n\n/**\n * Get validation error summary\n */\nexport function getValidationSummary(result: ValidationResult): string {\n if (result.valid) {\n return 'Validation successful';\n }\n\n if (!result.errors || result.errors.length === 0) {\n return 'Validation failed with unknown error';\n }\n\n return formatErrorSummary(result.errors);\n}\n","/**\n * Document validation implementation\n * Single source of truth for all document validation\n */\n\nimport type { Static } from '@sinclair/typebox';\nimport {\n ComponentDefinitionSchema,\n StandardComponentDefinitionSchema,\n} from '../../schemas/components';\nimport { extractStandardComponentNames } from '@json-to-office/shared';\nimport { comprehensiveValidateDocument } from './deep-validator';\n\n// JsonComponentDefinitionSchema is just an alias for ComponentDefinitionSchema\nconst JsonComponentDefinitionSchema = ComponentDefinitionSchema;\nimport type { DocumentValidationResult, ValidationOptions } from './types';\nimport { validateAgainstSchema, validateJson } from './base-validator';\n\n/**\n * Validate a document/report component definition\n */\nexport function validateDocument(\n data: unknown,\n options?: ValidationOptions\n): DocumentValidationResult {\n const result = validateAgainstSchema(\n ComponentDefinitionSchema,\n data,\n options\n );\n\n // If validation failed, use deep validation to get all detailed errors\n let finalErrors = result.errors || [];\n let finalValid = result.valid;\n if (!result.valid && data) {\n finalErrors = comprehensiveValidateDocument(data, result.errors);\n // If TypeBox's union check produced only generic catch-all errors and the\n // deep validator finds nothing actionable, treat the document as valid.\n if (finalErrors.length === 0) {\n finalValid = true;\n }\n }\n\n // Add document-specific metadata. Keep `data` populated whenever `valid` is\n // true so `isValidDocument()` (which requires both) stays consistent — when\n // TypeBox failed and the deep validator cleared the doc, fall back to the\n // original input as the data payload.\n const resolvedData =\n result.data ??\n (finalValid\n ? (data as Static<typeof ComponentDefinitionSchema>)\n : undefined);\n const documentResult: DocumentValidationResult = {\n ...result,\n valid: finalValid,\n documentType: 'docx',\n errors: finalErrors,\n data: resolvedData,\n };\n\n // Check if document has custom components\n if (finalValid) {\n const doc = resolvedData as any;\n if (doc && doc.children && Array.isArray(doc.children)) {\n const hasCustom = doc.children.some(\n (c: any) => !isStandardComponentName(c.name)\n );\n documentResult.hasCustomComponents = hasCustom;\n }\n }\n\n return documentResult;\n}\n\n/**\n * Validate a JSON document (string or object)\n */\nexport function validateJsonDocument(\n jsonInput: string | object,\n options?: ValidationOptions\n): DocumentValidationResult {\n // Use the JSON-specific schema which includes the $schema field\n const result = validateJson(\n JsonComponentDefinitionSchema,\n jsonInput,\n options\n );\n\n // If validation failed, use deep validation to get all detailed errors\n let finalErrors = result.errors || [];\n let finalValid = result.valid;\n if (!result.valid && result.parsed) {\n finalErrors = comprehensiveValidateDocument(result.parsed, result.errors);\n if (finalErrors.length === 0) {\n finalValid = true;\n }\n }\n\n // Add document-specific metadata. Keep `data` populated whenever `valid` is\n // true so `isValidDocument()` (which requires both) stays consistent — when\n // TypeBox failed and the deep validator cleared the doc, fall back to the\n // parsed input as the data payload.\n const resolvedData =\n result.data ??\n (finalValid\n ? (result.parsed as Static<typeof ComponentDefinitionSchema>)\n : undefined);\n const documentResult: DocumentValidationResult = {\n ...result,\n valid: finalValid,\n documentType: 'docx',\n errors: finalErrors,\n data: resolvedData,\n };\n\n // Check for custom components\n if (finalValid) {\n const doc = resolvedData as any;\n if (doc && doc.children && Array.isArray(doc.children)) {\n const hasCustom = doc.children.some(\n (c: any) => !isStandardComponentName(c.name)\n );\n documentResult.hasCustomComponents = hasCustom;\n }\n }\n\n return documentResult;\n}\n\n/**\n * Type guard for document validation result\n */\nexport function isValidDocument(\n result: DocumentValidationResult\n): result is DocumentValidationResult & {\n valid: true;\n data: Static<typeof ComponentDefinitionSchema>;\n} {\n return result.valid === true && result.data !== undefined;\n}\n\n/**\n * Extract standard component names from the schema (cached)\n */\nfunction getStandardComponentNames(): string[] {\n return extractStandardComponentNames(StandardComponentDefinitionSchema);\n}\n\n/**\n * Check if a component name is standard\n */\nfunction isStandardComponentName(name: string): boolean {\n const standardNames = getStandardComponentNames();\n return standardNames.includes(name);\n}\n\n/**\n * Create a document validator with default options\n */\nexport function createDocumentValidator(defaultOptions?: ValidationOptions) {\n return {\n validate: (data: unknown, options?: ValidationOptions) =>\n validateDocument(data, { ...defaultOptions, ...options }),\n validateJson: (jsonInput: string | object, options?: ValidationOptions) =>\n validateJsonDocument(jsonInput, { ...defaultOptions, ...options }),\n };\n}\n\n// Export convenient validators with common configurations\nexport const documentValidator = createDocumentValidator({\n clean: true,\n applyDefaults: true,\n maxErrors: 100, // Collect up to 100 errors to show all validation issues\n});\n\nexport const strictDocumentValidator = createDocumentValidator({\n clean: false,\n applyDefaults: false,\n maxErrors: 100, // Increased from 10 to show more errors\n});\n\n/**\n * Legacy compatibility exports\n */\nexport const validateJsonComponent = validateJsonDocument;\nexport const validateDocumentWithSchema = validateDocument;\n"],"mappings":";;;;;;;;;;;;;AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKP,SAAS,wBACP,OACA,SACQ;AACR,QAAM,UAAU,OAAO,MAAM,QAAQ,EAAE;AACvC,QAAM,OAAO,MAAM,QAAQ;AAG3B,MAAI,YAAY,QAAQ,YAAY,SAAS;AAC3C,WAAO,0BAA0B,KAAK;AAAA,EACxC;AAGA,MAAI,MAAM,SAAS,SAAS,sBAAsB,GAAG;AACnD,WAAO,oCAAoC,KAAK;AAAA,EAClD;AAGA,MAAI,MAAM,SAAS,SAAS,mBAAmB,GAAG;AAChD,WAAO,gCAAgC,KAAK;AAAA,EAC9C;AAGA,MACE,YAAY,YACZ,YAAY,YACZ,YAAY,aACZ,YAAY,WACZ,YAAY,UACZ;AACA,WAAO,4BAA4B,KAAK;AAAA,EAC1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SAAS,IAAI;AACpC;AAKO,SAAS,wBAAwB,gBAAoC;AAC1E,SAAO;AAAA,IACL,UAAU,CAAC,MAAe,YACxB,iBAAiB,MAAM,EAAE,GAAG,gBAAgB,GAAG,QAAQ,CAAC;AAAA,IAC1D,cAAc,CAAC,WAA4B,YACzC,qBAAqB,WAAW,EAAE,GAAG,gBAAgB,GAAG,QAAQ,CAAC;AAAA,EACrE;AACF;AAGO,IAAM,oBAAoB,wBAAwB;AAAA,EACvD,OAAO;AAAA,EACP,eAAe;AAAA,EACf,WAAW;AAAA;AACb,CAAC;AAEM,IAAM,0BAA0B,wBAAwB;AAAA,EAC7D,OAAO;AAAA,EACP,eAAe;AAAA,EACf,WAAW;AAAA;AACb,CAAC;AAKM,IAAM,wBAAwB;AAC9B,IAAM,6BAA6B;","names":["Value","transformValueErrors","result"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ComponentDefinitionSchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-M6LVAHZB.js";
|
|
4
4
|
|
|
5
5
|
// src/schemas/api.ts
|
|
6
6
|
import { Type } from "@sinclair/typebox";
|
|
@@ -94,4 +94,4 @@ export {
|
|
|
94
94
|
GenerateDocumentResponseSchema,
|
|
95
95
|
ValidateDocumentResponseSchema
|
|
96
96
|
};
|
|
97
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-PVQV2RS4.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ComponentDefinitionSchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-M6LVAHZB.js";
|
|
4
4
|
|
|
5
5
|
// src/schemas/document.ts
|
|
6
6
|
var JsonComponentDefinitionSchema = ComponentDefinitionSchema;
|
|
@@ -31,4 +31,4 @@ export {
|
|
|
31
31
|
JsonComponentDefinitionSchema,
|
|
32
32
|
JSON_SCHEMA_URLS
|
|
33
33
|
};
|
|
34
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-SMIG3LSE.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAllComponentSchemasNarrowed,
|
|
3
3
|
getStandardComponent
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YZYUY2VH.js";
|
|
5
5
|
|
|
6
6
|
// src/schemas/generator.ts
|
|
7
7
|
import { Type } from "@sinclair/typebox";
|
|
@@ -128,4 +128,4 @@ function generateUnifiedDocumentSchema(options = {}) {
|
|
|
128
128
|
export {
|
|
129
129
|
generateUnifiedDocumentSchema
|
|
130
130
|
};
|
|
131
|
-
//# sourceMappingURL=chunk-
|
|
131
|
+
//# sourceMappingURL=chunk-YRRBEJPB.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AlignmentSchema,
|
|
2
3
|
ColumnsPropsSchema,
|
|
3
4
|
ComponentDefaultsSchema,
|
|
4
5
|
FloatingPropertiesSchema,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
ListPropsSchema,
|
|
8
9
|
ParagraphPropsSchema,
|
|
9
10
|
SectionPropsSchema,
|
|
11
|
+
SpacingSchema,
|
|
10
12
|
StatisticPropsSchema,
|
|
11
13
|
TablePropsSchema,
|
|
12
14
|
createSectionPropsSchema,
|
|
@@ -17,7 +19,7 @@ import {
|
|
|
17
19
|
} from "./chunk-H56RLQOF.js";
|
|
18
20
|
|
|
19
21
|
// src/schemas/component-registry.ts
|
|
20
|
-
import { Type as
|
|
22
|
+
import { Type as Type6 } from "@sinclair/typebox";
|
|
21
23
|
|
|
22
24
|
// src/schemas/components/report.ts
|
|
23
25
|
import { Type } from "@sinclair/typebox";
|
|
@@ -411,6 +413,129 @@ var HighchartsPropsSchema = Type4.Object({
|
|
|
411
413
|
)
|
|
412
414
|
});
|
|
413
415
|
|
|
416
|
+
// src/schemas/components/visual.ts
|
|
417
|
+
import { Type as Type5 } from "@sinclair/typebox";
|
|
418
|
+
import {
|
|
419
|
+
MIN_VISUAL_DPI,
|
|
420
|
+
MAX_VISUAL_DPI,
|
|
421
|
+
DEFAULT_VISUAL_DPI
|
|
422
|
+
} from "@json-to-office/shared";
|
|
423
|
+
import { PptxSlideContentSchema } from "@json-to-office/shared-pptx";
|
|
424
|
+
var VisualCanvasBackgroundSchema = Type5.Object(
|
|
425
|
+
{
|
|
426
|
+
color: Type5.Optional(
|
|
427
|
+
Type5.String({
|
|
428
|
+
description: 'Background color (hex like "#FFFFFF" or a theme color name)'
|
|
429
|
+
})
|
|
430
|
+
),
|
|
431
|
+
image: Type5.Optional(
|
|
432
|
+
Type5.Object(
|
|
433
|
+
{
|
|
434
|
+
path: Type5.Optional(Type5.String()),
|
|
435
|
+
base64: Type5.Optional(Type5.String())
|
|
436
|
+
},
|
|
437
|
+
{ additionalProperties: false }
|
|
438
|
+
)
|
|
439
|
+
)
|
|
440
|
+
},
|
|
441
|
+
{ additionalProperties: false }
|
|
442
|
+
);
|
|
443
|
+
var VisualCanvasSchema = Type5.Object(
|
|
444
|
+
{
|
|
445
|
+
width: Type5.Number({
|
|
446
|
+
minimum: 0.1,
|
|
447
|
+
description: "Canvas width in inches (pptx slideWidth)"
|
|
448
|
+
}),
|
|
449
|
+
height: Type5.Number({
|
|
450
|
+
minimum: 0.1,
|
|
451
|
+
description: "Canvas height in inches (pptx slideHeight)"
|
|
452
|
+
}),
|
|
453
|
+
theme: Type5.Optional(
|
|
454
|
+
Type5.String({ description: "pptx theme name applied to the slide" })
|
|
455
|
+
),
|
|
456
|
+
background: Type5.Optional(VisualCanvasBackgroundSchema)
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
description: "pptx canvas definition for the visual",
|
|
460
|
+
additionalProperties: false
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
var VisualPropsSchema = Type5.Object(
|
|
464
|
+
{
|
|
465
|
+
// ── canvas (drives aspect ratio + physical size) ──
|
|
466
|
+
canvas: VisualCanvasSchema,
|
|
467
|
+
// pptx slide content elements, absolutely positioned on the canvas
|
|
468
|
+
elements: Type5.Optional(
|
|
469
|
+
Type5.Array(PptxSlideContentSchema, {
|
|
470
|
+
description: "pptx slide content elements (text, image, shape, table, highcharts, chart), positioned with x/y/w/h in inches"
|
|
471
|
+
})
|
|
472
|
+
),
|
|
473
|
+
// ── rasterization ──
|
|
474
|
+
dpi: Type5.Optional(
|
|
475
|
+
Type5.Number({
|
|
476
|
+
minimum: MIN_VISUAL_DPI,
|
|
477
|
+
maximum: MAX_VISUAL_DPI,
|
|
478
|
+
default: DEFAULT_VISUAL_DPI,
|
|
479
|
+
description: `Raster resolution in DPI (default ${DEFAULT_VISUAL_DPI}, range ${MIN_VISUAL_DPI}-${MAX_VISUAL_DPI}). Higher = sharper + larger.`
|
|
480
|
+
})
|
|
481
|
+
),
|
|
482
|
+
serverUrl: Type5.Optional(
|
|
483
|
+
Type5.String({
|
|
484
|
+
description: "Rasterization service URL override (default from services.pptx)"
|
|
485
|
+
})
|
|
486
|
+
),
|
|
487
|
+
// ── placement in the document (mirrors `image`) ──
|
|
488
|
+
width: Type5.Optional(
|
|
489
|
+
Type5.Union(
|
|
490
|
+
[
|
|
491
|
+
Type5.Number({ minimum: 1, description: "Rendered width in pixels" }),
|
|
492
|
+
Type5.String({
|
|
493
|
+
pattern: "^\\d+(\\.\\d+)?%$",
|
|
494
|
+
description: 'Rendered width as percentage (e.g. "90%")'
|
|
495
|
+
})
|
|
496
|
+
],
|
|
497
|
+
{
|
|
498
|
+
description: "Rendered width in the document, in pixels (number) or percentage string. Defaults to the canvas physical size."
|
|
499
|
+
}
|
|
500
|
+
)
|
|
501
|
+
),
|
|
502
|
+
height: Type5.Optional(
|
|
503
|
+
Type5.Union([
|
|
504
|
+
Type5.Number({ minimum: 1, description: "Rendered height in pixels" }),
|
|
505
|
+
Type5.String({
|
|
506
|
+
pattern: "^\\d+(\\.\\d+)?%$",
|
|
507
|
+
description: 'Rendered height as percentage (e.g. "90%")'
|
|
508
|
+
})
|
|
509
|
+
])
|
|
510
|
+
),
|
|
511
|
+
alignment: Type5.Optional(AlignmentSchema),
|
|
512
|
+
caption: Type5.Optional(
|
|
513
|
+
Type5.String({
|
|
514
|
+
description: "Caption (supports rich text with **bold**, *italic*, ***both***)"
|
|
515
|
+
})
|
|
516
|
+
),
|
|
517
|
+
alt: Type5.Optional(
|
|
518
|
+
Type5.String({ description: "Alternative text for accessibility" })
|
|
519
|
+
),
|
|
520
|
+
spacing: Type5.Optional(SpacingSchema),
|
|
521
|
+
floating: Type5.Optional(FloatingPropertiesSchema),
|
|
522
|
+
keepNext: Type5.Optional(
|
|
523
|
+
Type5.Boolean({
|
|
524
|
+
description: "Keep paragraph with next paragraph on same page"
|
|
525
|
+
})
|
|
526
|
+
),
|
|
527
|
+
keepLines: Type5.Optional(
|
|
528
|
+
Type5.Boolean({
|
|
529
|
+
description: "Keep all lines of paragraph together on same page"
|
|
530
|
+
})
|
|
531
|
+
)
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
description: "Visual component props (pptx-rendered graphic)",
|
|
535
|
+
additionalProperties: false
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
|
|
414
539
|
// src/schemas/component-registry.ts
|
|
415
540
|
var STANDARD_COMPONENTS_REGISTRY = [
|
|
416
541
|
// ========================================================================
|
|
@@ -442,6 +567,7 @@ var STANDARD_COMPONENTS_REGISTRY = [
|
|
|
442
567
|
"list",
|
|
443
568
|
"toc",
|
|
444
569
|
"highcharts",
|
|
570
|
+
"visual",
|
|
445
571
|
"columns",
|
|
446
572
|
"text-box"
|
|
447
573
|
],
|
|
@@ -461,6 +587,7 @@ var STANDARD_COMPONENTS_REGISTRY = [
|
|
|
461
587
|
"list",
|
|
462
588
|
"toc",
|
|
463
589
|
"highcharts",
|
|
590
|
+
"visual",
|
|
464
591
|
"text-box"
|
|
465
592
|
],
|
|
466
593
|
category: "layout",
|
|
@@ -533,6 +660,13 @@ var STANDARD_COMPONENTS_REGISTRY = [
|
|
|
533
660
|
hasChildren: false,
|
|
534
661
|
category: "content",
|
|
535
662
|
description: "Chart component powered by Highcharts - render line, bar, pie, heatmap, and more with rich options."
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
name: "visual",
|
|
666
|
+
propsSchema: VisualPropsSchema,
|
|
667
|
+
hasChildren: false,
|
|
668
|
+
category: "content",
|
|
669
|
+
description: "Free-canvas graphic authored as a single pptx slide and embedded as a rasterized PNG. Use for infographics, diagrams and layered compositions that the document flow cannot express."
|
|
536
670
|
}
|
|
537
671
|
];
|
|
538
672
|
function getStandardComponent(name) {
|
|
@@ -555,23 +689,23 @@ function isStandardComponent(name) {
|
|
|
555
689
|
}
|
|
556
690
|
function createComponentSchemaObject(component, childrenType, selfRef) {
|
|
557
691
|
const schema = {
|
|
558
|
-
name:
|
|
559
|
-
id:
|
|
560
|
-
enabled:
|
|
561
|
-
|
|
692
|
+
name: Type6.Literal(component.name),
|
|
693
|
+
id: Type6.Optional(Type6.String()),
|
|
694
|
+
enabled: Type6.Optional(
|
|
695
|
+
Type6.Boolean({
|
|
562
696
|
default: true,
|
|
563
697
|
description: "When false, this component is filtered out and not rendered. Defaults to true. Useful for conditional component inclusion."
|
|
564
698
|
})
|
|
565
699
|
)
|
|
566
700
|
};
|
|
567
701
|
if (component.special?.hasSchemaField) {
|
|
568
|
-
schema.$schema =
|
|
702
|
+
schema.$schema = Type6.Optional(Type6.String({ format: "uri" }));
|
|
569
703
|
}
|
|
570
704
|
schema.props = component.createPropsSchema && selfRef ? component.createPropsSchema(selfRef) : component.propsSchema;
|
|
571
705
|
if (component.hasChildren && childrenType) {
|
|
572
|
-
schema.children =
|
|
706
|
+
schema.children = Type6.Optional(Type6.Array(childrenType));
|
|
573
707
|
}
|
|
574
|
-
return
|
|
708
|
+
return Type6.Object(schema, { additionalProperties: false });
|
|
575
709
|
}
|
|
576
710
|
function createAllComponentSchemas(recursiveRef) {
|
|
577
711
|
return STANDARD_COMPONENTS_REGISTRY.map(
|
|
@@ -609,7 +743,7 @@ function createAllComponentSchemasNarrowed(selfRef, pluginSchemas = []) {
|
|
|
609
743
|
if (!containerDeps.every((d) => resolved.has(d))) continue;
|
|
610
744
|
const childSchemas = comp.allowedChildren.map((name) => resolved.get(name) ?? leafSchemas.get(name)).filter((s) => s !== void 0);
|
|
611
745
|
const allChildSchemas = [...childSchemas, ...pluginSchemas];
|
|
612
|
-
const childrenType = allChildSchemas.length === 1 ? allChildSchemas[0] :
|
|
746
|
+
const childrenType = allChildSchemas.length === 1 ? allChildSchemas[0] : Type6.Union(allChildSchemas);
|
|
613
747
|
resolved.set(
|
|
614
748
|
comp.name,
|
|
615
749
|
createComponentSchemaObject(comp, childrenType, selfRef)
|
|
@@ -636,6 +770,9 @@ export {
|
|
|
636
770
|
TocDepthRangeSchema,
|
|
637
771
|
TocPropsSchema,
|
|
638
772
|
HighchartsPropsSchema,
|
|
773
|
+
VisualCanvasBackgroundSchema,
|
|
774
|
+
VisualCanvasSchema,
|
|
775
|
+
VisualPropsSchema,
|
|
639
776
|
STANDARD_COMPONENTS_REGISTRY,
|
|
640
777
|
getStandardComponent,
|
|
641
778
|
getAllStandardComponentNames,
|
|
@@ -647,4 +784,4 @@ export {
|
|
|
647
784
|
createAllComponentSchemas,
|
|
648
785
|
createAllComponentSchemasNarrowed
|
|
649
786
|
};
|
|
650
|
-
//# sourceMappingURL=chunk-
|
|
787
|
+
//# sourceMappingURL=chunk-YZYUY2VH.js.map
|