Commit Graph
76 Commits
Author SHA1 Message Date
AlexKucera 2e8ac6a848 Enhances cleanup with async lifecycle handling
Updates plugin cleanup to utilize async handlers during onunload,
ensuring proper resource management and cleanup of temporary files.
Removes redundant process termination listeners and integrates lifecycle
methods for better maintainability and efficiency.

Improves robustness of plugin cleanup on unload.
2025-11-08 18:32:48 +01:00
AlexKucera 2c4076f3c9 Applies Obsidian linter and fixes code issues
Applies linting rules to the codebase and resolves identified issues.

Addresses:
- Renamed headings in settings tabs to improve UI consistency and style.
- Resolved require() style imports
- Added void operator to ensure correct promise handling.
- Replaced deprecated Obsidian API calls.
- Enforces sentence case to enhance UI text consistency.
2025-11-05 13:46:06 +01:00
Jarvis 9345198337 refactor: clean up ESLint warnings and code quality
- Remove unused imports and variables across multiple files
- Fix prefer-const warnings by changing let to const
- Remove unused catch block variables or convert to parameter-less catch blocks
- Update package-lock.json with TypeScript-ESLint v8 dependencies
- Reduce ESLint warnings from 42 to 22 (remaining are necessary 'any' types)
- All remaining warnings are for Obsidian API compatibility

Fixes improve code quality while maintaining functionality.
Remaining 'any' type warnings are appropriate for Obsidian plugin development.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 17:47:17 +02:00
Jarvis 2bd384fbd1 refactor: complete TypeScript type safety improvements
- Replace all 'any' types with proper TypeScript types throughout codebase
- Fix processedResult parameters to use PreprocessingResult interface
- Update UI modal types: app parameter (App), pluginDefaults (obsidianTypstPDFExportSettings)
- Fix dropdown components to use DropdownComponent from Obsidian API
- Replace plugin 'any' types with obsidianTypstPDFExport throughout converters
- Fix margins parameter to use proper interface structure
- Update fs parameter to use proper Node.js fs module type
- Improve error handling with proper unknown type and type guards
- Remove unused PdfEmbedProcessor and clean up imports

Achieves complete type safety with zero remaining 'any' types across src/ directory.
Provides better IDE support, compile-time error detection, and maintainability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 16:45:27 +02:00
Jarvis 3c384f1f1b refactor(main): move dependency methods to DependencyChecker
- Move showDependencyStatus() and checkDependenciesAsync() from main.ts to DependencyChecker.ts as static methods
- Replace 31-line implementations with 12-line delegation calls in main.ts
- Add necessary imports (Notice, ExportErrorHandler) to DependencyChecker.ts
- Maintain same public API while improving separation of concerns
- Reduce main.ts from 280 to 253 lines (total 79% reduction from original 1233 lines)

This completes Step 1.10 of the refactoring plan, achieving clean delegation
of dependency management functionality while preserving backward compatibility.

Build verified: ✅ TypeScript compilation successful
2025-09-09 10:23:22 +02:00
Jarvis 9427444015 refactor: move modal methods to ExportOrchestrator (step 1.9)
Move export modal orchestration from main.ts to ExportOrchestrator:
- Move showExportModal() and showExportModalForFiles() methods
- Add required imports to ExportOrchestrator (MarkdownView, ExportConfigModal, ModalSettingsHelper)
- Replace main.ts methods with delegation calls to ExportOrchestrator
- Remove unused imports from main.ts (ModalSettingsHelper, ExportConfigModal, etc.)
- Reduce main.ts from 351 → 290 lines (61 lines moved)

Improves separation of concerns by consolidating all export orchestration
logic in ExportOrchestrator, including modal creation and configuration.
Modal functionality preserved through delegation pattern.

Total progress: main.ts reduced from 1233 → 290 lines (943 lines extracted, 76% reduction)

Build passes successfully ✅

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 10:11:24 +02:00
Jarvis 94dfa0da95 refactor: extract EmbedProcessor from main.ts (step 1.8)
Extract all embed processing functionality into dedicated EmbedProcessor module:
- Move processPdfEmbeds(), processImageEmbeds(), processFileEmbeds() methods
- Move helper methods: resolvePdfPath(), copyImageToVaultTemp(), generatePdfEmbedContent(), generateFileEmbedContent(), getMimeTypeFromExtension(), getFileTypeIcon(), resolveFilePath()
- Replace with delegation pattern in main.ts
- Fix TypeScript type issues with proper type guards for path filtering
- Reduce main.ts from 805 → 351 lines (454 lines extracted)

