merong-docs 0.1.11 → 1.0.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/OVERVIEW.md +19 -19
- package/OVERVIEW.zh-CN.md +19 -22
- package/README.md +77 -77
- package/README.zh-CN.md +81 -81
- package/client/android-file-share.ts +25 -25
- package/client/controls.tsx +163 -163
- package/client/document-panel.tsx +166 -166
- package/client/external-file.tsx +78 -78
- package/client/file-reader.tsx +43 -43
- package/client/markdown-panel.tsx +737 -737
- package/client/markdown-scroll.ts +122 -122
- package/client/messages.ts +224 -224
- package/client/native-contacts.ts +145 -145
- package/client/page-render-queue.ts +12 -12
- package/client/page-selection.tsx +227 -227
- package/client/page-tools.tsx +72 -72
- package/client/pdf-geometry.ts +96 -96
- package/client/pdf-panel.tsx +477 -477
- package/client/reader-find.tsx +190 -190
- package/client/reader-notice.tsx +46 -46
- package/client/settings.tsx +143 -143
- package/client/syntax.tsx +55 -55
- package/client/viewport-geometry.ts +61 -61
- package/client/web.ts +462 -462
- package/client/worksheet-panel.tsx +631 -631
- package/client/zoom-controls.tsx +140 -140
- package/index.client.tsx +36 -36
- package/index.server.ts +73 -73
- package/node_modules/markdown-it/bin/markdown-it.mjs +0 -0
- package/node_modules/yaml/bin.mjs +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/scripts/prepare-office.mjs +20 -20
- package/server/engine.ts +89 -89
- package/server/external-file.ts +42 -42
- package/server/generated/document-worker.ts +1 -1
- package/server/generated/rust-reader_bg.wasm +0 -0
- package/server/markdown-index.ts +305 -305
- package/server/markdown-links.ts +51 -51
- package/server/markdown-page.ts +120 -120
- package/server/office-fonts.cjs +824 -824
- package/server/office-location.ts +41 -41
- package/server/office-preview.ts +186 -186
- package/server/office-worker.cjs +49 -49
- package/server/office-xml.ts +79 -79
- package/server/pdf-engine.ts +168 -168
- package/server/pdf-text-geometry.ts +60 -60
- package/server/rust-reader.ts +40 -40
- package/server/structured-document.ts +69 -69
- package/server/text-search.ts +15 -15
- package/server/worker-entry.ts +42 -42
- package/server/worker-protocol.ts +38 -38
- package/server/worksheet.ts +67 -67
- package/server/workspace-file.ts +63 -63
- package/shared/contracts.ts +187 -187
- package/shared/file-limits.ts +5 -5
- package/shared/markdown-constants.ts +4 -4
- package/shared/markdown-math.ts +198 -198
- package/shared/markdown-references.ts +83 -83
- package/shared/markdown-source-location.ts +8 -8
- package/shared/reader-settings.ts +15 -15
- package/shared/reader-shortcuts.ts +132 -132
- package/vendor/office2pdf/office2pdf_bg.wasm +2 -2
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import { useCallback, useLayoutEffect, useMemo, useRef, type RefObject } from "react";
|
|
2
|
-
import type { GestureResponderEvent, GestureResponderHandlers, View } from "react-native";
|
|
3
|
-
import type { Contact, Point } from "./viewport-geometry";
|
|
4
|
-
|
|
5
|
-
const flickWindow = 90;
|
|
6
|
-
const decelerationTime = 220;
|
|
7
|
-
const minFlingSpeed = 0.06;
|
|
8
|
-
const maxFlingSpeed = 3;
|
|
9
|
-
|
|
10
|
-
function readContacts({ nativeEvent }: GestureResponderEvent): Contact[] {
|
|
11
|
-
return nativeEvent.touches.slice(0, 2)
|
|
12
|
-
.map(({ identifier, pageX, pageY }) => ({ id: Number(identifier), x: pageX, y: pageY }))
|
|
13
|
-
.sort((first, second) => first.id - second.id);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function useNativeContacts(
|
|
17
|
-
viewport: RefObject<View | null>,
|
|
18
|
-
enabled: boolean,
|
|
19
|
-
onMove: (previous: Contact[], next: Contact[]) => void,
|
|
20
|
-
onGlide: (delta: Point) => boolean,
|
|
21
|
-
intercept?: (contacts: Contact[], pageContacts: Contact[]) => boolean,
|
|
22
|
-
): { handlers: GestureResponderHandlers; stopInertia: () => void } {
|
|
23
|
-
const move = useRef(onMove);
|
|
24
|
-
const glide = useRef(onGlide);
|
|
25
|
-
const interaction = useRef(intercept);
|
|
26
|
-
const origin = useRef<Point>({ x: 0, y: 0 });
|
|
27
|
-
const previous = useRef<Contact[]>([]);
|
|
28
|
-
const pending = useRef<Contact[]>([]);
|
|
29
|
-
const frame = useRef<number | undefined>(undefined);
|
|
30
|
-
const inertiaFrame = useRef<number | undefined>(undefined);
|
|
31
|
-
const lastMove = useRef(0);
|
|
32
|
-
const pendingTime = useRef(0);
|
|
33
|
-
const velocity = useRef<Point>({ x: 0, y: 0 });
|
|
34
|
-
|
|
35
|
-
const stopInertia = useCallback(() => {
|
|
36
|
-
if (inertiaFrame.current !== undefined) cancelAnimationFrame(inertiaFrame.current);
|
|
37
|
-
inertiaFrame.current = undefined;
|
|
38
|
-
}, []);
|
|
39
|
-
useLayoutEffect(() => {
|
|
40
|
-
move.current = onMove;
|
|
41
|
-
glide.current = onGlide;
|
|
42
|
-
interaction.current = intercept;
|
|
43
|
-
}, [onMove, onGlide, intercept]);
|
|
44
|
-
useLayoutEffect(() => () => {
|
|
45
|
-
stopInertia();
|
|
46
|
-
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
|
47
|
-
frame.current = undefined;
|
|
48
|
-
previous.current = [];
|
|
49
|
-
}, [enabled, stopInertia]);
|
|
50
|
-
|
|
51
|
-
const handlers = useMemo<GestureResponderHandlers>(() => {
|
|
52
|
-
if (!enabled) return {};
|
|
53
|
-
|
|
54
|
-
const toViewport = (contact: Contact) => ({
|
|
55
|
-
id: contact.id, x: contact.x - origin.current.x, y: contact.y - origin.current.y,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
function flush() {
|
|
59
|
-
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
|
60
|
-
frame.current = undefined;
|
|
61
|
-
const before = previous.current;
|
|
62
|
-
const next = pending.current;
|
|
63
|
-
previous.current = next;
|
|
64
|
-
const elapsed = pendingTime.current - lastMove.current;
|
|
65
|
-
lastMove.current = pendingTime.current;
|
|
66
|
-
if (before.length === 1 && next.length === 1 && before[0].id === next[0].id && elapsed > 0) {
|
|
67
|
-
const weight = 1 - Math.exp(-elapsed / 35);
|
|
68
|
-
velocity.current = {
|
|
69
|
-
x: velocity.current.x * (1 - weight) + (next[0].x - before[0].x) / elapsed * weight,
|
|
70
|
-
y: velocity.current.y * (1 - weight) + (next[0].y - before[0].y) / elapsed * weight,
|
|
71
|
-
};
|
|
72
|
-
} else {
|
|
73
|
-
velocity.current = { x: 0, y: 0 };
|
|
74
|
-
}
|
|
75
|
-
const contacts = next.map(toViewport);
|
|
76
|
-
if (interaction.current?.(contacts, next)) velocity.current = { x: 0, y: 0 };
|
|
77
|
-
else if (before.length && next.length) move.current(before.map(toViewport), contacts);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function rebase(event: GestureResponderEvent) {
|
|
81
|
-
if (frame.current !== undefined) flush();
|
|
82
|
-
previous.current = readContacts(event);
|
|
83
|
-
interaction.current?.(previous.current.map(toViewport), previous.current);
|
|
84
|
-
lastMove.current = performance.now();
|
|
85
|
-
velocity.current = { x: 0, y: 0 };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function release() {
|
|
89
|
-
if (frame.current !== undefined) flush();
|
|
90
|
-
const handled = interaction.current?.([], []);
|
|
91
|
-
const now = performance.now();
|
|
92
|
-
const speed = Math.hypot(velocity.current.x, velocity.current.y);
|
|
93
|
-
const canGlide = !handled && previous.current.length === 1 && now - lastMove.current <= flickWindow && speed >= minFlingSpeed;
|
|
94
|
-
previous.current = [];
|
|
95
|
-
if (!canGlide) return;
|
|
96
|
-
|
|
97
|
-
let lastFrameTime = now;
|
|
98
|
-
let remaining = Math.min(speed, maxFlingSpeed);
|
|
99
|
-
const direction = { x: velocity.current.x / speed, y: velocity.current.y / speed };
|
|
100
|
-
function step() {
|
|
101
|
-
inertiaFrame.current = undefined;
|
|
102
|
-
const time = performance.now();
|
|
103
|
-
const nextSpeed = remaining * Math.exp(-Math.min(time - lastFrameTime, 32) / decelerationTime);
|
|
104
|
-
const distance = (remaining - nextSpeed) * decelerationTime;
|
|
105
|
-
lastFrameTime = time;
|
|
106
|
-
remaining = nextSpeed;
|
|
107
|
-
if (remaining < minFlingSpeed || !glide.current({ x: direction.x * distance, y: direction.y * distance })) return;
|
|
108
|
-
inertiaFrame.current = requestAnimationFrame(step);
|
|
109
|
-
}
|
|
110
|
-
inertiaFrame.current = requestAnimationFrame(step);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
onStartShouldSetResponder: () => true,
|
|
115
|
-
onMoveShouldSetResponder: () => true,
|
|
116
|
-
onResponderGrant(event) {
|
|
117
|
-
stopInertia();
|
|
118
|
-
const { pageX, pageY, locationX, locationY } = event.nativeEvent;
|
|
119
|
-
origin.current = { x: pageX - locationX, y: pageY - locationY };
|
|
120
|
-
viewport.current?.measure((_left, _top, _width, _height, x, y) => { origin.current = { x, y }; });
|
|
121
|
-
rebase(event);
|
|
122
|
-
return true;
|
|
123
|
-
},
|
|
124
|
-
onResponderStart: rebase,
|
|
125
|
-
onResponderEnd(event) {
|
|
126
|
-
if (event.nativeEvent.touches.length > 0) rebase(event);
|
|
127
|
-
},
|
|
128
|
-
onResponderMove(event) {
|
|
129
|
-
pending.current = readContacts(event);
|
|
130
|
-
pendingTime.current = performance.now();
|
|
131
|
-
frame.current ??= requestAnimationFrame(flush);
|
|
132
|
-
},
|
|
133
|
-
onResponderRelease: release,
|
|
134
|
-
onResponderTerminate() {
|
|
135
|
-
interaction.current?.([], []);
|
|
136
|
-
stopInertia();
|
|
137
|
-
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
|
138
|
-
frame.current = undefined;
|
|
139
|
-
previous.current = [];
|
|
140
|
-
},
|
|
141
|
-
onResponderTerminationRequest: () => false,
|
|
142
|
-
};
|
|
143
|
-
}, [enabled, viewport, stopInertia]);
|
|
144
|
-
return { handlers, stopInertia };
|
|
145
|
-
}
|
|
1
|
+
import { useCallback, useLayoutEffect, useMemo, useRef, type RefObject } from "react";
|
|
2
|
+
import type { GestureResponderEvent, GestureResponderHandlers, View } from "react-native";
|
|
3
|
+
import type { Contact, Point } from "./viewport-geometry";
|
|
4
|
+
|
|
5
|
+
const flickWindow = 90;
|
|
6
|
+
const decelerationTime = 220;
|
|
7
|
+
const minFlingSpeed = 0.06;
|
|
8
|
+
const maxFlingSpeed = 3;
|
|
9
|
+
|
|
10
|
+
function readContacts({ nativeEvent }: GestureResponderEvent): Contact[] {
|
|
11
|
+
return nativeEvent.touches.slice(0, 2)
|
|
12
|
+
.map(({ identifier, pageX, pageY }) => ({ id: Number(identifier), x: pageX, y: pageY }))
|
|
13
|
+
.sort((first, second) => first.id - second.id);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useNativeContacts(
|
|
17
|
+
viewport: RefObject<View | null>,
|
|
18
|
+
enabled: boolean,
|
|
19
|
+
onMove: (previous: Contact[], next: Contact[]) => void,
|
|
20
|
+
onGlide: (delta: Point) => boolean,
|
|
21
|
+
intercept?: (contacts: Contact[], pageContacts: Contact[]) => boolean,
|
|
22
|
+
): { handlers: GestureResponderHandlers; stopInertia: () => void } {
|
|
23
|
+
const move = useRef(onMove);
|
|
24
|
+
const glide = useRef(onGlide);
|
|
25
|
+
const interaction = useRef(intercept);
|
|
26
|
+
const origin = useRef<Point>({ x: 0, y: 0 });
|
|
27
|
+
const previous = useRef<Contact[]>([]);
|
|
28
|
+
const pending = useRef<Contact[]>([]);
|
|
29
|
+
const frame = useRef<number | undefined>(undefined);
|
|
30
|
+
const inertiaFrame = useRef<number | undefined>(undefined);
|
|
31
|
+
const lastMove = useRef(0);
|
|
32
|
+
const pendingTime = useRef(0);
|
|
33
|
+
const velocity = useRef<Point>({ x: 0, y: 0 });
|
|
34
|
+
|
|
35
|
+
const stopInertia = useCallback(() => {
|
|
36
|
+
if (inertiaFrame.current !== undefined) cancelAnimationFrame(inertiaFrame.current);
|
|
37
|
+
inertiaFrame.current = undefined;
|
|
38
|
+
}, []);
|
|
39
|
+
useLayoutEffect(() => {
|
|
40
|
+
move.current = onMove;
|
|
41
|
+
glide.current = onGlide;
|
|
42
|
+
interaction.current = intercept;
|
|
43
|
+
}, [onMove, onGlide, intercept]);
|
|
44
|
+
useLayoutEffect(() => () => {
|
|
45
|
+
stopInertia();
|
|
46
|
+
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
|
47
|
+
frame.current = undefined;
|
|
48
|
+
previous.current = [];
|
|
49
|
+
}, [enabled, stopInertia]);
|
|
50
|
+
|
|
51
|
+
const handlers = useMemo<GestureResponderHandlers>(() => {
|
|
52
|
+
if (!enabled) return {};
|
|
53
|
+
|
|
54
|
+
const toViewport = (contact: Contact) => ({
|
|
55
|
+
id: contact.id, x: contact.x - origin.current.x, y: contact.y - origin.current.y,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function flush() {
|
|
59
|
+
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
|
60
|
+
frame.current = undefined;
|
|
61
|
+
const before = previous.current;
|
|
62
|
+
const next = pending.current;
|
|
63
|
+
previous.current = next;
|
|
64
|
+
const elapsed = pendingTime.current - lastMove.current;
|
|
65
|
+
lastMove.current = pendingTime.current;
|
|
66
|
+
if (before.length === 1 && next.length === 1 && before[0].id === next[0].id && elapsed > 0) {
|
|
67
|
+
const weight = 1 - Math.exp(-elapsed / 35);
|
|
68
|
+
velocity.current = {
|
|
69
|
+
x: velocity.current.x * (1 - weight) + (next[0].x - before[0].x) / elapsed * weight,
|
|
70
|
+
y: velocity.current.y * (1 - weight) + (next[0].y - before[0].y) / elapsed * weight,
|
|
71
|
+
};
|
|
72
|
+
} else {
|
|
73
|
+
velocity.current = { x: 0, y: 0 };
|
|
74
|
+
}
|
|
75
|
+
const contacts = next.map(toViewport);
|
|
76
|
+
if (interaction.current?.(contacts, next)) velocity.current = { x: 0, y: 0 };
|
|
77
|
+
else if (before.length && next.length) move.current(before.map(toViewport), contacts);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function rebase(event: GestureResponderEvent) {
|
|
81
|
+
if (frame.current !== undefined) flush();
|
|
82
|
+
previous.current = readContacts(event);
|
|
83
|
+
interaction.current?.(previous.current.map(toViewport), previous.current);
|
|
84
|
+
lastMove.current = performance.now();
|
|
85
|
+
velocity.current = { x: 0, y: 0 };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function release() {
|
|
89
|
+
if (frame.current !== undefined) flush();
|
|
90
|
+
const handled = interaction.current?.([], []);
|
|
91
|
+
const now = performance.now();
|
|
92
|
+
const speed = Math.hypot(velocity.current.x, velocity.current.y);
|
|
93
|
+
const canGlide = !handled && previous.current.length === 1 && now - lastMove.current <= flickWindow && speed >= minFlingSpeed;
|
|
94
|
+
previous.current = [];
|
|
95
|
+
if (!canGlide) return;
|
|
96
|
+
|
|
97
|
+
let lastFrameTime = now;
|
|
98
|
+
let remaining = Math.min(speed, maxFlingSpeed);
|
|
99
|
+
const direction = { x: velocity.current.x / speed, y: velocity.current.y / speed };
|
|
100
|
+
function step() {
|
|
101
|
+
inertiaFrame.current = undefined;
|
|
102
|
+
const time = performance.now();
|
|
103
|
+
const nextSpeed = remaining * Math.exp(-Math.min(time - lastFrameTime, 32) / decelerationTime);
|
|
104
|
+
const distance = (remaining - nextSpeed) * decelerationTime;
|
|
105
|
+
lastFrameTime = time;
|
|
106
|
+
remaining = nextSpeed;
|
|
107
|
+
if (remaining < minFlingSpeed || !glide.current({ x: direction.x * distance, y: direction.y * distance })) return;
|
|
108
|
+
inertiaFrame.current = requestAnimationFrame(step);
|
|
109
|
+
}
|
|
110
|
+
inertiaFrame.current = requestAnimationFrame(step);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
onStartShouldSetResponder: () => true,
|
|
115
|
+
onMoveShouldSetResponder: () => true,
|
|
116
|
+
onResponderGrant(event) {
|
|
117
|
+
stopInertia();
|
|
118
|
+
const { pageX, pageY, locationX, locationY } = event.nativeEvent;
|
|
119
|
+
origin.current = { x: pageX - locationX, y: pageY - locationY };
|
|
120
|
+
viewport.current?.measure((_left, _top, _width, _height, x, y) => { origin.current = { x, y }; });
|
|
121
|
+
rebase(event);
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
onResponderStart: rebase,
|
|
125
|
+
onResponderEnd(event) {
|
|
126
|
+
if (event.nativeEvent.touches.length > 0) rebase(event);
|
|
127
|
+
},
|
|
128
|
+
onResponderMove(event) {
|
|
129
|
+
pending.current = readContacts(event);
|
|
130
|
+
pendingTime.current = performance.now();
|
|
131
|
+
frame.current ??= requestAnimationFrame(flush);
|
|
132
|
+
},
|
|
133
|
+
onResponderRelease: release,
|
|
134
|
+
onResponderTerminate() {
|
|
135
|
+
interaction.current?.([], []);
|
|
136
|
+
stopInertia();
|
|
137
|
+
if (frame.current !== undefined) cancelAnimationFrame(frame.current);
|
|
138
|
+
frame.current = undefined;
|
|
139
|
+
previous.current = [];
|
|
140
|
+
},
|
|
141
|
+
onResponderTerminationRequest: () => false,
|
|
142
|
+
};
|
|
143
|
+
}, [enabled, viewport, stopInertia]);
|
|
144
|
+
return { handlers, stopInertia };
|
|
145
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function createPageRenderQueue() {
|
|
2
|
-
let tail: Promise<unknown> = Promise.resolve();
|
|
3
|
-
|
|
4
|
-
return function enqueue<Result>(signal: AbortSignal, render: () => Promise<Result>) {
|
|
5
|
-
const result = tail.then(() => {
|
|
6
|
-
if (signal.aborted) throw new Error("Page rendering cancelled.");
|
|
7
|
-
return render();
|
|
8
|
-
});
|
|
9
|
-
tail = result.catch(() => undefined);
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
1
|
+
export function createPageRenderQueue() {
|
|
2
|
+
let tail: Promise<unknown> = Promise.resolve();
|
|
3
|
+
|
|
4
|
+
return function enqueue<Result>(signal: AbortSignal, render: () => Promise<Result>) {
|
|
5
|
+
const result = tail.then(() => {
|
|
6
|
+
if (signal.aborted) throw new Error("Page rendering cancelled.");
|
|
7
|
+
return render();
|
|
8
|
+
});
|
|
9
|
+
tail = result.catch(() => undefined);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
}
|