@netless/app-presentation 0.1.9-beta.8 → 0.1.10
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/README-zh.md +173 -0
- package/README.md +94 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.global.js +296 -5489
- package/dist/index.js +296 -5489
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +296 -5489
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/app-presentation.ts +1 -1
- package/src/scrollbar/index.ts +3 -2
package/README-zh.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# @netless/app-presentation
|
|
2
|
+
|
|
3
|
+
一个 [Netless App](https://github.com/netless-io/netless-app),用于将多张图片作为演示文稿幻灯片展示。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
<pre>npm add <strong>@netless/app-presentation</strong></pre>
|
|
8
|
+
|
|
9
|
+
## 使用方法
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { register } from "@netless/fastboard"
|
|
13
|
+
import { install } from "@netless/app-presentation"
|
|
14
|
+
|
|
15
|
+
install(register, {
|
|
16
|
+
as: 'DocsViewer',
|
|
17
|
+
appOptions: {
|
|
18
|
+
// 启用滚动条功能
|
|
19
|
+
useScrollbar: true,
|
|
20
|
+
// 启用裁剪视图功能,只显示页面内容区域
|
|
21
|
+
useClipView: true,
|
|
22
|
+
// 滚动条事件回调
|
|
23
|
+
scrollbarEventCallback: {
|
|
24
|
+
onScrollCameraUpdated: (appid, originScale, scale) => {
|
|
25
|
+
console.log('相机缩放已更新', appid, scale)
|
|
26
|
+
},
|
|
27
|
+
onScrollbarDragEnd: () => {
|
|
28
|
+
console.log('滚动条拖拽已结束')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 将应用插入房间
|
|
36
|
+
|
|
37
|
+
如果你以 `{ as: 'DocsViewer' }` 的方式安装了这个应用,请调用 [`fastboard.insertDocs()`](https://github.com/netless-io/fastboard#insert-pdf-ppt-and-pptx)。
|
|
38
|
+
|
|
39
|
+
<details><summary>否则…</summary>
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
// 假设你已经获得了演示文稿页面的数据结构
|
|
43
|
+
const data = [
|
|
44
|
+
// [preview] 字段是可选的
|
|
45
|
+
{ width: 1024, height: 768, url: 'url/to/1.png', preview: 'url/to/1.small.png' },
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
// 现在调用 addApp()
|
|
49
|
+
fastboard.manager.addApp({
|
|
50
|
+
kind: 'Presentation',
|
|
51
|
+
options: {
|
|
52
|
+
// 挂载白板场景的文件夹名称
|
|
53
|
+
// 相同的文件夹名称将防止你再次插入
|
|
54
|
+
scenePath: `/presentation/foo`,
|
|
55
|
+
// 应用窗口标题
|
|
56
|
+
title: 'a.pdf',
|
|
57
|
+
// 白板场景规范
|
|
58
|
+
scenes: data.map((e, i) => ({
|
|
59
|
+
name: String(i + 1),
|
|
60
|
+
ppt: {
|
|
61
|
+
src: e.url,
|
|
62
|
+
width: e.width,
|
|
63
|
+
height: e.height,
|
|
64
|
+
previewURL: e.preview
|
|
65
|
+
}
|
|
66
|
+
}))
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
请注意,如果你没有使用 `{ as: 'DocsViewer' }` 替换 DocsViewer 应用,
|
|
72
|
+
[`dispatchDocsEvent()`](https://github.com/netless-io/fastboard#control-the-pdfpptx-apps)
|
|
73
|
+
函数将无法在 Presentation 应用上工作。这是因为该函数只处理类型为 `DocsViewer` 或 `Slide` 的应用。
|
|
74
|
+
|
|
75
|
+
</details>
|
|
76
|
+
|
|
77
|
+
### 应用选项
|
|
78
|
+
|
|
79
|
+
#### `useScrollbar`
|
|
80
|
+
启用滚动条功能,提供水平和垂直滚动条用于导航和查看演示文稿。
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
install(register, {
|
|
84
|
+
as: 'DocsViewer',
|
|
85
|
+
appOptions: {
|
|
86
|
+
useScrollbar: true,
|
|
87
|
+
scrollbarEventCallback: {
|
|
88
|
+
onScrollCameraUpdated: (appid, originScale, scale) => {
|
|
89
|
+
// 当相机缩放更新时触发
|
|
90
|
+
},
|
|
91
|
+
onScrollbarDragEnd: () => {
|
|
92
|
+
// 当滚动条拖拽结束时触发
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### `useClipView`
|
|
100
|
+
启用裁剪视图功能,只显示页面内容区域,隐藏白板区域外的内容。
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
install(register, {
|
|
104
|
+
as: 'DocsViewer',
|
|
105
|
+
appOptions: {
|
|
106
|
+
useClipView: true
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 应用结果 API
|
|
112
|
+
|
|
113
|
+
#### `screenshotCurrentPageAsync(context, width?, height?)`
|
|
114
|
+
异步截图当前页面到 Canvas 上下文。支持自定义宽度和高度。
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
const app = fastboard.manager.queryOne(appId)
|
|
118
|
+
if (app && app.kind === 'DocsViewer') {
|
|
119
|
+
const controller = app.appResult
|
|
120
|
+
const canvas = document.createElement('canvas')
|
|
121
|
+
const { width, height } = controller.getPageSize()
|
|
122
|
+
canvas.width = width
|
|
123
|
+
canvas.height = height
|
|
124
|
+
const ctx = canvas.getContext('2d')
|
|
125
|
+
if (ctx) {
|
|
126
|
+
await controller.screenshotCurrentPageAsync(ctx, width, height)
|
|
127
|
+
// 使用 canvas 进行后续操作,如导出图片
|
|
128
|
+
canvas.toBlob((blob) => {
|
|
129
|
+
if (!blob) {
|
|
130
|
+
alert("context.toBlob() 失败!")
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
const url = URL.createObjectURL(blob)
|
|
134
|
+
const a = document.createElement('a')
|
|
135
|
+
a.href = url
|
|
136
|
+
a.download = 'screenshot.png'
|
|
137
|
+
a.click()
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### `getPageSize()`
|
|
144
|
+
获取当前页面的尺寸(宽度和高度)。
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
const app = fastboard.manager.queryOne(appId)
|
|
148
|
+
if (app && app.kind === 'DocsViewer') {
|
|
149
|
+
const controller = app.appResult
|
|
150
|
+
const { width, height } = controller.getPageSize()
|
|
151
|
+
console.log(`当前页面尺寸: ${width}x${height}`)
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 开发
|
|
156
|
+
|
|
157
|
+
参见 [编写 Netless App](https://github.com/netless-io/fastboard/blob/main/docs/en/app.md)。
|
|
158
|
+
|
|
159
|
+
如果只想开发 UI 部分,运行:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
$ pnpm build
|
|
163
|
+
$ pnpm dev
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
然后访问 http://localhost:5173/ 在本地查看应用。
|
|
167
|
+
|
|
168
|
+
要在真实的白板房间中开发,请添加一个包含房间 uuid 和 token 的 .env.local 文件,
|
|
169
|
+
然后访问 http://localhost:5173/e2e/。
|
|
170
|
+
|
|
171
|
+
## 许可证
|
|
172
|
+
|
|
173
|
+
MIT @ [netless](https://github.com/netless-io)
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @netless/app-presentation
|
|
2
2
|
|
|
3
|
+
[中文](https://github.com/netless-io/netless-app-presentation/blob/main/README-zh.md)
|
|
4
|
+
|
|
3
5
|
A [Netless App](https://github.com/netless-io/netless-app) that display multiple images as presentation slides.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
@@ -12,7 +14,24 @@ A [Netless App](https://github.com/netless-io/netless-app) that display multiple
|
|
|
12
14
|
import { register } from "@netless/fastboard"
|
|
13
15
|
import { install } from "@netless/app-presentation"
|
|
14
16
|
|
|
15
|
-
install(register, {
|
|
17
|
+
install(register, {
|
|
18
|
+
as: 'DocsViewer',
|
|
19
|
+
appOptions: {
|
|
20
|
+
// Enable scrollbar feature
|
|
21
|
+
useScrollbar: true,
|
|
22
|
+
// Enable clip view feature, only show page content area
|
|
23
|
+
useClipView: true,
|
|
24
|
+
// Scrollbar event callbacks
|
|
25
|
+
scrollbarEventCallback: {
|
|
26
|
+
onScrollCameraUpdated: (appid, originScale, scale) => {
|
|
27
|
+
console.log('Camera scale updated', appid, scale)
|
|
28
|
+
},
|
|
29
|
+
onScrollbarDragEnd: () => {
|
|
30
|
+
console.log('Scrollbar drag ended')
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
16
35
|
```
|
|
17
36
|
|
|
18
37
|
### Insert This App Into Room
|
|
@@ -59,6 +78,80 @@ handles app whose kind is `DocsViewer` or `Slide`.
|
|
|
59
78
|
|
|
60
79
|
</details>
|
|
61
80
|
|
|
81
|
+
### App Options
|
|
82
|
+
|
|
83
|
+
#### `useScrollbar`
|
|
84
|
+
Enable scrollbar feature, providing horizontal and vertical scrollbars for navigation and viewing presentations.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
install(register, {
|
|
88
|
+
as: 'DocsViewer',
|
|
89
|
+
appOptions: {
|
|
90
|
+
useScrollbar: true,
|
|
91
|
+
scrollbarEventCallback: {
|
|
92
|
+
onScrollCameraUpdated: (appid, originScale, scale) => {
|
|
93
|
+
// Triggered when camera scale is updated
|
|
94
|
+
},
|
|
95
|
+
onScrollbarDragEnd: () => {
|
|
96
|
+
// Triggered when scrollbar drag ends
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### `useClipView`
|
|
104
|
+
Enable clip view feature, only show page content area, hide content outside the whiteboard area.
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
install(register, {
|
|
108
|
+
as: 'DocsViewer',
|
|
109
|
+
appOptions: {
|
|
110
|
+
useClipView: true
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### App Result API
|
|
116
|
+
|
|
117
|
+
#### `screenshotCurrentPageAsync(context, width?, height?)`
|
|
118
|
+
Asynchronously screenshot the current page to Canvas context. Supports custom width and height.
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const app = fastboard.manager.queryOne(appId)
|
|
122
|
+
if (app && app.kind === 'DocsViewer') {
|
|
123
|
+
const controller = app.appResult
|
|
124
|
+
const canvas = document.createElement('canvas')
|
|
125
|
+
const { width, height } = controller.getPageSize()
|
|
126
|
+
canvas.width = width
|
|
127
|
+
canvas.height = height
|
|
128
|
+
const ctx = canvas.getContext('2d')
|
|
129
|
+
if (ctx) {
|
|
130
|
+
await controller.screenshotCurrentPageAsync(ctx, width, height)
|
|
131
|
+
// Use canvas for subsequent operations, such as exporting images
|
|
132
|
+
canvas.toBlob((blob) => {
|
|
133
|
+
const url = URL.createObjectURL(blob)
|
|
134
|
+
const a = document.createElement('a')
|
|
135
|
+
a.href = url
|
|
136
|
+
a.download = 'screenshot.png'
|
|
137
|
+
a.click()
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### `getPageSize()`
|
|
144
|
+
Get the size (width and height) of the current page.
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
const app = fastboard.manager.queryOne(appId)
|
|
148
|
+
if (app && app.kind === 'DocsViewer') {
|
|
149
|
+
const controller = app.appResult
|
|
150
|
+
const { width, height } = controller.getPageSize()
|
|
151
|
+
console.log(`Current page size: ${width}x${height}`)
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
62
155
|
## Develop
|
|
63
156
|
|
|
64
157
|
See [Write you a Netless App](https://github.com/netless-io/fastboard/blob/main/docs/en/app.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { View, NetlessApp, AppContext, WindowManager } from '@netless/window-manager';
|
|
2
|
-
import * as lodash from 'lodash';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* A combination of {@link Disposer} and {@link IDisposable}.
|
|
@@ -346,7 +345,7 @@ declare class Scrollbar {
|
|
|
346
345
|
constructor(container: HTMLElement, option: ScrollbarOption, view: View);
|
|
347
346
|
private c;
|
|
348
347
|
setReadonly(bol: boolean): void;
|
|
349
|
-
onCameraUpdated:
|
|
348
|
+
onCameraUpdated: any;
|
|
350
349
|
onDragStart: () => void;
|
|
351
350
|
getScrollXRange(camera: {
|
|
352
351
|
scale: number;
|