@openmaic/renderer 0.0.1 → 0.0.3

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.
Files changed (175) hide show
  1. package/DESIGN.md +7 -1
  2. package/README.md +11 -3
  3. package/dist/SlideCanvas.d.ts +12 -1
  4. package/dist/SlideCanvas.js +105 -0
  5. package/dist/SlideCanvas.js.map +1 -0
  6. package/dist/SlideElement.d.ts +3 -2
  7. package/dist/SlideElement.js +60 -0
  8. package/dist/SlideElement.js.map +1 -0
  9. package/dist/context.d.ts +2 -1
  10. package/dist/context.js +27 -0
  11. package/dist/context.js.map +1 -0
  12. package/dist/editing/EditableSlideCanvas.d.ts +26 -0
  13. package/dist/editing/EditableSlideCanvas.js +352 -0
  14. package/dist/editing/EditableSlideCanvas.js.map +1 -0
  15. package/dist/editing/core/drag.d.ts +108 -0
  16. package/dist/editing/core/drag.js +119 -0
  17. package/dist/editing/core/drag.js.map +1 -0
  18. package/dist/editing/core/geometry.d.ts +48 -0
  19. package/dist/editing/core/geometry.js +186 -0
  20. package/dist/editing/core/geometry.js.map +1 -0
  21. package/dist/editing/core/intent.d.ts +39 -0
  22. package/dist/editing/core/intent.js +35 -0
  23. package/dist/editing/core/intent.js.map +1 -0
  24. package/dist/editing/core/line-drag.d.ts +19 -0
  25. package/dist/editing/core/line-drag.js +163 -0
  26. package/dist/editing/core/line-drag.js.map +1 -0
  27. package/dist/editing/core/marquee.d.ts +56 -0
  28. package/dist/editing/core/marquee.js +74 -0
  29. package/dist/editing/core/marquee.js.map +1 -0
  30. package/dist/editing/core/resize.d.ts +121 -0
  31. package/dist/editing/core/resize.js +392 -0
  32. package/dist/editing/core/resize.js.map +1 -0
  33. package/dist/editing/core/rotate.d.ts +37 -0
  34. package/dist/editing/core/rotate.js +74 -0
  35. package/dist/editing/core/rotate.js.map +1 -0
  36. package/dist/editing/core/selection.d.ts +68 -0
  37. package/dist/editing/core/selection.js +108 -0
  38. package/dist/editing/core/selection.js.map +1 -0
  39. package/dist/editing/core/snapping.d.ts +54 -0
  40. package/dist/editing/core/snapping.js +96 -0
  41. package/dist/editing/core/snapping.js.map +1 -0
  42. package/dist/editing/handles/BorderLine.d.ts +15 -0
  43. package/dist/editing/handles/BorderLine.js +17 -0
  44. package/dist/editing/handles/BorderLine.js.map +1 -0
  45. package/dist/editing/handles/LineHandles.d.ts +28 -0
  46. package/dist/editing/handles/LineHandles.js +51 -0
  47. package/dist/editing/handles/LineHandles.js.map +1 -0
  48. package/dist/editing/handles/MarqueeBox.d.ts +19 -0
  49. package/dist/editing/handles/MarqueeBox.js +26 -0
  50. package/dist/editing/handles/MarqueeBox.js.map +1 -0
  51. package/dist/editing/handles/ResizeHandles.d.ts +31 -0
  52. package/dist/editing/handles/ResizeHandles.js +44 -0
  53. package/dist/editing/handles/ResizeHandles.js.map +1 -0
  54. package/dist/editing/handles/RotateHandle.d.ts +26 -0
  55. package/dist/editing/handles/RotateHandle.js +52 -0
  56. package/dist/editing/handles/RotateHandle.js.map +1 -0
  57. package/dist/editing/handles/SelectionOverlay.d.ts +18 -0
  58. package/dist/editing/handles/SelectionOverlay.js +35 -0
  59. package/dist/editing/handles/SelectionOverlay.js.map +1 -0
  60. package/dist/editing/index.d.ts +3 -0
  61. package/dist/editing/index.js +4 -0
  62. package/dist/editing/index.js.map +1 -0
  63. package/dist/editing/types.d.ts +107 -0
  64. package/dist/editing/types.js +7 -0
  65. package/dist/editing/types.js.map +1 -0
  66. package/dist/editing/useEditGesture.d.ts +46 -0
  67. package/dist/editing/useEditGesture.js +217 -0
  68. package/dist/editing/useEditGesture.js.map +1 -0
  69. package/dist/editing/useLineHandleGesture.d.ts +35 -0
  70. package/dist/editing/useLineHandleGesture.js +112 -0
  71. package/dist/editing/useLineHandleGesture.js.map +1 -0
  72. package/dist/editing/useMarqueeGesture.d.ts +43 -0
  73. package/dist/editing/useMarqueeGesture.js +157 -0
  74. package/dist/editing/useMarqueeGesture.js.map +1 -0
  75. package/dist/editing/useResizeGesture.d.ts +43 -0
  76. package/dist/editing/useResizeGesture.js +137 -0
  77. package/dist/editing/useResizeGesture.js.map +1 -0
  78. package/dist/editing/useRotateGesture.d.ts +47 -0
  79. package/dist/editing/useRotateGesture.js +128 -0
  80. package/dist/editing/useRotateGesture.js.map +1 -0
  81. package/dist/effects/HighlightOverlay.js +44 -0
  82. package/dist/effects/HighlightOverlay.js.map +1 -0
  83. package/dist/effects/LaserOverlay.js +40 -0
  84. package/dist/effects/LaserOverlay.js.map +1 -0
  85. package/dist/effects/SpotlightOverlay.d.ts +3 -1
  86. package/dist/effects/SpotlightOverlay.js +99 -0
  87. package/dist/effects/SpotlightOverlay.js.map +1 -0
  88. package/dist/effects/ZoomWrapper.js +19 -0
  89. package/dist/effects/ZoomWrapper.js.map +1 -0
  90. package/dist/elements/chart/BaseChartElement.js +22 -0
  91. package/dist/elements/chart/BaseChartElement.js.map +1 -0
  92. package/dist/elements/chart/Chart.js +83 -0
  93. package/dist/elements/chart/Chart.js.map +1 -0
  94. package/dist/elements/chart/chartOption.js +178 -0
  95. package/dist/elements/chart/chartOption.js.map +1 -0
  96. package/dist/elements/code/BaseCodeElement.js +525 -0
  97. package/dist/elements/code/BaseCodeElement.js.map +1 -0
  98. package/dist/elements/image/BaseImageElement.d.ts +4 -4
  99. package/dist/elements/image/BaseImageElement.js +76 -0
  100. package/dist/elements/image/BaseImageElement.js.map +1 -0
  101. package/dist/elements/image/ImageOutline.js +30 -0
  102. package/dist/elements/image/ImageOutline.js.map +1 -0
  103. package/dist/elements/image/clipPaths.js +130 -0
  104. package/dist/elements/image/clipPaths.js.map +1 -0
  105. package/dist/elements/image/useClipImage.js +40 -0
  106. package/dist/elements/image/useClipImage.js.map +1 -0
  107. package/dist/elements/image/useFilter.d.ts +1 -0
  108. package/dist/elements/image/useFilter.js +35 -0
  109. package/dist/elements/image/useFilter.js.map +1 -0
  110. package/dist/elements/index.js +14 -9
  111. package/dist/elements/index.js.map +1 -1
  112. package/dist/elements/latex/BaseLatexElement.js +94 -0
  113. package/dist/elements/latex/BaseLatexElement.js.map +1 -0
  114. package/dist/elements/line/BaseLineElement.js +72 -0
  115. package/dist/elements/line/BaseLineElement.js.map +1 -0
  116. package/dist/elements/line/LinePointMarker.js +19 -0
  117. package/dist/elements/line/LinePointMarker.js.map +1 -0
  118. package/dist/elements/shape/BaseShapeElement.js +174 -0
  119. package/dist/elements/shape/BaseShapeElement.js.map +1 -0
  120. package/dist/elements/shape/GradientDefs.js +11 -0
  121. package/dist/elements/shape/GradientDefs.js.map +1 -0
  122. package/dist/elements/shape/PatternDefs.js +8 -0
  123. package/dist/elements/shape/PatternDefs.js.map +1 -0
  124. package/dist/elements/shared/ElementOutline.js +13 -0
  125. package/dist/elements/shared/ElementOutline.js.map +1 -0
  126. package/dist/elements/shared/useElementFill.js +15 -0
  127. package/dist/elements/shared/useElementFill.js.map +1 -0
  128. package/dist/elements/shared/useElementFlip.js +18 -0
  129. package/dist/elements/shared/useElementFlip.js.map +1 -0
  130. package/dist/elements/shared/useElementOutline.js +19 -0
  131. package/dist/elements/shared/useElementOutline.js.map +1 -0
  132. package/dist/elements/shared/useElementShadow.js +15 -0
  133. package/dist/elements/shared/useElementShadow.js.map +1 -0
  134. package/dist/elements/table/BaseTableElement.js +21 -0
  135. package/dist/elements/table/BaseTableElement.js.map +1 -0
  136. package/dist/elements/table/StaticTable.js +117 -0
  137. package/dist/elements/table/StaticTable.js.map +1 -0
  138. package/dist/elements/table/tableUtils.js +28 -0
  139. package/dist/elements/table/tableUtils.js.map +1 -0
  140. package/dist/elements/text/BaseTextElement.js +46 -0
  141. package/dist/elements/text/BaseTextElement.js.map +1 -0
  142. package/dist/elements/video/BaseVideoElement.d.ts +3 -1
  143. package/dist/elements/video/BaseVideoElement.js +36 -0
  144. package/dist/elements/video/BaseVideoElement.js.map +1 -0
  145. package/dist/hooks/useSlideBackgroundStyle.js +43 -0
  146. package/dist/hooks/useSlideBackgroundStyle.js.map +1 -0
  147. package/dist/hooks/useViewportSize.d.ts +2 -0
  148. package/dist/hooks/useViewportSize.js +71 -0
  149. package/dist/hooks/useViewportSize.js.map +1 -0
  150. package/dist/index.js +11 -31
  151. package/dist/index.js.map +1 -1
  152. package/dist/snapshot/index.d.ts +1 -0
  153. package/dist/snapshot/index.js +93 -28
  154. package/dist/snapshot/index.js.map +1 -1
  155. package/dist/snapshot/katex-fonts-embed.d.ts +10 -0
  156. package/dist/snapshot/katex-fonts-embed.js +13 -0
  157. package/dist/snapshot/katex-fonts-embed.js.map +1 -0
  158. package/dist/snapshot/measure.d.ts +32 -0
  159. package/dist/snapshot/measure.js +129 -0
  160. package/dist/snapshot/measure.js.map +1 -0
  161. package/dist/styles.js +50 -0
  162. package/dist/styles.js.map +1 -0
  163. package/dist/types/effects.d.ts +2 -0
  164. package/dist/utils/cn.js +9 -0
  165. package/dist/utils/cn.js.map +1 -0
  166. package/dist/utils/element.js +85 -0
  167. package/dist/utils/element.js.map +1 -0
  168. package/dist/utils/geometry.d.ts +2 -2
  169. package/dist/utils/geometry.js +44 -0
  170. package/dist/utils/geometry.js.map +1 -0
  171. package/package.json +19 -4
  172. package/dist/chunks/BaseCodeElement-Bh-Bfdz6.js +0 -1742
  173. package/dist/chunks/BaseCodeElement-Bh-Bfdz6.js.map +0 -1
  174. package/dist/chunks/SlideCanvas-BwlcjqMl.js +0 -469
  175. package/dist/chunks/SlideCanvas-BwlcjqMl.js.map +0 -1
