@studyllm/resume-preview 0.0.0-stage → 3.2.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/LICENSE +21 -0
- package/README.en.md +318 -0
- package/README.md +313 -2
- package/build/constants.js +217 -0
- package/build/diagram-service.js +143 -0
- package/build/file-utils.js +350 -0
- package/build/handlers.js +172 -0
- package/build/html-utils.js +20 -0
- package/build/i18n.js +198 -0
- package/build/index.js +171 -0
- package/build/live-server.js +488 -0
- package/build/logger.js +92 -0
- package/build/mermaid-cli.js +48 -0
- package/build/page-renderer.js +152 -0
- package/build/preview/favicon.svg +23 -0
- package/build/preview/gallery.css +217 -0
- package/build/preview/gallery.html +59 -0
- package/build/preview/gallery.js +259 -0
- package/build/preview/i18n/en.json +57 -0
- package/build/preview/i18n/zh-CN.json +57 -0
- package/build/preview/i18n.js +125 -0
- package/build/preview/resume-template.html +13 -0
- package/build/preview/resume.css +237 -0
- package/build/preview/resume.js +393 -0
- package/build/preview/shared.css +529 -0
- package/build/resume-renderer.js +486 -0
- package/build/resume-service.js +117 -0
- package/build/routes.js +335 -0
- package/build/serve.js +46 -0
- package/build/types.js +5 -0
- package/package.json +63 -4
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
// Resume preview page functionality
|
|
2
|
+
// Configuration is read from data attributes on the body element
|
|
3
|
+
//
|
|
4
|
+
// The WebSocket and pan/zoom logic mirrors src/preview/script.js so both
|
|
5
|
+
// preview pages behave the same way.
|
|
6
|
+
|
|
7
|
+
(function () {
|
|
8
|
+
// ===== Configuration =====
|
|
9
|
+
const config = {
|
|
10
|
+
resumeId: document.body.dataset.resumeId,
|
|
11
|
+
port: document.body.dataset.port,
|
|
12
|
+
liveEnabled: document.body.dataset.liveEnabled === "true",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Looks up a translated string. Falls back to the key when the i18n module
|
|
17
|
+
* is unavailable, so a broken script shows a key instead of an empty page.
|
|
18
|
+
*/
|
|
19
|
+
function t(key, vars) {
|
|
20
|
+
const i18n = window.RPI18n;
|
|
21
|
+
return i18n ? i18n.t(key, vars) : key;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ===== Constants =====
|
|
25
|
+
const MIN_SCALE = 0.1;
|
|
26
|
+
const MAX_SCALE = 10;
|
|
27
|
+
const ZOOM_BUTTON_FACTOR = 1.2;
|
|
28
|
+
const WHEEL_ZOOM_FACTOR = 0.001;
|
|
29
|
+
|
|
30
|
+
// ===== DOM Elements =====
|
|
31
|
+
const elements = {
|
|
32
|
+
viewport: document.querySelector(".resume-viewport"),
|
|
33
|
+
sheet: document.querySelector(".resume-sheet"),
|
|
34
|
+
statusText: document.getElementById("status-text"),
|
|
35
|
+
statusIndicator: document.getElementById("status-indicator"),
|
|
36
|
+
resetButton: document.getElementById("reset-pan"),
|
|
37
|
+
backButton: document.getElementById("back-button"),
|
|
38
|
+
zoomInButton: document.getElementById("zoom-in"),
|
|
39
|
+
zoomOutButton: document.getElementById("zoom-out"),
|
|
40
|
+
zoomLevel: document.getElementById("zoom-level"),
|
|
41
|
+
exportButton: document.getElementById("export-btn"),
|
|
42
|
+
exportMenu: document.getElementById("export-menu"),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// ===== Pan/Zoom State =====
|
|
46
|
+
const panState = {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
scale: 1,
|
|
50
|
+
isDragging: false,
|
|
51
|
+
dragStartX: 0,
|
|
52
|
+
dragStartY: 0,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// ===== WebSocket State =====
|
|
56
|
+
const wsState = {
|
|
57
|
+
connection: null,
|
|
58
|
+
reconnectInterval: null,
|
|
59
|
+
reconnectAttempts: 0,
|
|
60
|
+
maxReconnectAttempts: 30,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// ===== Pan/Zoom Functions =====
|
|
64
|
+
function clampScale(value) {
|
|
65
|
+
return Math.min(MAX_SCALE, Math.max(MIN_SCALE, value));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function updateZoomLevel() {
|
|
69
|
+
if (elements.zoomLevel) {
|
|
70
|
+
elements.zoomLevel.textContent = `${Math.round(panState.scale * 100)}%`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resetView() {
|
|
75
|
+
panState.x = 0;
|
|
76
|
+
panState.y = 0;
|
|
77
|
+
panState.scale = 1;
|
|
78
|
+
applyTransform();
|
|
79
|
+
updateZoomLevel();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function applyTransform() {
|
|
83
|
+
if (elements.sheet) {
|
|
84
|
+
elements.sheet.style.transform = `translate(${panState.x}px, ${panState.y}px) scale(${panState.scale})`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function zoomAtPoint(newScale, pivotX, pivotY) {
|
|
89
|
+
newScale = clampScale(newScale);
|
|
90
|
+
const ratio = 1 - newScale / panState.scale;
|
|
91
|
+
panState.x += (pivotX - panState.x) * ratio;
|
|
92
|
+
panState.y += (pivotY - panState.y) * ratio;
|
|
93
|
+
panState.scale = newScale;
|
|
94
|
+
applyTransform();
|
|
95
|
+
updateZoomLevel();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function zoomAtCenter(newScale) {
|
|
99
|
+
if (!elements.viewport) return;
|
|
100
|
+
const rect = elements.viewport.getBoundingClientRect();
|
|
101
|
+
zoomAtPoint(newScale, rect.width / 2, rect.height / 2);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function normalizeWheelDelta(e) {
|
|
105
|
+
var deltaY = e.deltaY;
|
|
106
|
+
if (e.deltaMode === 1) deltaY *= 40;
|
|
107
|
+
else if (e.deltaMode === 2) deltaY *= 800;
|
|
108
|
+
return deltaY;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function handleWheel(e) {
|
|
112
|
+
if (!elements.viewport) return;
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
const rect = elements.viewport.getBoundingClientRect();
|
|
115
|
+
const pivotX = e.clientX - rect.left;
|
|
116
|
+
const pivotY = e.clientY - rect.top;
|
|
117
|
+
const newScale = clampScale(panState.scale - normalizeWheelDelta(e) * WHEEL_ZOOM_FACTOR);
|
|
118
|
+
zoomAtPoint(newScale, pivotX, pivotY);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function handleMouseDown(e) {
|
|
122
|
+
if (!elements.viewport || e.target.closest(".status-bar")) return;
|
|
123
|
+
panState.isDragging = true;
|
|
124
|
+
panState.dragStartX = e.clientX - panState.x;
|
|
125
|
+
panState.dragStartY = e.clientY - panState.y;
|
|
126
|
+
elements.viewport.style.cursor = "grabbing";
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function handleMouseUp(e) {
|
|
131
|
+
panState.isDragging = false;
|
|
132
|
+
if (elements.viewport) {
|
|
133
|
+
elements.viewport.style.cursor = "grab";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function handleMouseMove(e) {
|
|
138
|
+
if (!panState.isDragging) return;
|
|
139
|
+
panState.x = e.clientX - panState.dragStartX;
|
|
140
|
+
panState.y = e.clientY - panState.dragStartY;
|
|
141
|
+
applyTransform();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ===== Touch Event Handlers =====
|
|
145
|
+
function handleTouchStart(e) {
|
|
146
|
+
if (!elements.viewport) return;
|
|
147
|
+
if (e.touches.length !== 1) return;
|
|
148
|
+
panState.isDragging = true;
|
|
149
|
+
panState.dragStartX = e.touches[0].clientX - panState.x;
|
|
150
|
+
panState.dragStartY = e.touches[0].clientY - panState.y;
|
|
151
|
+
elements.viewport.style.cursor = "grabbing";
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function handleTouchMove(e) {
|
|
156
|
+
if (!panState.isDragging) return;
|
|
157
|
+
panState.x = e.touches[0].clientX - panState.dragStartX;
|
|
158
|
+
panState.y = e.touches[0].clientY - panState.dragStartY;
|
|
159
|
+
applyTransform();
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function handleTouchEnd(e) {
|
|
164
|
+
panState.isDragging = false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ===== Status Update Functions =====
|
|
168
|
+
function setStatus(text, isConnected) {
|
|
169
|
+
if (elements.statusText) {
|
|
170
|
+
elements.statusText.textContent = text;
|
|
171
|
+
}
|
|
172
|
+
if (elements.statusIndicator) {
|
|
173
|
+
elements.statusIndicator.classList.toggle("disconnected", !isConnected);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ===== WebSocket Functions =====
|
|
178
|
+
function handleWebSocketOpen() {
|
|
179
|
+
console.log("WebSocket connected");
|
|
180
|
+
setStatus(t("preview.statusLive"), true);
|
|
181
|
+
wsState.reconnectAttempts = 0;
|
|
182
|
+
if (wsState.reconnectInterval) {
|
|
183
|
+
clearInterval(wsState.reconnectInterval);
|
|
184
|
+
wsState.reconnectInterval = null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function handleWebSocketMessage(event) {
|
|
189
|
+
if (event.data === "reload") {
|
|
190
|
+
console.log("Reloading resume...");
|
|
191
|
+
location.reload();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function handleWebSocketClose() {
|
|
196
|
+
console.log("WebSocket disconnected");
|
|
197
|
+
|
|
198
|
+
if (wsState.reconnectAttempts >= wsState.maxReconnectAttempts) {
|
|
199
|
+
setStatus(t("preview.statusFailed"), false);
|
|
200
|
+
console.warn(
|
|
201
|
+
`Max reconnection attempts (${wsState.maxReconnectAttempts}) reached. Stop reconnecting.`
|
|
202
|
+
);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setStatus(t("preview.statusDisconnected"), false);
|
|
207
|
+
|
|
208
|
+
if (!wsState.reconnectInterval) {
|
|
209
|
+
wsState.reconnectInterval = setInterval(() => {
|
|
210
|
+
if (wsState.reconnectAttempts >= wsState.maxReconnectAttempts) {
|
|
211
|
+
clearInterval(wsState.reconnectInterval);
|
|
212
|
+
wsState.reconnectInterval = null;
|
|
213
|
+
setStatus(t("preview.statusFailed"), false);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
wsState.reconnectAttempts++;
|
|
217
|
+
console.log(
|
|
218
|
+
`Attempting to reconnect... (${wsState.reconnectAttempts}/${wsState.maxReconnectAttempts})`
|
|
219
|
+
);
|
|
220
|
+
connectWebSocket();
|
|
221
|
+
}, 2000);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function handleWebSocketError(error) {
|
|
226
|
+
console.error("WebSocket error:", error);
|
|
227
|
+
if (wsState.connection) {
|
|
228
|
+
wsState.connection.close();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function connectWebSocket() {
|
|
233
|
+
if (!config.port || !config.resumeId) return;
|
|
234
|
+
wsState.connection = new WebSocket(
|
|
235
|
+
`ws://localhost:${config.port}/resume/${encodeURIComponent(config.resumeId)}`
|
|
236
|
+
);
|
|
237
|
+
wsState.connection.onopen = handleWebSocketOpen;
|
|
238
|
+
wsState.connection.onmessage = handleWebSocketMessage;
|
|
239
|
+
wsState.connection.onclose = handleWebSocketClose;
|
|
240
|
+
wsState.connection.onerror = handleWebSocketError;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ===== Export Functions =====
|
|
244
|
+
function getFilename(format) {
|
|
245
|
+
return `${config.resumeId || "resume"}.${format}`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function downloadBlob(blob, filename) {
|
|
249
|
+
const url = URL.createObjectURL(blob);
|
|
250
|
+
const link = document.createElement("a");
|
|
251
|
+
link.href = url;
|
|
252
|
+
link.download = filename;
|
|
253
|
+
document.body.appendChild(link);
|
|
254
|
+
link.click();
|
|
255
|
+
document.body.removeChild(link);
|
|
256
|
+
URL.revokeObjectURL(url);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function exportResume(format) {
|
|
260
|
+
if (!config.resumeId) {
|
|
261
|
+
alert(t("preview.exportMissingId"));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const exportUrl = `${window.location.origin}/resume/export/${encodeURIComponent(
|
|
266
|
+
config.resumeId
|
|
267
|
+
)}?format=${encodeURIComponent(format)}`;
|
|
268
|
+
|
|
269
|
+
fetch(exportUrl)
|
|
270
|
+
.then(function (response) {
|
|
271
|
+
if (!response.ok) {
|
|
272
|
+
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
|
|
273
|
+
}
|
|
274
|
+
return response.blob();
|
|
275
|
+
})
|
|
276
|
+
.then(function (blob) {
|
|
277
|
+
downloadBlob(blob, getFilename(format));
|
|
278
|
+
})
|
|
279
|
+
.catch(function (error) {
|
|
280
|
+
console.error("Resume export failed", error);
|
|
281
|
+
alert(t("preview.exportFailed", { message: error.message }));
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function handleExport(format) {
|
|
286
|
+
hideExportMenu();
|
|
287
|
+
exportResume(format);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function toggleExportMenu() {
|
|
291
|
+
if (elements.exportMenu) {
|
|
292
|
+
elements.exportMenu.classList.toggle("visible");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function hideExportMenu() {
|
|
297
|
+
if (elements.exportMenu) {
|
|
298
|
+
elements.exportMenu.classList.remove("visible");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ===== Initialization =====
|
|
303
|
+
function initializePanZoom() {
|
|
304
|
+
if (elements.viewport) {
|
|
305
|
+
elements.viewport.addEventListener("mousedown", handleMouseDown);
|
|
306
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
307
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
308
|
+
elements.viewport.addEventListener("wheel", handleWheel, { passive: false });
|
|
309
|
+
elements.viewport.addEventListener("touchstart", handleTouchStart, { passive: false });
|
|
310
|
+
elements.viewport.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
311
|
+
elements.viewport.addEventListener("touchend", handleTouchEnd);
|
|
312
|
+
elements.viewport.style.cursor = "grab";
|
|
313
|
+
}
|
|
314
|
+
if (elements.resetButton) {
|
|
315
|
+
elements.resetButton.addEventListener("click", resetView);
|
|
316
|
+
}
|
|
317
|
+
if (elements.backButton) {
|
|
318
|
+
elements.backButton.addEventListener("click", function () {
|
|
319
|
+
if (window.history.length > 1) {
|
|
320
|
+
window.history.back();
|
|
321
|
+
} else {
|
|
322
|
+
window.location.href = "/";
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
if (elements.zoomInButton) {
|
|
327
|
+
elements.zoomInButton.addEventListener("click", function () {
|
|
328
|
+
zoomAtCenter(panState.scale * ZOOM_BUTTON_FACTOR);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
if (elements.zoomOutButton) {
|
|
332
|
+
elements.zoomOutButton.addEventListener("click", function () {
|
|
333
|
+
zoomAtCenter(panState.scale / ZOOM_BUTTON_FACTOR);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (elements.exportButton) {
|
|
338
|
+
elements.exportButton.addEventListener("click", function (e) {
|
|
339
|
+
e.stopPropagation();
|
|
340
|
+
toggleExportMenu();
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (elements.exportMenu) {
|
|
345
|
+
elements.exportMenu.querySelectorAll(".export-option").forEach(function (btn) {
|
|
346
|
+
btn.addEventListener("click", function () {
|
|
347
|
+
handleExport(this.dataset.format);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
document.addEventListener("click", function (e) {
|
|
353
|
+
if (!e.target.closest(".export-dropdown")) {
|
|
354
|
+
hideExportMenu();
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function initializeWebSocket() {
|
|
360
|
+
if (!config.liveEnabled) {
|
|
361
|
+
setStatus(t("preview.statusStatic"), false);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
connectWebSocket();
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function initialize() {
|
|
368
|
+
initializePanZoom();
|
|
369
|
+
initializeWebSocket();
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Cleanup on page unload
|
|
373
|
+
function cleanup() {
|
|
374
|
+
if (wsState.connection) {
|
|
375
|
+
wsState.connection.close();
|
|
376
|
+
wsState.connection = null;
|
|
377
|
+
}
|
|
378
|
+
if (wsState.reconnectInterval) {
|
|
379
|
+
clearInterval(wsState.reconnectInterval);
|
|
380
|
+
wsState.reconnectInterval = null;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Register cleanup handler
|
|
385
|
+
window.addEventListener("beforeunload", cleanup);
|
|
386
|
+
|
|
387
|
+
// Start the application. The dictionary has to be in place before the
|
|
388
|
+
// status line shows anything.
|
|
389
|
+
const i18nReady = window.RPI18n ? window.RPI18n.ready : Promise.resolve();
|
|
390
|
+
i18nReady.then(function () {
|
|
391
|
+
initialize();
|
|
392
|
+
});
|
|
393
|
+
})();
|