@openmaic/renderer 0.2.2 → 0.2.4
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/context.d.ts +2 -0
- package/dist/context.js.map +1 -1
- package/dist/effects/SpotlightOverlay.js +2 -12
- package/dist/effects/SpotlightOverlay.js.map +1 -1
- package/dist/elements/image/BaseImageElement.js +3 -1
- package/dist/elements/image/BaseImageElement.js.map +1 -1
- package/dist/elements/latex/BaseLatexElement.js +7 -8
- package/dist/elements/latex/BaseLatexElement.js.map +1 -1
- package/dist/elements/text/BaseTextElement.js +4 -2
- 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/utils/spotlight-rect.d.ts +7 -0
- package/dist/utils/spotlight-rect.js +51 -0
- package/dist/utils/spotlight-rect.js.map +1 -0
- package/package.json +3 -3
package/dist/context.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { SlideEffects } from './types/effects';
|
|
|
4
4
|
export interface SlideContextValue {
|
|
5
5
|
slide: Slide;
|
|
6
6
|
scale?: number;
|
|
7
|
+
/** Preserve the text, formula, and image sizing used by existing classroom slides. */
|
|
8
|
+
classroomSizing?: boolean;
|
|
7
9
|
background?: SlideBackground;
|
|
8
10
|
effects?: SlideEffects;
|
|
9
11
|
renderImage?: (element: PPTImageElement, resolvedSrc: string, defaultContent: ReactNode) => ReactNode;
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../src/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext, type CSSProperties, type ReactNode } from 'react';\nimport type {\n PPTElement,\n PPTImageElement,\n PPTVideoElement,\n Slide,\n SlideBackground,\n} from '@openmaic/dsl';\nimport type { SlideEffects } from './types/effects';\n\nexport interface SlideContextValue {\n slide: Slide;\n scale?: number;\n background?: SlideBackground;\n effects?: SlideEffects;\n renderImage?: (\n element: PPTImageElement,\n resolvedSrc: string,\n defaultContent: ReactNode,\n ) => ReactNode;\n renderVideo?: (element: PPTVideoElement) => ReactNode;\n videoInteractive?: boolean;\n onElementClick?: (element: PPTElement, event: React.MouseEvent) => void;\n}\n\nconst SlideContext = createContext<SlideContextValue | null>(null);\n\nexport interface SlideRendererProviderProps extends SlideContextValue {\n children?: ReactNode;\n className?: string;\n style?: CSSProperties;\n}\n\nexport function SlideRendererProvider({\n children,\n className,\n style,\n ...value\n}: SlideRendererProviderProps) {\n return (\n <SlideContext.Provider value={value}>\n {className || style ? (\n <div className={className} style={style}>\n {children}\n </div>\n ) : (\n children\n )}\n </SlideContext.Provider>\n );\n}\n\n/**\n * Read the closest SlideRendererProvider value.\n * Throws if used outside a provider — use `useOptionalSlideContext` for nullable access.\n */\nexport function useSlideContext(): SlideContextValue {\n const value = useContext(SlideContext);\n if (!value) {\n throw new Error(\n 'useSlideContext must be used inside a <SlideRendererProvider>. ' +\n 'Pass props directly to <SlideCanvas> if you do not need the provider.',\n );\n }\n return value;\n}\n\n/** Nullable variant; returns null when outside a provider. */\nexport function useOptionalSlideContext(): SlideContextValue | null {\n return useContext(SlideContext);\n}\n"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext, type CSSProperties, type ReactNode } from 'react';\nimport type {\n PPTElement,\n PPTImageElement,\n PPTVideoElement,\n Slide,\n SlideBackground,\n} from '@openmaic/dsl';\nimport type { SlideEffects } from './types/effects';\n\nexport interface SlideContextValue {\n slide: Slide;\n scale?: number;\n /** Preserve the text, formula, and image sizing used by existing classroom slides. */\n classroomSizing?: boolean;\n background?: SlideBackground;\n effects?: SlideEffects;\n renderImage?: (\n element: PPTImageElement,\n resolvedSrc: string,\n defaultContent: ReactNode,\n ) => ReactNode;\n renderVideo?: (element: PPTVideoElement) => ReactNode;\n videoInteractive?: boolean;\n onElementClick?: (element: PPTElement, event: React.MouseEvent) => void;\n}\n\nconst SlideContext = createContext<SlideContextValue | null>(null);\n\nexport interface SlideRendererProviderProps extends SlideContextValue {\n children?: ReactNode;\n className?: string;\n style?: CSSProperties;\n}\n\nexport function SlideRendererProvider({\n children,\n className,\n style,\n ...value\n}: SlideRendererProviderProps) {\n return (\n <SlideContext.Provider value={value}>\n {className || style ? (\n <div className={className} style={style}>\n {children}\n </div>\n ) : (\n children\n )}\n </SlideContext.Provider>\n );\n}\n\n/**\n * Read the closest SlideRendererProvider value.\n * Throws if used outside a provider — use `useOptionalSlideContext` for nullable access.\n */\nexport function useSlideContext(): SlideContextValue {\n const value = useContext(SlideContext);\n if (!value) {\n throw new Error(\n 'useSlideContext must be used inside a <SlideRendererProvider>. ' +\n 'Pass props directly to <SlideCanvas> if you do not need the provider.',\n );\n }\n return value;\n}\n\n/** Nullable variant; returns null when outside a provider. */\nexport function useOptionalSlideContext(): SlideContextValue | null {\n return useContext(SlideContext);\n}\n"],"names":[],"mappings":";;;;AA6BA;AAQM;AAMJ;AAWF;AAEA;;;AAGG;;AAED;;;AAIM;;AAGN;AACF;AAEA;;AAEE;AACF;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { useRef, useState, useCallback, useLayoutEffect } from 'react';
|
|
4
|
+
import { measureSpotlightRect } from '../utils/spotlight-rect.js';
|
|
4
5
|
import { AnimatePresence, motion } from 'motion/react';
|
|
5
6
|
|
|
6
7
|
function SpotlightOverlay({ options, elementIdPrefix = 'slide-element-', measurementKey, }) {
|
|
@@ -19,18 +20,7 @@ function SpotlightOverlay({ options, elementIdPrefix = 'slide-element-', measure
|
|
|
19
20
|
}
|
|
20
21
|
const contentEl = domElement.querySelector('.element-content');
|
|
21
22
|
const targetEl = contentEl ?? domElement;
|
|
22
|
-
|
|
23
|
-
const targetRect = targetEl.getBoundingClientRect();
|
|
24
|
-
if (containerRect.width === 0 || containerRect.height === 0) {
|
|
25
|
-
setRect(null);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
setRect({
|
|
29
|
-
x: ((targetRect.left - containerRect.left) / containerRect.width) * 100,
|
|
30
|
-
y: ((targetRect.top - containerRect.top) / containerRect.height) * 100,
|
|
31
|
-
w: (targetRect.width / containerRect.width) * 100,
|
|
32
|
-
h: (targetRect.height / containerRect.height) * 100,
|
|
33
|
-
});
|
|
23
|
+
setRect(measureSpotlightRect(containerRef.current, targetEl));
|
|
34
24
|
}, [spotlightElementId, elementIdPrefix]);
|
|
35
25
|
useLayoutEffect(() => {
|
|
36
26
|
// eslint-disable-next-line react-hooks/set-state-in-effect -- DOM measurement requires effect
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpotlightOverlay.js","sources":["../../src/effects/SpotlightOverlay.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState, useLayoutEffect, useCallback } from 'react';\nimport { motion, AnimatePresence } from 'motion/react';\nimport type { SpotlightEffectOptions } from '../types/effects';\n\ninterface SpotlightRect {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\nexport interface SpotlightOverlayProps {\n options?: SpotlightEffectOptions;\n /** ID prefix the SlideElement uses on its root div. Default `slide-element-`. */\n elementIdPrefix?: string;\n /** Remeasure when host element data changes without changing the target ID. */\n measurementKey?: unknown;\n}\n\nexport function SpotlightOverlay({\n options,\n elementIdPrefix = 'slide-element-',\n measurementKey,\n}: SpotlightOverlayProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [rect, setRect] = useState<SpotlightRect | null>(null);\n\n const spotlightElementId = options?.elementId;\n\n const measure = useCallback(() => {\n if (!spotlightElementId || !containerRef.current) {\n setRect(null);\n return;\n }\n\n const domElement = document.getElementById(`${elementIdPrefix}${spotlightElementId}`);\n if (!domElement) {\n setRect(null);\n return;\n }\n\n const contentEl = domElement.querySelector('.element-content');\n const targetEl = contentEl ?? domElement;\n\n
|
|
1
|
+
{"version":3,"file":"SpotlightOverlay.js","sources":["../../src/effects/SpotlightOverlay.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState, useLayoutEffect, useCallback } from 'react';\nimport { measureSpotlightRect } from '../utils/spotlight-rect';\nimport { motion, AnimatePresence } from 'motion/react';\nimport type { SpotlightEffectOptions } from '../types/effects';\n\ninterface SpotlightRect {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\nexport interface SpotlightOverlayProps {\n options?: SpotlightEffectOptions;\n /** ID prefix the SlideElement uses on its root div. Default `slide-element-`. */\n elementIdPrefix?: string;\n /** Remeasure when host element data changes without changing the target ID. */\n measurementKey?: unknown;\n}\n\nexport function SpotlightOverlay({\n options,\n elementIdPrefix = 'slide-element-',\n measurementKey,\n}: SpotlightOverlayProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [rect, setRect] = useState<SpotlightRect | null>(null);\n\n const spotlightElementId = options?.elementId;\n\n const measure = useCallback(() => {\n if (!spotlightElementId || !containerRef.current) {\n setRect(null);\n return;\n }\n\n const domElement = document.getElementById(`${elementIdPrefix}${spotlightElementId}`);\n if (!domElement) {\n setRect(null);\n return;\n }\n\n const contentEl = domElement.querySelector('.element-content');\n const targetEl = contentEl ?? domElement;\n\n setRect(measureSpotlightRect(containerRef.current, targetEl));\n }, [spotlightElementId, elementIdPrefix]);\n\n useLayoutEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- DOM measurement requires effect\n measure();\n\n const container = containerRef.current;\n if (!container || !spotlightElementId) return;\n\n const root = document.getElementById(`${elementIdPrefix}${spotlightElementId}`);\n const target = root?.querySelector('.element-content') ?? root;\n if (!target) return;\n\n const observer = new ResizeObserver(measure);\n observer.observe(container);\n observer.observe(target);\n\n const media = target.querySelectorAll('img, video');\n media.forEach((element) => {\n element.addEventListener('load', measure);\n element.addEventListener('loadedmetadata', measure);\n });\n\n return () => {\n observer.disconnect();\n media.forEach((element) => {\n element.removeEventListener('load', measure);\n element.removeEventListener('loadedmetadata', measure);\n });\n };\n }, [measure, measurementKey, spotlightElementId, elementIdPrefix]);\n\n const active = !!spotlightElementId && !!rect;\n const dimness = options?.dimness ?? 0.7;\n\n return (\n <div\n ref={containerRef}\n style={{\n position: 'absolute',\n inset: 0,\n zIndex: 100,\n pointerEvents: 'none',\n overflow: 'hidden',\n }}\n >\n <AnimatePresence mode=\"wait\">\n {active && rect && (\n <motion.div\n key={`spotlight-${spotlightElementId}`}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n style={{ position: 'absolute', inset: 0 }}\n >\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox=\"0 0 100 100\"\n preserveAspectRatio=\"none\"\n style={{ position: 'absolute', inset: 0 }}\n >\n <defs>\n <mask id={`mask-${spotlightElementId}`}>\n <rect x=\"0\" y=\"0\" width=\"100\" height=\"100\" fill=\"white\" />\n <motion.rect\n fill=\"black\"\n initial={{\n x: rect.x - 8,\n y: rect.y - 8,\n width: rect.w + 16,\n height: rect.h + 16,\n rx: 4,\n }}\n animate={{\n x: rect.x - 0.4,\n y: rect.y - 0.6,\n width: rect.w + 0.8,\n height: rect.h + 1.2,\n rx: 1,\n }}\n transition={{ duration: 0.6, ease: [0.16, 1, 0.3, 1] }}\n />\n </mask>\n </defs>\n\n <rect\n width=\"100\"\n height=\"100\"\n fill={`rgba(0,0,0,${dimness})`}\n mask={`url(#mask-${spotlightElementId})`}\n />\n\n <motion.rect\n initial={{\n x: rect.x - 4,\n y: rect.y - 4,\n width: rect.w + 8,\n height: rect.h + 8,\n opacity: 0,\n rx: 2,\n }}\n animate={{\n x: rect.x - 0.4,\n y: rect.y - 0.6,\n width: rect.w + 0.8,\n height: rect.h + 1.2,\n opacity: 1,\n rx: 1,\n }}\n fill=\"none\"\n stroke=\"rgba(255,255,255,0.7)\"\n strokeWidth=\"1.2\"\n style={{ vectorEffect: 'non-scaling-stroke' } as React.CSSProperties}\n transition={{ duration: 0.5, delay: 0.05, ease: [0.16, 1, 0.3, 1] }}\n />\n </svg>\n </motion.div>\n )}\n </AnimatePresence>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAsBM;AAKJ;;AAGA;AAEA;;;;;AAME;;;;;;AAOA;;AAGF;;;AAIE;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAGA;AACE;AACA;AACF;AAEA;;AAEE;AACE;AACA;AACF;AACF;;;AAIF;AAEA;AAIM;AACA;AACA;AACA;AACA;;AAyBc;AACA;AACA;AACA;AACA;AACD;AAEC;AACA;AACA;AACA;AACA;;AAgBJ;AACA;AACA;AACA;AACA;AACA;AACD;AAEC;AACA;AACA;AACA;AACA;AACA;;AAclB;;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { useElementShadow } from '../shared/useElementShadow.js';
|
|
4
4
|
import { useElementFlip } from '../shared/useElementFlip.js';
|
|
5
|
+
import { useOptionalSlideContext } from '../../context.js';
|
|
5
6
|
import { useClipImage } from './useClipImage.js';
|
|
6
7
|
import { useFilter } from './useFilter.js';
|
|
7
8
|
import { ImageOutline } from './ImageOutline.js';
|
|
@@ -12,6 +13,7 @@ function BaseImageElement({ elementInfo, renderImage }) {
|
|
|
12
13
|
const { clipShape, imgPosition } = useClipImage(elementInfo);
|
|
13
14
|
const { filter } = useFilter(elementInfo.filters);
|
|
14
15
|
const src = elementInfo.src;
|
|
16
|
+
const classroomSizing = useOptionalSlideContext()?.classroomSizing;
|
|
15
17
|
// Soft-edge feather (a:softEdge): fade the image alpha to transparent over
|
|
16
18
|
// `softEdge` px at every edge. Two intersecting linear-gradient masks feather
|
|
17
19
|
// all four sides (corners get both). html2canvas-pro ignores CSS masks, so
|
|
@@ -42,7 +44,7 @@ function BaseImageElement({ elementInfo, renderImage }) {
|
|
|
42
44
|
left: imgPosition.left,
|
|
43
45
|
width: imgPosition.width,
|
|
44
46
|
height: imgPosition.height,
|
|
45
|
-
maxWidth: 'none',
|
|
47
|
+
maxWidth: classroomSizing ? '100%' : 'none',
|
|
46
48
|
maxHeight: 'none',
|
|
47
49
|
filter,
|
|
48
50
|
...softEdgeMaskStyle,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseImageElement.js","sources":["../../../src/elements/image/BaseImageElement.tsx"],"sourcesContent":["'use client';\n\nimport type { CSSProperties, ReactNode } from 'react';\nimport type { PPTImageElement } from '@openmaic/dsl';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { useElementFlip } from '../shared/useElementFlip';\nimport { useClipImage } from './useClipImage';\nimport { useFilter } from './useFilter';\nimport { ImageOutline } from './ImageOutline';\n\nexport interface BaseImageElementProps {\n elementInfo: PPTImageElement;\n /**\n * Optional render slot: replace the default <img> with custom content.\n * The slot receives `(element, resolvedSrc, defaultContent)` and is responsible\n * for selecting placeholders, retry UI, or the renderer's prepared image.\n * Its return value is authoritative, including `null`.\n */\n renderImage?: (\n element: PPTImageElement,\n resolvedSrc: string,\n defaultContent: ReactNode,\n ) => ReactNode;\n}\n\nexport function BaseImageElement({ elementInfo, renderImage }: BaseImageElementProps) {\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const { flipStyle } = useElementFlip(elementInfo.flipH, elementInfo.flipV);\n const { clipShape, imgPosition } = useClipImage(elementInfo);\n const { filter } = useFilter(elementInfo.filters);\n\n const src = elementInfo.src;\n\n // Soft-edge feather (a:softEdge): fade the image alpha to transparent over\n // `softEdge` px at every edge. Two intersecting linear-gradient masks feather\n // all four sides (corners get both). html2canvas-pro ignores CSS masks, so\n // slideToPng bakes the same feather into pixels via the data-soft-edge hook.\n const softEdge =\n elementInfo.softEdge && elementInfo.softEdge > 0 ? elementInfo.softEdge : undefined;\n const softEdgeMaskStyle: CSSProperties = softEdge\n ? (() => {\n const grad = (dir: string) =>\n `linear-gradient(${dir}, transparent 0, #000 ${softEdge}px, #000 calc(100% - ${softEdge}px), transparent 100%)`;\n const mask = `${grad('to right')}, ${grad('to bottom')}`;\n return {\n maskImage: mask,\n WebkitMaskImage: mask,\n maskComposite: 'intersect',\n WebkitMaskComposite: 'source-in',\n maskRepeat: 'no-repeat',\n WebkitMaskRepeat: 'no-repeat',\n } as CSSProperties;\n })()\n : {};\n const defaultContent = src ? (\n <>\n <img\n src={src}\n draggable={false}\n data-soft-edge={softEdge || undefined}\n // Lazy + async decode: thumbnail surfaces (sidebar, nav rail, course\n // cards) mount far more images than the viewport needs. In-viewport\n // images are unaffected — the browser fetches them immediately.\n // slideToPng forces these back to eager in its off-screen tree.\n loading=\"lazy\"\n decoding=\"async\"\n style={{\n position: 'absolute',\n top: imgPosition.top,\n left: imgPosition.left,\n width: imgPosition.width,\n height: imgPosition.height,\n maxWidth: 'none',\n maxHeight: 'none',\n filter,\n ...softEdgeMaskStyle,\n }}\n alt=\"\"\n onDragStart={(e) => e.preventDefault()}\n />\n {elementInfo.colorMask && (\n <div\n style={{\n position: 'absolute',\n inset: 0,\n backgroundColor: elementInfo.colorMask,\n }}\n />\n )}\n </>\n ) : null;\n\n return (\n <div\n className=\"base-element-image element-content\"\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 style={{\n width: '100%',\n height: '100%',\n transform: `rotate(${elementInfo.rotate}deg)`,\n }}\n >\n <div\n style={{\n position: 'relative',\n width: '100%',\n height: '100%',\n filter: shadowStyle ? `drop-shadow(${shadowStyle})` : '',\n transform: flipStyle,\n }}\n >\n <ImageOutline elementInfo={elementInfo} />\n\n <div\n style={{\n position: 'relative',\n width: '100%',\n height: '100%',\n overflow: 'hidden',\n clipPath: clipShape.style,\n pointerEvents: renderImage ? 'auto' : undefined,\n }}\n >\n {renderImage ? renderImage(elementInfo, src, defaultContent) : defaultContent}\n </div>\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseImageElement.js","sources":["../../../src/elements/image/BaseImageElement.tsx"],"sourcesContent":["'use client';\n\nimport type { CSSProperties, ReactNode } from 'react';\nimport type { PPTImageElement } from '@openmaic/dsl';\nimport { useElementShadow } from '../shared/useElementShadow';\nimport { useElementFlip } from '../shared/useElementFlip';\nimport { useOptionalSlideContext } from '../../context';\nimport { useClipImage } from './useClipImage';\nimport { useFilter } from './useFilter';\nimport { ImageOutline } from './ImageOutline';\n\nexport interface BaseImageElementProps {\n elementInfo: PPTImageElement;\n /**\n * Optional render slot: replace the default <img> with custom content.\n * The slot receives `(element, resolvedSrc, defaultContent)` and is responsible\n * for selecting placeholders, retry UI, or the renderer's prepared image.\n * Its return value is authoritative, including `null`.\n */\n renderImage?: (\n element: PPTImageElement,\n resolvedSrc: string,\n defaultContent: ReactNode,\n ) => ReactNode;\n}\n\nexport function BaseImageElement({ elementInfo, renderImage }: BaseImageElementProps) {\n const { shadowStyle } = useElementShadow(elementInfo.shadow);\n const { flipStyle } = useElementFlip(elementInfo.flipH, elementInfo.flipV);\n const { clipShape, imgPosition } = useClipImage(elementInfo);\n const { filter } = useFilter(elementInfo.filters);\n\n const src = elementInfo.src;\n const classroomSizing = useOptionalSlideContext()?.classroomSizing;\n\n // Soft-edge feather (a:softEdge): fade the image alpha to transparent over\n // `softEdge` px at every edge. Two intersecting linear-gradient masks feather\n // all four sides (corners get both). html2canvas-pro ignores CSS masks, so\n // slideToPng bakes the same feather into pixels via the data-soft-edge hook.\n const softEdge =\n elementInfo.softEdge && elementInfo.softEdge > 0 ? elementInfo.softEdge : undefined;\n const softEdgeMaskStyle: CSSProperties = softEdge\n ? (() => {\n const grad = (dir: string) =>\n `linear-gradient(${dir}, transparent 0, #000 ${softEdge}px, #000 calc(100% - ${softEdge}px), transparent 100%)`;\n const mask = `${grad('to right')}, ${grad('to bottom')}`;\n return {\n maskImage: mask,\n WebkitMaskImage: mask,\n maskComposite: 'intersect',\n WebkitMaskComposite: 'source-in',\n maskRepeat: 'no-repeat',\n WebkitMaskRepeat: 'no-repeat',\n } as CSSProperties;\n })()\n : {};\n const defaultContent = src ? (\n <>\n <img\n src={src}\n draggable={false}\n data-soft-edge={softEdge || undefined}\n // Lazy + async decode: thumbnail surfaces (sidebar, nav rail, course\n // cards) mount far more images than the viewport needs. In-viewport\n // images are unaffected — the browser fetches them immediately.\n // slideToPng forces these back to eager in its off-screen tree.\n loading=\"lazy\"\n decoding=\"async\"\n style={{\n position: 'absolute',\n top: imgPosition.top,\n left: imgPosition.left,\n width: imgPosition.width,\n height: imgPosition.height,\n maxWidth: classroomSizing ? '100%' : 'none',\n maxHeight: 'none',\n filter,\n ...softEdgeMaskStyle,\n }}\n alt=\"\"\n onDragStart={(e) => e.preventDefault()}\n />\n {elementInfo.colorMask && (\n <div\n style={{\n position: 'absolute',\n inset: 0,\n backgroundColor: elementInfo.colorMask,\n }}\n />\n )}\n </>\n ) : null;\n\n return (\n <div\n className=\"base-element-image element-content\"\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 style={{\n width: '100%',\n height: '100%',\n transform: `rotate(${elementInfo.rotate}deg)`,\n }}\n >\n <div\n style={{\n position: 'relative',\n width: '100%',\n height: '100%',\n filter: shadowStyle ? `drop-shadow(${shadowStyle})` : '',\n transform: flipStyle,\n }}\n >\n <ImageOutline elementInfo={elementInfo} />\n\n <div\n style={{\n position: 'relative',\n width: '100%',\n height: '100%',\n overflow: 'hidden',\n clipPath: clipShape.style,\n pointerEvents: renderImage ? 'auto' : undefined,\n }}\n >\n {renderImage ? renderImage(elementInfo, src, defaultContent) : defaultContent}\n </div>\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA4BE;;;AAIA;AACA;;;;;;;;AAUM;AAEA;;AAEE;AACA;AACA;AACA;AACA;AACA;;AAEJ;;AAEJ;;;;;;AAaQ;;;;;;AAMA;;AAEA;;AAQE;AACA;;AAED;AAMT;AAIM;AACA;AACA;AACA;AACA;;AAKE;AACA;AACA;;AAKE;AACA;AACA;;AAEA;;AAOE;AACA;AACA;AACA;;;;AAWd;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useRef,
|
|
3
|
+
import { useRef, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
4
|
+
import { useOptionalSlideContext } from '../../context.js';
|
|
4
5
|
|
|
5
6
|
function BaseLatexElement({ elementInfo }) {
|
|
6
7
|
return (jsx("div", { className: "base-element-latex", style: {
|
|
@@ -28,8 +29,8 @@ const ALIGN_MAP = {
|
|
|
28
29
|
right: 'flex-end',
|
|
29
30
|
};
|
|
30
31
|
function KatexContent({ html, width, height, align = 'center', }) {
|
|
32
|
+
const classroomSizing = useOptionalSlideContext()?.classroomSizing;
|
|
31
33
|
const innerRef = useRef(null);
|
|
32
|
-
const [scale, setScale] = useState(1);
|
|
33
34
|
// Measure the formula's natural size and shrink-to-fit its box. Extracted so
|
|
34
35
|
// it can run both synchronously on mount (useLayoutEffect) and again once the
|
|
35
36
|
// KaTeX fonts finish loading (useEffect below).
|
|
@@ -47,12 +48,10 @@ function KatexContent({ html, width, height, align = 'center', }) {
|
|
|
47
48
|
const naturalW = innerRef.current.scrollWidth;
|
|
48
49
|
const naturalH = innerRef.current.scrollHeight;
|
|
49
50
|
if (naturalW > 0 && naturalH > 0) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// would otherwise get scaled up to fill the box and render huge.
|
|
53
|
-
setScale(Math.min(width / naturalW, height / naturalH, 1));
|
|
51
|
+
const fit = Math.min(width / naturalW, height / naturalH);
|
|
52
|
+
innerRef.current.style.transform = `scale(${classroomSizing ? fit : Math.min(fit, 1)})`;
|
|
54
53
|
}
|
|
55
|
-
}, [width, height]);
|
|
54
|
+
}, [width, height, classroomSizing]);
|
|
56
55
|
useLayoutEffect(() => {
|
|
57
56
|
measure();
|
|
58
57
|
}, [measure, html]);
|
|
@@ -85,7 +84,7 @@ function KatexContent({ html, width, height, align = 'center', }) {
|
|
|
85
84
|
justifyContent: justify,
|
|
86
85
|
}, children: jsx("div", { ref: innerRef, className: "slide-renderer-prose", style: {
|
|
87
86
|
transformOrigin: origin,
|
|
88
|
-
transform:
|
|
87
|
+
transform: 'scale(1)',
|
|
89
88
|
whiteSpace: 'nowrap',
|
|
90
89
|
}, dangerouslySetInnerHTML: { __html: html } }) }));
|
|
91
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseLatexElement.js","sources":["../../../src/elements/latex/BaseLatexElement.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useRef,
|
|
1
|
+
{"version":3,"file":"BaseLatexElement.js","sources":["../../../src/elements/latex/BaseLatexElement.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useRef, useLayoutEffect } from 'react';\nimport { useOptionalSlideContext } from '../../context';\nimport type { PPTLatexElement } from '@openmaic/dsl';\n\nexport interface BaseLatexElementProps {\n elementInfo: PPTLatexElement;\n}\n\nexport function BaseLatexElement({ elementInfo }: BaseLatexElementProps) {\n return (\n <div\n className=\"base-element-latex\"\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 // KaTeX glyphs inherit `color`; apply the formula's resolved color\n // (e.g. 蓝色权重) so it isn't forced to the browser default.\n ...(elementInfo.color ? { color: elementInfo.color } : {}),\n }}\n >\n {elementInfo.html ? (\n <KatexContent\n html={elementInfo.html}\n width={elementInfo.width}\n height={elementInfo.height}\n align={elementInfo.align}\n />\n ) : elementInfo.path && elementInfo.viewBox ? (\n <svg\n overflow=\"visible\"\n width={elementInfo.width}\n height={elementInfo.height}\n stroke={elementInfo.color}\n strokeWidth={elementInfo.strokeWidth}\n fill=\"none\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n style={{ transformOrigin: '0 0', overflow: 'visible' }}\n >\n <g\n transform={`scale(${elementInfo.width / elementInfo.viewBox[0]}, ${\n elementInfo.height / elementInfo.viewBox[1]\n }) translate(0,0) matrix(1,0,0,1,0,0)`}\n >\n <path d={elementInfo.path} />\n </g>\n </svg>\n ) : null}\n </div>\n </div>\n </div>\n );\n}\n\nconst ALIGN_MAP = {\n left: 'flex-start',\n center: 'center',\n right: 'flex-end',\n} as const;\n\nfunction KatexContent({\n html,\n width,\n height,\n align = 'center',\n}: {\n html: string;\n width: number;\n height: number;\n align?: 'left' | 'center' | 'right';\n}) {\n const classroomSizing = useOptionalSlideContext()?.classroomSizing;\n const innerRef = useRef<HTMLDivElement>(null);\n\n // Measure the formula's natural size and shrink-to-fit its box. Extracted so\n // it can run both synchronously on mount (useLayoutEffect) and again once the\n // KaTeX fonts finish loading (useEffect below).\n //\n // KaTeX lays out large delimiters (\\left\\{, \\begin{cases}) using the metrics of\n // its `KaTeX_Size1`–`Size4` faces. Those woff2 files load asynchronously, so a\n // first measure on a cold export runs against the fallback font — the brace is\n // sized wrong and the piecewise body (`cases`) desynchronizes from it (the bug\n // reported as \"大括号后面的分段函数与大括号错位\"). Re-measuring after\n // `document.fonts.ready` snaps the scale back to the real glyph metrics before\n // the off-screen snapshot captures the frame.\n const measure = useCallback(() => {\n if (!innerRef.current) return;\n const naturalW = innerRef.current.scrollWidth;\n const naturalH = innerRef.current.scrollHeight;\n if (naturalW > 0 && naturalH > 0) {\n const fit = Math.min(width / naturalW, height / naturalH);\n innerRef.current.style.transform = `scale(${classroomSizing ? fit : Math.min(fit, 1)})`;\n }\n }, [width, height, classroomSizing]);\n\n useLayoutEffect(() => {\n measure();\n }, [measure, html]);\n\n useEffect(() => {\n const fonts = typeof document !== 'undefined' ? document.fonts : undefined;\n if (!fonts) return;\n let cancelled = false;\n // Re-measure once the font set settles (initial + any subsequent face that\n // finishes decoding), so the fit-scale reflects the real KaTeX_Size metrics.\n fonts.ready.then(() => {\n if (!cancelled) measure();\n });\n const onLoadingDone = () => measure();\n fonts.addEventListener?.('loadingdone', onLoadingDone);\n return () => {\n cancelled = true;\n fonts.removeEventListener?.('loadingdone', onLoadingDone);\n };\n }, [measure, html]);\n\n const justify = ALIGN_MAP[align];\n const origin =\n align === 'left' ? 'left center' : align === 'right' ? 'right center' : 'center center';\n\n return (\n <div\n style={{\n width,\n height,\n overflow: 'hidden',\n display: 'flex',\n alignItems: 'center',\n justifyContent: justify,\n }}\n >\n <div\n ref={innerRef}\n className=\"slide-renderer-prose\"\n style={{\n transformOrigin: origin,\n transform: 'scale(1)',\n whiteSpace: 'nowrap',\n }}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;AAUM;AACJ;AAIM;AACA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;AACD;AAKG;AACA;AACA;;;AAGA;AACD;AAkCX;AAEA;AACE;AACA;AACA;;AAGF;AAWE;AACA;;;;;;;;;;;;AAaA;;;AAEE;AACA;;AAEE;;;;;AAMF;AACF;;AAGE;AACA;;;;;AAIA;AACE;AAAgB;AAClB;AACA;;AAEA;;;AAGA;AACF;AAEA;;;;;AASM;AACA;AACA;AACA;;AAOE;AACA;AACA;;AAMV;;"}
|
|
@@ -5,6 +5,7 @@ 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 { useOptionalSlideContext } from '../../context.js';
|
|
8
9
|
import { hasTextInsets } from '../shared/hasTextInsets.js';
|
|
9
10
|
|
|
10
11
|
function BaseTextElement({ elementInfo, target, renderContent, fillHeight = false, }) {
|
|
@@ -15,7 +16,8 @@ function BaseTextElement({ elementInfo, target, renderContent, fillHeight = fals
|
|
|
15
16
|
// Imported OOXML text carries its own bodyPr insets on the outer div.
|
|
16
17
|
// Adding the editor's default inset again shifts the label and reduces line width.
|
|
17
18
|
const contentHasTextInsets = hasTextInsets(elementInfo.content);
|
|
18
|
-
const
|
|
19
|
+
const classroomSizing = useOptionalSlideContext()?.classroomSizing;
|
|
20
|
+
const vAlign = classroomSizing && !fillHeight ? 'top' : (elementInfo.vAlign ?? 'top');
|
|
19
21
|
const justifyContent = vAlign === 'middle' ? 'center' : vAlign === 'bottom' ? 'flex-end' : 'flex-start';
|
|
20
22
|
const defaultContent = (jsx("div", { ref: proseRef, "data-inline-math-root": "", className: "text ProseMirror-static", style: {
|
|
21
23
|
position: 'relative',
|
|
@@ -41,7 +43,7 @@ function BaseTextElement({ elementInfo, target, renderContent, fillHeight = fals
|
|
|
41
43
|
}, children: jsxs("div", { className: "element-content slide-renderer-prose", style: {
|
|
42
44
|
position: 'relative',
|
|
43
45
|
boxSizing: 'border-box',
|
|
44
|
-
padding: contentHasTextInsets ? 0 : '10px',
|
|
46
|
+
padding: contentHasTextInsets && (!classroomSizing || fillHeight) ? 0 : '10px',
|
|
45
47
|
overflowWrap: 'break-word',
|
|
46
48
|
width: elementInfo.vertical ? 'auto' : '100%',
|
|
47
49
|
height: elementInfo.vertical || fillHeight ? '100%' : 'auto',
|
|
@@ -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';\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":"
|
|
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 { useOptionalSlideContext } from '../../context';\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 classroomSizing = useOptionalSlideContext()?.classroomSizing;\n const vAlign = classroomSizing && !fillHeight ? 'top' : (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 && (!classroomSizing || fillHeight) ? 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":";;;;;;;;;;AAmBM;;AAOJ;;AAEA;;;;AAKA;;;AAIA;AAMM;;AAEA;AACD;AAKL;AAIM;AACA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;;;;AAIA;AACA;;AAED;AAKG;AACA;AACA;AACA;;AAEA;;;;AAIA;;AAEA;;;;AAKA;;;AAGD;AAYX;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { HighlightOverlay, SpotlightOverlay, LaserOverlay, ZoomWrapper, type Hig
|
|
|
5
5
|
export { useSlideBackgroundStyle } from './hooks/useSlideBackgroundStyle';
|
|
6
6
|
export { useViewportSize, type ViewportStyles, type UseViewportSizeOptions, type UseViewportSizeResult, } from './hooks/useViewportSize';
|
|
7
7
|
export { findElementGeometry, findNearestCorner, getElementPercentageGeometry, type PercentageGeometry, } from './utils/geometry';
|
|
8
|
+
export { measureSpotlightRect } from './utils/spotlight-rect';
|
|
8
9
|
export { cn } from './utils/cn';
|
|
9
10
|
export { getElementRange, getLineElementPath, getTableSubThemeColor } from './utils/element';
|
|
10
11
|
export { createTextProseStyles } from './styles';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { ZoomWrapper } from './effects/ZoomWrapper.js';
|
|
|
8
8
|
export { useSlideBackgroundStyle } from './hooks/useSlideBackgroundStyle.js';
|
|
9
9
|
export { useViewportSize } from './hooks/useViewportSize.js';
|
|
10
10
|
export { findElementGeometry, findNearestCorner, getElementPercentageGeometry } from './utils/geometry.js';
|
|
11
|
+
export { measureSpotlightRect } from './utils/spotlight-rect.js';
|
|
11
12
|
export { cn } from './utils/cn.js';
|
|
12
13
|
export { getElementRange, getLineElementPath, getTableSubThemeColor } from './utils/element.js';
|
|
13
14
|
export { createTextProseStyles } from './styles.js';
|
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":";;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Translation and transform-origin affect the center, which the browser already
|
|
2
|
+
// measures. Only the linear part is needed for center deltas and box dimensions.
|
|
3
|
+
function linearTransform(element) {
|
|
4
|
+
let matrix;
|
|
5
|
+
for (let node = element; node; node = node.parentElement) {
|
|
6
|
+
const transform = getComputedStyle(node).transform;
|
|
7
|
+
if (transform && transform !== 'none') {
|
|
8
|
+
const parent = new DOMMatrix(transform);
|
|
9
|
+
matrix = matrix ? parent.multiply(matrix) : parent;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (matrix)
|
|
13
|
+
return new DOMMatrix([matrix.a, matrix.b, matrix.c, matrix.d, 0, 0]);
|
|
14
|
+
}
|
|
15
|
+
/** Measure the target's rendered border box in the overlay's 0–100 viewBox. */
|
|
16
|
+
function measureSpotlightRect(overlay, target) {
|
|
17
|
+
const frame = overlay.getBoundingClientRect();
|
|
18
|
+
const box = target.getBoundingClientRect();
|
|
19
|
+
if (!frame.width || !frame.height)
|
|
20
|
+
return null;
|
|
21
|
+
const axes = linearTransform(overlay);
|
|
22
|
+
if (!axes || (!axes.b && !axes.c && axes.a > 0 && axes.d > 0)) {
|
|
23
|
+
return {
|
|
24
|
+
x: ((box.left - frame.left) / frame.width) * 100,
|
|
25
|
+
y: ((box.top - frame.top) / frame.height) * 100,
|
|
26
|
+
w: (box.width / frame.width) * 100,
|
|
27
|
+
h: (box.height / frame.height) * 100,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (!(target instanceof HTMLElement) || !overlay.clientWidth || !overlay.clientHeight)
|
|
31
|
+
return null;
|
|
32
|
+
// The center survives rotation, whereas the corners of a viewport-aligned
|
|
33
|
+
// bounding rect no longer correspond to the corners of the target.
|
|
34
|
+
const inverse = axes.inverse();
|
|
35
|
+
const center = inverse.transformPoint({
|
|
36
|
+
x: box.left + box.width / 2 - (frame.left + frame.width / 2),
|
|
37
|
+
y: box.top + box.height / 2 - (frame.top + frame.height / 2),
|
|
38
|
+
});
|
|
39
|
+
const local = inverse.multiply(linearTransform(target));
|
|
40
|
+
const width = Math.abs(local.a) * target.offsetWidth + Math.abs(local.c) * target.offsetHeight;
|
|
41
|
+
const height = Math.abs(local.b) * target.offsetWidth + Math.abs(local.d) * target.offsetHeight;
|
|
42
|
+
return {
|
|
43
|
+
x: 50 + ((center.x - width / 2) / overlay.clientWidth) * 100,
|
|
44
|
+
y: 50 + ((center.y - height / 2) / overlay.clientHeight) * 100,
|
|
45
|
+
w: (width / overlay.clientWidth) * 100,
|
|
46
|
+
h: (height / overlay.clientHeight) * 100,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { measureSpotlightRect };
|
|
51
|
+
//# sourceMappingURL=spotlight-rect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spotlight-rect.js","sources":["../../src/utils/spotlight-rect.ts"],"sourcesContent":["// Translation and transform-origin affect the center, which the browser already\n// measures. Only the linear part is needed for center deltas and box dimensions.\nfunction linearTransform(element: Element) {\n let matrix: DOMMatrix | undefined;\n for (let node: Element | null = element; node; node = node.parentElement) {\n const transform = getComputedStyle(node).transform;\n if (transform && transform !== 'none') {\n const parent = new DOMMatrix(transform);\n matrix = matrix ? parent.multiply(matrix) : parent;\n }\n }\n if (matrix) return new DOMMatrix([matrix.a, matrix.b, matrix.c, matrix.d, 0, 0]);\n}\n\n/** Measure the target's rendered border box in the overlay's 0–100 viewBox. */\nexport function measureSpotlightRect(overlay: HTMLElement, target: Element) {\n const frame = overlay.getBoundingClientRect();\n const box = target.getBoundingClientRect();\n if (!frame.width || !frame.height) return null;\n\n const axes = linearTransform(overlay);\n if (!axes || (!axes.b && !axes.c && axes.a > 0 && axes.d > 0)) {\n return {\n x: ((box.left - frame.left) / frame.width) * 100,\n y: ((box.top - frame.top) / frame.height) * 100,\n w: (box.width / frame.width) * 100,\n h: (box.height / frame.height) * 100,\n };\n }\n\n if (!(target instanceof HTMLElement) || !overlay.clientWidth || !overlay.clientHeight)\n return null;\n // The center survives rotation, whereas the corners of a viewport-aligned\n // bounding rect no longer correspond to the corners of the target.\n const inverse = axes.inverse();\n const center = inverse.transformPoint({\n x: box.left + box.width / 2 - (frame.left + frame.width / 2),\n y: box.top + box.height / 2 - (frame.top + frame.height / 2),\n });\n const local = inverse.multiply(linearTransform(target));\n const width = Math.abs(local.a) * target.offsetWidth + Math.abs(local.c) * target.offsetHeight;\n const height = Math.abs(local.b) * target.offsetWidth + Math.abs(local.d) * target.offsetHeight;\n return {\n x: 50 + ((center.x - width / 2) / overlay.clientWidth) * 100,\n y: 50 + ((center.y - height / 2) / overlay.clientHeight) * 100,\n w: (width / overlay.clientWidth) * 100,\n h: (height / overlay.clientHeight) * 100,\n };\n}\n"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmaic/renderer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "React component for rendering PPTist-style Slide JSON, extracted from OpenMAIC.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"lucide-react": "^0.562.0",
|
|
82
82
|
"tailwind-merge": "^3.4.0",
|
|
83
83
|
"tinycolor2": "^1.6.0",
|
|
84
|
-
"@openmaic/
|
|
85
|
-
"@openmaic/
|
|
84
|
+
"@openmaic/dsl": "^0.13.0",
|
|
85
|
+
"@openmaic/geometry": "^0.1.0"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@rollup/plugin-commonjs": "^28.0.1",
|