@json-to-office/shared-docx 0.1.3 → 0.3.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.
Files changed (37) hide show
  1. package/dist/{chunk-36K7MD3C.js → chunk-3D6HY6AC.js} +160 -87
  2. package/dist/chunk-3D6HY6AC.js.map +1 -0
  3. package/dist/{chunk-HHMK2RWF.js → chunk-AMVS7BRX.js} +7 -2
  4. package/dist/chunk-AMVS7BRX.js.map +1 -0
  5. package/dist/{chunk-FV6RFK6S.js → chunk-CVI7GFWX.js} +6 -7
  6. package/dist/chunk-CVI7GFWX.js.map +1 -0
  7. package/dist/{chunk-2YG3S7G3.js → chunk-DEIEJUY4.js} +2 -2
  8. package/dist/{chunk-HE6AENGO.js → chunk-EDYWA2KA.js} +2 -2
  9. package/dist/{chunk-ITHHY2YT.js → chunk-GGNGVIZO.js} +14 -39
  10. package/dist/{chunk-ITHHY2YT.js.map → chunk-GGNGVIZO.js.map} +1 -1
  11. package/dist/{chunk-THYJPIZN.js → chunk-S4EFGCIC.js} +2 -2
  12. package/dist/{chunk-JIF2EIDR.js → chunk-WJA5TGNI.js} +25 -15
  13. package/dist/chunk-WJA5TGNI.js.map +1 -0
  14. package/dist/{chunk-MEEABCM6.js → chunk-YNBTESFN.js} +6 -6
  15. package/dist/index.d.ts +1 -202
  16. package/dist/index.js +22 -22
  17. package/dist/schemas/api.js +3 -3
  18. package/dist/schemas/component-registry.d.ts +35 -5
  19. package/dist/schemas/component-registry.js +3 -1
  20. package/dist/schemas/components.d.ts +12 -200
  21. package/dist/schemas/components.js +6 -4
  22. package/dist/schemas/document.js +4 -4
  23. package/dist/schemas/export.js +3 -1
  24. package/dist/schemas/generator.js +2 -2
  25. package/dist/schemas/theme.d.ts +3 -597
  26. package/dist/schemas/theme.js +3 -3
  27. package/dist/validation/unified/index.d.ts +3 -201
  28. package/dist/validation/unified/index.js +5 -5
  29. package/package.json +2 -2
  30. package/dist/chunk-36K7MD3C.js.map +0 -1
  31. package/dist/chunk-FV6RFK6S.js.map +0 -1
  32. package/dist/chunk-HHMK2RWF.js.map +0 -1
  33. package/dist/chunk-JIF2EIDR.js.map +0 -1
  34. /package/dist/{chunk-2YG3S7G3.js.map → chunk-DEIEJUY4.js.map} +0 -0
  35. /package/dist/{chunk-HE6AENGO.js.map → chunk-EDYWA2KA.js.map} +0 -0
  36. /package/dist/{chunk-THYJPIZN.js.map → chunk-S4EFGCIC.js.map} +0 -0
  37. /package/dist/{chunk-MEEABCM6.js.map → chunk-YNBTESFN.js.map} +0 -0
@@ -1 +0,0 @@
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 STANDARD_COMPONENTS_REGISTRY,\n createComponentSchemaObject,\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 // Create a recursive component definition schema\n const ComponentDefinition = Type.Recursive(\n (This) => {\n const componentSchemas: TSchema[] = [];\n\n // Add standard components from registry - SINGLE SOURCE OF TRUTH\n if (includeStandardComponents) {\n for (const component of STANDARD_COMPONENTS_REGISTRY) {\n componentSchemas.push(createComponentSchemaObject(component, This));\n }\n }\n\n // Add custom components\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 // Attach description directly to the version literal so Monaco\n // shows it in the autocomplete dropdown for version values\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 // Build description: combine component-level + version-level descriptions\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 componentSchemas.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 componentSchemas.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 componentSchemas.push(\n Type.Object(schema, {\n additionalProperties: false,\n ...(customComponent.description\n ? { description: customComponent.description }\n : {}),\n })\n );\n }\n }\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 // Create union with discriminator for proper JSON Schema generation\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 // In the unified structure, a document IS a report component with an optional $schema field\n // Only support the new unified structure - no legacy support\n\n // Get report component props from registry\n const reportComponent = getStandardComponent('docx');\n if (!reportComponent) {\n throw new Error('Docx root component not found in registry');\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(Type.Array(ComponentDefinition)),\n },\n {\n additionalProperties: false,\n title,\n description,\n }\n );\n}\n"],"mappings":";;;;;;;AA2BA,SAAS,YAAqB;AAM9B,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,QAAM,sBAAsB,KAAK;AAAA,IAC/B,CAAC,SAAS;AACR,YAAM,mBAA8B,CAAC;AAGrC,UAAI,2BAA2B;AAC7B,mBAAW,aAAa,8BAA8B;AACpD,2BAAiB,KAAK,4BAA4B,WAAW,IAAI,CAAC;AAAA,QACpE;AAAA,MACF;AAGA,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;AAGlC,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,SA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