@@ -0,0 +1,32 @@
1
+ import type { Slide } from '@openmaic/dsl';
2
+ /** Percentage geometry (0–100) — mirrors the compiler's `PercentageGeometry`. */
3
+ export interface MeasuredGeometry {
4
+ x: number;
5
+ y: number;
6
+ w: number;
7
+ h: number;
8
+ centerX: number;
9
+ centerY: number;
10
+ }
11
+ export interface MeasureOptions {
12
+ /**
13
+ * Off-screen render width in px. Defaults to the slide's native
14
+ * `viewportSize`. Only the *ratio* of element box to container matters for the
15
+ * 0–100 normalization, so the absolute width is not important — but rendering
16
+ * near native size keeps text wrapping (hence auto-height) faithful.
17
+ */
18
+ width?: number;
19
+ /** Settle timeout in ms for `document.fonts.ready`. Default 5000. */
20
+ timeoutMs?: number;
21
+ }
22
+ /**
23
+ * Measure the rendered content-box geometry (0–100) of the given element ids on
24
+ * a slide. Returns a Map keyed by element id; ids that could not be located are
25
+ * absent (the caller falls back to the authored-box calc). Never throws for a
26
+ * missing element — only for a non-browser environment.
27
+ *
28
+ * The measurement matches `SpotlightOverlay`: prefer the element's
29
+ * `.element-content` box, else the element wrapper, normalized against the
30
+ * SlideCanvas inner container so it is independent of the off-screen scale.
31
+ */
32
+ export declare function measureSlideElementGeometry(slide: Slide, elementIds: readonly string[], options?: MeasureOptions): Promise<Map<string, MeasuredGeometry>>;
@@ -0,0 +1,129 @@
1
+ "use client";
2
+ import { createElement } from 'react';
3
+ import { flushSync } from 'react-dom';
4
+ import { createRoot } from 'react-dom/client';
5
+ import { SlideCanvas } from '../SlideCanvas.js';
6
+
7
+ const DEFAULT_VIEWPORT_RATIO = 0.5625;
8
+ const DEFAULT_TIMEOUT_MS = 5000;
9
+ /** SlideElement renders each element wrapper as `slide-element-<id>` by default. */
10
+ const ELEMENT_ID_PREFIX = 'slide-element-';
11
+ function nextFrame() {
12
+ return new Promise((resolve) => requestAnimationFrame(() => resolve()));
13
+ }
14
+ /**
15
+ * Measure the rendered content-box geometry (0–100) of the given element ids on
16
+ * a slide. Returns a Map keyed by element id; ids that could not be located are
17
+ * absent (the caller falls back to the authored-box calc). Never throws for a
18
+ * missing element — only for a non-browser environment.
19
+ *
20
+ * The measurement matches `SpotlightOverlay`: prefer the element's
21
+ * `.element-content` box, else the element wrapper, normalized against the
22
+ * SlideCanvas inner container so it is independent of the off-screen scale.
23
+ */
24
+ async function measureSlideElementGeometry(slide, elementIds, options = {}) {
25
+ const result = new Map();
26
+ if (typeof document === 'undefined') {
27
+ throw new Error('measureSlideElementGeometry requires a browser environment');
28
+ }
29
+ const ids = [...new Set(elementIds)].filter(Boolean);
30
+ if (ids.length === 0)
31
+ return result;
32
+ const width = options.width ?? slide.viewportSize ?? 1280;
33
+ const viewportRatio = slide.viewportRatio ?? DEFAULT_VIEWPORT_RATIO;
34
+ const height = Math.round(width * viewportRatio);
35
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
36
+ const container = document.createElement('div');
37
+ container.style.cssText = [
38
+ 'position: absolute',
39
+ 'left: -99999px',
40
+ 'top: 0',
41
+ `width: ${width}px`,
42
+ `height: ${height}px`,
43
+ 'pointer-events: none',
44
+ ].join('; ');
45
+ document.body.appendChild(container);
46
+ let root = null;
47
+ try {
48
+ root = createRoot(container);
49
+ flushSync(() => {
50
+ root.render(createElement(SlideCanvas, { slide, chrome: false }));
51
+ });
52
+ // Let the ResizeObserver-driven fit settle, then settle fonts before we read
53
+ // rects. Auto-height text only reaches its final extent once the real faces
54
+ // load, and `document.fonts.ready` alone is racy — it can resolve before the
55
+ // off-screen render triggers a self-hosted woff2 fetch, leaving a fallback
56
+ // face whose Latin/digit advances differ and shift the measured content box.
57
+ // So force-load every (style, weight, family) actually used first (mirrors
58
+ // `slideToPng`), then await readiness, capped by the settle timeout.
59
+ await nextFrame();
60
+ await nextFrame();
61
+ if (document.fonts && typeof document.fonts.load === 'function') {
62
+ const fontSpecs = new Set();
63
+ container.querySelectorAll('*').forEach((el) => {
64
+ if (!el.textContent || !el.textContent.trim())
65
+ return;
66
+ const cs = getComputedStyle(el);
67
+ if (!cs.fontFamily)
68
+ return;
69
+ fontSpecs.add(`${cs.fontStyle} ${cs.fontWeight} 16px ${cs.fontFamily}`);
70
+ });
71
+ await Promise.race([
72
+ Promise.all([...fontSpecs].map((spec) => document.fonts.load(spec).catch(() => undefined))),
73
+ new Promise((resolve) => setTimeout(resolve, timeoutMs)),
74
+ ]);
75
+ }
76
+ if (document.fonts?.ready) {
77
+ await Promise.race([
78
+ document.fonts.ready,
79
+ new Promise((resolve) => setTimeout(resolve, timeoutMs)),
80
+ ]);
81
+ }
82
+ // Let any font-triggered relayout settle (KaTeX re-fits once KaTeX_Size loads,
83
+ // a React state update) before reading rects — two frames to commit.
84
+ await nextFrame();
85
+ await nextFrame();
86
+ // The SlideCanvas inner container is the positioned box every element is
87
+ // absolute within; normalizing against it (not the outer offscreen div)
88
+ // makes the geometry independent of the fit scale — exactly what
89
+ // SpotlightOverlay does against its own `inset:0` container.
90
+ const canvasEl = container.firstElementChild ?? container;
91
+ const containerRect = canvasEl.getBoundingClientRect();
92
+ if (containerRect.width === 0 || containerRect.height === 0)
93
+ return result;
94
+ for (const id of ids) {
95
+ const el = container.querySelector(`#${cssEscape(ELEMENT_ID_PREFIX + id)}`);
96
+ if (!el)
97
+ continue;
98
+ const contentEl = el.querySelector('.element-content');
99
+ const targetEl = contentEl ?? el;
100
+ const r = targetEl.getBoundingClientRect();
101
+ if (r.width === 0 && r.height === 0)
102
+ continue;
103
+ const x = ((r.left - containerRect.left) / containerRect.width) * 100;
104
+ const y = ((r.top - containerRect.top) / containerRect.height) * 100;
105
+ const w = (r.width / containerRect.width) * 100;
106
+ const h = (r.height / containerRect.height) * 100;
107
+ result.set(id, { x, y, w, h, centerX: x + w / 2, centerY: y + h / 2 });
108
+ }
109
+ }
110
+ finally {
111
+ if (root) {
112
+ const r = root;
113
+ setTimeout(() => r.unmount(), 0);
114
+ }
115
+ setTimeout(() => container.remove(), 0);
116
+ }
117
+ return result;
118
+ }
119
+ /** Minimal CSS.escape fallback for element ids used in a selector. */
120
+ function cssEscape(value) {
121
+ const g = globalThis;
122
+ if (g.CSS?.escape)
123
+ return g.CSS.escape(value);
124
+ // Escape characters that are not safe in a CSS identifier.
125
+ return value.replace(/[^a-zA-Z0-9_-]/g, (ch) => `\\${ch}`);
126
+ }
127
+
128
+ export { measureSlideElementGeometry };
129
+ //# sourceMappingURL=measure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measure.js","sources":["../../src/snapshot/measure.ts"],"sourcesContent":["'use client';\n\n/**\n * Off-screen element-geometry measurement.\n *\n * The video-export compiler places spotlight/laser/video effects on a slide\n * element's geometry. Its pure fallback ({@link ../geometry}) reads the\n * element's *authored* `left/top/width/height` against a fixed 1000×562.5 base\n * — the element's **outer box**. But the live overlays (and the exported frame\n * PNG) measure the element's `.element-content` box, which differs for\n * auto-sized text (`height:auto`) and its 10px content padding, so a spotlight\n * on the authored box sits offset from the rendered text (issue #867 item 5).\n *\n * This measures the same content box the live `SpotlightOverlay` does: it mounts\n * the slide off-screen at native size (the same 1:1 mount `slideToPng` uses),\n * then for each requested element id reads `.element-content`'s\n * `getBoundingClientRect()` normalized against the canvas container rect → 0–100\n * space. The app feeds the result to the compiler as a `GeometryProbe` so the\n * IR carries rendered geometry; the compile stays pure and falls back to the\n * authored box for anything not measured.\n *\n * App-side / impure: needs a browser (DOM + layout). Mirrors `slideToPng`'s\n * mount lifecycle.\n */\n\nimport { createElement } from 'react';\nimport { flushSync } from 'react-dom';\nimport { createRoot, type Root } from 'react-dom/client';\nimport { SlideCanvas } from '../SlideCanvas';\nimport type { Slide } from '@openmaic/dsl';\n\n/** Percentage geometry (0–100) — mirrors the compiler's `PercentageGeometry`. */\nexport interface MeasuredGeometry {\n x: number;\n y: number;\n w: number;\n h: number;\n centerX: number;\n centerY: number;\n}\n\nexport interface MeasureOptions {\n /**\n * Off-screen render width in px. Defaults to the slide's native\n * `viewportSize`. Only the *ratio* of element box to container matters for the\n * 0–100 normalization, so the absolute width is not important — but rendering\n * near native size keeps text wrapping (hence auto-height) faithful.\n */\n width?: number;\n /** Settle timeout in ms for `document.fonts.ready`. Default 5000. */\n timeoutMs?: number;\n}\n\nconst DEFAULT_VIEWPORT_RATIO = 0.5625;\nconst DEFAULT_TIMEOUT_MS = 5000;\n/** SlideElement renders each element wrapper as `slide-element-<id>` by default. */\nconst ELEMENT_ID_PREFIX = 'slide-element-';\n\nfunction nextFrame(): Promise<void> {\n return new Promise((resolve) => requestAnimationFrame(() => resolve()));\n}\n\n/**\n * Measure the rendered content-box geometry (0–100) of the given element ids on\n * a slide. Returns a Map keyed by element id; ids that could not be located are\n * absent (the caller falls back to the authored-box calc). Never throws for a\n * missing element — only for a non-browser environment.\n *\n * The measurement matches `SpotlightOverlay`: prefer the element's\n * `.element-content` box, else the element wrapper, normalized against the\n * SlideCanvas inner container so it is independent of the off-screen scale.\n */\nexport async function measureSlideElementGeometry(\n slide: Slide,\n elementIds: readonly string[],\n options: MeasureOptions = {},\n): Promise<Map<string, MeasuredGeometry>> {\n const result = new Map<string, MeasuredGeometry>();\n if (typeof document === 'undefined') {\n throw new Error('measureSlideElementGeometry requires a browser environment');\n }\n const ids = [...new Set(elementIds)].filter(Boolean);\n if (ids.length === 0) return result;\n\n const width = options.width ?? slide.viewportSize ?? 1280;\n const viewportRatio = slide.viewportRatio ?? DEFAULT_VIEWPORT_RATIO;\n const height = Math.round(width * viewportRatio);\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\n const container = document.createElement('div');\n container.style.cssText = [\n 'position: absolute',\n 'left: -99999px',\n 'top: 0',\n `width: ${width}px`,\n `height: ${height}px`,\n 'pointer-events: none',\n ].join('; ');\n document.body.appendChild(container);\n\n let root: Root | null = null;\n try {\n root = createRoot(container);\n flushSync(() => {\n root!.render(createElement(SlideCanvas, { slide, chrome: false }));\n });\n\n // Let the ResizeObserver-driven fit settle, then settle fonts before we read\n // rects. Auto-height text only reaches its final extent once the real faces\n // load, and `document.fonts.ready` alone is racy — it can resolve before the\n // off-screen render triggers a self-hosted woff2 fetch, leaving a fallback\n // face whose Latin/digit advances differ and shift the measured content box.\n // So force-load every (style, weight, family) actually used first (mirrors\n // `slideToPng`), then await readiness, capped by the settle timeout.\n await nextFrame();\n await nextFrame();\n if (document.fonts && typeof document.fonts.load === 'function') {\n const fontSpecs = new Set<string>();\n container.querySelectorAll<HTMLElement>('*').forEach((el) => {\n if (!el.textContent || !el.textContent.trim()) return;\n const cs = getComputedStyle(el);\n if (!cs.fontFamily) return;\n fontSpecs.add(`${cs.fontStyle} ${cs.fontWeight} 16px ${cs.fontFamily}`);\n });\n await Promise.race([\n Promise.all([...fontSpecs].map((spec) => document.fonts.load(spec).catch(() => undefined))),\n new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n }\n if (document.fonts?.ready) {\n await Promise.race([\n document.fonts.ready,\n new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n }\n // Let any font-triggered relayout settle (KaTeX re-fits once KaTeX_Size loads,\n // a React state update) before reading rects — two frames to commit.\n await nextFrame();\n await nextFrame();\n\n // The SlideCanvas inner container is the positioned box every element is\n // absolute within; normalizing against it (not the outer offscreen div)\n // makes the geometry independent of the fit scale — exactly what\n // SpotlightOverlay does against its own `inset:0` container.\n const canvasEl = (container.firstElementChild as HTMLElement | null) ?? container;\n const containerRect = canvasEl.getBoundingClientRect();\n if (containerRect.width === 0 || containerRect.height === 0) return result;\n\n for (const id of ids) {\n const el = container.querySelector<HTMLElement>(`#${cssEscape(ELEMENT_ID_PREFIX + id)}`);\n if (!el) continue;\n const contentEl = el.querySelector<HTMLElement>('.element-content');\n const targetEl = contentEl ?? el;\n const r = targetEl.getBoundingClientRect();\n if (r.width === 0 && r.height === 0) continue;\n const x = ((r.left - containerRect.left) / containerRect.width) * 100;\n const y = ((r.top - containerRect.top) / containerRect.height) * 100;\n const w = (r.width / containerRect.width) * 100;\n const h = (r.height / containerRect.height) * 100;\n result.set(id, { x, y, w, h, centerX: x + w / 2, centerY: y + h / 2 });\n }\n } finally {\n if (root) {\n const r = root;\n setTimeout(() => r.unmount(), 0);\n }\n setTimeout(() => container.remove(), 0);\n }\n\n return result;\n}\n\n/** Minimal CSS.escape fallback for element ids used in a selector. */\nfunction cssEscape(value: string): string {\n const g = globalThis as { CSS?: { escape?: (v: string) => string } };\n if (g.CSS?.escape) return g.CSS.escape(value);\n // Escape characters that are not safe in a CSS identifier.\n return value.replace(/[^a-zA-Z0-9_-]/g, (ch) => `\\\\${ch}`);\n}\n"],"names":[],"mappings":";;;;;;AAqDA;AACA;AACA;AACA;AAEA;AACE;AACF;AAEA;;;;;;;;;AASG;AACI;AAKL;AACA;AACE;;AAEF;AACA;AAAsB;;AAGtB;;AAEA;;AAGA;;;;AAIE;AACA;;AAED;AACD;;AAGA;AACE;;AAEE;AACF;;;;;;;;;;AAWA;AACE;;;;AAGE;;;AAEA;AACF;;AAEE;AACA;AACD;;AAEH;;;AAGI;AACD;;;;;;;;;;AAWH;AACA;;AAC6D;AAE7D;AACE;AACA;;;AAEA;AACA;;;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;AAUJ;AACF;AAEA;AACA;;AAEE;;;AAEA;AACF;;"}
package/dist/styles.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Package-level CSS rules that can't be expressed inline (descendant selectors,
3
+ * keyframes, pseudo-classes). Rendered once via `<style>` at the top of
4
+ * `<SlideCanvas>` so the package stays self-contained without Tailwind.
5
+ *
6
+ * The `.slide-renderer-prose` rules are intentionally minimal "browser-default
7
+ * resets" — they un-do the user-agent stylesheet (1em <p> margin, KaTeX block
8
+ * margin) so the slide JSON is the single source of truth. They do not
9
+ * positively style anything; spacing comes from the data via the
10
+ * `--paragraphSpace` CSS variable, which is unset when undefined in data.
11
+ */
12
+ const SLIDE_RENDERER_STYLES = `
13
+ .slide-renderer-prose p {
14
+ margin-top: 0;
15
+ margin-bottom: var(--paragraphSpace, 0);
16
+ }
17
+ .slide-renderer-prose p:last-child {
18
+ margin-bottom: 0;
19
+ }
20
+ .slide-renderer-prose .katex-display {
21
+ margin: 0 !important;
22
+ }
23
+ /* Table cell inner container — matches the classroom (Vue) .cell-text design:
24
+ tight base line-height, and a small spacing between adjacent <p> siblings
25
+ so multi-paragraph cells don't collapse into a single visual block. The
26
+ <p> margin reset above sets the baseline to 0; this rule re-adds spacing
27
+ only between adjacent siblings, leaving the first/last paragraph flush. */
28
+ .slide-renderer-cell-text p + p {
29
+ margin-top: 0.4em;
30
+ }
31
+ @keyframes slide-renderer-pulse {
32
+ 50% { opacity: 0.5; }
33
+ }
34
+ @keyframes slide-renderer-ping {
35
+ 75%, 100% { transform: scale(2); opacity: 0; }
36
+ }
37
+ @keyframes slide-renderer-code-cursor-blink {
38
+ 0%, 100% { opacity: 1; }
39
+ 50% { opacity: 0; }
40
+ }
41
+ .slide-renderer-pulse {
42
+ animation: slide-renderer-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
43
+ }
44
+ .slide-renderer-ping {
45
+ animation: slide-renderer-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
46
+ }
47
+ `;
48
+
49
+ export { SLIDE_RENDERER_STYLES };
50
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +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 are intentionally minimal \"browser-default\n * resets\" — they un-do the user-agent stylesheet (1em <p> margin, KaTeX block\n * margin) so the slide JSON is the single source of truth. They do not\n * positively style anything; spacing comes from the data via the\n * `--paragraphSpace` CSS variable, which is unset when undefined in data.\n */\nexport const SLIDE_RENDERER_STYLES = `\n.slide-renderer-prose p {\n margin-top: 0;\n margin-bottom: var(--paragraphSpace, 0);\n}\n.slide-renderer-prose p:last-child {\n margin-bottom: 0;\n}\n.slide-renderer-prose .katex-display {\n margin: 0 !important;\n}\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;;;;;;;;;;AAUG;AACI,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -5,6 +5,7 @@ export interface LaserEffectOptions {
5
5
  }
