@json-to-office/shared-docx 0.21.0 → 0.23.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-QR4I4ZNV.js → chunk-2TQ74H6S.js} +2 -2
- package/dist/{chunk-QNIC7H4H.js → chunk-3JOBFRYR.js} +62 -4
- package/dist/{chunk-QNIC7H4H.js.map → chunk-3JOBFRYR.js.map} +1 -1
- package/dist/{chunk-K5USZWUG.js → chunk-7636IMZ5.js} +2 -2
- package/dist/{chunk-YSDZJNWV.js → chunk-FNCLWYTA.js} +2 -2
- package/dist/{chunk-RV6RFQQP.js → chunk-GJBRYTGZ.js} +6 -6
- package/dist/{chunk-CO76J5GZ.js → chunk-HTOT7PVC.js} +3 -3
- package/dist/{chunk-2NLQPZ4G.js → chunk-KNMPYZUO.js} +2 -2
- package/dist/{chunk-2NLQPZ4G.js.map → chunk-KNMPYZUO.js.map} +1 -1
- package/dist/{chunk-3KZ3BI25.js → chunk-S4TSENRQ.js} +26 -10
- package/dist/chunk-S4TSENRQ.js.map +1 -0
- package/dist/{chunk-TFPNI2DM.js → chunk-U7UNC7QH.js} +2 -2
- package/dist/{chunk-OQCQOBHB.js → chunk-YQE7H4H4.js} +6 -3
- package/dist/{chunk-OQCQOBHB.js.map → chunk-YQE7H4H4.js.map} +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/schemas/api.js +4 -4
- package/dist/schemas/component-defaults.js +1 -1
- package/dist/schemas/component-registry.js +2 -2
- package/dist/schemas/components.d.ts +5 -4
- package/dist/schemas/components.js +3 -3
- package/dist/schemas/document.js +5 -5
- package/dist/schemas/export.js +3 -3
- package/dist/schemas/generator.js +3 -3
- package/dist/schemas/theme.d.ts +19 -1
- package/dist/schemas/theme.js +4 -2
- package/dist/validation/unified/index.d.ts +0 -2
- package/dist/validation/unified/index.js +6 -6
- package/package.json +2 -2
- package/dist/chunk-3KZ3BI25.js.map +0 -1
- /package/dist/{chunk-QR4I4ZNV.js.map → chunk-2TQ74H6S.js.map} +0 -0
- /package/dist/{chunk-K5USZWUG.js.map → chunk-7636IMZ5.js.map} +0 -0
- /package/dist/{chunk-YSDZJNWV.js.map → chunk-FNCLWYTA.js.map} +0 -0
- /package/dist/{chunk-RV6RFQQP.js.map → chunk-GJBRYTGZ.js.map} +0 -0
- /package/dist/{chunk-CO76J5GZ.js.map → chunk-HTOT7PVC.js.map} +0 -0
- /package/dist/{chunk-TFPNI2DM.js.map → chunk-U7UNC7QH.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getContainerComponents
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-S4TSENRQ.js";
|
|
4
4
|
|
|
5
5
|
// src/schemas/export.ts
|
|
6
6
|
function fixSchemaReferences(schema, rootDefinitionName = "ComponentDefinition") {
|
|
@@ -272,4 +272,4 @@ export {
|
|
|
272
272
|
BASE_SCHEMA_METADATA,
|
|
273
273
|
THEME_SCHEMA_METADATA
|
|
274
274
|
};
|
|
275
|
-
//# sourceMappingURL=chunk-
|
|
275
|
+
//# sourceMappingURL=chunk-U7UNC7QH.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAllComponentSchemasNarrowed,
|
|
3
3
|
getStandardComponent
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-S4TSENRQ.js";
|
|
5
5
|
|
|
6
6
|
// src/schemas/generator.ts
|
|
7
7
|
import { Type } from "@sinclair/typebox";
|
|
@@ -107,7 +107,10 @@ function generateUnifiedDocumentSchema(options = {}) {
|
|
|
107
107
|
name: Type.Literal("docx"),
|
|
108
108
|
id: Type.Optional(Type.String()),
|
|
109
109
|
$schema: Type.Optional(Type.String({ format: "uri" })),
|
|
110
|
-
|
|
110
|
+
// Optional so the exported schema agrees with the runtime validator and
|
|
111
|
+
// the generator, both of which treat a propless root as `props: {}`.
|
|
112
|
+
// Schema-driven editors would otherwise flag a document that builds.
|
|
113
|
+
props: Type.Optional(reportComponent.propsSchema),
|
|
111
114
|
children: Type.Optional(
|
|
112
115
|
Type.Array(
|
|
113
116
|
capturedPluginSchemas.length > 0 ? Type.Union([capturedSectionSchema, ...capturedPluginSchemas]) : capturedSectionSchema
|
|
@@ -128,4 +131,4 @@ function generateUnifiedDocumentSchema(options = {}) {
|
|
|
128
131
|
export {
|
|
129
132
|
generateUnifiedDocumentSchema
|
|
130
133
|
};
|
|
131
|
-
//# sourceMappingURL=chunk-
|
|
134
|
+
//# sourceMappingURL=chunk-YQE7H4H4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas/generator.ts"],"sourcesContent":["/**\n * Unified Document Schema Generator - SHARED UTILITY\n *\n * This is the SHARED implementation for generating document schemas.\n * It's used by MULTIPLE CONSUMERS with different requirements:\n *\n * 1. BUILD-TIME: generate-schemas.mjs uses this to create static .schema.json files\n * - Only standard components (no custom components available at build time)\n * - Outputs to filesystem for IDE autocomplete\n *\n * 2. RUNTIME PLUGIN: plugin/schema.ts uses this for plugin-enhanced schemas\n * - Includes custom components registered at runtime\n * - Cannot be generated at build time (components must be instantiated)\n *\n * 3. WEB APP: Monaco editor may use this for in-browser validation\n * - Optimized for browser environment\n * - No filesystem access\n *\n * This separation is ARCHITECTURAL, not accidental:\n * - Build-time vs runtime constraints are incompatible\n * - Custom components require runtime instantiation\n * - Different consumers need different output formats\n *\n * IMPORTANT: Standard components are defined in component-registry.ts (SINGLE SOURCE OF TRUTH).\n * This generator consumes that registry to ensure consistency across all schema generation.\n */\n\nimport { Type, TSchema } from '@sinclair/typebox';\nimport {\n createAllComponentSchemasNarrowed,\n getStandardComponent,\n} from './component-registry';\nimport { latestVersion } from '@json-to-office/shared';\n\n/**\n * Per-version props schema entry\n */\nexport interface VersionedPropsEntry {\n version: string;\n propsSchema: TSchema;\n hasChildren?: boolean;\n description?: string;\n}\n\n/**\n * Custom component interface for plugins\n */\nexport interface CustomComponentInfo {\n name: string;\n propsSchema: TSchema;\n /** When true, the component includes an optional `children` array */\n hasChildren?: boolean;\n /** Human-readable description shown in autocomplete */\n description?: string;\n /**\n * Per-version props schemas for version-discriminated validation.\n * When provided, separate schema variants are generated per version,\n * each pairing its version literal with its specific props schema.\n * A \"no version\" fallback variant uses the latest version's props.\n */\n versionedProps?: VersionedPropsEntry[];\n}\n\n/**\n * Options for generating document schema\n */\nexport interface GenerateDocumentSchemaOptions {\n includeStandardComponents?: boolean;\n includeTheme?: boolean;\n customComponents?: CustomComponentInfo[];\n title?: string;\n description?: string;\n}\n\n/**\n * Generate a complete document schema with all components\n *\n * This is the SHARED IMPLEMENTATION used by:\n * - Build-time schema generation (standard components only)\n * - Runtime plugin schema generation (with custom components)\n * - Web app schema generation (optimized for browser)\n *\n * @param options Configuration for what to include in the schema\n * @returns TypeBox schema that can be converted to JSON Schema\n */\nexport function generateUnifiedDocumentSchema(\n options: GenerateDocumentSchemaOptions = {}\n): TSchema {\n const {\n includeStandardComponents = true,\n customComponents = [],\n title = 'JSON Report Definition',\n description = 'JSON report definition with TypeBox schemas',\n } = options;\n\n // Captured from inside the recursive callback for the root's children.\n let capturedSectionSchema: TSchema | undefined;\n let capturedPluginSchemas: TSchema[] = [];\n\n // Create a recursive component definition schema\n const ComponentDefinition = Type.Recursive(\n (This) => {\n // ── Phase 1: Build plugin schemas (plugins get Self for arbitrary nesting) ──\n const pluginSchemas: TSchema[] = [];\n\n for (const customComponent of customComponents) {\n if (\n customComponent.versionedProps &&\n customComponent.versionedProps.length > 0\n ) {\n // Version-discriminated: one variant per version + one \"no version\" fallback\n const versionEntries = customComponent.versionedProps;\n const latest = latestVersion(versionEntries.map((e) => e.version));\n\n // Per-version variants: version is required, props are version-specific\n for (const entry of versionEntries) {\n const versionLiteralDesc =\n entry.description || customComponent.description;\n const schema: Record<string, TSchema> = {\n name: Type.Literal(customComponent.name),\n id: Type.Optional(Type.String()),\n version: versionLiteralDesc\n ? Type.Literal(entry.version, {\n description: versionLiteralDesc,\n })\n : Type.Literal(entry.version),\n props: entry.propsSchema,\n };\n if (entry.hasChildren) {\n schema.children = Type.Optional(Type.Array(This));\n }\n const versionDesc = entry.description\n ? `${customComponent.name} v${entry.version} — ${entry.description}`\n : customComponent.description\n ? `${customComponent.name} v${entry.version} — ${customComponent.description}`\n : `${customComponent.name} v${entry.version}`;\n pluginSchemas.push(\n Type.Object(schema, {\n additionalProperties: false,\n description: versionDesc,\n })\n );\n }\n\n // \"No version\" fallback: version is NOT allowed, uses latest props\n const latestEntry = versionEntries.find((e) => e.version === latest)!;\n const fallbackSchema: Record<string, TSchema> = {\n name: Type.Literal(customComponent.name),\n id: Type.Optional(Type.String()),\n props: latestEntry.propsSchema,\n };\n if (latestEntry.hasChildren) {\n fallbackSchema.children = Type.Optional(Type.Array(This));\n }\n const fallbackDesc = latestEntry.description\n ? `${customComponent.name} (latest: v${latest}) — ${latestEntry.description}`\n : customComponent.description\n ? `${customComponent.name} (latest: v${latest}) — ${customComponent.description}`\n : `${customComponent.name} (latest: v${latest})`;\n pluginSchemas.push(\n Type.Object(fallbackSchema, {\n additionalProperties: false,\n description: fallbackDesc,\n })\n );\n } else {\n // Non-versioned component: single variant\n const hasChildren = !!customComponent.hasChildren;\n const schema: Record<string, TSchema> = {\n name: Type.Literal(customComponent.name),\n id: Type.Optional(Type.String()),\n props: customComponent.propsSchema,\n };\n if (hasChildren) {\n schema.children = Type.Optional(Type.Array(This));\n }\n pluginSchemas.push(\n Type.Object(schema, {\n additionalProperties: false,\n ...(customComponent.description\n ? { description: customComponent.description }\n : {}),\n })\n );\n }\n }\n\n // ── Phase 2: Build standard components with narrowed children ──\n const { schemas: standardSchemas, byName } = includeStandardComponents\n ? createAllComponentSchemasNarrowed(This, pluginSchemas)\n : { schemas: [] as TSchema[], byName: new Map<string, TSchema>() };\n\n // Capture the narrowed section schema + plugins for the root's children.\n // Must happen inside the callback while standardSchemas is available.\n capturedSectionSchema = byName.get('section');\n capturedPluginSchemas = pluginSchemas;\n\n const componentSchemas = [...standardSchemas, ...pluginSchemas];\n\n // Create the union based on the number of schemas\n if (componentSchemas.length === 0) {\n return Type.Any();\n } else if (componentSchemas.length === 1) {\n return componentSchemas[0];\n } else {\n const componentDescription =\n customComponents.length > 0\n ? 'Component definition with discriminated union including custom components'\n : 'Component definition with discriminated union';\n\n return Type.Union(componentSchemas, {\n discriminator: { propertyName: 'name' },\n description: componentDescription,\n });\n }\n },\n { $id: 'ComponentDefinition' }\n );\n\n // Build root docx schema with narrowed children (section only).\n // ComponentDefinition is embedded in `definitions` so that $refs inside\n // section header/footer and table cell content resolve correctly.\n const reportComponent = getStandardComponent('docx');\n if (!reportComponent) {\n throw new Error('Docx root component not found in registry');\n }\n\n if (!capturedSectionSchema) {\n throw new Error('Section schema not found in narrowed standard schemas');\n }\n\n return Type.Object(\n {\n name: Type.Literal('docx'),\n id: Type.Optional(Type.String()),\n $schema: Type.Optional(Type.String({ format: 'uri' })),\n props: reportComponent.propsSchema,\n children: Type.Optional(\n Type.Array(\n capturedPluginSchemas.length > 0\n ? Type.Union([capturedSectionSchema, ...capturedPluginSchemas])\n : capturedSectionSchema\n )\n ),\n },\n {\n additionalProperties: false,\n title,\n description,\n // Embed ComponentDefinition so convertToJsonSchema extracts it to\n // definitions and bare $ref: \"ComponentDefinition\" values resolve.\n definitions: { ComponentDefinition },\n } as Record<string, unknown>\n );\n}\n"],"mappings":";;;;;;AA2BA,SAAS,YAAqB;AAK9B,SAAS,qBAAqB;AAqDvB,SAAS,8BACd,UAAyC,CAAC,GACjC;AACT,QAAM;AAAA,IACJ,4BAA4B;AAAA,IAC5B,mBAAmB,CAAC;AAAA,IACpB,QAAQ;AAAA,IACR,cAAc;AAAA,EAChB,IAAI;AAGJ,MAAI;AACJ,MAAI,wBAAmC,CAAC;AAGxC,QAAM,sBAAsB,KAAK;AAAA,IAC/B,CAAC,SAAS;AAER,YAAM,gBAA2B,CAAC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N,eAAO,KAAK,MAAM,kBAAkB;AAAA,UAClC,eAAe,EAAE,cAAc,OAAO;AAAA,UACtC,aAAa;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,KAAK,sBAAsB;AAAA,EAC/B;AAKA,QAAM,kBAAkB,qBAAqB,MAAM;AACnD,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AAEA,MAAI,CAAC,uBAAuB;AAC1B,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO,KAAK;AAAA,IACV;AAAA,MACE,MAAM,KAAK,QAAQ,MAAM;AAAA,MACzB,IAAI,KAAK,SAAS,KAAK,OAAO,CAAC;AAAA,MAC/B,SAAS,KAAK,SAAS,KAAK,OAAO,EAAE,QAAQ,MAAM,CAAC,CAAC;AAAA,MACrD,OAAO,gBAAgB;AAAA,MACvB,UAAU,KAAK;AAAA,QACb,KAAK;AAAA,UACH,sBAAsB,SAAS,IAC3B,KAAK,MAAM,CAAC,uBAAuB,GAAG,qBAAqB,CAAC,IAC5D;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,sBAAsB;AAAA,MACtB;AAAA,MACA;AAAA;AAAA;AAAA,MAGA,aAAa,EAAE,oBAAoB;AAAA,IACrC;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/schemas/generator.ts"],"sourcesContent":["/**\n * Unified Document Schema Generator - SHARED UTILITY\n *\n * This is the SHARED implementation for generating document schemas.\n * It's used by MULTIPLE CONSUMERS with different requirements:\n *\n * 1. BUILD-TIME: generate-schemas.mjs uses this to create static .schema.json files\n * - Only standard components (no custom components available at build time)\n * - Outputs to filesystem for IDE autocomplete\n *\n * 2. RUNTIME PLUGIN: plugin/schema.ts uses this for plugin-enhanced schemas\n * - Includes custom components registered at runtime\n * - Cannot be generated at build time (components must be instantiated)\n *\n * 3. WEB APP: Monaco editor may use this for in-browser validation\n * - Optimized for browser environment\n * - No filesystem access\n *\n * This separation is ARCHITECTURAL, not accidental:\n * - Build-time vs runtime constraints are incompatible\n * - Custom components require runtime instantiation\n * - Different consumers need different output formats\n *\n * IMPORTANT: Standard components are defined in component-registry.ts (SINGLE SOURCE OF TRUTH).\n * This generator consumes that registry to ensure consistency across all schema generation.\n */\n\nimport { Type, TSchema } from '@sinclair/typebox';\nimport {\n createAllComponentSchemasNarrowed,\n getStandardComponent,\n} from './component-registry';\nimport { latestVersion } from '@json-to-office/shared';\n\n/**\n * Per-version props schema entry\n */\nexport interface VersionedPropsEntry {\n version: string;\n propsSchema: TSchema;\n hasChildren?: boolean;\n description?: string;\n}\n\n/**\n * Custom component interface for plugins\n */\nexport interface CustomComponentInfo {\n name: string;\n propsSchema: TSchema;\n /** When true, the component includes an optional `children` array */\n hasChildren?: boolean;\n /** Human-readable description shown in autocomplete */\n description?: string;\n /**\n * Per-version props schemas for version-discriminated validation.\n * When provided, separate schema variants are generated per version,\n * each pairing its version literal with its specific props schema.\n * A \"no version\" fallback variant uses the latest version's props.\n */\n versionedProps?: VersionedPropsEntry[];\n}\n\n/**\n * Options for generating document schema\n */\nexport interface GenerateDocumentSchemaOptions {\n includeStandardComponents?: boolean;\n includeTheme?: boolean;\n customComponents?: CustomComponentInfo[];\n title?: string;\n description?: string;\n}\n\n/**\n * Generate a complete document schema with all components\n *\n * This is the SHARED IMPLEMENTATION used by:\n * - Build-time schema generation (standard components only)\n * - Runtime plugin schema generation (with custom components)\n * - Web app schema generation (optimized for browser)\n *\n * @param options Configuration for what to include in the schema\n * @returns TypeBox schema that can be converted to JSON Schema\n */\nexport function generateUnifiedDocumentSchema(\n options: GenerateDocumentSchemaOptions = {}\n): TSchema {\n const {\n includeStandardComponents = true,\n customComponents = [],\n title = 'JSON Report Definition',\n description = 'JSON report definition with TypeBox schemas',\n } = options;\n\n // Captured from inside the recursive callback for the root's children.\n let capturedSectionSchema: TSchema | undefined;\n let capturedPluginSchemas: TSchema[] = [];\n\n // Create a recursive component definition schema\n const ComponentDefinition = Type.Recursive(\n (This) => {\n // ── Phase 1: Build plugin schemas (plugins get Self for arbitrary nesting) ──\n const pluginSchemas: TSchema[] = [];\n\n for (const customComponent of customComponents) {\n if (\n customComponent.versionedProps &&\n customComponent.versionedProps.length > 0\n ) {\n // Version-discriminated: one variant per version + one \"no version\" fallback\n const versionEntries = customComponent.versionedProps;\n const latest = latestVersion(versionEntries.map((e) => e.version));\n\n // Per-version variants: version is required, props are version-specific\n for (const entry of versionEntries) {\n const versionLiteralDesc =\n entry.description || customComponent.description;\n const schema: Record<string, TSchema> = {\n name: Type.Literal(customComponent.name),\n id: Type.Optional(Type.String()),\n version: versionLiteralDesc\n ? Type.Literal(entry.version, {\n description: versionLiteralDesc,\n })\n : Type.Literal(entry.version),\n props: entry.propsSchema,\n };\n if (entry.hasChildren) {\n schema.children = Type.Optional(Type.Array(This));\n }\n const versionDesc = entry.description\n ? `${customComponent.name} v${entry.version} — ${entry.description}`\n : customComponent.description\n ? `${customComponent.name} v${entry.version} — ${customComponent.description}`\n : `${customComponent.name} v${entry.version}`;\n pluginSchemas.push(\n Type.Object(schema, {\n additionalProperties: false,\n description: versionDesc,\n })\n );\n }\n\n // \"No version\" fallback: version is NOT allowed, uses latest props\n const latestEntry = versionEntries.find((e) => e.version === latest)!;\n const fallbackSchema: Record<string, TSchema> = {\n name: Type.Literal(customComponent.name),\n id: Type.Optional(Type.String()),\n props: latestEntry.propsSchema,\n };\n if (latestEntry.hasChildren) {\n fallbackSchema.children = Type.Optional(Type.Array(This));\n }\n const fallbackDesc = latestEntry.description\n ? `${customComponent.name} (latest: v${latest}) — ${latestEntry.description}`\n : customComponent.description\n ? `${customComponent.name} (latest: v${latest}) — ${customComponent.description}`\n : `${customComponent.name} (latest: v${latest})`;\n pluginSchemas.push(\n Type.Object(fallbackSchema, {\n additionalProperties: false,\n description: fallbackDesc,\n })\n );\n } else {\n // Non-versioned component: single variant\n const hasChildren = !!customComponent.hasChildren;\n const schema: Record<string, TSchema> = {\n name: Type.Literal(customComponent.name),\n id: Type.Optional(Type.String()),\n props: customComponent.propsSchema,\n };\n if (hasChildren) {\n schema.children = Type.Optional(Type.Array(This));\n }\n pluginSchemas.push(\n Type.Object(schema, {\n additionalProperties: false,\n ...(customComponent.description\n ? { description: customComponent.description }\n : {}),\n })\n );\n }\n }\n\n // ── Phase 2: Build standard components with narrowed children ──\n const { schemas: standardSchemas, byName } = includeStandardComponents\n ? createAllComponentSchemasNarrowed(This, pluginSchemas)\n : { schemas: [] as TSchema[], byName: new Map<string, TSchema>() };\n\n // Capture the narrowed section schema + plugins for the root's children.\n // Must happen inside the callback while standardSchemas is available.\n capturedSectionSchema = byName.get('section');\n capturedPluginSchemas = pluginSchemas;\n\n const componentSchemas = [...standardSchemas, ...pluginSchemas];\n\n // Create the union based on the number of schemas\n if (componentSchemas.length === 0) {\n return Type.Any();\n } else if (componentSchemas.length === 1) {\n return componentSchemas[0];\n } else {\n const componentDescription =\n customComponents.length > 0\n ? 'Component definition with discriminated union including custom components'\n : 'Component definition with discriminated union';\n\n return Type.Union(componentSchemas, {\n discriminator: { propertyName: 'name' },\n description: componentDescription,\n });\n }\n },\n { $id: 'ComponentDefinition' }\n );\n\n // Build root docx schema with narrowed children (section only).\n // ComponentDefinition is embedded in `definitions` so that $refs inside\n // section header/footer and table cell content resolve correctly.\n const reportComponent = getStandardComponent('docx');\n if (!reportComponent) {\n throw new Error('Docx root component not found in registry');\n }\n\n if (!capturedSectionSchema) {\n throw new Error('Section schema not found in narrowed standard schemas');\n }\n\n return Type.Object(\n {\n name: Type.Literal('docx'),\n id: Type.Optional(Type.String()),\n $schema: Type.Optional(Type.String({ format: 'uri' })),\n // Optional so the exported schema agrees with the runtime validator and\n // the generator, both of which treat a propless root as `props: {}`.\n // Schema-driven editors would otherwise flag a document that builds.\n props: Type.Optional(reportComponent.propsSchema),\n children: Type.Optional(\n Type.Array(\n capturedPluginSchemas.length > 0\n ? Type.Union([capturedSectionSchema, ...capturedPluginSchemas])\n : capturedSectionSchema\n )\n ),\n },\n {\n additionalProperties: false,\n title,\n description,\n // Embed ComponentDefinition so convertToJsonSchema extracts it to\n // definitions and bare $ref: \"ComponentDefinition\" values resolve.\n definitions: { ComponentDefinition },\n } as Record<string, unknown>\n );\n}\n"],"mappings":";;;;;;AA2BA,SAAS,YAAqB;AAK9B,SAAS,qBAAqB;AAqDvB,SAAS,8BACd,UAAyC,CAAC,GACjC;AACT,QAAM;AAAA,IACJ,4BAA4B;AAAA,IAC5B,mBAAmB,CAAC;AAAA,IACpB,QAAQ;AAAA,IACR,cAAc;AAAA,EAChB,IAAI;AAGJ,MAAI;AACJ,MAAI,wBAAmC,CAAC;AAGxC,QAAM,sBAAsB,KAAK;AAAA,IAC/B,CAAC,SAAS;AAER,YAAM,gBAA2B,CAAC;AAElC,iBAAW,mBAAmB,kBAAkB;AAC9C,YACE,gBAAgB,kBAChB,gBAAgB,eAAe,SAAS,GACxC;AAEA,gBAAM,iBAAiB,gBAAgB;AACvC,gBAAM,SAAS,cAAc,eAAe,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;AAGjE,qBAAW,SAAS,gBAAgB;AAClC,kBAAM,qBACJ,MAAM,eAAe,gBAAgB;AACvC,kBAAM,SAAkC;AAAA,cACtC,MAAM,KAAK,QAAQ,gBAAgB,IAAI;AAAA,cACvC,IAAI,KAAK,SAAS,KAAK,OAAO,CAAC;AAAA,cAC/B,SAAS,qBACL,KAAK,QAAQ,MAAM,SAAS;AAAA,gBAC1B,aAAa;AAAA,cACf,CAAC,IACD,KAAK,QAAQ,MAAM,OAAO;AAAA,cAC9B,OAAO,MAAM;AAAA,YACf;AACA,gBAAI,MAAM,aAAa;AACrB,qBAAO,WAAW,KAAK,SAAS,KAAK,MAAM,IAAI,CAAC;AAAA,YAClD;AACA,kBAAM,cAAc,MAAM,cACtB,GAAG,gBAAgB,IAAI,KAAK,MAAM,OAAO,WAAM,MAAM,WAAW,KAChE,gBAA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,CAAC,IAC5D;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,sBAAsB;AAAA,MACtB;AAAA,MACA;AAAA;AAAA;AAAA,MAGA,aAAa,EAAE,oBAAoB;AAAA,IACrC;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { Alignment, AlignmentSchema, BaseComponentProps, BaseComponentPropsSchem
|
|
|
3
3
|
export { AddWarningFunction, ComponentSchemaConfig, DEFAULT_ERROR_CONFIG, ERROR_EMOJIS, ErrorFormatterConfig, GenerationWarning, ParsedSemver, ComponentDefinition as SharedComponentDefinition, ValidationError, ValidationResult, calculatePosition, clearComponentNamesCache, compareSemver, convertToJsonSchema, createComponentSchema, createErrorConfig, createJsonParseError, exportSchemaToFile, extractStandardComponentNames, fixSchemaReferences, formatErrorMessage, formatErrorSummary, getLiteralValue, getObjectSchemaPropertyNames, getSchemaMetadata, groupErrorsByPath, isLiteralSchema, isObjectSchema, isUnionSchema, isValidSemver, latestVersion, parseSemver, createComponentSchemaObject as sharedCreateComponentSchemaObject, transformValueError, transformValueErrors } from '@json-to-office/shared';
|
|
4
4
|
import { DocumentValidationResult, ValidationError } from './schemas/document.js';
|
|
5
5
|
export { JSON_SCHEMA_URLS, JsonComponentDefinitionSchema } from './schemas/document.js';
|
|
6
|
-
export { DocumentMargins, FontDefinition, Fonts, HeadingDefinition, Page, PageDimensions, StyleDefinitions, ThemeConfigJson, ThemeConfigSchema, isValidThemeConfig } from './schemas/theme.js';
|
|
6
|
+
export { DocumentMargins, FontDefinition, Fonts, HeadingDefinition, Page, PageDimensions, StyleDefinitions, ThemeConfigJson, ThemeConfigSchema, createMinimalTheme, isValidThemeConfig } from './schemas/theme.js';
|
|
7
7
|
export { GenerateDocumentRequest, GenerateDocumentRequestSchema, GenerateDocumentResponse, GenerateDocumentResponseSchema, ValidateDocumentRequest, ValidateDocumentRequestSchema, ValidateDocumentResponse, ValidateDocumentResponseSchema } from './schemas/api.js';
|
|
8
8
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
9
9
|
import { Static } from '@sinclair/typebox';
|
|
@@ -542,8 +542,6 @@ declare const COMPONENT_SCHEMA_MAP: {
|
|
|
542
542
|
author: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
543
543
|
company: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
544
544
|
date: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
545
|
-
created: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
546
|
-
modified: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
547
545
|
version: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
548
546
|
tags: _sinclair_typebox.TOptional<_sinclair_typebox.TArray<_sinclair_typebox.TString>>;
|
|
549
547
|
}>>;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generateUnifiedDocumentSchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YQE7H4H4.js";
|
|
4
4
|
import {
|
|
5
5
|
DOC_LINKS,
|
|
6
6
|
ERROR_TEMPLATES,
|
|
@@ -32,21 +32,22 @@ import {
|
|
|
32
32
|
validateTheme,
|
|
33
33
|
validateThemeJson,
|
|
34
34
|
validateThemeWithEnhancement
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-GJBRYTGZ.js";
|
|
36
36
|
import {
|
|
37
37
|
ThemeConfigSchema,
|
|
38
|
+
createMinimalTheme,
|
|
38
39
|
isValidThemeConfig
|
|
39
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-3JOBFRYR.js";
|
|
40
41
|
import {
|
|
41
42
|
GenerateDocumentRequestSchema,
|
|
42
43
|
GenerateDocumentResponseSchema,
|
|
43
44
|
ValidateDocumentRequestSchema,
|
|
44
45
|
ValidateDocumentResponseSchema
|
|
45
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-7636IMZ5.js";
|
|
46
47
|
import {
|
|
47
48
|
JSON_SCHEMA_URLS,
|
|
48
49
|
JsonComponentDefinitionSchema
|
|
49
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-FNCLWYTA.js";
|
|
50
51
|
import {
|
|
51
52
|
comprehensiveValidateDocument,
|
|
52
53
|
createDocumentValidator,
|
|
@@ -68,11 +69,11 @@ import {
|
|
|
68
69
|
validateJsonComponent,
|
|
69
70
|
validateJsonDocument,
|
|
70
71
|
validateWithEnhancement
|
|
71
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-HTOT7PVC.js";
|
|
72
73
|
import {
|
|
73
74
|
ComponentDefinitionSchema,
|
|
74
75
|
StandardComponentDefinitionSchema
|
|
75
|
-
} from "./chunk-
|
|
76
|
+
} from "./chunk-2TQ74H6S.js";
|
|
76
77
|
import {
|
|
77
78
|
CustomComponentDefinitionSchema,
|
|
78
79
|
TextSpaceAfterComponentSchema,
|
|
@@ -86,7 +87,7 @@ import {
|
|
|
86
87
|
createComponentSchema,
|
|
87
88
|
exportSchemaToFile,
|
|
88
89
|
fixSchemaReferences
|
|
89
|
-
} from "./chunk-
|
|
90
|
+
} from "./chunk-U7UNC7QH.js";
|
|
90
91
|
import {
|
|
91
92
|
HighchartsPropsSchema,
|
|
92
93
|
ReportPropsSchema,
|
|
@@ -95,7 +96,7 @@ import {
|
|
|
95
96
|
VisualCanvasBackgroundSchema,
|
|
96
97
|
VisualCanvasSchema,
|
|
97
98
|
VisualPropsSchema
|
|
98
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-S4TSENRQ.js";
|
|
99
100
|
import {
|
|
100
101
|
AlignmentSchema,
|
|
101
102
|
BaseComponentPropsSchema,
|
|
@@ -117,7 +118,7 @@ import {
|
|
|
117
118
|
SpacingSchema,
|
|
118
119
|
StatisticPropsSchema,
|
|
119
120
|
TablePropsSchema
|
|
120
|
-
} from "./chunk-
|
|
121
|
+
} from "./chunk-KNMPYZUO.js";
|
|
121
122
|
import "./chunk-E5YI66B3.js";
|
|
122
123
|
|
|
123
124
|
// src/diff/word-diff.ts
|
|
@@ -1695,6 +1696,7 @@ export {
|
|
|
1695
1696
|
createErrorConfig,
|
|
1696
1697
|
createJsonParseError,
|
|
1697
1698
|
createJsonValidator,
|
|
1699
|
+
createMinimalTheme,
|
|
1698
1700
|
createThemeValidator,
|
|
1699
1701
|
createValidatedComponent,
|
|
1700
1702
|
createValidator,
|