@openmaic/renderer 0.1.15 → 0.1.16

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.
@@ -13,4 +13,5 @@ export { useElementFill } from './shared/useElementFill';
13
13
  export { useElementOutline } from './shared/useElementOutline';
14
14
  export { useElementShadow } from './shared/useElementShadow';
15
15
  export { useElementFlip } from './shared/useElementFlip';
16
+ export { hasTextInsets } from './shared/hasTextInsets';
16
17
  export { getTextStyle } from './table/tableUtils';
@@ -13,5 +13,6 @@ export { useElementFill } from './shared/useElementFill.js';
13
13
  export { useElementOutline } from './shared/useElementOutline.js';
14
14
  export { useElementShadow } from './shared/useElementShadow.js';
15
15
  export { useElementFlip } from './shared/useElementFlip.js';
16
+ export { hasTextInsets } from './shared/hasTextInsets.js';
16
17
  export { getTextStyle } from './table/tableUtils.js';
17
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
@@ -5,4 +5,4 @@ export interface BaseShapeElementProps {
5
5
  /** Replace the static Shape label with editor content. */
6
6
  renderLabel?: (element: PPTShapeElement, defaultContent: ReactNode) => ReactNode;
7
7
  }
8
- export declare function BaseShapeElement({ elementInfo, renderLabel }: BaseShapeElementProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function BaseShapeElement({ elementInfo, renderLabel }: BaseShapeElementProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,98 +1,34 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useRef } from 'react';
3
+ import { useMemo, useRef } from 'react';
4
+ import { validateShapeGeometry, RENDER_PATH_LIMITS, shapeToTextFallback } from '@openmaic/geometry';
4
5
  import { useElementOutline } from '../shared/useElementOutline.js';
5
6
  import { useElementShadow } from '../shared/useElementShadow.js';
6
7
  import { useElementFlip } from '../shared/useElementFlip.js';
7
8
  import { useElementFill } from '../shared/useElementFill.js';
8
9
  import { GradientDefs } from './GradientDefs.js';
10
+ import { BaseTextElement } from '../text/BaseTextElement.js';
9
11
  import { PatternDefs } from './PatternDefs.js';
10
12
  import { preservesPlainTextLineBreaks } from '../../utils/richText.js';
11
13
  import { useInnerHtml, useInlineMath } from '../../utils/inlineMath.js';
14
+ import { hasTextInsets } from '../shared/hasTextInsets.js';
12
15
 
13
- /**
14
- * Bounding box of a path's coordinates (path/viewBox space). Uses control
15
- * points for curves (a safe superset). Handles the commands our shapes emit
16
- * (M/L/C/Q/S/H/V/A/T/Z, absolute). Returns null if no coordinates.
17
- */
18
- function pathCoordBBox(d) {
19
- const tokens = d.match(/[a-zA-Z]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi);
20
- if (!tokens)
21
- return null;
22
- let i = 0;
23
- let cmd = '';
24
- let minX = Infinity;
25
- let minY = Infinity;
26
- let maxX = -Infinity;
27
- let maxY = -Infinity;
28
- const addX = (x) => {
29
- if (x < minX)
30
- minX = x;
31
- if (x > maxX)
32
- maxX = x;
33
- };
34
- const addY = (y) => {
35
- if (y < minY)
36
- minY = y;
37
- if (y > maxY)
38
- maxY = y;
39
- };
40
- const num = () => parseFloat(tokens[i++]);
41
- while (i < tokens.length) {
42
- // Path commands are single letters. Use an anchored test so number tokens
43
- // in scientific notation (e.g. "4.74e-16") aren't misread as commands.
44
- if (/^[a-zA-Z]$/.test(tokens[i])) {
45
- cmd = tokens[i];
46
- i++;
47
- }
48
- const c = cmd.toUpperCase();
49
- if (c === 'M' || c === 'L' || c === 'T') {
50
- addX(num());
51
- addY(num());
52
- }
53
- else if (c === 'C') {
54
- addX(num());
55
- addY(num());
56
- addX(num());
57
- addY(num());
58
- addX(num());
59
- addY(num());
60
- }
61
- else if (c === 'Q' || c === 'S') {
62
- addX(num());
63
- addY(num());
64
- addX(num());
65
- addY(num());
66
- }
67
- else if (c === 'H') {
68
- addX(num());
69
- }
70
- else if (c === 'V') {
71
- addY(num());
72
- }
73
- else if (c === 'A') {
74
- num();
75
- num();
76
- num();
77
- num();
78
- num();
79
- addX(num());
80
- addY(num());
81
- }
82
- else if (c === 'Z') ;
83
- else {
84
- i++; // unknown token, skip to avoid infinite loop
85
- }
86
- }
87
- if (!Number.isFinite(minX) ||
88
- !Number.isFinite(minY) ||
89
- !Number.isFinite(maxX) ||
90
- !Number.isFinite(maxY)) {
91
- return null;
16
+ function BaseShapeElement({ elementInfo, renderLabel }) {
17
+ const geometry = useMemo(() => validateShapeGeometry({
18
+ path: elementInfo.path,
19
+ viewBox: elementInfo.viewBox,
20
+ width: elementInfo.width,
21
+ height: elementInfo.height,
22
+ }, RENDER_PATH_LIMITS), [elementInfo.path, elementInfo.viewBox, elementInfo.width, elementInfo.height]);
23
+ if (!geometry.ok) {
24
+ const fallback = shapeToTextFallback(elementInfo);
25
+ return fallback ? (jsx("div", { "data-shape-geometry-error": geometry.error.code, children: jsx(BaseTextElement, { elementInfo: fallback, fillHeight: Boolean(renderLabel), renderContent: renderLabel ? (_text, content) => renderLabel(elementInfo, content) : undefined }) })) : null;
92
26
  }
93
- return { minX, minY, maxX, maxY };
27
+ return (jsx(ValidShapeElement, { elementInfo: elementInfo, renderLabel: renderLabel, geometry: geometry }));
94
28
  }
95
- function BaseShapeElement({ elementInfo, renderLabel }) {
29
+ function ValidShapeElement({ elementInfo, renderLabel, geometry, }) {
30
+ const width = elementInfo.width;
31
+ const height = elementInfo.height;
96
32
  const { fill } = useElementFill(elementInfo, 'base');
97
33
  const { outlineWidth, outlineColor, strokeDashArray } = useElementOutline(elementInfo.outline);
98
34
  const { shadowStyle } = useElementShadow(elementInfo.shadow);
@@ -114,7 +50,9 @@ function BaseShapeElement({ elementInfo, renderLabel }) {
114
50
  flexDirection: 'column',
115
51
  justifyContent,
116
52
  overflowWrap: 'break-word',
117
- lineHeight: text.lineHeight,
53
+ boxSizing: 'border-box',
54
+ padding: hasTextInsets(text.content) ? 0 : 10,
55
+ lineHeight: text.lineHeight ?? 1.625,
118
56
  letterSpacing: `${text.wordSpace || 0}px`,
119
57
  // PowerPoint/WPS 在 group flipH/flipV 时只镜像几何与位置,文字字形保持
120
58
  // 正向。父层 element-content 已应用 flipStyle 镜像 SVG path;这里给文字
@@ -129,8 +67,8 @@ function BaseShapeElement({ elementInfo, renderLabel }) {
129
67
  position: 'absolute',
130
68
  top: `${elementInfo.top}px`,
131
69
  left: `${elementInfo.left}px`,
132
- width: `${elementInfo.width}px`,
133
- height: `${elementInfo.height}px`,
70
+ width: `${width}px`,
71
+ height: `${height}px`,
134
72
  }, children: jsx("div", { className: "rotate-wrapper", style: {
135
73
  width: '100%',
136
74
  height: '100%',
@@ -153,9 +91,9 @@ function BaseShapeElement({ elementInfo, renderLabel }) {
153
91
  // exported PNG. Fix: grow the SVG viewport to contain the full path
154
92
  // bbox and offset it back, so the geometry renders in the exact same
155
93
  // place but nothing falls outside the captured viewport.
156
- const sx = elementInfo.width / (elementInfo.viewBox[0] || elementInfo.width || 1);
157
- const sy = elementInfo.height / (elementInfo.viewBox[1] || elementInfo.height || 1);
158
- const bbox = pathCoordBBox(elementInfo.path);
94
+ const sx = elementInfo.width / elementInfo.viewBox[0];
95
+ const sy = elementInfo.height / elementInfo.viewBox[1];
96
+ const bbox = geometry.bounds;
159
97
  const CAP = 4000; // guard against pathological coords blowing up the SVG
160
98
  let padL = 0;
161
99
  let padT = 0;
@@ -167,7 +105,7 @@ function BaseShapeElement({ elementInfo, renderLabel }) {
167
105
  padR = Math.min(CAP, Math.max(0, bbox.maxX * sx - elementInfo.width));
168
106
  padB = Math.min(CAP, Math.max(0, bbox.maxY * sy - elementInfo.height));
169
107
  }
170
- return (jsxs("svg", { overflow: "visible", width: elementInfo.width + padL + padR, height: elementInfo.height + padT + padB, style: {
108
+ return (jsxs("svg", { overflow: "visible", width: width + padL + padR, height: height + padT + padB, style: {
171
109
  position: 'absolute',
172
110
  left: -padL,
173
111
  top: -padT,
@@ -1 +1 @@
1
- {"version":3,"file":"BaseShapeElement.js","sources":["../../../src/elements/shape/BaseShapeElement.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, type ReactNode } from 'react';\nimport type { PPTShapeElement, ShapeText } from '@openmaic/dsl';\nimport { useElementOutline } from '../shared/useElementOutline';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { useElementFlip } from '../shared/useElementFlip';\nimport { useElementFill } from '../shared/useElementFill';\nimport { GradientDefs } from './GradientDefs';\nimport { PatternDefs } from './PatternDefs';\nimport { preservesPlainTextLineBreaks } from '../../utils/richText';\nimport { useInlineMath, useInnerHtml } from '../../utils/inlineMath';\n\nexport interface BaseShapeElementProps {\n elementInfo: PPTShapeElement;\n /** Replace the static Shape label with editor content. */\n renderLabel?: (element: PPTShapeElement, defaultContent: ReactNode) => ReactNode;\n}\n\n/**\n * Bounding box of a path's coordinates (path/viewBox space). Uses control\n * points for curves (a safe superset). Handles the commands our shapes emit\n * (M/L/C/Q/S/H/V/A/T/Z, absolute). Returns null if no coordinates.\n */\nfunction pathCoordBBox(\n d: string,\n): { minX: number; minY: number; maxX: number; maxY: number } | null {\n const tokens = d.match(/[a-zA-Z]|-?\\d*\\.?\\d+(?:e[-+]?\\d+)?/gi);\n if (!tokens) return null;\n let i = 0;\n let cmd = '';\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n const addX = (x: number) => {\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n };\n const addY = (y: number) => {\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n };\n const num = () => parseFloat(tokens[i++]);\n while (i < tokens.length) {\n // Path commands are single letters. Use an anchored test so number tokens\n // in scientific notation (e.g. \"4.74e-16\") aren't misread as commands.\n if (/^[a-zA-Z]$/.test(tokens[i])) {\n cmd = tokens[i];\n i++;\n }\n const c = cmd.toUpperCase();\n if (c === 'M' || c === 'L' || c === 'T') {\n addX(num());\n addY(num());\n } else if (c === 'C') {\n addX(num());\n addY(num());\n addX(num());\n addY(num());\n addX(num());\n addY(num());\n } else if (c === 'Q' || c === 'S') {\n addX(num());\n addY(num());\n addX(num());\n addY(num());\n } else if (c === 'H') {\n addX(num());\n } else if (c === 'V') {\n addY(num());\n } else if (c === 'A') {\n num();\n num();\n num();\n num();\n num();\n addX(num());\n addY(num());\n } else if (c === 'Z') {\n // no coords\n } else {\n i++; // unknown token, skip to avoid infinite loop\n }\n }\n if (\n !Number.isFinite(minX) ||\n !Number.isFinite(minY) ||\n !Number.isFinite(maxX) ||\n !Number.isFinite(maxY)\n ) {\n return null;\n }\n return { minX, minY, maxX, maxY };\n}\n\nexport function BaseShapeElement({ elementInfo, renderLabel }: BaseShapeElementProps) {\n const { fill } = useElementFill(elementInfo, 'base');\n const { outlineWidth, outlineColor, strokeDashArray } = useElementOutline(elementInfo.outline);\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const { flipStyle } = useElementFlip(elementInfo.flipH, elementInfo.flipV);\n\n const text: ShapeText = elementInfo.text || {\n content: '',\n align: 'middle',\n defaultFontName: 'Microsoft YaHei',\n defaultColor: '#333333',\n };\n\n const proseRef = useRef<HTMLDivElement>(null);\n const innerHtml = useInnerHtml(text.content);\n useInlineMath(proseRef, text.content);\n\n const justifyContent =\n text.align === 'top' ? 'flex-start' : text.align === 'bottom' ? 'flex-end' : 'center';\n const defaultLabelContent = (\n <div\n className=\"shape-text\"\n style={{\n position: 'absolute',\n inset: 0,\n display: 'flex',\n flexDirection: 'column',\n justifyContent,\n overflowWrap: 'break-word',\n lineHeight: text.lineHeight,\n letterSpacing: `${text.wordSpace || 0}px`,\n // PowerPoint/WPS 在 group flipH/flipV 时只镜像几何与位置,文字字形保持\n // 正向。父层 element-content 已应用 flipStyle 镜像 SVG path;这里给文字\n // 叠加同一个 flipStyle,两次 flip 抵消,让文字保持正向。\n transform: flipStyle,\n }}\n >\n <div\n ref={proseRef}\n data-inline-math-root=\"\"\n className=\"ProseMirror-static slide-renderer-prose\"\n style={{\n // @ts-expect-error CSS custom properties\n '--paragraphSpace': `${text.paragraphSpace === undefined ? 5 : text.paragraphSpace}px`,\n whiteSpace: preservesPlainTextLineBreaks(text.content) ? 'pre-line' : undefined,\n }}\n dangerouslySetInnerHTML={innerHtml}\n />\n </div>\n );\n\n return (\n <div\n className=\"base-element-shape\"\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 }}\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={{\n position: 'relative',\n width: '100%',\n height: '100%',\n opacity: elementInfo.opacity,\n filter: shadowStyle ? `drop-shadow(${shadowStyle})` : '',\n transform: flipStyle,\n color: text.defaultColor,\n fontFamily: text.defaultFontName,\n }}\n >\n {(() => {\n // The shape's path can extend OUTSIDE its width×height box (e.g.\n // curved connectors whose extreme adj values bulge the curve far\n // past the bbox). A browser shows that via overflow:visible, but\n // html2canvas-pro rasterizes each SVG to its width×height viewport\n // and CLIPS the overflow — turning connector arcs into stubs in the\n // exported PNG. Fix: grow the SVG viewport to contain the full path\n // bbox and offset it back, so the geometry renders in the exact same\n // place but nothing falls outside the captured viewport.\n const sx = elementInfo.width / (elementInfo.viewBox[0] || elementInfo.width || 1);\n const sy = elementInfo.height / (elementInfo.viewBox[1] || elementInfo.height || 1);\n const bbox = pathCoordBBox(elementInfo.path);\n const CAP = 4000; // guard against pathological coords blowing up the SVG\n let padL = 0;\n let padT = 0;\n let padR = 0;\n let padB = 0;\n if (bbox) {\n padL = Math.min(CAP, Math.max(0, -bbox.minX * sx));\n padT = Math.min(CAP, Math.max(0, -bbox.minY * sy));\n padR = Math.min(CAP, Math.max(0, bbox.maxX * sx - elementInfo.width));\n padB = Math.min(CAP, Math.max(0, bbox.maxY * sy - elementInfo.height));\n }\n return (\n <svg\n overflow=\"visible\"\n width={elementInfo.width + padL + padR}\n height={elementInfo.height + padT + padB}\n style={{\n position: 'absolute',\n left: -padL,\n top: -padT,\n transformOrigin: '0 0',\n overflow: 'visible',\n display: 'block',\n }}\n >\n <defs>\n {elementInfo.pattern && (\n <PatternDefs id={`base-pattern-${elementInfo.id}`} src={elementInfo.pattern} />\n )}\n {elementInfo.gradient && (\n <GradientDefs\n id={`base-gradient-${elementInfo.id}`}\n type={elementInfo.gradient.type}\n colors={elementInfo.gradient.colors}\n rotate={elementInfo.gradient.rotate}\n />\n )}\n </defs>\n <g transform={`translate(${padL},${padT}) scale(${sx}, ${sy})`}>\n <path\n vectorEffect=\"non-scaling-stroke\"\n strokeLinecap=\"butt\"\n strokeMiterlimit=\"8\"\n d={elementInfo.path}\n fill={fill}\n stroke={outlineColor}\n strokeWidth={outlineWidth}\n strokeDasharray={strokeDashArray}\n />\n </g>\n </svg>\n );\n })()}\n\n {renderLabel ? renderLabel(elementInfo, defaultLabelContent) : defaultLabelContent}\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAmBA;;;;AAIG;AACH;;AAIE;AAAa;;;;;AAKb;AACA;AACA;;;;;AAGA;AACA;;;;;AAGA;AACA;AACA;;;;AAII;AACA;;AAEF;AACA;AACE;AACA;;AACK;AACL;AACA;AACA;AACA;AACA;AACA;;;AAEA;AACA;AACA;AACA;;AACK;AACL;;AACK;AACL;;AACK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AACK;;;;;AAMT;AAEE;AACA;AACA;AAEA;;;AAGJ;;;AAIE;;AAEA;AAEA;AACE;AACA;AACA;AACA;;AAGF;;AAEA;;;AAQM;AACA;AACA;AACA;;AAEA;;AAEA;;;;AAIA;AACD;;AAQG;AACA;AACD;AAMP;AAIM;AACA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;AACD;AAKG;AACA;AACA;;;AAGA;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;AAiBM;;;AAGA;AACA;AACA;;;AAqClB;;"}
1
+ {"version":3,"file":"BaseShapeElement.js","sources":["../../../src/elements/shape/BaseShapeElement.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo, useRef, type ReactNode } from 'react';\nimport type { PPTShapeElement, ShapeText } from '@openmaic/dsl';\nimport {\n validateShapeGeometry,\n RENDER_PATH_LIMITS,\n shapeToTextFallback,\n type PathValidation,\n} from '@openmaic/geometry';\nimport { useElementOutline } from '../shared/useElementOutline';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { useElementFlip } from '../shared/useElementFlip';\nimport { useElementFill } from '../shared/useElementFill';\nimport { GradientDefs } from './GradientDefs';\nimport { BaseTextElement } from '../text/BaseTextElement';\nimport { PatternDefs } from './PatternDefs';\nimport { preservesPlainTextLineBreaks } from '../../utils/richText';\nimport { useInlineMath, useInnerHtml } from '../../utils/inlineMath';\nimport { hasTextInsets } from '../shared/hasTextInsets';\n\nexport interface BaseShapeElementProps {\n elementInfo: PPTShapeElement;\n /** Replace the static Shape label with editor content. */\n renderLabel?: (element: PPTShapeElement, defaultContent: ReactNode) => ReactNode;\n}\n\nexport function BaseShapeElement({ elementInfo, renderLabel }: BaseShapeElementProps) {\n const geometry = useMemo(\n () =>\n validateShapeGeometry(\n {\n path: elementInfo.path,\n viewBox: elementInfo.viewBox,\n width: elementInfo.width,\n height: elementInfo.height,\n },\n RENDER_PATH_LIMITS,\n ),\n [elementInfo.path, elementInfo.viewBox, elementInfo.width, elementInfo.height],\n );\n if (!geometry.ok) {\n const fallback = shapeToTextFallback(elementInfo);\n return fallback ? (\n <div data-shape-geometry-error={geometry.error.code}>\n <BaseTextElement\n elementInfo={fallback}\n fillHeight={Boolean(renderLabel)}\n renderContent={\n renderLabel ? (_text, content) => renderLabel(elementInfo, content) : undefined\n }\n />\n </div>\n ) : null;\n }\n return (\n <ValidShapeElement elementInfo={elementInfo} renderLabel={renderLabel} geometry={geometry} />\n );\n}\n\nfunction ValidShapeElement({\n elementInfo,\n renderLabel,\n geometry,\n}: BaseShapeElementProps & {\n geometry: Extract<PathValidation, { ok: true }>;\n}) {\n const width = elementInfo.width;\n const height = elementInfo.height;\n const { fill } = useElementFill(elementInfo, 'base');\n const { outlineWidth, outlineColor, strokeDashArray } = useElementOutline(elementInfo.outline);\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const { flipStyle } = useElementFlip(elementInfo.flipH, elementInfo.flipV);\n\n const text: ShapeText = elementInfo.text || {\n content: '',\n align: 'middle',\n defaultFontName: 'Microsoft YaHei',\n defaultColor: '#333333',\n };\n\n const proseRef = useRef<HTMLDivElement>(null);\n const innerHtml = useInnerHtml(text.content);\n useInlineMath(proseRef, text.content);\n\n const justifyContent =\n text.align === 'top' ? 'flex-start' : text.align === 'bottom' ? 'flex-end' : 'center';\n const defaultLabelContent = (\n <div\n className=\"shape-text\"\n style={{\n position: 'absolute',\n inset: 0,\n display: 'flex',\n flexDirection: 'column',\n justifyContent,\n overflowWrap: 'break-word',\n boxSizing: 'border-box',\n padding: hasTextInsets(text.content) ? 0 : 10,\n lineHeight: text.lineHeight ?? 1.625,\n letterSpacing: `${text.wordSpace || 0}px`,\n // PowerPoint/WPS 在 group flipH/flipV 时只镜像几何与位置,文字字形保持\n // 正向。父层 element-content 已应用 flipStyle 镜像 SVG path;这里给文字\n // 叠加同一个 flipStyle,两次 flip 抵消,让文字保持正向。\n transform: flipStyle,\n }}\n >\n <div\n ref={proseRef}\n data-inline-math-root=\"\"\n className=\"ProseMirror-static slide-renderer-prose\"\n style={{\n // @ts-expect-error CSS custom properties\n '--paragraphSpace': `${text.paragraphSpace === undefined ? 5 : text.paragraphSpace}px`,\n whiteSpace: preservesPlainTextLineBreaks(text.content) ? 'pre-line' : undefined,\n }}\n dangerouslySetInnerHTML={innerHtml}\n />\n </div>\n );\n\n return (\n <div\n className=\"base-element-shape\"\n style={{\n position: 'absolute',\n top: `${elementInfo.top}px`,\n left: `${elementInfo.left}px`,\n width: `${width}px`,\n height: `${height}px`,\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={{\n position: 'relative',\n width: '100%',\n height: '100%',\n opacity: elementInfo.opacity,\n filter: shadowStyle ? `drop-shadow(${shadowStyle})` : '',\n transform: flipStyle,\n color: text.defaultColor,\n fontFamily: text.defaultFontName,\n }}\n >\n {(() => {\n // The shape's path can extend OUTSIDE its width×height box (e.g.\n // curved connectors whose extreme adj values bulge the curve far\n // past the bbox). A browser shows that via overflow:visible, but\n // html2canvas-pro rasterizes each SVG to its width×height viewport\n // and CLIPS the overflow — turning connector arcs into stubs in the\n // exported PNG. Fix: grow the SVG viewport to contain the full path\n // bbox and offset it back, so the geometry renders in the exact same\n // place but nothing falls outside the captured viewport.\n const sx = elementInfo.width / elementInfo.viewBox[0];\n const sy = elementInfo.height / elementInfo.viewBox[1];\n const bbox = geometry.bounds;\n const CAP = 4000; // guard against pathological coords blowing up the SVG\n let padL = 0;\n let padT = 0;\n let padR = 0;\n let padB = 0;\n if (bbox) {\n padL = Math.min(CAP, Math.max(0, -bbox.minX * sx));\n padT = Math.min(CAP, Math.max(0, -bbox.minY * sy));\n padR = Math.min(CAP, Math.max(0, bbox.maxX * sx - elementInfo.width));\n padB = Math.min(CAP, Math.max(0, bbox.maxY * sy - elementInfo.height));\n }\n return (\n <svg\n overflow=\"visible\"\n width={width + padL + padR}\n height={height + padT + padB}\n style={{\n position: 'absolute',\n left: -padL,\n top: -padT,\n transformOrigin: '0 0',\n overflow: 'visible',\n display: 'block',\n }}\n >\n <defs>\n {elementInfo.pattern && (\n <PatternDefs id={`base-pattern-${elementInfo.id}`} src={elementInfo.pattern} />\n )}\n {elementInfo.gradient && (\n <GradientDefs\n id={`base-gradient-${elementInfo.id}`}\n type={elementInfo.gradient.type}\n colors={elementInfo.gradient.colors}\n rotate={elementInfo.gradient.rotate}\n />\n )}\n </defs>\n <g transform={`translate(${padL},${padT}) scale(${sx}, ${sy})`}>\n <path\n vectorEffect=\"non-scaling-stroke\"\n strokeLinecap=\"butt\"\n strokeMiterlimit=\"8\"\n d={elementInfo.path}\n fill={fill}\n stroke={outlineColor}\n strokeWidth={outlineWidth}\n strokeDasharray={strokeDashArray}\n />\n </g>\n </svg>\n );\n })()}\n\n {renderLabel ? renderLabel(elementInfo, defaultLabelContent) : defaultLabelContent}\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyCE;AACE;;;AAaF;AAGF;AAEA;AAOE;AACA;;AAEA;;AAEA;AAEA;AACE;AACA;AACA;AACA;;AAGF;;AAEA;;;AAQM;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;;;AAIA;AACD;;AAQG;AACA;AACD;AAMP;AAIM;AACA;AACA;;;AAGD;AAKG;AACA;AACA;AACD;AAKG;AACA;AACA;;;AAGA;;;;;;;;;;;;AAcA;AACA;AACA;AACA;;;;;;;;;;;;AAiBM;;;AAGA;AACA;AACA;;;AAqClB;;"}
@@ -0,0 +1,2 @@
1
+ /** Imported PPTX labels carry their own text box padding on the outer div. */
2
+ export declare function hasTextInsets(content: string): boolean;
@@ -0,0 +1,9 @@
1
+ /** Imported PPTX labels carry their own text box padding on the outer div. */
2
+ function hasTextInsets(content) {
3
+ const hasExplicitTextInsets = /^\s*<div\b[^>]*\sdata-pptx-text-insets\s*=\s*(["'])true\1/i.test(content);
4
+ // Legacy saved slides predate the marker but retain an inline padding style.
5
+ return (hasExplicitTextInsets || /^\s*<div\b[^>]*\sstyle\s*=\s*["'][^"']*\bpadding\s*:/i.test(content));
6
+ }
7
+
8
+ export { hasTextInsets };
9
+ //# sourceMappingURL=hasTextInsets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasTextInsets.js","sources":["../../../src/elements/shared/hasTextInsets.ts"],"sourcesContent":["/** Imported PPTX labels carry their own text box padding on the outer div. */\nexport function hasTextInsets(content: string): boolean {\n const hasExplicitTextInsets = /^\\s*<div\\b[^>]*\\sdata-pptx-text-insets\\s*=\\s*([\"'])true\\1/i.test(\n content,\n );\n // Legacy saved slides predate the marker but retain an inline padding style.\n return (\n hasExplicitTextInsets || /^\\s*<div\\b[^>]*\\sstyle\\s*=\\s*[\"'][^\"']*\\bpadding\\s*:/i.test(content)\n );\n}\n"],"names":[],"mappings":"AAAA;AACM,SAAU,aAAa,CAAC,OAAe,EAAA;IAC3C,MAAM,qBAAqB,GAAG,4DAA4D,CAAC,IAAI,CAC7F,OAAO,CACR;;IAED,QACE,qBAAqB,IAAI,uDAAuD,CAAC,IAAI,CAAC,OAAO,CAAC;AAElG;;;;"}
@@ -4,5 +4,7 @@ export interface BaseTextElementProps {
4
4
  elementInfo: PPTTextElement;
5
5
  target?: string;
6
6
  renderContent?: (element: PPTTextElement, defaultContent: ReactNode) => ReactNode;
7
+ /** Keep a recovered shape's label container sized for an absolute-positioned editor. */
8
+ fillHeight?: boolean;
7
9
  }
8
- export declare function BaseTextElement({ elementInfo, target, renderContent }: BaseTextElementProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function BaseTextElement({ elementInfo, target, renderContent, fillHeight, }: BaseTextElementProps): import("react/jsx-runtime").JSX.Element;
@@ -5,19 +5,16 @@ import { useElementShadow } from '../shared/useElementShadow.js';
5
5
  import { ElementOutline } from '../shared/ElementOutline.js';
6
6
  import { preservesPlainTextLineBreaks } from '../../utils/richText.js';
7
7
  import { useInnerHtml, useInlineMath } from '../../utils/inlineMath.js';
8
+ import { hasTextInsets } from '../shared/hasTextInsets.js';
8
9
 
9
- function BaseTextElement({ elementInfo, target, renderContent }) {
10
+ function BaseTextElement({ elementInfo, target, renderContent, fillHeight = false, }) {
10
11
  const { shadowStyle } = useElementShadow(elementInfo.shadow);
11
12
  const proseRef = useRef(null);
12
13
  const innerHtml = useInnerHtml(elementInfo.content);
13
14
  useInlineMath(proseRef, elementInfo.content);
14
15
  // Imported OOXML text carries its own bodyPr insets on the outer div.
15
- // Adding the editor's default inset again shifts vertical text left and
16
- // reduces the available line width for horizontal text.
17
- const hasExplicitTextInsets = /^\s*<div\b[^>]*\sdata-pptx-text-insets\s*=\s*(["'])true\1/i.test(elementInfo.content);
18
- // Legacy saved slides predate the marker. Retain their existing inset behavior.
19
- const hasTextInsets = hasExplicitTextInsets ||
20
- /^\s*<div\b[^>]*\bstyle\s*=\s*["'][^"']*\bpadding\s*:/i.test(elementInfo.content);
16
+ // Adding the editor's default inset again shifts the label and reduces line width.
17
+ const contentHasTextInsets = hasTextInsets(elementInfo.content);
21
18
  const vAlign = elementInfo.vAlign ?? 'top';
22
19
  const justifyContent = vAlign === 'middle' ? 'center' : vAlign === 'bottom' ? 'flex-end' : 'flex-start';
23
20
  const defaultContent = (jsx("div", { ref: proseRef, "data-inline-math-root": "", className: "text ProseMirror-static", style: {
@@ -44,10 +41,13 @@ function BaseTextElement({ elementInfo, target, renderContent }) {
44
41
  }, children: jsxs("div", { className: "element-content slide-renderer-prose", style: {
45
42
  position: 'relative',
46
43
  boxSizing: 'border-box',
47
- padding: hasTextInsets ? 0 : '10px',
44
+ padding: contentHasTextInsets ? 0 : '10px',
48
45
  overflowWrap: 'break-word',
49
46
  width: elementInfo.vertical ? 'auto' : '100%',
50
- height: elementInfo.vertical ? '100%' : 'auto',
47
+ height: elementInfo.vertical || fillHeight ? '100%' : 'auto',
48
+ display: fillHeight ? 'flex' : undefined,
49
+ flexDirection: fillHeight ? 'column' : undefined,
50
+ justifyContent: fillHeight ? justifyContent : undefined,
51
51
  textShadow: shadowStyle,
52
52
  lineHeight: elementInfo.lineHeight,
53
53
  letterSpacing: elementInfo.wordSpace !== undefined ? `${elementInfo.wordSpace}px` : undefined,
@@ -1 +1 @@
1
- {"version":3,"file":"BaseTextElement.js","sources":["../../../src/elements/text/BaseTextElement.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, type CSSProperties, type ReactNode } from 'react';\nimport type { PPTTextElement } from '@openmaic/dsl';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { ElementOutline } from '../shared/ElementOutline';\nimport { preservesPlainTextLineBreaks } from '../../utils/richText';\nimport { useInlineMath, useInnerHtml } from '../../utils/inlineMath';\n\nexport interface BaseTextElementProps {\n elementInfo: PPTTextElement;\n target?: string;\n renderContent?: (element: PPTTextElement, defaultContent: ReactNode) => ReactNode;\n}\n\nexport function BaseTextElement({ elementInfo, target, renderContent }: BaseTextElementProps) {\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const proseRef = useRef<HTMLDivElement>(null);\n const innerHtml = useInnerHtml(elementInfo.content);\n useInlineMath(proseRef, elementInfo.content);\n // Imported OOXML text carries its own bodyPr insets on the outer div.\n // Adding the editor's default inset again shifts vertical text left and\n // reduces the available line width for horizontal text.\n const hasExplicitTextInsets = /^\\s*<div\\b[^>]*\\sdata-pptx-text-insets\\s*=\\s*([\"'])true\\1/i.test(\n elementInfo.content,\n );\n // Legacy saved slides predate the marker. Retain their existing inset behavior.\n const hasTextInsets =\n hasExplicitTextInsets ||\n /^\\s*<div\\b[^>]*\\bstyle\\s*=\\s*[\"'][^\"']*\\bpadding\\s*:/i.test(elementInfo.content);\n\n const vAlign = elementInfo.vAlign ?? 'top';\n const justifyContent =\n vAlign === 'middle' ? 'center' : vAlign === 'bottom' ? 'flex-end' : 'flex-start';\n const defaultContent = (\n <div\n ref={proseRef}\n data-inline-math-root=\"\"\n className=\"text ProseMirror-static\"\n style={{\n position: 'relative',\n pointerEvents: target === 'thumbnail' ? 'none' : undefined,\n whiteSpace: preservesPlainTextLineBreaks(elementInfo.content) ? 'pre-line' : undefined,\n }}\n dangerouslySetInnerHTML={innerHtml}\n />\n );\n\n return (\n <div\n className=\"base-element-text\"\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 }}\n >\n <div\n className=\"rotate-wrapper\"\n style={{\n width: '100%',\n height: '100%',\n transform: `rotate(${elementInfo.rotate}deg)`,\n // Fill the full text box and rotate it with the glyphs/outline.\n backgroundColor: elementInfo.fill,\n opacity: elementInfo.opacity,\n display: 'flex',\n flexDirection: 'column',\n justifyContent,\n }}\n >\n <div\n className=\"element-content slide-renderer-prose\"\n style={{\n position: 'relative',\n boxSizing: 'border-box',\n padding: hasTextInsets ? 0 : '10px',\n overflowWrap: 'break-word',\n width: elementInfo.vertical ? 'auto' : '100%',\n height: elementInfo.vertical ? '100%' : 'auto',\n textShadow: shadowStyle,\n lineHeight: elementInfo.lineHeight,\n letterSpacing:\n elementInfo.wordSpace !== undefined ? `${elementInfo.wordSpace}px` : undefined,\n color: elementInfo.defaultColor,\n fontFamily: elementInfo.defaultFontName,\n writingMode: elementInfo.vertical ? 'vertical-rl' : 'horizontal-tb',\n ...(elementInfo.paragraphSpace !== undefined\n ? ({ '--paragraphSpace': `${elementInfo.paragraphSpace}px` } as CSSProperties)\n : null),\n }}\n >\n <ElementOutline\n width={elementInfo.width}\n height={elementInfo.height}\n outline={elementInfo.outline}\n />\n {renderContent?.(elementInfo, defaultContent) ?? defaultContent}\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAeM;;AAEJ;;AAEA;;;;;;;AAUE;AAEF;;AAGA;AAMM;;AAEA;AACD;AAKL;AAIM;AACA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;;;;AAIA;AACA;;AAED;AAKG;AACA;;AAEA;;;AAGA;;AAEA;;;;AAKA;;;AAGD;AAYX;;"}
1
+ {"version":3,"file":"BaseTextElement.js","sources":["../../../src/elements/text/BaseTextElement.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, type CSSProperties, type ReactNode } from 'react';\nimport type { PPTTextElement } from '@openmaic/dsl';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { ElementOutline } from '../shared/ElementOutline';\nimport { preservesPlainTextLineBreaks } from '../../utils/richText';\nimport { useInlineMath, useInnerHtml } from '../../utils/inlineMath';\nimport { hasTextInsets } from '../shared/hasTextInsets';\n\nexport interface BaseTextElementProps {\n elementInfo: PPTTextElement;\n target?: string;\n renderContent?: (element: PPTTextElement, defaultContent: ReactNode) => ReactNode;\n /** Keep a recovered shape's label container sized for an absolute-positioned editor. */\n fillHeight?: boolean;\n}\n\nexport function BaseTextElement({\n elementInfo,\n target,\n renderContent,\n fillHeight = false,\n}: BaseTextElementProps) {\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const proseRef = useRef<HTMLDivElement>(null);\n const innerHtml = useInnerHtml(elementInfo.content);\n useInlineMath(proseRef, elementInfo.content);\n // Imported OOXML text carries its own bodyPr insets on the outer div.\n // Adding the editor's default inset again shifts the label and reduces line width.\n const contentHasTextInsets = hasTextInsets(elementInfo.content);\n\n const vAlign = elementInfo.vAlign ?? 'top';\n const justifyContent =\n vAlign === 'middle' ? 'center' : vAlign === 'bottom' ? 'flex-end' : 'flex-start';\n const defaultContent = (\n <div\n ref={proseRef}\n data-inline-math-root=\"\"\n className=\"text ProseMirror-static\"\n style={{\n position: 'relative',\n pointerEvents: target === 'thumbnail' ? 'none' : undefined,\n whiteSpace: preservesPlainTextLineBreaks(elementInfo.content) ? 'pre-line' : undefined,\n }}\n dangerouslySetInnerHTML={innerHtml}\n />\n );\n\n return (\n <div\n className=\"base-element-text\"\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 }}\n >\n <div\n className=\"rotate-wrapper\"\n style={{\n width: '100%',\n height: '100%',\n transform: `rotate(${elementInfo.rotate}deg)`,\n // Fill the full text box and rotate it with the glyphs/outline.\n backgroundColor: elementInfo.fill,\n opacity: elementInfo.opacity,\n display: 'flex',\n flexDirection: 'column',\n justifyContent,\n }}\n >\n <div\n className=\"element-content slide-renderer-prose\"\n style={{\n position: 'relative',\n boxSizing: 'border-box',\n padding: contentHasTextInsets ? 0 : '10px',\n overflowWrap: 'break-word',\n width: elementInfo.vertical ? 'auto' : '100%',\n height: elementInfo.vertical || fillHeight ? '100%' : 'auto',\n display: fillHeight ? 'flex' : undefined,\n flexDirection: fillHeight ? 'column' : undefined,\n justifyContent: fillHeight ? justifyContent : undefined,\n textShadow: shadowStyle,\n lineHeight: elementInfo.lineHeight,\n letterSpacing:\n elementInfo.wordSpace !== undefined ? `${elementInfo.wordSpace}px` : undefined,\n color: elementInfo.defaultColor,\n fontFamily: elementInfo.defaultFontName,\n writingMode: elementInfo.vertical ? 'vertical-rl' : 'horizontal-tb',\n ...(elementInfo.paragraphSpace !== undefined\n ? ({ '--paragraphSpace': `${elementInfo.paragraphSpace}px` } as CSSProperties)\n : null),\n }}\n >\n <ElementOutline\n width={elementInfo.width}\n height={elementInfo.height}\n outline={elementInfo.outline}\n />\n {renderContent?.(elementInfo, defaultContent) ?? defaultContent}\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAkBM;;AAOJ;;AAEA;;;;AAKA;;AAGA;AAMM;;AAEA;AACD;AAKL;AAIM;AACA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;;;;AAIA;AACA;;AAED;AAKG;AACA;;AAEA;;AAEA;;;;AAIA;;AAEA;;;;AAKA;;;AAGD;AAYX;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmaic/renderer",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "React component for rendering PPTist-style Slide JSON, extracted from OpenMAIC.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -79,7 +79,8 @@
79
79
  "lucide-react": "^0.562.0",
80
80
  "tailwind-merge": "^3.4.0",
81
81
  "tinycolor2": "^1.6.0",
82
- "@openmaic/dsl": "^0.12.0"
82
+ "@openmaic/dsl": "^0.12.0",
83
+ "@openmaic/geometry": "^0.1.0"
83
84
  },
84
85
  "devDependencies": {
85
86
  "@rollup/plugin-commonjs": "^28.0.1",