@codeleap/styles 7.0.0 → 7.0.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/classes/Cacher.js +166 -0
- package/dist/classes/Cacher.js.map +1 -0
- package/dist/classes/StaleControl.js +101 -0
- package/dist/classes/StaleControl.js.map +1 -0
- package/dist/classes/StyleCache.js +91 -0
- package/dist/classes/StyleCache.js.map +1 -0
- package/dist/classes/StylePersistor.js +54 -0
- package/dist/classes/StylePersistor.js.map +1 -0
- package/dist/classes/StyleRegistry.js +470 -0
- package/dist/classes/StyleRegistry.js.map +1 -0
- package/dist/classes/index.js +3 -0
- package/dist/classes/index.js.map +1 -0
- package/dist/constants.js +24 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useCompositionStyles.js +27 -0
- package/dist/hooks/useCompositionStyles.js.map +1 -0
- package/dist/hooks/useNestedStylesByKey.js +17 -0
- package/dist/hooks/useNestedStylesByKey.js.map +1 -0
- package/dist/hooks/useStyleObserver.js +22 -0
- package/dist/hooks/useStyleObserver.js.map +1 -0
- package/dist/hooks/useTheme.js +24 -0
- package/dist/hooks/useTheme.js.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/calc.js +44 -0
- package/dist/lib/calc.js.map +1 -0
- package/dist/lib/createStyles.js +58 -0
- package/dist/lib/createStyles.js.map +1 -0
- package/dist/lib/createTheme.js +143 -0
- package/dist/lib/createTheme.js.map +1 -0
- package/dist/lib/cssVariables.js +73 -0
- package/dist/lib/cssVariables.js.map +1 -0
- package/dist/lib/index.js +5 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/theme/generateColorScheme.js +38 -0
- package/dist/theme/generateColorScheme.js.map +1 -0
- package/dist/theme/index.js +4 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/themeStore.js +139 -0
- package/dist/theme/themeStore.js.map +1 -0
- package/dist/theme/validateTheme.js +33 -0
- package/dist/theme/validateTheme.js.map +1 -0
- package/dist/tools/colors.js +138 -0
- package/dist/tools/colors.js.map +1 -0
- package/dist/tools/deepClone.js +8 -0
- package/dist/tools/deepClone.js.map +1 -0
- package/dist/tools/deepmerge.js +13 -0
- package/dist/tools/deepmerge.js.map +1 -0
- package/dist/tools/hashKey.js +16 -0
- package/dist/tools/hashKey.js.map +1 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/minifier.js +34 -0
- package/dist/tools/minifier.js.map +1 -0
- package/dist/tools/multiplierProperty.js +9 -0
- package/dist/tools/multiplierProperty.js.map +1 -0
- package/dist/types/cache.js +2 -0
- package/dist/types/cache.js.map +1 -0
- package/dist/types/component.js +2 -0
- package/dist/types/component.js.map +1 -0
- package/dist/types/core.js +3 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/icon.js +3 -0
- package/dist/types/icon.js.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/spacing.js +28 -0
- package/dist/types/spacing.js.map +1 -0
- package/dist/types/store.js +2 -0
- package/dist/types/store.js.map +1 -0
- package/dist/types/style.js +2 -0
- package/dist/types/style.js.map +1 -0
- package/dist/types/theme.js +2 -0
- package/dist/types/theme.js.map +1 -0
- package/dist/utils.js +97 -0
- package/dist/utils.js.map +1 -0
- package/dist/variants/borderCreator.js +26 -0
- package/dist/variants/borderCreator.js.map +1 -0
- package/dist/variants/createAppVariants.js +17 -0
- package/dist/variants/createAppVariants.js.map +1 -0
- package/dist/variants/defaultVariants.js +137 -0
- package/dist/variants/defaultVariants.js.map +1 -0
- package/dist/variants/dynamicVariants.js +89 -0
- package/dist/variants/dynamicVariants.js.map +1 -0
- package/dist/variants/index.js +7 -0
- package/dist/variants/index.js.map +1 -0
- package/dist/variants/mediaQuery.js +56 -0
- package/dist/variants/mediaQuery.js.map +1 -0
- package/dist/variants/spacing.js +81 -0
- package/dist/variants/spacing.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { StyleConstants } from '../constants';
|
|
2
|
+
import { hashKey } from '../tools';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a stale time date by adding 7 days to the current date
|
|
5
|
+
* @returns {Date} The future date representing the stale time
|
|
6
|
+
*/
|
|
7
|
+
function generateStaleTime() {
|
|
8
|
+
const time = 7;
|
|
9
|
+
let currentTime = new Date();
|
|
10
|
+
currentTime.setDate(currentTime.getDate() + time);
|
|
11
|
+
return currentTime;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generic cache implementation with persistence and stale time management
|
|
15
|
+
* @template T - The type of values stored in the cache
|
|
16
|
+
*/
|
|
17
|
+
export class Cache {
|
|
18
|
+
/**
|
|
19
|
+
* Gets the persistence key for cache data
|
|
20
|
+
* @returns {string} The storage key for cache data
|
|
21
|
+
*/
|
|
22
|
+
get persistKeyCache() {
|
|
23
|
+
return `@styles.caches.${this.registryName}.cache`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets the persistence key for stale time
|
|
27
|
+
* @returns {string} The storage key for stale time
|
|
28
|
+
*/
|
|
29
|
+
get persistKeyStaleTime() {
|
|
30
|
+
return `@styles.caches.${this.registryName}.staleTime`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new Cache instance
|
|
34
|
+
* @param {CacheType} registryName - The name/type of the cache registry
|
|
35
|
+
* @param {StateStorage} [storage=null] - The storage implementation for persistence
|
|
36
|
+
* @param {boolean} [persistCache=!!storage] - Whether to persist cache to storage
|
|
37
|
+
*/
|
|
38
|
+
constructor(registryName, storage = undefined, persistCache = !!storage) {
|
|
39
|
+
this.registryName = registryName;
|
|
40
|
+
this.storage = storage;
|
|
41
|
+
this.persistCache = persistCache;
|
|
42
|
+
/** In-memory cache storage */
|
|
43
|
+
this.cache = {};
|
|
44
|
+
/** Debounce timer for batch persistence */
|
|
45
|
+
this.persistTimer = null;
|
|
46
|
+
/** Debounce delay in milliseconds */
|
|
47
|
+
this.persistDelay = 4500;
|
|
48
|
+
if (!persistCache || !StyleConstants.STORE_CACHE_ENABLED)
|
|
49
|
+
return;
|
|
50
|
+
const { persistedCache, persistedStaleTime } = this.loadStorage();
|
|
51
|
+
const currentTime = new Date();
|
|
52
|
+
const isStaled = currentTime > persistedStaleTime;
|
|
53
|
+
if (isStaled) {
|
|
54
|
+
this.clearStorage();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (StyleConstants.LOG) {
|
|
58
|
+
console.log('Cache [constructor] ->', { persistedCache, persistedStaleTime, registryName });
|
|
59
|
+
}
|
|
60
|
+
this.setCache(persistedCache);
|
|
61
|
+
this.storeStaleTime(persistedStaleTime);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Generates a cache key and retrieves the cached value
|
|
65
|
+
* @param {string} cacheBaseKey - The base key for cache generation
|
|
66
|
+
* @param {Array<any> | any} data - The data to use for key generation
|
|
67
|
+
* @returns {{ key: string, value: T | null }} Object containing the cache key and value
|
|
68
|
+
*/
|
|
69
|
+
keyFor(cacheBaseKey, data) {
|
|
70
|
+
var _a;
|
|
71
|
+
const values = [cacheBaseKey, data];
|
|
72
|
+
const cacheKey = hashKey(values);
|
|
73
|
+
const cachedValue = (_a = this.cache[cacheKey]) !== null && _a !== void 0 ? _a : null;
|
|
74
|
+
return {
|
|
75
|
+
key: cacheKey,
|
|
76
|
+
value: cachedValue,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Stores a value in the cache and optionally persists it
|
|
81
|
+
* @param {string} key - The cache key
|
|
82
|
+
* @param {T} cache - The value to cache
|
|
83
|
+
* @returns {T} The cached value
|
|
84
|
+
*/
|
|
85
|
+
cacheFor(key, cache) {
|
|
86
|
+
this.cache[key] = cache;
|
|
87
|
+
if (this.persistCache) {
|
|
88
|
+
this.schedulePersist();
|
|
89
|
+
}
|
|
90
|
+
return cache;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Replaces the entire cache with new data
|
|
94
|
+
* @param {Record<string, T>} cache - The new cache data
|
|
95
|
+
*/
|
|
96
|
+
setCache(cache) {
|
|
97
|
+
this.cache = cache !== null && cache !== void 0 ? cache : {};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Clears both in-memory and persistent cache
|
|
101
|
+
*/
|
|
102
|
+
clear() {
|
|
103
|
+
if (this.persistTimer) {
|
|
104
|
+
clearTimeout(this.persistTimer);
|
|
105
|
+
this.persistTimer = null;
|
|
106
|
+
}
|
|
107
|
+
this.cache = {};
|
|
108
|
+
this.clearStorage();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Schedules cache persistence with debounce
|
|
112
|
+
*/
|
|
113
|
+
schedulePersist() {
|
|
114
|
+
if (this.persistTimer) {
|
|
115
|
+
clearTimeout(this.persistTimer);
|
|
116
|
+
}
|
|
117
|
+
this.persistTimer = setTimeout(() => {
|
|
118
|
+
this.storeCache();
|
|
119
|
+
this.persistTimer = null;
|
|
120
|
+
}, this.persistDelay);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Loads cache data and stale time from persistent storage
|
|
124
|
+
* @returns {{ persistedStaleTime: Date, persistedCache: any }} Loaded data from storage
|
|
125
|
+
*/
|
|
126
|
+
loadStorage() {
|
|
127
|
+
if (!this.persistCache)
|
|
128
|
+
return { persistedStaleTime: generateStaleTime(), persistedCache: {} };
|
|
129
|
+
const persistedStaleTime = this.storage.getItem(this.persistKeyStaleTime);
|
|
130
|
+
const persistedCache = this.storage.getItem(this.persistKeyCache);
|
|
131
|
+
return {
|
|
132
|
+
persistedStaleTime: !persistedStaleTime ? generateStaleTime() : new Date(persistedStaleTime),
|
|
133
|
+
persistedCache,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Clears cache data from persistent storage
|
|
138
|
+
*/
|
|
139
|
+
clearStorage() {
|
|
140
|
+
if (!this.persistCache)
|
|
141
|
+
return;
|
|
142
|
+
this.storage.removeItem(this.persistKeyStaleTime);
|
|
143
|
+
this.storage.removeItem(this.persistKeyCache);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Stores cache data to persistent storage
|
|
147
|
+
* @param {Record<string, T>} [cache=null] - Cache data to store (uses current cache if not provided)
|
|
148
|
+
*/
|
|
149
|
+
storeCache(cache = undefined) {
|
|
150
|
+
if (!this.persistCache)
|
|
151
|
+
return;
|
|
152
|
+
const value = cache !== null && cache !== void 0 ? cache : this.cache;
|
|
153
|
+
this.storage.setItem(this.persistKeyCache, value);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Stores stale time to persistent storage
|
|
157
|
+
* @param {Date} staleTime - The stale time to store
|
|
158
|
+
*/
|
|
159
|
+
storeStaleTime(staleTime) {
|
|
160
|
+
if (!this.persistCache)
|
|
161
|
+
return;
|
|
162
|
+
const value = staleTime.toISOString();
|
|
163
|
+
this.storage.setItem(this.persistKeyStaleTime, value);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=Cacher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cacher.js","sourceRoot":"","sources":["../../src/classes/Cacher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC;;;GAGG;AACH,SAAS,iBAAiB;IACxB,MAAM,IAAI,GAAG,CAAC,CAAA;IAEd,IAAI,WAAW,GAAG,IAAI,IAAI,EAAE,CAAA;IAE5B,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IAEjD,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,KAAK;IAUhB;;;OAGG;IACH,IAAI,e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NUSED_IMPLEMENTATION - Class available for future use
|
|
3
|
+
* Stale data controller with temporal expiration system
|
|
4
|
+
*
|
|
5
|
+
* @description This implementation is complete but not currently being used.
|
|
6
|
+
* Developed for potential future need of time-based cache invalidation.
|
|
7
|
+
*/
|
|
8
|
+
export class StaleControl {
|
|
9
|
+
/**
|
|
10
|
+
* @param staleTime - Expiration time in minutes (default: 60 minutes)
|
|
11
|
+
* @param staleTimeIdentifier - Separator to identify timestamp in value (default: '//:')
|
|
12
|
+
* @param wiperInterval - Expired data check interval in milliseconds (default: 30 minutes)
|
|
13
|
+
*/
|
|
14
|
+
constructor(staleTime = 60, // minutes
|
|
15
|
+
staleTimeIdentifier = '//:', wiperInterval = 30 * 60 * 1000) {
|
|
16
|
+
this.staleTime = staleTime;
|
|
17
|
+
this.staleTimeIdentifier = staleTimeIdentifier;
|
|
18
|
+
this.wiperInterval = wiperInterval;
|
|
19
|
+
this.wiperId = null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a value is expired based on embedded timestamp
|
|
23
|
+
* @param value - Value with embedded timestamp
|
|
24
|
+
* @returns boolean indicating if value is expired
|
|
25
|
+
*/
|
|
26
|
+
isStaled(value) {
|
|
27
|
+
const { staleTime } = this.extractStaleTime(value);
|
|
28
|
+
const currentTime = new Date();
|
|
29
|
+
const isStaled = currentTime > staleTime;
|
|
30
|
+
return isStaled;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Inserts expiration timestamp into a value
|
|
34
|
+
* @param value - Original value without timestamp
|
|
35
|
+
* @returns Value with expiration timestamp embedded
|
|
36
|
+
*/
|
|
37
|
+
insertStaleTime(value) {
|
|
38
|
+
const currentTime = new Date();
|
|
39
|
+
currentTime.setMinutes(currentTime.getMinutes() + this.staleTime);
|
|
40
|
+
const staleTime = currentTime.toISOString();
|
|
41
|
+
const valueWithStaleTime = `${value}${this.staleTimeIdentifier}${staleTime}`;
|
|
42
|
+
return valueWithStaleTime;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Refreshes the expiration timestamp of a value
|
|
46
|
+
* @param value - Value with existing timestamp
|
|
47
|
+
* @returns Value with refreshed expiration timestamp
|
|
48
|
+
*/
|
|
49
|
+
refreshStaleTime(value) {
|
|
50
|
+
const { value: extractedValue } = this.extractStaleTime(value);
|
|
51
|
+
const refreshedValue = this.insertStaleTime(extractedValue);
|
|
52
|
+
return refreshedValue;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Extracts expiration timestamp and original value
|
|
56
|
+
* @param value - Value with embedded timestamp
|
|
57
|
+
* @returns Object containing expiration date and original value
|
|
58
|
+
*/
|
|
59
|
+
extractStaleTime(value) {
|
|
60
|
+
const [extractedValue, _staleTime] = (value === null || value === void 0 ? void 0 : value.split(this.staleTimeIdentifier)) || [];
|
|
61
|
+
const staleTime = new Date(_staleTime || 0);
|
|
62
|
+
return {
|
|
63
|
+
staleTime,
|
|
64
|
+
value: extractedValue || value,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Wipes expired cache; verifies isStaled values and removes them
|
|
69
|
+
* @throws Error indicating method is not implemented
|
|
70
|
+
*/
|
|
71
|
+
cacheWiper() {
|
|
72
|
+
throw new Error('Cache Wiper not implemented - Requires storage integration for future use');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Registers periodic cache cleaning interval
|
|
76
|
+
*/
|
|
77
|
+
registerCacheWiper() {
|
|
78
|
+
if (this.wiperId !== null) {
|
|
79
|
+
this.unregisterCacheWiper();
|
|
80
|
+
}
|
|
81
|
+
this.wiperId = setInterval(() => {
|
|
82
|
+
this.cacheWiper();
|
|
83
|
+
}, this.wiperInterval);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Unregisters periodic cache cleaning interval
|
|
87
|
+
*/
|
|
88
|
+
unregisterCacheWiper() {
|
|
89
|
+
if (this.wiperId) {
|
|
90
|
+
clearInterval(this.wiperId);
|
|
91
|
+
this.wiperId = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Cleanup method to clear intervals when instance is no longer needed
|
|
96
|
+
*/
|
|
97
|
+
destroy() {
|
|
98
|
+
this.unregisterCacheWiper();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=StaleControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaleControl.js","sourceRoot":"","sources":["../../src/classes/StaleControl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACF,MAAM,OAAO,YAAY;IAGxB;;;;OAIG;IACH,YACU,YAAoB,EAAE,EAAE,UAAU;IAClC,sBAA8B,KAAK,EACnC,gBAAwB,EAAE,GAAG,EAAE,GAAG,IAAI;QAFtC,cAAS,GAAT,SAAS,CAAa;QACtB,wBAAmB,GAAnB,mBAAmB,CAAgB;QACnC,kBAAa,GAAb,aAAa,CAAyB;QAVxC,YAAO,GAA0C,IAAI,CAAA;IAW1D,CAAC;IAEJ;;;;OAIG;IACH,QAAQ,CAAC,KAAa;QACpB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAElD,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAA;QAE9B,MAAM,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAA;QAExC,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,KAAa;QAC3B,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAA;QAC9B,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;QAEjE,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,EAAE,CAAA;QAC3C,MAAM,kBAAkB,GAAG,GAAG,KAAK,GAAG,IAAI,CAAC,mBAAmB,GAAG,SAAS,EAAE,CAAA;QAE5E,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B,CAAC;CACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Cache } from './Cacher';
|
|
2
|
+
import { hashKey, minifier } from '../tools';
|
|
3
|
+
import { StyleConstants } from '../constants';
|
|
4
|
+
/**
|
|
5
|
+
* Aggregates the six typed `Cache` buckets used by the style registry.
|
|
6
|
+
* Three buckets (`styles`, `compositions`, `responsive`) are in-memory only.
|
|
7
|
+
* Three buckets (`variants`, `common`, `components`) are backed by the
|
|
8
|
+
* provided `StateStorage` and survive page reloads until the stale window expires.
|
|
9
|
+
*
|
|
10
|
+
* All keys are derived from a `baseKey` that encodes the active color scheme,
|
|
11
|
+
* theme snapshot, and common variants — so switching color scheme automatically
|
|
12
|
+
* invalidates all cached values without an explicit `wipeCache` call.
|
|
13
|
+
*/
|
|
14
|
+
export class StyleCache {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new StyleCache instance
|
|
17
|
+
* @param storage - State storage instance for persistent caches
|
|
18
|
+
*/
|
|
19
|
+
constructor(storage) {
|
|
20
|
+
/** Cache for style data */
|
|
21
|
+
this.styles = new Cache('styles');
|
|
22
|
+
/** Cache for style compositions */
|
|
23
|
+
this.compositions = new Cache('compositions');
|
|
24
|
+
/** Cache for responsive styles */
|
|
25
|
+
this.responsive = new Cache('responsive');
|
|
26
|
+
this.variants = new Cache('variants', storage);
|
|
27
|
+
this.common = new Cache('common', storage);
|
|
28
|
+
this.components = new Cache('components', storage);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Registers and generates a base key for cache operations
|
|
32
|
+
* @param keys - Array of values to include in base key generation
|
|
33
|
+
* @returns The generated base key hash
|
|
34
|
+
*/
|
|
35
|
+
registerBaseKey(keys) {
|
|
36
|
+
keys.push(StyleConstants.STORES_PERSIST_VERSION);
|
|
37
|
+
const baseKey = hashKey(keys);
|
|
38
|
+
this.baseKey = baseKey;
|
|
39
|
+
return baseKey;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Clears all cache instances
|
|
43
|
+
*/
|
|
44
|
+
wipeCache() {
|
|
45
|
+
this.components.clear();
|
|
46
|
+
this.responsive.clear();
|
|
47
|
+
this.compositions.clear();
|
|
48
|
+
this.variants.clear();
|
|
49
|
+
this.common.clear();
|
|
50
|
+
this.styles.clear();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generates a cache key and retrieves cached value if exists
|
|
54
|
+
* @param type - The cache type to use
|
|
55
|
+
* @param keyData - Data to use for key generation (array or object)
|
|
56
|
+
* @returns Object containing the generated key and cached value (if any)
|
|
57
|
+
*/
|
|
58
|
+
keyFor(type, keyData) {
|
|
59
|
+
var _a;
|
|
60
|
+
const cache = this[type];
|
|
61
|
+
const withFunctionsHash = Object.values(keyData).map((value) => {
|
|
62
|
+
if (typeof value === 'function') {
|
|
63
|
+
return value.toString();
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
});
|
|
67
|
+
const values = [this.baseKey, ...withFunctionsHash];
|
|
68
|
+
const cacheKey = hashKey(values);
|
|
69
|
+
const cachedValue = minifier.decompress((_a = cache.cache[cacheKey]) !== null && _a !== void 0 ? _a : null);
|
|
70
|
+
return {
|
|
71
|
+
key: cacheKey,
|
|
72
|
+
value: cachedValue,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Stores a value in the specified cache with compression
|
|
77
|
+
* @param type - The cache type to use
|
|
78
|
+
* @param key - Cache key
|
|
79
|
+
* @param value - Value to cache
|
|
80
|
+
* @returns The cached value (compressed if caching is enabled)
|
|
81
|
+
*/
|
|
82
|
+
cacheFor(type, key, value) {
|
|
83
|
+
if (!StyleConstants.CACHE_ENABLED) {
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
const cache = this[type];
|
|
87
|
+
const minifiedValue = minifier.compress(value);
|
|
88
|
+
return cache.cacheFor(key, minifiedValue);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=StyleCache.js.map
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
|
1
|
+
import { minifier } from '../tools';
|
|
2
|
+
import { StyleConstants } from '../constants';
|
|
3
|
+
/**
|
|
4
|
+
* Adapts a platform `StoragePersistor` to the `StateStorage` interface expected by
|
|
5
|
+
* `StyleCache`. All values are LZ-compressed on write and decompressed on read,
|
|
6
|
+
* substantially reducing storage footprint for large serialised style caches.
|
|
7
|
+
*/
|
|
8
|
+
export class StylePersistor {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new StylePersistor instance with compression capabilities
|
|
11
|
+
* @param {StoragePersistor} storage - The underlying storage implementation
|
|
12
|
+
*/
|
|
13
|
+
constructor(storage) {
|
|
14
|
+
this.storage = storage;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Stores a value in the underlying storage with compression
|
|
18
|
+
*
|
|
19
|
+
* @param {string} name - Storage key identifier
|
|
20
|
+
* @param {string} value - Value to store (will be compressed)
|
|
21
|
+
* @returns {void}
|
|
22
|
+
* @throws {Error} If the underlying storage fails to set the value
|
|
23
|
+
*/
|
|
24
|
+
setItem(name, value) {
|
|
25
|
+
const minifiedValue = minifier.compress(value);
|
|
26
|
+
return this.storage.set(name, minifiedValue);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves and decompresses a value from storage
|
|
30
|
+
* Returns null if key doesn't exist, value is null/undefined, or decompression fails
|
|
31
|
+
*
|
|
32
|
+
* @param {string} name - Storage key identifier
|
|
33
|
+
* @returns {string | null} Decompressed value or null if not found/invalid
|
|
34
|
+
* @throws {Error} If the underlying storage fails to get the value
|
|
35
|
+
*/
|
|
36
|
+
getItem(name) {
|
|
37
|
+
const persistedValue = this.storage.get(name);
|
|
38
|
+
if (StyleConstants.LOG) {
|
|
39
|
+
console.log('StylePersistor [getItem] => ' + name, persistedValue);
|
|
40
|
+
}
|
|
41
|
+
return minifier.decompress(persistedValue !== null && persistedValue !== void 0 ? persistedValue : null);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Removes an item from storage
|
|
45
|
+
*
|
|
46
|
+
* @param {string} name - Storage key identifier
|
|
47
|
+
* @returns {void}
|
|
48
|
+
* @throws {Error} If the underlying storage fails to delete the value
|
|
49
|
+
*/
|
|
50
|
+
removeItem(name) {
|
|
51
|
+
return this.storage.del(name);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=StylePersistor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StylePersistor.js","sourceRoot":"","sources":["../../src/classes/StylePersistor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAc7C;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACzB;;;OAGG;IACH,YACU,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAC/B,CAAC;IAEL;;;;;;;OAOG;IACH,OAAO,CAAC,IAAY,EAAE,KAAa;QACjC,MAAM,aAAa,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAE9C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;IAC9C,CAAC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,IAAY;QAClB,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAE7C,IAAI,cAAc,CAAC,GAAG,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,8BAA8B,GAAG,IAAI,EAAE,cAAc,CAAC,CAAA;QACpE,CAAC;QAED,OAAO,QAAQ,CAAC,UAAU,CAAC,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,IAAI,CAAC,CAAA;IACpD,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;CACF"}
|