@netless/forge-imagery-doc 0.1.2 → 0.1.3
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/changelog.md +4 -0
- package/dist/Container.d.ts +1 -1
- package/dist/Container.d.ts.map +1 -1
- package/dist/ContinuousContainer.d.ts +5 -5
- package/dist/ContinuousContainer.d.ts.map +1 -1
- package/dist/FooterView.d.ts +1 -1
- package/dist/FooterView.d.ts.map +1 -1
- package/dist/ImageryDoc.d.ts +18 -18
- package/dist/ImageryDoc.d.ts.map +1 -1
- package/dist/ImageryDocApplication.d.ts +3 -3
- package/dist/ImageryDocApplication.d.ts.map +1 -1
- package/dist/ImageryDocPermissions.d.ts +26 -25
- package/dist/ImageryDocPermissions.d.ts.map +1 -1
- package/dist/InfinityScroll.d.ts +1 -1
- package/dist/InfinityScroll.d.ts.map +1 -1
- package/dist/LazyImage.d.ts.map +1 -1
- package/dist/SingleContainer.d.ts +6 -6
- package/dist/SingleContainer.d.ts.map +1 -1
- package/dist/imagery-doc.esm.js +92 -51
- package/dist/imagery-doc.esm.js.map +2 -2
- package/dist/imagery-doc.js +92 -51
- package/dist/imagery-doc.js.map +2 -2
- package/dist/index.d.ts +4 -4
- package/package.json +5 -4
- package/src/Container.ts +6 -6
- package/src/ContinuousContainer.ts +135 -135
- package/src/FooterView.ts +121 -121
- package/src/ImageryDoc.ts +17 -17
- package/src/ImageryDocApplication.ts +212 -199
- package/src/ImageryDocPermissions.ts +95 -85
- package/src/InfinityScroll.ts +43 -42
- package/src/LazyImage.ts +55 -55
- package/src/SingleContainer.ts +236 -226
- package/src/icons.ts +3 -3
- package/src/index.ts +4 -4
package/src/InfinityScroll.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import EventEmitter from
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
2
|
|
|
3
3
|
interface InfinityScrollEvents {
|
|
4
4
|
scale: (value: number) => void;
|
|
@@ -7,49 +7,50 @@ interface InfinityScrollEvents {
|
|
|
7
7
|
|
|
8
8
|
export class InfinityScroll extends EventEmitter<InfinityScrollEvents> {
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
public readonly view: HTMLDivElement;
|
|
11
|
+
private lastDelta: {x: number, y: number} = { x: 0, y: 0 };
|
|
12
|
+
private lastTriggerTime: number = 0;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
private handleWheel = (evt: WheelEvent) => {
|
|
21
|
-
evt.preventDefault();
|
|
22
|
-
evt.stopImmediatePropagation();
|
|
23
|
-
evt.stopPropagation();
|
|
14
|
+
public constructor(view: HTMLDivElement) {
|
|
15
|
+
super();
|
|
16
|
+
this.view = view;
|
|
17
|
+
this.view.addEventListener('wheel', this.handleWheel, { passive: false, capture: true });
|
|
18
|
+
}
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
if (evt.ctrlKey) { // 双指捏合
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
const wheelDelta = Math.sign((evt.wheelDelta || 100)) * 120;
|
|
33
|
-
const deltaY = evt.deltaY + this.lastDelta.y;
|
|
34
|
-
let scale: number;
|
|
35
|
-
if (deltaY > 0) {
|
|
36
|
-
scale = Math.max(1 - Math.abs(deltaY / wheelDelta), 0.00000001)
|
|
37
|
-
} else { // 放大
|
|
38
|
-
scale = 1 + Math.abs(deltaY / wheelDelta)
|
|
39
|
-
}
|
|
40
|
-
scale = Math.max(0.9, scale);
|
|
41
|
-
scale = Math.min(1.1, scale);
|
|
42
|
-
this.emit("scale", scale);
|
|
43
|
-
} else { // 拖动
|
|
44
|
-
const deltaX = this.lastDelta.x + evt.deltaX;
|
|
45
|
-
const deltaY = this.lastDelta.y + evt.deltaY;
|
|
46
|
-
this.emit("translate", deltaX, deltaY);
|
|
47
|
-
}
|
|
48
|
-
this.lastTriggerTime = Date.now();
|
|
49
|
-
this.lastDelta = { x: 0, y: 0 };
|
|
50
|
-
};
|
|
20
|
+
private handleWheel = (evt: WheelEvent) => {
|
|
21
|
+
evt.preventDefault();
|
|
22
|
+
evt.stopImmediatePropagation();
|
|
23
|
+
evt.stopPropagation();
|
|
51
24
|
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
if (Date.now() - this.lastTriggerTime < 32) {
|
|
26
|
+
this.lastDelta.y += evt.deltaY;
|
|
27
|
+
this.lastDelta.x += evt.deltaX;
|
|
28
|
+
return;
|
|
54
29
|
}
|
|
30
|
+
if (evt.ctrlKey) { // 双指捏合
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const wheelDelta = Math.sign((evt.wheelDelta || 100)) * 120;
|
|
33
|
+
const deltaY = evt.deltaY + this.lastDelta.y;
|
|
34
|
+
let scale: number;
|
|
35
|
+
if (deltaY > 0) {
|
|
36
|
+
scale = Math.max(1 - Math.abs(deltaY / wheelDelta), 0.00000001);
|
|
37
|
+
} else { // 放大
|
|
38
|
+
scale = 1 + Math.abs(deltaY / wheelDelta);
|
|
39
|
+
}
|
|
40
|
+
scale = Math.max(0.9, scale);
|
|
41
|
+
scale = Math.min(1.1, scale);
|
|
42
|
+
this.emit('scale', scale);
|
|
43
|
+
} else { // 拖动
|
|
44
|
+
const deltaX = this.lastDelta.x + evt.deltaX;
|
|
45
|
+
const deltaY = this.lastDelta.y + evt.deltaY;
|
|
46
|
+
this.emit('translate', deltaX, deltaY);
|
|
47
|
+
}
|
|
48
|
+
this.lastTriggerTime = Date.now();
|
|
49
|
+
this.lastDelta = { x: 0, y: 0 };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
public dispose() {
|
|
53
|
+
this.view.removeEventListener('wheel', this.handleWheel);
|
|
54
|
+
this.removeAllListeners();
|
|
55
|
+
}
|
|
55
56
|
}
|
package/src/LazyImage.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { kvStore } from
|
|
1
|
+
import { kvStore } from '@netless/forge-room';
|
|
2
2
|
|
|
3
3
|
export class LazyImage {
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
public readonly view: HTMLDivElement;
|
|
6
|
+
public readonly width: number;
|
|
7
|
+
public readonly height: number;
|
|
8
|
+
private src: string;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
public constructor(src: string, width: number, height: number) {
|
|
11
|
+
this.src = src;
|
|
12
|
+
this.width = width;
|
|
13
|
+
this.height = height;
|
|
14
|
+
this.view = document.createElement('div');
|
|
15
|
+
this.view.setAttribute('data-forge-src', src);
|
|
16
|
+
this.view.style.width = `${width}px`;
|
|
17
|
+
this.view.style.height = `${height}px`;
|
|
18
|
+
this.view.style.transformOrigin = '0 0';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public scale(scale: number) {
|
|
22
|
+
// this.localScale = scale;
|
|
23
|
+
this.view.style.width = `${this.width * scale}px`;
|
|
24
|
+
this.view.style.height = `${this.height * scale}px`;
|
|
25
|
+
// this.img.style.width = "100%";
|
|
26
|
+
}
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
public async getImgContent(): Promise<string> {
|
|
29
|
+
let base64Data: string | null = null;
|
|
30
|
+
try {
|
|
31
|
+
base64Data = await kvStore.getItem(this.src);
|
|
32
|
+
} catch {
|
|
33
|
+
// ignore
|
|
34
|
+
}
|
|
35
|
+
if (base64Data) {
|
|
36
|
+
return base64Data;
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
const response = await fetch(this.src);
|
|
40
|
+
const blob = await response.blob();
|
|
41
|
+
return new Promise<string>((resolve, reject) => {
|
|
42
|
+
const reader = new FileReader();
|
|
43
|
+
reader.onload = (_e) => {
|
|
44
|
+
kvStore.setItem(this.src, reader.result as string);
|
|
45
|
+
resolve(reader.result as string);
|
|
46
|
+
};
|
|
47
|
+
reader.onerror = () => {
|
|
48
|
+
reject(reader.error);
|
|
49
|
+
};
|
|
50
|
+
reader.readAsDataURL(blob);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
38
53
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const reader = new FileReader();
|
|
43
|
-
reader.onload = (e) => {
|
|
44
|
-
kvStore.setItem(this.src, reader.result as string);
|
|
45
|
-
resolve(reader.result as string);
|
|
46
|
-
};
|
|
47
|
-
reader.onerror = () => {
|
|
48
|
-
reject(reader.error);
|
|
49
|
-
};
|
|
50
|
-
reader.readAsDataURL(blob);
|
|
51
|
-
});
|
|
54
|
+
public async prepare(): Promise<void> {
|
|
55
|
+
if (this.view.children.length > 0) {
|
|
56
|
+
return;
|
|
52
57
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const img = document.createElement("img");
|
|
60
|
-
img.src = base64Data;
|
|
61
|
-
img.style.width = "100%";
|
|
62
|
-
if (this.view.children.length === 0) {
|
|
63
|
-
this.view.appendChild(img);
|
|
64
|
-
}
|
|
58
|
+
const base64Data: string = await this.getImgContent();
|
|
59
|
+
const img = document.createElement('img');
|
|
60
|
+
img.src = base64Data;
|
|
61
|
+
img.style.width = '100%';
|
|
62
|
+
if (this.view.children.length === 0) {
|
|
63
|
+
this.view.appendChild(img);
|
|
65
64
|
}
|
|
65
|
+
}
|
|
66
66
|
}
|