6
6
  export interface SpotlightEffectOptions {
7
7
  elementId: string;
8
+ dimness?: number;
8
9
  }
9
10
  export interface HighlightEffectOptions {
10
11
  elementId: string;
@@ -21,5 +22,6 @@ export interface SlideEffects {
21
22
  laser?: LaserEffectOptions;
22
23
  spotlight?: SpotlightEffectOptions;
23
24
  highlight?: HighlightEffectOptions;
25
+ highlights?: HighlightEffectOptions[];
24
26
  zoom?: ZoomEffectOptions;
25
27
  }
@@ -0,0 +1,9 @@
1
+ import { clsx } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+
4
+ function cn(...inputs) {
5
+ return twMerge(clsx(inputs));
6
+ }
7
+
8
+ export { cn };
9
+ //# sourceMappingURL=cn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cn.js","sources":["../../src/utils/cn.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"names":[],"mappings":";;;AAGM,SAAU,EAAE,CAAC,GAAG,MAAoB,EAAA;AACxC,IAAA,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;"}
@@ -0,0 +1,85 @@
1
+ import tinycolor from 'tinycolor2';
2
+
3
+ const getRectRotatedRange = (element) => {
4
+ const { left, top, width, height, rotate = 0 } = element;
5
+ const radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / 2;
6
+ const auxiliaryAngle = (Math.atan(height / width) * 180) / Math.PI;
7
+ const tlbraRadian = ((180 - rotate - auxiliaryAngle) * Math.PI) / 180;
8
+ const trblaRadian = ((auxiliaryAngle - rotate) * Math.PI) / 180;
9
+ const middleLeft = left + width / 2;
10
+ const middleTop = top + height / 2;
11
+ const xAxis = [
12
+ middleLeft + radius * Math.cos(tlbraRadian),
13
+ middleLeft + radius * Math.cos(trblaRadian),
14
+ middleLeft - radius * Math.cos(tlbraRadian),
15
+ middleLeft - radius * Math.cos(trblaRadian),
16
+ ];
17
+ const yAxis = [
18
+ middleTop - radius * Math.sin(tlbraRadian),
19
+ middleTop - radius * Math.sin(trblaRadian),
20
+ middleTop + radius * Math.sin(tlbraRadian),
21
+ middleTop + radius * Math.sin(trblaRadian),
22
+ ];
23
+ return {
24
+ xRange: [Math.min(...xAxis), Math.max(...xAxis)],
25
+ yRange: [Math.min(...yAxis), Math.max(...yAxis)],
26
+ };
27
+ };
28
+ const getElementRange = (element) => {
29
+ let minX, maxX, minY, maxY;
30
+ if (element.type === 'line') {
31
+ minX = element.left;
32
+ maxX = element.left + Math.max(element.start[0], element.end[0]);
33
+ minY = element.top;
34
+ maxY = element.top + Math.max(element.start[1], element.end[1]);
35
+ }
36
+ else if ('rotate' in element && element.rotate) {
37
+ const { left, top, width, height, rotate } = element;
38
+ const { xRange, yRange } = getRectRotatedRange({ left, top, width, height, rotate });
39
+ minX = xRange[0];
40
+ maxX = xRange[1];
41
+ minY = yRange[0];
42
+ maxY = yRange[1];
43
+ }
44
+ else {
45
+ minX = element.left;
46
+ maxX = element.left + element.width;
47
+ minY = element.top;
48
+ maxY = element.top + element.height;
49
+ }
50
+ return { minX, maxX, minY, maxY };
51
+ };
52
+ const getTableSubThemeColor = (themeColor) => {
53
+ const rgba = tinycolor(themeColor);
54
+ return [rgba.setAlpha(0.3).toRgbString(), rgba.setAlpha(0.1).toRgbString()];
55
+ };
56
+ const getLineElementPath = (element) => {
57
+ const startArr = Array.isArray(element.start) ? element.start : [0, 0];
58
+ const endArr = Array.isArray(element.end) ? element.end : [100, 100];
59
+ const start = startArr.join(',');
60
+ const end = endArr.join(',');
61
+ if (element.broken) {
62
+ const mid = element.broken.join(',');
63
+ return `M${start} L${mid} L${end}`;
64
+ }
65
+ else if (element.broken2) {
66
+ const { minX, maxX, minY, maxY } = getElementRange(element);
67
+ if (maxX - minX >= maxY - minY)
68
+ return `M${start} L${element.broken2[0]},${startArr[1]} L${element.broken2[0]},${endArr[1]} ${end}`;
69
+ return `M${start} L${startArr[0]},${element.broken2[1]} L${endArr[0]},${element.broken2[1]} ${end}`;
70
+ }
71
+ else if (element.curve) {
72
+ const mid = element.curve.join(',');
73
+ return `M${start} Q${mid} ${end}`;
74
+ }
75
+ else if (element.cubic) {
76
+ const [c1, c2] = element.cubic;
77
+ const p1 = c1.join(',');
78
+ const p2 = c2.join(',');
79
+ return `M${start} C${p1} ${p2} ${end}`;
80
+ }
81
+ return `M${start} L${end}`;
82
+ };
83
+
84
+ export { getElementRange, getLineElementPath, getRectRotatedRange, getTableSubThemeColor };
85
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","sources":["../../src/utils/element.ts"],"sourcesContent":["import tinycolor from 'tinycolor2';\nimport type { PPTElement, PPTLineElement } from '@openmaic/dsl';\n\ninterface RotatedElementData {\n left: number;\n top: number;\n width: number;\n height: number;\n rotate: number;\n}\n\nexport const getRectRotatedRange = (element: RotatedElementData) => {\n const { left, top, width, height, rotate = 0 } = element;\n\n const radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / 2;\n const auxiliaryAngle = (Math.atan(height / width) * 180) / Math.PI;\n\n const tlbraRadian = ((180 - rotate - auxiliaryAngle) * Math.PI) / 180;\n const trblaRadian = ((auxiliaryAngle - rotate) * Math.PI) / 180;\n\n const middleLeft = left + width / 2;\n const middleTop = top + height / 2;\n\n const xAxis = [\n middleLeft + radius * Math.cos(tlbraRadian),\n middleLeft + radius * Math.cos(trblaRadian),\n middleLeft - radius * Math.cos(tlbraRadian),\n middleLeft - radius * Math.cos(trblaRadian),\n ];\n const yAxis = [\n middleTop - radius * Math.sin(tlbraRadian),\n middleTop - radius * Math.sin(trblaRadian),\n middleTop + radius * Math.sin(tlbraRadian),\n middleTop + radius * Math.sin(trblaRadian),\n ];\n\n return {\n xRange: [Math.min(...xAxis), Math.max(...xAxis)],\n yRange: [Math.min(...yAxis), Math.max(...yAxis)],\n };\n};\n\nexport const getElementRange = (element: PPTElement) => {\n let minX: number, maxX: number, minY: number, maxY: number;\n\n if (element.type === 'line') {\n minX = element.left;\n maxX = element.left + Math.max(element.start[0], element.end[0]);\n minY = element.top;\n maxY = element.top + Math.max(element.start[1], element.end[1]);\n } else if ('rotate' in element && element.rotate) {\n const { left, top, width, height, rotate } = element;\n const { xRange, yRange } = getRectRotatedRange({ left, top, width, height, rotate });\n minX = xRange[0];\n maxX = xRange[1];\n minY = yRange[0];\n maxY = yRange[1];\n } else {\n minX = element.left;\n maxX = element.left + element.width;\n minY = element.top;\n maxY = element.top + element.height;\n }\n return { minX, maxX, minY, maxY };\n};\n\nexport const getTableSubThemeColor = (themeColor: string) => {\n const rgba = tinycolor(themeColor);\n return [rgba.setAlpha(0.3).toRgbString(), rgba.setAlpha(0.1).toRgbString()];\n};\n\nexport const getLineElementPath = (element: PPTLineElement) => {\n const startArr = Array.isArray(element.start) ? element.start : [0, 0];\n const endArr = Array.isArray(element.end) ? element.end : [100, 100];\n const start = startArr.join(',');\n const end = endArr.join(',');\n if (element.broken) {\n const mid = element.broken.join(',');\n return `M${start} L${mid} L${end}`;\n } else if (element.broken2) {\n const { minX, maxX, minY, maxY } = getElementRange(element);\n if (maxX - minX >= maxY - minY)\n return `M${start} L${element.broken2[0]},${startArr[1]} L${element.broken2[0]},${endArr[1]} ${end}`;\n return `M${start} L${startArr[0]},${element.broken2[1]} L${endArr[0]},${element.broken2[1]} ${end}`;\n } else if (element.curve) {\n const mid = element.curve.join(',');\n return `M${start} Q${mid} ${end}`;\n } else if (element.cubic) {\n const [c1, c2] = element.cubic;\n const p1 = c1.join(',');\n const p2 = c2.join(',');\n return `M${start} C${p1} ${p2} ${end}`;\n }\n return `M${start} L${end}`;\n};\n"],"names":[],"mappings":";;AAWO,MAAM,mBAAmB,GAAG,CAAC,OAA2B,KAAI;AACjE,IAAA,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO;IAExD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACtE,IAAA,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE;AAElE,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,GAAG,MAAM,GAAG,cAAc,IAAI,IAAI,CAAC,EAAE,IAAI,GAAG;AACrE,IAAA,MAAM,WAAW,GAAG,CAAC,CAAC,cAAc,GAAG,MAAM,IAAI,IAAI,CAAC,EAAE,IAAI,GAAG;AAE/D,IAAA,MAAM,UAAU,GAAG,IAAI,GAAG,KAAK,GAAG,CAAC;AACnC,IAAA,MAAM,SAAS,GAAG,GAAG,GAAG,MAAM,GAAG,CAAC;AAElC,IAAA,MAAM,KAAK,GAAG;QACZ,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;QAC3C,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;QAC3C,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;QAC3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AAC,IAAI,CAAC,GAAG,CAAC;AACnC,QAAA,OAAO,IAAI,KAAK,CAAA,EAAA,EAAK,GAAG,CAAA,CAAA,EAAI,GAAG,EAAE;IACnC;AAAO,SAAA,IAAI,OAAO,CAAC,KAAK,EAAE;QACxB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK;QAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACvB,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,EAAK,EAAE,IAAI,EAAE,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE;IACxC;AACA,IAAA,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,EAAA,EAAK,GAAG,EAAE;AAC5B;;;;"}
@@ -11,8 +11,8 @@ export interface PercentageGeometry {
11
11
  centerX: number;
12
12
  centerY: number;
13
13
  }
14
- export declare function getElementPercentageGeometry(element: PPTElement, viewportSize?: number): PercentageGeometry | null;
15
- export declare function findElementGeometry(elements: PPTElement[], elementId: string, viewportSize?: number): PercentageGeometry | null;
14
+ export declare function getElementPercentageGeometry(element: PPTElement, viewportSize?: number, viewportRatio?: number): PercentageGeometry | null;
15
+ export declare function findElementGeometry(elements: PPTElement[], elementId: string, viewportSize?: number, viewportRatio?: number): PercentageGeometry | null;
16
16
  export declare function findNearestCorner(geometry: PercentageGeometry): {
17
17
  x: number;
18
18
  y: number;
@@ -0,0 +1,44 @@
1
+ function getElementPercentageGeometry(element, viewportSize = 1000, viewportRatio = 0.5625) {
2
+ if (!('left' in element) ||
3
+ !('top' in element) ||
4
+ !('width' in element) ||
5
+ !('height' in element)) {
6
+ return null;
7
+ }
8
+ const { left, top, width, height } = element;
9
+ const x = (left / viewportSize) * 100;
10
+ const y = (top / (viewportSize * viewportRatio)) * 100;
11
+ const w = (width / viewportSize) * 100;
12
+ const h = (height / (viewportSize * viewportRatio)) * 100;
13
+ const centerX = x + w / 2;
14
+ const centerY = y + h / 2;
15
+ return { x, y, w, h, centerX, centerY };
16
+ }
17
+ function findElementGeometry(elements, elementId, viewportSize = 1000, viewportRatio = 0.5625) {
18
+ const element = elements.find((el) => el.id === elementId);
19
+ if (!element)
20
+ return null;
21
+ return getElementPercentageGeometry(element, viewportSize, viewportRatio);
22
+ }
23
+ function findNearestCorner(geometry) {
24
+ const { centerX, centerY } = geometry;
25
+ const corners = [
26
+ { x: 0, y: 0 },
27
+ { x: 100, y: 0 },
28
+ { x: 0, y: 100 },
29
+ { x: 100, y: 100 },
30
+ ];
31
+ let minDistance = Infinity;
32
+ let nearestCorner = corners[0];
33
+ for (const corner of corners) {
34
+ const distance = Math.sqrt(Math.pow(corner.x - centerX, 2) + Math.pow(corner.y - centerY, 2));
35
+ if (distance < minDistance) {
36
+ minDistance = distance;
37
+ nearestCorner = corner;
38
+ }
39
+ }
40
+ return nearestCorner;
41
+ }
42
+
43
+ export { findElementGeometry, findNearestCorner, getElementPercentageGeometry };
44
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","sources":["../../src/utils/geometry.ts"],"sourcesContent":["import type { PPTElement } from '@openmaic/dsl';\n\n/**\n * Percentage-based geometry (0-100 coordinate system)\n * Used by spotlight/laser overlays for responsive positioning.\n */\nexport interface PercentageGeometry {\n x: number;\n y: number;\n w: number;\n h: number;\n centerX: number;\n centerY: number;\n}\n\nexport function getElementPercentageGeometry(\n element: PPTElement,\n viewportSize: number = 1000,\n viewportRatio: number = 0.5625,\n): PercentageGeometry | null {\n if (\n !('left' in element) ||\n !('top' in element) ||\n !('width' in element) ||\n !('height' in element)\n ) {\n return null;\n }\n\n const { left, top, width, height } = element;\n\n const x = (left / viewportSize) * 100;\n const y = (top / (viewportSize * viewportRatio)) * 100;\n const w = (width / viewportSize) * 100;\n const h = (height / (viewportSize * viewportRatio)) * 100;\n\n const centerX = x + w / 2;\n const centerY = y + h / 2;\n\n return { x, y, w, h, centerX, centerY };\n}\n\nexport function findElementGeometry(\n elements: PPTElement[],\n elementId: string,\n viewportSize: number = 1000,\n viewportRatio: number = 0.5625,\n): PercentageGeometry | null {\n const element = elements.find((el) => el.id === elementId);\n if (!element) return null;\n return getElementPercentageGeometry(element, viewportSize, viewportRatio);\n}\n\nexport function findNearestCorner(geometry: PercentageGeometry): {\n x: number;\n y: number;\n} {\n const { centerX, centerY } = geometry;\n\n const corners = [\n { x: 0, y: 0 },\n { x: 100, y: 0 },\n { x: 0, y: 100 },\n { x: 100, y: 100 },\n ];\n\n let minDistance = Infinity;\n let nearestCorner = corners[0];\n\n for (const corner of corners) {\n const distance = Math.sqrt(Math.pow(corner.x - centerX, 2) + Math.pow(corner.y - centerY, 2));\n if (distance < minDistance) {\n minDistance = distance;\n nearestCorner = corner;\n }\n }\n\n return nearestCorner;\n}\n"],"names":[],"mappings":"AAeM,SAAU,4BAA4B,CAC1C,OAAmB,EACnB,YAAA,GAAuB,IAAI,EAC3B,aAAA,GAAwB,MAAM,EAAA;AAE9B,IAAA,IACE,EAAE,MAAM,IAAI,OAAO,CAAC;AACpB,QAAA,EAAE,KAAK,IAAI,OAAO,CAAC;AACnB,QAAA,EAAE,OAAO,IAAI,OAAO,CAAC;AACrB,QAAA,EAAE,QAAQ,IAAI,OAAO,CAAC,EACtB;AACA,QAAA,OAAO,IAAI;IACb;IAEA,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO;IAE5C,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,YAAY,IAAI,GAAG;AACrC,IAAA,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,YAAY,GAAG,aAAa,CAAC,IAAI,GAAG;IACtD,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,YAAY,IAAI,GAAG;AACtC,IAAA,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,YAAY,GAAG,aAAa,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AE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC;AAC7F,QAAA,IAAI,QAAQ,GAAG,WAAW,EAAE;YAC1B,WAAW,GAAG,QAAQ;YACtB,aAAa,GAAG,MAAM;QACxB;IACF;AAEA,IAAA,OAAO,aAAa;AACtB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmaic/renderer",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "React component for rendering PPTist-style Slide JSON, extracted from OpenMAIC.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,6 +23,10 @@
23
23
  "types": "./dist/snapshot/index.d.ts",
24
24
  "import": "./dist/snapshot/index.js"
25
25
  },
26
+ "./editing": {
27
+ "types": "./dist/editing/index.d.ts",
28
+ "import": "./dist/editing/index.js"
29
+ },
26
30
  "./fonts.css": "./fonts.css"
27
31
  },