Creates focused 474-line EmbedProcessor module handling:
- PDF embed processing with preview image generation
- Image embed processing with path resolution
- File embed processing with MIME type detection
- Multi-strategy path resolution for vault attachments
- Proper error handling and fallback mechanisms

Build passes successfully ✅

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 10:06:03 +02:00
Jarvis bf2028dc0d refactor: extract ObsidianTypstPDFExportSettingTab to separate module
Extract the complete settings UI class (427 lines) from main.ts into
src/plugin/SettingsTab.ts to improve maintainability and reduce file size.

Changes:
- Create src/plugin/SettingsTab.ts with full settings UI implementation
- Remove ObsidianTypstPDFExportSettingTab class from main.ts
- Add import for extracted SettingsTab class
- Maintain all existing functionality and UI sections

Build verified: npm run build passes successfully
Line reduction: main.ts reduced from 1233 to 805 lines (-428 lines)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 09:55:06 +02:00
Jarvis 0793893228 refactor: extract PathResolver from main.ts - complete Phase 1
Extract all path resolution utilities from main.ts into a focused
PathResolver module, completing the Phase 1 refactoring of main.ts
into 6 focused modules.

- Create PathResolver.ts with path resolution and validation utilities
- Extract resolveExecutablePath() with system search fallback logic
- Extract prepareOutputPath() with directory creation and security validation
- Delegate path operations from main.ts to PathResolver
- Reduce main.ts by ~80 lines while maintaining all functionality

Phase 1 Summary:
- ✅ PluginLifecycle.ts (89 lines) - Plugin initialization & cleanup
- ✅ CommandRegistry.ts (35 lines) - Command registration & handlers
- ✅ EventHandlers.ts (109 lines) - Event handling & menu items
- ✅ ExportOrchestrator.ts (263 lines) - Export workflow coordination
- ✅ FontManager.ts (120 lines) - Font discovery & caching
- ✅ PathResolver.ts (80 lines) - Path resolution utilities

Total: Reduced main.ts from 1792 → ~1100 lines (39% reduction)
All functionality preserved with improved maintainability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-09 09:39:50 +02:00
Jarvis 35c351d55c refactor: extract FontManager from main.ts
Extract all font management functionality from main.ts into a focused
FontManager module to improve maintainability and reduce complexity.

- Create FontManager.ts with font discovery and caching logic
- Extract cacheAvailableFonts() and getCachedFonts() methods
- Add getAvailableFonts() wrapper method for consistent API
- Delegate font operations from main.ts to FontManager
- Fix initialization order: FontManager before PluginLifecycle
- Make resolveExecutablePath() public for FontManager access
- Reduce main.ts by ~115 lines while maintaining all functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 20:13:07 +02:00
Jarvis 7c6a244976 refactor: extract ExportOrchestrator from main.ts
Extract all export orchestration methods from main.ts into a focused
ExportOrchestrator module to improve maintainability and reduce complexity.

- Create ExportOrchestrator.ts with export workflow coordination
- Extract exportFile(), exportFiles(), exportFileWithConfig() methods
- Extract processBatchExport(), cancelExport(), handleFolderExport() methods
- Delegate export operations from main.ts to ExportOrchestrator
- Make processing methods public for ExportOrchestrator access
- Reduce main.ts by ~205 lines while maintaining all functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 19:49:20 +02:00
Jarvis d1d322fa17 refactor: extract EventHandlers from main.ts
Extract event handling logic into focused EventHandlers module:
- Create src/plugin/EventHandlers.ts for menu and ribbon handlers
- Move registerEventHandlers() and handleRibbonClick() methods
- Make exportFile(), exportFiles(), showExportModalForFiles(), isMarkdownFile() public
- Reduce main.ts by ~100 lines, improving maintainability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 19:27:38 +02:00
Jarvis 651671da2d refactor: extract CommandRegistry from main.ts
Extract command registration logic into dedicated CommandRegistry
class to improve separation of concerns and reduce main.ts complexity.

- Create src/plugin/CommandRegistry.ts (~35 lines)
- Move registerCommands() method to CommandRegistry
- Extract all 3 command definitions with callbacks:
  * export-current-note
  * export-with-config
  * check-dependencies
- Update main.ts to delegate to CommandRegistry
- Change exportCurrentNote() and showExportModal() to public
- Remove old registerCommands() method from main.ts

