@openmaic/renderer 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/shape/BaseShapeElement.js +2 -0
- package/dist/elements/shape/BaseShapeElement.js.map +1 -1
- package/dist/elements/text/BaseTextElement.js +2 -0
- package/dist/elements/text/BaseTextElement.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.d.ts +9 -1
- package/dist/styles.js +25 -10
- package/dist/styles.js.map +1 -1
- package/dist/utils/richText.d.ts +1 -0
- package/dist/utils/richText.js +12 -0
- package/dist/utils/richText.js.map +1 -0
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ import { useElementFlip } from '../shared/useElementFlip.js';
|
|
|
6
6
|
import { useElementFill } from '../shared/useElementFill.js';
|
|
7
7
|
import { GradientDefs } from './GradientDefs.js';
|
|
8
8
|
import { PatternDefs } from './PatternDefs.js';
|
|
9
|
+
import { preservesPlainTextLineBreaks } from '../../utils/richText.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Bounding box of a path's coordinates (path/viewBox space). Uses control
|
|
@@ -117,6 +118,7 @@ function BaseShapeElement({ elementInfo, renderLabel }) {
|
|
|
117
118
|
}, children: jsx("div", { className: "ProseMirror-static slide-renderer-prose", style: {
|
|
118
119
|
// @ts-expect-error CSS custom properties
|
|
119
120
|
'--paragraphSpace': `${text.paragraphSpace === undefined ? 5 : text.paragraphSpace}px`,
|
|
121
|
+
whiteSpace: preservesPlainTextLineBreaks(text.content) ? 'pre-line' : undefined,
|
|
120
122
|
}, dangerouslySetInnerHTML: { __html: text.content } }) }));
|
|
121
123
|
return (jsx("div", { className: "base-element-shape", style: {
|
|
122
124
|
position: 'absolute',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseShapeElement.js","sources":["../../../src/elements/shape/BaseShapeElement.tsx"],"sourcesContent":["'use client';\n\nimport 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';\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 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 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 }}\n dangerouslySetInnerHTML={{ __html: text.content }}\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":"
|
|
1
|
+
{"version":3,"file":"BaseShapeElement.js","sources":["../../../src/elements/shape/BaseShapeElement.tsx"],"sourcesContent":["'use client';\n\nimport 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';\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 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 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={{ __html: text.content }}\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":";;;;;;;;;;AAkBA;;;;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;;;;AASI;AACA;AACA;AACA;;AAEA;;AAEA;;;;AAIA;AACD;;AAMG;AACA;AACD;AAMP;AAIM;AACA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;AACD;AAKG;AACA;AACA;;;AAGA;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;AAiBM;;;AAGA;AACA;AACA;;;AAqClB;;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { useElementShadow } from '../shared/useElementShadow.js';
|
|
4
4
|
import { ElementOutline } from '../shared/ElementOutline.js';
|
|
5
|
+
import { preservesPlainTextLineBreaks } from '../../utils/richText.js';
|
|
5
6
|
|
|
6
7
|
function BaseTextElement({ elementInfo, target, renderContent }) {
|
|
7
8
|
const { shadowStyle } = useElementShadow(elementInfo.shadow);
|
|
@@ -10,6 +11,7 @@ function BaseTextElement({ elementInfo, target, renderContent }) {
|
|
|
10
11
|
const defaultContent = (jsx("div", { className: "text ProseMirror-static", style: {
|
|
11
12
|
position: 'relative',
|
|
12
13
|
pointerEvents: target === 'thumbnail' ? 'none' : undefined,
|
|
14
|
+
whiteSpace: preservesPlainTextLineBreaks(elementInfo.content) ? 'pre-line' : undefined,
|
|
13
15
|
}, dangerouslySetInnerHTML: { __html: elementInfo.content } }));
|
|
14
16
|
return (jsx("div", { className: "base-element-text", style: {
|
|
15
17
|
position: 'absolute',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTextElement.js","sources":["../../../src/elements/text/BaseTextElement.tsx"],"sourcesContent":["'use client';\n\nimport type { CSSProperties, ReactNode } from 'react';\nimport type { PPTTextElement } from '@openmaic/dsl';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { ElementOutline } from '../shared/ElementOutline';\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\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 className=\"text ProseMirror-static\"\n style={{\n position: 'relative',\n pointerEvents: target === 'thumbnail' ? 'none' : undefined,\n }}\n dangerouslySetInnerHTML={{ __html: elementInfo.content }}\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: '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":"
|
|
1
|
+
{"version":3,"file":"BaseTextElement.js","sources":["../../../src/elements/text/BaseTextElement.tsx"],"sourcesContent":["'use client';\n\nimport type { CSSProperties, ReactNode } from 'react';\nimport type { PPTTextElement } from '@openmaic/dsl';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { ElementOutline } from '../shared/ElementOutline';\nimport { preservesPlainTextLineBreaks } from '../../utils/richText';\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\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 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={{ __html: elementInfo.content }}\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: '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":";;;;;;AAcM;;AAGJ;;;AAOM;;AAEA;;AAMN;AAIM;AACA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;;;;AAIA;AACA;;AAED;AAKG;AACA;AACA;AACA;;;AAGA;;AAEA;;;;AAKA;;;AAGD;AAYX;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export { useViewportSize, type ViewportStyles, type UseViewportSizeOptions, type
|
|
|
7
7
|
export { findElementGeometry, findNearestCorner, getElementPercentageGeometry, type PercentageGeometry, } from './utils/geometry';
|
|
8
8
|
export { cn } from './utils/cn';
|
|
9
9
|
export { getElementRange, getLineElementPath, getTableSubThemeColor } from './utils/element';
|
|
10
|
+
export { createTextProseStyles } from './styles';
|
|
10
11
|
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -10,5 +10,6 @@ export { useViewportSize } from './hooks/useViewportSize.js';
|
|
|
10
10
|
export { findElementGeometry, findNearestCorner, getElementPercentageGeometry } from './utils/geometry.js';
|
|
11
11
|
export { cn } from './utils/cn.js';
|
|
12
12
|
export { getElementRange, getLineElementPath, getTableSubThemeColor } from './utils/element.js';
|
|
13
|
+
export { createTextProseStyles } from './styles.js';
|
|
13
14
|
export * from '@openmaic/dsl';
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
package/dist/styles.d.ts
CHANGED
|
@@ -8,4 +8,12 @@
|
|
|
8
8
|
* `--paragraphSpace` CSS variable. List rules restore semantic markers that
|
|
9
9
|
* host resets such as Tailwind Preflight remove.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Generates the reset rules that define rich-text geometry inside a slide.
|
|
13
|
+
*
|
|
14
|
+
* Both the static renderer and the ProseMirror editor need these exact rules:
|
|
15
|
+
* keeping the selector configurable lets them share one layout contract while
|
|
16
|
+
* retaining their different DOM roots.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createTextProseStyles(selector: string): string;
|
|
19
|
+
export declare const SLIDE_RENDERER_STYLES: string;
|
package/dist/styles.js
CHANGED
|
@@ -8,34 +8,49 @@
|
|
|
8
8
|
* `--paragraphSpace` CSS variable. List rules restore semantic markers that
|
|
9
9
|
* host resets such as Tailwind Preflight remove.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Generates the reset rules that define rich-text geometry inside a slide.
|
|
13
|
+
*
|
|
14
|
+
* Both the static renderer and the ProseMirror editor need these exact rules:
|
|
15
|
+
* keeping the selector configurable lets them share one layout contract while
|
|
16
|
+
* retaining their different DOM roots.
|
|
17
|
+
*/
|
|
18
|
+
function createTextProseStyles(selector) {
|
|
19
|
+
return `
|
|
20
|
+
${selector} p {
|
|
13
21
|
margin-top: 0;
|
|
14
22
|
margin-bottom: var(--paragraphSpace, 0);
|
|
15
23
|
}
|
|
16
|
-
|
|
24
|
+
${selector} p:last-child {
|
|
17
25
|
margin-bottom: 0;
|
|
18
26
|
}
|
|
19
|
-
|
|
27
|
+
${selector} p:empty::before {
|
|
28
|
+
content: '\\00a0';
|
|
29
|
+
}
|
|
30
|
+
${selector} .katex-display {
|
|
20
31
|
margin: 0 !important;
|
|
21
32
|
}
|
|
22
|
-
|
|
33
|
+
${selector} ul {
|
|
23
34
|
list-style-position: outside !important;
|
|
24
35
|
padding-inline-start: 1.5rem !important;
|
|
25
36
|
}
|
|
26
|
-
|
|
37
|
+
${selector} ul:not([style*="list-style-type"]) {
|
|
27
38
|
list-style-type: disc !important;
|
|
28
39
|
}
|
|
29
|
-
|
|
40
|
+
${selector} ol {
|
|
30
41
|
list-style-position: outside !important;
|
|
31
42
|
padding-inline-start: 1.5rem !important;
|
|
32
43
|
}
|
|
33
|
-
|
|
44
|
+
${selector} ol:not([style*="list-style-type"]) {
|
|
34
45
|
list-style-type: decimal !important;
|
|
35
46
|
}
|
|
36
|
-
|
|
47
|
+
${selector} li {
|
|
37
48
|
display: list-item !important;
|
|
38
49
|
}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
const SLIDE_RENDERER_STYLES = `
|
|
53
|
+
${createTextProseStyles('.slide-renderer-prose')}
|
|
39
54
|
/* Table cell inner container — matches the classroom (Vue) .cell-text design:
|
|
40
55
|
tight base line-height, and a small spacing between adjacent <p> siblings
|
|
41
56
|
so multi-paragraph cells don't collapse into a single visual block. The
|
|
@@ -62,5 +77,5 @@ const SLIDE_RENDERER_STYLES = `
|
|
|
62
77
|
}
|
|
63
78
|
`;
|
|
64
79
|
|
|
65
|
-
export { SLIDE_RENDERER_STYLES };
|
|
80
|
+
export { SLIDE_RENDERER_STYLES, createTextProseStyles };
|
|
66
81
|
//# sourceMappingURL=styles.js.map
|
package/dist/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sources":["../src/styles.ts"],"sourcesContent":["/**\n * Package-level CSS rules that can't be expressed inline (descendant selectors,\n * keyframes, pseudo-classes). Rendered once via `<style>` at the top of\n * `<SlideCanvas>` so the package stays self-contained without Tailwind.\n *\n * The `.slide-renderer-prose` rules undo host and user-agent defaults so the\n * slide JSON is the single source of truth. Paragraph spacing comes from the\n * `--paragraphSpace` CSS variable. List rules restore semantic markers that\n * host resets such as Tailwind Preflight remove.\n */\nexport
|
|
1
|
+
{"version":3,"file":"styles.js","sources":["../src/styles.ts"],"sourcesContent":["/**\n * Package-level CSS rules that can't be expressed inline (descendant selectors,\n * keyframes, pseudo-classes). Rendered once via `<style>` at the top of\n * `<SlideCanvas>` so the package stays self-contained without Tailwind.\n *\n * The `.slide-renderer-prose` rules undo host and user-agent defaults so the\n * slide JSON is the single source of truth. Paragraph spacing comes from the\n * `--paragraphSpace` CSS variable. List rules restore semantic markers that\n * host resets such as Tailwind Preflight remove.\n */\n/**\n * Generates the reset rules that define rich-text geometry inside a slide.\n *\n * Both the static renderer and the ProseMirror editor need these exact rules:\n * keeping the selector configurable lets them share one layout contract while\n * retaining their different DOM roots.\n */\nexport function createTextProseStyles(selector: string): string {\n return `\n${selector} p {\n margin-top: 0;\n margin-bottom: var(--paragraphSpace, 0);\n}\n${selector} p:last-child {\n margin-bottom: 0;\n}\n${selector} p:empty::before {\n content: '\\\\00a0';\n}\n${selector} .katex-display {\n margin: 0 !important;\n}\n${selector} ul {\n list-style-position: outside !important;\n padding-inline-start: 1.5rem !important;\n}\n${selector} ul:not([style*=\"list-style-type\"]) {\n list-style-type: disc !important;\n}\n${selector} ol {\n list-style-position: outside !important;\n padding-inline-start: 1.5rem !important;\n}\n${selector} ol:not([style*=\"list-style-type\"]) {\n list-style-type: decimal !important;\n}\n${selector} li {\n display: list-item !important;\n}\n`;\n}\n\nexport const SLIDE_RENDERER_STYLES = `\n${createTextProseStyles('.slide-renderer-prose')}\n/* Table cell inner container — matches the classroom (Vue) .cell-text design:\n tight base line-height, and a small spacing between adjacent <p> siblings\n so multi-paragraph cells don't collapse into a single visual block. The\n <p> margin reset above sets the baseline to 0; this rule re-adds spacing\n only between adjacent siblings, leaving the first/last paragraph flush. */\n.slide-renderer-cell-text p + p {\n margin-top: 0.4em;\n}\n@keyframes slide-renderer-pulse {\n 50% { opacity: 0.5; }\n}\n@keyframes slide-renderer-ping {\n 75%, 100% { transform: scale(2); opacity: 0; }\n}\n@keyframes slide-renderer-code-cursor-blink {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0; }\n}\n.slide-renderer-pulse {\n animation: slide-renderer-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;\n}\n.slide-renderer-ping {\n animation: slide-renderer-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;\n}\n`;\n"],"names":[],"mappings":"AAAA;;;;;;;;;AASG;AACH;;;;;;AAMG;AACG,SAAU,qBAAqB,CAAC,QAAgB,EAAA;IACpD,OAAO;EACP,QAAQ,CAAA;;;;EAIR,QAAQ,CAAA;;;EAGR,QAAQ,CAAA;;;EAGR,QAAQ,CAAA;;;EAGR,QAAQ,CAAA;;;;EAIR,QAAQ,CAAA;;;EAGR,QAAQ,CAAA;;;;EAIR,QAAQ,CAAA;;;EAGR,QAAQ,CAAA;;;CAGT;AACD;AAEO,MAAM,qBAAqB,GAAG;EACnC,qBAAqB,CAAC,uBAAuB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function preservesPlainTextLineBreaks(content: string): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `content` is an HTML-string contract. Only markup-free values can safely use
|
|
3
|
+
* `white-space: pre-line`: a newline between rich HTML block tags is source
|
|
4
|
+
* formatting, not visible slide content.
|
|
5
|
+
*/
|
|
6
|
+
const HTML_MARKUP_PATTERN = /<\/?[a-z][^>]*>|<![^>]*>/i;
|
|
7
|
+
function preservesPlainTextLineBreaks(content) {
|
|
8
|
+
return !HTML_MARKUP_PATTERN.test(content);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { preservesPlainTextLineBreaks };
|
|
12
|
+
//# sourceMappingURL=richText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"richText.js","sources":["../../src/utils/richText.ts"],"sourcesContent":["/**\n * `content` is an HTML-string contract. Only markup-free values can safely use\n * `white-space: pre-line`: a newline between rich HTML block tags is source\n * formatting, not visible slide content.\n */\nconst HTML_MARKUP_PATTERN = /<\\/?[a-z][^>]*>|<![^>]*>/i;\n\nexport function preservesPlainTextLineBreaks(content: string): boolean {\n return !HTML_MARKUP_PATTERN.test(content);\n}\n"],"names":[],"mappings":"AAAA;;;;AAIG;AACH,MAAM,mBAAmB,GAAG,2BAA2B;AAEjD,SAAU,4BAA4B,CAAC,OAAe,EAAA;AAC1D,IAAA,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC;AAC3C;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmaic/renderer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "React component for rendering PPTist-style Slide JSON, extracted from OpenMAIC.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"lucide-react": "^0.562.0",
|
|
76
76
|
"tailwind-merge": "^3.4.0",
|
|
77
77
|
"tinycolor2": "^1.6.0",
|
|
78
|
-
"@openmaic/dsl": "^0.
|
|
78
|
+
"@openmaic/dsl": "^0.9.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@rollup/plugin-commonjs": "^28.0.1",
|