28
32
  "files": [
@@ -42,6 +46,11 @@
42
46
  "react"
43
47
  ],
44
48
  "license": "MIT",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/THU-MAIC/OpenMAIC",
52
+ "directory": "packages/@openmaic/renderer"
53
+ },
45
54
  "publishConfig": {
46
55
  "registry": "https://registry.npmjs.org",
47
56
  "access": "public"
@@ -70,25 +79,31 @@
70
79
  "lucide-react": "^0.562.0",
71
80
  "tailwind-merge": "^3.4.0",
72
81
  "tinycolor2": "^1.6.0",
73
- "@openmaic/dsl": "0.0.1"
82
+ "@openmaic/dsl": "0.4.0"
74
83
  },
75
84
  "devDependencies": {
76
85
  "@rollup/plugin-commonjs": "^28.0.1",
77
86
  "@rollup/plugin-node-resolve": "^16.0.1",
78
87
  "@rollup/plugin-typescript": "^12.1.0",
88
+ "@testing-library/dom": "^10.4.1",
89
+ "@testing-library/react": "^16.3.2",
79
90
  "@types/katex": "^0.16.8",
80
91
  "@types/react": "^19",
81
92
  "@types/react-dom": "^19",
82
93
  "@types/tinycolor2": "^1.4.6",
94
+ "jsdom": "^29.1.1",
83
95
  "rollup": "^4.35.0",
96
+ "rollup-plugin-preserve-directives": "^0.4.0",
84
97
  "tslib": "^2.8.0",
85
98
  "typescript": "^5"
86
99
  },
87
100
  "scripts": {
88
101
  "clean": "rm -rf dist",
89
102
  "genfonts": "node scripts/generate-fonts-css.mjs",
90
- "build": "node scripts/generate-fonts-css.mjs && rm -rf dist && rollup -c && tsc --emitDeclarationOnly --declarationDir dist",
103
+ "gen-katex-fonts": "node scripts/generate-katex-fonts.mjs",
104
+ "build": "node scripts/generate-fonts-css.mjs && node scripts/generate-katex-fonts.mjs && rm -rf dist && rollup -c && tsc --emitDeclarationOnly --declarationDir dist",
91
105
  "dev": "rollup -c -w",
92
- "typecheck": "tsc --noEmit"
106
+ "typecheck": "tsc --noEmit",
107
+ "test": "vitest run"
93
108
  }
94
109
  }