Part of comprehensive refactoring plan (main.ts: 1792 lines → 6 modules).
Step 1.2 complete. Commands functionality preserved.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 19:19:01 +02:00
Jarvis 991a9ae0ec refactor: extract PluginLifecycle from main.ts
Extract plugin initialization and cleanup logic into dedicated
PluginLifecycle class to reduce complexity of main.ts file.

- Create src/plugin/PluginLifecycle.ts (~100 lines)
- Move onload/onunload initialization logic
- Move template extraction and component setup
- Move dependency checking and font caching
- Update main.ts to delegate to lifecycle manager
- Change methods to public visibility where needed

Part of comprehensive refactoring plan to break down large files
(main.ts: 1792 lines → 6 focused modules). Step 1.1 complete.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 19:14:11 +02:00
Jarvis 8879f40be5 fix: update ImageMagick to use 'magick' instead of deprecated 'convert'
- Update default ImageMagick executable from 'convert' to 'magick' in constants
- Remove deprecated 'convert' subcommand from ImageMagick spawn calls
- Update UI labels and settings descriptions to reflect 'magick' command
- Fix pdf2img PATH environment to include Node.js installation paths

This resolves ImageMagick v7 deprecation warning and fixes pdf2img execution
failure caused by missing Node.js in PATH. The 'convert' command was deprecated
in ImageMagick v7 in favor of the unified 'magick' command.

Fixes: "env: node: No such file or directory" error in pdf2img execution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 10:55:27 +02:00
Jarvis 1b36ebb705 fix(core): enhance dependency checker with comprehensive path resolution
- Add support for user-configured additionalPaths in dependency checking
- Implement comprehensive default system paths (home-relative and absolute)
- Update path resolution to handle both full paths and bare executable names
- Use 'which' command fallback with augmented PATH for executable discovery
- Ensure consistent path handling across sync and async dependency methods

This resolves issues where executables installed in common locations like
/opt/homebrew/bin were not found when executable path settings were empty.
The plugin now searches standard package manager installation directories
by default while respecting user-configured additional paths.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 10:32:16 +02:00
Jarvis a1380d88a0 fix: address Obsidian Review Bot feedback for plugin submission
- Replace hardcoded '.obsidian' paths with Vault#configDir for proper config directory support
- Move inline styles to CSS classes for better theme compatibility
- Remove unnecessary type casting by using proper type predicates
- Add proper TypeScript type narrowing for filtered arrays

This addresses all required issues identified by the Obsidian Review Bot:
* TempDirectoryManager now accepts configDir parameter from app.vault.configDir
* PdfToImageConverter uses configDir instead of hardcoded '.obsidian'
* ExportConfigModal uses CSS classes (.export-progress-visible, .export-form-hidden) instead of inline styles
* Progress bar width controlled via CSS custom property --progress-width
* Removed 'as TFile[]' casting by implementing isMarkdownFile type predicate

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 23:10:31 +02:00
AlexKucera 31cbb0010e Merge branch 'develop' into feature/generic_embed 2025-09-05 18:03:49 +02:00
AlexKucera 5519c98957 Improves plugin directory path handling dynamically
Updates file path resolution to use plugin manifest directory dynamically

Replaces hardcoded plugin directory paths with more flexible approach
- Uses `this.manifest.dir!` to determine plugin directory
- Supports better cross-platform and installation compatibility
- Removes static path references in multiple plugin components

Enhances plugin robustness by making directory paths more configurable
2025-09-05 17:56:56 +02:00
AlexKucera 05f28f84f3 Add Generic File embedding 2025-09-05 17:41:18 +02:00
AlexKucera 3cff3ff70a Renames plugin to "Typst PDF Export"
Updates the plugin's name from "Obsidian Typst PDF Export" to "Typst PDF Export".

This change simplifies the plugin's identifier and display name,
making it more concise and user-friendly. It involves updates to
the manifest file, plugin configuration, and references within the
codebase.
2025-09-05 16:57:23 +02:00
AlexKucera b5387722cf Removes unnecessary console logs
Removes console log statements related to template extraction.

These logs were primarily for debugging and are no longer needed in the production code.
2025-09-05 16:15:44 +02:00
AlexKucera c0d9cff790 Shortens plugin name
Updates the plugin's display name for brevity in notices and settings.
2025-09-05 16:10:37 +02:00
AlexKucera da678ada03 Updates export to use new settings structure
Updates the export file function to utilize the new settings structure for page setup and typography.

