@openmaic/renderer 0.0.3 → 0.0.5

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.
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useRef, useState, useMemo, useEffect } from 'react';
3
+ import { useRef, useState, useId, useMemo, useEffect } from 'react';
4
4
  import { getLineElementPath } from '../../utils/element.js';
5
5
  import { useElementShadow } from '../shared/useElementShadow.js';
6
6
  import { LinePointMarker } from './LinePointMarker.js';
@@ -10,6 +10,7 @@ function BaseLineElement({ elementInfo, animate }) {
10
10
  const { shadowStyle } = useElementShadow(elementInfo.shadow);
11
11
  const pathRef = useRef(null);
12
12
  const [drawComplete, setDrawComplete] = useState(!animate);
13
+ const markerId = `${elementInfo.id}-${useId().replaceAll(':', '')}`;
13
14
  const svgWidth = useMemo(() => {
14
15
  const width = Math.abs(elementInfo.start[0] - elementInfo.end[0]);
15
16
  return width < 24 ? 24 : width;
@@ -61,10 +62,10 @@ function BaseLineElement({ elementInfo, animate }) {
61
62
  width: '100%',
62
63
  height: '100%',
63
64
  filter: shadowStyle ? `drop-shadow(${shadowStyle})` : '',
64
- }, children: jsxs("svg", { overflow: "visible", width: svgWidth, height: svgHeight, style: { transformOrigin: '0 0', overflow: 'visible' }, children: [jsxs("defs", { children: [elementInfo.points[0] && (jsx(LinePointMarker, { id: elementInfo.id, position: "start", type: elementInfo.points[0], color: elementInfo.color, baseSize: elementInfo.width })), elementInfo.points[1] && (jsx(LinePointMarker, { id: elementInfo.id, position: "end", type: elementInfo.points[1], color: elementInfo.color, baseSize: elementInfo.width }))] }), jsx("path", { ref: pathRef, d: path, stroke: elementInfo.color, strokeWidth: elementInfo.width, strokeDasharray: lineDashArray, fill: "none", markerStart: drawComplete && elementInfo.points[0]
65
- ? `url(#${elementInfo.id}-${elementInfo.points[0]}-start)`
65
+ }, children: jsxs("svg", { overflow: "visible", width: svgWidth, height: svgHeight, style: { transformOrigin: '0 0', overflow: 'visible' }, children: [jsxs("defs", { children: [elementInfo.points[0] && (jsx(LinePointMarker, { id: markerId, position: "start", type: elementInfo.points[0], color: elementInfo.color, baseSize: elementInfo.width })), elementInfo.points[1] && (jsx(LinePointMarker, { id: markerId, position: "end", type: elementInfo.points[1], color: elementInfo.color, baseSize: elementInfo.width }))] }), jsx("path", { ref: pathRef, d: path, stroke: elementInfo.color, strokeWidth: elementInfo.width, strokeDasharray: lineDashArray, fill: "none", markerStart: drawComplete && elementInfo.points[0]
66
+ ? `url(#${markerId}-${elementInfo.points[0]}-start)`
66
67
  : '', markerEnd: drawComplete && elementInfo.points[1]
67
- ? `url(#${elementInfo.id}-${elementInfo.points[1]}-end)`
68
+ ? `url(#${markerId}-${elementInfo.points[1]}-end)`
68
69
  : '' })] }) }) }));
69
70
  }
70
71
 
@@ -1 +1 @@
1
- {"version":3,"file":"BaseLineElement.js","sources":["../../../src/elements/line/BaseLineElement.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo, useRef, useState, useEffect } from 'react';\nimport type { PPTLineElement } from '@openmaic/dsl';\nimport { getLineElementPath } from '../../utils/element';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { LinePointMarker } from './LinePointMarker';\n\nexport interface BaseLineElementProps {\n elementInfo: PPTLineElement;\n animate?: boolean;\n}\n\nconst DRAW_ANIMATION_MS = 600;\n\nexport function BaseLineElement({ elementInfo, animate }: BaseLineElementProps) {\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const pathRef = useRef<SVGPathElement>(null);\n const [drawComplete, setDrawComplete] = useState(!animate);\n\n const svgWidth = useMemo(() => {\n const width = Math.abs(elementInfo.start[0] - elementInfo.end[0]);\n return width < 24 ? 24 : width;\n }, [elementInfo.start, elementInfo.end]);\n\n const svgHeight = useMemo(() => {\n const height = Math.abs(elementInfo.start[1] - elementInfo.end[1]);\n return height < 24 ? 24 : height;\n }, [elementInfo.start, elementInfo.end]);\n\n const lineDashArray = useMemo(() => {\n const size = elementInfo.width;\n if (elementInfo.style === 'dashed')\n return size <= 8 ? `${size * 5} ${size * 2.5}` : `${size * 5} ${size * 1.5}`;\n if (elementInfo.style === 'dotted')\n return size <= 8 ? `${size * 1.8} ${size * 1.6}` : `${size * 1.5} ${size * 1.2}`;\n return '0 0';\n }, [elementInfo.width, elementInfo.style]);\n\n const path = useMemo(() => getLineElementPath(elementInfo), [elementInfo]);\n\n useEffect(() => {\n if (!animate) return;\n const pathEl = pathRef.current;\n if (!pathEl) return;\n\n const length = pathEl.getTotalLength();\n if (length === 0) {\n const t = setTimeout(() => setDrawComplete(true), 0);\n return () => clearTimeout(t);\n }\n\n pathEl.style.strokeDasharray = `${length}`;\n pathEl.style.strokeDashoffset = `${length}`;\n pathEl.style.transition = 'none';\n pathEl.getBoundingClientRect();\n pathEl.style.transition = `stroke-dashoffset ${DRAW_ANIMATION_MS}ms ease-out`;\n pathEl.style.strokeDashoffset = '0';\n\n const timer = setTimeout(() => {\n pathEl.style.transition = 'none';\n pathEl.style.strokeDasharray = '';\n pathEl.style.strokeDashoffset = '';\n setDrawComplete(true);\n }, DRAW_ANIMATION_MS + 50);\n\n return () => clearTimeout(timer);\n }, [animate]);\n\n return (\n <div\n className=\"base-element-line\"\n style={{\n position: 'absolute',\n top: `${elementInfo.top}px`,\n left: `${elementInfo.left}px`,\n }}\n >\n <div\n className=\"element-content\"\n style={{\n position: 'relative',\n width: '100%',\n height: '100%',\n filter: shadowStyle ? `drop-shadow(${shadowStyle})` : '',\n }}\n >\n <svg\n overflow=\"visible\"\n width={svgWidth}\n height={svgHeight}\n style={{ transformOrigin: '0 0', overflow: 'visible' }}\n >\n <defs>\n {elementInfo.points[0] && (\n <LinePointMarker\n id={elementInfo.id}\n position=\"start\"\n type={elementInfo.points[0]}\n color={elementInfo.color}\n baseSize={elementInfo.width}\n />\n )}\n {elementInfo.points[1] && (\n <LinePointMarker\n id={elementInfo.id}\n position=\"end\"\n type={elementInfo.points[1]}\n color={elementInfo.color}\n baseSize={elementInfo.width}\n />\n )}\n </defs>\n <path\n ref={pathRef}\n d={path}\n stroke={elementInfo.color}\n strokeWidth={elementInfo.width}\n strokeDasharray={lineDashArray}\n fill=\"none\"\n markerStart={\n drawComplete && elementInfo.points[0]\n ? `url(#${elementInfo.id}-${elementInfo.points[0]}-start)`\n : ''\n }\n markerEnd={\n drawComplete && elementInfo.points[1]\n ? `url(#${elementInfo.id}-${elementInfo.points[1]}-end)`\n : ''\n }\n />\n </svg>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;AAaA;;;AAIE;;AAGA;;;;AAKA;;;;AAKA;AACE;AACA;;AAEA;;AAEA;;AAGF;;AAGE;;AACA;AACA;;AAEA;AACA;AACE;AACA;;;;AAKF;;;AAGA;AAEA;AACE;AACA;AACA;;AAEF;AAEA;AACF;AAEA;AAIM;AACA;AACA;AACD;AAKG;AACA;AACA;;AAED;AAqCO;AACA;AAIA;AACA;AAOhB;;"}
1
+ {"version":3,"file":"BaseLineElement.js","sources":["../../../src/elements/line/BaseLineElement.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo, useRef, useState, useEffect, useId } from 'react';\nimport type { PPTLineElement } from '@openmaic/dsl';\nimport { getLineElementPath } from '../../utils/element';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { LinePointMarker } from './LinePointMarker';\n\nexport interface BaseLineElementProps {\n elementInfo: PPTLineElement;\n animate?: boolean;\n}\n\nconst DRAW_ANIMATION_MS = 600;\n\nexport function BaseLineElement({ elementInfo, animate }: BaseLineElementProps) {\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const pathRef = useRef<SVGPathElement>(null);\n const [drawComplete, setDrawComplete] = useState(!animate);\n const markerId = `${elementInfo.id}-${useId().replaceAll(':', '')}`;\n\n const svgWidth = useMemo(() => {\n const width = Math.abs(elementInfo.start[0] - elementInfo.end[0]);\n return width < 24 ? 24 : width;\n }, [elementInfo.start, elementInfo.end]);\n\n const svgHeight = useMemo(() => {\n const height = Math.abs(elementInfo.start[1] - elementInfo.end[1]);\n return height < 24 ? 24 : height;\n }, [elementInfo.start, elementInfo.end]);\n\n const lineDashArray = useMemo(() => {\n const size = elementInfo.width;\n if (elementInfo.style === 'dashed')\n return size <= 8 ? `${size * 5} ${size * 2.5}` : `${size * 5} ${size * 1.5}`;\n if (elementInfo.style === 'dotted')\n return size <= 8 ? `${size * 1.8} ${size * 1.6}` : `${size * 1.5} ${size * 1.2}`;\n return '0 0';\n }, [elementInfo.width, elementInfo.style]);\n\n const path = useMemo(() => getLineElementPath(elementInfo), [elementInfo]);\n\n useEffect(() => {\n if (!animate) return;\n const pathEl = pathRef.current;\n if (!pathEl) return;\n\n const length = pathEl.getTotalLength();\n if (length === 0) {\n const t = setTimeout(() => setDrawComplete(true), 0);\n return () => clearTimeout(t);\n }\n\n pathEl.style.strokeDasharray = `${length}`;\n pathEl.style.strokeDashoffset = `${length}`;\n pathEl.style.transition = 'none';\n pathEl.getBoundingClientRect();\n pathEl.style.transition = `stroke-dashoffset ${DRAW_ANIMATION_MS}ms ease-out`;\n pathEl.style.strokeDashoffset = '0';\n\n const timer = setTimeout(() => {\n pathEl.style.transition = 'none';\n pathEl.style.strokeDasharray = '';\n pathEl.style.strokeDashoffset = '';\n setDrawComplete(true);\n }, DRAW_ANIMATION_MS + 50);\n\n return () => clearTimeout(timer);\n }, [animate]);\n\n return (\n <div\n className=\"base-element-line\"\n style={{\n position: 'absolute',\n top: `${elementInfo.top}px`,\n left: `${elementInfo.left}px`,\n }}\n >\n <div\n className=\"element-content\"\n style={{\n position: 'relative',\n width: '100%',\n height: '100%',\n filter: shadowStyle ? `drop-shadow(${shadowStyle})` : '',\n }}\n >\n <svg\n overflow=\"visible\"\n width={svgWidth}\n height={svgHeight}\n style={{ transformOrigin: '0 0', overflow: 'visible' }}\n >\n <defs>\n {elementInfo.points[0] && (\n <LinePointMarker\n id={markerId}\n position=\"start\"\n type={elementInfo.points[0]}\n color={elementInfo.color}\n baseSize={elementInfo.width}\n />\n )}\n {elementInfo.points[1] && (\n <LinePointMarker\n id={markerId}\n position=\"end\"\n type={elementInfo.points[1]}\n color={elementInfo.color}\n baseSize={elementInfo.width}\n />\n )}\n </defs>\n <path\n ref={pathRef}\n d={path}\n stroke={elementInfo.color}\n strokeWidth={elementInfo.width}\n strokeDasharray={lineDashArray}\n fill=\"none\"\n markerStart={\n drawComplete && elementInfo.points[0]\n ? `url(#${markerId}-${elementInfo.points[0]}-start)`\n : ''\n }\n markerEnd={\n drawComplete && elementInfo.points[1]\n ? `url(#${markerId}-${elementInfo.points[1]}-end)`\n : ''\n }\n />\n </svg>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;AAaA;;;AAIE;;AAEA;AAEA;;;;AAKA;;;;AAKA;AACE;AACA;;AAEA;;AAEA;;AAGF;;AAGE;;AACA;AACA;;AAEA;AACA;AACE;AACA;;;;AAKF;;;AAGA;AAEA;AACE;AACA;AACA;;AAEF;AAEA;AACF;AAEA;AAIM;AACA;AACA;AACD;AAKG;AACA;AACA;;AAED;;AAsCO;;AAKA;AAOhB;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmaic/renderer",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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,7 @@
79
79
  "lucide-react": "^0.562.0",
80
80
  "tailwind-merge": "^3.4.0",
81
81
  "tinycolor2": "^1.6.0",
82
- "@openmaic/dsl": "0.4.0"
82
+ "@openmaic/dsl": "^0.6.2"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@rollup/plugin-commonjs": "^28.0.1",