import { VersionManager } from './version-manager'; export interface PolyfillConfig { feature: string; url: string; condition: () => boolean; priority: number; size: number; // KB } export class PolyfillManager { private versionManager = VersionManager.getInstance(); private loadedPolyfills = new Set(); private polyfills: PolyfillConfig[] = [ { feature: 'custom-elements', url: 'https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js', condition: () => !this.versionManager.isFeatureSupported('customElements'), priority: 1, size: 7 }, { feature: 'shadow-dom', url: 'https://unpkg.com/@webcomponents/shadydom@1.11.0/shadydom.min.js', condition: () => !this.versionManager.isFeatureSupported('shadowDOM'), priority: 1, size: 15 }, { feature: 'container-queries', url: 'https://unpkg.com/container-query-polyfill@1.0.2/dist/container-query-polyfill.modern.js', condition: () => !this.versionManager.isFeatureSupported('containerQueries'), priority: 2, size: 25 }, { feature: 'focus-visible', url: 'https://unpkg.com/focus-visible@5.2.0/dist/focus-visible.min.js', condition: () => typeof window !== 'undefined' && typeof CSS !== 'undefined' && !CSS.supports('selector(:focus-visible)'), priority: 3, size: 2 }, { feature: 'smoothscroll', url: 'https://unpkg.com/smoothscroll-polyfill@0.4.4/dist/smoothscroll.min.js', condition: () => typeof window !== 'undefined' && typeof document !== 'undefined' && !('scrollBehavior' in document.documentElement.style), priority: 3, size: 8 }, { feature: 'resize-observer', url: 'https://unpkg.com/resize-observer-polyfill@1.5.1/dist/ResizeObserver.global.js', condition: () => typeof window !== 'undefined' && typeof (window as unknown as { ResizeObserver?: unknown }).ResizeObserver === 'undefined', priority: 3, size: 8 }, { feature: 'intersection-observer', url: 'https://unpkg.com/intersection-observer@0.12.2/intersection-observer.js', condition: () => typeof window !== 'undefined' && !('IntersectionObserver' in window), priority: 3, size: 9 }, { feature: 'anchor-positioning', url: 'https://unpkg.com/@oddbird/css-anchor-positioning@0.1.0/dist/css-anchor-positioning.min.js', condition: () => !this.versionManager.isFeatureSupported('anchorPositioning'), priority: 4, size: 45 }, { feature: 'view-transitions', // Inline-safe shim applied without injecting a