This change ensures consistency with the modal settings and simplifies the configuration process.
2025-09-05 15:47:39 +02:00
Jarvis 8557720f43 feat: add comprehensive template embedding and release automation
Implements dual-strategy template distribution for reliable plugin deployment:

Template Embedding System:
- Add esbuild plugin to embed .typ templates as base64 strings in main.js
- Create EmbeddedTemplateManager for automatic template extraction
- Add TypeScript declarations for virtual template-embed module
- Templates auto-extract on plugin load if missing from disk

Release Automation:
- Add GitHub Actions workflow for automated ZIP releases
- Create package-plugin.js script for complete distribution packages
- Update version-bump.mjs for Obsidian-compliant tags (no 'v' prefix)
- Ensure releases include templates/ directory for manual installations

Documentation Updates:
- Comprehensive installation instructions with troubleshooting
- Clear warnings about requiring complete ZIP packages
- Multiple installation methods including manual and automated

This ensures the plugin works regardless of installation method:
- ZIP releases provide templates/ directory (primary method)
- Embedded templates auto-extract as fallback (secondary method)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-05 15:34:00 +02:00
AlexKucera d40253e6c4 Enhances template handling for Typst exports.
Improves template resolution for Typst exports by adding the plugin's templates directory as a resource path. This allows Typst to correctly locate and utilize template files within the plugin.

Updates the template path handling to use relative paths from the vault root, ensuring proper import behavior within Typst.
2025-09-05 10:41:31 +02:00
AlexKucera 6ff1a24773 Removes excessive logging
Removes console log statements used for debugging during development, resulting in cleaner output and improved performance in production.
2025-09-04 22:48:55 +02:00
AlexKucera 21fdfbf207 Normalizes output folder path for settings
Ensures that the output folder path is normalized before being saved in the settings. This prevents issues with inconsistent or invalid paths.
2025-09-04 22:30:06 +02:00
AlexKucera 151dc537a5 Removes default hotkeys for export commands
Removes the default hotkeys assigned to the export commands.
This allows users to define their own preferred hotkeys
without being restricted by default settings.
2025-09-04 22:26:46 +02:00
Jarvis 70241a012c feat: add PDF embedding and frontmatter display controls
- Add embedPdfFiles setting to control PDF attachment embedding
- Add printFrontmatter setting to display frontmatter as formatted text
- Implement frontmatter formatting with proper line breaks and bullet lists
- Add settings toggles to both plugin settings and export modal
- Fix filename sanitization for PDF preview images with spaces
- Ensure modal export config includes new behavior settings
- Always generate PDF preview images regardless of embedding setting

The frontmatter display formats long comma-separated values (like email lists)
as bulleted lists and adds proper line breaks after each property label.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 22:15:08 +02:00
AlexKucera a15caaef1e Adds type safety to process event handlers
Specifies the types for data and close events in process handlers.

This improves code clarity and maintainability by ensuring that the
data received from stdout and stderr streams is treated as a Buffer,
and the close event receives a number or null for the exit code.
2025-09-04 16:40:02 +02:00
AlexKucera 6af3f74e68 Improves file access using asynchronous methods
Refactors file access operations to use asynchronous methods
instead of synchronous ones. This enhances performance and
responsiveness by preventing blocking operations, especially
during file system interactions.

The changes involve using `fs.promises.access` instead of
`fs.existsSync` and `fs.promises.mkdir` instead of
`fs.mkdirSync`. This ensures non-blocking file system operations
across the application, improving the overall user experience.
2025-09-04 15:09:56 +02:00
AlexKucera b255b6354e Refactors batch export logic
Consolidates the export files and export files with configuration functionalities into a shared `processBatchExport` method.

This reduces code duplication and improves maintainability
by centralizing the batch processing logic.
2025-09-04 15:01:06 +02:00
AlexKucera e48af55635 Adds robustness to file system operations
Improves error handling when creating directories,
loading, and saving settings. This prevents crashes and
provides more informative error messages to the user.

Adds a try-catch block to `fs.statSync` to handle cases where a
file might be deleted between `readdirSync` and `statSync`,
preventing program termination.
2025-09-03 23:09:36 +02:00
AlexKucera 742b9a14c8 Adds user notification on font caching failure
Notifies the user when font caching fails, providing different levels of detail depending on whether debug mode is enabled.
This helps the user to be aware of potential font rendering issues and provides guidance on how to troubleshoot them.
2025-09-03 23:05:51 +02:00
AlexKucera ddac8bd045 Cleans up temporary directories on startup/unload
Ensures temporary directories are cleaned up when the plugin loads and unloads, preventing potential issues from leftover files.

