@openmaic/renderer 0.0.1
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/DESIGN.md +247 -0
- package/FONTS.md +90 -0
- package/LICENSE +21 -0
- package/README.md +217 -0
- package/dist/SlideCanvas.d.ts +40 -0
- package/dist/SlideElement.d.ts +14 -0
- package/dist/chunks/BaseCodeElement-Bh-Bfdz6.js +1742 -0
- package/dist/chunks/BaseCodeElement-Bh-Bfdz6.js.map +1 -0
- package/dist/chunks/SlideCanvas-BwlcjqMl.js +469 -0
- package/dist/chunks/SlideCanvas-BwlcjqMl.js.map +1 -0
- package/dist/context.d.ts +25 -0
- package/dist/effects/HighlightOverlay.d.ts +7 -0
- package/dist/effects/LaserOverlay.d.ts +7 -0
- package/dist/effects/SpotlightOverlay.d.ts +7 -0
- package/dist/effects/ZoomWrapper.d.ts +9 -0
- package/dist/effects/index.d.ts +4 -0
- package/dist/elements/chart/BaseChartElement.d.ts +6 -0
- package/dist/elements/chart/Chart.d.ts +13 -0
- package/dist/elements/chart/chartOption.d.ts +15 -0
- package/dist/elements/code/BaseCodeElement.d.ts +6 -0
- package/dist/elements/image/BaseImageElement.d.ts +13 -0
- package/dist/elements/image/ImageOutline.d.ts +5 -0
- package/dist/elements/image/clipPaths.d.ts +13 -0
- package/dist/elements/image/useClipImage.d.ts +10 -0
- package/dist/elements/image/useFilter.d.ts +4 -0
- package/dist/elements/index.d.ts +14 -0
- package/dist/elements/index.js +10 -0
- package/dist/elements/index.js.map +1 -0
- package/dist/elements/latex/BaseLatexElement.d.ts +5 -0
- package/dist/elements/line/BaseLineElement.d.ts +6 -0
- package/dist/elements/line/LinePointMarker.d.ts +11 -0
- package/dist/elements/shape/BaseShapeElement.d.ts +5 -0
- package/dist/elements/shape/GradientDefs.d.ts +9 -0
- package/dist/elements/shape/PatternDefs.d.ts +6 -0
- package/dist/elements/shared/ElementOutline.d.ts +7 -0
- package/dist/elements/shared/useElementFill.d.ts +4 -0
- package/dist/elements/shared/useElementFlip.d.ts +3 -0
- package/dist/elements/shared/useElementOutline.d.ts +7 -0
- package/dist/elements/shared/useElementShadow.d.ts +4 -0
- package/dist/elements/table/BaseTableElement.d.ts +6 -0
- package/dist/elements/table/StaticTable.d.ts +6 -0
- package/dist/elements/table/tableUtils.d.ts +5 -0
- package/dist/elements/text/BaseTextElement.d.ts +6 -0
- package/dist/elements/video/BaseVideoElement.d.ts +13 -0
- package/dist/hooks/useSlideBackgroundStyle.d.ts +5 -0
- package/dist/hooks/useViewportSize.d.ts +27 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/snapshot/index.d.ts +46 -0
- package/dist/snapshot/index.js +347 -0
- package/dist/snapshot/index.js.map +1 -0
- package/dist/styles.d.ts +12 -0
- package/dist/types/effects.d.ts +25 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/element.d.ts +21 -0
- package/dist/utils/geometry.d.ts +19 -0
- package/font-licenses/ARPHIC-PL.txt +58 -0
- package/font-licenses/OFL.txt +101 -0
- package/font-licenses/ZcoolHappy-LICENSE.txt +16 -0
- package/fonts.css +45 -0
- package/package.json +94 -0
package/DESIGN.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# maic-renderer 设计稿(v1:只读画布)
|
|
2
|
+
|
|
3
|
+
> 配套计划:`docs/superpowers/plans/2026-05-28-maic-renderer-package.md`
|
|
4
|
+
> 原始 spec:`docs/superpowers/specs/2026-05-28-maic-renderer-package-design.md`
|
|
5
|
+
|
|
6
|
+
## 1. 目标
|
|
7
|
+
|
|
8
|
+
把 OpenMAIC 主仓 `components/maic-renderer/` 中的只读画布部分抽成独立 workspace 包,让任意 React + Tailwind 4 项目都能"装包 → 传 Slide → 直接渲染"。
|
|
9
|
+
|
|
10
|
+
**v1 范围限定为只读画布**(对应主仓 `Editor/ScreenCanvas.tsx` 子树)。编辑能力(`Editor/Canvas/*`、`Operate/*`、ProseMirror live editor)留给 v2。
|
|
11
|
+
|
|
12
|
+
理由:
|
|
13
|
+
1. 闭环最小可用,跟 `pptxtojson-pro` 形成「产 Slide → 渲 Slide」对子。
|
|
14
|
+
2. 编辑器接口面(选中态、命令、撤销、剪贴板、协作)定型后难改,第一版强行定下来大概率返工。
|
|
15
|
+
3. 只读包本身有独立价值(嵌课件、报告、回放、PDF 导出预览等)。
|
|
16
|
+
|
|
17
|
+
## 2. 设计决策
|
|
18
|
+
|
|
19
|
+
| # | 决策点 | 选择 | 理由 |
|
|
20
|
+
|---|--------|------|------|
|
|
21
|
+
| D1 | 范围 | 分两步:v1 只读 + v2 编辑 | 闭环最小,风险可控 |
|
|
22
|
+
| D2 | 数据 API | **纯 Props 主**;同时导出可选 Provider | 上手最快,进阶用户也照顾到 |
|
|
23
|
+
| D3 | 样式 | **要求消费者使用 Tailwind 4** | 工作量最小,跟主仓工程实践一致 |
|
|
24
|
+
| D4 | 特效层 | **包含**,4 个全做成可选 props,默认关 | 还原"OpenMAIC 同款画布"必备,但默认零负担 |
|
|
25
|
+
| D5 | 业务耦合元素 | **暴露 renderImage / renderVideo 插槽**,包内默认渲原生标签 | 包不感知业务,消费者按需注入 |
|
|
26
|
+
| D6 | i18n | 包不带文案 | UI 文案下放给消费者 |
|
|
27
|
+
| D7 | ProseMirror | v1 不依赖 | 只读用 dangerouslySetInnerHTML 就够,体积大幅缩小 |
|
|
28
|
+
| D8 | 包发布 | workspace 包,未来可发 npm;当前名 `maic-renderer`(同 `pptxtojson-pro` 风格) | 一致性 |
|
|
29
|
+
|
|
30
|
+
## 3. 对外 API
|
|
31
|
+
|
|
32
|
+
### 3.1 主入口
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { SlideCanvas, type SlideCanvasProps } from 'maic-renderer';
|
|
36
|
+
|
|
37
|
+
interface SlideCanvasProps {
|
|
38
|
+
/** 单页幻灯片数据(PPTist 风格) */
|
|
39
|
+
slide: Slide;
|
|
40
|
+
/** 画布缩放,默认 1 */
|
|
41
|
+
scale?: number;
|
|
42
|
+
/** 可选:覆盖 slide.background */
|
|
43
|
+
background?: SlideBackground;
|
|
44
|
+
/** 可选:4 个播放特效,默认全关 */
|
|
45
|
+
effects?: {
|
|
46
|
+
laser?: { elementId: string; color?: string; duration?: number };
|
|
47
|
+
spotlight?: { elementId: string };
|
|
48
|
+
highlight?: { elementId: string };
|
|
49
|
+
zoom?: { elementId: string; scale: number };
|
|
50
|
+
};
|
|
51
|
+
/** 可选:图片渲染插槽,消费者可注入 placeholder/retry 逻辑 */
|
|
52
|
+
renderImage?: (el: PPTImageElement, resolvedSrc: string) => React.ReactNode;
|
|
53
|
+
/** 可选:视频渲染插槽 */
|
|
54
|
+
renderVideo?: (el: PPTVideoElement) => React.ReactNode;
|
|
55
|
+
/** 可选:元素点击 */
|
|
56
|
+
onElementClick?: (el: PPTElement, event: React.MouseEvent) => void;
|
|
57
|
+
/** 透传外层 */
|
|
58
|
+
className?: string;
|
|
59
|
+
style?: React.CSSProperties;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3.2 Provider 高阶模式(可选)
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { SlideRendererProvider, useSlideContext } from 'maic-renderer';
|
|
67
|
+
|
|
68
|
+
<SlideRendererProvider slide={slide} scale={0.9}>
|
|
69
|
+
<SlideCanvas />
|
|
70
|
+
<MyCustomOverlay /> {/* 子组件 useSlideContext() 拿数据 */}
|
|
71
|
+
</SlideRendererProvider>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3.3 元素子组件(细粒度复用)
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import {
|
|
78
|
+
BaseTextElement, BaseShapeElement, BaseImageElement,
|
|
79
|
+
BaseLineElement, BaseChartElement, BaseLatexElement,
|
|
80
|
+
BaseTableElement, BaseVideoElement, BaseCodeElement,
|
|
81
|
+
} from 'maic-renderer/elements';
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 3.4 类型
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import type {
|
|
88
|
+
Slide, PPTElement, SlideBackground, SlideTheme,
|
|
89
|
+
PPTTextElement, PPTShapeElement, PPTImageElement,
|
|
90
|
+
PPTLineElement, PPTChartElement, PPTLatexElement,
|
|
91
|
+
PPTTableElement, PPTVideoElement, PPTCodeElement,
|
|
92
|
+
ImageElementClip, ImageElementFilters,
|
|
93
|
+
Gradient, GradientType, PPTElementOutline, PPTElementShadow,
|
|
94
|
+
} from 'maic-renderer/types';
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 4. 包结构
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
packages/maic-renderer/
|
|
101
|
+
├── package.json
|
|
102
|
+
├── README.md
|
|
103
|
+
├── DESIGN.md
|
|
104
|
+
├── tsconfig.json
|
|
105
|
+
├── rollup.config.js
|
|
106
|
+
└── src/
|
|
107
|
+
├── index.ts # 主入口
|
|
108
|
+
├── SlideCanvas.tsx # 替代 ScreenCanvas(props 驱动)
|
|
109
|
+
├── SlideElement.tsx # 替代 ScreenElement
|
|
110
|
+
├── context.tsx # Provider + useSlideContext
|
|
111
|
+
├── effects/
|
|
112
|
+
│ ├── index.ts
|
|
113
|
+
│ ├── HighlightOverlay.tsx
|
|
114
|
+
│ ├── SpotlightOverlay.tsx
|
|
115
|
+
│ ├── LaserOverlay.tsx
|
|
116
|
+
│ └── ZoomWrapper.tsx
|
|
117
|
+
├── elements/
|
|
118
|
+
│ ├── index.ts
|
|
119
|
+
│ ├── text/BaseTextElement.tsx
|
|
120
|
+
│ ├── shape/
|
|
121
|
+
│ │ ├── BaseShapeElement.tsx
|
|
122
|
+
│ │ ├── GradientDefs.tsx
|
|
123
|
+
│ │ └── PatternDefs.tsx
|
|
124
|
+
│ ├── image/
|
|
125
|
+
│ │ ├── BaseImageElement.tsx
|
|
126
|
+
│ │ ├── ImageOutline.tsx
|
|
127
|
+
│ │ ├── useClipImage.ts
|
|
128
|
+
│ │ └── useFilter.ts
|
|
129
|
+
│ ├── line/BaseLineElement.tsx
|
|
130
|
+
│ ├── chart/
|
|
131
|
+
│ │ ├── BaseChartElement.tsx
|
|
132
|
+
│ │ └── Chart.tsx
|
|
133
|
+
│ ├── latex/BaseLatexElement.tsx
|
|
134
|
+
│ ├── table/BaseTableElement.tsx
|
|
135
|
+
│ ├── video/BaseVideoElement.tsx
|
|
136
|
+
│ ├── code/BaseCodeElement.tsx
|
|
137
|
+
│ └── shared/
|
|
138
|
+
│ ├── ElementOutline.tsx
|
|
139
|
+
│ ├── useElementFill.ts
|
|
140
|
+
│ ├── useElementOutline.ts
|
|
141
|
+
│ ├── useElementShadow.ts
|
|
142
|
+
│ └── useElementFlip.ts
|
|
143
|
+
├── hooks/
|
|
144
|
+
│ ├── useSlideBackgroundStyle.ts
|
|
145
|
+
│ └── useViewportSize.ts
|
|
146
|
+
├── utils/
|
|
147
|
+
│ ├── cn.ts
|
|
148
|
+
│ ├── geometry.ts
|
|
149
|
+
│ └── element.ts
|
|
150
|
+
└── types/
|
|
151
|
+
├── slides.ts # 从 lib/types/slides 拷贝
|
|
152
|
+
├── effects.ts # 新增
|
|
153
|
+
└── index.ts
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 5. 依赖
|
|
157
|
+
|
|
158
|
+
**peerDependencies**:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"react": ">=18",
|
|
163
|
+
"react-dom": ">=18",
|
|
164
|
+
"motion": ">=11",
|
|
165
|
+
"tailwindcss": ">=4"
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**dependencies**(运行时必备):
|
|
170
|
+
|
|
171
|
+
- `katex` — latex 渲染
|
|
172
|
+
- `tinycolor2` — 颜色工具
|
|
173
|
+
- `lucide-react` — 图标
|
|
174
|
+
- `clsx`、`tailwind-merge` — `cn` helper
|
|
175
|
+
|
|
176
|
+
**chart 库**:复用主仓现用方案,T10 实现阶段确认。开发阶段先 inline 进 dependencies,若体积过大改 peerDep。
|
|
177
|
+
|
|
178
|
+
**ProseMirror 系列**:v1 完全不依赖。
|
|
179
|
+
|
|
180
|
+
## 6. 构建
|
|
181
|
+
|
|
182
|
+
跟 `pptxtojson-pro` 完全一致:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
pnpm build # rollup -c && tsc --emitDeclarationOnly
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
产物:
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
dist/
|
|
192
|
+
├── index.{js,cjs,d.ts}
|
|
193
|
+
├── elements/index.{js,cjs,d.ts}
|
|
194
|
+
└── types/index.{js,cjs,d.ts}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## 7. 关键解耦点
|
|
198
|
+
|
|
199
|
+
### 7.1 ScreenCanvas → SlideCanvas
|
|
200
|
+
|
|
201
|
+
| 原 | 新 |
|
|
202
|
+
|----|----|
|
|
203
|
+
| `useCanvasStore.use.canvasScale()` | `props.scale ?? 1` |
|
|
204
|
+
| `useSceneSelector(c => c.canvas.elements)` | `props.slide.elements` |
|
|
205
|
+
| `useSceneSelector(c => c.canvas.background)` | `props.background ?? props.slide.background` |
|
|
206
|
+
| `useCanvasStore.use.laserElementId/Options()` | `props.effects?.laser` |
|
|
207
|
+
| `useCanvasStore.use.zoomTarget()` | `props.effects?.zoom` |
|
|
208
|
+
| `findElementGeometry(...)` | 拷贝进 `utils/geometry.ts` |
|
|
209
|
+
|
|
210
|
+
### 7.2 ScreenElement → SlideElement
|
|
211
|
+
|
|
212
|
+
`theme.fontColor` / `theme.fontName` 改成从 `props.slide.theme` 读取;`useSceneSelector` 移除。
|
|
213
|
+
|
|
214
|
+
### 7.3 BaseImageElement
|
|
215
|
+
|
|
216
|
+
包内退化成纯 `<img>` 版本(含 clip/filter/outline/shadow),所有 placeholder / retry / i18n 逻辑剥离。消费者通过 `renderImage` 注入业务版本。
|
|
217
|
+
|
|
218
|
+
### 7.4 BaseVideoElement
|
|
219
|
+
|
|
220
|
+
同上,纯 `<video>`。
|
|
221
|
+
|
|
222
|
+
### 7.5 其余 Base*Element
|
|
223
|
+
|
|
224
|
+
只有类型导入路径要改(`@/lib/types/slides` → `../../types/slides`),无业务耦合。
|
|
225
|
+
|
|
226
|
+
## 8. 验收标准
|
|
227
|
+
|
|
228
|
+
1. `pnpm --filter maic-renderer build` 通过,产出干净 dist
|
|
229
|
+
2. 主仓 `/maic-renderer-demo` 路由用包渲染一份手写 Slide,目视与原 `ScreenCanvas` 一致
|
|
230
|
+
3. v1 **不替换主仓既有调用**
|
|
231
|
+
|
|
232
|
+
## 9. v2 预告
|
|
233
|
+
|
|
234
|
+
- `Editor/Canvas/*` 抽到包内 `editing/`
|
|
235
|
+
- ProseMirror live editor
|
|
236
|
+
- 选中/拖拽/resize/旋转/裁剪/对齐线/标尺
|
|
237
|
+
- 撤销/重做/剪贴板
|
|
238
|
+
- API:`<SlideEditor slide editable onChange={...} />`
|
|
239
|
+
|
|
240
|
+
## 10. 风险
|
|
241
|
+
|
|
242
|
+
| 风险 | 等级 | 缓解 |
|
|
243
|
+
|------|------|------|
|
|
244
|
+
| Chart 库依赖不明,包体积可能膨胀 | 中 | T10 阶段确认;若 >200KB gz 改 peerDep |
|
|
245
|
+
| Tailwind 4 强依赖筛掉很多消费者 | 中 | README 显著说明;v3 再考虑编译 CSS |
|
|
246
|
+
| 主仓 `Slide` 类型未来演进,包内拷贝版会漂移 | 低 | 后续可通过 `pptxtojson-pro` 已有的 `openmaic/types/slides.ts` 三方共享 |
|
|
247
|
+
| BaseImageElement 砍业务后主仓现有页面会丢功能 | **无影响** | 本次任务不替换主仓调用,主仓继续用自己的 `BaseImageElement` |
|
package/FONTS.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Bundled font licenses & attribution
|
|
2
|
+
|
|
3
|
+
`@openmaic/renderer` does **not** embed any font binaries. `fonts.css` only declares
|
|
4
|
+
`@font-face` rules whose `src` points at self-hosted woff2 files on object
|
|
5
|
+
storage (`https://file.maic.chat/fonts/<name>.woff2`). Serving those faces is a
|
|
6
|
+
form of redistribution, so each face below must be cleared for redistribution
|
|
7
|
+
and attributed here. This file is the font attribution/clearance record; it is
|
|
8
|
+
**separate** from the package's own `LICENSE` (MIT), which does not cover
|
|
9
|
+
the fonts.
|
|
10
|
+
|
|
11
|
+
> The importer does not remap fonts: it passes each slide's original
|
|
12
|
+
> `font-family` names through unchanged. A name only renders in one of the faces
|
|
13
|
+
> below if it matches; otherwise the browser falls back. This list mirrors
|
|
14
|
+
> `fonts.config.mjs`.
|
|
15
|
+
|
|
16
|
+
## Whitelist (6 families)
|
|
17
|
+
|
|
18
|
+
| Family (`font-family`) | 中文名 | License | Redistribution | Copyright / source |
|
|
19
|
+
| ---------------------- | ------ | ------- | :------------: | ------------------ |
|
|
20
|
+
| `SourceHanSans` | 思源黑体 | SIL OFL 1.1 | ✅ | © 2014–2021 Adobe, Reserved Font Name "Source Han Sans" — https://github.com/adobe-fonts/source-han-sans |
|
|
21
|
+
| `SourceHanSerif` | 思源宋体 | SIL OFL 1.1 | ✅ | © 2017–2021 Adobe, Reserved Font Name "Source Han Serif" — https://github.com/adobe-fonts/source-han-serif |
|
|
22
|
+
| `LXGWWenKai` | 霞鹜文楷 | SIL OFL 1.1 | ✅ | © 2021 The LXGW WenKai Project Authors — https://github.com/lxgw/LxgwWenKai |
|
|
23
|
+
| `ZhuQueFangSong` | 朱雀仿宋 | SIL OFL 1.1 | ✅ | © 2023 Zhejiang JadeFoci Technology Co. LTD — https://www.jadefoci.com/ |
|
|
24
|
+
| `ZcoolHappy` | 站酷快乐体 | 站酷 (ZCOOL) free-use license (永久免费授权所有人使用,可免费商用) | ✅ (conditions) | © ZCOOL (站酷), designers retain attribution — [license](./font-licenses/ZcoolHappy-LICENSE.txt) |
|
|
25
|
+
| `WenDingPLKaiTi` | 文鼎PL简中楷 (AR PL KaitiM GB) | Arphic Public License (1999) | ✅ | © 1994–1999 Arphic Technology Co., Ltd. — [license](./font-licenses/ARPHIC-PL.txt) |
|
|
26
|
+
|
|
27
|
+
✅ = free to redistribute (bundle/embed/serve) as long as its conditions are met
|
|
28
|
+
(notice/license travels with it; not sold on its own). The four OFL faces are
|
|
29
|
+
OFL 1.1; `ZcoolHappy` is permanently free for everyone to use with the
|
|
30
|
+
conditions noted below.
|
|
31
|
+
|
|
32
|
+
### `ZcoolHappy` — note
|
|
33
|
+
|
|
34
|
+
Permanently free for everyone to use, including commercial use, per ZCOOL's
|
|
35
|
+
statement ([`font-licenses/ZcoolHappy-LICENSE.txt`](./font-licenses/ZcoolHappy-LICENSE.txt)).
|
|
36
|
+
Conditions: keep the original font name unchanged, do not resell the font as a
|
|
37
|
+
standalone commodity, and retain the designers' attribution. Serving it from our
|
|
38
|
+
CDN as part of this free package meets those conditions.
|
|
39
|
+
|
|
40
|
+
## SIL Open Font License 1.1 (the 4 OFL faces above)
|
|
41
|
+
|
|
42
|
+
OFL §2 requires the copyright notice + this license to accompany every
|
|
43
|
+
redistributed copy. The full OFL 1.1 text and the four per-face copyright lines
|
|
44
|
+
are bundled at [`font-licenses/OFL.txt`](./font-licenses/OFL.txt).
|
|
45
|
+
|
|
46
|
+
## `WenDingPLKaiTi` (AR PL KaitiM GB) — Arphic Public License 1999
|
|
47
|
+
|
|
48
|
+
The `WenDingPLKaiTi` family served here **is a WOFF2 conversion / distribution
|
|
49
|
+
of `AR PL KaitiM GB` (文鼎 PL 简中楷)** licensed under the Arphic Public License.
|
|
50
|
+
`AR PL KaitiM GB` is one of the four fonts Arphic Technology released in 1999
|
|
51
|
+
under that license — an FSF-recognized copyleft free-software license that
|
|
52
|
+
**explicitly permits commercial use and verbatim redistribution** ("You may copy
|
|
53
|
+
and distribute verbatim copies of this Font in any medium, without restriction,
|
|
54
|
+
provided that you retain this license file (ARPHICPL.TXT) unaltered in all
|
|
55
|
+
copies"). Arphic reconfirmed in 2022 that these four 1999 faces remain free for
|
|
56
|
+
commercial use (distinct from the 2010 non-commercial license).
|
|
57
|
+
|
|
58
|
+
**Identity verified from the woff2's embedded `name` table** (so the
|
|
59
|
+
`WenDingPLKaiTi` ⇄ `AR PL KaitiM GB` correspondence is provable, not asserted):
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
nameID 1/4 Family/Full : AR PL KaitiM GB
|
|
63
|
+
nameID 0 Copyright : (c) Copyright 1994-1999, Arphic Technology Co., Ltd.
|
|
64
|
+
nameID 7 Trademark : Arphic is a registered trademark of Arphic Technology Co., Ltd.
|
|
65
|
+
nameID 8/9 Manufacturer/Designer : Arphic Technology Co., Ltd.
|
|
66
|
+
nameID 11 Vendor URL : http://www.arphic.com.tw
|
|
67
|
+
nameID 13 License : ARPHIC PUBLIC LICENSE (full text embedded)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
(Reproduce with `fc-scan` or `python -m fontTools.ttx -t name <file>`.)
|
|
71
|
+
|
|
72
|
+
**Modification notice (Arphic PL §2.a):** the only changes from the original
|
|
73
|
+
`AR PL KaitiM GB` are (1) format conversion from TrueType to WOFF2 and (2) the
|
|
74
|
+
exposed `font-family` name `WenDingPLKaiTi`. No glyphs were modified. The
|
|
75
|
+
verbatim license is bundled at
|
|
76
|
+
[`font-licenses/ARPHIC-PL.txt`](./font-licenses/ARPHIC-PL.txt) and must be kept
|
|
77
|
+
unaltered alongside the served font.
|
|
78
|
+
|
|
79
|
+
## Removed faces
|
|
80
|
+
|
|
81
|
+
Faces previously bundled but **dropped** from the whitelist because their
|
|
82
|
+
redistribution terms are not clearly permissive:
|
|
83
|
+
|
|
84
|
+
- The FangZheng family (Hei / Kai / ShuSong / FangSong), MiSans, DeYiHei and
|
|
85
|
+
several display faces — commercially licensed.
|
|
86
|
+
- `AlibabaPuHuiTi` (阿里巴巴普惠体) — free for commercial **use**, but its license
|
|
87
|
+
grants no explicit redistribution/re-host right (unlike OFL), so it was dropped
|
|
88
|
+
to keep redistribution unambiguous.
|
|
89
|
+
|
|
90
|
+
If any are reinstated, add a cleared license entry above first.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 THU-MAIC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# @openmaic/renderer
|
|
2
|
+
|
|
3
|
+
React component for rendering PPTist-style `Slide` JSON. Extracted from [OpenMAIC](https://github.com/THU-MAIC/OpenMAIC).
|
|
4
|
+
|
|
5
|
+
> **v1 = read-only canvas.** Editing (selection, drag/resize, ProseMirror inline editor) is planned for v2.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @openmaic/renderer
|
|
11
|
+
# or
|
|
12
|
+
npm install @openmaic/renderer
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Required peers:
|
|
16
|
+
|
|
17
|
+
- `react >= 18`
|
|
18
|
+
- `react-dom >= 18`
|
|
19
|
+
- `motion >= 11`
|
|
20
|
+
- `tailwindcss >= 4` — **the package emits Tailwind 4 arbitrary-value classes, consumers must use Tailwind 4**
|
|
21
|
+
|
|
22
|
+
Optional peers (install only if your slides use the corresponding element type):
|
|
23
|
+
|
|
24
|
+
- `echarts >= 5` — for chart elements
|
|
25
|
+
- `shiki >= 1` — for code elements
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { SlideCanvas, type Slide } from '@openmaic/renderer';
|
|
31
|
+
|
|
32
|
+
const slide: Slide = {
|
|
33
|
+
id: 'demo-1',
|
|
34
|
+
viewportSize: 1000,
|
|
35
|
+
viewportRatio: 0.5625,
|
|
36
|
+
theme: {
|
|
37
|
+
backgroundColor: '#ffffff',
|
|
38
|
+
themeColors: ['#5b8def'],
|
|
39
|
+
fontColor: '#222222',
|
|
40
|
+
fontName: 'sans-serif',
|
|
41
|
+
},
|
|
42
|
+
elements: [
|
|
43
|
+
{
|
|
44
|
+
type: 'text',
|
|
45
|
+
id: 't1',
|
|
46
|
+
left: 100,
|
|
47
|
+
top: 80,
|
|
48
|
+
width: 800,
|
|
49
|
+
height: 60,
|
|
50
|
+
rotate: 0,
|
|
51
|
+
content: '<p>Hello, Slide</p>',
|
|
52
|
+
defaultFontName: 'sans-serif',
|
|
53
|
+
defaultColor: '#222',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
background: { type: 'solid', color: '#ffffff' },
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default function Demo() {
|
|
60
|
+
return (
|
|
61
|
+
<div style={{ width: 800, height: 450 }}>
|
|
62
|
+
<SlideCanvas slide={slide} />
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The canvas auto-fits its parent container. The parent must have a defined `width × height`.
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
### `<SlideCanvas slide effects? renderImage? renderVideo? onElementClick? scale? background? />`
|
|
73
|
+
|
|
74
|
+
The main read-only entry. Reads everything from props; zero global state.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
interface SlideCanvasProps {
|
|
78
|
+
slide?: Slide; // required unless via <SlideRendererProvider>
|
|
79
|
+
scale?: number; // omit = auto-fit container
|
|
80
|
+
background?: SlideBackground; // overrides slide.background
|
|
81
|
+
effects?: SlideEffects; // laser / spotlight / highlight / zoom, all default off
|
|
82
|
+
renderImage?: (el, src) => ReactNode;
|
|
83
|
+
renderVideo?: (el) => ReactNode;
|
|
84
|
+
onElementClick?: (el, event) => void;
|
|
85
|
+
className?: string;
|
|
86
|
+
style?: CSSProperties;
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Play-time effects
|
|
91
|
+
|
|
92
|
+
All effects are off by default. Pass any combination via `effects`:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
<SlideCanvas
|
|
96
|
+
slide={slide}
|
|
97
|
+
effects={{
|
|
98
|
+
laser: { elementId: 't1', color: '#ff3b30' },
|
|
99
|
+
spotlight: { elementId: 't1' },
|
|
100
|
+
highlight: { elementId: 't1', color: '#ff6b6b', animated: true },
|
|
101
|
+
zoom: { elementId: 't1', scale: 1.5 },
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Media injection slots
|
|
107
|
+
|
|
108
|
+
The package's `BaseImageElement` and `BaseVideoElement` render plain `<img>` / `<video>` and know nothing about your media pipeline. Inject business behaviour via the `renderImage` / `renderVideo` slots:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<SlideCanvas
|
|
112
|
+
slide={slide}
|
|
113
|
+
renderImage={(el, src) => (
|
|
114
|
+
src.startsWith('placeholder:')
|
|
115
|
+
? <MyPlaceholder taskId={src} />
|
|
116
|
+
: <img src={resolveCdnUrl(src)} alt="" style={{ width: '100%', height: '100%' }} />
|
|
117
|
+
)}
|
|
118
|
+
/>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `<SlideRendererProvider>` + `useSlideContext()`
|
|
122
|
+
|
|
123
|
+
Optional high-order pattern when sibling overlays need the same slide data:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
import { SlideRendererProvider, SlideCanvas, useSlideContext } from '@openmaic/renderer';
|
|
127
|
+
|
|
128
|
+
function MyAnnotationLayer() {
|
|
129
|
+
const { slide } = useSlideContext();
|
|
130
|
+
return <div>Annotations for {slide.id}</div>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
<SlideRendererProvider slide={slide} scale={0.9}>
|
|
134
|
+
<SlideCanvas /> {/* reads slide/scale from context */}
|
|
135
|
+
<MyAnnotationLayer />
|
|
136
|
+
</SlideRendererProvider>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Granular components — `@openmaic/renderer/elements`
|
|
140
|
+
|
|
141
|
+
If you want to compose your own layout instead of using `SlideCanvas`, the 9 base elements are exported individually:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import {
|
|
145
|
+
BaseTextElement, BaseShapeElement, BaseImageElement,
|
|
146
|
+
BaseLineElement, BaseChartElement, BaseLatexElement,
|
|
147
|
+
BaseTableElement, BaseVideoElement, BaseCodeElement,
|
|
148
|
+
ElementOutline,
|
|
149
|
+
} from '@openmaic/renderer/elements';
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Each accepts `{ elementInfo: PPTXxxElement }`. Image/Video also take a render slot.
|
|
153
|
+
|
|
154
|
+
### Types — `@openmaic/renderer/types`
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import type {
|
|
158
|
+
Slide, PPTElement, SlideBackground, SlideTheme,
|
|
159
|
+
PPTTextElement, PPTShapeElement, PPTImageElement,
|
|
160
|
+
PPTLineElement, PPTChartElement, PPTLatexElement,
|
|
161
|
+
PPTTableElement, PPTVideoElement, PPTCodeElement,
|
|
162
|
+
ImageElementClip, ImageElementFilters,
|
|
163
|
+
Gradient, GradientType, PPTElementOutline, PPTElementShadow,
|
|
164
|
+
SlideEffects, LaserEffectOptions, SpotlightEffectOptions,
|
|
165
|
+
HighlightEffectOptions, ZoomEffectOptions,
|
|
166
|
+
} from '@openmaic/renderer/types';
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Tailwind 4 setup
|
|
170
|
+
|
|
171
|
+
Ensure your `tailwind.config.{ts,js}` includes the package source:
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
export default {
|
|
175
|
+
content: [
|
|
176
|
+
'./src/**/*.{ts,tsx}',
|
|
177
|
+
'./node_modules/@openmaic/renderer/dist/**/*.{js,cjs}',
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Fonts (optional, CDN-hosted)
|
|
183
|
+
|
|
184
|
+
Slides imported from PowerPoint often reference Chinese faces that aren't
|
|
185
|
+
installed on the viewer's machine. The package ships a `fonts.css` with
|
|
186
|
+
`@font-face` rules for a small whitelist of self-hosted CJK faces — import it
|
|
187
|
+
once at your app shell to make those faces available:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
import '@openmaic/renderer/fonts.css';
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
> **Runtime dependency — read this.** The `@font-face` `src` URLs point at an
|
|
194
|
+
> external font host (`https://file.maic.chat/fonts/<name>.woff2`); the woff2
|
|
195
|
+
> files are **not** bundled in the package. So this is a hard runtime dependency:
|
|
196
|
+
> the host must be **reachable and CORS-enabled** from the consumer's app, or the
|
|
197
|
+
> browser will **silently fall back to system fonts** (no error, just different
|
|
198
|
+
> glyphs/metrics). If you need a different origin (self-hosting, air-gapped, a
|
|
199
|
+
> private CDN), change `FONT_CDN_BASE_URL` in `fonts.config.mjs` and regenerate
|
|
200
|
+
> with `pnpm run genfonts`.
|
|
201
|
+
>
|
|
202
|
+
> The import is **optional** — slides render fine without it, using whatever
|
|
203
|
+
> fonts the system provides. See [FONTS.md](./FONTS.md) for the face list and
|
|
204
|
+
> their licenses.
|
|
205
|
+
|
|
206
|
+
## Companion package
|
|
207
|
+
|
|
208
|
+
[`@openmaic/importer`](../importer) converts `.pptx` files to the same `Slide[]` shape, so you can do `.pptx → @openmaic/renderer` end-to-end.
|
|
209
|
+
|
|
210
|
+
## See also
|
|
211
|
+
|
|
212
|
+
- [DESIGN.md](./DESIGN.md) — package design decisions and scope
|
|
213
|
+
- v2 will add editing (`<SlideEditor editable onChange />`); the read-only `<SlideCanvas>` API will remain stable
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { PPTElement, PPTImageElement, PPTVideoElement, Slide, SlideBackground } from '@openmaic/dsl';
|
|
3
|
+
import type { SlideEffects } from './types/effects';
|
|
4
|
+
export interface SlideCanvasProps {
|
|
5
|
+
/**
|
|
6
|
+
* Single slide data (PPTist-style). May be omitted when this component is
|
|
7
|
+
* rendered inside a `<SlideRendererProvider>` that supplies it.
|
|
8
|
+
*/
|
|
9
|
+
slide?: Slide;
|
|
10
|
+
/**
|
|
11
|
+
* Canvas scale. When omitted, the canvas auto-fits the container using
|
|
12
|
+
* `slide.viewportSize` and `slide.viewportRatio`. Set to a fixed number
|
|
13
|
+
* (e.g. 1) to skip auto-fit and render at slide-native dimensions.
|
|
14
|
+
*/
|
|
15
|
+
scale?: number;
|
|
16
|
+
/** Override `slide.background`. */
|
|
17
|
+
background?: SlideBackground;
|
|
18
|
+
/** Optional play-time effects, all default off. */
|
|
19
|
+
effects?: SlideEffects;
|
|
20
|
+
/** Replace default <img> rendering for image elements. */
|
|
21
|
+
renderImage?: (element: PPTImageElement, resolvedSrc: string) => ReactNode;
|
|
22
|
+
/** Replace default <video> rendering for video elements. */
|
|
23
|
+
renderVideo?: (element: PPTVideoElement) => ReactNode;
|
|
24
|
+
/** Click handler invoked on any element. */
|
|
25
|
+
onElementClick?: (element: PPTElement, event: React.MouseEvent) => void;
|
|
26
|
+
/** Class on the outer container. */
|
|
27
|
+
className?: string;
|
|
28
|
+
/** Inline style on the outer container. */
|
|
29
|
+
style?: CSSProperties;
|
|
30
|
+
/**
|
|
31
|
+
* Card-style chrome on the inner slide container (drop shadow + rounded
|
|
32
|
+
* corners). Defaults to `true` for on-screen previews. Snapshot pipelines
|
|
33
|
+
* pass `false` so the captured PNG matches the source PPT's edges exactly
|
|
34
|
+
* — html2canvas would otherwise bake the 1px shadow outline and the
|
|
35
|
+
* 0.5rem corner radius into the output and the comparator reads them as
|
|
36
|
+
* a thin border + rounded corners that the original PPT does not have.
|
|
37
|
+
*/
|
|
38
|
+
chrome?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare function SlideCanvas(props: SlideCanvasProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type PPTElement, type PPTImageElement, type PPTVideoElement, type SlideTheme } from '@openmaic/dsl';
|
|
3
|
+
export interface SlideElementProps {
|
|
4
|
+
elementInfo: PPTElement;
|
|
5
|
+
elementIndex: number;
|
|
6
|
+
theme?: Pick<SlideTheme, 'fontColor' | 'fontName'>;
|
|
7
|
+
animate?: boolean;
|
|
8
|
+
renderImage?: (element: PPTImageElement, resolvedSrc: string) => ReactNode;
|
|
9
|
+
renderVideo?: (element: PPTVideoElement) => ReactNode;
|
|
10
|
+
onElementClick?: (element: PPTElement, event: React.MouseEvent) => void;
|
|
11
|
+
/** Prefix used for the root div id — must match SpotlightOverlay's `elementIdPrefix`. */
|
|
12
|
+
idPrefix?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function SlideElement({ elementInfo, elementIndex, theme, animate, renderImage, renderVideo, onElementClick, idPrefix, }: SlideElementProps): import("react/jsx-runtime").JSX.Element | null;
|