import { type ScannerOptions } from './options'; import { MasterCSS } from '@master/css'; import type { MasterCSSManifest } from '@master/css-schema/manifest'; import { type SourceAdapter } from '@master/css-source'; import { EventEmitter } from 'node:events'; interface ScannerResetOptions { emit?: boolean; } export default class CSSScanner extends EventEmitter { customOptions: ScannerOptions; cwd: string; latentClasses: Set; validClasses: Set; invalidClasses: Set; nativeClassNames: Set; usedNativeClasses: Set; initialized: boolean; initializing?: Promise; resetDependencies: string[]; /** * Per-source content-hash cache. When the same `source` arrives with the * same `content` (HMR re-fires the same file unchanged, vite transform * runs the same module twice), we skip re-running the regex pipeline * and re-validating every class. */ private contentHashes; /** * Memoized result of `generateValidRules` per syntax string. The same * class commonly appears in 100+ files in real codebases; without this, * we re-run css.generate() + validateCSS() per occurrence. With it, the * second occurrence is an O(1) Map lookup. */ private validRulesCache; /** Precompiled minimatch patterns for per-module allow/exclude checks. */ private sourceMatchers?; private sourceMatcherOptions?; /** Memoized adapter list so per-file extraction does not rebuild it. */ private sourceAdapters?; private sourceAdapterOptions?; /** Pre-split class exclusion matchers for `scan()` hot path. */ private classExclusionMatcher?; private classExclusionOptions?; constructor(customOptions?: ScannerOptions, cwd?: string); init(customOptions?: ScannerOptions): Promise; private initInternal; reset(customOptions?: ScannerOptions, resetOptions?: ScannerResetOptions): Promise; destroy(): Promise; private insertSafelist; /** * @description Extract source content candidates. * @param source * @param content * @returns string[] Latent classes */ collectCandidates(source: string, content: string): string[]; /** * @description Extract trusted content candidates and scan. * @param source * @param content * @returns string[] Latent classes */ scan(source: string, content: string): Promise; scanModule(source: string, content: string): Promise; resolveSourceAdapter(source: string): SourceAdapter | undefined; private getSourceMatchers; private getClassExclusionMatcher; private isClassExcluded; isModuleAllowed(source: string): boolean; /** * computed from `options.manifest` */ get manifest(): MasterCSSManifest; get slotCSSRule(): string; } export default interface CSSScanner { css: MasterCSS; options: ScannerOptions; } export {};