@openmaic/renderer 0.1.8 → 0.1.10
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/elements/chart/BaseChartElement.js +1 -1
- package/dist/elements/chart/BaseChartElement.js.map +1 -1
- package/dist/elements/chart/Chart.d.ts +3 -2
- package/dist/elements/chart/Chart.js +4 -2
- package/dist/elements/chart/Chart.js.map +1 -1
- package/dist/elements/chart/chartOption.d.ts +6 -4
- package/dist/elements/chart/chartOption.js +148 -36
- package/dist/elements/chart/chartOption.js.map +1 -1
- package/dist/elements/chart/chartRuntime.js +1 -0
- package/dist/elements/chart/chartRuntime.js.map +1 -1
- package/dist/snapshot/bakeImageSoftEdge.d.ts +10 -0
- package/dist/snapshot/bakeImageSoftEdge.js +63 -0
- package/dist/snapshot/bakeImageSoftEdge.js.map +1 -0
- package/dist/snapshot/index.js +1 -59
- package/dist/snapshot/index.js.map +1 -1
- package/dist/utils/element.js +30 -6
- package/dist/utils/element.js.map +1 -1
- package/package.json +2 -2
|
@@ -15,7 +15,7 @@ function BaseChartElement({ elementInfo, target }) {
|
|
|
15
15
|
width: '100%',
|
|
16
16
|
height: '100%',
|
|
17
17
|
transform: `rotate(${elementInfo.rotate}deg)`,
|
|
18
|
-
}, children: jsxs("div", { className: "element-content", style: { width: '100%', height: '100%', backgroundColor: elementInfo.fill }, children: [jsx(ElementOutline, { width: elementInfo.width, height: elementInfo.height, outline: elementInfo.outline }), jsx(Chart, { width: elementInfo.width, height: elementInfo.height, type: elementInfo.chartType, data: elementInfo.data, themeColors: elementInfo.themeColors, textColor: elementInfo.textColor, lineColor: elementInfo.lineColor, options: elementInfo.options })] }) }) }));
|
|
18
|
+
}, children: jsxs("div", { className: "element-content", style: { width: '100%', height: '100%', backgroundColor: elementInfo.fill }, children: [jsx(ElementOutline, { width: elementInfo.width, height: elementInfo.height, outline: elementInfo.outline }), jsx(Chart, { width: elementInfo.width, height: elementInfo.height, type: elementInfo.chartType, data: elementInfo.data, themeColors: elementInfo.themeColors, textColor: elementInfo.textColor, lineColor: elementInfo.lineColor, options: elementInfo.options, importedStyle: elementInfo.importedStyle })] }) }) }));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export { BaseChartElement };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseChartElement.js","sources":["../../../src/elements/chart/BaseChartElement.tsx"],"sourcesContent":["'use client';\n\nimport type { PPTChartElement } from '@openmaic/dsl';\nimport { ElementOutline } from '../shared/ElementOutline';\nimport { Chart } from './Chart';\n\nexport interface BaseChartElementProps {\n elementInfo: PPTChartElement;\n target?: string;\n}\n\nexport function BaseChartElement({ elementInfo, target }: BaseChartElementProps) {\n return (\n <div\n className=\"base-element-chart\"\n style={{\n position: 'absolute',\n top: `${elementInfo.top}px`,\n left: `${elementInfo.left}px`,\n width: `${elementInfo.width}px`,\n height: `${elementInfo.height}px`,\n pointerEvents: target === 'thumbnail' ? 'none' : undefined,\n }}\n >\n <div\n className=\"rotate-wrapper\"\n style={{\n width: '100%',\n height: '100%',\n transform: `rotate(${elementInfo.rotate}deg)`,\n }}\n >\n <div\n className=\"element-content\"\n style={{ width: '100%', height: '100%', backgroundColor: elementInfo.fill }}\n >\n <ElementOutline\n width={elementInfo.width}\n height={elementInfo.height}\n outline={elementInfo.outline}\n />\n <Chart\n width={elementInfo.width}\n height={elementInfo.height}\n type={elementInfo.chartType}\n data={elementInfo.data}\n themeColors={elementInfo.themeColors}\n textColor={elementInfo.textColor}\n lineColor={elementInfo.lineColor}\n options={elementInfo.options}\n />\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAYE;AAIM;AACA;AACA;AACA;AACA;;AAED;AAKG;AACA;AACA;;
|
|
1
|
+
{"version":3,"file":"BaseChartElement.js","sources":["../../../src/elements/chart/BaseChartElement.tsx"],"sourcesContent":["'use client';\n\nimport type { PPTChartElement } from '@openmaic/dsl';\nimport { ElementOutline } from '../shared/ElementOutline';\nimport { Chart } from './Chart';\n\nexport interface BaseChartElementProps {\n elementInfo: PPTChartElement;\n target?: string;\n}\n\nexport function BaseChartElement({ elementInfo, target }: BaseChartElementProps) {\n return (\n <div\n className=\"base-element-chart\"\n style={{\n position: 'absolute',\n top: `${elementInfo.top}px`,\n left: `${elementInfo.left}px`,\n width: `${elementInfo.width}px`,\n height: `${elementInfo.height}px`,\n pointerEvents: target === 'thumbnail' ? 'none' : undefined,\n }}\n >\n <div\n className=\"rotate-wrapper\"\n style={{\n width: '100%',\n height: '100%',\n transform: `rotate(${elementInfo.rotate}deg)`,\n }}\n >\n <div\n className=\"element-content\"\n style={{ width: '100%', height: '100%', backgroundColor: elementInfo.fill }}\n >\n <ElementOutline\n width={elementInfo.width}\n height={elementInfo.height}\n outline={elementInfo.outline}\n />\n <Chart\n width={elementInfo.width}\n height={elementInfo.height}\n type={elementInfo.chartType}\n data={elementInfo.data}\n themeColors={elementInfo.themeColors}\n textColor={elementInfo.textColor}\n lineColor={elementInfo.lineColor}\n options={elementInfo.options}\n importedStyle={elementInfo.importedStyle}\n />\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAYE;AAIM;AACA;AACA;AACA;AACA;;AAED;AAKG;AACA;AACA;;AA2BV;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChartData, ChartOptions, ChartType } from '@openmaic/dsl';
|
|
1
|
+
import type { ChartData, ChartOptions, ChartType, ImportedChartStyle } from '@openmaic/dsl';
|
|
2
2
|
interface ChartProps {
|
|
3
3
|
width: number;
|
|
4
4
|
height: number;
|
|
@@ -8,6 +8,7 @@ interface ChartProps {
|
|
|
8
8
|
textColor?: string;
|
|
9
9
|
lineColor?: string;
|
|
10
10
|
options?: ChartOptions;
|
|
11
|
+
importedStyle?: ImportedChartStyle;
|
|
11
12
|
}
|
|
12
|
-
export declare function Chart({ width: _width, height: _height, type, data, themeColors: rawThemeColors, textColor, lineColor, options, }: ChartProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function Chart({ width: _width, height: _height, type, data, themeColors: rawThemeColors, textColor, lineColor, options, importedStyle, }: ChartProps): import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -5,7 +5,7 @@ import tinycolor from 'tinycolor2';
|
|
|
5
5
|
import { getChartOption } from './chartOption.js';
|
|
6
6
|
import { loadChartRuntime } from './chartRuntime.js';
|
|
7
7
|
|
|
8
|
-
function Chart({ width: _width, height: _height, type, data, themeColors: rawThemeColors, textColor, lineColor, options, }) {
|
|
8
|
+
function Chart({ width: _width, height: _height, type, data, themeColors: rawThemeColors, textColor, lineColor, options, importedStyle, }) {
|
|
9
9
|
const chartRef = useRef(null);
|
|
10
10
|
const chartInstance = useRef(null);
|
|
11
11
|
const resizeObserverRef = useRef(null);
|
|
@@ -35,17 +35,19 @@ function Chart({ width: _width, height: _height, type, data, themeColors: rawThe
|
|
|
35
35
|
return;
|
|
36
36
|
const option = getChartOption({
|
|
37
37
|
type,
|
|
38
|
+
importedStyle,
|
|
38
39
|
data,
|
|
39
40
|
themeColors,
|
|
40
41
|
textColor,
|
|
41
42
|
lineColor,
|
|
42
43
|
lineSmooth: options?.lineSmooth || false,
|
|
43
44
|
stack: options?.stack || false,
|
|
45
|
+
percentStack: options?.percentStack || false,
|
|
44
46
|
});
|
|
45
47
|
if (option) {
|
|
46
48
|
chartInstance.current.setOption(option, true);
|
|
47
49
|
}
|
|
48
|
-
}, [type, data, themeColors, textColor, lineColor, options]);
|
|
50
|
+
}, [type, data, themeColors, textColor, lineColor, options, importedStyle]);
|
|
49
51
|
useEffect(() => {
|
|
50
52
|
updateOptionRef.current = updateOption;
|
|
51
53
|
}, [updateOption]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chart.js","sources":["../../../src/elements/chart/Chart.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useMemo, useState, useCallback } from 'react';\nimport tinycolor from 'tinycolor2';\nimport type { ChartData, ChartOptions, ChartType } from '@openmaic/dsl';\nimport { getChartOption } from './chartOption';\nimport { loadChartRuntime } from './chartRuntime';\n\ninterface ChartProps {\n width: number;\n height: number;\n type: ChartType;\n data: ChartData;\n themeColors: string[];\n textColor?: string;\n lineColor?: string;\n options?: ChartOptions;\n}\n\nexport function Chart({\n width: _width,\n height: _height,\n type,\n data,\n themeColors: rawThemeColors,\n textColor,\n lineColor,\n options,\n}: ChartProps) {\n const chartRef = useRef<HTMLDivElement>(null);\n const chartInstance = useRef<import('echarts/core').ECharts | null>(null);\n const resizeObserverRef = useRef<ResizeObserver | null>(null);\n const updateOptionRef = useRef<() => void>(() => undefined);\n const [chartState, setChartState] = useState<'loading' | 'ready' | 'error'>('loading');\n\n const themeColors = useMemo(() => {\n let colors: string[] = [];\n if (rawThemeColors.length >= 10) {\n colors = rawThemeColors;\n } else if (rawThemeColors.length === 1) {\n colors = tinycolor(rawThemeColors[0])\n .analogous(10)\n .map((color) => color.toRgbString());\n } else {\n const len = rawThemeColors.length;\n const supplement = tinycolor(rawThemeColors[len - 1])\n .analogous(10 + 1 - len)\n .map((color) => color.toRgbString());\n colors = [...rawThemeColors.slice(0, len - 1), ...supplement];\n }\n return colors;\n }, [rawThemeColors]);\n\n const updateOption = useCallback(() => {\n if (!chartInstance.current) return;\n\n const option = getChartOption({\n type,\n data,\n themeColors,\n textColor,\n lineColor,\n lineSmooth: options?.lineSmooth || false,\n stack: options?.stack || false,\n });\n\n if (option) {\n chartInstance.current.setOption(option, true);\n }\n }, [type, data, themeColors, textColor, lineColor, options]);\n\n useEffect(() => {\n updateOptionRef.current = updateOption;\n }, [updateOption]);\n\n useEffect(() => {\n let mounted = true;\n\n void loadChartRuntime()\n .then((echarts) => {\n if (!mounted || !chartRef.current) return;\n\n chartInstance.current = echarts.init(chartRef.current, null, { renderer: 'svg' });\n setChartState('ready');\n updateOptionRef.current();\n\n const resizeObserver = new ResizeObserver(() => {\n chartInstance.current?.resize();\n });\n resizeObserver.observe(chartRef.current);\n resizeObserverRef.current = resizeObserver;\n })\n .catch(() => {\n if (mounted) setChartState('error');\n });\n\n return () => {\n mounted = false;\n resizeObserverRef.current?.disconnect();\n resizeObserverRef.current = null;\n chartInstance.current?.dispose();\n chartInstance.current = null;\n };\n // The runtime and ECharts instance are initialized once per mounted chart.\n // Option changes are applied by the effect below without re-initializing.\n }, []);\n\n useEffect(() => {\n updateOption();\n }, [updateOption]);\n\n return (\n <div\n ref={chartRef}\n className=\"chart\"\n data-chart-state={chartState}\n aria-busy={chartState === 'loading'}\n style={{ width: '100%', height: '100%' }}\n />\n );\n}\n"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"Chart.js","sources":["../../../src/elements/chart/Chart.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useMemo, useState, useCallback } from 'react';\nimport tinycolor from 'tinycolor2';\nimport type { ChartData, ChartOptions, ChartType, ImportedChartStyle } from '@openmaic/dsl';\nimport { getChartOption } from './chartOption';\nimport { loadChartRuntime } from './chartRuntime';\n\ninterface ChartProps {\n width: number;\n height: number;\n type: ChartType;\n data: ChartData;\n themeColors: string[];\n textColor?: string;\n lineColor?: string;\n options?: ChartOptions;\n importedStyle?: ImportedChartStyle;\n}\n\nexport function Chart({\n width: _width,\n height: _height,\n type,\n data,\n themeColors: rawThemeColors,\n textColor,\n lineColor,\n options,\n importedStyle,\n}: ChartProps) {\n const chartRef = useRef<HTMLDivElement>(null);\n const chartInstance = useRef<import('echarts/core').ECharts | null>(null);\n const resizeObserverRef = useRef<ResizeObserver | null>(null);\n const updateOptionRef = useRef<() => void>(() => undefined);\n const [chartState, setChartState] = useState<'loading' | 'ready' | 'error'>('loading');\n\n const themeColors = useMemo(() => {\n let colors: string[] = [];\n if (rawThemeColors.length >= 10) {\n colors = rawThemeColors;\n } else if (rawThemeColors.length === 1) {\n colors = tinycolor(rawThemeColors[0])\n .analogous(10)\n .map((color) => color.toRgbString());\n } else {\n const len = rawThemeColors.length;\n const supplement = tinycolor(rawThemeColors[len - 1])\n .analogous(10 + 1 - len)\n .map((color) => color.toRgbString());\n colors = [...rawThemeColors.slice(0, len - 1), ...supplement];\n }\n return colors;\n }, [rawThemeColors]);\n\n const updateOption = useCallback(() => {\n if (!chartInstance.current) return;\n\n const option = getChartOption({\n type,\n importedStyle,\n data,\n themeColors,\n textColor,\n lineColor,\n lineSmooth: options?.lineSmooth || false,\n stack: options?.stack || false,\n percentStack: options?.percentStack || false,\n });\n\n if (option) {\n chartInstance.current.setOption(option, true);\n }\n }, [type, data, themeColors, textColor, lineColor, options, importedStyle]);\n\n useEffect(() => {\n updateOptionRef.current = updateOption;\n }, [updateOption]);\n\n useEffect(() => {\n let mounted = true;\n\n void loadChartRuntime()\n .then((echarts) => {\n if (!mounted || !chartRef.current) return;\n\n chartInstance.current = echarts.init(chartRef.current, null, { renderer: 'svg' });\n setChartState('ready');\n updateOptionRef.current();\n\n const resizeObserver = new ResizeObserver(() => {\n chartInstance.current?.resize();\n });\n resizeObserver.observe(chartRef.current);\n resizeObserverRef.current = resizeObserver;\n })\n .catch(() => {\n if (mounted) setChartState('error');\n });\n\n return () => {\n mounted = false;\n resizeObserverRef.current?.disconnect();\n resizeObserverRef.current = null;\n chartInstance.current?.dispose();\n chartInstance.current = null;\n };\n // The runtime and ECharts instance are initialized once per mounted chart.\n // Option changes are applied by the effect below without re-initializing.\n }, []);\n\n useEffect(() => {\n updateOption();\n }, [updateOption]);\n\n return (\n <div\n ref={chartRef}\n className=\"chart\"\n data-chart-state={chartState}\n aria-busy={chartState === 'loading'}\n style={{ width: '100%', height: '100%' }}\n />\n );\n}\n"],"names":[],"mappings":";;;;;;;AAoBM;AAWJ;AACA;AACA;;;AAIA;;AAEE;;;AAEO;AACL;;;;;AAIA;;AAEG;;AAEH;;AAEF;AACF;AAEA;;;;;;;;;;AAUI;AACA;AACA;AACD;;;;AAKH;;AAGE;AACF;;;AAKE;AACG;AACC;;AAEA;;;AAIA;AACE;AACF;AACA;AACA;AACF;;AAEE;;AACF;AAEF;;AAEE;AACA;AACA;AACA;AACF;;;;;AAMA;AACF;AAEA;AASF;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComposeOption } from 'echarts/core';
|
|
2
|
-
import type { BarSeriesOption, LineSeriesOption, PieSeriesOption, ScatterSeriesOption, RadarSeriesOption } from 'echarts/charts';
|
|
3
|
-
import type { ChartData, ChartType } from '@openmaic/dsl';
|
|
4
|
-
type EChartOption = ComposeOption<BarSeriesOption | LineSeriesOption | PieSeriesOption | ScatterSeriesOption | RadarSeriesOption>;
|
|
2
|
+
import type { BarSeriesOption, PictorialBarSeriesOption, LineSeriesOption, PieSeriesOption, ScatterSeriesOption, RadarSeriesOption } from 'echarts/charts';
|
|
3
|
+
import type { ChartData, ChartType, ImportedChartStyle } from '@openmaic/dsl';
|
|
4
|
+
type EChartOption = ComposeOption<PictorialBarSeriesOption | BarSeriesOption | LineSeriesOption | PieSeriesOption | ScatterSeriesOption | RadarSeriesOption>;
|
|
5
5
|
export interface ChartOptionPayload {
|
|
6
6
|
type: ChartType;
|
|
7
7
|
data: ChartData;
|
|
@@ -10,6 +10,8 @@ export interface ChartOptionPayload {
|
|
|
10
10
|
lineColor?: string;
|
|
11
11
|
lineSmooth?: boolean;
|
|
12
12
|
stack?: boolean;
|
|
13
|
+
percentStack?: boolean;
|
|
14
|
+
importedStyle?: ImportedChartStyle;
|
|
13
15
|
}
|
|
14
|
-
export declare const getChartOption: ({ type, data, themeColors, textColor, lineColor, lineSmooth, stack, }: ChartOptionPayload) => EChartOption | null;
|
|
16
|
+
export declare const getChartOption: ({ type, data, themeColors, textColor, lineColor, lineSmooth, stack, percentStack, importedStyle, }: ChartOptionPayload) => EChartOption | null;
|
|
15
17
|
export {};
|
|
@@ -1,52 +1,164 @@
|
|
|
1
|
-
|
|
1
|
+
// ECharts paints pictorial symbols in a square SVG image box. A square wrapper
|
|
2
|
+
// with an explicitly stretched inner image preserves Office's stretch fill.
|
|
3
|
+
function stretchedPictureSymbol(src) {
|
|
4
|
+
const escaped = src.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
5
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0 0 400 400"><image href="${escaped}" x="0" y="0" width="400" height="400" preserveAspectRatio="none"/></svg>`;
|
|
6
|
+
return `image://data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
7
|
+
}
|
|
8
|
+
const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmooth, stack, percentStack, importedStyle, }) => {
|
|
9
|
+
if (!Array.isArray(data?.series) || data.series.length === 0 || !Array.isArray(data.labels)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
2
12
|
const textStyle = textColor ? { color: textColor } : {};
|
|
13
|
+
const normalize = stack && percentStack && ['bar', 'column', 'line', 'area'].includes(type);
|
|
14
|
+
const totals = normalize
|
|
15
|
+
? Array.from({ length: Math.max(0, ...data.series.map((values) => values.length)) }, (_, i) => data.series.reduce((sum, values) => sum + Math.abs(values[i] ?? 0), 0))
|
|
16
|
+
: [];
|
|
17
|
+
const plotSeries = normalize
|
|
18
|
+
? data.series.map((values) => values.map((value, i) => (totals[i] ? value / totals[i] : 0)))
|
|
19
|
+
: data.series;
|
|
20
|
+
const originalValueLabel = (seriesIndex) => normalize
|
|
21
|
+
? {
|
|
22
|
+
formatter: ({ dataIndex }) => String(data.series[seriesIndex][dataIndex]),
|
|
23
|
+
}
|
|
24
|
+
: {};
|
|
3
25
|
const axisLine = textColor ? { lineStyle: { color: textColor } } : undefined;
|
|
4
26
|
const axisLabel = { show: true, color: textColor ?? '#333333' };
|
|
5
27
|
const splitLine = lineColor ? { lineStyle: { color: lineColor } } : {};
|
|
6
|
-
if (!Array.isArray(data?.series) || data.series.length === 0 || !Array.isArray(data.labels)) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
28
|
const categoryAxisLabel = {
|
|
10
29
|
...axisLabel,
|
|
11
30
|
interval: data.labels.length <= 8 ? 0 : 'auto',
|
|
12
31
|
};
|
|
13
32
|
const legend = data.series.length > 1 ? { top: 'bottom', textStyle } : undefined;
|
|
14
|
-
if (type === 'bar') {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
if (type === 'bar' || type === 'column') {
|
|
34
|
+
const importedSeries = importedStyle?.series ?? [];
|
|
35
|
+
const hasPicture = !stack && importedSeries.some((s) => Object.keys(s.pointImages ?? {}).length > 0);
|
|
36
|
+
const axisOptions = (style, category) => ({
|
|
37
|
+
...(style?.show !== undefined ? { show: style.show } : {}),
|
|
38
|
+
axisLine: style
|
|
39
|
+
? {
|
|
40
|
+
show: style.lineVisible ?? true,
|
|
41
|
+
lineStyle: { color: style.lineColor ?? textColor ?? '#333333' },
|
|
42
|
+
}
|
|
43
|
+
: axisLine,
|
|
44
|
+
axisLabel: {
|
|
45
|
+
...(category ? categoryAxisLabel : axisLabel),
|
|
46
|
+
...(!category && /^0(?:\.0+)?%$/.test(style?.numberFormat ?? '')
|
|
47
|
+
? {
|
|
48
|
+
formatter: (value) => `${(value * 100).toFixed((style?.numberFormat?.split('.')[1]?.split('%')[0] ?? '').length)}%`,
|
|
49
|
+
}
|
|
50
|
+
: {}),
|
|
51
|
+
...(style?.labelVisible !== undefined ? { show: style.labelVisible } : {}),
|
|
52
|
+
...(style?.labelColor ? { color: style.labelColor } : {}),
|
|
53
|
+
...(style?.labelFontSize !== undefined ? { fontSize: style.labelFontSize } : {}),
|
|
54
|
+
...(style?.labelBold !== undefined
|
|
55
|
+
? { fontWeight: style.labelBold ? 'bold' : 'normal' }
|
|
56
|
+
: {}),
|
|
57
|
+
},
|
|
58
|
+
splitLine: style?.gridlines !== undefined
|
|
59
|
+
? { show: style.gridlines, lineStyle: { color: style.gridlineColor ?? '#e0e6f1' } }
|
|
60
|
+
: category
|
|
61
|
+
? undefined
|
|
62
|
+
: splitLine,
|
|
63
|
+
...(category
|
|
64
|
+
? {}
|
|
65
|
+
: {
|
|
66
|
+
min: style?.min ??
|
|
67
|
+
(style?.majorUnit && style.majorUnit > 0
|
|
68
|
+
? ({ min }) => Math.floor(Math.min(0, min) / style.majorUnit) * style.majorUnit
|
|
69
|
+
: undefined),
|
|
70
|
+
max: style?.max ??
|
|
71
|
+
(style?.majorUnit && style.majorUnit > 0
|
|
72
|
+
? ({ max }) => Math.ceil(Math.max(0, max) / style.majorUnit) * style.majorUnit
|
|
73
|
+
: undefined),
|
|
74
|
+
interval: style?.majorUnit,
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
const category = {
|
|
78
|
+
type: 'category',
|
|
79
|
+
data: data.labels,
|
|
80
|
+
...axisOptions(importedStyle?.categoryAxis, true),
|
|
33
81
|
};
|
|
34
|
-
|
|
35
|
-
|
|
82
|
+
const value = { type: 'value', ...axisOptions(importedStyle?.valueAxis, false) };
|
|
83
|
+
// Picture-filled percent columns use an extra automatic tick above the peak,
|
|
84
|
+
// matching Office's automatic range while honoring explicit scale settings.
|
|
85
|
+
if (hasPicture &&
|
|
86
|
+
value.max === undefined &&
|
|
87
|
+
!importedStyle?.valueAxis?.majorUnit &&
|
|
88
|
+
/^0(?:\.0+)?%$/.test(importedStyle?.valueAxis?.numberFormat ?? '')) {
|
|
89
|
+
value.max = ({ max }) => {
|
|
90
|
+
if (max <= 0)
|
|
91
|
+
return 0;
|
|
92
|
+
const magnitude = 10 ** Math.floor(Math.log10(max / 6));
|
|
93
|
+
const unit = [1, 2, 5, 10].find((n) => n * magnitude >= max / 6) * magnitude;
|
|
94
|
+
return (Math.floor(max / unit + 1e-9) + 1) * unit;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const plot = importedStyle?.plotArea;
|
|
36
98
|
return {
|
|
37
99
|
color: themeColors,
|
|
38
100
|
textStyle,
|
|
39
101
|
legend,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
102
|
+
...(plot
|
|
103
|
+
? {
|
|
104
|
+
grid: {
|
|
105
|
+
left: `${plot.x * 100}%`,
|
|
106
|
+
top: `${plot.y * 100}%`,
|
|
107
|
+
width: `${plot.w * 100}%`,
|
|
108
|
+
height: `${plot.h * 100}%`,
|
|
109
|
+
containLabel: false,
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
: {}),
|
|
113
|
+
xAxis: type === 'bar' ? category : value,
|
|
114
|
+
yAxis: type === 'bar' ? value : category,
|
|
115
|
+
series: plotSeries.map((item, index) => {
|
|
116
|
+
const style = importedSeries[index];
|
|
117
|
+
// ECharts lays out bar and pictorialBar independently. Keep every
|
|
118
|
+
// unstacked series in the same layout when any point uses a picture;
|
|
119
|
+
// points without images retain a rectangular symbol.
|
|
120
|
+
const picture = !!hasPicture;
|
|
43
121
|
const seriesItem = {
|
|
44
|
-
data:
|
|
122
|
+
data: style || picture
|
|
123
|
+
? item.map((n, i) => ({
|
|
124
|
+
value: n,
|
|
125
|
+
...(picture
|
|
126
|
+
? {
|
|
127
|
+
symbol: style?.pointImages?.[String(i)]
|
|
128
|
+
? stretchedPictureSymbol(style.pointImages[String(i)])
|
|
129
|
+
: 'rect',
|
|
130
|
+
}
|
|
131
|
+
: {}),
|
|
132
|
+
itemStyle: {
|
|
133
|
+
color: style?.pointFills?.[String(i)] ??
|
|
134
|
+
style?.fill ??
|
|
135
|
+
themeColors[index % themeColors.length],
|
|
136
|
+
},
|
|
137
|
+
}))
|
|
138
|
+
: item,
|
|
45
139
|
name: data.legends[index],
|
|
46
|
-
type: 'bar',
|
|
47
|
-
|
|
48
|
-
|
|
140
|
+
type: picture ? 'pictorialBar' : 'bar',
|
|
141
|
+
...(picture
|
|
142
|
+
? {
|
|
143
|
+
symbolSize: ['100%', '100%'],
|
|
144
|
+
symbolRepeat: false,
|
|
145
|
+
symbolClip: false,
|
|
146
|
+
// Override pictorialBar's overlapping/unclipped defaults.
|
|
147
|
+
barGap: '20%',
|
|
148
|
+
clip: true,
|
|
149
|
+
}
|
|
150
|
+
: {}),
|
|
151
|
+
label: { show: style?.showValue ?? true, ...originalValueLabel(index) },
|
|
152
|
+
itemStyle: {
|
|
153
|
+
borderRadius: importedStyle ? 0 : type === 'bar' ? [2, 2, 0, 0] : [0, 2, 2, 0],
|
|
154
|
+
},
|
|
49
155
|
};
|
|
156
|
+
// OOXML gapWidth is the gap as a percentage of a bar's width.
|
|
157
|
+
// For a single/stacked series, convert to percentage of a category band.
|
|
158
|
+
if (importedStyle?.gapWidth !== undefined && (data.series.length === 1 || stack)) {
|
|
159
|
+
const gap = Math.max(0, importedStyle.gapWidth);
|
|
160
|
+
seriesItem.barCategoryGap = `${(gap / (100 + gap)) * 100}%`;
|
|
161
|
+
}
|
|
50
162
|
if (stack)
|
|
51
163
|
seriesItem.stack = 'A';
|
|
52
164
|
return seriesItem;
|
|
@@ -60,13 +172,13 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
60
172
|
legend,
|
|
61
173
|
xAxis: { type: 'category', data: data.labels, axisLine, axisLabel: categoryAxisLabel },
|
|
62
174
|
yAxis: { type: 'value', axisLine, axisLabel, splitLine },
|
|
63
|
-
series:
|
|
175
|
+
series: plotSeries.map((item, index) => {
|
|
64
176
|
const seriesItem = {
|
|
65
177
|
data: item,
|
|
66
178
|
name: data.legends[index],
|
|
67
179
|
type: 'line',
|
|
68
180
|
smooth: lineSmooth,
|
|
69
|
-
label: { show: true },
|
|
181
|
+
label: { show: true, ...originalValueLabel(index) },
|
|
70
182
|
};
|
|
71
183
|
if (stack)
|
|
72
184
|
seriesItem.stack = 'A';
|
|
@@ -131,13 +243,13 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
131
243
|
axisLabel: categoryAxisLabel,
|
|
132
244
|
},
|
|
133
245
|
yAxis: { type: 'value', axisLine, axisLabel, splitLine },
|
|
134
|
-
series:
|
|
246
|
+
series: plotSeries.map((item, index) => {
|
|
135
247
|
const seriesItem = {
|
|
136
248
|
data: item,
|
|
137
249
|
name: data.legends[index],
|
|
138
250
|
type: 'line',
|
|
139
251
|
areaStyle: {},
|
|
140
|
-
label: { show: true },
|
|
252
|
+
label: { show: true, ...originalValueLabel(index) },
|
|
141
253
|
};
|
|
142
254
|
if (stack)
|
|
143
255
|
seriesItem.stack = 'A';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chartOption.js","sources":["../../../src/elements/chart/chartOption.ts"],"sourcesContent":["import type { ComposeOption } from 'echarts/core';\nimport type {\n BarSeriesOption,\n LineSeriesOption,\n PieSeriesOption,\n ScatterSeriesOption,\n RadarSeriesOption,\n} from 'echarts/charts';\nimport type { ChartData, ChartType } from '@openmaic/dsl';\n\ntype EChartOption = ComposeOption<\n BarSeriesOption | LineSeriesOption | PieSeriesOption | ScatterSeriesOption | RadarSeriesOption\n>;\n\nexport interface ChartOptionPayload {\n type: ChartType;\n data: ChartData;\n themeColors: string[];\n textColor?: string;\n lineColor?: string;\n lineSmooth?: boolean;\n stack?: boolean;\n}\n\nexport const getChartOption = ({\n type,\n data,\n themeColors,\n textColor,\n lineColor,\n lineSmooth,\n stack,\n}: ChartOptionPayload): EChartOption | null => {\n const textStyle = textColor ? { color: textColor } : {};\n\n const axisLine = textColor ? { lineStyle: { color: textColor } } : undefined;\n const axisLabel = { show: true, color: textColor ?? '#333333' };\n const splitLine = lineColor ? { lineStyle: { color: lineColor } } : {};\n\n if (!Array.isArray(data?.series) || data.series.length === 0 || !Array.isArray(data.labels)) {\n return null;\n }\n const categoryAxisLabel = {\n ...axisLabel,\n interval: data.labels.length <= 8 ? 0 : ('auto' as const),\n };\n\n const legend = data.series.length > 1 ? { top: 'bottom' as const, textStyle } : undefined;\n\n if (type === 'bar') {\n return {\n color: themeColors,\n textStyle,\n legend,\n xAxis: { type: 'category', data: data.labels, axisLine, axisLabel: categoryAxisLabel },\n yAxis: { type: 'value', axisLine, axisLabel, splitLine },\n series: data.series.map((item, index) => {\n const seriesItem: BarSeriesOption = {\n data: item,\n name: data.legends[index],\n type: 'bar',\n label: { show: true },\n itemStyle: { borderRadius: [2, 2, 0, 0] },\n };\n if (stack) seriesItem.stack = 'A';\n return seriesItem;\n }),\n };\n }\n if (type === 'column') {\n return {\n color: themeColors,\n textStyle,\n legend,\n yAxis: { type: 'category', data: data.labels, axisLine, axisLabel: categoryAxisLabel },\n xAxis: { type: 'value', axisLine, axisLabel, splitLine },\n series: data.series.map((item, index) => {\n const seriesItem: BarSeriesOption = {\n data: item,\n name: data.legends[index],\n type: 'bar',\n label: { show: true },\n itemStyle: { borderRadius: [0, 2, 2, 0] },\n };\n if (stack) seriesItem.stack = 'A';\n return seriesItem;\n }),\n };\n }\n if (type === 'line') {\n return {\n color: themeColors,\n textStyle,\n legend,\n xAxis: { type: 'category', data: data.labels, axisLine, axisLabel: categoryAxisLabel },\n yAxis: { type: 'value', axisLine, axisLabel, splitLine },\n series: data.series.map((item, index) => {\n const seriesItem: LineSeriesOption = {\n data: item,\n name: data.legends[index],\n type: 'line',\n smooth: lineSmooth,\n label: { show: true },\n };\n if (stack) seriesItem.stack = 'A';\n return seriesItem;\n }),\n };\n }\n if (type === 'pie') {\n const series0 = data.series[0];\n if (!Array.isArray(series0)) return null;\n return {\n color: themeColors,\n textStyle,\n legend: { top: 'bottom' as const, textStyle },\n series: [\n {\n data: series0.map((item, index) => ({ value: item, name: data.labels[index] })),\n label: textColor ? { color: textColor } : {},\n type: 'pie',\n radius: '70%',\n emphasis: {\n itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' },\n label: { show: true, fontSize: 14, fontWeight: 'bold' },\n },\n },\n ],\n };\n }\n if (type === 'ring') {\n const series0 = data.series[0];\n if (!Array.isArray(series0)) return null;\n return {\n color: themeColors,\n textStyle,\n legend: { top: 'bottom' as const, textStyle },\n series: [\n {\n data: series0.map((item, index) => ({ value: item, name: data.labels[index] })),\n label: textColor ? { color: textColor } : {},\n type: 'pie',\n radius: ['40%', '70%'],\n padAngle: 1,\n avoidLabelOverlap: false,\n itemStyle: { borderRadius: 4 },\n emphasis: { label: { show: true, fontSize: 14, fontWeight: 'bold' } },\n },\n ],\n };\n }\n if (type === 'area') {\n return {\n color: themeColors,\n textStyle,\n legend,\n xAxis: {\n type: 'category',\n boundaryGap: false,\n data: data.labels,\n axisLine,\n axisLabel: categoryAxisLabel,\n },\n yAxis: { type: 'value', axisLine, axisLabel, splitLine },\n series: data.series.map((item, index) => {\n const seriesItem: LineSeriesOption = {\n data: item,\n name: data.legends[index],\n type: 'line',\n areaStyle: {},\n label: { show: true },\n };\n if (stack) seriesItem.stack = 'A';\n return seriesItem;\n }),\n };\n }\n if (type === 'radar') {\n return {\n color: themeColors,\n textStyle,\n legend,\n radar: {\n indicator: data.labels.map((item) => ({ name: item })),\n splitLine,\n axisLine: lineColor ? { lineStyle: { color: lineColor } } : undefined,\n },\n series: [\n {\n data: data.series.map((item, index) => ({ value: item, name: data.legends[index] })),\n type: 'radar',\n },\n ],\n };\n }\n if (type === 'scatter') {\n const series0 = data.series[0];\n if (!Array.isArray(series0)) return null;\n const formatedData: number[][] = [];\n for (let i = 0; i < series0.length; i++) {\n const x = series0[i];\n const y = data.series[1]?.[i] ?? x;\n formatedData.push([x, y]);\n }\n\n return {\n color: themeColors,\n textStyle,\n xAxis: { axisLine, axisLabel, splitLine },\n yAxis: { axisLine, axisLabel, splitLine },\n series: [{ symbolSize: 12, data: formatedData, type: 'scatter' }],\n };\n }\n\n return null;\n};\n"],"names":[],"mappings":"MAwBa,cAAc,GAAG,CAAC,EAC7B,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,SAAS,EACT,SAAS,EACT,UAAU,EACV,KAAK,GACc,KAAyB;AAC5C,IAAA,MAAM,S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AAA,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE;AACzC,YAAA,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE;AACzC,YAAA,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;SAClE;IACH;AAEA,IAAA,OAAO,IAAI;AACb;;;;"}
|
|
1
|
+
{"version":3,"file":"chartOption.js","sources":["../../../src/elements/chart/chartOption.ts"],"sourcesContent":["import type { ComposeOption } from 'echarts/core';\nimport type {\n BarSeriesOption,\n PictorialBarSeriesOption,\n LineSeriesOption,\n PieSeriesOption,\n ScatterSeriesOption,\n RadarSeriesOption,\n} from 'echarts/charts';\nimport type { ChartData, ChartType, ImportedChartStyle, ImportedChartAxis } from '@openmaic/dsl';\n\ntype EChartOption = ComposeOption<\n | PictorialBarSeriesOption\n | BarSeriesOption\n | LineSeriesOption\n | PieSeriesOption\n | ScatterSeriesOption\n | RadarSeriesOption\n>;\n\nexport interface ChartOptionPayload {\n type: ChartType;\n data: ChartData;\n themeColors: string[];\n textColor?: string;\n lineColor?: string;\n lineSmooth?: boolean;\n stack?: boolean;\n percentStack?: boolean;\n importedStyle?: ImportedChartStyle;\n}\n\n// ECharts paints pictorial symbols in a square SVG image box. A square wrapper\n// with an explicitly stretched inner image preserves Office's stretch fill.\nfunction stretchedPictureSymbol(src: string): string {\n const escaped = src.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<');\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"400\" height=\"400\" viewBox=\"0 0 400 400\"><image href=\"${escaped}\" x=\"0\" y=\"0\" width=\"400\" height=\"400\" preserveAspectRatio=\"none\"/></svg>`;\n return `image://data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;\n}\n\nexport const getChartOption = ({\n type,\n data,\n themeColors,\n textColor,\n lineColor,\n lineSmooth,\n stack,\n percentStack,\n importedStyle,\n}: ChartOptionPayload): EChartOption | null => {\n if (!Array.isArray(data?.series) || data.series.length === 0 || !Array.isArray(data.labels)) {\n return null;\n }\n const textStyle = textColor ? { color: textColor } : {};\n const normalize = stack && percentStack && ['bar', 'column', 'line', 'area'].includes(type);\n const totals = normalize\n ? Array.from({ length: Math.max(0, ...data.series.map((values) => values.length)) }, (_, i) =>\n data.series.reduce((sum, values) => sum + Math.abs(values[i] ?? 0), 0),\n )\n : [];\n const plotSeries = normalize\n ? data.series.map((values) => values.map((value, i) => (totals[i] ? value / totals[i] : 0)))\n : data.series;\n const originalValueLabel = (seriesIndex: number) =>\n normalize\n ? {\n formatter: ({ dataIndex }: { dataIndex: number }) =>\n String(data.series[seriesIndex][dataIndex]),\n }\n : {};\n\n const axisLine = textColor ? { lineStyle: { color: textColor } } : undefined;\n const axisLabel = { show: true, color: textColor ?? '#333333' };\n const splitLine = lineColor ? { lineStyle: { color: lineColor } } : {};\n\n const categoryAxisLabel = {\n ...axisLabel,\n interval: data.labels.length <= 8 ? 0 : ('auto' as const),\n };\n\n const legend = data.series.length > 1 ? { top: 'bottom' as const, textStyle } : undefined;\n\n if (type === 'bar' || type === 'column') {\n const importedSeries = importedStyle?.series ?? [];\n const hasPicture =\n !stack && importedSeries.some((s) => Object.keys(s.pointImages ?? {}).length > 0);\n const axisOptions = (style: ImportedChartAxis | undefined, category: boolean) => ({\n ...(style?.show !== undefined ? { show: style.show } : {}),\n axisLine: style\n ? {\n show: style.lineVisible ?? true,\n lineStyle: { color: style.lineColor ?? textColor ?? '#333333' },\n }\n : axisLine,\n axisLabel: {\n ...(category ? categoryAxisLabel : axisLabel),\n ...(!category && /^0(?:\\.0+)?%$/.test(style?.numberFormat ?? '')\n ? {\n formatter: (value: number) =>\n `${(value * 100).toFixed((style?.numberFormat?.split('.')[1]?.split('%')[0] ?? '').length)}%`,\n }\n : {}),\n ...(style?.labelVisible !== undefined ? { show: style.labelVisible } : {}),\n ...(style?.labelColor ? { color: style.labelColor } : {}),\n ...(style?.labelFontSize !== undefined ? { fontSize: style.labelFontSize } : {}),\n ...(style?.labelBold !== undefined\n ? { fontWeight: style.labelBold ? ('bold' as const) : ('normal' as const) }\n : {}),\n },\n splitLine:\n style?.gridlines !== undefined\n ? { show: style.gridlines, lineStyle: { color: style.gridlineColor ?? '#e0e6f1' } }\n : category\n ? undefined\n : splitLine,\n ...(category\n ? {}\n : {\n min:\n style?.min ??\n (style?.majorUnit && style.majorUnit > 0\n ? ({ min }: { min: number }) =>\n Math.floor(Math.min(0, min) / style.majorUnit!) * style.majorUnit!\n : undefined),\n max:\n style?.max ??\n (style?.majorUnit && style.majorUnit > 0\n ? ({ max }: { max: number }) =>\n Math.ceil(Math.max(0, max) / style.majorUnit!) * style.majorUnit!\n : undefined),\n interval: style?.majorUnit,\n }),\n });\n const category = {\n type: 'category' as const,\n data: data.labels,\n ...axisOptions(importedStyle?.categoryAxis, true),\n };\n const value = { type: 'value' as const, ...axisOptions(importedStyle?.valueAxis, false) };\n // Picture-filled percent columns use an extra automatic tick above the peak,\n // matching Office's automatic range while honoring explicit scale settings.\n if (\n hasPicture &&\n value.max === undefined &&\n !importedStyle?.valueAxis?.majorUnit &&\n /^0(?:\\.0+)?%$/.test(importedStyle?.valueAxis?.numberFormat ?? '')\n ) {\n value.max = ({ max }: { max: number }) => {\n if (max <= 0) return 0;\n const magnitude = 10 ** Math.floor(Math.log10(max / 6));\n const unit = [1, 2, 5, 10].find((n) => n * magnitude >= max / 6)! * magnitude;\n return (Math.floor(max / unit + 1e-9) + 1) * unit;\n };\n }\n const plot = importedStyle?.plotArea;\n return {\n color: themeColors,\n textStyle,\n legend,\n ...(plot\n ? {\n grid: {\n left: `${plot.x * 100}%`,\n top: `${plot.y * 100}%`,\n width: `${plot.w * 100}%`,\n height: `${plot.h * 100}%`,\n containLabel: false,\n },\n }\n : {}),\n xAxis: type === 'bar' ? category : value,\n yAxis: type === 'bar' ? value : category,\n series: plotSeries.map((item, index) => {\n const style = importedSeries[index];\n // ECharts lays out bar and pictorialBar independently. Keep every\n // unstacked series in the same layout when any point uses a picture;\n // points without images retain a rectangular symbol.\n const picture = !!hasPicture;\n const seriesItem: BarSeriesOption | PictorialBarSeriesOption = {\n data:\n style || picture\n ? item.map((n, i) => ({\n value: n,\n ...(picture\n ? {\n symbol: style?.pointImages?.[String(i)]\n ? stretchedPictureSymbol(style.pointImages[String(i)])\n : 'rect',\n }\n : {}),\n itemStyle: {\n color:\n style?.pointFills?.[String(i)] ??\n style?.fill ??\n themeColors[index % themeColors.length],\n },\n }))\n : item,\n name: data.legends[index],\n type: picture ? 'pictorialBar' : 'bar',\n ...(picture\n ? {\n symbolSize: ['100%', '100%'],\n symbolRepeat: false,\n symbolClip: false,\n // Override pictorialBar's overlapping/unclipped defaults.\n barGap: '20%',\n clip: true,\n }\n : {}),\n label: { show: style?.showValue ?? true, ...originalValueLabel(index) },\n itemStyle: {\n borderRadius: importedStyle ? 0 : type === 'bar' ? [2, 2, 0, 0] : [0, 2, 2, 0],\n },\n };\n // OOXML gapWidth is the gap as a percentage of a bar's width.\n // For a single/stacked series, convert to percentage of a category band.\n if (importedStyle?.gapWidth !== undefined && (data.series.length === 1 || stack)) {\n const gap = Math.max(0, importedStyle.gapWidth);\n seriesItem.barCategoryGap = `${(gap / (100 + gap)) * 100}%`;\n }\n if (stack) seriesItem.stack = 'A';\n return seriesItem;\n }),\n };\n }\n if (type === 'line') {\n return {\n color: themeColors,\n textStyle,\n legend,\n xAxis: { type: 'category', data: data.labels, axisLine, axisLabel: categoryAxisLabel },\n yAxis: { type: 'value', axisLine, axisLabel, splitLine },\n series: plotSeries.map((item, index) => {\n const seriesItem: LineSeriesOption = {\n data: item,\n name: data.legends[index],\n type: 'line',\n smooth: lineSmooth,\n label: { show: true, ...originalValueLabel(index) },\n };\n if (stack) seriesItem.stack = 'A';\n return seriesItem;\n }),\n };\n }\n if (type === 'pie') {\n const series0 = data.series[0];\n if (!Array.isArray(series0)) return null;\n return {\n color: themeColors,\n textStyle,\n legend: { top: 'bottom' as const, textStyle },\n series: [\n {\n data: series0.map((item, index) => ({ value: item, name: data.labels[index] })),\n label: textColor ? { color: textColor } : {},\n type: 'pie',\n radius: '70%',\n emphasis: {\n itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' },\n label: { show: true, fontSize: 14, fontWeight: 'bold' },\n },\n },\n ],\n };\n }\n if (type === 'ring') {\n const series0 = data.series[0];\n if (!Array.isArray(series0)) return null;\n return {\n color: themeColors,\n textStyle,\n legend: { top: 'bottom' as const, textStyle },\n series: [\n {\n data: series0.map((item, index) => ({ value: item, name: data.labels[index] })),\n label: textColor ? { color: textColor } : {},\n type: 'pie',\n radius: ['40%', '70%'],\n padAngle: 1,\n avoidLabelOverlap: false,\n itemStyle: { borderRadius: 4 },\n emphasis: { label: { show: true, fontSize: 14, fontWeight: 'bold' } },\n },\n ],\n };\n }\n if (type === 'area') {\n return {\n color: themeColors,\n textStyle,\n legend,\n xAxis: {\n type: 'category',\n boundaryGap: false,\n data: data.labels,\n axisLine,\n axisLabel: categoryAxisLabel,\n },\n yAxis: { type: 'value', axisLine, axisLabel, splitLine },\n series: plotSeries.map((item, index) => {\n const seriesItem: LineSeriesOption = {\n data: item,\n name: data.legends[index],\n type: 'line',\n areaStyle: {},\n label: { show: true, ...originalValueLabel(index) },\n };\n if (stack) seriesItem.stack = 'A';\n return seriesItem;\n }),\n };\n }\n if (type === 'radar') {\n return {\n color: themeColors,\n textStyle,\n legend,\n radar: {\n indicator: data.labels.map((item) => ({ name: item })),\n splitLine,\n axisLine: lineColor ? { lineStyle: { color: lineColor } } : undefined,\n },\n series: [\n {\n data: data.series.map((item, index) => ({ value: item, name: data.legends[index] })),\n type: 'radar',\n },\n ],\n };\n }\n if (type === 'scatter') {\n const series0 = data.series[0];\n if (!Array.isArray(series0)) return null;\n const formatedData: number[][] = [];\n for (let i = 0; i < series0.length; i++) {\n const x = series0[i];\n const y = data.series[1]?.[i] ?? x;\n formatedData.push([x, y]);\n }\n\n return {\n color: themeColors,\n textStyle,\n xAxis: { axisLine, axisLabel, splitLine },\n yAxis: { axisLine, axisLabel, splitLine },\n series: [{ symbolSize: 12, data: formatedData, type: 'scatter' }],\n };\n }\n\n return null;\n};\n"],"names":[],"mappings":"AAgCA;AACA;AACA,SAAS,sBAAsB,CAAC,GAAW,EAAA;IACzC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;AACxF,IAAA,MAAM,GAAG,GAAG,CAAA,oGAAA,EAAuG,OAAO,2EAA2E;AACrM,IAAA,OAAO,4CAA4C,kBAAkB,CAAC,GAAG,CAAC,EAAE;AAC9E;AAEO,MAAM,cAAc,GAAG,CAAC,EAC7B,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,SAAS,EACT,SAAS,EACT,UAAU,EACV,KAAK,EACL,YAAY,EACZ,aAAa,GACM,KAAyB;AAC5C,IAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;AAC3F,QAAA,OAAO,IAAI;IACb;AACA,IAAA,MAAM,SAAS,GAAG,SAAS,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE;IACvD,MAAM,SAAS,GAAG,KAAK,IAAI,YAAY,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC3F,MAAM,MAAM,GAAG;AACb,UAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CA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AAC;QAC3B;QAEA,OAAO;AACL,YAAA,KAAK,EAAE,WAAW;YAClB,SAAS;AACT,YAAA,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE;AACzC,YAAA,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE;AACzC,YAAA,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;SAClE;IACH;AAEA,IAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chartRuntime.js","sources":["../../../src/elements/chart/chartRuntime.ts"],"sourcesContent":["import type * as echartsCore from 'echarts/core';\n\ntype EChartsRuntime = typeof echartsCore;\n\nlet runtimePromise: Promise<EChartsRuntime> | undefined;\n\n/**\n * Load and register the small ECharts surface used by chart elements.\n *\n * Keeping this behind a shared promise is important for two reasons: charts\n * remain optional for consumers that only render text/images, and multiple\n * charts on one slide do not race to register the same ECharts extensions.\n */\nexport function loadChartRuntime(): Promise<EChartsRuntime> {\n runtimePromise ??= Promise.all([\n import('echarts/core'),\n import('echarts/charts'),\n import('echarts/components'),\n import('echarts/renderers'),\n ]).then(([echarts, charts, components, renderers]) => {\n echarts.use([\n charts.BarChart,\n charts.LineChart,\n charts.PieChart,\n charts.ScatterChart,\n charts.RadarChart,\n components.LegendComponent,\n renderers.SVGRenderer,\n ]);\n return echarts;\n });\n\n return runtimePromise;\n}\n"],"names":[],"mappings":"AAIA,IAAI,cAAmD;AAEvD;;;;;;AAMG;SACa,gBAAgB,GAAA;AAC9B,IAAA,cAAc,KAAK,OAAO,CAAC,GAAG,CAAC;QAC7B,OAAO,cAAc,CAAC;QACtB,OAAO,gBAAgB,CAAC;QACxB,OAAO,oBAAoB,CAAC;QAC5B,OAAO,mBAAmB,CAAC;AAC5B,KAAA,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,KAAI;QACnD,OAAO,CAAC,GAAG,CAAC;AACV,YAAA,MAAM,CAAC,QAAQ;AACf,YAAA,MAAM,CAAC,SAAS;AAChB,YAAA,MAAM,CAAC,QAAQ;AACf,YAAA,MAAM,CAAC,YAAY;AACnB,YAAA,MAAM,CAAC,UAAU;AACjB,YAAA,UAAU,CAAC,eAAe;AAC1B,YAAA,SAAS,CAAC,WAAW;AACtB,SAAA,CAAC;AACF,QAAA,OAAO,OAAO;AAChB,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,cAAc;AACvB;;;;"}
|
|
1
|
+
{"version":3,"file":"chartRuntime.js","sources":["../../../src/elements/chart/chartRuntime.ts"],"sourcesContent":["import type * as echartsCore from 'echarts/core';\n\ntype EChartsRuntime = typeof echartsCore;\n\nlet runtimePromise: Promise<EChartsRuntime> | undefined;\n\n/**\n * Load and register the small ECharts surface used by chart elements.\n *\n * Keeping this behind a shared promise is important for two reasons: charts\n * remain optional for consumers that only render text/images, and multiple\n * charts on one slide do not race to register the same ECharts extensions.\n */\nexport function loadChartRuntime(): Promise<EChartsRuntime> {\n runtimePromise ??= Promise.all([\n import('echarts/core'),\n import('echarts/charts'),\n import('echarts/components'),\n import('echarts/renderers'),\n ]).then(([echarts, charts, components, renderers]) => {\n echarts.use([\n charts.BarChart,\n charts.PictorialBarChart,\n charts.LineChart,\n charts.PieChart,\n charts.ScatterChart,\n charts.RadarChart,\n components.LegendComponent,\n renderers.SVGRenderer,\n ]);\n return echarts;\n });\n\n return runtimePromise;\n}\n"],"names":[],"mappings":"AAIA,IAAI,cAAmD;AAEvD;;;;;;AAMG;SACa,gBAAgB,GAAA;AAC9B,IAAA,cAAc,KAAK,OAAO,CAAC,GAAG,CAAC;QAC7B,OAAO,cAAc,CAAC;QACtB,OAAO,gBAAgB,CAAC;QACxB,OAAO,oBAAoB,CAAC;QAC5B,OAAO,mBAAmB,CAAC;AAC5B,KAAA,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,KAAI;QACnD,OAAO,CAAC,GAAG,CAAC;AACV,YAAA,MAAM,CAAC,QAAQ;AACf,YAAA,MAAM,CAAC,iBAAiB;AACxB,YAAA,MAAM,CAAC,SAAS;AAChB,YAAA,MAAM,CAAC,QAAQ;AACf,YAAA,MAAM,CAAC,YAAY;AACnB,YAAA,MAAM,CAAC,UAAU;AACjB,YAAA,UAAU,CAAC,eAAe;AAC1B,YAAA,SAAS,CAAC,WAAW;AACtB,SAAA,CAAC;AACF,QAAA,OAAO,OAAO;AAChB,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,cAAc;AACvB;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bake the soft-edge feather (a:softEdge) into an <img>'s bitmap. html2canvas-pro
|
|
3
|
+
* ignores CSS masks, so the feather BaseImageElement applies is lost in the PNG.
|
|
4
|
+
* The feather radius is read from `data-soft-edge` (px in the element's displayed
|
|
5
|
+
* box) and scaled to the image's natural pixels. Two `destination-in` linear
|
|
6
|
+
* gradient passes multiply the alpha down to 0 within `r` of each edge (corners
|
|
7
|
+
* get both axes), matching the live CSS mask. No-ops on undecoded/ CORS-tainted
|
|
8
|
+
* images or zero radius.
|
|
9
|
+
*/
|
|
10
|
+
export declare function bakeImageSoftEdge(img: HTMLImageElement): Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bake the soft-edge feather (a:softEdge) into an <img>'s bitmap. html2canvas-pro
|
|
3
|
+
* ignores CSS masks, so the feather BaseImageElement applies is lost in the PNG.
|
|
4
|
+
* The feather radius is read from `data-soft-edge` (px in the element's displayed
|
|
5
|
+
* box) and scaled to the image's natural pixels. Two `destination-in` linear
|
|
6
|
+
* gradient passes multiply the alpha down to 0 within `r` of each edge (corners
|
|
7
|
+
* get both axes), matching the live CSS mask. No-ops on undecoded/ CORS-tainted
|
|
8
|
+
* images or zero radius.
|
|
9
|
+
*/
|
|
10
|
+
async function bakeImageSoftEdge(img) {
|
|
11
|
+
const rCss = parseFloat(img.dataset.softEdge || '');
|
|
12
|
+
if (!rCss || rCss <= 0)
|
|
13
|
+
return;
|
|
14
|
+
if (!img.complete || img.naturalWidth === 0)
|
|
15
|
+
return;
|
|
16
|
+
const displayedW = img.offsetWidth || img.naturalWidth;
|
|
17
|
+
const displayedH = img.offsetHeight || img.naturalHeight;
|
|
18
|
+
const w = img.naturalWidth;
|
|
19
|
+
const h = img.naturalHeight;
|
|
20
|
+
const rx = Math.min((rCss * w) / displayedW, w / 2);
|
|
21
|
+
const ry = Math.min((rCss * h) / displayedH, h / 2);
|
|
22
|
+
if (rx <= 0 || ry <= 0)
|
|
23
|
+
return;
|
|
24
|
+
try {
|
|
25
|
+
const canvas = document.createElement('canvas');
|
|
26
|
+
canvas.width = w;
|
|
27
|
+
canvas.height = h;
|
|
28
|
+
const ctx = canvas.getContext('2d');
|
|
29
|
+
if (!ctx)
|
|
30
|
+
return;
|
|
31
|
+
ctx.drawImage(img, 0, 0, w, h);
|
|
32
|
+
ctx.globalCompositeOperation = 'destination-in';
|
|
33
|
+
const stops = (g, extent, r) => {
|
|
34
|
+
const f = r / extent;
|
|
35
|
+
g.addColorStop(0, 'rgba(0,0,0,0)');
|
|
36
|
+
g.addColorStop(f, 'rgba(0,0,0,1)');
|
|
37
|
+
g.addColorStop(1 - f, 'rgba(0,0,0,1)');
|
|
38
|
+
g.addColorStop(1, 'rgba(0,0,0,0)');
|
|
39
|
+
return g;
|
|
40
|
+
};
|
|
41
|
+
const gh = stops(ctx.createLinearGradient(0, 0, w, 0), w, rx);
|
|
42
|
+
ctx.fillStyle = gh;
|
|
43
|
+
ctx.fillRect(0, 0, w, h);
|
|
44
|
+
const gv = stops(ctx.createLinearGradient(0, 0, 0, h), h, ry);
|
|
45
|
+
ctx.fillStyle = gv;
|
|
46
|
+
ctx.fillRect(0, 0, w, h);
|
|
47
|
+
const baked = canvas.toDataURL('image/png');
|
|
48
|
+
img.removeAttribute('data-soft-edge');
|
|
49
|
+
img.style.maskImage = '';
|
|
50
|
+
img.style.webkitMaskImage = '';
|
|
51
|
+
await new Promise((resolve) => {
|
|
52
|
+
img.addEventListener('load', () => resolve(), { once: true });
|
|
53
|
+
img.addEventListener('error', () => resolve(), { once: true });
|
|
54
|
+
img.src = baked;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// CORS-tainted source — keep the original <img>.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { bakeImageSoftEdge };
|
|
63
|
+
//# sourceMappingURL=bakeImageSoftEdge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bakeImageSoftEdge.js","sources":["../../src/snapshot/bakeImageSoftEdge.ts"],"sourcesContent":["/**\n * Bake the soft-edge feather (a:softEdge) into an <img>'s bitmap. html2canvas-pro\n * ignores CSS masks, so the feather BaseImageElement applies is lost in the PNG.\n * The feather radius is read from `data-soft-edge` (px in the element's displayed\n * box) and scaled to the image's natural pixels. Two `destination-in` linear\n * gradient passes multiply the alpha down to 0 within `r` of each edge (corners\n * get both axes), matching the live CSS mask. No-ops on undecoded/ CORS-tainted\n * images or zero radius.\n */\nexport async function bakeImageSoftEdge(img: HTMLImageElement): Promise<void> {\n const rCss = parseFloat(img.dataset.softEdge || '');\n if (!rCss || rCss <= 0) return;\n if (!img.complete || img.naturalWidth === 0) return;\n\n const displayedW = img.offsetWidth || img.naturalWidth;\n const displayedH = img.offsetHeight || img.naturalHeight;\n const w = img.naturalWidth;\n const h = img.naturalHeight;\n const rx = Math.min((rCss * w) / displayedW, w / 2);\n const ry = Math.min((rCss * h) / displayedH, h / 2);\n if (rx <= 0 || ry <= 0) return;\n\n try {\n const canvas = document.createElement('canvas');\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.drawImage(img, 0, 0, w, h);\n ctx.globalCompositeOperation = 'destination-in';\n\n const stops = (g: CanvasGradient, extent: number, r: number) => {\n const f = r / extent;\n g.addColorStop(0, 'rgba(0,0,0,0)');\n g.addColorStop(f, 'rgba(0,0,0,1)');\n g.addColorStop(1 - f, 'rgba(0,0,0,1)');\n g.addColorStop(1, 'rgba(0,0,0,0)');\n return g;\n };\n const gh = stops(ctx.createLinearGradient(0, 0, w, 0), w, rx);\n ctx.fillStyle = gh;\n ctx.fillRect(0, 0, w, h);\n const gv = stops(ctx.createLinearGradient(0, 0, 0, h), h, ry);\n ctx.fillStyle = gv;\n ctx.fillRect(0, 0, w, h);\n\n const baked = canvas.toDataURL('image/png');\n img.removeAttribute('data-soft-edge');\n img.style.maskImage = '';\n (img.style as unknown as Record<string, string>).webkitMaskImage = '';\n await new Promise<void>((resolve) => {\n img.addEventListener('load', () => resolve(), { once: true });\n img.addEventListener('error', () => resolve(), { once: true });\n img.src = baked;\n });\n } catch {\n // CORS-tainted source — keep the original <img>.\n }\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;AAQG;AACI,eAAe,iBAAiB,CAAC,GAAqB,EAAA;AAC3D,IAAA,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;AACnD,IAAA,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC;QAAE;IACxB,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,YAAY,KAAK,CAAC;QAAE;IAE7C,MAAM,UAAU,GAAG,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,YAAY;IACtD,MAAM,UAAU,GAAG,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,aAAa;AACxD,IAAA,MAAM,CAAC,GAAG,GAAG,CAAC,YAAY;AAC1B,IAAA,MAAM,CAAC,GAAG,GAAG,CAAC,aAAa;AAC3B,IAAA,MAAM,EAAE,GAA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7D,QAAA,GAAG,CAAC,SAAS,GAAG,EAAE;QAClB,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACxB,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;AAC7D,QAAA,GAAG,CAAC,SAAS,GAAG,EAAE;QAClB,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAExB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC;AAC3C,QAAA,GAAG,CAAC,eAAe,CAAC,gBAAgB,CAAC;AACrC,QAAA,GAAG,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE;AACvB,QAAA,GAAG,CAAC,KAA2C,CAAC,eAAe,GAAG,EAAE;AACrE,QAAA,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,KAAI;AAClC,YAAA,GAAG,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC7D,YAAA,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC9D,YAAA,GAAG,CAAC,GAAG,GAAG,KAAK;AACjB,QAAA,CAAC,CAAC;IACJ;AAAE,IAAA,MAAM;;IAER;AACF;;;;"}
|
package/dist/snapshot/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { bakeImageSoftEdge } from './bakeImageSoftEdge.js';
|
|
2
3
|
import { createElement } from 'react';
|
|
3
4
|
import { flushSync } from 'react-dom';
|
|
4
5
|
import { createRoot } from 'react-dom/client';
|
|
@@ -358,65 +359,6 @@ async function bakeImageFilter(img) {
|
|
|
358
359
|
// CORS-tainted source or unsupported ctx.filter — keep the original <img>.
|
|
359
360
|
}
|
|
360
361
|
}
|
|
361
|
-
/**
|
|
362
|
-
* Bake the soft-edge feather (a:softEdge) into an <img>'s bitmap. html2canvas-pro
|
|
363
|
-
* ignores CSS masks, so the feather BaseImageElement applies is lost in the PNG.
|
|
364
|
-
* The feather radius is read from `data-soft-edge` (px in the element's displayed
|
|
365
|
-
* box) and scaled to the image's natural pixels. Two `destination-in` linear
|
|
366
|
-
* gradient passes multiply the alpha down to 0 within `r` of each edge (corners
|
|
367
|
-
* get both axes), matching the live CSS mask. No-ops on undecoded/ CORS-tainted
|
|
368
|
-
* images or zero radius.
|
|
369
|
-
*/
|
|
370
|
-
async function bakeImageSoftEdge(img) {
|
|
371
|
-
const rCss = parseFloat(img.dataset.softEdge || '');
|
|
372
|
-
if (!rCss || rCss <= 0)
|
|
373
|
-
return;
|
|
374
|
-
if (!img.complete || img.naturalWidth === 0)
|
|
375
|
-
return;
|
|
376
|
-
const displayedW = img.offsetWidth || img.naturalWidth;
|
|
377
|
-
const scale = img.naturalWidth / displayedW;
|
|
378
|
-
const w = img.naturalWidth;
|
|
379
|
-
const h = img.naturalHeight;
|
|
380
|
-
const r = Math.min(rCss * scale, w / 2, h / 2);
|
|
381
|
-
if (r <= 0)
|
|
382
|
-
return;
|
|
383
|
-
try {
|
|
384
|
-
const canvas = document.createElement('canvas');
|
|
385
|
-
canvas.width = w;
|
|
386
|
-
canvas.height = h;
|
|
387
|
-
const ctx = canvas.getContext('2d');
|
|
388
|
-
if (!ctx)
|
|
389
|
-
return;
|
|
390
|
-
ctx.drawImage(img, 0, 0, w, h);
|
|
391
|
-
ctx.globalCompositeOperation = 'destination-in';
|
|
392
|
-
const stops = (g, extent) => {
|
|
393
|
-
const f = r / extent;
|
|
394
|
-
g.addColorStop(0, 'rgba(0,0,0,0)');
|
|
395
|
-
g.addColorStop(f, 'rgba(0,0,0,1)');
|
|
396
|
-
g.addColorStop(1 - f, 'rgba(0,0,0,1)');
|
|
397
|
-
g.addColorStop(1, 'rgba(0,0,0,0)');
|
|
398
|
-
return g;
|
|
399
|
-
};
|
|
400
|
-
const gh = stops(ctx.createLinearGradient(0, 0, w, 0), w);
|
|
401
|
-
ctx.fillStyle = gh;
|
|
402
|
-
ctx.fillRect(0, 0, w, h);
|
|
403
|
-
const gv = stops(ctx.createLinearGradient(0, 0, 0, h), h);
|
|
404
|
-
ctx.fillStyle = gv;
|
|
405
|
-
ctx.fillRect(0, 0, w, h);
|
|
406
|
-
const baked = canvas.toDataURL('image/png');
|
|
407
|
-
img.removeAttribute('data-soft-edge');
|
|
408
|
-
img.style.maskImage = '';
|
|
409
|
-
img.style.webkitMaskImage = '';
|
|
410
|
-
await new Promise((resolve) => {
|
|
411
|
-
img.addEventListener('load', () => resolve(), { once: true });
|
|
412
|
-
img.addEventListener('error', () => resolve(), { once: true });
|
|
413
|
-
img.src = baked;
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
catch {
|
|
417
|
-
// CORS-tainted source — keep the original <img>.
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
362
|
function canvasToBlob(canvas) {
|
|
421
363
|
return new Promise((resolve, reject) => {
|
|
422
364
|
canvas.toBlob((blob) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/snapshot/index.ts"],"sourcesContent":["'use client';\n\n/**\n * Off-screen Slide → PNG renderer.\n *\n * Mounts the given `Slide` into an off-screen container at its native pixel\n * size, waits for fonts + images to settle, then rasterizes the DOM. Returns the\n * rendered output as a Blob (default) or a `data:image/png;base64,...` string.\n *\n * Rasterization is native-paint-first: `html-to-image` serializes the slide into\n * an SVG `<foreignObject>` that the **same Chrome engine painting the live\n * classroom** rasterizes — so formulas (KaTeX HTML), CSS `filter`, soft-edge\n * `mask`, and mixed CJK/Latin text come out exactly as the classroom shows them.\n * html2canvas-pro, by contrast, re-implements layout/paint and so re-rasterizes\n * KaTeX's vlist/frac-line/delimiter internals, drops CSS filter/mask, and can't\n * draw `<video>` — all sources of the exported-vs-live drift.\n *\n * The one thing a foreignObject SVG can't do is reach the document's font\n * registry, so web fonts must be inlined as data URLs first (`getFontEmbedCSS`).\n * This is the historical reason html-to-image was avoided (fonts loaded async →\n * fallback-font wrapping); embedding up front removes it. If the embed still\n * misses the KaTeX faces, or a cross-origin image taints the canvas, we fall back\n * to html2canvas-pro (baking filter/mask into pixels and neutralizing its KaTeX\n * text-rendering override) rather than ship broken output.\n *\n * Use cases: visual regression baselines (compare with the source PPT's\n * own PNG export), user-triggered \"export slide as image\", CI snapshot\n * jobs. Caller does not need a live `<SlideCanvas>` mounted in the UI.\n */\n\nimport { createElement } from 'react';\nimport { flushSync } from 'react-dom';\nimport { createRoot, type Root } from 'react-dom/client';\nimport html2canvas from 'html2canvas-pro';\nimport { getFontEmbedCSS, toBlob, toPng } from 'html-to-image';\nimport { SlideCanvas } from '../SlideCanvas';\nimport type { Slide } from '@openmaic/dsl';\nimport { KATEX_FONT_EMBED_CSS } from './katex-fonts-embed';\n\nexport { measureSlideElementGeometry, type MeasuredGeometry, type MeasureOptions } from './measure';\n\nexport interface SlideToPngOptions {\n /**\n * Output pixel width. Defaults to the slide's native `viewportSize`\n * (e.g. 1280 for a 16:9 widescreen deck). Height is derived from\n * `viewportRatio`.\n */\n width?: number;\n /**\n * Multiplier on output resolution. Default tracks `window.devicePixelRatio`\n * (typically 2 on retina displays) so the exported PNG is as sharp as\n * the on-screen canvas. Pass 1 for a lighter file at the cost of\n * sub-pixel clarity.\n */\n pixelRatio?: number;\n /**\n * Background color filled behind the slide. Defaults to white. Pass\n * 'transparent' to keep the slide's own background only.\n */\n backgroundColor?: string;\n /**\n * Output format. 'blob' yields a `Blob` suitable for `URL.createObjectURL`\n * + download; 'dataUrl' yields a `data:image/png;base64,...` string.\n */\n format?: 'blob' | 'dataUrl';\n /**\n * Settle timeout in milliseconds. The snapshot waits for `document.fonts.ready`\n * and every `<img>` inside the container to load (or error) before\n * capturing — but won't wait longer than this. Defaults to 5000.\n */\n timeoutMs?: number;\n /**\n * Debug only — render the off-screen container on-screen for the given\n * number of milliseconds after snapshot so you can visually confirm what\n * was captured. Do not use in production.\n */\n debugVisibleMs?: number;\n}\n\nconst DEFAULT_VIEWPORT_RATIO = 0.5625;\nconst DEFAULT_TIMEOUT_MS = 5000;\n\n/**\n * Render a `Slide` to a PNG image.\n *\n * Throws if called outside a browser (no `document` / `window`), if React\n * fails to mount, or if html2canvas-pro hits a CORS-tainted canvas (cross-\n * origin `<img>` without permissive headers will block the snapshot).\n */\nexport async function slideToPng(\n slide: Slide,\n options: SlideToPngOptions = {},\n): Promise<Blob | string> {\n if (typeof document === 'undefined') {\n throw new Error('slideToPng requires a browser environment');\n }\n\n const width = options.width ?? slide.viewportSize ?? 1280;\n const viewportRatio = slide.viewportRatio ?? DEFAULT_VIEWPORT_RATIO;\n const height = Math.round(width * viewportRatio);\n const backgroundColor = options.backgroundColor ?? '#ffffff';\n const pixelRatio = options.pixelRatio ?? window.devicePixelRatio ?? 1;\n const format = options.format ?? 'blob';\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const debugVisibleMs = options.debugVisibleMs ?? 0;\n\n // Off-screen container sized exactly to the slide so SlideCanvas's\n // fit-to-container math collapses to a 1:1 native render (no scale, no\n // centering offset). `position: absolute` (not fixed) + far-left offset\n // keeps the element in layout but out of the viewport; some browsers\n // skip paint for `position: fixed` elements outside the viewport, which\n // breaks the snapshot.\n const container = document.createElement('div');\n container.style.cssText = [\n 'position: absolute',\n 'left: -99999px',\n 'top: 0',\n `width: ${width}px`,\n `height: ${height}px`,\n 'pointer-events: none',\n `background-color: ${backgroundColor}`,\n ].join('; ');\n document.body.appendChild(container);\n\n let root: Root | null = null;\n try {\n root = createRoot(container);\n // flushSync forces the initial commit to happen synchronously instead of\n // being deferred by React 18's scheduler. Without it, the next RAFs can\n // fire before the first render lands and the snapshot captures an empty\n // container.\n flushSync(() => {\n root!.render(createElement(SlideCanvas, { slide, chrome: false }));\n });\n\n // BaseImageElement renders <img loading=\"lazy\">, and this container sits\n // permanently outside the viewport — lazy images would never fetch, and\n // the load-wait below would time out on blank slides. Force eager loading\n // for the throwaway tree so snapshot behavior is unchanged.\n container.querySelectorAll('img').forEach((img) => {\n img.loading = 'eager';\n });\n\n // Give the SlideCanvas's ResizeObserver-driven `useViewportSize` a few\n // frames to fire and write `fitScale`. Default state already paints at\n // 1:1, but waiting avoids a flash of unscaled content when the slide\n // viewportSize differs from the container.\n await nextFrame();\n await nextFrame();\n\n // Charts load ECharts asynchronously because it is an optional peer\n // dependency. Wait for every chart element to finish loading before\n // rasterizing; otherwise exports can capture the intentionally empty\n // loading container while the live slide eventually renders correctly.\n await waitForCharts(container, timeoutMs);\n\n // Explicitly force-load every (style, weight, family) the slide actually\n // uses BEFORE snapshotting. `document.fonts.ready` alone is racy: it can\n // resolve before the off-screen render has triggered a self-hosted woff2\n // fetch, so html2canvas captures a fallback face. For mixed CJK+Latin text\n // the fallback's Latin/digit advance widths differ from the intended font,\n // shifting number/English runs (seen on cold single-slide exports). Loading\n // each face up front makes the capture deterministic regardless of warmup.\n if (document.fonts && typeof document.fonts.load === 'function') {\n const fontSpecs = new Set<string>();\n container.querySelectorAll<HTMLElement>('*').forEach((el) => {\n if (!el.textContent || !el.textContent.trim()) return;\n const cs = getComputedStyle(el);\n if (!cs.fontFamily) return;\n fontSpecs.add(`${cs.fontStyle} ${cs.fontWeight} 16px ${cs.fontFamily}`);\n });\n await Promise.race([\n Promise.all([...fontSpecs].map((spec) => document.fonts.load(spec).catch(() => undefined))),\n new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n }\n\n await Promise.race([\n Promise.all([\n document.fonts ? document.fonts.ready : Promise.resolve(),\n ...Array.from(container.querySelectorAll('img')).map((img) => {\n if (img.complete && img.naturalWidth > 0) return Promise.resolve();\n return new Promise<void>((resolve) => {\n const done = () => resolve();\n img.addEventListener('load', done, { once: true });\n img.addEventListener('error', done, { once: true });\n });\n }),\n ]),\n new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n\n // html2canvas-pro can't draw <video> elements (it ignores the `poster`\n // attribute and renders nothing for an undecoded source), so a video that\n // shows fine on the live canvas comes out白板 in the PNG. Convert every\n // <video> in the throwaway off-screen tree into an <img> of its poster\n // (or current decoded frame) BEFORE the snapshot. The native-paint path can\n // render a poster'd <video>, but a posterless one still needs the decoded\n // frame, so we do this for both capture paths.\n await Promise.all(\n Array.from(container.querySelectorAll('video')).map((video) => replaceVideoWithFrame(video)),\n );\n\n // Let any font-triggered relayout settle before capture. KaTeX formulas\n // re-run their shrink-to-fit measurement once the KaTeX_Size faces finish\n // loading (BaseLatexElement); that's a React state update, so give it two\n // frames to commit before we read the DOM — otherwise a cold export can\n // capture the stale fallback-metric scale (misaligned large braces).\n await nextFrame();\n await nextFrame();\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.debug('[slideToPng] container ready', {\n innerHTMLLength: container.innerHTML.length,\n imgCount: container.querySelectorAll('img').length,\n size: `${width}x${height}`,\n });\n }\n\n // Target the inner SlideCanvas root so the capture's bounding box matches the\n // slide exactly (otherwise the outer container's padding/margin assumptions\n // can leave white edges).\n const target = (container.firstElementChild as HTMLElement | null) ?? container;\n\n // PRIMARY: native paint via `html-to-image` (foreignObject → the same Chrome\n // engine that paints the live classroom rasterizes the same DOM). Reproduces\n // formulas, CSS filter, soft-edge masks, and mixed CJK/Latin text as the\n // classroom shows them — no per-feature bakes.\n //\n // A foreignObject SVG can't reach the document font registry, so fonts must\n // be inlined as data URLs first. KaTeX math faces are prepended from the\n // bundled woff2 ({@link KATEX_FONT_EMBED_CSS}) — NOT left to `getFontEmbedCSS`,\n // which reads `cssRules` and silently drops a cross-origin KaTeX stylesheet,\n // collapsing large braces to a fallback glyph. `getFontEmbedCSS` still runs\n // for brand/CJK web fonts. As a belt-and-braces guard we verify every KaTeX\n // face the formula actually references is present in the combined CSS, and\n // fall back to html2canvas rather than ship broken glyphs if any is missing.\n try {\n const fontEmbedCSS = KATEX_FONT_EMBED_CSS + '\\n' + (await getFontEmbedCSS(target));\n const missing = missingKatexFaces(target, fontEmbedCSS);\n if (missing.length > 0) {\n throw new Error(\n `KaTeX font faces not embedded (${missing.join(', ')}); using html2canvas fallback`,\n );\n }\n const nativeOpts = {\n width,\n height,\n pixelRatio,\n backgroundColor,\n fontEmbedCSS,\n cacheBust: false,\n };\n if (format === 'blob') {\n const blob = await toBlob(target, nativeOpts);\n if (!blob) throw new Error('html-to-image toBlob returned null');\n return blob;\n }\n return await toPng(target, nativeOpts);\n } catch (nativeErr) {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.debug(\n '[slideToPng] native paint unavailable, falling back to html2canvas:',\n nativeErr,\n );\n }\n }\n\n // FALLBACK: html2canvas-pro. Reached only when native paint fails (e.g. a\n // cross-origin image taints the foreignObject canvas). It can't render CSS\n // `filter` (PPT lum/alphaModFix washout) or the soft-edge `mask`\n // (a:softEdge), so bake both into pixels first with a Canvas2D pass.\n await Promise.all(\n Array.from(container.querySelectorAll('img')).map((img) => bakeImageFilter(img)),\n );\n await Promise.all(\n Array.from(container.querySelectorAll<HTMLImageElement>('img[data-soft-edge]')).map((img) =>\n bakeImageSoftEdge(img),\n ),\n );\n\n const canvas = await html2canvas(target, {\n backgroundColor,\n width,\n height,\n scale: pixelRatio,\n useCORS: true,\n // Skip walking the page's stylesheets; the cloned DOM already inherits\n // computed styles. This also avoids CORS errors when the document has\n // cross-origin stylesheets.\n foreignObjectRendering: false,\n logging: false,\n // html2canvas-pro's CJK text measurement can mis-position full-width\n // punctuation (e.g. `(`/`)` get pushed past the cell boundary and\n // appear clipped). Force neutral kerning + feature settings on the\n // cloned tree so each glyph advances at its natural width — but restore\n // native rendering for KaTeX, whose glyph metrics the override would\n // reshape (misaligned braces/subscripts).\n onclone: (clonedDoc) => {\n const style = clonedDoc.createElement('style');\n style.textContent = `\n .slide-renderer-cell-text,\n .slide-renderer-cell-text *,\n .slide-renderer-prose,\n .slide-renderer-prose * {\n font-kerning: none !important;\n font-feature-settings: normal !important;\n font-variant-east-asian: normal !important;\n text-rendering: geometricPrecision !important;\n }\n .slide-renderer-prose .katex,\n .slide-renderer-prose .katex * {\n font-kerning: auto !important;\n text-rendering: auto !important;\n }\n `;\n clonedDoc.head.appendChild(style);\n },\n });\n\n if (format === 'blob') {\n return await canvasToBlob(canvas);\n }\n return canvas.toDataURL('image/png');\n } finally {\n if (debugVisibleMs > 0) {\n // Temporarily show the container on-screen so the caller can compare\n // what was captured vs the on-page render.\n container.style.left = '0';\n container.style.top = '0';\n container.style.zIndex = '99999';\n container.style.border = '4px dashed magenta';\n await new Promise((r) => setTimeout(r, debugVisibleMs));\n }\n // Defer unmount one tick so React doesn't warn about unmounting during\n // a commit phase (the html2canvas promise can still be mid-render in\n // dev mode).\n if (root) {\n const r = root;\n setTimeout(() => r.unmount(), 0);\n }\n setTimeout(() => container.remove(), 0);\n }\n}\n\nfunction nextFrame(): Promise<void> {\n return new Promise((resolve) => requestAnimationFrame(() => resolve()));\n}\n\nasync function waitForCharts(root: HTMLElement, timeoutMs: number): Promise<void> {\n const deadline = performance.now() + timeoutMs;\n while (root.querySelector('[data-chart-state=\"loading\"]')) {\n if (performance.now() >= deadline) return;\n await nextFrame();\n }\n}\n\n/**\n * KaTeX faces (`KaTeX_Main`, `KaTeX_Size4`, …) actually referenced by the\n * formulas in `root` that are NOT declared in `fontEmbedCSS`. A non-empty result\n * means the native-paint capture would render those glyphs in a fallback font\n * (e.g. a large brace collapsing to a small `{`), so the caller falls back to\n * html2canvas. Reads each `.katex` descendant's computed `font-family` — the\n * families the browser resolved for the glyphs actually on screen — rather than\n * assuming the full set, so an all-embedded formula never triggers a fallback.\n */\nfunction missingKatexFaces(root: HTMLElement, fontEmbedCSS: string): string[] {\n const used = new Set<string>();\n root.querySelectorAll<HTMLElement>('.katex, .katex *').forEach((el) => {\n for (const part of getComputedStyle(el).fontFamily.split(',')) {\n const name = part.trim().replace(/^[\"']|[\"']$/g, '');\n if (name.startsWith('KaTeX_')) used.add(name);\n }\n });\n return [...used].filter((face) => !fontEmbedCSS.includes(face));\n}\n\n/**\n * Replace a <video> with an <img> showing its poster (or, if no poster is set,\n * its current decoded frame drawn onto a canvas). Copies the video's inline\n * style so layout is unchanged, then waits for the <img> to load so the\n * subsequent html2canvas pass captures it. No-ops if there's nothing to draw.\n */\nasync function replaceVideoWithFrame(video: HTMLVideoElement): Promise<void> {\n const parent = video.parentElement;\n if (!parent) return;\n\n let imgSrc: string | null = video.poster || video.getAttribute('poster') || null;\n\n // No poster but the source decoded → grab the current frame.\n if (!imgSrc && video.readyState >= 2 && video.videoWidth > 0) {\n try {\n const frame = document.createElement('canvas');\n frame.width = video.videoWidth;\n frame.height = video.videoHeight;\n frame.getContext('2d')?.drawImage(video, 0, 0);\n imgSrc = frame.toDataURL('image/png');\n } catch {\n // CORS-tainted frame — leave imgSrc null and bail below.\n }\n }\n if (!imgSrc) return;\n\n const img = document.createElement('img');\n img.src = imgSrc;\n img.style.cssText = video.style.cssText;\n if (!img.style.width) img.style.width = '100%';\n if (!img.style.height) img.style.height = '100%';\n if (!img.style.objectFit) img.style.objectFit = 'contain';\n\n await new Promise<void>((resolve) => {\n if (img.complete && img.naturalWidth > 0) return resolve();\n img.addEventListener('load', () => resolve(), { once: true });\n img.addEventListener('error', () => resolve(), { once: true });\n });\n\n parent.replaceChild(img, video);\n}\n\n/**\n * Bake an <img>'s CSS `filter` into its bitmap. html2canvas-pro ignores the\n * `filter` property, so without this any brightness/contrast/saturate/opacity\n * applied by the renderer (PPT lum/alphaModFix corrections) is lost in the PNG.\n * Draws the image through a Canvas2D `ctx.filter` pass, swaps the src for the\n * baked PNG, and clears the inline filter so the value isn't double-applied.\n * No-ops when there's no filter, the image hasn't decoded, or the canvas is\n * CORS-tainted (export would throw — leave the original img untouched).\n */\nasync function bakeImageFilter(img: HTMLImageElement): Promise<void> {\n const filter = (img.style.filter || '').trim();\n if (!filter || filter === 'none') return;\n if (!img.complete || img.naturalWidth === 0) return;\n\n try {\n const canvas = document.createElement('canvas');\n canvas.width = img.naturalWidth;\n canvas.height = img.naturalHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.filter = filter;\n ctx.drawImage(img, 0, 0, canvas.width, canvas.height);\n const baked = canvas.toDataURL('image/png');\n\n img.style.filter = '';\n await new Promise<void>((resolve) => {\n img.addEventListener('load', () => resolve(), { once: true });\n img.addEventListener('error', () => resolve(), { once: true });\n img.src = baked;\n });\n } catch {\n // CORS-tainted source or unsupported ctx.filter — keep the original <img>.\n }\n}\n\n/**\n * Bake the soft-edge feather (a:softEdge) into an <img>'s bitmap. html2canvas-pro\n * ignores CSS masks, so the feather BaseImageElement applies is lost in the PNG.\n * The feather radius is read from `data-soft-edge` (px in the element's displayed\n * box) and scaled to the image's natural pixels. Two `destination-in` linear\n * gradient passes multiply the alpha down to 0 within `r` of each edge (corners\n * get both axes), matching the live CSS mask. No-ops on undecoded/ CORS-tainted\n * images or zero radius.\n */\nasync function bakeImageSoftEdge(img: HTMLImageElement): Promise<void> {\n const rCss = parseFloat(img.dataset.softEdge || '');\n if (!rCss || rCss <= 0) return;\n if (!img.complete || img.naturalWidth === 0) return;\n\n const displayedW = img.offsetWidth || img.naturalWidth;\n const scale = img.naturalWidth / displayedW;\n const w = img.naturalWidth;\n const h = img.naturalHeight;\n const r = Math.min(rCss * scale, w / 2, h / 2);\n if (r <= 0) return;\n\n try {\n const canvas = document.createElement('canvas');\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.drawImage(img, 0, 0, w, h);\n ctx.globalCompositeOperation = 'destination-in';\n\n const stops = (g: CanvasGradient, extent: number) => {\n const f = r / extent;\n g.addColorStop(0, 'rgba(0,0,0,0)');\n g.addColorStop(f, 'rgba(0,0,0,1)');\n g.addColorStop(1 - f, 'rgba(0,0,0,1)');\n g.addColorStop(1, 'rgba(0,0,0,0)');\n return g;\n };\n const gh = stops(ctx.createLinearGradient(0, 0, w, 0), w);\n ctx.fillStyle = gh;\n ctx.fillRect(0, 0, w, h);\n const gv = stops(ctx.createLinearGradient(0, 0, 0, h), h);\n ctx.fillStyle = gv;\n ctx.fillRect(0, 0, w, h);\n\n const baked = canvas.toDataURL('image/png');\n img.removeAttribute('data-soft-edge');\n img.style.maskImage = '';\n (img.style as unknown as Record<string, string>).webkitMaskImage = '';\n await new Promise<void>((resolve) => {\n img.addEventListener('load', () => resolve(), { once: true });\n img.addEventListener('error', () => resolve(), { once: true });\n img.src = baked;\n });\n } catch {\n // CORS-tainted source — keep the original <img>.\n }\n}\n\nfunction canvasToBlob(canvas: HTMLCanvasElement): Promise<Blob> {\n return new Promise((resolve, reject) => {\n canvas.toBlob((blob) => {\n if (blob) resolve(blob);\n else reject(new Error('slideToPng: canvas.toBlob returned null'));\n }, 'image/png');\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+EA;AACA;AAEA;;;;;;AAMG;AACI;AAIL;AACE;;;AAIF;;AAEA;;AAEA;AACA;AACA;;;;;;;;AASA;;;;AAIE;AACA;;AAEA;AACD;AACD;;AAGA;AACE;;;;;;AAME;AACF;;;;;;AAOE;AACF;;;;;;;;;;;AAaA;;;;;;;;AASA;AACE;;;;AAGE;;;AAEA;AACF;;AAEE;AACA;AACD;;;;AAKC;AACA;;AAC4C;AAC1C;AACE;AACA;AACA;AACF;AACF;;AAEF;AACD;;;;;;;;AASD;;;;;;;;;;AAcE;AACE;;AAEA;AACD;;;;;AAMH;;;;;;;;;;;;;;AAeA;AACE;;AAEA;AACE;;AAIF;;;;;;AAME;;AAEF;;AAEE;AAAW;AACX;;AAEF;;;;;AAIE;;;;;;;AAWJ;AAGA;AAMA;;;;AAIE;AACA;;;;AAIA;AACA;;;;;;;AAOA;;;;;;;;;;;;;;;;;;AAkBE;;AAEH;AAED;AACE;;AAEF;;;AAEA;;;AAGE;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWN;AAEA;AACE;AACF;AAEA;;AAEE;AACE;;;;AAGJ;AAEA;;;;;;;;AAQG;AACH;AACE;;AAEE;AACE;AACA;AAA+B;;AAEnC;;AAEF;AAEA;;;;;AAKG;AACH;AACE;AACA;;AAEA;;AAGA;AACE;;AAEE;AACA;AACA;AACA;;AACA;;;;AAIJ;;;AAGA;;AAEA;AAAsB;AACtB;AAAuB;AACvB;AAA0B;AAE1B;;;AAEE;AACA;AACF;AAEA;AACF;AAEA;;;;;;;;AAQG;AACH;AACE;AACA;;;;AAGA;;AAEE;AACA;;AAEA;;AACA;AACA;;AAGA;AACA;AACE;AACA;AACA;AACF;;AACA;;;AAGJ;AAEA;;;;;;;;AAQG;AACH;AACE;AACA;;;;;AAIA;AACA;AACA;AACA;;;AAGA;;AAEE;AACA;;AAEA;;AACA;AACA;AAEA;AACE;AACA;AACA;;AAEA;AACA;AACF;AACA;AACA;;AAEA;AACA;;;AAIA;AACA;AACC;AACD;AACE;AACA;AACA;AACF;;AACA;;;AAGJ;AAEA;;AAEI;AACE;;;AACK;;AAET;AACF;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/snapshot/index.ts"],"sourcesContent":["'use client';\n\nimport { bakeImageSoftEdge } from './bakeImageSoftEdge';\n\n/**\n * Off-screen Slide → PNG renderer.\n *\n * Mounts the given `Slide` into an off-screen container at its native pixel\n * size, waits for fonts + images to settle, then rasterizes the DOM. Returns the\n * rendered output as a Blob (default) or a `data:image/png;base64,...` string.\n *\n * Rasterization is native-paint-first: `html-to-image` serializes the slide into\n * an SVG `<foreignObject>` that the **same Chrome engine painting the live\n * classroom** rasterizes — so formulas (KaTeX HTML), CSS `filter`, soft-edge\n * `mask`, and mixed CJK/Latin text come out exactly as the classroom shows them.\n * html2canvas-pro, by contrast, re-implements layout/paint and so re-rasterizes\n * KaTeX's vlist/frac-line/delimiter internals, drops CSS filter/mask, and can't\n * draw `<video>` — all sources of the exported-vs-live drift.\n *\n * The one thing a foreignObject SVG can't do is reach the document's font\n * registry, so web fonts must be inlined as data URLs first (`getFontEmbedCSS`).\n * This is the historical reason html-to-image was avoided (fonts loaded async →\n * fallback-font wrapping); embedding up front removes it. If the embed still\n * misses the KaTeX faces, or a cross-origin image taints the canvas, we fall back\n * to html2canvas-pro (baking filter/mask into pixels and neutralizing its KaTeX\n * text-rendering override) rather than ship broken output.\n *\n * Use cases: visual regression baselines (compare with the source PPT's\n * own PNG export), user-triggered \"export slide as image\", CI snapshot\n * jobs. Caller does not need a live `<SlideCanvas>` mounted in the UI.\n */\n\nimport { createElement } from 'react';\nimport { flushSync } from 'react-dom';\nimport { createRoot, type Root } from 'react-dom/client';\nimport html2canvas from 'html2canvas-pro';\nimport { getFontEmbedCSS, toBlob, toPng } from 'html-to-image';\nimport { SlideCanvas } from '../SlideCanvas';\nimport type { Slide } from '@openmaic/dsl';\nimport { KATEX_FONT_EMBED_CSS } from './katex-fonts-embed';\n\nexport { measureSlideElementGeometry, type MeasuredGeometry, type MeasureOptions } from './measure';\n\nexport interface SlideToPngOptions {\n /**\n * Output pixel width. Defaults to the slide's native `viewportSize`\n * (e.g. 1280 for a 16:9 widescreen deck). Height is derived from\n * `viewportRatio`.\n */\n width?: number;\n /**\n * Multiplier on output resolution. Default tracks `window.devicePixelRatio`\n * (typically 2 on retina displays) so the exported PNG is as sharp as\n * the on-screen canvas. Pass 1 for a lighter file at the cost of\n * sub-pixel clarity.\n */\n pixelRatio?: number;\n /**\n * Background color filled behind the slide. Defaults to white. Pass\n * 'transparent' to keep the slide's own background only.\n */\n backgroundColor?: string;\n /**\n * Output format. 'blob' yields a `Blob` suitable for `URL.createObjectURL`\n * + download; 'dataUrl' yields a `data:image/png;base64,...` string.\n */\n format?: 'blob' | 'dataUrl';\n /**\n * Settle timeout in milliseconds. The snapshot waits for `document.fonts.ready`\n * and every `<img>` inside the container to load (or error) before\n * capturing — but won't wait longer than this. Defaults to 5000.\n */\n timeoutMs?: number;\n /**\n * Debug only — render the off-screen container on-screen for the given\n * number of milliseconds after snapshot so you can visually confirm what\n * was captured. Do not use in production.\n */\n debugVisibleMs?: number;\n}\n\nconst DEFAULT_VIEWPORT_RATIO = 0.5625;\nconst DEFAULT_TIMEOUT_MS = 5000;\n\n/**\n * Render a `Slide` to a PNG image.\n *\n * Throws if called outside a browser (no `document` / `window`), if React\n * fails to mount, or if html2canvas-pro hits a CORS-tainted canvas (cross-\n * origin `<img>` without permissive headers will block the snapshot).\n */\nexport async function slideToPng(\n slide: Slide,\n options: SlideToPngOptions = {},\n): Promise<Blob | string> {\n if (typeof document === 'undefined') {\n throw new Error('slideToPng requires a browser environment');\n }\n\n const width = options.width ?? slide.viewportSize ?? 1280;\n const viewportRatio = slide.viewportRatio ?? DEFAULT_VIEWPORT_RATIO;\n const height = Math.round(width * viewportRatio);\n const backgroundColor = options.backgroundColor ?? '#ffffff';\n const pixelRatio = options.pixelRatio ?? window.devicePixelRatio ?? 1;\n const format = options.format ?? 'blob';\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const debugVisibleMs = options.debugVisibleMs ?? 0;\n\n // Off-screen container sized exactly to the slide so SlideCanvas's\n // fit-to-container math collapses to a 1:1 native render (no scale, no\n // centering offset). `position: absolute` (not fixed) + far-left offset\n // keeps the element in layout but out of the viewport; some browsers\n // skip paint for `position: fixed` elements outside the viewport, which\n // breaks the snapshot.\n const container = document.createElement('div');\n container.style.cssText = [\n 'position: absolute',\n 'left: -99999px',\n 'top: 0',\n `width: ${width}px`,\n `height: ${height}px`,\n 'pointer-events: none',\n `background-color: ${backgroundColor}`,\n ].join('; ');\n document.body.appendChild(container);\n\n let root: Root | null = null;\n try {\n root = createRoot(container);\n // flushSync forces the initial commit to happen synchronously instead of\n // being deferred by React 18's scheduler. Without it, the next RAFs can\n // fire before the first render lands and the snapshot captures an empty\n // container.\n flushSync(() => {\n root!.render(createElement(SlideCanvas, { slide, chrome: false }));\n });\n\n // BaseImageElement renders <img loading=\"lazy\">, and this container sits\n // permanently outside the viewport — lazy images would never fetch, and\n // the load-wait below would time out on blank slides. Force eager loading\n // for the throwaway tree so snapshot behavior is unchanged.\n container.querySelectorAll('img').forEach((img) => {\n img.loading = 'eager';\n });\n\n // Give the SlideCanvas's ResizeObserver-driven `useViewportSize` a few\n // frames to fire and write `fitScale`. Default state already paints at\n // 1:1, but waiting avoids a flash of unscaled content when the slide\n // viewportSize differs from the container.\n await nextFrame();\n await nextFrame();\n\n // Charts load ECharts asynchronously because it is an optional peer\n // dependency. Wait for every chart element to finish loading before\n // rasterizing; otherwise exports can capture the intentionally empty\n // loading container while the live slide eventually renders correctly.\n await waitForCharts(container, timeoutMs);\n\n // Explicitly force-load every (style, weight, family) the slide actually\n // uses BEFORE snapshotting. `document.fonts.ready` alone is racy: it can\n // resolve before the off-screen render has triggered a self-hosted woff2\n // fetch, so html2canvas captures a fallback face. For mixed CJK+Latin text\n // the fallback's Latin/digit advance widths differ from the intended font,\n // shifting number/English runs (seen on cold single-slide exports). Loading\n // each face up front makes the capture deterministic regardless of warmup.\n if (document.fonts && typeof document.fonts.load === 'function') {\n const fontSpecs = new Set<string>();\n container.querySelectorAll<HTMLElement>('*').forEach((el) => {\n if (!el.textContent || !el.textContent.trim()) return;\n const cs = getComputedStyle(el);\n if (!cs.fontFamily) return;\n fontSpecs.add(`${cs.fontStyle} ${cs.fontWeight} 16px ${cs.fontFamily}`);\n });\n await Promise.race([\n Promise.all([...fontSpecs].map((spec) => document.fonts.load(spec).catch(() => undefined))),\n new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n }\n\n await Promise.race([\n Promise.all([\n document.fonts ? document.fonts.ready : Promise.resolve(),\n ...Array.from(container.querySelectorAll('img')).map((img) => {\n if (img.complete && img.naturalWidth > 0) return Promise.resolve();\n return new Promise<void>((resolve) => {\n const done = () => resolve();\n img.addEventListener('load', done, { once: true });\n img.addEventListener('error', done, { once: true });\n });\n }),\n ]),\n new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n\n // html2canvas-pro can't draw <video> elements (it ignores the `poster`\n // attribute and renders nothing for an undecoded source), so a video that\n // shows fine on the live canvas comes out白板 in the PNG. Convert every\n // <video> in the throwaway off-screen tree into an <img> of its poster\n // (or current decoded frame) BEFORE the snapshot. The native-paint path can\n // render a poster'd <video>, but a posterless one still needs the decoded\n // frame, so we do this for both capture paths.\n await Promise.all(\n Array.from(container.querySelectorAll('video')).map((video) => replaceVideoWithFrame(video)),\n );\n\n // Let any font-triggered relayout settle before capture. KaTeX formulas\n // re-run their shrink-to-fit measurement once the KaTeX_Size faces finish\n // loading (BaseLatexElement); that's a React state update, so give it two\n // frames to commit before we read the DOM — otherwise a cold export can\n // capture the stale fallback-metric scale (misaligned large braces).\n await nextFrame();\n await nextFrame();\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.debug('[slideToPng] container ready', {\n innerHTMLLength: container.innerHTML.length,\n imgCount: container.querySelectorAll('img').length,\n size: `${width}x${height}`,\n });\n }\n\n // Target the inner SlideCanvas root so the capture's bounding box matches the\n // slide exactly (otherwise the outer container's padding/margin assumptions\n // can leave white edges).\n const target = (container.firstElementChild as HTMLElement | null) ?? container;\n\n // PRIMARY: native paint via `html-to-image` (foreignObject → the same Chrome\n // engine that paints the live classroom rasterizes the same DOM). Reproduces\n // formulas, CSS filter, soft-edge masks, and mixed CJK/Latin text as the\n // classroom shows them — no per-feature bakes.\n //\n // A foreignObject SVG can't reach the document font registry, so fonts must\n // be inlined as data URLs first. KaTeX math faces are prepended from the\n // bundled woff2 ({@link KATEX_FONT_EMBED_CSS}) — NOT left to `getFontEmbedCSS`,\n // which reads `cssRules` and silently drops a cross-origin KaTeX stylesheet,\n // collapsing large braces to a fallback glyph. `getFontEmbedCSS` still runs\n // for brand/CJK web fonts. As a belt-and-braces guard we verify every KaTeX\n // face the formula actually references is present in the combined CSS, and\n // fall back to html2canvas rather than ship broken glyphs if any is missing.\n try {\n const fontEmbedCSS = KATEX_FONT_EMBED_CSS + '\\n' + (await getFontEmbedCSS(target));\n const missing = missingKatexFaces(target, fontEmbedCSS);\n if (missing.length > 0) {\n throw new Error(\n `KaTeX font faces not embedded (${missing.join(', ')}); using html2canvas fallback`,\n );\n }\n const nativeOpts = {\n width,\n height,\n pixelRatio,\n backgroundColor,\n fontEmbedCSS,\n cacheBust: false,\n };\n if (format === 'blob') {\n const blob = await toBlob(target, nativeOpts);\n if (!blob) throw new Error('html-to-image toBlob returned null');\n return blob;\n }\n return await toPng(target, nativeOpts);\n } catch (nativeErr) {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.debug(\n '[slideToPng] native paint unavailable, falling back to html2canvas:',\n nativeErr,\n );\n }\n }\n\n // FALLBACK: html2canvas-pro. Reached only when native paint fails (e.g. a\n // cross-origin image taints the foreignObject canvas). It can't render CSS\n // `filter` (PPT lum/alphaModFix washout) or the soft-edge `mask`\n // (a:softEdge), so bake both into pixels first with a Canvas2D pass.\n await Promise.all(\n Array.from(container.querySelectorAll('img')).map((img) => bakeImageFilter(img)),\n );\n await Promise.all(\n Array.from(container.querySelectorAll<HTMLImageElement>('img[data-soft-edge]')).map((img) =>\n bakeImageSoftEdge(img),\n ),\n );\n\n const canvas = await html2canvas(target, {\n backgroundColor,\n width,\n height,\n scale: pixelRatio,\n useCORS: true,\n // Skip walking the page's stylesheets; the cloned DOM already inherits\n // computed styles. This also avoids CORS errors when the document has\n // cross-origin stylesheets.\n foreignObjectRendering: false,\n logging: false,\n // html2canvas-pro's CJK text measurement can mis-position full-width\n // punctuation (e.g. `(`/`)` get pushed past the cell boundary and\n // appear clipped). Force neutral kerning + feature settings on the\n // cloned tree so each glyph advances at its natural width — but restore\n // native rendering for KaTeX, whose glyph metrics the override would\n // reshape (misaligned braces/subscripts).\n onclone: (clonedDoc) => {\n const style = clonedDoc.createElement('style');\n style.textContent = `\n .slide-renderer-cell-text,\n .slide-renderer-cell-text *,\n .slide-renderer-prose,\n .slide-renderer-prose * {\n font-kerning: none !important;\n font-feature-settings: normal !important;\n font-variant-east-asian: normal !important;\n text-rendering: geometricPrecision !important;\n }\n .slide-renderer-prose .katex,\n .slide-renderer-prose .katex * {\n font-kerning: auto !important;\n text-rendering: auto !important;\n }\n `;\n clonedDoc.head.appendChild(style);\n },\n });\n\n if (format === 'blob') {\n return await canvasToBlob(canvas);\n }\n return canvas.toDataURL('image/png');\n } finally {\n if (debugVisibleMs > 0) {\n // Temporarily show the container on-screen so the caller can compare\n // what was captured vs the on-page render.\n container.style.left = '0';\n container.style.top = '0';\n container.style.zIndex = '99999';\n container.style.border = '4px dashed magenta';\n await new Promise((r) => setTimeout(r, debugVisibleMs));\n }\n // Defer unmount one tick so React doesn't warn about unmounting during\n // a commit phase (the html2canvas promise can still be mid-render in\n // dev mode).\n if (root) {\n const r = root;\n setTimeout(() => r.unmount(), 0);\n }\n setTimeout(() => container.remove(), 0);\n }\n}\n\nfunction nextFrame(): Promise<void> {\n return new Promise((resolve) => requestAnimationFrame(() => resolve()));\n}\n\nasync function waitForCharts(root: HTMLElement, timeoutMs: number): Promise<void> {\n const deadline = performance.now() + timeoutMs;\n while (root.querySelector('[data-chart-state=\"loading\"]')) {\n if (performance.now() >= deadline) return;\n await nextFrame();\n }\n}\n\n/**\n * KaTeX faces (`KaTeX_Main`, `KaTeX_Size4`, …) actually referenced by the\n * formulas in `root` that are NOT declared in `fontEmbedCSS`. A non-empty result\n * means the native-paint capture would render those glyphs in a fallback font\n * (e.g. a large brace collapsing to a small `{`), so the caller falls back to\n * html2canvas. Reads each `.katex` descendant's computed `font-family` — the\n * families the browser resolved for the glyphs actually on screen — rather than\n * assuming the full set, so an all-embedded formula never triggers a fallback.\n */\nfunction missingKatexFaces(root: HTMLElement, fontEmbedCSS: string): string[] {\n const used = new Set<string>();\n root.querySelectorAll<HTMLElement>('.katex, .katex *').forEach((el) => {\n for (const part of getComputedStyle(el).fontFamily.split(',')) {\n const name = part.trim().replace(/^[\"']|[\"']$/g, '');\n if (name.startsWith('KaTeX_')) used.add(name);\n }\n });\n return [...used].filter((face) => !fontEmbedCSS.includes(face));\n}\n\n/**\n * Replace a <video> with an <img> showing its poster (or, if no poster is set,\n * its current decoded frame drawn onto a canvas). Copies the video's inline\n * style so layout is unchanged, then waits for the <img> to load so the\n * subsequent html2canvas pass captures it. No-ops if there's nothing to draw.\n */\nasync function replaceVideoWithFrame(video: HTMLVideoElement): Promise<void> {\n const parent = video.parentElement;\n if (!parent) return;\n\n let imgSrc: string | null = video.poster || video.getAttribute('poster') || null;\n\n // No poster but the source decoded → grab the current frame.\n if (!imgSrc && video.readyState >= 2 && video.videoWidth > 0) {\n try {\n const frame = document.createElement('canvas');\n frame.width = video.videoWidth;\n frame.height = video.videoHeight;\n frame.getContext('2d')?.drawImage(video, 0, 0);\n imgSrc = frame.toDataURL('image/png');\n } catch {\n // CORS-tainted frame — leave imgSrc null and bail below.\n }\n }\n if (!imgSrc) return;\n\n const img = document.createElement('img');\n img.src = imgSrc;\n img.style.cssText = video.style.cssText;\n if (!img.style.width) img.style.width = '100%';\n if (!img.style.height) img.style.height = '100%';\n if (!img.style.objectFit) img.style.objectFit = 'contain';\n\n await new Promise<void>((resolve) => {\n if (img.complete && img.naturalWidth > 0) return resolve();\n img.addEventListener('load', () => resolve(), { once: true });\n img.addEventListener('error', () => resolve(), { once: true });\n });\n\n parent.replaceChild(img, video);\n}\n\n/**\n * Bake an <img>'s CSS `filter` into its bitmap. html2canvas-pro ignores the\n * `filter` property, so without this any brightness/contrast/saturate/opacity\n * applied by the renderer (PPT lum/alphaModFix corrections) is lost in the PNG.\n * Draws the image through a Canvas2D `ctx.filter` pass, swaps the src for the\n * baked PNG, and clears the inline filter so the value isn't double-applied.\n * No-ops when there's no filter, the image hasn't decoded, or the canvas is\n * CORS-tainted (export would throw — leave the original img untouched).\n */\nasync function bakeImageFilter(img: HTMLImageElement): Promise<void> {\n const filter = (img.style.filter || '').trim();\n if (!filter || filter === 'none') return;\n if (!img.complete || img.naturalWidth === 0) return;\n\n try {\n const canvas = document.createElement('canvas');\n canvas.width = img.naturalWidth;\n canvas.height = img.naturalHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.filter = filter;\n ctx.drawImage(img, 0, 0, canvas.width, canvas.height);\n const baked = canvas.toDataURL('image/png');\n\n img.style.filter = '';\n await new Promise<void>((resolve) => {\n img.addEventListener('load', () => resolve(), { once: true });\n img.addEventListener('error', () => resolve(), { once: true });\n img.src = baked;\n });\n } catch {\n // CORS-tainted source or unsupported ctx.filter — keep the original <img>.\n }\n}\n\nfunction canvasToBlob(canvas: HTMLCanvasElement): Promise<Blob> {\n return new Promise((resolve, reject) => {\n canvas.toBlob((blob) => {\n if (blob) resolve(blob);\n else reject(new Error('slideToPng: canvas.toBlob returned null'));\n }, 'image/png');\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAiFA;AACA;AAEA;;;;;;AAMG;AACI;AAIL;AACE;;;AAIF;;AAEA;;AAEA;AACA;AACA;;;;;;;;AASA;;;;AAIE;AACA;;AAEA;AACD;AACD;;AAGA;AACE;;;;;;AAME;AACF;;;;;;AAOE;AACF;;;;;;;;;;;AAaA;;;;;;;;AASA;AACE;;;;AAGE;;;AAEA;AACF;;AAEE;AACA;AACD;;;;AAKC;AACA;;AAC4C;AAC1C;AACE;AACA;AACA;AACF;AACF;;AAEF;AACD;;;;;;;;AASD;;;;;;;;;;AAcE;AACE;;AAEA;AACD;;;;;AAMH;;;;;;;;;;;;;;AAeA;AACE;;AAEA;AACE;;AAIF;;;;;;AAME;;AAEF;;AAEE;AAAW;AACX;;AAEF;;;;;AAIE;;;;;;;AAWJ;AAGA;AAMA;;;;AAIE;AACA;;;;AAIA;AACA;;;;;;;AAOA;;;;;;;;;;;;;;;;;;AAkBE;;AAEH;AAED;AACE;;AAEF;;;AAEA;;;AAGE;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWN;AAEA;AACE;AACF;AAEA;;AAEE;AACE;;;;AAGJ;AAEA;;;;;;;;AAQG;AACH;AACE;;AAEE;AACE;AACA;AAA+B;;AAEnC;;AAEF;AAEA;;;;;AAKG;AACH;AACE;AACA;;AAEA;;AAGA;AACE;;AAEE;AACA;AACA;AACA;;AACA;;;;AAIJ;;;AAGA;;AAEA;AAAsB;AACtB;AAAuB;AACvB;AAA0B;AAE1B;;;AAEE;AACA;AACF;AAEA;AACF;AAEA;;;;;;;;AAQG;AACH;AACE;AACA;;;;AAGA;;AAEE;AACA;;AAEA;;AACA;AACA;;AAGA;AACA;AACE;AACA;AACA;AACF;;AACA;;;AAGJ;AAEA;;AAEI;AACE;;;AACK;;AAET;AACF;;"}
|
package/dist/utils/element.js
CHANGED
|
@@ -25,13 +25,38 @@ const getRectRotatedRange = (element) => {
|
|
|
25
25
|
yRange: [Math.min(...yAxis), Math.max(...yAxis)],
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
+
// Preserve the existing endpoint-offset routing rule. Using the expanded
|
|
29
|
+
// bounds here would let a control point change the double elbow's direction.
|
|
30
|
+
const isHorizontalElbow = (start, end) => Math.max(start[0], end[0]) >= Math.max(start[1], end[1]);
|
|
28
31
|
const getElementRange = (element) => {
|
|
29
32
|
let minX, maxX, minY, maxY;
|
|
30
33
|
if (element.type === 'line') {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const xs = [element.start[0], element.end[0]];
|
|
35
|
+
const ys = [element.start[1], element.end[1]];
|
|
36
|
+
// Follow the same path-variant precedence as getLineElementPath. Bezier
|
|
37
|
+
// control hulls conservatively enclose the curve; elbows use drawn vertices.
|
|
38
|
+
if (element.broken) {
|
|
39
|
+
xs.push(element.broken[0]);
|
|
40
|
+
ys.push(element.broken[1]);
|
|
41
|
+
}
|
|
42
|
+
else if (element.broken2) {
|
|
43
|
+
if (isHorizontalElbow(element.start, element.end))
|
|
44
|
+
xs.push(element.broken2[0]);
|
|
45
|
+
else
|
|
46
|
+
ys.push(element.broken2[1]);
|
|
47
|
+
}
|
|
48
|
+
else if (element.curve) {
|
|
49
|
+
xs.push(element.curve[0]);
|
|
50
|
+
ys.push(element.curve[1]);
|
|
51
|
+
}
|
|
52
|
+
else if (element.cubic) {
|
|
53
|
+
xs.push(element.cubic[0][0], element.cubic[1][0]);
|
|
54
|
+
ys.push(element.cubic[0][1], element.cubic[1][1]);
|
|
55
|
+
}
|
|
56
|
+
minX = element.left + Math.min(...xs);
|
|
57
|
+
maxX = element.left + Math.max(...xs);
|
|
58
|
+
minY = element.top + Math.min(...ys);
|
|
59
|
+
maxY = element.top + Math.max(...ys);
|
|
35
60
|
}
|
|
36
61
|
else if ('rotate' in element && element.rotate) {
|
|
37
62
|
const { left, top, width, height, rotate } = element;
|
|
@@ -63,8 +88,7 @@ const getLineElementPath = (element) => {
|
|
|
63
88
|
return `M${start} L${mid} L${end}`;
|
|
64
89
|
}
|
|
65
90
|
else if (element.broken2) {
|
|
66
|
-
|
|
67
|
-
if (maxX - minX >= maxY - minY)
|
|
91
|
+
if (isHorizontalElbow(startArr, endArr))
|
|
68
92
|
return `M${start} L${element.broken2[0]},${startArr[1]} L${element.broken2[0]},${endArr[1]} ${end}`;
|
|
69
93
|
return `M${start} L${startArr[0]},${element.broken2[1]} L${endArr[0]},${element.broken2[1]} ${end}`;
|
|
70
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sources":["../../src/utils/element.ts"],"sourcesContent":["import tinycolor from 'tinycolor2';\nimport type { PPTElement, PPTLineElement } from '@openmaic/dsl';\n\ninterface RotatedElementData {\n left: number;\n top: number;\n width: number;\n height: number;\n rotate: number;\n}\n\nexport const getRectRotatedRange = (element: RotatedElementData) => {\n const { left, top, width, height, rotate = 0 } = element;\n\n const radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / 2;\n const auxiliaryAngle = (Math.atan(height / width) * 180) / Math.PI;\n\n const tlbraRadian = ((180 - rotate - auxiliaryAngle) * Math.PI) / 180;\n const trblaRadian = ((auxiliaryAngle - rotate) * Math.PI) / 180;\n\n const middleLeft = left + width / 2;\n const middleTop = top + height / 2;\n\n const xAxis = [\n middleLeft + radius * Math.cos(tlbraRadian),\n middleLeft + radius * Math.cos(trblaRadian),\n middleLeft - radius * Math.cos(tlbraRadian),\n middleLeft - radius * Math.cos(trblaRadian),\n ];\n const yAxis = [\n middleTop - radius * Math.sin(tlbraRadian),\n middleTop - radius * Math.sin(trblaRadian),\n middleTop + radius * Math.sin(tlbraRadian),\n middleTop + radius * Math.sin(trblaRadian),\n ];\n\n return {\n xRange: [Math.min(...xAxis), Math.max(...xAxis)],\n yRange: [Math.min(...yAxis), Math.max(...yAxis)],\n };\n};\n\nexport const getElementRange = (element: PPTElement) => {\n let minX: number, maxX: number, minY: number, maxY: number;\n\n if (element.type === 'line') {\n minX = element.left;\n maxX = element.left + Math.max(element.start[0], element.end[0]);\n minY = element.top;\n maxY = element.top + Math.max(element.start[1], element.end[1]);\n } else if ('rotate' in element && element.rotate) {\n const { left, top, width, height, rotate } = element;\n const { xRange, yRange } = getRectRotatedRange({ left, top, width, height, rotate });\n minX = xRange[0];\n maxX = xRange[1];\n minY = yRange[0];\n maxY = yRange[1];\n } else {\n minX = element.left;\n maxX = element.left + element.width;\n minY = element.top;\n maxY = element.top + element.height;\n }\n return { minX, maxX, minY, maxY };\n};\n\nexport const getTableSubThemeColor = (themeColor: string) => {\n const rgba = tinycolor(themeColor);\n return [rgba.setAlpha(0.3).toRgbString(), rgba.setAlpha(0.1).toRgbString()];\n};\n\nexport const getLineElementPath = (element: PPTLineElement) => {\n const startArr = Array.isArray(element.start) ? element.start : [0, 0];\n const endArr = Array.isArray(element.end) ? element.end : [100, 100];\n const start = startArr.join(',');\n const end = endArr.join(',');\n if (element.broken) {\n const mid = element.broken.join(',');\n return `M${start} L${mid} L${end}`;\n } else if (element.broken2) {\n const { minX, maxX, minY, maxY } = getElementRange(element);\n if (maxX - minX >= maxY - minY)\n return `M${start} L${element.broken2[0]},${startArr[1]} L${element.broken2[0]},${endArr[1]} ${end}`;\n return `M${start} L${startArr[0]},${element.broken2[1]} L${endArr[0]},${element.broken2[1]} ${end}`;\n } else if (element.curve) {\n const mid = element.curve.join(',');\n return `M${start} Q${mid} ${end}`;\n } else if (element.cubic) {\n const [c1, c2] = element.cubic;\n const p1 = c1.join(',');\n const p2 = c2.join(',');\n return `M${start} C${p1} ${p2} ${end}`;\n }\n return `M${start} L${end}`;\n};\n"],"names":[],"mappings":";;AAWO,MAAM,mBAAmB,GAAG,CAAC,OAA2B,KAAI;AACjE,IAAA,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO;IAExD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACtE,IAAA,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE;AAElE,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,GAAG,MAAM,GAAG,cAAc,IAAI,IAAI,CAAC,EAAE,IAAI,GAAG;AACrE,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,cAAc,GAAG,MAAM,IAAI,IAAI,CAAC,EAAE,IAAI,GAAG;AAE/D,IAAA,MAAM,UAAU,GAAG,IAAI,GAAG,KAAK,GAAG,CAAC;AACnC,IAAA,MAAM,SAAS,GAAG,GAAG,GAAG,MAAM,GAAG,CAAC;AAElC,IAAA,MAAM,KAAK,GAAG;QACZ,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;QAC3C,UAAU,GAAG,MAAM,GAAG,IAAI,CA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G,EAAE;IACrG;AAAO,SAAA,IAAI,OAAO,CAAC,KAAK,EAAE;QACxB,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;AACnC,QAAA,OAAO,IAAI,KAAK,CAAA,EAAA,EAAK,GAAG,CAAA,CAAA,EAAI,GAAG,EAAE;IACnC;AAAO,SAAA,IAAI,OAAO,CAAC,KAAK,EAAE;QACxB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK;QAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACvB,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,EAAK,EAAE,IAAI,EAAE,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE;IACxC;AACA,IAAA,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,EAAK,GAAG,EAAE;AAC5B;;;;"}
|
|
1
|
+
{"version":3,"file":"element.js","sources":["../../src/utils/element.ts"],"sourcesContent":["import tinycolor from 'tinycolor2';\nimport type { PPTElement, PPTLineElement } from '@openmaic/dsl';\n\ninterface RotatedElementData {\n left: number;\n top: number;\n width: number;\n height: number;\n rotate: number;\n}\n\nexport const getRectRotatedRange = (element: RotatedElementData) => {\n const { left, top, width, height, rotate = 0 } = element;\n\n const radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / 2;\n const auxiliaryAngle = (Math.atan(height / width) * 180) / Math.PI;\n\n const tlbraRadian = ((180 - rotate - auxiliaryAngle) * Math.PI) / 180;\n const trblaRadian = ((auxiliaryAngle - rotate) * Math.PI) / 180;\n\n const middleLeft = left + width / 2;\n const middleTop = top + height / 2;\n\n const xAxis = [\n middleLeft + radius * Math.cos(tlbraRadian),\n middleLeft + radius * Math.cos(trblaRadian),\n middleLeft - radius * Math.cos(tlbraRadian),\n middleLeft - radius * Math.cos(trblaRadian),\n ];\n const yAxis = [\n middleTop - radius * Math.sin(tlbraRadian),\n middleTop - radius * Math.sin(trblaRadian),\n middleTop + radius * Math.sin(tlbraRadian),\n middleTop + radius * Math.sin(trblaRadian),\n ];\n\n return {\n xRange: [Math.min(...xAxis), Math.max(...xAxis)],\n yRange: [Math.min(...yAxis), Math.max(...yAxis)],\n };\n};\n\n// Preserve the existing endpoint-offset routing rule. Using the expanded\n// bounds here would let a control point change the double elbow's direction.\nconst isHorizontalElbow = (start: number[], end: number[]) =>\n Math.max(start[0], end[0]) >= Math.max(start[1], end[1]);\n\nexport const getElementRange = (element: PPTElement) => {\n let minX: number, maxX: number, minY: number, maxY: number;\n\n if (element.type === 'line') {\n const xs = [element.start[0], element.end[0]];\n const ys = [element.start[1], element.end[1]];\n // Follow the same path-variant precedence as getLineElementPath. Bezier\n // control hulls conservatively enclose the curve; elbows use drawn vertices.\n if (element.broken) {\n xs.push(element.broken[0]);\n ys.push(element.broken[1]);\n } else if (element.broken2) {\n if (isHorizontalElbow(element.start, element.end)) xs.push(element.broken2[0]);\n else ys.push(element.broken2[1]);\n } else if (element.curve) {\n xs.push(element.curve[0]);\n ys.push(element.curve[1]);\n } else if (element.cubic) {\n xs.push(element.cubic[0][0], element.cubic[1][0]);\n ys.push(element.cubic[0][1], element.cubic[1][1]);\n }\n minX = element.left + Math.min(...xs);\n maxX = element.left + Math.max(...xs);\n minY = element.top + Math.min(...ys);\n maxY = element.top + Math.max(...ys);\n } else if ('rotate' in element && element.rotate) {\n const { left, top, width, height, rotate } = element;\n const { xRange, yRange } = getRectRotatedRange({ left, top, width, height, rotate });\n minX = xRange[0];\n maxX = xRange[1];\n minY = yRange[0];\n maxY = yRange[1];\n } else {\n minX = element.left;\n maxX = element.left + element.width;\n minY = element.top;\n maxY = element.top + element.height;\n }\n return { minX, maxX, minY, maxY };\n};\n\nexport const getTableSubThemeColor = (themeColor: string) => {\n const rgba = tinycolor(themeColor);\n return [rgba.setAlpha(0.3).toRgbString(), rgba.setAlpha(0.1).toRgbString()];\n};\n\nexport const getLineElementPath = (element: PPTLineElement) => {\n const startArr = Array.isArray(element.start) ? element.start : [0, 0];\n const endArr = Array.isArray(element.end) ? element.end : [100, 100];\n const start = startArr.join(',');\n const end = endArr.join(',');\n if (element.broken) {\n const mid = element.broken.join(',');\n return `M${start} L${mid} L${end}`;\n } else if (element.broken2) {\n if (isHorizontalElbow(startArr, endArr))\n return `M${start} L${element.broken2[0]},${startArr[1]} L${element.broken2[0]},${endArr[1]} ${end}`;\n return `M${start} L${startArr[0]},${element.broken2[1]} L${endArr[0]},${element.broken2[1]} ${end}`;\n } else if (element.curve) {\n const mid = element.curve.join(',');\n return `M${start} Q${mid} ${end}`;\n } else if (element.cubic) {\n const [c1, c2] = element.cubic;\n const p1 = c1.join(',');\n const p2 = c2.join(',');\n return `M${start} C${p1} ${p2} ${end}`;\n }\n return `M${start} L${end}`;\n};\n"],"names":[],"mappings":";;AAWO,MAAM,mBAAmB,GAAG,CAAC,OAA2B,KAAI;AACjE,IAAA,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO;IAExD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACtE,IAAA,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE;AAElE,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,GAAG,MAAM,GAAG,cAAc,IAAI,IAAI,CAAC,EAAE,IAAI,GAAG;AACrE,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,cAAc,GAAG,MAAM,IAAI,IAAI,CAAC,EAA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,CAAC,CAAC,CAAC,CAAA,EAAA,EAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA,CAAA,EAAI,MAAM,CAAC,CAAC,CAAC,CAAA,CAAA,EAAI,GAAG,EAAE;AACrG,QAAA,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,EAAK,QAAQ,CAAC,CAAC,CAAC,CAAA,CAAA,EAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA,EAAA,EAAK,MAAM,CAAC,CAAC,CAAC,CAAA,CAAA,EAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA,CAAA,EAAI,GAAG,EAAE;IACrG;AAAO,SAAA,IAAI,OAAO,CAAC,KAAK,EAAE;QACxB,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;AACnC,QAAA,OAAO,IAAI,KAAK,CAAA,EAAA,EAAK,GAAG,CAAA,CAAA,EAAI,GAAG,EAAE;IACnC;AAAO,SAAA,IAAI,OAAO,CAAC,KAAK,EAAE;QACxB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK;QAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACvB,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,EAAK,EAAE,IAAI,EAAE,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE;IACxC;AACA,IAAA,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,EAAK,GAAG,EAAE;AAC5B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmaic/renderer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "React component for rendering PPTist-style Slide JSON, extracted from OpenMAIC.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"lucide-react": "^0.562.0",
|
|
76
76
|
"tailwind-merge": "^3.4.0",
|
|
77
77
|
"tinycolor2": "^1.6.0",
|
|
78
|
-
"@openmaic/dsl": "^0.11.
|
|
78
|
+
"@openmaic/dsl": "^0.11.2"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@rollup/plugin-commonjs": "^28.0.1",
|