@barocss/browser 0.0.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,119 +0,0 @@
1
- import { GenerateCssRulesResult, Config } from '@barocss/kit';
2
- export interface BrowserRuntimeOptions {
3
- config?: Config;
4
- styleId?: string;
5
- insertionPoint?: 'head' | 'body' | HTMLElement;
6
- maxRulesPerPartition?: number;
7
- }
8
- export declare class BrowserRuntime {
9
- private cache;
10
- private rootCache;
11
- private context;
12
- private options;
13
- private isDestroyed;
14
- private incrementalParser;
15
- private changeDetector;
16
- private stylePartitionManager;
17
- constructor(options?: BrowserRuntimeOptions);
18
- /**
19
- * Add debug logs (by level)
20
- */
21
- private debugLog;
22
- private init;
23
- private injectPreflightCSS;
24
- private ensureCssVars;
25
- private getInsertionPoint;
26
- /**
27
- * Dynamically add one or more class names and generate/insert CSS
28
- */
29
- addClass(classes: string | string[]): void;
30
- /**
31
- * Process classes
32
- */
33
- private processClasses;
34
- /**
35
- * Process classes using incremental parsing
36
- */
37
- private processClassesIncremental;
38
- /**
39
- * Public method to apply parser results, update internal caches, and inject CSS
40
- */
41
- applyParseResults(results: Array<GenerateCssRulesResult>, _opts?: {
42
- isBrowser?: boolean;
43
- }): void;
44
- /**
45
- * MutationObserver instance method to automatically call addClass when class attributes change in DOM
46
- */
47
- observe(root?: HTMLElement, options?: {
48
- scan?: boolean;
49
- onReady?: () => void;
50
- }): MutationObserver;
51
- private normalizeClasses;
52
- has(cls: string): boolean;
53
- getCss(cls: string): string | undefined;
54
- getAllCss(): string;
55
- getClasses(): string[];
56
- /**
57
- * Get comprehensive cache statistics
58
- */
59
- getCacheStats(): {
60
- runtime: {
61
- cachedClasses: number;
62
- rootCacheSize: number;
63
- };
64
- ast: {
65
- size: number;
66
- maxSize: number;
67
- hitRate: number;
68
- };
69
- incremental: {
70
- processedClasses: number;
71
- pendingClasses: number;
72
- cacheStats: {
73
- ast: {
74
- size: number;
75
- maxSize: number;
76
- hitRate: number;
77
- };
78
- css: {};
79
- };
80
- };
81
- };
82
- /**
83
- * Clear all caches (useful for debugging or memory management)
84
- */
85
- clearCaches(): void;
86
- reset(): void;
87
- updateConfig(newConfig: Config): void;
88
- removeClass(classes: string | string[]): void;
89
- destroy(): void;
90
- getStats(): {
91
- cachedClasses: number;
92
- styleElementId: string;
93
- isDestroyed: boolean;
94
- config: Config;
95
- cacheStats: {
96
- runtime: {
97
- cachedClasses: number;
98
- rootCacheSize: number;
99
- };
100
- ast: {
101
- size: number;
102
- maxSize: number;
103
- hitRate: number;
104
- };
105
- incremental: {
106
- processedClasses: number;
107
- pendingClasses: number;
108
- cacheStats: {
109
- ast: {
110
- size: number;
111
- maxSize: number;
112
- hitRate: number;
113
- };
114
- css: {};
115
- };
116
- };
117
- };
118
- };
119
- }
@@ -1,80 +0,0 @@
1
- import { IncrementalParser } from '@barocss/kit';
2
- import { BrowserRuntime } from './browser-runtime';
3
- /**
4
- * Change detection system for DOM mutations
5
- *
6
- * ⚠️ BROWSER-ONLY: This class is designed for browser environments only.
7
- * It uses MutationObserver and DOM APIs that are not available in Node.js.
8
- *
9
- * This class monitors DOM changes and automatically processes new CSS classes
10
- * that are added to elements. It uses MutationObserver to detect:
11
- * - Class attribute changes on existing elements
12
- * - New elements being added to the DOM
13
- * - Changes in child elements
14
- *
15
- * For server-side usage, use IncrementalParser directly with processClassesSync()
16
- * or processClasses() methods.
17
- */
18
- export declare class ChangeDetector {
19
- /** MutationObserver instance for DOM change detection */
20
- private observer;
21
- /** Reference to IncrementalParser for class processing */
22
- private incrementalParser;
23
- /** Reference to BrowserRuntime for CSS injection (optional) */
24
- private BrowserRuntime?;
25
- /** Set of elements that have already been processed to avoid duplicates */
26
- private processedElements;
27
- /**
28
- * Create a new ChangeDetector instance
29
- *
30
- * @param incrementalParser - IncrementalParser instance for class processing
31
- * @param BrowserRuntime - Optional BrowserRuntime instance for CSS injection
32
- */
33
- constructor(incrementalParser: IncrementalParser, BrowserRuntime?: BrowserRuntime);
34
- /**
35
- * Starts observing DOM changes for new CSS classes
36
- *
37
- * This method sets up a MutationObserver that monitors:
38
- * - Attribute changes (specifically class attribute modifications)
39
- * - Child list changes (new elements being added)
40
- * - Subtree changes (changes in descendant elements)
41
- *
42
- * The observer automatically processes any new classes it discovers
43
- * by adding them to the IncrementalParser's pending queue.
44
- *
45
- * @param root - The root element to observe (defaults to document.body)
46
- * @param options - Configuration options including initial scan and onReady callback
47
- * @returns The MutationObserver instance for external control
48
- */
49
- observe(root?: HTMLElement, options?: {
50
- scan?: boolean;
51
- onReady?: () => void;
52
- }): MutationObserver;
53
- /**
54
- * Scan existing classes in the DOM and process them
55
- */
56
- private scanExistingClasses;
57
- /**
58
- * Processes an individual element and extracts new classes
59
- *
60
- * This method is called for each element discovered during DOM mutations.
61
- * It:
62
- * - Checks if the element has already been processed
63
- * - Extracts all class names from the element's className
64
- * - Filters out already processed classes
65
- * - Adds new classes to the collection for batch processing
66
- * - Marks the element as processed to avoid duplicates
67
- *
68
- * @param element - The HTML element to process
69
- * @param newClasses - Set to collect newly discovered class names
70
- */
71
- private processElement;
72
- /**
73
- * Stops observing DOM changes and cleans up resources
74
- *
75
- * This method disconnects the MutationObserver and clears the
76
- * observer reference to prevent memory leaks and allow the
77
- * ChangeDetector to be properly garbage collected.
78
- */
79
- disconnect(): void;
80
- }
@@ -1,51 +0,0 @@
1
- import { GenerateCssRulesResult } from '@barocss/kit';
2
- export interface StylePartition {
3
- id: string;
4
- styles: string[];
5
- styleElement: HTMLStyleElement;
6
- }
7
- export declare class StylePartitionManager {
8
- private partitions;
9
- private categoryPartitions;
10
- private partitionCounter;
11
- private maxRulesPerPartition;
12
- private insertionPoint;
13
- private classToPartitionMap;
14
- private classToCategoryPartitionMap;
15
- private styleIdPrefix;
16
- constructor(insertionPoint: HTMLElement, maxRulesPerPartition?: number, styleIdPrefix?: string);
17
- private initializeDefaultPartition;
18
- private createNewCategoryPartition;
19
- private createNewPartition;
20
- hasRule(rule: string): boolean;
21
- hasCategoryRule(rule: string, category: string): boolean;
22
- setRuleCache(rule: string, partitionIndex: number): void;
23
- setCategoryRuleCache(rule: string, category: string): void;
24
- get currentPartition(): StylePartition;
25
- getCategoryPartition(category: string): StylePartition | undefined;
26
- /**
27
- * Escape CSS rule text
28
- * - Properly escape special characters
29
- * - Prevent CSS syntax errors
30
- */
31
- private escapeCssRule;
32
- addRule(rule: string): boolean;
33
- addCategoryRule(rule: string, category: string): boolean;
34
- addRootRules(rules: string[]): {
35
- success: number;
36
- failed: number;
37
- };
38
- addRules(rules: GenerateCssRulesResult[]): {
39
- success: number;
40
- failed: number;
41
- };
42
- /**
43
- * 특정 규칙이 어느 파티션에 있는지 찾기
44
- */
45
- findRulePartition(rule: string): StylePartition | null;
46
- updateRuleContent(category: string, ruleContent: string): void;
47
- /**
48
- * 모든 파티션 정리
49
- */
50
- cleanup(): void;
51
- }
package/dist/utils.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function normalizeClassName(className: any): string;
2
- export declare function normalizeClassNameList(className: any): string[];