( plugin: CodeSpacePlugin, sourceFile: TFile, fallbackMarkdown: string, ownerDoc: Document, knownModals: Set<HTMLElement> )
| 382 | } |
| 383 | |
| 384 | function beginNativeExportSession( |
| 385 | plugin: CodeSpacePlugin, |
| 386 | sourceFile: TFile, |
| 387 | fallbackMarkdown: string, |
| 388 | ownerDoc: Document, |
| 389 | knownModals: Set<HTMLElement> |
| 390 | ): () => void { |
| 391 | cleanupActiveNativeExportSession(); |
| 392 | |
| 393 | const docWindow = ownerDoc.defaultView ?? window; |
| 394 | const body = ownerDoc.body; |
| 395 | if (!body) { |
| 396 | return () => undefined; |
| 397 | } |
| 398 | |
| 399 | const session: NativeExportSession = { |
| 400 | id: ++nativeExportSessionCounter, |
| 401 | sourceFile, |
| 402 | ownerDoc, |
| 403 | ownerWindow: docWindow, |
| 404 | fallbackMarkdown, |
| 405 | knownModals, |
| 406 | trackedModals: new Set<HTMLElement>(), |
| 407 | sawTrackedModal: false, |
| 408 | observer: null, |
| 409 | timeoutId: null, |
| 410 | restoreWindowOpen: null, |
| 411 | popupCleanups: new Set<() => void>(), |
| 412 | lastPopupScanSignature: null, |
| 413 | cachedReadHits: 0, |
| 414 | replacementAttempts: 0, |
| 415 | replacementSuccesses: 0, |
| 416 | popupOpened: false, |
| 417 | cleanup: () => undefined, |
| 418 | }; |
| 419 | |
| 420 | const cleanup = () => { |
| 421 | if (activeNativeExportSession !== session) { |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | session.observer?.disconnect(); |
| 426 | if (session.timeoutId !== null) { |
| 427 | docWindow.clearTimeout(session.timeoutId); |
| 428 | } |
| 429 | for (const popupCleanup of Array.from(session.popupCleanups)) { |
| 430 | popupCleanup(); |
| 431 | } |
| 432 | session.restoreWindowOpen?.(); |
| 433 | debugNativePdf(session, "cleaning up native export session", { |
| 434 | cachedReadHits: session.cachedReadHits, |
| 435 | replacementAttempts: session.replacementAttempts, |
| 436 | replacementSuccesses: session.replacementSuccesses, |
| 437 | trackedModalCount: session.trackedModals.size, |
| 438 | }); |
| 439 | activeNativeExportSession = null; |
| 440 | }; |
| 441 |
no test coverage detected