@ogxjs/core 0.1.1 → 0.2.0-alpha.1
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.
- package/dist/builder.d.ts +5 -0
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +11 -1
- package/dist/cache/hash.d.ts +66 -0
- package/dist/cache/hash.d.ts.map +1 -0
- package/dist/cache/hash.js +161 -0
- package/dist/cache/index.d.ts +10 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +12 -0
- package/dist/cache/lru.d.ts +122 -0
- package/dist/cache/lru.d.ts.map +1 -0
- package/dist/cache/lru.js +269 -0
- package/dist/cache/snapshot.d.ts +116 -0
- package/dist/cache/snapshot.d.ts.map +1 -0
- package/dist/cache/snapshot.js +204 -0
- package/dist/cache.d.ts +2 -2
- package/dist/cache.js +2 -2
- package/dist/css.d.ts +19 -6
- package/dist/css.d.ts.map +1 -1
- package/dist/index.d.ts +18 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -10
- package/dist/ogx.js +2 -2
- package/dist/perf/index.d.ts +8 -0
- package/dist/perf/index.d.ts.map +1 -0
- package/dist/perf/index.js +7 -0
- package/dist/perf/timing.d.ts +160 -0
- package/dist/perf/timing.d.ts.map +1 -0
- package/dist/perf/timing.js +305 -0
- package/dist/presets/blog.js +1 -1
- package/dist/presets/docs.d.ts +2 -0
- package/dist/presets/docs.d.ts.map +1 -1
- package/dist/presets/docs.js +26 -23
- package/dist/presets/minimal.d.ts +2 -0
- package/dist/presets/minimal.d.ts.map +1 -1
- package/dist/presets/minimal.js +8 -16
- package/dist/presets/social.d.ts +2 -0
- package/dist/presets/social.d.ts.map +1 -1
- package/dist/presets/social.js +28 -18
- package/dist/render-png.d.ts.map +1 -1
- package/dist/render-png.js +9 -1
- package/dist/render-svg.d.ts.map +1 -1
- package/dist/render-svg.js +11 -1
- package/dist/tailwind/class-cache.d.ts +141 -0
- package/dist/tailwind/class-cache.d.ts.map +1 -0
- package/dist/tailwind/class-cache.js +212 -0
- package/dist/tailwind/index.d.ts +14 -1
- package/dist/tailwind/index.d.ts.map +1 -1
- package/dist/tailwind/index.js +15 -1
- package/dist/tailwind/lookup-tables.d.ts +30 -0
- package/dist/tailwind/lookup-tables.d.ts.map +1 -0
- package/dist/tailwind/lookup-tables.js +427 -0
- package/dist/tailwind/parser-v2.d.ts +54 -0
- package/dist/tailwind/parser-v2.d.ts.map +1 -0
- package/dist/tailwind/parser-v2.js +250 -0
- package/dist/tailwind/parser.d.ts +1 -0
- package/dist/tailwind/parser.d.ts.map +1 -1
- package/dist/tailwind/parser.js +1 -0
- package/dist/tailwind/prefix-handlers.d.ts +68 -0
- package/dist/tailwind/prefix-handlers.d.ts.map +1 -0
- package/dist/tailwind/prefix-handlers.js +931 -0
- package/package.json +17 -2
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ogxjs/core - Tailwind Class Cache
|
|
3
|
+
* Per-class caching for maximum performance
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Caches individual parsed classes instead of full class strings.
|
|
7
|
+
* This allows reuse across different elements with overlapping classes.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* Element A: "flex bg-blue-500 p-4"
|
|
11
|
+
* Element B: "flex bg-red-500 p-4"
|
|
12
|
+
* → "flex" and "p-4" are parsed once, reused for both
|
|
13
|
+
*
|
|
14
|
+
* @performance
|
|
15
|
+
* - Eliminates redundant parsing for common classes
|
|
16
|
+
* - Reduces memory by sharing parsed results
|
|
17
|
+
* - O(1) lookup per class
|
|
18
|
+
*
|
|
19
|
+
* @version 0.2.0 "Turbo"
|
|
20
|
+
*/
|
|
21
|
+
// CONFIGURATION
|
|
22
|
+
/**
|
|
23
|
+
* Maximum cache size to prevent memory leaks
|
|
24
|
+
* ~5000 classes × ~200 bytes avg = ~1MB max
|
|
25
|
+
*/
|
|
26
|
+
const MAX_CACHE_SIZE = 5000;
|
|
27
|
+
/**
|
|
28
|
+
* Classes to never cache (dynamic/theme-dependent)
|
|
29
|
+
*/
|
|
30
|
+
const UNCACHEABLE_PATTERNS = [
|
|
31
|
+
/^dark:/, // Dark mode variants (theme-dependent)
|
|
32
|
+
];
|
|
33
|
+
// CLASS CACHE
|
|
34
|
+
/**
|
|
35
|
+
* Cache for individual parsed Tailwind classes
|
|
36
|
+
* Key: class name (e.g., "bg-blue-500")
|
|
37
|
+
* Value: parsed CSS properties
|
|
38
|
+
*
|
|
39
|
+
* @performance v0.2.0 Turbo optimizations:
|
|
40
|
+
* - Direct reference return (no spread copy) - trust consumers
|
|
41
|
+
* - No Object.freeze - avoid expensive operation
|
|
42
|
+
* - Lazy eviction check
|
|
43
|
+
*/
|
|
44
|
+
class TailwindClassCache {
|
|
45
|
+
cache = new Map();
|
|
46
|
+
hits = 0;
|
|
47
|
+
misses = 0;
|
|
48
|
+
/**
|
|
49
|
+
* Get cached CSS properties for a class
|
|
50
|
+
* @returns Cached properties or undefined if not cached
|
|
51
|
+
*
|
|
52
|
+
* @performance Returns direct reference - DO NOT MUTATE
|
|
53
|
+
*/
|
|
54
|
+
get(cls) {
|
|
55
|
+
const cached = this.cache.get(cls);
|
|
56
|
+
if (cached !== undefined) {
|
|
57
|
+
this.hits++;
|
|
58
|
+
return cached; // Direct reference - no copy overhead
|
|
59
|
+
}
|
|
60
|
+
this.misses++;
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Cache CSS properties for a class
|
|
65
|
+
* @param cls - Tailwind class name
|
|
66
|
+
* @param props - Parsed CSS properties (will be stored directly)
|
|
67
|
+
*/
|
|
68
|
+
set(cls, props) {
|
|
69
|
+
// Don't cache theme-dependent classes
|
|
70
|
+
if (this.isUncacheable(cls))
|
|
71
|
+
return;
|
|
72
|
+
// Evict oldest entries if cache is full (lazy check)
|
|
73
|
+
if (this.cache.size >= MAX_CACHE_SIZE) {
|
|
74
|
+
this.evictOldest();
|
|
75
|
+
}
|
|
76
|
+
// Store directly - no copy, no freeze
|
|
77
|
+
this.cache.set(cls, props);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if a class has cached properties
|
|
81
|
+
*/
|
|
82
|
+
has(cls) {
|
|
83
|
+
return this.cache.has(cls);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Clear the entire cache
|
|
87
|
+
*/
|
|
88
|
+
clear() {
|
|
89
|
+
this.cache.clear();
|
|
90
|
+
this.hits = 0;
|
|
91
|
+
this.misses = 0;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get cache statistics
|
|
95
|
+
*/
|
|
96
|
+
getStats() {
|
|
97
|
+
const total = this.hits + this.misses;
|
|
98
|
+
return {
|
|
99
|
+
size: this.cache.size,
|
|
100
|
+
maxSize: MAX_CACHE_SIZE,
|
|
101
|
+
hits: this.hits,
|
|
102
|
+
misses: this.misses,
|
|
103
|
+
hitRate: total > 0 ? this.hits / total : 0,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Check if a class should not be cached
|
|
108
|
+
*/
|
|
109
|
+
isUncacheable(cls) {
|
|
110
|
+
return UNCACHEABLE_PATTERNS.some((pattern) => pattern.test(cls));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Evict oldest entries (FIFO strategy)
|
|
114
|
+
* Removes 10% of cache to avoid frequent evictions
|
|
115
|
+
*/
|
|
116
|
+
evictOldest() {
|
|
117
|
+
const toRemove = Math.ceil(MAX_CACHE_SIZE * 0.1);
|
|
118
|
+
const iterator = this.cache.keys();
|
|
119
|
+
for (let i = 0; i < toRemove; i++) {
|
|
120
|
+
const { value, done } = iterator.next();
|
|
121
|
+
if (done)
|
|
122
|
+
break;
|
|
123
|
+
this.cache.delete(value);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// FULL STRING CACHE
|
|
128
|
+
/**
|
|
129
|
+
* Cache for full class strings (entire tw prop)
|
|
130
|
+
* Useful when the same exact class string is used multiple times
|
|
131
|
+
*
|
|
132
|
+
* Key: "flex bg-blue-500 p-4"
|
|
133
|
+
* Value: merged CSS properties
|
|
134
|
+
*
|
|
135
|
+
* @performance v0.2.0 Turbo optimizations:
|
|
136
|
+
* - Direct reference return (no spread copy)
|
|
137
|
+
* - No Object.freeze
|
|
138
|
+
* - Efficient LRU-like eviction
|
|
139
|
+
*/
|
|
140
|
+
class TailwindStringCache {
|
|
141
|
+
cache = new Map();
|
|
142
|
+
maxSize = 1000;
|
|
143
|
+
/**
|
|
144
|
+
* Get cached properties for a full class string
|
|
145
|
+
* @performance Returns direct reference - DO NOT MUTATE
|
|
146
|
+
*/
|
|
147
|
+
get(key) {
|
|
148
|
+
return this.cache.get(key);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Cache properties for a full class string
|
|
152
|
+
*/
|
|
153
|
+
set(key, props) {
|
|
154
|
+
if (this.cache.size >= this.maxSize) {
|
|
155
|
+
// Simple eviction: delete oldest entries (first 20%)
|
|
156
|
+
const toRemove = Math.ceil(this.maxSize * 0.2);
|
|
157
|
+
const iterator = this.cache.keys();
|
|
158
|
+
for (let i = 0; i < toRemove; i++) {
|
|
159
|
+
const { value, done } = iterator.next();
|
|
160
|
+
if (done)
|
|
161
|
+
break;
|
|
162
|
+
this.cache.delete(value);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Store directly - no copy, no freeze
|
|
166
|
+
this.cache.set(key, props);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Check if a string has cached properties
|
|
170
|
+
*/
|
|
171
|
+
has(key) {
|
|
172
|
+
return this.cache.has(key);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Clear the cache
|
|
176
|
+
*/
|
|
177
|
+
clear() {
|
|
178
|
+
this.cache.clear();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get cache size
|
|
182
|
+
*/
|
|
183
|
+
get size() {
|
|
184
|
+
return this.cache.size;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// EXPORTS
|
|
188
|
+
/**
|
|
189
|
+
* Singleton instance for class-level caching
|
|
190
|
+
*/
|
|
191
|
+
export const classCache = new TailwindClassCache();
|
|
192
|
+
/**
|
|
193
|
+
* Singleton instance for full string caching
|
|
194
|
+
*/
|
|
195
|
+
export const stringCache = new TailwindStringCache();
|
|
196
|
+
/**
|
|
197
|
+
* Clear all Tailwind caches
|
|
198
|
+
* Useful for testing or when theme changes
|
|
199
|
+
*/
|
|
200
|
+
export function clearAllCaches() {
|
|
201
|
+
classCache.clear();
|
|
202
|
+
stringCache.clear();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get combined cache statistics
|
|
206
|
+
*/
|
|
207
|
+
export function getCacheStats() {
|
|
208
|
+
return {
|
|
209
|
+
classCache: classCache.getStats(),
|
|
210
|
+
stringCacheSize: stringCache.size,
|
|
211
|
+
};
|
|
212
|
+
}
|
package/dist/tailwind/index.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @ogxjs/core - Tailwind Module
|
|
3
|
+
* High-performance Tailwind CSS parser
|
|
4
|
+
*
|
|
5
|
+
* @version 0.2.0 "Turbo"
|
|
6
|
+
*/
|
|
7
|
+
export type { CacheStats } from "./class-cache";
|
|
8
|
+
export { classCache, stringCache } from "./class-cache";
|
|
9
|
+
export { colors } from "./colors";
|
|
10
|
+
export { getStaticClass, isStaticClass, STATIC_CLASSES } from "./lookup-tables";
|
|
11
|
+
export { clearAllCaches, getCacheStats, parseTailwind, parseTailwindBatch, } from "./parser-v2";
|
|
12
|
+
export type { GradientState, ParseContext } from "./prefix-handlers";
|
|
13
|
+
export { ORDERED_PREFIXES, PREFIX_HANDLERS, parseSpacingValue, resolveColorValue, } from "./prefix-handlers";
|
|
14
|
+
export { borderRadius, fontSize, fontWeight, opacity, spacing } from "./scales";
|
|
2
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tailwind/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tailwind/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEhF,OAAO,EACN,cAAc,EACd,aAAa,EACb,aAAa,EACb,kBAAkB,GAClB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EACN,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/tailwind/index.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @ogxjs/core - Tailwind Module
|
|
3
|
+
* High-performance Tailwind CSS parser
|
|
4
|
+
*
|
|
5
|
+
* @version 0.2.0 "Turbo"
|
|
6
|
+
*/
|
|
7
|
+
export { classCache, stringCache } from "./class-cache";
|
|
8
|
+
export { colors } from "./colors";
|
|
9
|
+
// Advanced exports for customization
|
|
10
|
+
export { getStaticClass, isStaticClass, STATIC_CLASSES } from "./lookup-tables";
|
|
11
|
+
// Main parser (v2 with O(1) lookups)
|
|
12
|
+
export { clearAllCaches, getCacheStats, parseTailwind, parseTailwindBatch, } from "./parser-v2";
|
|
13
|
+
export { ORDERED_PREFIXES, PREFIX_HANDLERS, parseSpacingValue, resolveColorValue, } from "./prefix-handlers";
|
|
14
|
+
// Scales and values
|
|
15
|
+
export { borderRadius, fontSize, fontWeight, opacity, spacing } from "./scales";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ogxjs/core - Tailwind Lookup Tables
|
|
3
|
+
* O(1) lookup for static classes (no dynamic values)
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* This module provides instant lookup for ~200+ static Tailwind classes.
|
|
7
|
+
* Instead of iterating through if/else chains, we use Map for O(1) access.
|
|
8
|
+
*
|
|
9
|
+
* @performance
|
|
10
|
+
* - Before: O(n) where n = number of if/else conditions (~100)
|
|
11
|
+
* - After: O(1) constant time lookup
|
|
12
|
+
*
|
|
13
|
+
* @version 0.2.0 "Turbo"
|
|
14
|
+
*/
|
|
15
|
+
import type { CSSProperties } from "../css";
|
|
16
|
+
/**
|
|
17
|
+
* Static classes that map directly to CSS properties
|
|
18
|
+
* No parsing needed - just lookup and return
|
|
19
|
+
*/
|
|
20
|
+
export declare const STATIC_CLASSES: Map<string, CSSProperties>;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a class is static (can be looked up directly)
|
|
23
|
+
*/
|
|
24
|
+
export declare function isStaticClass(cls: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Get CSS properties for a static class
|
|
27
|
+
* Returns undefined if not a static class
|
|
28
|
+
*/
|
|
29
|
+
export declare function getStaticClass(cls: string): CSSProperties | undefined;
|
|
30
|
+
//# sourceMappingURL=lookup-tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup-tables.d.ts","sourceRoot":"","sources":["../../src/tailwind/lookup-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C;;;GAGG;AACH,eAAO,MAAM,cAAc,4BAsdzB,CAAC;AAEH;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAErE"}
|