@netless/slide 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/lib/RenderingTaskManager.d.ts +19 -0
- package/lib/RenderingTaskManager.js +134 -0
- package/lib/Slide.d.ts +74 -12
- package/lib/Slide.js +19 -19
- package/lib/waitUntil.d.ts +2 -0
- package/lib/waitUntil.js +56 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
2
|
+
export declare class Task {
|
|
3
|
+
state: "idle" | "start" | "end";
|
|
4
|
+
index: number;
|
|
5
|
+
slideIndex: number;
|
|
6
|
+
private fn;
|
|
7
|
+
private eventHub;
|
|
8
|
+
constructor(index: number, slideIndex: number, fn: () => Promise<void>, eventHub: EventEmitter);
|
|
9
|
+
apply(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare class RenderingTaskManager {
|
|
12
|
+
eventHub: EventEmitter;
|
|
13
|
+
private tasks;
|
|
14
|
+
private index;
|
|
15
|
+
constructor();
|
|
16
|
+
private replaceIdleTask;
|
|
17
|
+
addTask(fn: () => Promise<void>, slideIndex: number): void;
|
|
18
|
+
hasStartTask(): boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import EventEmitter from "eventemitter3";
|
|
38
|
+
var Task = /** @class */ (function () {
|
|
39
|
+
function Task(index, slideIndex, fn, eventHub) {
|
|
40
|
+
this.state = "idle";
|
|
41
|
+
this.index = -1;
|
|
42
|
+
this.slideIndex = -1;
|
|
43
|
+
this.fn = fn;
|
|
44
|
+
this.index = index;
|
|
45
|
+
this.slideIndex = slideIndex;
|
|
46
|
+
this.eventHub = eventHub;
|
|
47
|
+
}
|
|
48
|
+
Task.prototype.apply = function () {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var e_1;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
this.eventHub.emit("task-start", this);
|
|
55
|
+
_a.label = 1;
|
|
56
|
+
case 1:
|
|
57
|
+
_a.trys.push([1, 3, , 4]);
|
|
58
|
+
this.state = "start";
|
|
59
|
+
return [4 /*yield*/, this.fn()];
|
|
60
|
+
case 2:
|
|
61
|
+
_a.sent();
|
|
62
|
+
this.state = "end";
|
|
63
|
+
this.eventHub.emit("task-end", this);
|
|
64
|
+
return [3 /*break*/, 4];
|
|
65
|
+
case 3:
|
|
66
|
+
e_1 = _a.sent();
|
|
67
|
+
this.eventHub.emit("task-error", {
|
|
68
|
+
task: this,
|
|
69
|
+
error: e_1,
|
|
70
|
+
});
|
|
71
|
+
return [3 /*break*/, 4];
|
|
72
|
+
case 4: return [2 /*return*/];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
return Task;
|
|
78
|
+
}());
|
|
79
|
+
export { Task };
|
|
80
|
+
var RenderingTaskManager = /** @class */ (function () {
|
|
81
|
+
function RenderingTaskManager() {
|
|
82
|
+
var _this = this;
|
|
83
|
+
this.eventHub = new EventEmitter();
|
|
84
|
+
this.tasks = [];
|
|
85
|
+
this.index = 0;
|
|
86
|
+
this.eventHub.on("task-end", function (task) {
|
|
87
|
+
var _a;
|
|
88
|
+
var selfIndex = _this.tasks.findIndex(function (t) { return t.index === task.index; });
|
|
89
|
+
var nextIndex = selfIndex + 1;
|
|
90
|
+
if (nextIndex >= 0) {
|
|
91
|
+
(_a = _this.tasks[nextIndex]) === null || _a === void 0 ? void 0 : _a.apply();
|
|
92
|
+
}
|
|
93
|
+
if (selfIndex >= 0) {
|
|
94
|
+
_this.tasks.splice(selfIndex, 1);
|
|
95
|
+
_this.replaceIdleTask();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.eventHub.on("task-error", function (_a) {
|
|
99
|
+
var task = _a.task;
|
|
100
|
+
var selfIndex = _this.tasks.findIndex(function (t) { return t.index === task.index; });
|
|
101
|
+
if (selfIndex >= 0) {
|
|
102
|
+
_this.tasks.splice(selfIndex, 1);
|
|
103
|
+
_this.replaceIdleTask();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
RenderingTaskManager.prototype.replaceIdleTask = function () {
|
|
108
|
+
var _this = this;
|
|
109
|
+
var _a;
|
|
110
|
+
var ids = new Set();
|
|
111
|
+
for (var i = 0, len = this.tasks.length; i < len; i++) {
|
|
112
|
+
if (this.tasks[i].state === "idle" && ((_a = this.tasks[i + 1]) === null || _a === void 0 ? void 0 : _a.state) === "idle") {
|
|
113
|
+
ids.add(i);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
Array.from(ids).forEach(function (id) {
|
|
117
|
+
_this.tasks.splice(id, 1);
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
RenderingTaskManager.prototype.addTask = function (fn, slideIndex) {
|
|
121
|
+
var task = new Task(this.index++, slideIndex, fn, this.eventHub);
|
|
122
|
+
this.tasks.push(task);
|
|
123
|
+
this.tasks.sort(function (a, b) { return a.index - b.index; });
|
|
124
|
+
this.replaceIdleTask();
|
|
125
|
+
if (this.tasks.length === 1) {
|
|
126
|
+
task.apply();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
RenderingTaskManager.prototype.hasStartTask = function () {
|
|
130
|
+
return this.tasks.some(function (t) { return t.state === "start"; });
|
|
131
|
+
};
|
|
132
|
+
return RenderingTaskManager;
|
|
133
|
+
}());
|
|
134
|
+
export { RenderingTaskManager };
|
package/lib/Slide.d.ts
CHANGED
|
@@ -3,10 +3,20 @@ export declare const SLIDE_EVENTS: {
|
|
|
3
3
|
syncDispatch: string;
|
|
4
4
|
/** 同步事件接收 */
|
|
5
5
|
syncReceive: string;
|
|
6
|
+
/** 当前 slide 渲染开始触发 */
|
|
7
|
+
renderStart: string;
|
|
6
8
|
/** 当前 slide 渲染完毕触发 */
|
|
7
|
-
|
|
9
|
+
renderEnd: string;
|
|
10
|
+
/** 当前 slide 渲染出错触发 */
|
|
11
|
+
renderError: string;
|
|
8
12
|
/** slide 页码变化时触发 */
|
|
9
13
|
slideChange: string;
|
|
14
|
+
/** 主序列动画开始时触发 */
|
|
15
|
+
mainSeqStepStart: string;
|
|
16
|
+
/** 主序列动画结束时触发 */
|
|
17
|
+
mainSeqStepEnd: string;
|
|
18
|
+
animateStart: string;
|
|
19
|
+
animateEnd: string;
|
|
10
20
|
};
|
|
11
21
|
export interface ISlideRenderOptions {
|
|
12
22
|
/** 预期最低渲染 fps, 默认 40 */
|
|
@@ -36,40 +46,74 @@ interface ISlideState {
|
|
|
36
46
|
currentSlideIndex: number;
|
|
37
47
|
mainSeqStep: number;
|
|
38
48
|
mainSeqState: "idle" | "running" | "end" | null;
|
|
49
|
+
appliedInteractiveSeqIds: string[];
|
|
39
50
|
}
|
|
40
|
-
export declare type SyncEvent = SyncPrevStepEvent | SyncNextStepEvent | SyncRenderSlideEvent | SyncSetResourceEvent;
|
|
41
|
-
export interface
|
|
51
|
+
export declare type SyncEvent = SyncInteractiveAnimEvent | SyncPrevStepEvent | SyncNextStepEvent | SyncRenderSlideEvent | SyncSetResourceEvent;
|
|
52
|
+
export interface BasicSyncEvent {
|
|
53
|
+
}
|
|
54
|
+
export interface SyncInteractiveAnimEvent extends BasicSyncEvent {
|
|
55
|
+
type: "interactiveAnim";
|
|
56
|
+
action: string;
|
|
57
|
+
}
|
|
58
|
+
export interface SyncPrevStepEvent extends BasicSyncEvent {
|
|
42
59
|
type: "prevStep";
|
|
43
60
|
next: number;
|
|
44
61
|
}
|
|
45
|
-
export interface SyncNextStepEvent {
|
|
62
|
+
export interface SyncNextStepEvent extends BasicSyncEvent {
|
|
46
63
|
type: "nextStep";
|
|
47
64
|
next: number;
|
|
48
65
|
}
|
|
49
|
-
export interface SyncRenderSlideEvent {
|
|
66
|
+
export interface SyncRenderSlideEvent extends BasicSyncEvent {
|
|
50
67
|
type: "renderSlide";
|
|
51
68
|
index: number;
|
|
52
69
|
}
|
|
53
|
-
export interface SyncSetResourceEvent {
|
|
70
|
+
export interface SyncSetResourceEvent extends BasicSyncEvent {
|
|
54
71
|
type: "setResource";
|
|
55
72
|
taskId: string;
|
|
56
73
|
url: string;
|
|
57
74
|
}
|
|
58
75
|
export interface SlideEventEmitter {
|
|
59
|
-
emit(event: typeof SLIDE_EVENTS.
|
|
60
|
-
on(event: typeof SLIDE_EVENTS.
|
|
76
|
+
emit(event: typeof SLIDE_EVENTS.renderStart, index: number): boolean;
|
|
77
|
+
on(event: typeof SLIDE_EVENTS.renderStart, listener: (index: number) => void): this;
|
|
78
|
+
emit(event: typeof SLIDE_EVENTS.renderEnd, index: number): boolean;
|
|
79
|
+
on(event: typeof SLIDE_EVENTS.renderEnd, listener: (index: number) => void): this;
|
|
61
80
|
emit(event: typeof SLIDE_EVENTS.slideChange, nextSlideIndex: number): boolean;
|
|
62
81
|
on(event: typeof SLIDE_EVENTS.slideChange, listener: (nextSlideIndex: number) => void): this;
|
|
63
82
|
emit(event: typeof SLIDE_EVENTS.syncDispatch, args: SyncEvent): boolean;
|
|
64
83
|
on(event: typeof SLIDE_EVENTS.syncReceive, listener: (event: SyncEvent) => void): this;
|
|
84
|
+
emit(event: typeof SLIDE_EVENTS.renderError, args: {
|
|
85
|
+
error: Error;
|
|
86
|
+
index: number;
|
|
87
|
+
}): boolean;
|
|
88
|
+
on(event: typeof SLIDE_EVENTS.renderError, listener: (args: {
|
|
89
|
+
error: Error;
|
|
90
|
+
index: number;
|
|
91
|
+
}) => void): this;
|
|
92
|
+
emit(event: typeof SLIDE_EVENTS.animateStart): boolean;
|
|
93
|
+
on(event: typeof SLIDE_EVENTS.animateStart, listener: () => void): this;
|
|
94
|
+
emit(event: typeof SLIDE_EVENTS.animateEnd): boolean;
|
|
95
|
+
on(event: typeof SLIDE_EVENTS.animateEnd, listener: () => void): this;
|
|
96
|
+
emit(event: typeof SLIDE_EVENTS.mainSeqStepStart, index: number): boolean;
|
|
97
|
+
on(event: typeof SLIDE_EVENTS.mainSeqStepStart, listener: (index: number) => void): this;
|
|
98
|
+
emit(event: typeof SLIDE_EVENTS.mainSeqStepEnd, index: number): boolean;
|
|
99
|
+
on(event: typeof SLIDE_EVENTS.mainSeqStepEnd, listener: (index: number) => void): this;
|
|
65
100
|
}
|
|
66
101
|
declare const Slide_base: new () => SlideEventEmitter;
|
|
67
102
|
export declare class Slide extends Slide_base {
|
|
68
103
|
private __slideState;
|
|
104
|
+
private isAnimating;
|
|
105
|
+
private renderingTaskManager;
|
|
106
|
+
private isLoading;
|
|
69
107
|
private interactive;
|
|
70
108
|
private anchor;
|
|
71
109
|
private player;
|
|
110
|
+
private frameWidth;
|
|
111
|
+
private frameHeight;
|
|
112
|
+
private frame;
|
|
113
|
+
private frameResizeObserver;
|
|
72
114
|
constructor(config: ISlideConfig);
|
|
115
|
+
private frameResizeHandler;
|
|
116
|
+
private resizeView;
|
|
73
117
|
private receiveSyncHandler;
|
|
74
118
|
/**
|
|
75
119
|
* 设置整个 slide 的状态, slide 会以传入的状态更新画面.
|
|
@@ -77,6 +121,10 @@ export declare class Slide extends Slide_base {
|
|
|
77
121
|
* @param state ISlideState
|
|
78
122
|
*/
|
|
79
123
|
setSlideState(state: Partial<ISlideState>): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* 返回 slide 总页数
|
|
126
|
+
*/
|
|
127
|
+
get slideCount(): number;
|
|
80
128
|
/**
|
|
81
129
|
* 整个 slide 的状态, 将获取的值传递给另一个客户端, 并调用 setSlideState
|
|
82
130
|
* 可以完成整体同步. 只读属性.
|
|
@@ -148,25 +196,39 @@ export declare class Slide extends Slide_base {
|
|
|
148
196
|
* @param url 资源 url 前缀
|
|
149
197
|
*/
|
|
150
198
|
setResource(taskId: string, url: string): void;
|
|
199
|
+
private _renderSlide;
|
|
151
200
|
/**
|
|
152
201
|
* 渲染 index 参数对应的 ppt 页.
|
|
153
|
-
* @param index
|
|
202
|
+
* @param index 要显示的页码, 从 1 开始
|
|
154
203
|
*/
|
|
155
|
-
renderSlide(index: number):
|
|
204
|
+
renderSlide(index: number, isReceive?: boolean): void;
|
|
156
205
|
/**
|
|
157
206
|
* 执行下一个主序列动画
|
|
158
207
|
*/
|
|
159
|
-
nextStep(): void;
|
|
208
|
+
nextStep(isReceive?: boolean): void;
|
|
160
209
|
/**
|
|
161
210
|
* 执行上一个主序列动画
|
|
162
211
|
*/
|
|
163
|
-
prevStep(): void;
|
|
212
|
+
prevStep(isReceive?: boolean): void;
|
|
164
213
|
/**
|
|
165
214
|
* 重置主序列动画
|
|
166
215
|
* @param index 将要重置到的步数
|
|
167
216
|
* @param status 将要重置到的状态, "start" 重置到动画开始, "end" 重置到动画结束
|
|
168
217
|
*/
|
|
169
218
|
setMainSeqStep(index: number, status: "start" | "end"): void;
|
|
219
|
+
/**
|
|
220
|
+
* 设置是否可以互动
|
|
221
|
+
* @param val boolean
|
|
222
|
+
*/
|
|
223
|
+
setInteractive(val: boolean): void;
|
|
224
|
+
/**
|
|
225
|
+
* 暂停播放
|
|
226
|
+
*/
|
|
227
|
+
pause(): void;
|
|
228
|
+
/**
|
|
229
|
+
* 恢复播放状态
|
|
230
|
+
*/
|
|
231
|
+
resume(): void;
|
|
170
232
|
/**
|
|
171
233
|
* 销毁方法.
|
|
172
234
|
*/
|