# Description of Changes <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Reece <reece@stirlingpdf.com> Co-authored-by: Reece Browne <74901996+reecebrowne@users.noreply.github.com>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
|
|
// Base path - read from <base> tag at runtime to support dynamic subpaths
|
|
// Falls back to Vite's BASE_URL for build-time subpaths
|
|
// Normalized: no trailing slash, empty string instead of '.' or '/'
|
|
function getBasePath(): string {
|
|
// Try to read from <base> tag first (runtime subpath support)
|
|
if (typeof document !== 'undefined') {
|
|
const baseElement = document.querySelector('base');
|
|
if (baseElement) {
|
|
const href = baseElement.getAttribute('href');
|
|
if (href && href !== '%BASE_URL%') {
|
|
return href.replace(/\/$/, '').replace(/^\.$/, '').replace(/^\/$/, '');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fall back to Vite's BASE_URL (build-time subpath)
|
|
return (import.meta.env.BASE_URL || '/').replace(/\/$/, '').replace(/^\.$/, '').replace(/^\/$/, '');
|
|
}
|
|
|
|
export const BASE_PATH = getBasePath();
|
|
|
|
// EmbedPDF needs time to remove annotations internally before a recreation runs.
|
|
// Without the buffer we occasionally end up with duplicate annotations or stale image data.
|
|
export const ANNOTATION_RECREATION_DELAY_MS = 50;
|
|
export const ANNOTATION_VERIFICATION_DELAY_MS = 100;
|
|
|
|
/** For in-app navigations when you must touch window.location (rare). */
|
|
export const withBasePath = (path: string): string => {
|
|
const clean = path.startsWith('/') ? path : `/${path}`;
|
|
return `${BASE_PATH}${clean}`;
|
|
};
|
|
|
|
/** For OAuth (needs absolute URL with scheme+host) */
|
|
export const absoluteWithBasePath = (path: string): string => {
|
|
const clean = path.startsWith('/') ? path : `/${path}`;
|
|
return `${window.location.origin}${BASE_PATH}${clean}`;
|
|
};
|