This addresses potential accumulation of temp files from previous sessions and on plugin disable.
2025-09-03 23:02:11 +02:00
AlexKucera 42aa8e176c Adds output path validation for enhanced security
Enhances security by validating output paths and executable paths.

This prevents path traversal attacks and command injection vulnerabilities
by ensuring that users can only specify valid relative paths within the vault
and safe executable paths. It also displays notices when the path is deemed unsafe.
2025-09-03 22:56:30 +02:00
AlexKucera d4c4a1be73 Refactors margin input settings
Introduces a helper function to streamline the creation of margin input settings in the plugin settings tab. This improves code readability and reduces redundancy.
2025-09-03 22:46:10 +02:00
AlexKucera f4d43a7236 Refactors typography settings with helper
Uses a helper method to create the font dropdown settings, reducing code duplication and improving maintainability.

The shared logic for setting up font selection dropdowns is now encapsulated in a single function.
2025-09-03 22:41:29 +02:00
AlexKucera fcb62d5025 Enhances font caching with process spawning
Improves the font caching mechanism by using `child_process.spawn` instead of `child_process.exec` for enhanced security and reliability. This change also adds error handling for process spawning failures and includes the ability to set environment variables such as PATH.
2025-09-03 22:31:35 +02:00
AlexKucera 3f8f2b2089 Refactors project structure for improved modularity
Moves components and modules to more appropriate directories.

This change improves project organization and maintainability by grouping related files into logical directories, enhancing code discoverability and reducing potential naming conflicts.
2025-09-03 22:05:45 +02:00
AlexKucera f05ffa8bc8 Refactors project structure and PDF embedding
Moves components and converters to more appropriate directories for better code organization.

Adds a dedicated function for copying images to the vault temp directory and generating relative paths, reducing code duplication and simplifying PDF embedding.
2025-09-03 22:05:32 +02:00
AlexKucera a676f7e6c4 Refactors PDF embed logic for Typst
Introduces a helper function to generate Typst PDF embed syntax, including optional preview images and error handling.
This improves code readability and maintainability by centralizing the PDF embed logic.
2025-09-03 19:54:06 +02:00
AlexKucera 2bf0e57cdc Refactors PDF path resolution
Simplifies PDF embed processing by introducing a dedicated
`resolvePdfPath` method. This improves code readability and
maintainability by encapsulating the logic for finding PDF files
using different path resolution strategies. It also makes it easier to
test the path resolution logic independently.
2025-09-03 19:52:37 +02:00
AlexKucera a2020c90f3 Introduces temp directory management
Centralizes temporary directory creation and cleanup using a dedicated `TempDirectoryManager` class.

This change improves code maintainability and reduces redundancy by encapsulating temporary directory logic.

It also ensures that temporary directories are properly cleaned up after export operations, preventing potential disk space issues.
2025-09-03 19:48:43 +02:00
AlexKucera f9a6166da3 Centralizes export error handling
Introduces `ExportErrorHandler` to manage export-related errors, progress notices, and batch results.

This change provides a unified way to handle errors, display progress, and report results of export operations, improving code maintainability and user experience.
2025-09-03 19:43:52 +02:00
AlexKucera 608a51b81e Refactors export modal settings preparation
Introduces a helper class to encapsulate the logic for preparing the export configuration modal settings.

This improves code readability and maintainability by extracting the complex settings preparation logic from the main plugin file.
The helper handles both single and multi-file export scenarios, ensuring consistent settings across different export contexts.
2025-09-03 19:38:43 +02:00
AlexKucera d0b096368f Refactors dependency checking into a class
Consolidates dependency checking logic into a dedicated `DependencyChecker` class.
This improves code organization and reusability.
It now uses a single method for checking all dependencies, both asynchronously (for displaying status) and synchronously (for startup checks).
It also augments the PATH environment variable to include common binary locations to improve detection.

The status modal now displays more detailed information about each dependency.
2025-09-03 19:35:07 +02:00
AlexKucera 5fc8e348f4 Refactors fallback fonts into a constant
Moves the list of fallback fonts to a dedicated constant file.
This improves code readability and maintainability by centralizing
this configuration.
2025-09-03 19:31:19 +02:00
AlexKucera 42ad862ba0 Prioritizes config format in template variables
Ensures that the format specified in the export configuration
takes precedence over the default format specified in the settings
when populating template variables for PDF conversion.

Additionally, only uses the settings default for the export format
if one is not already provided.
2025-09-03 19:21:13 +02:00