@netless/forge-slide 0.1.0 → 0.1.1-alpha.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/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 +190 -11
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +190 -11
- package/dist/index.js.map +3 -3
- package/package.json +6 -5
- package/src/Slide.ts +57 -2
- package/src/SlideApplication.ts +164 -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 */)) {
|
|
@@ -67041,28 +67091,147 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67041
67091
|
return that.permissions;
|
|
67042
67092
|
}
|
|
67043
67093
|
});
|
|
67094
|
+
Object.defineProperty(this.emitter, "footView", {
|
|
67095
|
+
get() {
|
|
67096
|
+
return that.footer.root;
|
|
67097
|
+
}
|
|
67098
|
+
});
|
|
67044
67099
|
Object.defineProperty(this.emitter, "pageIndex", {
|
|
67045
67100
|
get() {
|
|
67046
67101
|
return that.currentSlideIndex;
|
|
67047
67102
|
}
|
|
67048
67103
|
});
|
|
67049
|
-
Object.defineProperty(this.emitter, "
|
|
67104
|
+
Object.defineProperty(this.emitter, "pageCount", {
|
|
67050
67105
|
get() {
|
|
67051
|
-
return
|
|
67052
|
-
|
|
67053
|
-
|
|
67054
|
-
|
|
67055
|
-
|
|
67106
|
+
return that.slide.slideCount;
|
|
67107
|
+
}
|
|
67108
|
+
});
|
|
67109
|
+
Object.defineProperty(this.emitter, "goto", {
|
|
67110
|
+
writable: false,
|
|
67111
|
+
enumerable: false,
|
|
67112
|
+
value: (pageIndex) => {
|
|
67113
|
+
this.sideBar.emit("pageChange", pageIndex);
|
|
67114
|
+
}
|
|
67115
|
+
});
|
|
67116
|
+
Object.defineProperty(this.emitter, "nextStep", {
|
|
67117
|
+
writable: false,
|
|
67118
|
+
enumerable: false,
|
|
67119
|
+
value: () => {
|
|
67120
|
+
this.footer.emit("nextStep");
|
|
67121
|
+
}
|
|
67122
|
+
});
|
|
67123
|
+
Object.defineProperty(this.emitter, "prevStep", {
|
|
67124
|
+
writable: false,
|
|
67125
|
+
enumerable: false,
|
|
67126
|
+
value: () => {
|
|
67127
|
+
this.footer.emit("prevStep");
|
|
67128
|
+
}
|
|
67129
|
+
});
|
|
67130
|
+
Object.defineProperty(this.emitter, "nextPage", {
|
|
67131
|
+
writable: false,
|
|
67132
|
+
enumerable: false,
|
|
67133
|
+
value: () => {
|
|
67134
|
+
this.footer.emit("nextPage");
|
|
67135
|
+
}
|
|
67136
|
+
});
|
|
67137
|
+
Object.defineProperty(this.emitter, "prevPage", {
|
|
67138
|
+
writable: false,
|
|
67139
|
+
enumerable: false,
|
|
67140
|
+
value: () => {
|
|
67141
|
+
this.footer.emit("prevPage");
|
|
67142
|
+
}
|
|
67143
|
+
});
|
|
67144
|
+
Object.defineProperty(this.emitter, "sideBarToggle", {
|
|
67145
|
+
writable: false,
|
|
67146
|
+
enumerable: false,
|
|
67147
|
+
value: () => {
|
|
67148
|
+
this.footer.emit("sideBarToggle");
|
|
67149
|
+
}
|
|
67150
|
+
});
|
|
67151
|
+
Object.defineProperty(this.emitter, "imgContent", {
|
|
67152
|
+
writable: false,
|
|
67153
|
+
enumerable: false,
|
|
67154
|
+
value: (pageIndex) => {
|
|
67155
|
+
return this.getImageContent(pageIndex);
|
|
67156
|
+
}
|
|
67157
|
+
});
|
|
67158
|
+
Object.defineProperty(this.emitter, "imgUrl", {
|
|
67159
|
+
writable: false,
|
|
67160
|
+
enumerable: false,
|
|
67161
|
+
value: (pageIndex) => {
|
|
67162
|
+
return this.getImageUrl(pageIndex);
|
|
67163
|
+
}
|
|
67164
|
+
});
|
|
67165
|
+
Object.defineProperty(this.emitter, "imgSize", {
|
|
67166
|
+
writable: false,
|
|
67167
|
+
enumerable: false,
|
|
67168
|
+
value: (pageIndex) => {
|
|
67169
|
+
return this.getImageSize(pageIndex);
|
|
67056
67170
|
}
|
|
67057
67171
|
});
|
|
67058
67172
|
}
|
|
67059
|
-
|
|
67173
|
+
async getPreviewImage(imageUrl) {
|
|
67174
|
+
const image = fetch(imageUrl);
|
|
67175
|
+
return await image.then((res) => res.blob()).then((blob) => {
|
|
67176
|
+
return new Promise((resolve) => {
|
|
67177
|
+
const reader = new FileReader();
|
|
67178
|
+
reader.onloadend = () => {
|
|
67179
|
+
const base64Data = reader.result;
|
|
67180
|
+
const img = document.createElement("img");
|
|
67181
|
+
img.src = base64Data;
|
|
67182
|
+
img.onload = () => {
|
|
67183
|
+
resolve({
|
|
67184
|
+
url: imageUrl,
|
|
67185
|
+
src: base64Data,
|
|
67186
|
+
width: img.width,
|
|
67187
|
+
height: img.height
|
|
67188
|
+
});
|
|
67189
|
+
};
|
|
67190
|
+
};
|
|
67191
|
+
reader.readAsDataURL(blob);
|
|
67192
|
+
});
|
|
67193
|
+
});
|
|
67194
|
+
}
|
|
67195
|
+
async getImageUrl(pageIndex) {
|
|
67196
|
+
return `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
|
|
67197
|
+
}
|
|
67198
|
+
async getImageSize(pageIndex) {
|
|
67199
|
+
const imageUrl = `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
|
|
67200
|
+
let preview = null;
|
|
67201
|
+
try {
|
|
67202
|
+
const result = await import_forge_room5.kvStore.getItem(imageUrl);
|
|
67203
|
+
preview = result ? JSON.parse(result) : null;
|
|
67204
|
+
} catch (e) {
|
|
67205
|
+
console.warn("kvStore getItem error", e);
|
|
67206
|
+
}
|
|
67207
|
+
if (preview) {
|
|
67208
|
+
return { width: preview.width, height: preview.height };
|
|
67209
|
+
}
|
|
67210
|
+
preview = await this.getPreviewImage(imageUrl);
|
|
67211
|
+
await import_forge_room5.kvStore.setItem(imageUrl, JSON.stringify(preview));
|
|
67212
|
+
return { width: preview.width, height: preview.height };
|
|
67213
|
+
}
|
|
67214
|
+
async getImageContent(pageIndex) {
|
|
67215
|
+
const imageUrl = `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
|
|
67216
|
+
let preview = null;
|
|
67217
|
+
try {
|
|
67218
|
+
const result = await import_forge_room5.kvStore.getItem(imageUrl);
|
|
67219
|
+
preview = result ? JSON.parse(result) : null;
|
|
67220
|
+
} catch (e) {
|
|
67221
|
+
console.warn("kvStore getItem error", e);
|
|
67222
|
+
}
|
|
67223
|
+
if (preview) {
|
|
67224
|
+
return preview.src;
|
|
67225
|
+
}
|
|
67226
|
+
preview = await this.getPreviewImage(imageUrl);
|
|
67227
|
+
await import_forge_room5.kvStore.setItem(imageUrl, JSON.stringify(preview));
|
|
67228
|
+
return preview.src;
|
|
67229
|
+
}
|
|
67060
67230
|
applySlideState = async (slideState, lastDispatch) => {
|
|
67061
67231
|
if (this.slide.slideState.currentSlideIndex < 0) {
|
|
67062
67232
|
this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, lastDispatch);
|
|
67063
67233
|
return;
|
|
67064
67234
|
}
|
|
67065
|
-
console.log("%cisEqual", "color: blue; font-size: 20px;", deepEqual(this.slide.slideState, slideState));
|
|
67066
67235
|
if (this.slide.slideState.currentSlideIndex > 0 && deepEqual(this.slide.slideState, slideState)) {
|
|
67067
67236
|
this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, lastDispatch);
|
|
67068
67237
|
} else {
|
|
@@ -67082,6 +67251,8 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67082
67251
|
}
|
|
67083
67252
|
};
|
|
67084
67253
|
async initialize(option) {
|
|
67254
|
+
this.prefix = option.prefix;
|
|
67255
|
+
this.taskId = option.taskId;
|
|
67085
67256
|
const whiteboardApp = new WhiteboardApplication();
|
|
67086
67257
|
whiteboardApp.roomDoc = this.roomDoc;
|
|
67087
67258
|
whiteboardApp.appId = `${option.taskId}_wb`;
|
|
@@ -67115,7 +67286,6 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67115
67286
|
this.contentContainer.appendChild(this.sideBar.root);
|
|
67116
67287
|
if (option.inheritWhiteboardId) {
|
|
67117
67288
|
whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
|
|
67118
|
-
console.log("inheritWhiteboardId", option.inheritWhiteboardId);
|
|
67119
67289
|
}
|
|
67120
67290
|
this.whiteboard.setViewModeToMain();
|
|
67121
67291
|
this.slideContainer.setAttribute("builder", "slide-builder");
|
|
@@ -67138,14 +67308,22 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67138
67308
|
dispatch: event
|
|
67139
67309
|
});
|
|
67140
67310
|
});
|
|
67311
|
+
this.slide.on("mainSeqStepStart", (animateIndex) => {
|
|
67312
|
+
this.emitter.emit("mainSeqStepStart", animateIndex);
|
|
67313
|
+
});
|
|
67314
|
+
this.slide.on("mainSeqStepEnd", (animateIndex) => {
|
|
67315
|
+
this.emitter.emit("mainSeqStepEnd", animateIndex);
|
|
67316
|
+
});
|
|
67141
67317
|
this.slide.on("renderStart", (slideIndex) => {
|
|
67142
67318
|
this.whiteboardApp.emitter.view.style.opacity = "0";
|
|
67143
67319
|
this.whiteboardApp.emitter.addPage(`${slideIndex}`);
|
|
67144
67320
|
this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
|
|
67321
|
+
this.emitter.emit("renderStart", slideIndex);
|
|
67145
67322
|
});
|
|
67146
67323
|
this.slide.on("renderEnd", (slideIndex) => {
|
|
67147
67324
|
this.currentSlideIndex = slideIndex;
|
|
67148
67325
|
this.whiteboardApp.emitter.view.style.opacity = "1";
|
|
67326
|
+
this.emitter.emit("renderEnd", slideIndex);
|
|
67149
67327
|
});
|
|
67150
67328
|
this.slide.on("stateChange", (state) => {
|
|
67151
67329
|
this.getMap(this.name).set("slideState", state);
|
|
@@ -67153,6 +67331,7 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67153
67331
|
this.getMap(this.name).observe(this.onSlideEventHandler);
|
|
67154
67332
|
window.slide = this.slide;
|
|
67155
67333
|
window.slideWhiteboard = this.whiteboardApp;
|
|
67334
|
+
window.forgeSlide = this;
|
|
67156
67335
|
const syncSlide = this.getMap(this.name).get("slideState");
|
|
67157
67336
|
if (syncSlide && syncSlide.taskId === option.taskId) {
|
|
67158
67337
|
await this.slide.setSlideState(syncSlide);
|
|
@@ -67163,7 +67342,7 @@ var SlideApplication = class extends import_forge_room4.AbstractApplication {
|
|
|
67163
67342
|
return this.userMap(userId);
|
|
67164
67343
|
});
|
|
67165
67344
|
this.permissions.on("change", (userId, flags, value) => {
|
|
67166
|
-
|
|
67345
|
+
this.emitter.emit("permissionChange", userId, flags, value);
|
|
67167
67346
|
if (this.userId === userId) {
|
|
67168
67347
|
if (flags.includes(4 /* clickAnim */)) {
|
|
67169
67348
|
this.slideContainer.style.pointerEvents = "auto";
|