@netless/forge-slide 0.1.0 → 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Slide.d.ts +57 -1
- package/dist/Slide.d.ts.map +1 -1
- package/dist/SlideApplication.d.ts +7 -1
- package/dist/SlideApplication.d.ts.map +1 -1
- package/dist/index.esm.js +192 -11
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +192 -11
- package/dist/index.js.map +3 -3
- package/package.json +6 -5
- package/src/Slide.ts +57 -2
- package/src/SlideApplication.ts +167 -18
package/dist/index.js
CHANGED
|
@@ -66594,12 +66594,55 @@ var import_eventemitter314 = __toESM(require("eventemitter3"));
|
|
|
66594
66594
|
var SlideForge = class extends import_eventemitter314.default {
|
|
66595
66595
|
view;
|
|
66596
66596
|
permissions;
|
|
66597
|
+
footView;
|
|
66598
|
+
/**
|
|
66599
|
+
* 当前页面索引, 从 0 开始
|
|
66600
|
+
*/
|
|
66597
66601
|
pageIndex;
|
|
66602
|
+
/**
|
|
66603
|
+
* 总页数
|
|
66604
|
+
*/
|
|
66605
|
+
pageCount;
|
|
66598
66606
|
/**
|
|
66599
66607
|
* 切换到参数指定页面, index 从 0 开始
|
|
66600
66608
|
* @param {number} index 页面索引
|
|
66601
66609
|
*/
|
|
66602
66610
|
goto;
|
|
66611
|
+
/**
|
|
66612
|
+
* 下一步, 如果已经是本页的最后一步, 则切换到下一页
|
|
66613
|
+
*/
|
|
66614
|
+
nextStep;
|
|
66615
|
+
/**
|
|
66616
|
+
* 上一步, 如果已经是本页的第一步, 则切换到上一页
|
|
66617
|
+
*/
|
|
66618
|
+
prevStep;
|
|
66619
|
+
/**
|
|
66620
|
+
* 下一页, 如果是最后一页, 则不执行任何操作
|
|
66621
|
+
*/
|
|
66622
|
+
nextPage;
|
|
66623
|
+
/**
|
|
66624
|
+
* 上一页, 如果是第一页, 则不执行任何操作
|
|
66625
|
+
*/
|
|
66626
|
+
prevPage;
|
|
66627
|
+
/**
|
|
66628
|
+
* 切换侧栏显示状态
|
|
66629
|
+
*/
|
|
66630
|
+
sideBarToggle;
|
|
66631
|
+
/**
|
|
66632
|
+
* 获取预览图图片内容, base64 编码
|
|
66633
|
+
* @param {number} index 页面索引
|
|
66634
|
+
*/
|
|
66635
|
+
imgContent;
|
|
66636
|
+
/**
|
|
66637
|
+
* 获取预览图图片链接
|
|
66638
|
+
* @param {number} index 页面索引
|
|
66639
|
+
*/
|
|
66640
|
+
imgUrl;
|
|
66641
|
+
/**
|
|
66642
|
+
* 获取预览图图片尺寸
|
|
66643
|
+
* @param {number} index 页面索引
|
|
66644
|
+
*/
|
|
66645
|
+
imgSize;
|
|
66603
66646
|
};
|
|
66604
66647
|
|
|
66605
66648
|
// src/ForgeSlidePermession.ts
|
|
@@ -66943,10 +66986,12 @@ async function delay2(time) {
|
|
|
66943
66986
|
}
|
|
66944
66987
|
|
|
66945
66988
|
// src/SlideApplication.ts
|
|
66989
|
+
var import_forge_room5 = require("@netless/forge-room");
|
|
66946
66990
|
var Slide_APP_NAME = "forge_slide";
|
|
66947
66991
|
var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
66948
66992
|
static applicationName = Slide_APP_NAME;
|
|
66949
66993
|
name = Slide_APP_NAME;
|
|
66994
|
+
emitter = new SlideForge();
|
|
66950
66995
|
whiteboardApp;
|
|
66951
66996
|
whiteboard;
|
|
66952
66997
|
rootView = document.createElement("div");
|
|
@@ -66958,8 +67003,11 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
66958
67003
|
sideBar;
|
|
66959
67004
|
slide;
|
|
66960
67005
|
currentSlideIndex = 0;
|
|
67006
|
+
taskId = "";
|
|
67007
|
+
prefix = "";
|
|
66961
67008
|
constructor() {
|
|
66962
67009
|
super();
|
|
67010
|
+
window.emitter = this.emitter;
|
|
66963
67011
|
this.rootView.setAttribute("data-forge-app", Slide_APP_NAME);
|
|
66964
67012
|
this.rootView.style.background = "#f0f0f0f0";
|
|
66965
67013
|
this.rootView.style.overflow = "hidden";
|
|
@@ -66972,7 +67020,9 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
66972
67020
|
this.footer = new FooterView();
|
|
66973
67021
|
this.sideBar = new SideBarView();
|
|
66974
67022
|
this.sideBar.on("pageChange", (index) => {
|
|
66975
|
-
this.slide.
|
|
67023
|
+
if (index > 0 && index <= this.slide.slideCount) {
|
|
67024
|
+
this.slide.renderSlide(index);
|
|
67025
|
+
}
|
|
66976
67026
|
});
|
|
66977
67027
|
this.footer.on("prevStep", () => {
|
|
66978
67028
|
if (!this.permissions.hasPermission(1 /* changeStep */)) {
|
|
@@ -67027,6 +67077,9 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67027
67077
|
}
|
|
67028
67078
|
});
|
|
67029
67079
|
this.rootView.appendChild(this.contentContainer);
|
|
67080
|
+
this.permissions.on("change", (userId, flags, value) => {
|
|
67081
|
+
this.emitter.emit("permissionChange", userId, flags, value);
|
|
67082
|
+
});
|
|
67030
67083
|
this.emitter.on("renderStart", (pageIndex) => {
|
|
67031
67084
|
this.footer.prevPageState(pageIndex !== 0);
|
|
67032
67085
|
});
|
|
@@ -67041,28 +67094,147 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67041
67094
|
return that.permissions;
|
|
67042
67095
|
}
|
|
67043
67096
|
});
|
|
67097
|
+
Object.defineProperty(this.emitter, "footView", {
|
|
67098
|
+
get() {
|
|
67099
|
+
return that.footer.root;
|
|
67100
|
+
}
|
|
67101
|
+
});
|
|
67044
67102
|
Object.defineProperty(this.emitter, "pageIndex", {
|
|
67045
67103
|
get() {
|
|
67046
67104
|
return that.currentSlideIndex;
|
|
67047
67105
|
}
|
|
67048
67106
|
});
|
|
67049
|
-
Object.defineProperty(this.emitter, "
|
|
67107
|
+
Object.defineProperty(this.emitter, "pageCount", {
|
|
67050
67108
|
get() {
|
|
67051
|
-
return
|
|
67052
|
-
|
|
67053
|
-
|
|
67054
|
-
|
|
67055
|
-
|
|
67109
|
+
return that.slide.slideCount;
|
|
67110
|
+
}
|
|
67111
|
+
});
|
|
67112
|
+
Object.defineProperty(this.emitter, "goto", {
|
|
67113
|
+
writable: false,
|
|
67114
|
+
enumerable: false,
|
|
67115
|
+
value: (pageIndex) => {
|
|
67116
|
+
this.sideBar.emit("pageChange", pageIndex);
|
|
67117
|
+
}
|
|
67118
|
+
});
|
|
67119
|
+
Object.defineProperty(this.emitter, "nextStep", {
|
|
67120
|
+
writable: false,
|
|
67121
|
+
enumerable: false,
|
|
67122
|
+
value: () => {
|
|
67123
|
+
this.footer.emit("nextStep");
|
|
67124
|
+
}
|
|
67125
|
+
});
|
|
67126
|
+
Object.defineProperty(this.emitter, "prevStep", {
|
|
67127
|
+
writable: false,
|
|
67128
|
+
enumerable: false,
|
|
67129
|
+
value: () => {
|
|
67130
|
+
this.footer.emit("prevStep");
|
|
67131
|
+
}
|
|
67132
|
+
});
|
|
67133
|
+
Object.defineProperty(this.emitter, "nextPage", {
|
|
67134
|
+
writable: false,
|
|
67135
|
+
enumerable: false,
|
|
67136
|
+
value: () => {
|
|
67137
|
+
this.footer.emit("nextPage");
|
|
67138
|
+
}
|
|
67139
|
+
});
|
|
67140
|
+
Object.defineProperty(this.emitter, "prevPage", {
|
|
67141
|
+
writable: false,
|
|
67142
|
+
enumerable: false,
|
|
67143
|
+
value: () => {
|
|
67144
|
+
this.footer.emit("prevPage");
|
|
67145
|
+
}
|
|
67146
|
+
});
|
|
67147
|
+
Object.defineProperty(this.emitter, "sideBarToggle", {
|
|
67148
|
+
writable: false,
|
|
67149
|
+
enumerable: false,
|
|
67150
|
+
value: () => {
|
|
67151
|
+
this.footer.emit("sideBarToggle");
|
|
67152
|
+
}
|
|
67153
|
+
});
|
|
67154
|
+
Object.defineProperty(this.emitter, "imgContent", {
|
|
67155
|
+
writable: false,
|
|
67156
|
+
enumerable: false,
|
|
67157
|
+
value: (pageIndex) => {
|
|
67158
|
+
return this.getImageContent(pageIndex);
|
|
67159
|
+
}
|
|
67160
|
+
});
|
|
67161
|
+
Object.defineProperty(this.emitter, "imgUrl", {
|
|
67162
|
+
writable: false,
|
|
67163
|
+
enumerable: false,
|
|
67164
|
+
value: (pageIndex) => {
|
|
67165
|
+
return this.getImageUrl(pageIndex);
|
|
67166
|
+
}
|
|
67167
|
+
});
|
|
67168
|
+
Object.defineProperty(this.emitter, "imgSize", {
|
|
67169
|
+
writable: false,
|
|
67170
|
+
enumerable: false,
|
|
67171
|
+
value: (pageIndex) => {
|
|
67172
|
+
return this.getImageSize(pageIndex);
|
|
67056
67173
|
}
|
|
67057
67174
|
});
|
|
67058
67175
|
}
|
|
67059
|
-
|
|
67176
|
+
async getPreviewImage(imageUrl) {
|
|
67177
|
+
const image = fetch(imageUrl);
|
|
67178
|
+
return await image.then((res) => res.blob()).then((blob) => {
|
|
67179
|
+
return new Promise((resolve) => {
|
|
67180
|
+
const reader = new FileReader();
|
|
67181
|
+
reader.onloadend = () => {
|
|
67182
|
+
const base64Data = reader.result;
|
|
67183
|
+
const img = document.createElement("img");
|
|
67184
|
+
img.src = base64Data;
|
|
67185
|
+
img.onload = () => {
|
|
67186
|
+
resolve({
|
|
67187
|
+
url: imageUrl,
|
|
67188
|
+
src: base64Data,
|
|
67189
|
+
width: img.width,
|
|
67190
|
+
height: img.height
|
|
67191
|
+
});
|
|
67192
|
+
};
|
|
67193
|
+
};
|
|
67194
|
+
reader.readAsDataURL(blob);
|
|
67195
|
+
});
|
|
67196
|
+
});
|
|
67197
|
+
}
|
|
67198
|
+
async getImageUrl(pageIndex) {
|
|
67199
|
+
return `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
|
|
67200
|
+
}
|
|
67201
|
+
async getImageSize(pageIndex) {
|
|
67202
|
+
const imageUrl = `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
|
|
67203
|
+
let preview = null;
|
|
67204
|
+
try {
|
|
67205
|
+
const result = await import_forge_room5.kvStore.getItem(imageUrl);
|
|
67206
|
+
preview = result ? JSON.parse(result) : null;
|
|
67207
|
+
} catch (e) {
|
|
67208
|
+
console.warn("kvStore getItem error", e);
|
|
67209
|
+
}
|
|
67210
|
+
if (preview) {
|
|
67211
|
+
return { width: preview.width, height: preview.height };
|
|
67212
|
+
}
|
|
67213
|
+
preview = await this.getPreviewImage(imageUrl);
|
|
67214
|
+
await import_forge_room5.kvStore.setItem(imageUrl, JSON.stringify(preview));
|
|
67215
|
+
return { width: preview.width, height: preview.height };
|
|
67216
|
+
}
|
|
67217
|
+
async getImageContent(pageIndex) {
|
|
67218
|
+
const imageUrl = `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
|
|
67219
|
+
let preview = null;
|
|
67220
|
+
try {
|
|
67221
|
+
const result = await import_forge_room5.kvStore.getItem(imageUrl);
|
|
67222
|
+
preview = result ? JSON.parse(result) : null;
|
|
67223
|
+
} catch (e) {
|
|
67224
|
+
console.warn("kvStore getItem error", e);
|
|
67225
|
+
}
|
|
67226
|
+
if (preview) {
|
|
67227
|
+
return preview.src;
|
|
67228
|
+
}
|
|
67229
|
+
preview = await this.getPreviewImage(imageUrl);
|
|
67230
|
+
await import_forge_room5.kvStore.setItem(imageUrl, JSON.stringify(preview));
|
|
67231
|
+
return preview.src;
|
|
67232
|
+
}
|
|
67060
67233
|
applySlideState = async (slideState, lastDispatch) => {
|
|
67061
67234
|
if (this.slide.slideState.currentSlideIndex < 0) {
|
|
67062
67235
|
this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, lastDispatch);
|
|
67063
67236
|
return;
|
|
67064
67237
|
}
|
|
67065
|
-
console.log("%cisEqual", "color: blue; font-size: 20px;", deepEqual(this.slide.slideState, slideState));
|
|
67066
67238
|
if (this.slide.slideState.currentSlideIndex > 0 && deepEqual(this.slide.slideState, slideState)) {
|
|
67067
67239
|
this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, lastDispatch);
|
|
67068
67240
|
} else {
|
|
@@ -67082,6 +67254,8 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67082
67254
|
}
|
|
67083
67255
|
};
|
|
67084
67256
|
async initialize(option) {
|
|
67257
|
+
this.prefix = option.prefix;
|
|
67258
|
+
this.taskId = option.taskId;
|
|
67085
67259
|
const whiteboardApp = new WhiteboardApplication();
|
|
67086
67260
|
whiteboardApp.roomDoc = this.roomDoc;
|
|
67087
67261
|
whiteboardApp.appId = `${option.taskId}_wb`;
|
|
@@ -67115,7 +67289,6 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67115
67289
|
this.contentContainer.appendChild(this.sideBar.root);
|
|
67116
67290
|
if (option.inheritWhiteboardId) {
|
|
67117
67291
|
whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
|
|
67118
|
-
console.log("inheritWhiteboardId", option.inheritWhiteboardId);
|
|
67119
67292
|
}
|
|
67120
67293
|
this.whiteboard.setViewModeToMain();
|
|
67121
67294
|
this.slideContainer.setAttribute("builder", "slide-builder");
|
|
@@ -67138,14 +67311,22 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67138
67311
|
dispatch: event
|
|
67139
67312
|
});
|
|
67140
67313
|
});
|
|
67314
|
+
this.slide.on("mainSeqStepStart", (animateIndex) => {
|
|
67315
|
+
this.emitter.emit("mainSeqStepStart", animateIndex);
|
|
67316
|
+
});
|
|
67317
|
+
this.slide.on("mainSeqStepEnd", (animateIndex) => {
|
|
67318
|
+
this.emitter.emit("mainSeqStepEnd", animateIndex);
|
|
67319
|
+
});
|
|
67141
67320
|
this.slide.on("renderStart", (slideIndex) => {
|
|
67142
67321
|
this.whiteboardApp.emitter.view.style.opacity = "0";
|
|
67143
67322
|
this.whiteboardApp.emitter.addPage(`${slideIndex}`);
|
|
67144
67323
|
this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
|
|
67324
|
+
this.emitter.emit("renderStart", slideIndex);
|
|
67145
67325
|
});
|
|
67146
67326
|
this.slide.on("renderEnd", (slideIndex) => {
|
|
67147
67327
|
this.currentSlideIndex = slideIndex;
|
|
67148
67328
|
this.whiteboardApp.emitter.view.style.opacity = "1";
|
|
67329
|
+
this.emitter.emit("renderEnd", slideIndex);
|
|
67149
67330
|
});
|
|
67150
67331
|
this.slide.on("stateChange", (state) => {
|
|
67151
67332
|
this.getMap(this.name).set("slideState", state);
|
|
@@ -67153,6 +67334,7 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67153
67334
|
this.getMap(this.name).observe(this.onSlideEventHandler);
|
|
67154
67335
|
window.slide = this.slide;
|
|
67155
67336
|
window.slideWhiteboard = this.whiteboardApp;
|
|
67337
|
+
window.forgeSlide = this;
|
|
67156
67338
|
const syncSlide = this.getMap(this.name).get("slideState");
|
|
67157
67339
|
if (syncSlide && syncSlide.taskId === option.taskId) {
|
|
67158
67340
|
await this.slide.setSlideState(syncSlide);
|
|
@@ -67163,7 +67345,6 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67163
67345
|
return this.userMap(userId);
|
|
67164
67346
|
});
|
|
67165
67347
|
this.permissions.on("change", (userId, flags, value) => {
|
|
67166
|
-
console.log(userId, flags, value);
|
|
67167
67348
|
if (this.userId === userId) {
|
|
67168
67349
|
if (flags.includes(4 /* clickAnim */)) {
|
|
67169
67350
|
this.slideContainer.style.pointerEvents = "auto";
|