@netless/forge-imagery-doc 0.1.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/build.mjs +34 -0
- package/dist/Cont.d.ts +1 -0
- package/dist/Cont.d.ts.map +1 -0
- package/dist/Container.d.ts +16 -0
- package/dist/Container.d.ts.map +1 -0
- package/dist/ContinuousContainer.d.ts +31 -0
- package/dist/ContinuousContainer.d.ts.map +1 -0
- package/dist/FooterView.d.ts +18 -0
- package/dist/FooterView.d.ts.map +1 -0
- package/dist/ImageryDoc.d.ts +57 -0
- package/dist/ImageryDoc.d.ts.map +1 -0
- package/dist/ImageryDocApplication.d.ts +38 -0
- package/dist/ImageryDocApplication.d.ts.map +1 -0
- package/dist/ImageryDocPermissions.d.ts +80 -0
- package/dist/ImageryDocPermissions.d.ts.map +1 -0
- package/dist/InfinityScroll.d.ts +15 -0
- package/dist/InfinityScroll.d.ts.map +1 -0
- package/dist/LazyImage.d.ts +11 -0
- package/dist/LazyImage.d.ts.map +1 -0
- package/dist/SideBarView.d.ts +4 -0
- package/dist/SideBarView.d.ts.map +1 -0
- package/dist/SingleContainer.d.ts +36 -0
- package/dist/SingleContainer.d.ts.map +1 -0
- package/dist/icons.d.ts +6 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/imagery-doc.esm.js +1031 -0
- package/dist/imagery-doc.esm.js.map +7 -0
- package/dist/imagery-doc.js +1064 -0
- package/dist/imagery-doc.js.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/infinityScrollor.d.ts +5 -0
- package/dist/infinityScrollor.d.ts.map +1 -0
- package/package.json +23 -0
- package/src/Container.ts +17 -0
- package/src/ContinuousContainer.ts +157 -0
- package/src/FooterView.ts +139 -0
- package/src/ImageryDoc.ts +64 -0
- package/src/ImageryDocApplication.ts +225 -0
- package/src/ImageryDocPermissions.ts +159 -0
- package/src/InfinityScroll.ts +55 -0
- package/src/LazyImage.ts +66 -0
- package/src/SingleContainer.ts +248 -0
- package/src/icons.ts +9 -0
- package/src/index.ts +5 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,1064 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
ImageryDoc: () => ImageryDoc,
|
|
34
|
+
ImageryDocApplication: () => ImageryDocApplication,
|
|
35
|
+
ImageryDocPermissionFlag: () => ImageryDocPermissionFlag
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// src/ImageryDoc.ts
|
|
40
|
+
var import_eventemitter3 = __toESM(require("eventemitter3"), 1);
|
|
41
|
+
function _defineProperty(e, r, t) {
|
|
42
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
43
|
+
}
|
|
44
|
+
function _toPropertyKey(t) {
|
|
45
|
+
var i = _toPrimitive(t, "string");
|
|
46
|
+
return "symbol" == typeof i ? i : i + "";
|
|
47
|
+
}
|
|
48
|
+
function _toPrimitive(t, r) {
|
|
49
|
+
if ("object" != typeof t || !t) return t;
|
|
50
|
+
var e = t[Symbol.toPrimitive];
|
|
51
|
+
if (void 0 !== e) {
|
|
52
|
+
var i = e.call(t, r || "default");
|
|
53
|
+
if ("object" != typeof i) return i;
|
|
54
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
55
|
+
}
|
|
56
|
+
return ("string" === r ? String : Number)(t);
|
|
57
|
+
}
|
|
58
|
+
var ImageryDoc = class extends import_eventemitter3.default {
|
|
59
|
+
constructor() {
|
|
60
|
+
super(...arguments);
|
|
61
|
+
_defineProperty(this, "view", void 0);
|
|
62
|
+
_defineProperty(this, "footView", void 0);
|
|
63
|
+
_defineProperty(this, "permissions", void 0);
|
|
64
|
+
_defineProperty(this, "pageIndex", void 0);
|
|
65
|
+
_defineProperty(this, "pageCount", void 0);
|
|
66
|
+
_defineProperty(this, "goto", void 0);
|
|
67
|
+
_defineProperty(this, "imgContent", void 0);
|
|
68
|
+
_defineProperty(this, "imgSize", void 0);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/ImageryDocApplication.ts
|
|
73
|
+
var import_forge_room2 = require("@netless/forge-room");
|
|
74
|
+
var import_forge_whiteboard = require("@netless/forge-whiteboard");
|
|
75
|
+
|
|
76
|
+
// src/LazyImage.ts
|
|
77
|
+
var import_forge_room = require("@netless/forge-room");
|
|
78
|
+
function _defineProperty2(e, r, t) {
|
|
79
|
+
return (r = _toPropertyKey2(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
80
|
+
}
|
|
81
|
+
function _toPropertyKey2(t) {
|
|
82
|
+
var i = _toPrimitive2(t, "string");
|
|
83
|
+
return "symbol" == typeof i ? i : i + "";
|
|
84
|
+
}
|
|
85
|
+
function _toPrimitive2(t, r) {
|
|
86
|
+
if ("object" != typeof t || !t) return t;
|
|
87
|
+
var e = t[Symbol.toPrimitive];
|
|
88
|
+
if (void 0 !== e) {
|
|
89
|
+
var i = e.call(t, r || "default");
|
|
90
|
+
if ("object" != typeof i) return i;
|
|
91
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
92
|
+
}
|
|
93
|
+
return ("string" === r ? String : Number)(t);
|
|
94
|
+
}
|
|
95
|
+
var LazyImage = class {
|
|
96
|
+
constructor(src, width, height) {
|
|
97
|
+
_defineProperty2(this, "view", void 0);
|
|
98
|
+
_defineProperty2(this, "width", void 0);
|
|
99
|
+
_defineProperty2(this, "height", void 0);
|
|
100
|
+
_defineProperty2(this, "src", void 0);
|
|
101
|
+
this.src = src;
|
|
102
|
+
this.width = width;
|
|
103
|
+
this.height = height;
|
|
104
|
+
this.view = document.createElement("div");
|
|
105
|
+
this.view.setAttribute("data-forge-src", src);
|
|
106
|
+
this.view.style.width = `${width}px`;
|
|
107
|
+
this.view.style.height = `${height}px`;
|
|
108
|
+
this.view.style.transformOrigin = "0 0";
|
|
109
|
+
}
|
|
110
|
+
scale(scale) {
|
|
111
|
+
this.view.style.width = `${this.width * scale}px`;
|
|
112
|
+
this.view.style.height = `${this.height * scale}px`;
|
|
113
|
+
}
|
|
114
|
+
async getImgContent() {
|
|
115
|
+
let base64Data = null;
|
|
116
|
+
try {
|
|
117
|
+
base64Data = await import_forge_room.kvStore.getItem(this.src);
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
if (base64Data) {
|
|
121
|
+
return base64Data;
|
|
122
|
+
}
|
|
123
|
+
const response = await fetch(this.src);
|
|
124
|
+
const blob = await response.blob();
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
const reader = new FileReader();
|
|
127
|
+
reader.onload = (e) => {
|
|
128
|
+
import_forge_room.kvStore.setItem(this.src, reader.result);
|
|
129
|
+
resolve(reader.result);
|
|
130
|
+
};
|
|
131
|
+
reader.onerror = () => {
|
|
132
|
+
reject(reader.error);
|
|
133
|
+
};
|
|
134
|
+
reader.readAsDataURL(blob);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async prepare() {
|
|
138
|
+
if (this.view.children.length > 0) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const base64Data = await this.getImgContent();
|
|
142
|
+
const img = document.createElement("img");
|
|
143
|
+
img.src = base64Data;
|
|
144
|
+
img.style.width = "100%";
|
|
145
|
+
if (this.view.children.length === 0) {
|
|
146
|
+
this.view.appendChild(img);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/ImageryDocPermissions.ts
|
|
152
|
+
var import_eventemitter32 = __toESM(require("eventemitter3"), 1);
|
|
153
|
+
function _defineProperty3(e, r, t) {
|
|
154
|
+
return (r = _toPropertyKey3(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
155
|
+
}
|
|
156
|
+
function _toPropertyKey3(t) {
|
|
157
|
+
var i = _toPrimitive3(t, "string");
|
|
158
|
+
return "symbol" == typeof i ? i : i + "";
|
|
159
|
+
}
|
|
160
|
+
function _toPrimitive3(t, r) {
|
|
161
|
+
if ("object" != typeof t || !t) return t;
|
|
162
|
+
var e = t[Symbol.toPrimitive];
|
|
163
|
+
if (void 0 !== e) {
|
|
164
|
+
var i = e.call(t, r || "default");
|
|
165
|
+
if ("object" != typeof i) return i;
|
|
166
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
167
|
+
}
|
|
168
|
+
return ("string" === r ? String : Number)(t);
|
|
169
|
+
}
|
|
170
|
+
var ImageryDocPermissionFlag = function(ImageryDocPermissionFlag2) {
|
|
171
|
+
ImageryDocPermissionFlag2[ImageryDocPermissionFlag2["none"] = 0] = "none";
|
|
172
|
+
ImageryDocPermissionFlag2[ImageryDocPermissionFlag2["switchPage"] = 1] = "switchPage";
|
|
173
|
+
ImageryDocPermissionFlag2[ImageryDocPermissionFlag2["camera"] = 2] = "camera";
|
|
174
|
+
ImageryDocPermissionFlag2[ImageryDocPermissionFlag2["sideBar"] = 4] = "sideBar";
|
|
175
|
+
ImageryDocPermissionFlag2[ImageryDocPermissionFlag2["all"] = ImageryDocPermissionFlag2.switchPage | ImageryDocPermissionFlag2.camera | ImageryDocPermissionFlag2.sideBar] = "all";
|
|
176
|
+
return ImageryDocPermissionFlag2;
|
|
177
|
+
}({});
|
|
178
|
+
var ImageryDocPermissions = class extends import_eventemitter32.default {
|
|
179
|
+
constructor(userManager, requestUserMap) {
|
|
180
|
+
super();
|
|
181
|
+
_defineProperty3(this, "requestUserMap", void 0);
|
|
182
|
+
_defineProperty3(this, "userManager", void 0);
|
|
183
|
+
_defineProperty3(this, "observers", /* @__PURE__ */ new Map());
|
|
184
|
+
_defineProperty3(this, "handleUserLeave", (user) => {
|
|
185
|
+
const cb = this.observers.get(user.id);
|
|
186
|
+
if (cb) {
|
|
187
|
+
this.requestUserMap(user.id).unobserve(cb);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
_defineProperty3(this, "handleUserJoin", (user) => {
|
|
191
|
+
this.addObserve(user.id);
|
|
192
|
+
});
|
|
193
|
+
this.userManager = userManager;
|
|
194
|
+
this.requestUserMap = requestUserMap;
|
|
195
|
+
this.createModel(this.userManager.selfId);
|
|
196
|
+
this.userManager.userIdList().forEach((userId) => {
|
|
197
|
+
this.addObserve(userId);
|
|
198
|
+
});
|
|
199
|
+
this.userManager.on("join", this.handleUserJoin);
|
|
200
|
+
this.userManager.on("leave", this.handleUserLeave);
|
|
201
|
+
}
|
|
202
|
+
addObserve(userId) {
|
|
203
|
+
const observer = (evt) => {
|
|
204
|
+
this.handleUserPermissionChange(userId, evt);
|
|
205
|
+
};
|
|
206
|
+
this.observers.set(userId, observer);
|
|
207
|
+
this.requestUserMap(userId).observe(observer);
|
|
208
|
+
}
|
|
209
|
+
createModel(userId) {
|
|
210
|
+
const userMap = this.requestUserMap(userId);
|
|
211
|
+
if (!userMap.has("permission")) {
|
|
212
|
+
userMap.set("permission", 0);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
handleUserPermissionChange(userId, evt) {
|
|
216
|
+
for (const [key, value] of evt.changes.keys.entries()) {
|
|
217
|
+
if (key === "permission") {
|
|
218
|
+
if (value.action === "add" || value.action === "update") {
|
|
219
|
+
const newValue = this.requestUserMap(userId).get("permission");
|
|
220
|
+
this.emit("change", userId, this.resolveFlags(newValue), newValue);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 解析权限列表组合
|
|
227
|
+
* @param {number} value - 权限数字值
|
|
228
|
+
* @return {WhiteboardPermissionFlag[]} - 权限列表
|
|
229
|
+
*/
|
|
230
|
+
resolveFlags(value) {
|
|
231
|
+
return [ImageryDocPermissionFlag.switchPage, ImageryDocPermissionFlag.sideBar, ImageryDocPermissionFlag.camera].filter((v) => (v & value) !== 0);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 获取权限列表组合对应的数值
|
|
235
|
+
* @param { string } userId 不传表示获取自己
|
|
236
|
+
*/
|
|
237
|
+
getPermissionValue(userId) {
|
|
238
|
+
return this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* 获取权限列表
|
|
242
|
+
* @param {string=} userId 可选, 不传表示获取自己
|
|
243
|
+
*/
|
|
244
|
+
getPermissionFlags(userId) {
|
|
245
|
+
const value = this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
|
|
246
|
+
return this.resolveFlags(value);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 返回对应 userId 是否有相应权限
|
|
250
|
+
* @param {string=} userId 可选, 不传表示返回自己是否有相应权限
|
|
251
|
+
* @param {WhiteboardPermissionFlag} flag
|
|
252
|
+
*/
|
|
253
|
+
hasPermission(flag, userId) {
|
|
254
|
+
return ((this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0) & flag) !== 0;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 添加权限
|
|
258
|
+
* @param {WhiteboardPermissionFlag} flag 权限标记
|
|
259
|
+
* @param {string=} userId 可选, 为 userId 添加权限, 不传表示为自己添加权限
|
|
260
|
+
*/
|
|
261
|
+
addPermission(flag, userId) {
|
|
262
|
+
const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
|
|
263
|
+
const oldValue = userMap.get("permission") ?? 0;
|
|
264
|
+
this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue | flag);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 移除权限
|
|
268
|
+
* @param {WhiteboardPermissionFlag} flag 权限标记
|
|
269
|
+
* @param {string=} userId 可选, 为 userId 移除权限, 不传表示为自己移除权限
|
|
270
|
+
*/
|
|
271
|
+
removePermission(flag, userId) {
|
|
272
|
+
const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
|
|
273
|
+
const oldValue = userMap.get("permission") ?? 0;
|
|
274
|
+
this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue & ~flag);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// src/icons.ts
|
|
279
|
+
var chevronLeft = (color) => `<svg style="width:100%;height:100%;padding:2px;box-sizing:border-box;" viewBox="0 0 12.3926 16.9629"><g><rect height="16.9629" opacity="0" width="12.3926" x="0" y="0"/><path d="M0 8.47656C0 8.7207 0.0878906 8.93555 0.273438 9.12109L8.01758 16.6895C8.18359 16.8652 8.39844 16.9531 8.65234 16.9531C9.16016 16.9531 9.55078 16.5723 9.55078 16.0645C9.55078 15.8105 9.44336 15.5957 9.28711 15.4297L2.17773 8.47656L9.28711 1.52344C9.44336 1.35742 9.55078 1.13281 9.55078 0.888672C9.55078 0.380859 9.16016 0 8.65234 0C8.39844 0 8.18359 0.0878906 8.01758 0.253906L0.273438 7.83203C0.0878906 8.00781 0 8.23242 0 8.47656Z" fill="${color}"/></g></svg>`;
|
|
280
|
+
var chevronRight = (color) => `<svg style="width:100%;height:100%;padding:2px;box-sizing:border-box;" viewBox="0 0 11.6895 16.9629"><g><rect height="16.9629" opacity="0" width="11.6895" x="0" y="0"/><path d="M11.6895 8.47656C11.6895 8.23242 11.5918 8.00781 11.4062 7.83203L3.67188 0.253906C3.49609 0.0878906 3.28125 0 3.02734 0C2.5293 0 2.13867 0.380859 2.13867 0.888672C2.13867 1.13281 2.23633 1.35742 2.39258 1.52344L9.50195 8.47656L2.39258 15.4297C2.23633 15.5957 2.13867 15.8105 2.13867 16.0645C2.13867 16.5723 2.5293 16.9531 3.02734 16.9531C3.28125 16.9531 3.49609 16.8652 3.67188 16.6895L11.4062 9.12109C11.5918 8.93555 11.6895 8.7207 11.6895 8.47656Z" fill="${color}"/></g></svg>`;
|
|
281
|
+
var sideBar = (color) => `<svg style="width:100%;height:100%;padding:2px;box-sizing:border-box;" viewBox="0 0 23.3887 17.998"><g><rect height="17.998" opacity="0" width="23.3887" x="0" y="0"/><path d="M3.06641 17.998L19.9609 17.998C22.0117 17.998 23.0273 16.9824 23.0273 14.9707L23.0273 3.04688C23.0273 1.03516 22.0117 0.0195312 19.9609 0.0195312L3.06641 0.0195312C1.02539 0.0195312 0 1.02539 0 3.04688L0 14.9707C0 16.9922 1.02539 17.998 3.06641 17.998ZM3.08594 16.4258C2.10938 16.4258 1.57227 15.9082 1.57227 14.8926L1.57227 3.125C1.57227 2.10938 2.10938 1.5918 3.08594 1.5918L19.9414 1.5918C20.9082 1.5918 21.4551 2.10938 21.4551 3.125L21.4551 14.8926C21.4551 15.9082 20.9082 16.4258 19.9414 16.4258ZM7.44141 16.7285L8.97461 16.7285L8.97461 1.29883L7.44141 1.29883ZM5.56641 5.21484C5.85938 5.21484 6.12305 4.95117 6.12305 4.66797C6.12305 4.375 5.85938 4.12109 5.56641 4.12109L3.4668 4.12109C3.17383 4.12109 2.91992 4.375 2.91992 4.66797C2.91992 4.95117 3.17383 5.21484 3.4668 5.21484ZM5.56641 7.74414C5.85938 7.74414 6.12305 7.48047 6.12305 7.1875C6.12305 6.89453 5.85938 6.65039 5.56641 6.65039L3.4668 6.65039C3.17383 6.65039 2.91992 6.89453 2.91992 7.1875C2.91992 7.48047 3.17383 7.74414 3.4668 7.74414ZM5.56641 10.2637C5.85938 10.2637 6.12305 10.0195 6.12305 9.72656C6.12305 9.43359 5.85938 9.17969 5.56641 9.17969L3.4668 9.17969C3.17383 9.17969 2.91992 9.43359 2.91992 9.72656C2.91992 10.0195 3.17383 10.2637 3.4668 10.2637Z" fill="${color}"/></g></svg>`;
|
|
282
|
+
var Icons = {
|
|
283
|
+
chevronLeft,
|
|
284
|
+
chevronRight,
|
|
285
|
+
sideBar
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/FooterView.ts
|
|
289
|
+
function _defineProperty4(e, r, t) {
|
|
290
|
+
return (r = _toPropertyKey4(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
291
|
+
}
|
|
292
|
+
function _toPropertyKey4(t) {
|
|
293
|
+
var i = _toPrimitive4(t, "string");
|
|
294
|
+
return "symbol" == typeof i ? i : i + "";
|
|
295
|
+
}
|
|
296
|
+
function _toPrimitive4(t, r) {
|
|
297
|
+
if ("object" != typeof t || !t) return t;
|
|
298
|
+
var e = t[Symbol.toPrimitive];
|
|
299
|
+
if (void 0 !== e) {
|
|
300
|
+
var i = e.call(t, r || "default");
|
|
301
|
+
if ("object" != typeof i) return i;
|
|
302
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
303
|
+
}
|
|
304
|
+
return ("string" === r ? String : Number)(t);
|
|
305
|
+
}
|
|
306
|
+
var EM_COLOR = "#8C8C8C";
|
|
307
|
+
var FooterView = class {
|
|
308
|
+
constructor(imageryDoc) {
|
|
309
|
+
_defineProperty4(this, "root", void 0);
|
|
310
|
+
_defineProperty4(this, "prevPage", void 0);
|
|
311
|
+
_defineProperty4(this, "nextPage", void 0);
|
|
312
|
+
_defineProperty4(this, "sideBarToggle", void 0);
|
|
313
|
+
_defineProperty4(this, "sideBarContainer", document.createElement("div"));
|
|
314
|
+
_defineProperty4(this, "isSlideBarVisible", false);
|
|
315
|
+
_defineProperty4(this, "imageryDoc", void 0);
|
|
316
|
+
_defineProperty4(this, "handleSideBarClick", (evt) => {
|
|
317
|
+
const target = evt.target;
|
|
318
|
+
const targetIndex = target.getAttribute("data-doc-index");
|
|
319
|
+
if (targetIndex) {
|
|
320
|
+
this.imageryDoc.goto(parseInt(targetIndex, 10));
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
this.imageryDoc = imageryDoc;
|
|
324
|
+
this.root = document.createElement("div");
|
|
325
|
+
this.root.style.height = "24px";
|
|
326
|
+
this.root.style.zIndex = "2";
|
|
327
|
+
this.root.style.display = "flex";
|
|
328
|
+
this.root.style.alignItems = "center";
|
|
329
|
+
this.root.style.backgroundColor = "#fff";
|
|
330
|
+
this.root.style.borderTop = "1px solid #f0f0f0";
|
|
331
|
+
this.prevPage = this.createIcon(Icons.chevronLeft(EM_COLOR), "18px", () => {
|
|
332
|
+
this.imageryDoc.goto(this.imageryDoc.pageIndex - 1);
|
|
333
|
+
});
|
|
334
|
+
this.nextPage = this.createIcon(Icons.chevronRight(EM_COLOR), "18px", () => {
|
|
335
|
+
this.imageryDoc.goto(this.imageryDoc.pageIndex + 1);
|
|
336
|
+
});
|
|
337
|
+
this.sideBarToggle = this.createIcon(Icons.sideBar(EM_COLOR), "20px", () => {
|
|
338
|
+
this.createSideBar();
|
|
339
|
+
this.isSlideBarVisible = !this.isSlideBarVisible;
|
|
340
|
+
if (this.isSlideBarVisible) {
|
|
341
|
+
this.sideBarContainer.style.display = "block";
|
|
342
|
+
} else {
|
|
343
|
+
this.sideBarContainer.style.display = "none";
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
this.root.appendChild(this.sideBarToggle);
|
|
347
|
+
this.root.appendChild(this.createSpacer());
|
|
348
|
+
this.root.appendChild(this.prevPage);
|
|
349
|
+
this.root.appendChild(this.nextPage);
|
|
350
|
+
this.root.appendChild(this.createSpacer());
|
|
351
|
+
}
|
|
352
|
+
prevPageState(enable) {
|
|
353
|
+
if (enable) {
|
|
354
|
+
this.prevPage.style.pointerEvents = "all";
|
|
355
|
+
this.prevPage.style.opacity = "1";
|
|
356
|
+
} else {
|
|
357
|
+
this.prevPage.style.pointerEvents = "none";
|
|
358
|
+
this.prevPage.style.opacity = "0.5";
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
nextPageState(enable) {
|
|
362
|
+
if (enable) {
|
|
363
|
+
this.nextPage.style.pointerEvents = "all";
|
|
364
|
+
this.nextPage.style.opacity = "1";
|
|
365
|
+
} else {
|
|
366
|
+
this.nextPage.style.pointerEvents = "none";
|
|
367
|
+
this.nextPage.style.opacity = "0.5";
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
createSpacer() {
|
|
371
|
+
const div = document.createElement("div");
|
|
372
|
+
div.style.flex = "1 1 auto";
|
|
373
|
+
return div;
|
|
374
|
+
}
|
|
375
|
+
createIcon(svgContent, size, action) {
|
|
376
|
+
const icon = document.createElement("div");
|
|
377
|
+
icon.style.width = size;
|
|
378
|
+
icon.style.height = size;
|
|
379
|
+
icon.style.borderRadius = "2px";
|
|
380
|
+
icon.style.margin = "6px";
|
|
381
|
+
icon.innerHTML = svgContent;
|
|
382
|
+
icon.addEventListener("click", () => {
|
|
383
|
+
action();
|
|
384
|
+
});
|
|
385
|
+
icon.addEventListener("mouseover", () => {
|
|
386
|
+
icon.style.backgroundColor = "#f0f0f0";
|
|
387
|
+
});
|
|
388
|
+
icon.addEventListener("mouseout", () => {
|
|
389
|
+
icon.style.backgroundColor = "transparent";
|
|
390
|
+
});
|
|
391
|
+
return icon;
|
|
392
|
+
}
|
|
393
|
+
createSideBar() {
|
|
394
|
+
if (this.imageryDoc.pageCount === 0) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (this.root.contains(this.sideBarContainer)) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
this.sideBarContainer.style.width = "24%";
|
|
401
|
+
this.sideBarContainer.style.maxWidth = "180px";
|
|
402
|
+
this.sideBarContainer.style.height = "calc(100% - 24px)";
|
|
403
|
+
this.sideBarContainer.style.position = "absolute";
|
|
404
|
+
this.sideBarContainer.style.bottom = "24px";
|
|
405
|
+
this.sideBarContainer.style.left = "0";
|
|
406
|
+
this.sideBarContainer.style.fontSize = "0px";
|
|
407
|
+
this.sideBarContainer.style.overflow = "auto";
|
|
408
|
+
this.sideBarContainer.style.backgroundColor = "#EFEFEF";
|
|
409
|
+
this.root.appendChild(this.sideBarContainer);
|
|
410
|
+
for (let i = 0, l = this.imageryDoc.pageCount; i < l; i++) {
|
|
411
|
+
const reviewPage = document.createElement("div");
|
|
412
|
+
reviewPage.style.width = "100%";
|
|
413
|
+
reviewPage.style.marginTop = "12px";
|
|
414
|
+
const reviewIndex = document.createElement("div");
|
|
415
|
+
reviewIndex.style.cssText = "font-size:12px;width:100%;text-align:center;height:24px;line-height:24px;color:#585858";
|
|
416
|
+
reviewIndex.textContent = `${i + 1}`;
|
|
417
|
+
const reviewImg = document.createElement("img");
|
|
418
|
+
reviewImg.setAttribute("data-doc-index", `${i}`);
|
|
419
|
+
reviewImg.style.cssText = "width:80%;margin:0 10%;box-shadow:1px 1px 5px #9e9e9e";
|
|
420
|
+
this.imageryDoc.imgContent(i).then((base64Data) => {
|
|
421
|
+
reviewImg.src = base64Data;
|
|
422
|
+
});
|
|
423
|
+
reviewPage.appendChild(reviewImg);
|
|
424
|
+
reviewPage.appendChild(reviewIndex);
|
|
425
|
+
this.sideBarContainer.appendChild(reviewPage);
|
|
426
|
+
}
|
|
427
|
+
this.sideBarContainer.addEventListener("click", this.handleSideBarClick);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// src/InfinityScroll.ts
|
|
432
|
+
var import_eventemitter33 = __toESM(require("eventemitter3"), 1);
|
|
433
|
+
function _defineProperty5(e, r, t) {
|
|
434
|
+
return (r = _toPropertyKey5(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
435
|
+
}
|
|
436
|
+
function _toPropertyKey5(t) {
|
|
437
|
+
var i = _toPrimitive5(t, "string");
|
|
438
|
+
return "symbol" == typeof i ? i : i + "";
|
|
439
|
+
}
|
|
440
|
+
function _toPrimitive5(t, r) {
|
|
441
|
+
if ("object" != typeof t || !t) return t;
|
|
442
|
+
var e = t[Symbol.toPrimitive];
|
|
443
|
+
if (void 0 !== e) {
|
|
444
|
+
var i = e.call(t, r || "default");
|
|
445
|
+
if ("object" != typeof i) return i;
|
|
446
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
447
|
+
}
|
|
448
|
+
return ("string" === r ? String : Number)(t);
|
|
449
|
+
}
|
|
450
|
+
var InfinityScroll = class extends import_eventemitter33.default {
|
|
451
|
+
constructor(view) {
|
|
452
|
+
super();
|
|
453
|
+
_defineProperty5(this, "view", void 0);
|
|
454
|
+
_defineProperty5(this, "lastDelta", {
|
|
455
|
+
x: 0,
|
|
456
|
+
y: 0
|
|
457
|
+
});
|
|
458
|
+
_defineProperty5(this, "lastTriggerTime", 0);
|
|
459
|
+
_defineProperty5(this, "handleWheel", (evt) => {
|
|
460
|
+
evt.preventDefault();
|
|
461
|
+
evt.stopImmediatePropagation();
|
|
462
|
+
evt.stopPropagation();
|
|
463
|
+
if (Date.now() - this.lastTriggerTime < 32) {
|
|
464
|
+
this.lastDelta.y += evt.deltaY;
|
|
465
|
+
this.lastDelta.x += evt.deltaX;
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (evt.ctrlKey) {
|
|
469
|
+
const wheelDelta = Math.sign(evt.wheelDelta || 100) * 120;
|
|
470
|
+
const deltaY = evt.deltaY + this.lastDelta.y;
|
|
471
|
+
let scale;
|
|
472
|
+
if (deltaY > 0) {
|
|
473
|
+
scale = Math.max(1 - Math.abs(deltaY / wheelDelta), 1e-8);
|
|
474
|
+
} else {
|
|
475
|
+
scale = 1 + Math.abs(deltaY / wheelDelta);
|
|
476
|
+
}
|
|
477
|
+
scale = Math.max(0.9, scale);
|
|
478
|
+
scale = Math.min(1.1, scale);
|
|
479
|
+
this.emit("scale", scale);
|
|
480
|
+
} else {
|
|
481
|
+
const deltaX = this.lastDelta.x + evt.deltaX;
|
|
482
|
+
const deltaY = this.lastDelta.y + evt.deltaY;
|
|
483
|
+
this.emit("translate", deltaX, deltaY);
|
|
484
|
+
}
|
|
485
|
+
this.lastTriggerTime = Date.now();
|
|
486
|
+
this.lastDelta = {
|
|
487
|
+
x: 0,
|
|
488
|
+
y: 0
|
|
489
|
+
};
|
|
490
|
+
});
|
|
491
|
+
this.view = view;
|
|
492
|
+
this.view.addEventListener("wheel", this.handleWheel, {
|
|
493
|
+
passive: false,
|
|
494
|
+
capture: true
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
dispose() {
|
|
498
|
+
this.view.removeEventListener("wheel", this.handleWheel);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/Container.ts
|
|
503
|
+
var ContainerKeys = {
|
|
504
|
+
scale: "scale",
|
|
505
|
+
translateX: "translateX",
|
|
506
|
+
translateY: "translateY",
|
|
507
|
+
pageIndex: "pageIndex"
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// src/ContinuousContainer.ts
|
|
511
|
+
function _defineProperty6(e, r, t) {
|
|
512
|
+
return (r = _toPropertyKey6(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
513
|
+
}
|
|
514
|
+
function _toPropertyKey6(t) {
|
|
515
|
+
var i = _toPrimitive6(t, "string");
|
|
516
|
+
return "symbol" == typeof i ? i : i + "";
|
|
517
|
+
}
|
|
518
|
+
function _toPrimitive6(t, r) {
|
|
519
|
+
if ("object" != typeof t || !t) return t;
|
|
520
|
+
var e = t[Symbol.toPrimitive];
|
|
521
|
+
if (void 0 !== e) {
|
|
522
|
+
var i = e.call(t, r || "default");
|
|
523
|
+
if ("object" != typeof i) return i;
|
|
524
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
525
|
+
}
|
|
526
|
+
return ("string" === r ? String : Number)(t);
|
|
527
|
+
}
|
|
528
|
+
var ContinuousContainer = class {
|
|
529
|
+
get translateY() {
|
|
530
|
+
return this.map.get(ContainerKeys.translateY);
|
|
531
|
+
}
|
|
532
|
+
set translateY(value) {
|
|
533
|
+
this.map.set(ContainerKeys.translateY, value);
|
|
534
|
+
}
|
|
535
|
+
get pageIndex() {
|
|
536
|
+
const step = 1 / this.images.length;
|
|
537
|
+
for (let i = 0; i < this.images.length; i++) {
|
|
538
|
+
if (this.translateY < step * i && Math.abs(this.translateY - step * i) >= 1e-4) {
|
|
539
|
+
return i - 1;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return this.images.length - 1;
|
|
543
|
+
}
|
|
544
|
+
constructor(map, whiteboardApp, parentView, imageDoc) {
|
|
545
|
+
_defineProperty6(this, "view", void 0);
|
|
546
|
+
_defineProperty6(this, "parentView", void 0);
|
|
547
|
+
_defineProperty6(this, "resizeObserver", void 0);
|
|
548
|
+
_defineProperty6(this, "images", []);
|
|
549
|
+
_defineProperty6(this, "scroll", void 0);
|
|
550
|
+
_defineProperty6(this, "map", void 0);
|
|
551
|
+
_defineProperty6(this, "whiteboardApp", void 0);
|
|
552
|
+
_defineProperty6(this, "imageDoc", void 0);
|
|
553
|
+
_defineProperty6(this, "totalHeight", 0);
|
|
554
|
+
_defineProperty6(this, "localScale", 1);
|
|
555
|
+
_defineProperty6(this, "handleMapChange", (event) => {
|
|
556
|
+
if (event.keysChanged.has(ContainerKeys.translateY)) {
|
|
557
|
+
this.updateSyncedTransform();
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
_defineProperty6(this, "handleResize", () => {
|
|
561
|
+
const bound = this.view.getBoundingClientRect();
|
|
562
|
+
let scaledHeight = 0;
|
|
563
|
+
for (const image of this.images) {
|
|
564
|
+
let scale = bound.width / image.width;
|
|
565
|
+
image.scale(scale);
|
|
566
|
+
scaledHeight += image.height * scale;
|
|
567
|
+
}
|
|
568
|
+
this.localScale = scaledHeight / this.totalHeight;
|
|
569
|
+
this.whiteboardApp.updateOptionSize(bound.width, bound.height);
|
|
570
|
+
this.whiteboardApp.adjustByOutFrame(bound.width, bound.height);
|
|
571
|
+
this.updateSyncedTransform();
|
|
572
|
+
});
|
|
573
|
+
_defineProperty6(this, "updateSyncedTransform", () => {
|
|
574
|
+
const bounds = this.view.getBoundingClientRect();
|
|
575
|
+
const maxTy = this.totalHeight * this.localScale - bounds.height;
|
|
576
|
+
let ty = this.translateY * this.totalHeight * this.localScale;
|
|
577
|
+
ty = Math.min(ty, maxTy);
|
|
578
|
+
ty = Math.max(ty, 0);
|
|
579
|
+
this.view.style.transform = `translate(0, ${-ty}px)`;
|
|
580
|
+
this.whiteboardApp.emitter.resetCamera();
|
|
581
|
+
this.whiteboardApp.emitter.translateCamera(0, -ty);
|
|
582
|
+
this.whiteboardApp.emitter.scaleCamera(this.localScale, "top-left");
|
|
583
|
+
console.log("localScale: ", this.localScale, this.translateY);
|
|
584
|
+
this.handleGoto(this.pageIndex);
|
|
585
|
+
});
|
|
586
|
+
this.imageDoc = imageDoc;
|
|
587
|
+
this.parentView = parentView;
|
|
588
|
+
this.map = map;
|
|
589
|
+
this.scroll = new InfinityScroll(this.parentView);
|
|
590
|
+
this.whiteboardApp = whiteboardApp;
|
|
591
|
+
this.view = document.createElement("div");
|
|
592
|
+
this.view.style.width = "100%";
|
|
593
|
+
this.view.style.height = "100%";
|
|
594
|
+
this.view.style.position = "absolute";
|
|
595
|
+
this.view.style.top = "0";
|
|
596
|
+
this.view.style.left = "0";
|
|
597
|
+
this.view.style.transformOrigin = "0, 0";
|
|
598
|
+
this.view.setAttribute("data-imagery-container", "continuous");
|
|
599
|
+
this.resizeObserver = new ResizeObserver(this.handleResize);
|
|
600
|
+
this.resizeObserver.observe(this.view);
|
|
601
|
+
this.whiteboardApp.updateInternalResizeObserverStatus(false);
|
|
602
|
+
this.map.observe(this.handleMapChange);
|
|
603
|
+
if (!this.map.has(ContainerKeys.scale)) {
|
|
604
|
+
this.map.set(ContainerKeys.scale, 1);
|
|
605
|
+
}
|
|
606
|
+
if (!this.map.has(ContainerKeys.translateX)) {
|
|
607
|
+
this.map.set(ContainerKeys.translateX, 0);
|
|
608
|
+
}
|
|
609
|
+
if (!this.map.has(ContainerKeys.translateY)) {
|
|
610
|
+
this.map.set(ContainerKeys.translateY, 0);
|
|
611
|
+
}
|
|
612
|
+
this.scroll.on("translate", (dx, dy) => {
|
|
613
|
+
this.handleTranslate(dx, dy);
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
init() {
|
|
617
|
+
this.updateSyncedTransform();
|
|
618
|
+
this.totalHeight = this.images.reduce((prev, curr) => prev + curr.height, 0);
|
|
619
|
+
}
|
|
620
|
+
handleTranslate(dx, dy) {
|
|
621
|
+
const dyNormalized = dy / this.totalHeight;
|
|
622
|
+
let nextTy = this.translateY + dyNormalized;
|
|
623
|
+
nextTy = Math.max(0, nextTy);
|
|
624
|
+
nextTy = Math.min(1, nextTy);
|
|
625
|
+
this.translateY = nextTy;
|
|
626
|
+
}
|
|
627
|
+
goto(index) {
|
|
628
|
+
let nextIndex = Math.max(0, index);
|
|
629
|
+
nextIndex = Math.min(this.images.length - 1, nextIndex);
|
|
630
|
+
this.translateY = nextIndex / this.images.length;
|
|
631
|
+
}
|
|
632
|
+
append(image) {
|
|
633
|
+
this.images.push(image);
|
|
634
|
+
this.view.appendChild(image.view);
|
|
635
|
+
}
|
|
636
|
+
async handleGoto(index) {
|
|
637
|
+
if (index < 0 || index >= this.images.length) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
this.imageDoc.emit("renderStart", index);
|
|
641
|
+
const target = this.images[index];
|
|
642
|
+
if (target) {
|
|
643
|
+
await target.prepare();
|
|
644
|
+
}
|
|
645
|
+
this.imageDoc.emit("renderEnd", index);
|
|
646
|
+
for (let i = index - 3; i <= index + 3; i++) {
|
|
647
|
+
const img = this.images[i];
|
|
648
|
+
if (img) {
|
|
649
|
+
img.prepare();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
dispose() {
|
|
654
|
+
this.resizeObserver.disconnect();
|
|
655
|
+
this.scroll.dispose();
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
// src/SingleContainer.ts
|
|
660
|
+
function _defineProperty7(e, r, t) {
|
|
661
|
+
return (r = _toPropertyKey7(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
662
|
+
}
|
|
663
|
+
function _toPropertyKey7(t) {
|
|
664
|
+
var i = _toPrimitive7(t, "string");
|
|
665
|
+
return "symbol" == typeof i ? i : i + "";
|
|
666
|
+
}
|
|
667
|
+
function _toPrimitive7(t, r) {
|
|
668
|
+
if ("object" != typeof t || !t) return t;
|
|
669
|
+
var e = t[Symbol.toPrimitive];
|
|
670
|
+
if (void 0 !== e) {
|
|
671
|
+
var i = e.call(t, r || "default");
|
|
672
|
+
if ("object" != typeof i) return i;
|
|
673
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
674
|
+
}
|
|
675
|
+
return ("string" === r ? String : Number)(t);
|
|
676
|
+
}
|
|
677
|
+
var delay = (value) => new Promise((resolve) => setTimeout(resolve, value));
|
|
678
|
+
async function waitUntil(fn, timeout) {
|
|
679
|
+
let start = Date.now();
|
|
680
|
+
while (!fn() && Date.now() - start < timeout) {
|
|
681
|
+
await delay(50);
|
|
682
|
+
start = Date.now();
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
var SingleContainer = class {
|
|
686
|
+
get scale() {
|
|
687
|
+
return this.map.get(ContainerKeys.scale);
|
|
688
|
+
}
|
|
689
|
+
set scale(value) {
|
|
690
|
+
this.map.set(ContainerKeys.scale, value);
|
|
691
|
+
}
|
|
692
|
+
get translateX() {
|
|
693
|
+
return this.map.get(ContainerKeys.translateX);
|
|
694
|
+
}
|
|
695
|
+
set translateX(value) {
|
|
696
|
+
this.map.set(ContainerKeys.translateX, value);
|
|
697
|
+
}
|
|
698
|
+
get translateY() {
|
|
699
|
+
return this.map.get(ContainerKeys.translateY);
|
|
700
|
+
}
|
|
701
|
+
set translateY(value) {
|
|
702
|
+
this.map.set(ContainerKeys.translateY, value);
|
|
703
|
+
}
|
|
704
|
+
get pageIndex() {
|
|
705
|
+
return this.map.get(ContainerKeys.pageIndex);
|
|
706
|
+
}
|
|
707
|
+
constructor(map, whiteboardApp, parentView, imageDoc) {
|
|
708
|
+
_defineProperty7(this, "view", void 0);
|
|
709
|
+
_defineProperty7(this, "parentView", void 0);
|
|
710
|
+
_defineProperty7(this, "resizeObserver", void 0);
|
|
711
|
+
_defineProperty7(this, "images", []);
|
|
712
|
+
_defineProperty7(this, "currentImage", null);
|
|
713
|
+
_defineProperty7(this, "scroll", void 0);
|
|
714
|
+
_defineProperty7(this, "map", void 0);
|
|
715
|
+
_defineProperty7(this, "whiteboardApp", void 0);
|
|
716
|
+
_defineProperty7(this, "timeoutId", null);
|
|
717
|
+
_defineProperty7(this, "imageDoc", void 0);
|
|
718
|
+
_defineProperty7(this, "handleMapChange", (event) => {
|
|
719
|
+
if (event.keysChanged.has(ContainerKeys.scale) || event.keysChanged.has(ContainerKeys.translateX) || event.keysChanged.has(ContainerKeys.translateY)) {
|
|
720
|
+
this.updateSyncedTransform();
|
|
721
|
+
}
|
|
722
|
+
if (event.keysChanged.has(ContainerKeys.pageIndex)) {
|
|
723
|
+
this.handleGoto(this.pageIndex).catch((error) => {
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
_defineProperty7(this, "handleResize", () => {
|
|
728
|
+
const bound = this.parentView.getBoundingClientRect();
|
|
729
|
+
if (this.currentImage) {
|
|
730
|
+
let scale = bound.width / this.currentImage.width;
|
|
731
|
+
if (this.currentImage.height * scale > bound.height) {
|
|
732
|
+
scale = bound.height / this.currentImage.height;
|
|
733
|
+
}
|
|
734
|
+
const tx = Math.round((bound.width - this.currentImage.width * scale) / 2 / scale);
|
|
735
|
+
const ty = Math.round((bound.height - this.currentImage.height * scale) / 2 / scale);
|
|
736
|
+
this.currentImage.view.style.transform = `scale(${scale}) translate(${tx}px, ${ty}px)`;
|
|
737
|
+
this.updateSyncedTransform();
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
_defineProperty7(this, "updateSyncedTransform", () => {
|
|
741
|
+
if (!this.currentImage) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
const parentBounds = this.parentView.getBoundingClientRect();
|
|
745
|
+
const tx = -this.translateX * parentBounds.width / this.scale;
|
|
746
|
+
const ty = -this.translateY * parentBounds.height / this.scale;
|
|
747
|
+
this.view.style.transform = `scale(${this.scale}) translate(${tx}px, ${ty}px)`;
|
|
748
|
+
const whiteboardView = this.whiteboardApp.emitter.view;
|
|
749
|
+
whiteboardView.style.width = `${parentBounds.width}px`;
|
|
750
|
+
whiteboardView.style.height = `${parentBounds.height}px`;
|
|
751
|
+
whiteboardView.style.top = "0";
|
|
752
|
+
whiteboardView.style.left = "0";
|
|
753
|
+
whiteboardView.style.transform = `scale(${this.scale}) translate(${tx}px, ${ty}px)`;
|
|
754
|
+
this.whiteboardApp.adjustByOutFrame(parentBounds.width, parentBounds.height);
|
|
755
|
+
window.clearTimeout(this.timeoutId);
|
|
756
|
+
this.timeoutId = window.setTimeout(() => {
|
|
757
|
+
whiteboardView.style.width = `${parentBounds.width * this.scale}px`;
|
|
758
|
+
whiteboardView.style.height = `${parentBounds.height * this.scale}px`;
|
|
759
|
+
whiteboardView.style.top = `${-(this.scale - 1) * parentBounds.height / 2 + ty * this.scale}px`;
|
|
760
|
+
whiteboardView.style.left = `${-(this.scale - 1) * parentBounds.width / 2 + tx * this.scale}px`;
|
|
761
|
+
whiteboardView.style.transform = `scale(1) translate(0px, 0px)`;
|
|
762
|
+
this.whiteboardApp.adjustByOutFrame(parentBounds.width * this.scale, parentBounds.height * this.scale);
|
|
763
|
+
}, 200);
|
|
764
|
+
});
|
|
765
|
+
this.imageDoc = imageDoc;
|
|
766
|
+
this.parentView = parentView;
|
|
767
|
+
this.map = map;
|
|
768
|
+
this.scroll = new InfinityScroll(this.parentView);
|
|
769
|
+
this.whiteboardApp = whiteboardApp;
|
|
770
|
+
this.view = document.createElement("div");
|
|
771
|
+
this.view.style.width = "100%";
|
|
772
|
+
this.view.style.height = "100%";
|
|
773
|
+
this.view.style.position = "absolute";
|
|
774
|
+
this.view.style.top = "0";
|
|
775
|
+
this.view.style.left = "0";
|
|
776
|
+
this.view.style.transformOrigin = "center";
|
|
777
|
+
this.view.setAttribute("data-imagery-container", "single");
|
|
778
|
+
this.resizeObserver = new ResizeObserver(this.handleResize);
|
|
779
|
+
this.resizeObserver.observe(this.view);
|
|
780
|
+
window.imageWhiteboard = this.whiteboardApp;
|
|
781
|
+
this.whiteboardApp.updateInternalResizeObserverStatus(false);
|
|
782
|
+
this.map.observe(this.handleMapChange);
|
|
783
|
+
if (!this.map.has(ContainerKeys.scale)) {
|
|
784
|
+
this.map.set(ContainerKeys.scale, 1);
|
|
785
|
+
}
|
|
786
|
+
if (!this.map.has(ContainerKeys.translateX)) {
|
|
787
|
+
this.map.set(ContainerKeys.translateX, 0);
|
|
788
|
+
}
|
|
789
|
+
if (!this.map.has(ContainerKeys.translateY)) {
|
|
790
|
+
this.map.set(ContainerKeys.translateY, 0);
|
|
791
|
+
}
|
|
792
|
+
if (!this.map.has(ContainerKeys.pageIndex)) {
|
|
793
|
+
this.map.set(ContainerKeys.pageIndex, 0);
|
|
794
|
+
}
|
|
795
|
+
this.scroll.on("translate", (dx, dy) => {
|
|
796
|
+
this.handleTranslate(dx, dy);
|
|
797
|
+
});
|
|
798
|
+
this.scroll.on("scale", (scale) => {
|
|
799
|
+
let nextScale = this.scale * scale;
|
|
800
|
+
nextScale = Math.max(1, nextScale);
|
|
801
|
+
nextScale = Math.min(2, nextScale);
|
|
802
|
+
this.scale = nextScale;
|
|
803
|
+
this.handleTranslate(0, 0);
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
init() {
|
|
807
|
+
this.handleGoto(this.pageIndex).catch((error) => {
|
|
808
|
+
});
|
|
809
|
+
this.updateSyncedTransform();
|
|
810
|
+
}
|
|
811
|
+
handleTranslate(dx, dy) {
|
|
812
|
+
const image = this.view.children[0];
|
|
813
|
+
if (!image) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
const imageBounds = image.getBoundingClientRect();
|
|
817
|
+
const parentBounds = this.parentView.getBoundingClientRect();
|
|
818
|
+
const maxDx = (imageBounds.width - parentBounds.width) / 2;
|
|
819
|
+
const maxDy = (imageBounds.height - parentBounds.height) / 2;
|
|
820
|
+
if (maxDx > 0) {
|
|
821
|
+
let nextDx = this.translateX * parentBounds.width + dx;
|
|
822
|
+
if (nextDx >= 0) {
|
|
823
|
+
nextDx = Math.min(nextDx, maxDx);
|
|
824
|
+
} else {
|
|
825
|
+
nextDx = Math.max(nextDx, -maxDx);
|
|
826
|
+
}
|
|
827
|
+
this.translateX = nextDx / parentBounds.width;
|
|
828
|
+
} else {
|
|
829
|
+
this.translateX = 0;
|
|
830
|
+
}
|
|
831
|
+
if (maxDy > 0) {
|
|
832
|
+
let nextDy = this.translateY * parentBounds.height + dy;
|
|
833
|
+
if (nextDy >= 0) {
|
|
834
|
+
nextDy = Math.min(nextDy, maxDy);
|
|
835
|
+
} else {
|
|
836
|
+
nextDy = Math.max(nextDy, -maxDy);
|
|
837
|
+
}
|
|
838
|
+
this.translateY = nextDy / parentBounds.height;
|
|
839
|
+
} else {
|
|
840
|
+
this.translateY = 0;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
goto(index) {
|
|
844
|
+
let nextIndex = Math.max(0, index);
|
|
845
|
+
nextIndex = Math.min(this.images.length - 1, nextIndex);
|
|
846
|
+
this.map.set(ContainerKeys.pageIndex, nextIndex);
|
|
847
|
+
}
|
|
848
|
+
append(image) {
|
|
849
|
+
this.images.push(image);
|
|
850
|
+
}
|
|
851
|
+
async handleGoto(index) {
|
|
852
|
+
await waitUntil(() => this.images.length > 0, 3e3);
|
|
853
|
+
if (index < 0 || index >= this.images.length) {
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
this.imageDoc.emit("renderStart", index);
|
|
857
|
+
if (this.view.children[0]) {
|
|
858
|
+
this.view.removeChild(this.view.children[0]);
|
|
859
|
+
}
|
|
860
|
+
this.whiteboardApp.emitter.view.style.opacity = "0";
|
|
861
|
+
const target = this.images[index];
|
|
862
|
+
if (target) {
|
|
863
|
+
await target.prepare();
|
|
864
|
+
this.view.appendChild(target.view);
|
|
865
|
+
this.currentImage = target;
|
|
866
|
+
this.whiteboardApp.emitter.gotoPage(`doc_${index}`);
|
|
867
|
+
this.whiteboardApp.updateOptionSize(this.currentImage.width, this.currentImage.height);
|
|
868
|
+
this.whiteboardApp.emitter.view.style.opacity = "1";
|
|
869
|
+
this.handleResize();
|
|
870
|
+
}
|
|
871
|
+
this.imageDoc.emit("renderEnd", index);
|
|
872
|
+
for (let i = index - 3; i <= index + 3; i++) {
|
|
873
|
+
const img = this.images[i];
|
|
874
|
+
if (img) {
|
|
875
|
+
img.prepare();
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
dispose() {
|
|
880
|
+
this.resizeObserver.disconnect();
|
|
881
|
+
this.scroll.dispose();
|
|
882
|
+
window.clearTimeout(this.timeoutId);
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
// src/ImageryDocApplication.ts
|
|
887
|
+
function _defineProperty8(e, r, t) {
|
|
888
|
+
return (r = _toPropertyKey8(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
|
|
889
|
+
}
|
|
890
|
+
function _toPropertyKey8(t) {
|
|
891
|
+
var i = _toPrimitive8(t, "string");
|
|
892
|
+
return "symbol" == typeof i ? i : i + "";
|
|
893
|
+
}
|
|
894
|
+
function _toPrimitive8(t, r) {
|
|
895
|
+
if ("object" != typeof t || !t) return t;
|
|
896
|
+
var e = t[Symbol.toPrimitive];
|
|
897
|
+
if (void 0 !== e) {
|
|
898
|
+
var i = e.call(t, r || "default");
|
|
899
|
+
if ("object" != typeof i) return i;
|
|
900
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
901
|
+
}
|
|
902
|
+
return ("string" === r ? String : Number)(t);
|
|
903
|
+
}
|
|
904
|
+
var IMAGERY_DOC_APP_NAME = "imagery_doc";
|
|
905
|
+
var ImageryDocApplication = class extends import_forge_room2.AbstractApplication {
|
|
906
|
+
constructor() {
|
|
907
|
+
super();
|
|
908
|
+
_defineProperty8(this, "name", IMAGERY_DOC_APP_NAME);
|
|
909
|
+
_defineProperty8(this, "emitter", new ImageryDoc());
|
|
910
|
+
_defineProperty8(this, "whiteboardApp", void 0);
|
|
911
|
+
_defineProperty8(this, "whiteboard", void 0);
|
|
912
|
+
_defineProperty8(this, "container", void 0);
|
|
913
|
+
_defineProperty8(this, "rootView", document.createElement("div"));
|
|
914
|
+
_defineProperty8(this, "contentContainer", document.createElement("div"));
|
|
915
|
+
_defineProperty8(this, "whiteboardContainer", document.createElement("div"));
|
|
916
|
+
_defineProperty8(this, "footerContainer", document.createElement("div"));
|
|
917
|
+
_defineProperty8(this, "permissions", void 0);
|
|
918
|
+
_defineProperty8(this, "footer", void 0);
|
|
919
|
+
_defineProperty8(this, "images", []);
|
|
920
|
+
this.rootView.setAttribute("data-forge-app", "imagery-doc");
|
|
921
|
+
this.rootView.style.background = "red";
|
|
922
|
+
this.rootView.style.overflow = "hidden";
|
|
923
|
+
this.contentContainer.style.width = "100%";
|
|
924
|
+
this.contentContainer.style.height = "100%";
|
|
925
|
+
this.contentContainer.style.display = "flex";
|
|
926
|
+
this.contentContainer.style.flexDirection = "column";
|
|
927
|
+
this.footer = new FooterView(this.emitter);
|
|
928
|
+
this.rootView.appendChild(this.contentContainer);
|
|
929
|
+
this.emitter.on("renderStart", (pageIndex) => {
|
|
930
|
+
this.footer.prevPageState(pageIndex !== 0);
|
|
931
|
+
this.footer.nextPageState(pageIndex !== this.images.length - 1);
|
|
932
|
+
});
|
|
933
|
+
const that = this;
|
|
934
|
+
Object.defineProperty(this.emitter, "footView", {
|
|
935
|
+
get() {
|
|
936
|
+
return that.footerContainer;
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
Object.defineProperty(this.emitter, "view", {
|
|
940
|
+
get() {
|
|
941
|
+
return that.rootView;
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
Object.defineProperty(this.emitter, "permissions", {
|
|
945
|
+
get() {
|
|
946
|
+
return that.permissions;
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
Object.defineProperty(this.emitter, "pageIndex", {
|
|
950
|
+
get() {
|
|
951
|
+
return that.container.pageIndex;
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
Object.defineProperty(this.emitter, "pageCount", {
|
|
955
|
+
get() {
|
|
956
|
+
return that.images.length;
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
Object.defineProperty(this.emitter, "goto", {
|
|
960
|
+
get() {
|
|
961
|
+
return (index) => {
|
|
962
|
+
if (that.permissions.hasPermission(ImageryDocPermissionFlag.switchPage)) {
|
|
963
|
+
that.container.goto(index);
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
Object.defineProperty(this.emitter, "imgContent", {
|
|
969
|
+
get() {
|
|
970
|
+
return (index) => {
|
|
971
|
+
return that.images[index].getImgContent();
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
Object.defineProperty(this.emitter, "imgSize", {
|
|
976
|
+
get() {
|
|
977
|
+
return (index) => {
|
|
978
|
+
return {
|
|
979
|
+
width: that.images[index].width,
|
|
980
|
+
height: that.images[index].height
|
|
981
|
+
};
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
async initialize(option) {
|
|
987
|
+
const whiteboardApp = new import_forge_whiteboard.WhiteboardApplication();
|
|
988
|
+
whiteboardApp.roomDoc = this.roomDoc;
|
|
989
|
+
whiteboardApp.appId = `${this.appId}_wb`;
|
|
990
|
+
whiteboardApp.userId = this.userId;
|
|
991
|
+
whiteboardApp.userManager = this.userManager;
|
|
992
|
+
whiteboardApp.applicationManager = this.applicationManager;
|
|
993
|
+
await whiteboardApp.initialize({
|
|
994
|
+
width: -1,
|
|
995
|
+
height: -1
|
|
996
|
+
});
|
|
997
|
+
this.whiteboardApp = whiteboardApp;
|
|
998
|
+
this.whiteboard = whiteboardApp.emitter;
|
|
999
|
+
this.whiteboard.enableCameraByMouse = false;
|
|
1000
|
+
this.whiteboard.enableCameraByTouch = false;
|
|
1001
|
+
this.whiteboard.view.style.width = "100%";
|
|
1002
|
+
this.whiteboard.view.style.height = "100%";
|
|
1003
|
+
this.whiteboard.view.style.position = "absolute";
|
|
1004
|
+
this.whiteboard.view.style.top = "0";
|
|
1005
|
+
this.whiteboard.view.style.left = "0";
|
|
1006
|
+
this.whiteboard.setCanvasBackgroundColor("#f0f0f000");
|
|
1007
|
+
if (option.displayMode === "single") {
|
|
1008
|
+
this.container = new SingleContainer(this.getMap("single-container"), whiteboardApp, this.whiteboardContainer, this.emitter);
|
|
1009
|
+
} else {
|
|
1010
|
+
this.container = new ContinuousContainer(this.getMap("continuous-container"), whiteboardApp, this.whiteboardContainer, this.emitter);
|
|
1011
|
+
}
|
|
1012
|
+
this.whiteboardContainer.style.position = "relative";
|
|
1013
|
+
this.whiteboardContainer.style.flex = "1 1 auto";
|
|
1014
|
+
this.whiteboardContainer.style.overflow = "hidden";
|
|
1015
|
+
this.whiteboardContainer.appendChild(this.container.view);
|
|
1016
|
+
this.whiteboardContainer.appendChild(this.whiteboard.view);
|
|
1017
|
+
this.contentContainer.appendChild(this.whiteboardContainer);
|
|
1018
|
+
this.contentContainer.appendChild(this.footerContainer);
|
|
1019
|
+
this.footerContainer.appendChild(this.footer.root);
|
|
1020
|
+
this.whiteboard.setViewModeToMain();
|
|
1021
|
+
let i = 0;
|
|
1022
|
+
this.whiteboard.permissions.addPermission(import_forge_whiteboard.WhiteboardPermissionFlag.mainView);
|
|
1023
|
+
while (i < option.images.length) {
|
|
1024
|
+
const image = option.images[i];
|
|
1025
|
+
this.images[i] = new LazyImage(image.src, image.width, image.height);
|
|
1026
|
+
this.container.append(this.images[i]);
|
|
1027
|
+
if (option.displayMode === "single") {
|
|
1028
|
+
this.whiteboard.addPage(`doc_${i}`);
|
|
1029
|
+
}
|
|
1030
|
+
i += 1;
|
|
1031
|
+
}
|
|
1032
|
+
if (option.displayMode === "continuous") {
|
|
1033
|
+
this.whiteboard.addPage("doc_continuous");
|
|
1034
|
+
this.whiteboard.gotoPage("doc_continuous");
|
|
1035
|
+
}
|
|
1036
|
+
if (option.displayMode === "single") {
|
|
1037
|
+
this.whiteboard.setViewModeToMain();
|
|
1038
|
+
} else {
|
|
1039
|
+
this.whiteboard.setViewModeToFree();
|
|
1040
|
+
}
|
|
1041
|
+
this.permissions = new ImageryDocPermissions(this.userManager, (userId) => {
|
|
1042
|
+
return this.userMap(userId);
|
|
1043
|
+
});
|
|
1044
|
+
this.permissions.addPermission(ImageryDocPermissionFlag.all);
|
|
1045
|
+
this.whiteboardApp.disableViewModel();
|
|
1046
|
+
this.container.init();
|
|
1047
|
+
this.whiteboard.permissions.removePermission(import_forge_whiteboard.WhiteboardPermissionFlag.mainView);
|
|
1048
|
+
if (option.inheritWhiteboardId) {
|
|
1049
|
+
whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
|
|
1050
|
+
}
|
|
1051
|
+
return Promise.resolve(void 0);
|
|
1052
|
+
}
|
|
1053
|
+
userMap(userId) {
|
|
1054
|
+
return this.getMap(`user/${userId}`);
|
|
1055
|
+
}
|
|
1056
|
+
async dispose() {
|
|
1057
|
+
await this.whiteboardApp.dispose();
|
|
1058
|
+
this.rootView.parentElement?.removeChild(this.rootView);
|
|
1059
|
+
this.container.dispose();
|
|
1060
|
+
return Promise.resolve(void 0);
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
_defineProperty8(ImageryDocApplication, "applicationName", IMAGERY_DOC_APP_NAME);
|
|
1064
|
+
//# sourceMappingURL=imagery-doc.js.map
|