@openmaic/renderer 0.1.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/elements/chart/chartOption.d.ts +2 -1
- package/dist/elements/chart/chartOption.js +55 -21
- package/dist/elements/chart/chartOption.js.map +1 -1
- package/dist/elements/chart/chartRuntime.js +5 -1
- package/dist/elements/chart/chartRuntime.js.map +1 -1
- package/dist/utils/inlineMath.d.ts +1 -1
- package/dist/utils/inlineMath.js +13 -2
- package/dist/utils/inlineMath.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Required peers:
|
|
|
34
34
|
|
|
35
35
|
Optional peers (install only if your slides use the corresponding element type):
|
|
36
36
|
|
|
37
|
-
- `echarts >= 5` — for chart elements
|
|
37
|
+
- `echarts >= 5.5` — for chart elements (uses endpoint label alignment for compact charts)
|
|
38
38
|
- `shiki >= 1` — for code elements
|
|
39
39
|
|
|
40
40
|
## Quickstart
|
|
@@ -112,8 +112,9 @@ Use `mathPriority="background"` for thumbnails: newly mounted or changed content
|
|
|
112
112
|
shares a copy of the frame's remaining allowance after foreground layout effects,
|
|
113
113
|
before paint. This leaves foreground capacity available if the user switches slides
|
|
114
114
|
after thumbnails mount in the same frame; that frame may use both allowances.
|
|
115
|
-
Remaining formulas
|
|
116
|
-
parent rerenders do not advance that queued work.
|
|
115
|
+
Remaining formulas stay hidden until rendered in idle time after foreground
|
|
116
|
+
canvases; unrelated parent rerenders do not advance that queued work. Formulas
|
|
117
|
+
that cannot be typeset still appear as text. Snapshot APIs still finish all
|
|
117
118
|
formulas synchronously within the existing per-prose-root hard caps.
|
|
118
119
|
|
|
119
120
|
### Play-time effects
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ComposeOption } from 'echarts/core';
|
|
2
|
+
import type { GridComponentOption } from 'echarts/components';
|
|
2
3
|
import type { BarSeriesOption, PictorialBarSeriesOption, LineSeriesOption, PieSeriesOption, ScatterSeriesOption, RadarSeriesOption } from 'echarts/charts';
|
|
3
4
|
import type { ChartData, ChartType, ImportedChartStyle } from '@openmaic/dsl';
|
|
4
|
-
type EChartOption = ComposeOption<PictorialBarSeriesOption | BarSeriesOption | LineSeriesOption | PieSeriesOption | ScatterSeriesOption | RadarSeriesOption>;
|
|
5
|
+
type EChartOption = ComposeOption<PictorialBarSeriesOption | BarSeriesOption | LineSeriesOption | PieSeriesOption | ScatterSeriesOption | RadarSeriesOption | GridComponentOption>;
|
|
5
6
|
export interface ChartOptionPayload {
|
|
6
7
|
type: ChartType;
|
|
7
8
|
data: ChartData;
|
|
@@ -24,12 +24,39 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
24
24
|
: {};
|
|
25
25
|
const axisLine = textColor ? { lineStyle: { color: textColor } } : undefined;
|
|
26
26
|
const axisLabel = { show: true, color: textColor ?? '#333333' };
|
|
27
|
+
// Preserve explicit imported layouts; ordinary endpoints face into the plot.
|
|
28
|
+
const horizontalEndpointAlignment = importedStyle?.plotArea
|
|
29
|
+
? {}
|
|
30
|
+
: { alignMinLabel: 'left', alignMaxLabel: 'right' };
|
|
27
31
|
const splitLine = lineColor ? { lineStyle: { color: lineColor } } : {};
|
|
28
32
|
const categoryAxisLabel = {
|
|
29
33
|
...axisLabel,
|
|
30
34
|
interval: data.labels.length <= 8 ? 0 : 'auto',
|
|
31
35
|
};
|
|
32
36
|
const legend = data.series.length > 1 ? { top: 'bottom', textStyle } : undefined;
|
|
37
|
+
const cartesianLegend = legend
|
|
38
|
+
? { type: 'scroll', bottom: 0, left: '4%', right: '4%', textStyle }
|
|
39
|
+
: undefined;
|
|
40
|
+
const plot = importedStyle?.plotArea;
|
|
41
|
+
// Preserve an imported plot rectangle exactly; ordinary charts reflow with
|
|
42
|
+
// the container and keep axis labels and the legend out of the plot. Text
|
|
43
|
+
// headroom and a single legend row need fixed pixels, not percent heights.
|
|
44
|
+
const grid = plot
|
|
45
|
+
? {
|
|
46
|
+
left: `${plot.x * 100}%`,
|
|
47
|
+
top: `${plot.y * 100}%`,
|
|
48
|
+
width: `${plot.w * 100}%`,
|
|
49
|
+
height: `${plot.h * 100}%`,
|
|
50
|
+
containLabel: false,
|
|
51
|
+
outerBoundsMode: 'none',
|
|
52
|
+
}
|
|
53
|
+
: {
|
|
54
|
+
left: '4%',
|
|
55
|
+
right: '4%',
|
|
56
|
+
top: type === 'line' || type === 'area' ? 22 : '8%',
|
|
57
|
+
bottom: cartesianLegend && type !== 'scatter' ? 26 : '12%',
|
|
58
|
+
containLabel: true,
|
|
59
|
+
};
|
|
33
60
|
if (type === 'bar' || type === 'column') {
|
|
34
61
|
const importedSeries = importedStyle?.series ?? [];
|
|
35
62
|
const hasPicture = !stack && importedSeries.some((s) => Object.keys(s.pointImages ?? {}).length > 0);
|
|
@@ -45,7 +72,7 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
45
72
|
...(category ? categoryAxisLabel : axisLabel),
|
|
46
73
|
...(!category && /^0(?:\.0+)?%$/.test(style?.numberFormat ?? '')
|
|
47
74
|
? {
|
|
48
|
-
formatter: (value) => `${(value * 100).toFixed((style?.numberFormat?.split('.')[1]?.split('%')[0] ?? '').length)}%`,
|
|
75
|
+
formatter: (value) => `${(Number(value) * 100).toFixed((style?.numberFormat?.split('.')[1]?.split('%')[0] ?? '').length)}%`,
|
|
49
76
|
}
|
|
50
77
|
: {}),
|
|
51
78
|
...(style?.labelVisible !== undefined ? { show: style.labelVisible } : {}),
|
|
@@ -94,23 +121,14 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
94
121
|
return (Math.floor(max / unit + 1e-9) + 1) * unit;
|
|
95
122
|
};
|
|
96
123
|
}
|
|
97
|
-
const plot = importedStyle?.plotArea;
|
|
98
124
|
return {
|
|
99
125
|
color: themeColors,
|
|
100
126
|
textStyle,
|
|
101
|
-
legend,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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,
|
|
127
|
+
legend: cartesianLegend,
|
|
128
|
+
grid,
|
|
129
|
+
xAxis: type === 'bar'
|
|
130
|
+
? category
|
|
131
|
+
: { ...value, axisLabel: { ...value.axisLabel, ...horizontalEndpointAlignment } },
|
|
114
132
|
yAxis: type === 'bar' ? value : category,
|
|
115
133
|
series: plotSeries.map((item, index) => {
|
|
116
134
|
const style = importedSeries[index];
|
|
@@ -169,8 +187,14 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
169
187
|
return {
|
|
170
188
|
color: themeColors,
|
|
171
189
|
textStyle,
|
|
172
|
-
legend,
|
|
173
|
-
|
|
190
|
+
legend: cartesianLegend,
|
|
191
|
+
grid,
|
|
192
|
+
xAxis: {
|
|
193
|
+
type: 'category',
|
|
194
|
+
data: data.labels,
|
|
195
|
+
axisLine,
|
|
196
|
+
axisLabel: categoryAxisLabel,
|
|
197
|
+
},
|
|
174
198
|
yAxis: { type: 'value', axisLine, axisLabel, splitLine },
|
|
175
199
|
series: plotSeries.map((item, index) => {
|
|
176
200
|
const seriesItem = {
|
|
@@ -234,18 +258,27 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
234
258
|
return {
|
|
235
259
|
color: themeColors,
|
|
236
260
|
textStyle,
|
|
237
|
-
legend,
|
|
261
|
+
legend: cartesianLegend,
|
|
262
|
+
grid,
|
|
238
263
|
xAxis: {
|
|
239
264
|
type: 'category',
|
|
240
265
|
boundaryGap: false,
|
|
241
266
|
data: data.labels,
|
|
242
267
|
axisLine,
|
|
243
|
-
axisLabel: categoryAxisLabel,
|
|
268
|
+
axisLabel: { ...categoryAxisLabel, ...horizontalEndpointAlignment },
|
|
244
269
|
},
|
|
245
270
|
yAxis: { type: 'value', axisLine, axisLabel, splitLine },
|
|
246
271
|
series: plotSeries.map((item, index) => {
|
|
247
272
|
const seriesItem = {
|
|
248
|
-
|
|
273
|
+
// Area points sit on the plot edges; turn endpoint values inward.
|
|
274
|
+
data: plot
|
|
275
|
+
? item
|
|
276
|
+
: item.map((value, dataIndex) => ({
|
|
277
|
+
value,
|
|
278
|
+
label: {
|
|
279
|
+
align: dataIndex === 0 ? 'left' : dataIndex === item.length - 1 ? 'right' : 'center',
|
|
280
|
+
},
|
|
281
|
+
})),
|
|
249
282
|
name: data.legends[index],
|
|
250
283
|
type: 'line',
|
|
251
284
|
areaStyle: {},
|
|
@@ -288,7 +321,8 @@ const getChartOption = ({ type, data, themeColors, textColor, lineColor, lineSmo
|
|
|
288
321
|
return {
|
|
289
322
|
color: themeColors,
|
|
290
323
|
textStyle,
|
|
291
|
-
|
|
324
|
+
grid,
|
|
325
|
+
xAxis: { axisLine, axisLabel: { ...axisLabel, ...horizontalEndpointAlignment }, splitLine },
|
|
292
326
|
yAxis: { axisLine, axisLabel, splitLine },
|
|
293
327
|
series: [{ symbolSize: 12, data: formatedData, type: 'scatter' }],
|
|
294
328
|
};
|
|
@@ -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 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,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,IAAA,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,QAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;AAAE,YAAA,OAAO,IAAI;QACxC,MAAM,YAAY,GAAe,EAAE;AACnC,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACvC,YAAA,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;AACpB,YAAA,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YAClC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;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
|
+
{"version":3,"file":"chartOption.js","sources":["../../../src/elements/chart/chartOption.ts"],"sourcesContent":["import type { ComposeOption } from 'echarts/core';\nimport type { GridComponentOption } from 'echarts/components';\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 | GridComponentOption\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 // Preserve explicit imported layouts; ordinary endpoints face into the plot.\n const horizontalEndpointAlignment = importedStyle?.plotArea\n ? {}\n : { alignMinLabel: 'left' as const, alignMaxLabel: 'right' as const };\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 const cartesianLegend = legend\n ? { type: 'scroll' as const, bottom: 0, left: '4%', right: '4%', textStyle }\n : undefined;\n const plot = importedStyle?.plotArea;\n // Preserve an imported plot rectangle exactly; ordinary charts reflow with\n // the container and keep axis labels and the legend out of the plot. Text\n // headroom and a single legend row need fixed pixels, not percent heights.\n const grid: GridComponentOption = plot\n ? {\n left: `${plot.x * 100}%`,\n top: `${plot.y * 100}%`,\n width: `${plot.w * 100}%`,\n height: `${plot.h * 100}%`,\n containLabel: false,\n outerBoundsMode: 'none',\n }\n : {\n left: '4%',\n right: '4%',\n top: type === 'line' || type === 'area' ? 22 : '8%',\n bottom: cartesianLegend && type !== 'scatter' ? 26 : '12%',\n containLabel: true,\n };\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 | string) =>\n `${(Number(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 return {\n color: themeColors,\n textStyle,\n legend: cartesianLegend,\n grid,\n xAxis:\n type === 'bar'\n ? category\n : { ...value, axisLabel: { ...value.axisLabel, ...horizontalEndpointAlignment } },\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: cartesianLegend,\n grid,\n xAxis: {\n type: 'category',\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 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: cartesianLegend,\n grid,\n xAxis: {\n type: 'category',\n boundaryGap: false,\n data: data.labels,\n axisLine,\n axisLabel: { ...categoryAxisLabel, ...horizontalEndpointAlignment },\n },\n yAxis: { type: 'value', axisLine, axisLabel, splitLine },\n series: plotSeries.map((item, index) => {\n const seriesItem: LineSeriesOption = {\n // Area points sit on the plot edges; turn endpoint values inward.\n data: plot\n ? item\n : item.map((value, dataIndex) => ({\n value,\n label: {\n align:\n dataIndex === 0 ? 'left' : dataIndex === item.length - 1 ? 'right' : 'center',\n },\n })),\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 grid,\n xAxis: { axisLine, axisLabel: { ...axisLabel, ...horizontalEndpointAlignment }, splitLine },\n yAxis: { axisLine, axisLabel, splitLine },\n series: [{ symbolSize: 12, data: formatedData, type: 'scatter' }],\n };\n }\n\n return null;\n};\n"],"names":[],"mappings":"AAkCA;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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,WAAW;YAClB,SAAS;YACT,IAAI;AACJ,YAAA,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,GAAG,2BAA2B,EAAE,EAAE,SAAS,EAAE;AAC3F,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;;;;"}
|
|
@@ -12,7 +12,8 @@ function loadChartRuntime() {
|
|
|
12
12
|
import('echarts/charts'),
|
|
13
13
|
import('echarts/components'),
|
|
14
14
|
import('echarts/renderers'),
|
|
15
|
-
|
|
15
|
+
import('echarts/features'),
|
|
16
|
+
]).then(([echarts, charts, components, renderers, features]) => {
|
|
16
17
|
echarts.use([
|
|
17
18
|
charts.BarChart,
|
|
18
19
|
charts.PictorialBarChart,
|
|
@@ -23,6 +24,9 @@ function loadChartRuntime() {
|
|
|
23
24
|
components.LegendComponent,
|
|
24
25
|
renderers.SVGRenderer,
|
|
25
26
|
]);
|
|
27
|
+
// ECharts 5 includes containLabel; ECharts 6 exposes it as an opt-in.
|
|
28
|
+
if (features.LegacyGridContainLabel)
|
|
29
|
+
echarts.use(features.LegacyGridContainLabel);
|
|
26
30
|
return echarts;
|
|
27
31
|
});
|
|
28
32
|
return runtimePromise;
|
|
@@ -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.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;
|
|
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 import('echarts/features'),\n ]).then(([echarts, charts, components, renderers, features]) => {\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 // ECharts 5 includes containLabel; ECharts 6 exposes it as an opt-in.\n if (features.LegacyGridContainLabel) echarts.use(features.LegacyGridContainLabel);\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;QAC3B,OAAO,kBAAkB,CAAC;AAC3B,KAAA,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,KAAI;QAC7D,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;;QAEF,IAAI,QAAQ,CAAC,sBAAsB;AAAE,YAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,sBAAsB,CAAC;AACjF,QAAA,OAAO,OAAO;AAChB,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,cAAc;AACvB;;;;"}
|
|
@@ -39,7 +39,7 @@ export interface RenderInlineMathOptions {
|
|
|
39
39
|
* Typeset the inline formulas under `root`. Each `span[data-inline-math]` is
|
|
40
40
|
* replaced by a KaTeX render of its source carrying the same attribute (the
|
|
41
41
|
* editor's storage shape); a source that cannot be typeset is shown as text.
|
|
42
|
-
* Returns `true` when
|
|
42
|
+
* Returns `true` when the budget deferred formulas; pending sources stay hidden.
|
|
43
43
|
*/
|
|
44
44
|
export declare function renderInlineMath(root: ParentNode, options?: RenderInlineMathOptions): boolean;
|
|
45
45
|
/**
|
package/dist/utils/inlineMath.js
CHANGED
|
@@ -104,8 +104,15 @@ function typeset(doc, latex) {
|
|
|
104
104
|
}
|
|
105
105
|
/** Formulas shown as text because they fell past a root's hard cap. */
|
|
106
106
|
const capped = new WeakSet();
|
|
107
|
+
function hidePendingMath(root) {
|
|
108
|
+
for (const element of root.querySelectorAll(`span[${INLINE_MATH_ATTRIBUTE}]`)) {
|
|
109
|
+
if (!handled.has(element))
|
|
110
|
+
element.style.visibility = 'hidden';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
107
113
|
function showSource(element, latex) {
|
|
108
114
|
element.textContent = latex;
|
|
115
|
+
element.style.removeProperty('visibility');
|
|
109
116
|
handled.add(element);
|
|
110
117
|
}
|
|
111
118
|
/** Show a formula past the hard cap as its source text, whatever it shows now. */
|
|
@@ -123,7 +130,7 @@ function showCapped(element, latex) {
|
|
|
123
130
|
* Typeset the inline formulas under `root`. Each `span[data-inline-math]` is
|
|
124
131
|
* replaced by a KaTeX render of its source carrying the same attribute (the
|
|
125
132
|
* editor's storage shape); a source that cannot be typeset is shown as text.
|
|
126
|
-
* Returns `true` when
|
|
133
|
+
* Returns `true` when the budget deferred formulas; pending sources stay hidden.
|
|
127
134
|
*/
|
|
128
135
|
function renderInlineMath(root, options = {}) {
|
|
129
136
|
return renderPass(root, options, newBudget());
|
|
@@ -194,6 +201,8 @@ function renderPass(root, options, budget) {
|
|
|
194
201
|
deferredTypesets.delete(element);
|
|
195
202
|
element.replaceWith(formula);
|
|
196
203
|
}
|
|
204
|
+
if (pending)
|
|
205
|
+
hidePendingMath(root);
|
|
197
206
|
return pending;
|
|
198
207
|
}
|
|
199
208
|
/**
|
|
@@ -401,8 +410,10 @@ function useInlineMath(ref, html) {
|
|
|
401
410
|
if (before?.root === root &&
|
|
402
411
|
before.html === html &&
|
|
403
412
|
before.priority === priority &&
|
|
404
|
-
liveMath.isQueued(root))
|
|
413
|
+
liveMath.isQueued(root)) {
|
|
414
|
+
hidePendingMath(root);
|
|
405
415
|
return;
|
|
416
|
+
}
|
|
406
417
|
liveMath.render(root, priority);
|
|
407
418
|
});
|
|
408
419
|
// Only clean up on unmount: per-commit removal would discard pending queue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inlineMath.js","sources":["../../src/utils/inlineMath.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useContext, useLayoutEffect, useMemo, useRef, type RefObject } from 'react';\nimport katex from 'katex';\nimport { safeKatexOptions } from '@openmaic/dsl';\n\n/**\n * Inline formulas in slide prose. Stored prose carries each formula as LaTeX\n * source (`<span data-inline-math=\"LATEX\">LATEX</span>`); older or unsaved\n * content may still carry a rendered KaTeX tree with the same attribute. The\n * renderer typesets every such span in the browser from its source.\n */\nexport const INLINE_MATH_ATTRIBUTE = 'data-inline-math';\n\n/**\n * Marks an element whose injected prose is one typesetting root (a text box,\n * a shape label, a table), so callers that typeset a whole slide at once use\n * the same roots, budgets and caps as the live elements.\n */\nexport const INLINE_MATH_ROOT_ATTRIBUTE = 'data-inline-math-root';\n\n/** Longest source typeset; longer sources are shown as plain LaTeX text. */\nexport const MAX_INLINE_MATH_SOURCE = 2_000;\n\n/**\n * Bound uncached typesetting work in a batch. Live prose roots share a batch;\n * standalone renderInlineMath calls get their own. Ordinary slides fit before\n * paint; mixed/dense slides may defer even short formulas to idle time.\n */\nexport const INLINE_MATH_SYNC_SOURCE_BUDGET = 4_000;\nexport const INLINE_MATH_SYNC_FORMULA_BUDGET = 100;\n\n/**\n * Also bound inserted markup, including cache hits: short matrix sources can\n * expand to thousands of nodes whose style/layout cost comes after typesetting.\n * Uses the serialized size already recorded by the cache, not a DOM traversal.\n * Leave room for dense ordinary slides (e.g. 32 integrals/sums across text boxes).\n */\nconst INLINE_MATH_SYNC_MARKUP_BUDGET = 256_000;\n\n/**\n * Hard cap per prose root, counting every formula in document order: past it,\n * formulas are shown as their LaTeX text and never typeset.\n */\nexport const INLINE_MATH_MAX_ROOT_SOURCE = 50_000;\nexport const INLINE_MATH_MAX_ROOT_FORMULAS = 1_000;\n\n/** Formula elements this module already handled, so a repeated pass skips them. */\nconst handled = new WeakSet<Element>();\n\n/**\n * Typeset formulas by source, cloned on use: React may rewrite the injected\n * markup on any re-render, and re-typesetting the same source must stay\n * cheap. Bounded by the size of the cached markup, counted in serialized\n * characters (an estimate, not heap bytes); large renders are not kept.\n */\nconst TYPESET_CACHE_MAX_MARKUP = 2_000_000;\nconst TYPESET_CACHE_MAX_ENTRY = 64_000;\ntype TypesetEntry = { readonly formula: Element | null; readonly size: number };\nconst typesetCache = new Map<string, TypesetEntry>();\nlet typesetCacheSize = 0;\n// Keep a rejected render with its source node until it can be inserted. Unlike\n// the shared cache, this also covers large entries and cannot be overwritten by\n// another root. Replacing/removing the prose releases its pending renders.\nconst deferredTypesets = new WeakMap<Element, { latex: string; entry: TypesetEntry }>();\n\n/** Typeset one formula, or `null` to keep its source as text. */\nfunction typesetUncached(doc: Document, latex: string): Element | null {\n if (!latex.trim() || latex.length > MAX_INLINE_MATH_SOURCE) return null;\n const host = doc.createElement('span');\n try {\n // Authored input: `safeKatexOptions` forces `trust: false`, makes\n // formula-defined macros inert, bounds expansion, and builds a fresh\n // `macros` object per call (KaTeX writes global definitions into it).\n katex.render(\n latex,\n host,\n safeKatexOptions({\n displayMode: false,\n output: 'html',\n throwOnError: false,\n strict: 'ignore',\n }),\n );\n } catch {\n // KaTeX refuses to run in a quirks-mode document (no doctype); the source\n // then stays as text.\n return null;\n }\n const formula = host.firstElementChild;\n formula?.setAttribute(INLINE_MATH_ATTRIBUTE, latex);\n return formula;\n}\n\nfunction typeset(doc: Document, latex: string): TypesetEntry {\n let entry = typesetCache.get(latex);\n if (entry) {\n // Refresh recency.\n typesetCache.delete(latex);\n typesetCache.set(latex, entry);\n } else {\n const formula = typesetUncached(doc, latex);\n entry = { formula, size: latex.length + (formula?.outerHTML.length ?? 0) };\n if (entry.size <= TYPESET_CACHE_MAX_ENTRY) {\n typesetCache.set(latex, entry);\n typesetCacheSize += entry.size;\n for (const [key, value] of typesetCache) {\n if (typesetCacheSize <= TYPESET_CACHE_MAX_MARKUP) break;\n typesetCache.delete(key);\n typesetCacheSize -= value.size;\n }\n }\n }\n return entry;\n}\n\nexport interface RenderInlineMathOptions {\n /**\n * Typeset every formula now, ignoring the per-pass budget (the hard cap\n * still applies). For callers that capture the result right away, such as\n * slide snapshots.\n */\n readonly complete?: boolean;\n}\n\n/** Formulas shown as text because they fell past a root's hard cap. */\nconst capped = new WeakSet<Element>();\n\nfunction showSource(element: Element, latex: string): void {\n element.textContent = latex;\n handled.add(element);\n}\n\n/** Show a formula past the hard cap as its source text, whatever it shows now. */\nfunction showCapped(element: Element, latex: string): void {\n if (capped.has(element)) return;\n const span = (element.ownerDocument ?? document).createElement('span');\n span.setAttribute(INLINE_MATH_ATTRIBUTE, latex);\n span.textContent = latex;\n handled.add(span);\n capped.add(span);\n element.replaceWith(span);\n}\n\n/**\n * Typeset the inline formulas under `root`. Each `span[data-inline-math]` is\n * replaced by a KaTeX render of its source carrying the same attribute (the\n * editor's storage shape); a source that cannot be typeset is shown as text.\n * Returns `true` when formulas were left for a later pass by the budget.\n */\nexport function renderInlineMath(root: ParentNode, options: RenderInlineMathOptions = {}): boolean {\n return renderPass(root, options, newBudget());\n}\n\ntype TypesetBudget = { source: number; formulas: number; markup: number; full: boolean };\n\nfunction newBudget(): TypesetBudget {\n return { source: 0, formulas: 0, markup: 0, full: false };\n}\n\nfunction renderPass(\n root: ParentNode,\n options: RenderInlineMathOptions,\n budget: TypesetBudget,\n): boolean {\n const doc = (root as Node).ownerDocument ?? (root as Document);\n let rootSource = 0;\n let rootFormulas = 0;\n let pending = false;\n for (const element of root.querySelectorAll(`span[${INLINE_MATH_ATTRIBUTE}]`)) {\n // Inside a formula replaced earlier in this pass.\n if (!(root as Node).contains(element)) continue;\n const latex = element.getAttribute(INLINE_MATH_ATTRIBUTE) ?? '';\n rootSource += latex.length;\n rootFormulas += 1;\n // The cap depends only on document order within the root, so a formula\n // ends up the same whatever earlier passes did with it.\n if (rootSource > INLINE_MATH_MAX_ROOT_SOURCE || rootFormulas > INLINE_MATH_MAX_ROOT_FORMULAS) {\n showCapped(element, latex);\n continue;\n }\n if (handled.has(element) && !capped.has(element)) continue;\n const deferred = deferredTypesets.get(element);\n const prepared = deferred?.latex === latex ? deferred.entry : undefined;\n const cached = prepared ?? typesetCache.get(latex);\n // Preserve source order within a root, but let a later root use cached\n // formulas that fit in the space left by a rejected large formula.\n if (!options.complete && (pending || (budget.full && !cached))) {\n pending = true;\n continue;\n }\n if (!cached) {\n if (\n !options.complete &&\n budget.formulas > 0 &&\n (budget.source + latex.length > INLINE_MATH_SYNC_SOURCE_BUDGET ||\n budget.formulas >= INLINE_MATH_SYNC_FORMULA_BUDGET)\n ) {\n budget.full = true;\n pending = true;\n continue;\n }\n budget.source += latex.length;\n budget.formulas += 1;\n }\n const entry = prepared ?? typeset(doc, latex);\n if (!entry.formula) {\n showSource(element, latex);\n continue;\n }\n // Always allow one formula to make progress, even if it exceeds a batch.\n if (\n !options.complete &&\n budget.markup > 0 &&\n budget.markup + entry.size > INLINE_MATH_SYNC_MARKUP_BUDGET\n ) {\n budget.full = true;\n pending = true;\n deferredTypesets.set(element, { latex, entry });\n continue;\n }\n budget.markup += entry.size;\n const formula =\n entry.formula.ownerDocument === doc\n ? (entry.formula.cloneNode(true) as Element)\n : (doc.importNode(entry.formula, true) as Element);\n handled.add(formula);\n deferredTypesets.delete(element);\n element.replaceWith(formula);\n }\n return pending;\n}\n\n/**\n * Typeset every formula under `container` now, root by root (each element\n * marked with {@link INLINE_MATH_ROOT_ATTRIBUTE}), so each root keeps its own\n * hard cap exactly as the live elements apply it. For snapshots, which\n * capture right away instead of waiting for idle time.\n */\nexport function completeInlineMath(container: Element): void {\n const roots = [...container.querySelectorAll(`[${INLINE_MATH_ROOT_ATTRIBUTE}]`)];\n if (container.hasAttribute(INLINE_MATH_ROOT_ATTRIBUTE)) roots.unshift(container);\n for (const root of roots) renderInlineMath(root, { complete: true });\n}\n\n/**\n * A `dangerouslySetInnerHTML` value that keeps its identity while `html` is\n * unchanged. React rewrites injected markup whenever it receives a new value\n * object, which would discard typeset formulas and any idle progress on each\n * re-render; a stable value leaves the DOM alone.\n */\nexport function useInnerHtml(html: string): { __html: string } {\n return useMemo(() => ({ __html: html }), [html]);\n}\n\n/** {@link useInnerHtml} for a grid of cells (table text), keyed on every cell's markup. */\nexport function useInnerHtmlGrid(cells: readonly (readonly string[])[]): { __html: string }[][] {\n const key = JSON.stringify(cells);\n return useMemo(\n () => (JSON.parse(key) as string[][]).map((row) => row.map((html) => ({ __html: html }))),\n [key],\n );\n}\n\ntype IdleHandle = { cancel(): void };\n\ntype IdleScope = typeof globalThis & {\n requestIdleCallback?: (callback: () => void, options?: { timeout: number }) => number;\n cancelIdleCallback?: (handle: number) => void;\n};\n\n/**\n * Run `run` when the page is idle. The scheduling functions are read once,\n * here, and the handle is always cancelled with the function from the same\n * pair: the global may be replaced or removed between scheduling and\n * cancelling (polyfills, test stubs), and a handle from one implementation\n * means nothing to another.\n */\nfunction whenIdle(run: () => void): IdleHandle {\n const scope = globalThis as IdleScope;\n const request = scope.requestIdleCallback;\n const cancel = scope.cancelIdleCallback;\n if (typeof request === 'function' && typeof cancel === 'function') {\n const handle = request.call(scope, run, { timeout: 500 });\n return { cancel: () => cancel.call(scope, handle) };\n }\n const schedule = scope.setTimeout;\n const clear = scope.clearTimeout;\n const handle = schedule.call(scope, run, 16);\n return { cancel: () => clear.call(scope, handle) };\n}\n\ntype MathPriority = 'normal' | 'background';\nexport const InlineMathPriorityContext = createContext<MathPriority>('normal');\n\n/**\n * Own the live queues and frame allowances. Background roots share a copy of\n * the remaining foreground allowance, so an earlier thumbnail commit cannot\n * spend the next foreground commit's budget. Neither is renewed on removal.\n */\nfunction createLiveMath() {\n // Idle work rotates roots within each priority, with foreground canvases first.\n const queuedRoots = new Map<Element, MathPriority>();\n // Only newly admitted background roots may spend the remaining frame allowance.\n const prePaintCandidates = new Set<Element>();\n let frameBudget: TypesetBudget | null = null;\n let backgroundBudget: TypesetBudget | null = null;\n let cancelFrameReset: (() => void) | null = null;\n let idleJob: { cancel?: () => void } | null = null;\n let prePaintScheduled = false;\n\n function resetFrameBudget(): void {\n cancelFrameReset?.();\n cancelFrameReset = null;\n frameBudget = null;\n backgroundBudget = null;\n }\n\n function frameAllowance(): TypesetBudget {\n if (!frameBudget) {\n const budget = (frameBudget = newBudget());\n const reset = () => {\n if (frameBudget === budget) {\n frameBudget = null;\n backgroundBudget = null;\n cancelFrameReset = null;\n }\n };\n if (\n typeof requestAnimationFrame === 'function' &&\n typeof cancelAnimationFrame === 'function'\n ) {\n const cancel = cancelAnimationFrame;\n const handle = requestAnimationFrame(reset);\n cancelFrameReset = () => cancel(handle);\n } else {\n const cancel = clearTimeout;\n const handle = setTimeout(reset, 16);\n cancelFrameReset = () => cancel(handle);\n }\n }\n return frameBudget;\n }\n\n function renderIdleRoots(priority: MathPriority, budget: TypesetBudget): void {\n for (const [root, queuedPriority] of [...queuedRoots]) {\n if (queuedPriority !== priority) continue;\n queuedRoots.delete(root);\n if (root.isConnected && renderPass(root, {}, budget)) queuedRoots.set(root, priority);\n if (budget.full) break;\n }\n }\n\n function scheduleIdle(): void {\n if (!queuedRoots.size) {\n idleJob?.cancel?.();\n idleJob = null;\n return;\n }\n if (idleJob) return;\n const job: { cancel?: () => void } = {};\n idleJob = job;\n job.cancel = whenIdle(() => {\n // A cancelled callback must not drain work queued by a later mount.\n if (idleJob !== job) return;\n idleJob = null;\n resetFrameBudget();\n const budget = newBudget();\n for (const priority of ['normal', 'background'] as const) {\n renderIdleRoots(priority, budget);\n if (budget.full) break;\n }\n scheduleIdle();\n }).cancel;\n }\n\n function flushPrePaint(): void {\n prePaintScheduled = false;\n if (!prePaintCandidates.size) return;\n const budget = (backgroundBudget ??= { ...frameAllowance() });\n // Visit every newly admitted root: cached formulas may fit after an earlier\n // root fills the allowance. Older queued roots remain in idle time.\n for (const root of prePaintCandidates) {\n queuedRoots.delete(root);\n if (root.isConnected && renderPass(root, {}, budget)) queuedRoots.set(root, 'background');\n }\n prePaintCandidates.clear();\n scheduleIdle();\n }\n\n return {\n isQueued: (root: Element): boolean => queuedRoots.has(root),\n\n render(root: Element, priority: MathPriority): void {\n if (priority === 'background') {\n prePaintCandidates.add(root);\n if (!prePaintScheduled) {\n prePaintScheduled = true;\n queueMicrotask(flushPrePaint);\n }\n return;\n }\n prePaintCandidates.delete(root);\n if (renderPass(root, {}, frameAllowance())) queuedRoots.set(root, priority);\n else queuedRoots.delete(root);\n scheduleIdle();\n },\n\n remove(root: Element): void {\n prePaintCandidates.delete(root);\n queuedRoots.delete(root);\n if (!queuedRoots.size) {\n idleJob?.cancel?.();\n idleJob = null;\n }\n },\n };\n}\n\nconst liveMath = createLiveMath();\n\n/**\n * Typeset the inline formulas of prose injected into `ref` as `html`. Runs\n * after every commit, before paint: React may rewrite the injected markup on\n * any re-render (not only when `html` changes), which would put the stored\n * source spans back. Formulas already typeset are skipped and cached renders\n * are cloned, so a commit that left the markup alone costs one query. What the\n * shared budget leaves over is typeset in idle time, using the current markup.\n * Pending roots stay in that queue on unchanged commits (including when an\n * external caller rewrites the HTML). New content can use the current frame's\n * synchronous allowance. Unmounting or replacing a root removes its queued work.\n * Foreground roots run in layout effects; background roots use the remaining\n * allowance in a microtask, following the nearest InlineMathPriorityContext.\n * Never updates React state.\n */\nexport function useInlineMath(ref: RefObject<Element | null>, html: string): void {\n const priority = useContext(InlineMathPriorityContext);\n const previous = useRef<{ root: Element | null; html: string; priority: MathPriority }>(null);\n useLayoutEffect(() => {\n const root = ref.current;\n const before = previous.current;\n if (before?.root && before.root !== root) liveMath.remove(before.root);\n previous.current = { root, html, priority };\n if (!root) return;\n if (!html.includes(INLINE_MATH_ATTRIBUTE)) {\n liveMath.remove(root);\n return;\n }\n if (\n before?.root === root &&\n before.html === html &&\n before.priority === priority &&\n liveMath.isQueued(root)\n )\n return;\n liveMath.render(root, priority);\n });\n // Only clean up on unmount: per-commit removal would discard pending queue\n // membership and let unchanged rerenders reenter the pre-paint path.\n useLayoutEffect(() => {\n return () => {\n if (previous.current?.root) liveMath.remove(previous.current.root);\n previous.current = null;\n };\n }, []);\n}\n"],"names":[],"mappings":";;;;;AAMA;;;;;AAKG;AACI;AAEP;;;;AAIG;AACI;AAEP;AACO;AAEP;;;;AAIG;AACI;AACA;AAEP;;;;;AAKG;AACH;AAEA;;;AAGG;AACI;AACA;AAEP;AACA;AAEA;;;;;AAKG;AACH;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;AAC8D;;AAE5D;;;;;AAQM;AACA;AACA;AACA;AACD;;AAEH;;;AAGA;;AAEF;AACA;AACA;AACF;AAEA;;;;AAII;AACA;;;;;AAIA;AACE;AACA;;;;AAGE;AACA;;;;AAIN;AACF;AAWA;AACA;AAEA;AACE;AACA;AACF;AAEA;AACA;AACE;;AACA;AACA;AACA;AACA;AACA;AACA;AACF;AAEA;;;;;AAKG;;;AAGH;AAIA;AACE;AACF;AAEA;AAKE;;;;AAIA;;AAEE;;;AAEA;;;;;AAKE;;;AAGF;;;AAEA;;;;AAIA;;;;;;;;AASM;AAEF;;;;AAIF;AACA;;;AAGF;AACE;;;;;;;AASA;;;;;AAKF;;;;AAKA;AACA;AACA;;AAEF;AACF;AAEA;;;;;AAKG;AACG;AACJ;AACA;AAAwD;;;AAE1D;AAEA;;;;;AAKG;AACG;AACJ;AACF;AAEA;AACM;;AAEJ;AAIF;AASA;;;;;;AAMG;AACH;;AAEE;AACA;;AAEE;AACA;;AAEF;AACA;AACA;AACA;AACF;;AAKA;;;;AAIG;AACH;;AAEE;;AAEA;;;;;;AAOA;;;;;;AAOA;;;;AAIM;;;;;AAKF;;AAGE;;AAGA;;;;;;;;;AAQJ;;AAGF;AACE;;;AAEE;;AACsD;;;;;AAK1D;AACE;AACE;;;;AAIF;;;;AAGA;;;;;AAIE;AACA;;AAEE;;;;AAGF;;;AAIJ;;;;;;;AAME;AACE;;AACsD;;;AAGxD;;;;;AAOE;AACE;;;;;;;AAOF;;AAC4C;;AACvC;AACL;;AAGF;AACE;AACA;AACA;AACE;;;;;AAKR;AAEA;AAEA;;;;;;;;;;;;;AAaG;AACG;AACJ;AACA;;AAEE;AACA;;AAC0C;;AAE1C;;;AAEE;;;AAGF;;;AAIE;;AAGF;AACF;;;;AAIE;AACE;;AACA;AACF;;AAEJ;;"}
|
|
1
|
+
{"version":3,"file":"inlineMath.js","sources":["../../src/utils/inlineMath.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useContext, useLayoutEffect, useMemo, useRef, type RefObject } from 'react';\nimport katex from 'katex';\nimport { safeKatexOptions } from '@openmaic/dsl';\n\n/**\n * Inline formulas in slide prose. Stored prose carries each formula as LaTeX\n * source (`<span data-inline-math=\"LATEX\">LATEX</span>`); older or unsaved\n * content may still carry a rendered KaTeX tree with the same attribute. The\n * renderer typesets every such span in the browser from its source.\n */\nexport const INLINE_MATH_ATTRIBUTE = 'data-inline-math';\n\n/**\n * Marks an element whose injected prose is one typesetting root (a text box,\n * a shape label, a table), so callers that typeset a whole slide at once use\n * the same roots, budgets and caps as the live elements.\n */\nexport const INLINE_MATH_ROOT_ATTRIBUTE = 'data-inline-math-root';\n\n/** Longest source typeset; longer sources are shown as plain LaTeX text. */\nexport const MAX_INLINE_MATH_SOURCE = 2_000;\n\n/**\n * Bound uncached typesetting work in a batch. Live prose roots share a batch;\n * standalone renderInlineMath calls get their own. Ordinary slides fit before\n * paint; mixed/dense slides may defer even short formulas to idle time.\n */\nexport const INLINE_MATH_SYNC_SOURCE_BUDGET = 4_000;\nexport const INLINE_MATH_SYNC_FORMULA_BUDGET = 100;\n\n/**\n * Also bound inserted markup, including cache hits: short matrix sources can\n * expand to thousands of nodes whose style/layout cost comes after typesetting.\n * Uses the serialized size already recorded by the cache, not a DOM traversal.\n * Leave room for dense ordinary slides (e.g. 32 integrals/sums across text boxes).\n */\nconst INLINE_MATH_SYNC_MARKUP_BUDGET = 256_000;\n\n/**\n * Hard cap per prose root, counting every formula in document order: past it,\n * formulas are shown as their LaTeX text and never typeset.\n */\nexport const INLINE_MATH_MAX_ROOT_SOURCE = 50_000;\nexport const INLINE_MATH_MAX_ROOT_FORMULAS = 1_000;\n\n/** Formula elements this module already handled, so a repeated pass skips them. */\nconst handled = new WeakSet<Element>();\n\n/**\n * Typeset formulas by source, cloned on use: React may rewrite the injected\n * markup on any re-render, and re-typesetting the same source must stay\n * cheap. Bounded by the size of the cached markup, counted in serialized\n * characters (an estimate, not heap bytes); large renders are not kept.\n */\nconst TYPESET_CACHE_MAX_MARKUP = 2_000_000;\nconst TYPESET_CACHE_MAX_ENTRY = 64_000;\ntype TypesetEntry = { readonly formula: Element | null; readonly size: number };\nconst typesetCache = new Map<string, TypesetEntry>();\nlet typesetCacheSize = 0;\n// Keep a rejected render with its source node until it can be inserted. Unlike\n// the shared cache, this also covers large entries and cannot be overwritten by\n// another root. Replacing/removing the prose releases its pending renders.\nconst deferredTypesets = new WeakMap<Element, { latex: string; entry: TypesetEntry }>();\n\n/** Typeset one formula, or `null` to keep its source as text. */\nfunction typesetUncached(doc: Document, latex: string): Element | null {\n if (!latex.trim() || latex.length > MAX_INLINE_MATH_SOURCE) return null;\n const host = doc.createElement('span');\n try {\n // Authored input: `safeKatexOptions` forces `trust: false`, makes\n // formula-defined macros inert, bounds expansion, and builds a fresh\n // `macros` object per call (KaTeX writes global definitions into it).\n katex.render(\n latex,\n host,\n safeKatexOptions({\n displayMode: false,\n output: 'html',\n throwOnError: false,\n strict: 'ignore',\n }),\n );\n } catch {\n // KaTeX refuses to run in a quirks-mode document (no doctype); the source\n // then stays as text.\n return null;\n }\n const formula = host.firstElementChild;\n formula?.setAttribute(INLINE_MATH_ATTRIBUTE, latex);\n return formula;\n}\n\nfunction typeset(doc: Document, latex: string): TypesetEntry {\n let entry = typesetCache.get(latex);\n if (entry) {\n // Refresh recency.\n typesetCache.delete(latex);\n typesetCache.set(latex, entry);\n } else {\n const formula = typesetUncached(doc, latex);\n entry = { formula, size: latex.length + (formula?.outerHTML.length ?? 0) };\n if (entry.size <= TYPESET_CACHE_MAX_ENTRY) {\n typesetCache.set(latex, entry);\n typesetCacheSize += entry.size;\n for (const [key, value] of typesetCache) {\n if (typesetCacheSize <= TYPESET_CACHE_MAX_MARKUP) break;\n typesetCache.delete(key);\n typesetCacheSize -= value.size;\n }\n }\n }\n return entry;\n}\n\nexport interface RenderInlineMathOptions {\n /**\n * Typeset every formula now, ignoring the per-pass budget (the hard cap\n * still applies). For callers that capture the result right away, such as\n * slide snapshots.\n */\n readonly complete?: boolean;\n}\n\n/** Formulas shown as text because they fell past a root's hard cap. */\nconst capped = new WeakSet<Element>();\n\nfunction hidePendingMath(root: ParentNode): void {\n for (const element of root.querySelectorAll<HTMLElement>(`span[${INLINE_MATH_ATTRIBUTE}]`)) {\n if (!handled.has(element)) element.style.visibility = 'hidden';\n }\n}\n\nfunction showSource(element: HTMLElement, latex: string): void {\n element.textContent = latex;\n element.style.removeProperty('visibility');\n handled.add(element);\n}\n\n/** Show a formula past the hard cap as its source text, whatever it shows now. */\nfunction showCapped(element: Element, latex: string): void {\n if (capped.has(element)) return;\n const span = (element.ownerDocument ?? document).createElement('span');\n span.setAttribute(INLINE_MATH_ATTRIBUTE, latex);\n span.textContent = latex;\n handled.add(span);\n capped.add(span);\n element.replaceWith(span);\n}\n\n/**\n * Typeset the inline formulas under `root`. Each `span[data-inline-math]` is\n * replaced by a KaTeX render of its source carrying the same attribute (the\n * editor's storage shape); a source that cannot be typeset is shown as text.\n * Returns `true` when the budget deferred formulas; pending sources stay hidden.\n */\nexport function renderInlineMath(root: ParentNode, options: RenderInlineMathOptions = {}): boolean {\n return renderPass(root, options, newBudget());\n}\n\ntype TypesetBudget = { source: number; formulas: number; markup: number; full: boolean };\n\nfunction newBudget(): TypesetBudget {\n return { source: 0, formulas: 0, markup: 0, full: false };\n}\n\nfunction renderPass(\n root: ParentNode,\n options: RenderInlineMathOptions,\n budget: TypesetBudget,\n): boolean {\n const doc = (root as Node).ownerDocument ?? (root as Document);\n let rootSource = 0;\n let rootFormulas = 0;\n let pending = false;\n for (const element of root.querySelectorAll<HTMLElement>(`span[${INLINE_MATH_ATTRIBUTE}]`)) {\n // Inside a formula replaced earlier in this pass.\n if (!(root as Node).contains(element)) continue;\n const latex = element.getAttribute(INLINE_MATH_ATTRIBUTE) ?? '';\n rootSource += latex.length;\n rootFormulas += 1;\n // The cap depends only on document order within the root, so a formula\n // ends up the same whatever earlier passes did with it.\n if (rootSource > INLINE_MATH_MAX_ROOT_SOURCE || rootFormulas > INLINE_MATH_MAX_ROOT_FORMULAS) {\n showCapped(element, latex);\n continue;\n }\n if (handled.has(element) && !capped.has(element)) continue;\n const deferred = deferredTypesets.get(element);\n const prepared = deferred?.latex === latex ? deferred.entry : undefined;\n const cached = prepared ?? typesetCache.get(latex);\n // Preserve source order within a root, but let a later root use cached\n // formulas that fit in the space left by a rejected large formula.\n if (!options.complete && (pending || (budget.full && !cached))) {\n pending = true;\n continue;\n }\n if (!cached) {\n if (\n !options.complete &&\n budget.formulas > 0 &&\n (budget.source + latex.length > INLINE_MATH_SYNC_SOURCE_BUDGET ||\n budget.formulas >= INLINE_MATH_SYNC_FORMULA_BUDGET)\n ) {\n budget.full = true;\n pending = true;\n continue;\n }\n budget.source += latex.length;\n budget.formulas += 1;\n }\n const entry = prepared ?? typeset(doc, latex);\n if (!entry.formula) {\n showSource(element, latex);\n continue;\n }\n // Always allow one formula to make progress, even if it exceeds a batch.\n if (\n !options.complete &&\n budget.markup > 0 &&\n budget.markup + entry.size > INLINE_MATH_SYNC_MARKUP_BUDGET\n ) {\n budget.full = true;\n pending = true;\n deferredTypesets.set(element, { latex, entry });\n continue;\n }\n budget.markup += entry.size;\n const formula =\n entry.formula.ownerDocument === doc\n ? (entry.formula.cloneNode(true) as Element)\n : (doc.importNode(entry.formula, true) as Element);\n handled.add(formula);\n deferredTypesets.delete(element);\n element.replaceWith(formula);\n }\n if (pending) hidePendingMath(root);\n return pending;\n}\n\n/**\n * Typeset every formula under `container` now, root by root (each element\n * marked with {@link INLINE_MATH_ROOT_ATTRIBUTE}), so each root keeps its own\n * hard cap exactly as the live elements apply it. For snapshots, which\n * capture right away instead of waiting for idle time.\n */\nexport function completeInlineMath(container: Element): void {\n const roots = [...container.querySelectorAll(`[${INLINE_MATH_ROOT_ATTRIBUTE}]`)];\n if (container.hasAttribute(INLINE_MATH_ROOT_ATTRIBUTE)) roots.unshift(container);\n for (const root of roots) renderInlineMath(root, { complete: true });\n}\n\n/**\n * A `dangerouslySetInnerHTML` value that keeps its identity while `html` is\n * unchanged. React rewrites injected markup whenever it receives a new value\n * object, which would discard typeset formulas and any idle progress on each\n * re-render; a stable value leaves the DOM alone.\n */\nexport function useInnerHtml(html: string): { __html: string } {\n return useMemo(() => ({ __html: html }), [html]);\n}\n\n/** {@link useInnerHtml} for a grid of cells (table text), keyed on every cell's markup. */\nexport function useInnerHtmlGrid(cells: readonly (readonly string[])[]): { __html: string }[][] {\n const key = JSON.stringify(cells);\n return useMemo(\n () => (JSON.parse(key) as string[][]).map((row) => row.map((html) => ({ __html: html }))),\n [key],\n );\n}\n\ntype IdleHandle = { cancel(): void };\n\ntype IdleScope = typeof globalThis & {\n requestIdleCallback?: (callback: () => void, options?: { timeout: number }) => number;\n cancelIdleCallback?: (handle: number) => void;\n};\n\n/**\n * Run `run` when the page is idle. The scheduling functions are read once,\n * here, and the handle is always cancelled with the function from the same\n * pair: the global may be replaced or removed between scheduling and\n * cancelling (polyfills, test stubs), and a handle from one implementation\n * means nothing to another.\n */\nfunction whenIdle(run: () => void): IdleHandle {\n const scope = globalThis as IdleScope;\n const request = scope.requestIdleCallback;\n const cancel = scope.cancelIdleCallback;\n if (typeof request === 'function' && typeof cancel === 'function') {\n const handle = request.call(scope, run, { timeout: 500 });\n return { cancel: () => cancel.call(scope, handle) };\n }\n const schedule = scope.setTimeout;\n const clear = scope.clearTimeout;\n const handle = schedule.call(scope, run, 16);\n return { cancel: () => clear.call(scope, handle) };\n}\n\ntype MathPriority = 'normal' | 'background';\nexport const InlineMathPriorityContext = createContext<MathPriority>('normal');\n\n/**\n * Own the live queues and frame allowances. Background roots share a copy of\n * the remaining foreground allowance, so an earlier thumbnail commit cannot\n * spend the next foreground commit's budget. Neither is renewed on removal.\n */\nfunction createLiveMath() {\n // Idle work rotates roots within each priority, with foreground canvases first.\n const queuedRoots = new Map<Element, MathPriority>();\n // Only newly admitted background roots may spend the remaining frame allowance.\n const prePaintCandidates = new Set<Element>();\n let frameBudget: TypesetBudget | null = null;\n let backgroundBudget: TypesetBudget | null = null;\n let cancelFrameReset: (() => void) | null = null;\n let idleJob: { cancel?: () => void } | null = null;\n let prePaintScheduled = false;\n\n function resetFrameBudget(): void {\n cancelFrameReset?.();\n cancelFrameReset = null;\n frameBudget = null;\n backgroundBudget = null;\n }\n\n function frameAllowance(): TypesetBudget {\n if (!frameBudget) {\n const budget = (frameBudget = newBudget());\n const reset = () => {\n if (frameBudget === budget) {\n frameBudget = null;\n backgroundBudget = null;\n cancelFrameReset = null;\n }\n };\n if (\n typeof requestAnimationFrame === 'function' &&\n typeof cancelAnimationFrame === 'function'\n ) {\n const cancel = cancelAnimationFrame;\n const handle = requestAnimationFrame(reset);\n cancelFrameReset = () => cancel(handle);\n } else {\n const cancel = clearTimeout;\n const handle = setTimeout(reset, 16);\n cancelFrameReset = () => cancel(handle);\n }\n }\n return frameBudget;\n }\n\n function renderIdleRoots(priority: MathPriority, budget: TypesetBudget): void {\n for (const [root, queuedPriority] of [...queuedRoots]) {\n if (queuedPriority !== priority) continue;\n queuedRoots.delete(root);\n if (root.isConnected && renderPass(root, {}, budget)) queuedRoots.set(root, priority);\n if (budget.full) break;\n }\n }\n\n function scheduleIdle(): void {\n if (!queuedRoots.size) {\n idleJob?.cancel?.();\n idleJob = null;\n return;\n }\n if (idleJob) return;\n const job: { cancel?: () => void } = {};\n idleJob = job;\n job.cancel = whenIdle(() => {\n // A cancelled callback must not drain work queued by a later mount.\n if (idleJob !== job) return;\n idleJob = null;\n resetFrameBudget();\n const budget = newBudget();\n for (const priority of ['normal', 'background'] as const) {\n renderIdleRoots(priority, budget);\n if (budget.full) break;\n }\n scheduleIdle();\n }).cancel;\n }\n\n function flushPrePaint(): void {\n prePaintScheduled = false;\n if (!prePaintCandidates.size) return;\n const budget = (backgroundBudget ??= { ...frameAllowance() });\n // Visit every newly admitted root: cached formulas may fit after an earlier\n // root fills the allowance. Older queued roots remain in idle time.\n for (const root of prePaintCandidates) {\n queuedRoots.delete(root);\n if (root.isConnected && renderPass(root, {}, budget)) queuedRoots.set(root, 'background');\n }\n prePaintCandidates.clear();\n scheduleIdle();\n }\n\n return {\n isQueued: (root: Element): boolean => queuedRoots.has(root),\n\n render(root: Element, priority: MathPriority): void {\n if (priority === 'background') {\n prePaintCandidates.add(root);\n if (!prePaintScheduled) {\n prePaintScheduled = true;\n queueMicrotask(flushPrePaint);\n }\n return;\n }\n prePaintCandidates.delete(root);\n if (renderPass(root, {}, frameAllowance())) queuedRoots.set(root, priority);\n else queuedRoots.delete(root);\n scheduleIdle();\n },\n\n remove(root: Element): void {\n prePaintCandidates.delete(root);\n queuedRoots.delete(root);\n if (!queuedRoots.size) {\n idleJob?.cancel?.();\n idleJob = null;\n }\n },\n };\n}\n\nconst liveMath = createLiveMath();\n\n/**\n * Typeset the inline formulas of prose injected into `ref` as `html`. Runs\n * after every commit, before paint: React may rewrite the injected markup on\n * any re-render (not only when `html` changes), which would put the stored\n * source spans back. Formulas already typeset are skipped and cached renders\n * are cloned, so a commit that left the markup alone costs one query. What the\n * shared budget leaves over is typeset in idle time, using the current markup.\n * Pending roots stay in that queue on unchanged commits (including when an\n * external caller rewrites the HTML). New content can use the current frame's\n * synchronous allowance. Unmounting or replacing a root removes its queued work.\n * Foreground roots run in layout effects; background roots use the remaining\n * allowance in a microtask, following the nearest InlineMathPriorityContext.\n * Never updates React state.\n */\nexport function useInlineMath(ref: RefObject<Element | null>, html: string): void {\n const priority = useContext(InlineMathPriorityContext);\n const previous = useRef<{ root: Element | null; html: string; priority: MathPriority }>(null);\n useLayoutEffect(() => {\n const root = ref.current;\n const before = previous.current;\n if (before?.root && before.root !== root) liveMath.remove(before.root);\n previous.current = { root, html, priority };\n if (!root) return;\n if (!html.includes(INLINE_MATH_ATTRIBUTE)) {\n liveMath.remove(root);\n return;\n }\n if (\n before?.root === root &&\n before.html === html &&\n before.priority === priority &&\n liveMath.isQueued(root)\n ) {\n hidePendingMath(root);\n return;\n }\n liveMath.render(root, priority);\n });\n // Only clean up on unmount: per-commit removal would discard pending queue\n // membership and let unchanged rerenders reenter the pre-paint path.\n useLayoutEffect(() => {\n return () => {\n if (previous.current?.root) liveMath.remove(previous.current.root);\n previous.current = null;\n };\n }, []);\n}\n"],"names":[],"mappings":";;;;;AAMA;;;;;AAKG;AACI;AAEP;;;;AAIG;AACI;AAEP;AACO;AAEP;;;;AAIG;AACI;AACA;AAEP;;;;;AAKG;AACH;AAEA;;;AAGG;AACI;AACA;AAEP;AACA;AAEA;;;;;AAKG;AACH;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;AAC8D;;AAE5D;;;;;AAQM;AACA;AACA;AACA;AACD;;AAEH;;;AAGA;;AAEF;AACA;AACA;AACF;AAEA;;;;AAII;AACA;;;;;AAIA;AACE;AACA;;;;AAGE;AACA;;;;AAIN;AACF;AAWA;AACA;AAEA;AACE;AACE;AAA2B;;AAE/B;AAEA;AACE;AACA;AACA;AACF;AAEA;AACA;AACE;;AACA;AACA;AACA;AACA;AACA;AACA;AACF;AAEA;;;;;AAKG;;;AAGH;AAIA;AACE;AACF;AAEA;AAKE;;;;AAIA;;AAEE;;;AAEA;;;;;AAKE;;;AAGF;;;AAEA;;;;AAIA;;;;;;;;AASM;AAEF;;;;AAIF;AACA;;;AAGF;AACE;;;;;;;AASA;;;;;AAKF;;;;AAKA;AACA;AACA;;AAEF;;AACA;AACF;AAEA;;;;;AAKG;AACG;AACJ;AACA;AAAwD;;;AAE1D;AAEA;;;;;AAKG;AACG;AACJ;AACF;AAEA;AACM;;AAEJ;AAIF;AASA;;;;;;AAMG;AACH;;AAEE;AACA;;AAEE;AACA;;AAEF;AACA;AACA;AACA;AACF;;AAKA;;;;AAIG;AACH;;AAEE;;AAEA;;;;;;AAOA;;;;;;AAOA;;;;AAIM;;;;;AAKF;;AAGE;;AAGA;;;;;;;;;AAQJ;;AAGF;AACE;;;AAEE;;AACsD;;;;;AAK1D;AACE;AACE;;;;AAIF;;;;AAGA;;;;;AAIE;AACA;;AAEE;;;;AAGF;;;AAIJ;;;;;;;AAME;AACE;;AACsD;;;AAGxD;;;;;AAOE;AACE;;;;;;;AAOF;;AAC4C;;AACvC;AACL;;AAGF;AACE;AACA;AACA;AACE;;;;;AAKR;AAEA;AAEA;;;;;;;;;;;;;AAaG;AACG;AACJ;AACA;;AAEE;AACA;;AAC0C;;AAE1C;;;AAEE;;;AAGF;;;AAIE;;;;AAKF;AACF;;;;AAIE;AACE;;AACA;AACF;;AAEJ;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmaic/renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React component for rendering PPTist-style Slide JSON, extracted from OpenMAIC.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"echarts": ">=5",
|
|
59
|
+
"echarts": ">=5.5",
|
|
60
60
|
"motion": ">=11",
|
|
61
61
|
"react": ">=18",
|
|
62
62
|
"react-dom": ">=18",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"lucide-react": "^0.562.0",
|
|
80
80
|
"tailwind-merge": "^3.4.0",
|
|
81
81
|
"tinycolor2": "^1.6.0",
|
|
82
|
-
"@openmaic/
|
|
83
|
-
"@openmaic/
|
|
82
|
+
"@openmaic/geometry": "^0.1.0",
|
|
83
|
+
"@openmaic/dsl": "^0.12.0"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@rollup/plugin-commonjs": "^28.0.1",
|