@json-to-office/core-docx 0.15.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/components/highcharts.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/visual.d.ts +42 -0
- package/dist/components/visual.d.ts.map +1 -0
- package/dist/core/cached-render.d.ts.map +1 -1
- package/dist/core/flattenVisuals.d.ts +33 -0
- package/dist/core/flattenVisuals.d.ts.map +1 -0
- package/dist/core/render.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +291 -29
- package/dist/index.js.map +1 -1
- package/dist/plugin/example/index.js +176 -29
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/styles/utils/componentDefaults.d.ts +6 -0
- package/dist/styles/utils/componentDefaults.d.ts.map +1 -1
- package/dist/styles/utils/resolveComponentTree.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/serviceClient.d.ts +39 -0
- package/dist/utils/serviceClient.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highcharts.d.ts","sourceRoot":"","sources":["../../src/components/highcharts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,aAAa,EAEd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"highcharts.d.ts","sourceRoot":"","sources":["../../src/components/highcharts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,aAAa,EAEd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAUxC,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAwDD;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CA+BhC"}
|
|
@@ -13,5 +13,6 @@ export { renderColumnsComponent } from './columns';
|
|
|
13
13
|
export { renderStatisticComponent } from './statistic';
|
|
14
14
|
export { renderTocComponent } from './toc';
|
|
15
15
|
export { renderHighchartsComponent } from './highcharts';
|
|
16
|
+
export { renderVisualComponent } from './visual';
|
|
16
17
|
export { textSpaceAfterComponent } from './text-space-after';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visual Component
|
|
3
|
+
*
|
|
4
|
+
* Renders a free-canvas graphic authored as a single pptx slide and embeds it
|
|
5
|
+
* as a rasterized PNG. The slide is rendered to an image by an injected
|
|
6
|
+
* rasterization service (`services.pptx`) — exactly the way the `highcharts`
|
|
7
|
+
* component offloads chart rendering to an export server — then desugars to a
|
|
8
|
+
* plain `image`.
|
|
9
|
+
*/
|
|
10
|
+
import { Paragraph, Table } from 'docx';
|
|
11
|
+
import { ComponentDefinition, RenderContext } from '../types';
|
|
12
|
+
import { ThemeConfig } from '../styles';
|
|
13
|
+
import { type ImageOptions } from '../core/content';
|
|
14
|
+
import type { VisualProps } from '@json-to-office/shared-docx';
|
|
15
|
+
/**
|
|
16
|
+
* Build a single-slide pptx presentation component definition from visual props.
|
|
17
|
+
* The shape mirrors a normal `.pptx.json` document so the pptx engine renders
|
|
18
|
+
* it unchanged. Exported for reuse by the `flattenVisuals` transform.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildVisualPresentation(props: VisualProps): Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Default rendered width (px) for a visual: its physical canvas inches, so a
|
|
23
|
+
* 6×4 canvas prints 6×4 unless `width` overrides.
|
|
24
|
+
*/
|
|
25
|
+
export declare function defaultVisualWidthPx(props: VisualProps): number;
|
|
26
|
+
/**
|
|
27
|
+
* Shared image-placement options derived from a visual's props. Used by BOTH
|
|
28
|
+
* the render-time createImage call and the flatten transform so the two
|
|
29
|
+
* desugaring paths can't drift (width default, alignment default, caption,
|
|
30
|
+
* spacing, floating, keepNext/keepLines all live here once).
|
|
31
|
+
*/
|
|
32
|
+
export declare function visualToImageOptions(props: VisualProps): ImageOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Map visual props to the `image` props they desugar to (used by the
|
|
35
|
+
* `flattenVisuals` transform to produce a portable, service-free document).
|
|
36
|
+
*/
|
|
37
|
+
export declare function visualToImageProps(props: VisualProps, base64DataUri: string): Record<string, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Render visual component
|
|
40
|
+
*/
|
|
41
|
+
export declare function renderVisualComponent(component: ComponentDefinition, theme: ThemeConfig, themeName?: string, context?: RenderContext): Promise<(Paragraph | Table)[]>;
|
|
42
|
+
//# sourceMappingURL=visual.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visual.d.ts","sourceRoot":"","sources":["../../src/components/visual.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,aAAa,EAEd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAY/D;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,WAAW,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuBzB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAWrE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAClB,aAAa,EAAE,MAAM,GACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMzB;AA0DD;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,WAAW,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CA2BhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-render.d.ts","sourceRoot":"","sources":["../../src/core/cached-render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,U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AS,EAAE,MAAM,EACjB,OAAO,EAAE,aAAa,EACtB,WAAW,UAAQ,GAClB,OAAO,CAAC,CAAC,SAAS,GAAG,KAAK,GAAG,eAAe,GAAG,OAAO,CAAC,EAAE,CAAC,CAyF5D;AAKD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,KAAK,CAAC;IAChB,SAAS,EAAE,mBAAmB,CAAC;IAC/B,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC,GACD,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED;;GAEG;AACH,wBAAgB,sBAAsB,kEAMrC;AAED;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,GAAG,CACvD,MAAM,EACN,OAAO,CACR,GAAG,IAAI,CAAC,CAgBR;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GACzB,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flattenVisuals — desugar `visual` components to plain `image` components ahead
|
|
3
|
+
* of time, producing a portable, service-free `.docx.json`.
|
|
4
|
+
*
|
|
5
|
+
* The normal pipeline rasterizes `visual` nodes at render time via
|
|
6
|
+
* `services.pptx`. This transform does the same desugaring offline: walk the
|
|
7
|
+
* document tree, rasterize each `visual` with the supplied rasterizer, and
|
|
8
|
+
* replace it with `{ name: 'image', props: { base64, ... } }`. The result builds
|
|
9
|
+
* with no rasterization service configured — handy for shipping documents that
|
|
10
|
+
* generate on hosts without LibreOffice/poppler.
|
|
11
|
+
*
|
|
12
|
+
* The walk covers every place the docx model can hold a child component, not
|
|
13
|
+
* just `children`: section `props.header`/`props.footer`, and table
|
|
14
|
+
* `props.columns[].cells[].content` / `props.columns[].header.content`.
|
|
15
|
+
*/
|
|
16
|
+
import { type PptxRasterizer } from '@json-to-office/shared';
|
|
17
|
+
export interface FlattenVisualsOptions {
|
|
18
|
+
/** Rasterizer that turns a single-slide pptx presentation into a PNG. */
|
|
19
|
+
rasterize: PptxRasterizer;
|
|
20
|
+
/** Default DPI applied when a `visual` does not specify one (default 200). */
|
|
21
|
+
dpi?: number;
|
|
22
|
+
/** Max concurrent rasterizations (default 4). */
|
|
23
|
+
concurrency?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Return a deep copy of `doc` with every `visual` node replaced by the `image`
|
|
27
|
+
* node it rasterizes to. Visuals rasterize with bounded concurrency. A
|
|
28
|
+
* `visual` with `enabled: false` is left untouched (it's filtered out at render
|
|
29
|
+
* anyway, so rasterizing it would be wasted work). Non-visual nodes are copied
|
|
30
|
+
* structurally and otherwise unchanged.
|
|
31
|
+
*/
|
|
32
|
+
export declare function flattenVisuals<T = unknown>(doc: T, options: FlattenVisualsOptions): Promise<T>;
|
|
33
|
+
//# sourceMappingURL=flattenVisuals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenVisuals.d.ts","sourceRoot":"","sources":["../../src/core/flattenVisuals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAC;AAShC,MAAM,WAAW,qBAAqB;IACpC,yEAAyE;IACzE,SAAS,EAAE,cAAc,CAAC;IAC1B,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA4BD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9C,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,CAAC,CAAC,CASZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/core/render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,QAAQ,EACR,SAAS,EACT,KAAK,EACL,eAAe,EACf,eAAe,EAKf,OAAO,EACR,MAAM,MAAM,CAAC;AAad,OAAO,EACL,mBAAmB,EACnB,aAAa,
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/core/render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,QAAQ,EACR,SAAS,EACT,KAAK,EACL,eAAe,EACf,eAAe,EAKf,OAAO,EACR,MAAM,MAAM,CAAC;AAad,OAAO,EACL,mBAAmB,EACnB,aAAa,EAed,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAMxC,OAAO,EAAE,iBAAiB,EAAuB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAKrD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAoC7D;;GAEG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE;IACR,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,GACA,OAAO,CAAC,QAAQ,CAAC,CAwJnB;AAiOD;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,aAAa,EACtB,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,eAAe,CAAC,CAiH1B;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,CAAC,SAAS,GAAG,KAAK,GAAG,eAAe,GAAG,OAAO,CAAC,EAAE,CAAC,CAmC5D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare function getCoreVersion(): string;
|
|
2
2
|
export { generateDocument, generateFromConfig, generateDocumentFromJson, generateDocumentFromFile, generateBufferFromJson, generateBufferFromFile, generateAndSaveFromJson, generateAndSaveFromFile, validateJsonSchema, isReportComponentDefinition, saveDocument, generateAndSave, DocumentGenerator as CoreDocumentGenerator, } from './core/generator';
|
|
3
|
+
export { flattenVisuals, type FlattenVisualsOptions, } from './core/flattenVisuals';
|
|
3
4
|
export { MemoryCache, CacheKeyGenerator, DEFAULT_CACHE_CONFIG, getCacheConfigFromEnv, mergeConfigs, ComponentCacheAnalytics, type CacheConfiguration, type CachedComponent, type CacheStatistics, type CacheKeyOptions, type CacheEvents, type CacheAnalyticsReport, type ComponentPerformanceMetrics, type ComponentCacheTrends, type CacheOptimizationRecommendation, type TimeSeriesPoint, } from './cache/index';
|
|
4
5
|
export { initializeComponentCache, getComponentCache, clearComponentCache, getComponentCacheStats, warmComponentCache, } from './core/cached-render';
|
|
5
|
-
export { isReportComponent, isSectionComponent, isHeadingComponent, isParagraphComponent, isColumnsComponent, isImageComponent, isStatisticComponent, isTableComponent, isListComponent, isHighchartsComponent, } from './types/index';
|
|
6
|
+
export { isReportComponent, isSectionComponent, isHeadingComponent, isParagraphComponent, isColumnsComponent, isImageComponent, isStatisticComponent, isTableComponent, isListComponent, isHighchartsComponent, isVisualComponent, } from './types/index';
|
|
6
7
|
export type { ImageContent, StatisticContent, TableData, SectionProperties, ColumnSettings, PageSizeOptions, PageMarginOptions, PageNumberOptions, PageBorderOptions, RenderContext, } from './types/index';
|
|
7
8
|
export * from './utils/formatters';
|
|
8
9
|
export { parseTextWithDecorators } from './utils/textParser';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAGD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,2BAA2B,EAC3B,YAAY,EACZ,eAAe,EACf,iBAAiB,IAAI,qBAAqB,GAC3C,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EACZ,uBAAuB,EAEvB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,+BAA+B,EACpC,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAEL,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAGD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACv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955
1955
|
isListComponent,
|
|
1956
1956
|
isTocComponent,
|
|
1957
|
-
isHighchartsComponent
|
|
1957
|
+
isHighchartsComponent,
|
|
1958
|
+
isVisualComponent
|
|
1958
1959
|
} from "@json-to-office/shared-docx";
|
|
1959
1960
|
|
|
1960
1961
|
// src/core/generator.ts
|
|
@@ -2050,6 +2051,9 @@ function resolveListProps(props, theme) {
|
|
|
2050
2051
|
function resolveHighchartsProps(props, _theme) {
|
|
2051
2052
|
return props;
|
|
2052
2053
|
}
|
|
2054
|
+
function resolveVisualProps(props, _theme) {
|
|
2055
|
+
return props;
|
|
2056
|
+
}
|
|
2053
2057
|
function getCustomComponentDefaults(theme, componentName) {
|
|
2054
2058
|
const defaults = getComponentDefaults(theme);
|
|
2055
2059
|
return defaults?.[componentName] || {};
|
|
@@ -2079,7 +2083,8 @@ var RESOLVER_MAP = {
|
|
|
2079
2083
|
section: resolveSectionProps,
|
|
2080
2084
|
columns: resolveColumnsProps,
|
|
2081
2085
|
list: resolveListProps,
|
|
2082
|
-
highcharts: resolveHighchartsProps
|
|
2086
|
+
highcharts: resolveHighchartsProps,
|
|
2087
|
+
visual: resolveVisualProps
|
|
2083
2088
|
};
|
|
2084
2089
|
function resolveComponentDefaults(component, theme) {
|
|
2085
2090
|
if (!component.props) return component;
|
|
@@ -4068,7 +4073,7 @@ async function clearComponentCache() {
|
|
|
4068
4073
|
}
|
|
4069
4074
|
}
|
|
4070
4075
|
async function renderComponentWithCache(component, theme, themeName, context, bypassCache = false) {
|
|
4071
|
-
const forceBypassForType = component.name === "toc" || component.name === "section" || componentHasRevision(component);
|
|
4076
|
+
const forceBypassForType = component.name === "toc" || component.name === "section" || component.name === "visual" || componentHasRevision(component);
|
|
4072
4077
|
if (!componentCache) {
|
|
4073
4078
|
initializeComponentCache();
|
|
4074
4079
|
}
|
|
@@ -6350,21 +6355,61 @@ function hasNodeBuiltins() {
|
|
|
6350
6355
|
}
|
|
6351
6356
|
}
|
|
6352
6357
|
|
|
6358
|
+
// src/utils/serviceClient.ts
|
|
6359
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
6360
|
+
function resolveServiceUrl(propsUrl, servicesUrl, defaultUrl) {
|
|
6361
|
+
const raw = (propsUrl || servicesUrl || defaultUrl).trim();
|
|
6362
|
+
const withScheme = /^https?:\/\//i.test(raw) ? raw : `http://${raw}`;
|
|
6363
|
+
return withScheme.replace(/\/+$/, "");
|
|
6364
|
+
}
|
|
6365
|
+
async function postJsonToService(opts) {
|
|
6366
|
+
const resolvedHeaders = typeof opts.headers === "function" ? await opts.headers(opts.body) : opts.headers;
|
|
6367
|
+
const headers = {
|
|
6368
|
+
"Content-Type": "application/json",
|
|
6369
|
+
...resolvedHeaders
|
|
6370
|
+
};
|
|
6371
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
6372
|
+
const controller = new AbortController();
|
|
6373
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
6374
|
+
let response;
|
|
6375
|
+
try {
|
|
6376
|
+
response = await fetch(`${opts.url}${opts.path}`, {
|
|
6377
|
+
method: "POST",
|
|
6378
|
+
headers,
|
|
6379
|
+
body: JSON.stringify(opts.body),
|
|
6380
|
+
signal: controller.signal
|
|
6381
|
+
});
|
|
6382
|
+
} catch (error) {
|
|
6383
|
+
if (error?.name === "AbortError") {
|
|
6384
|
+
throw new Error(
|
|
6385
|
+
`${opts.serviceLabel} timed out after ${timeoutMs}ms at ${opts.url}.`
|
|
6386
|
+
);
|
|
6387
|
+
}
|
|
6388
|
+
const cause = error instanceof Error ? error.message : String(error);
|
|
6389
|
+
throw new Error(opts.onUnreachable(opts.url, cause));
|
|
6390
|
+
} finally {
|
|
6391
|
+
clearTimeout(timer);
|
|
6392
|
+
}
|
|
6393
|
+
if (!response.ok) {
|
|
6394
|
+
throw new Error(
|
|
6395
|
+
`${opts.serviceLabel} returned ${response.status}: ${response.statusText}`
|
|
6396
|
+
);
|
|
6397
|
+
}
|
|
6398
|
+
return response;
|
|
6399
|
+
}
|
|
6400
|
+
|
|
6353
6401
|
// src/components/highcharts.ts
|
|
6354
6402
|
var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
|
|
6355
|
-
function getExportServerUrl(propsUrl, servicesUrl) {
|
|
6356
|
-
const raw = propsUrl || servicesUrl || DEFAULT_EXPORT_SERVER_URL;
|
|
6357
|
-
return raw.startsWith("http") ? raw : `http://${raw}`;
|
|
6358
|
-
}
|
|
6359
6403
|
async function generateChart(config, servicesConfig) {
|
|
6360
6404
|
if (!isNodeEnvironment()) {
|
|
6361
6405
|
throw new Error(
|
|
6362
6406
|
"Highcharts export server requires a Node.js environment. Chart generation is not available in browser environments."
|
|
6363
6407
|
);
|
|
6364
6408
|
}
|
|
6365
|
-
const serverUrl =
|
|
6409
|
+
const serverUrl = resolveServiceUrl(
|
|
6366
6410
|
config.serverUrl,
|
|
6367
|
-
servicesConfig?.serverUrl
|
|
6411
|
+
servicesConfig?.serverUrl,
|
|
6412
|
+
DEFAULT_EXPORT_SERVER_URL
|
|
6368
6413
|
);
|
|
6369
6414
|
const requestBody = {
|
|
6370
6415
|
infile: config.options,
|
|
@@ -6372,26 +6417,15 @@ async function generateChart(config, servicesConfig) {
|
|
|
6372
6417
|
b64: true,
|
|
6373
6418
|
scale: config.scale
|
|
6374
6419
|
};
|
|
6375
|
-
const
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
body: JSON.stringify(requestBody)
|
|
6384
|
-
}).catch((error) => {
|
|
6385
|
-
throw new Error(
|
|
6386
|
-
`Highcharts Export Server is not running at ${serverUrl}. Start it with: npx highcharts-export-server --enableServer true
|
|
6387
|
-
Cause: ${error instanceof Error ? error.message : String(error)}`
|
|
6388
|
-
);
|
|
6420
|
+
const response = await postJsonToService({
|
|
6421
|
+
url: serverUrl,
|
|
6422
|
+
path: "/export",
|
|
6423
|
+
body: requestBody,
|
|
6424
|
+
headers: servicesConfig?.headers,
|
|
6425
|
+
serviceLabel: "Highcharts export server",
|
|
6426
|
+
onUnreachable: (url, cause) => `Highcharts Export Server is not running at ${url}. Start it with: npx highcharts-export-server --enableServer true
|
|
6427
|
+
Cause: ${cause}`
|
|
6389
6428
|
});
|
|
6390
|
-
if (!response.ok) {
|
|
6391
|
-
throw new Error(
|
|
6392
|
-
`Highcharts export server returned ${response.status}: ${response.statusText}`
|
|
6393
|
-
);
|
|
6394
|
-
}
|
|
6395
6429
|
const base64Data = await response.text();
|
|
6396
6430
|
const base64DataUri = `data:image/png;base64,${base64Data}`;
|
|
6397
6431
|
const width = config.options.chart.width;
|
|
@@ -6425,6 +6459,116 @@ async function renderHighchartsComponent(component, theme, themeName, context) {
|
|
|
6425
6459
|
return imageParagraphs;
|
|
6426
6460
|
}
|
|
6427
6461
|
|
|
6462
|
+
// src/components/visual.ts
|
|
6463
|
+
import {
|
|
6464
|
+
clampVisualDpi,
|
|
6465
|
+
DEFAULT_VISUAL_DPI
|
|
6466
|
+
} from "@json-to-office/shared";
|
|
6467
|
+
var DEFAULT_RASTERIZE_SERVER_URL = "http://localhost:7802";
|
|
6468
|
+
var PIXELS_PER_INCH = 96;
|
|
6469
|
+
function buildVisualPresentation(props) {
|
|
6470
|
+
const { canvas, elements } = props;
|
|
6471
|
+
const presentationProps = {
|
|
6472
|
+
slideWidth: canvas.width,
|
|
6473
|
+
slideHeight: canvas.height
|
|
6474
|
+
};
|
|
6475
|
+
if (canvas.theme) presentationProps.theme = canvas.theme;
|
|
6476
|
+
const slideProps = {};
|
|
6477
|
+
if (canvas.background) slideProps.background = canvas.background;
|
|
6478
|
+
return {
|
|
6479
|
+
name: "pptx",
|
|
6480
|
+
props: presentationProps,
|
|
6481
|
+
children: [
|
|
6482
|
+
{
|
|
6483
|
+
name: "slide",
|
|
6484
|
+
props: slideProps,
|
|
6485
|
+
children: elements ?? []
|
|
6486
|
+
}
|
|
6487
|
+
]
|
|
6488
|
+
};
|
|
6489
|
+
}
|
|
6490
|
+
function defaultVisualWidthPx(props) {
|
|
6491
|
+
return Math.round(props.canvas.width * PIXELS_PER_INCH);
|
|
6492
|
+
}
|
|
6493
|
+
function visualToImageOptions(props) {
|
|
6494
|
+
return {
|
|
6495
|
+
width: props.width ?? defaultVisualWidthPx(props),
|
|
6496
|
+
...props.height !== void 0 && { height: props.height },
|
|
6497
|
+
alignment: props.alignment ?? "center",
|
|
6498
|
+
...props.caption !== void 0 && { caption: props.caption },
|
|
6499
|
+
...props.spacing !== void 0 && { spacing: props.spacing },
|
|
6500
|
+
...props.floating !== void 0 && { floating: props.floating },
|
|
6501
|
+
...props.keepNext !== void 0 && { keepNext: props.keepNext },
|
|
6502
|
+
...props.keepLines !== void 0 && { keepLines: props.keepLines }
|
|
6503
|
+
};
|
|
6504
|
+
}
|
|
6505
|
+
function visualToImageProps(props, base64DataUri) {
|
|
6506
|
+
return {
|
|
6507
|
+
base64: base64DataUri,
|
|
6508
|
+
...visualToImageOptions(props),
|
|
6509
|
+
...props.alt !== void 0 && { alt: props.alt }
|
|
6510
|
+
};
|
|
6511
|
+
}
|
|
6512
|
+
async function rasterize(presentation, dpi, propsServerUrl, serviceConfig) {
|
|
6513
|
+
if (!isNodeEnvironment()) {
|
|
6514
|
+
throw new Error(
|
|
6515
|
+
"Visual rasterization requires a Node.js environment. It is not available in browser environments."
|
|
6516
|
+
);
|
|
6517
|
+
}
|
|
6518
|
+
if (serviceConfig?.render) {
|
|
6519
|
+
return serviceConfig.render({ presentation, dpi });
|
|
6520
|
+
}
|
|
6521
|
+
const serverUrl = resolveServiceUrl(
|
|
6522
|
+
propsServerUrl,
|
|
6523
|
+
serviceConfig?.serverUrl,
|
|
6524
|
+
DEFAULT_RASTERIZE_SERVER_URL
|
|
6525
|
+
);
|
|
6526
|
+
const response = await postJsonToService({
|
|
6527
|
+
url: serverUrl,
|
|
6528
|
+
path: "/rasterize",
|
|
6529
|
+
body: { presentation, dpi },
|
|
6530
|
+
headers: serviceConfig?.headers,
|
|
6531
|
+
serviceLabel: "PPTX rasterization service",
|
|
6532
|
+
onUnreachable: (url, cause) => `PPTX rasterization service is not reachable at ${url}. Configure services.pptx with a \`render\` callback or a running \`serverUrl\`.
|
|
6533
|
+
Cause: ${cause}`
|
|
6534
|
+
});
|
|
6535
|
+
let result;
|
|
6536
|
+
try {
|
|
6537
|
+
result = await response.json();
|
|
6538
|
+
} catch {
|
|
6539
|
+
throw new Error(
|
|
6540
|
+
"PPTX rasterization service returned a non-JSON response (expected { base64DataUri, width, height })."
|
|
6541
|
+
);
|
|
6542
|
+
}
|
|
6543
|
+
if (!result?.base64DataUri) {
|
|
6544
|
+
throw new Error(
|
|
6545
|
+
"PPTX rasterization service returned a malformed response (missing base64DataUri)."
|
|
6546
|
+
);
|
|
6547
|
+
}
|
|
6548
|
+
return result;
|
|
6549
|
+
}
|
|
6550
|
+
async function renderVisualComponent(component, theme, themeName, context) {
|
|
6551
|
+
if (!isVisualComponent(component)) return [];
|
|
6552
|
+
const props = component.props;
|
|
6553
|
+
const serviceConfig = context?.services?.pptx;
|
|
6554
|
+
const presentation = buildVisualPresentation(props);
|
|
6555
|
+
const dpi = clampVisualDpi(
|
|
6556
|
+
props.dpi ?? serviceConfig?.dpi ?? DEFAULT_VISUAL_DPI
|
|
6557
|
+
);
|
|
6558
|
+
const result = await rasterize(
|
|
6559
|
+
presentation,
|
|
6560
|
+
dpi,
|
|
6561
|
+
props.serverUrl,
|
|
6562
|
+
serviceConfig
|
|
6563
|
+
);
|
|
6564
|
+
return await createImage(
|
|
6565
|
+
result.base64DataUri,
|
|
6566
|
+
theme,
|
|
6567
|
+
themeName,
|
|
6568
|
+
visualToImageOptions(props)
|
|
6569
|
+
);
|
|
6570
|
+
}
|
|
6571
|
+
|
|
6428
6572
|
// src/components/text-space-after.ts
|
|
6429
6573
|
import { Type } from "@sinclair/typebox";
|
|
6430
6574
|
|
|
@@ -6581,7 +6725,7 @@ async function renderDocument(structure, layout, options) {
|
|
|
6581
6725
|
}
|
|
6582
6726
|
});
|
|
6583
6727
|
}
|
|
6584
|
-
async function renderHeaderFooterComponents(components, theme, themeName,
|
|
6728
|
+
async function renderHeaderFooterComponents(components, theme, themeName, context) {
|
|
6585
6729
|
if (!components || components.length === 0) {
|
|
6586
6730
|
return [];
|
|
6587
6731
|
}
|
|
@@ -6713,6 +6857,14 @@ async function renderHeaderFooterComponents(components, theme, themeName, _conte
|
|
|
6713
6857
|
} else if (isTableComponent(component)) {
|
|
6714
6858
|
const tables = await renderTableComponent(component, theme, themeName);
|
|
6715
6859
|
elements.push(...tables);
|
|
6860
|
+
} else if (isVisualComponent(component)) {
|
|
6861
|
+
const visualEls = await renderVisualComponent(
|
|
6862
|
+
component,
|
|
6863
|
+
theme,
|
|
6864
|
+
themeName,
|
|
6865
|
+
context
|
|
6866
|
+
);
|
|
6867
|
+
elements.push(...visualEls);
|
|
6716
6868
|
}
|
|
6717
6869
|
}
|
|
6718
6870
|
return elements;
|
|
@@ -6833,6 +6985,8 @@ async function renderComponent(component, theme, themeName, context) {
|
|
|
6833
6985
|
themeName,
|
|
6834
6986
|
context
|
|
6835
6987
|
);
|
|
6988
|
+
} else if (isVisualComponent(component)) {
|
|
6989
|
+
return await renderVisualComponent(component, theme, themeName, context);
|
|
6836
6990
|
} else if (isSectionComponent(component)) {
|
|
6837
6991
|
return await renderSectionComponent(component, theme, themeName, context);
|
|
6838
6992
|
}
|
|
@@ -7204,6 +7358,112 @@ var DocumentGenerator = {
|
|
|
7204
7358
|
isReportComponentDefinition
|
|
7205
7359
|
};
|
|
7206
7360
|
|
|
7361
|
+
// src/core/flattenVisuals.ts
|
|
7362
|
+
import {
|
|
7363
|
+
clampVisualDpi as clampVisualDpi2,
|
|
7364
|
+
DEFAULT_VISUAL_DPI as DEFAULT_VISUAL_DPI2
|
|
7365
|
+
} from "@json-to-office/shared";
|
|
7366
|
+
var DEFAULT_CONCURRENCY = 4;
|
|
7367
|
+
function createLimiter(max) {
|
|
7368
|
+
let active = 0;
|
|
7369
|
+
const queue = [];
|
|
7370
|
+
const release = () => {
|
|
7371
|
+
active--;
|
|
7372
|
+
queue.shift()?.();
|
|
7373
|
+
};
|
|
7374
|
+
return async function limit(fn) {
|
|
7375
|
+
if (active >= max)
|
|
7376
|
+
await new Promise((resolve2) => queue.push(resolve2));
|
|
7377
|
+
active++;
|
|
7378
|
+
try {
|
|
7379
|
+
return await fn();
|
|
7380
|
+
} finally {
|
|
7381
|
+
release();
|
|
7382
|
+
}
|
|
7383
|
+
};
|
|
7384
|
+
}
|
|
7385
|
+
async function flattenVisuals(doc, options) {
|
|
7386
|
+
const ctx = {
|
|
7387
|
+
rasterize: options.rasterize,
|
|
7388
|
+
dpi: options.dpi,
|
|
7389
|
+
limit: createLimiter(
|
|
7390
|
+
Math.max(1, options.concurrency ?? DEFAULT_CONCURRENCY)
|
|
7391
|
+
)
|
|
7392
|
+
};
|
|
7393
|
+
return await flattenNode(doc, ctx);
|
|
7394
|
+
}
|
|
7395
|
+
async function rasterizeVisual(obj, ctx) {
|
|
7396
|
+
const props = obj.props;
|
|
7397
|
+
const dpi = clampVisualDpi2(props.dpi ?? ctx.dpi ?? DEFAULT_VISUAL_DPI2);
|
|
7398
|
+
const result = await ctx.limit(
|
|
7399
|
+
() => ctx.rasterize({ presentation: buildVisualPresentation(props), dpi })
|
|
7400
|
+
);
|
|
7401
|
+
const image = {
|
|
7402
|
+
name: "image",
|
|
7403
|
+
props: visualToImageProps(props, result.base64DataUri)
|
|
7404
|
+
};
|
|
7405
|
+
if (obj.id !== void 0) image.id = obj.id;
|
|
7406
|
+
if (obj.enabled !== void 0) image.enabled = obj.enabled;
|
|
7407
|
+
return image;
|
|
7408
|
+
}
|
|
7409
|
+
async function flattenNode(node, ctx) {
|
|
7410
|
+
if (Array.isArray(node)) {
|
|
7411
|
+
return Promise.all(node.map((n) => flattenNode(n, ctx)));
|
|
7412
|
+
}
|
|
7413
|
+
if (!node || typeof node !== "object") return node;
|
|
7414
|
+
const obj = node;
|
|
7415
|
+
if (obj.name === "visual" && obj.props && obj.enabled !== false) {
|
|
7416
|
+
return rasterizeVisual(obj, ctx);
|
|
7417
|
+
}
|
|
7418
|
+
const next = { ...obj };
|
|
7419
|
+
if (Array.isArray(obj.children)) {
|
|
7420
|
+
next.children = await flattenNode(obj.children, ctx);
|
|
7421
|
+
}
|
|
7422
|
+
if (obj.props && typeof obj.props === "object") {
|
|
7423
|
+
const props = obj.props;
|
|
7424
|
+
let propsChanged = false;
|
|
7425
|
+
const nextProps = { ...props };
|
|
7426
|
+
for (const key of ["header", "footer"]) {
|
|
7427
|
+
if (Array.isArray(props[key])) {
|
|
7428
|
+
nextProps[key] = await flattenNode(props[key], ctx);
|
|
7429
|
+
propsChanged = true;
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
if (Array.isArray(props.columns)) {
|
|
7433
|
+
nextProps.columns = await Promise.all(
|
|
7434
|
+
props.columns.map((col) => flattenColumn(col, ctx))
|
|
7435
|
+
);
|
|
7436
|
+
propsChanged = true;
|
|
7437
|
+
}
|
|
7438
|
+
if (propsChanged) next.props = nextProps;
|
|
7439
|
+
}
|
|
7440
|
+
return next;
|
|
7441
|
+
}
|
|
7442
|
+
async function flattenColumn(col, ctx) {
|
|
7443
|
+
if (!col || typeof col !== "object") return col;
|
|
7444
|
+
const column = col;
|
|
7445
|
+
const nextCol = { ...column };
|
|
7446
|
+
const header = column.header;
|
|
7447
|
+
if (header && typeof header === "object" && "content" in header) {
|
|
7448
|
+
nextCol.header = {
|
|
7449
|
+
...header,
|
|
7450
|
+
content: await flattenNode(header.content, ctx)
|
|
7451
|
+
};
|
|
7452
|
+
}
|
|
7453
|
+
if (Array.isArray(column.cells)) {
|
|
7454
|
+
nextCol.cells = await Promise.all(
|
|
7455
|
+
column.cells.map(async (cell) => {
|
|
7456
|
+
if (cell && typeof cell === "object" && "content" in cell) {
|
|
7457
|
+
const c = cell;
|
|
7458
|
+
return { ...c, content: await flattenNode(c.content, ctx) };
|
|
7459
|
+
}
|
|
7460
|
+
return cell;
|
|
7461
|
+
})
|
|
7462
|
+
);
|
|
7463
|
+
}
|
|
7464
|
+
return nextCol;
|
|
7465
|
+
}
|
|
7466
|
+
|
|
7207
7467
|
// src/utils/warningsDocument.ts
|
|
7208
7468
|
function generateWarningsDocument(warnings) {
|
|
7209
7469
|
if (!warnings || warnings.length === 0) {
|
|
@@ -8023,6 +8283,7 @@ export {
|
|
|
8023
8283
|
examples,
|
|
8024
8284
|
exportPluginSchema,
|
|
8025
8285
|
exportThemeToJson,
|
|
8286
|
+
flattenVisuals,
|
|
8026
8287
|
formatDate,
|
|
8027
8288
|
formatWarningsText,
|
|
8028
8289
|
generateAndSave,
|
|
@@ -8057,6 +8318,7 @@ export {
|
|
|
8057
8318
|
isSectionComponent,
|
|
8058
8319
|
isStatisticComponent,
|
|
8059
8320
|
isTableComponent,
|
|
8321
|
+
isVisualComponent,
|
|
8060
8322
|
loadJsonExample,
|
|
8061
8323
|
loadThemeFromFile,
|
|
8062
8324
|
loadThemeFromJson,
|