@codeleap/styles 7.0.0 → 7.0.2

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.
Files changed (95) hide show
  1. package/dist/classes/Cacher.js +170 -0
  2. package/dist/classes/Cacher.js.map +1 -0
  3. package/dist/classes/StaleControl.js +105 -0
  4. package/dist/classes/StaleControl.js.map +1 -0
  5. package/dist/classes/StyleCache.js +95 -0
  6. package/dist/classes/StyleCache.js.map +1 -0
  7. package/dist/classes/StylePersistor.js +58 -0
  8. package/dist/classes/StylePersistor.js.map +1 -0
  9. package/dist/classes/StyleRegistry.js +474 -0
  10. package/dist/classes/StyleRegistry.js.map +1 -0
  11. package/dist/classes/index.js +19 -0
  12. package/dist/classes/index.js.map +1 -0
  13. package/dist/constants.js +27 -0
  14. package/dist/constants.js.map +1 -0
  15. package/dist/hooks/index.js +21 -0
  16. package/dist/hooks/index.js.map +1 -0
  17. package/dist/hooks/useCompositionStyles.js +30 -0
  18. package/dist/hooks/useCompositionStyles.js.map +1 -0
  19. package/dist/hooks/useNestedStylesByKey.js +20 -0
  20. package/dist/hooks/useNestedStylesByKey.js.map +1 -0
  21. package/dist/hooks/useStyleObserver.js +26 -0
  22. package/dist/hooks/useStyleObserver.js.map +1 -0
  23. package/dist/hooks/useTheme.js +28 -0
  24. package/dist/hooks/useTheme.js.map +1 -0
  25. package/dist/index.js +28 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/lib/calc.js +48 -0
  28. package/dist/lib/calc.js.map +1 -0
  29. package/dist/lib/createStyles.js +63 -0
  30. package/dist/lib/createStyles.js.map +1 -0
  31. package/dist/lib/createTheme.js +147 -0
  32. package/dist/lib/createTheme.js.map +1 -0
  33. package/dist/lib/cssVariables.js +79 -0
  34. package/dist/lib/cssVariables.js.map +1 -0
  35. package/dist/lib/index.js +18 -0
  36. package/dist/lib/index.js.map +1 -0
  37. package/dist/theme/generateColorScheme.js +41 -0
  38. package/dist/theme/generateColorScheme.js.map +1 -0
  39. package/dist/theme/index.js +20 -0
  40. package/dist/theme/index.js.map +1 -0
  41. package/dist/theme/themeStore.d.ts +4 -4
  42. package/dist/theme/themeStore.d.ts.map +1 -1
  43. package/dist/theme/themeStore.js +143 -0
  44. package/dist/theme/themeStore.js.map +1 -0
  45. package/dist/theme/validateTheme.js +36 -0
  46. package/dist/theme/validateTheme.js.map +1 -0
  47. package/dist/tools/colors.js +147 -0
  48. package/dist/tools/colors.js.map +1 -0
  49. package/dist/tools/deepClone.js +14 -0
  50. package/dist/tools/deepClone.js.map +1 -0
  51. package/dist/tools/deepmerge.js +20 -0
  52. package/dist/tools/deepmerge.js.map +1 -0
  53. package/dist/tools/hashKey.js +20 -0
  54. package/dist/tools/hashKey.js.map +1 -0
  55. package/dist/tools/index.js +46 -0
  56. package/dist/tools/index.js.map +1 -0
  57. package/dist/tools/minifier.js +39 -0
  58. package/dist/tools/minifier.js.map +1 -0
  59. package/dist/tools/multiplierProperty.js +12 -0
  60. package/dist/tools/multiplierProperty.js.map +1 -0
  61. package/dist/types/cache.js +3 -0
  62. package/dist/types/cache.js.map +1 -0
  63. package/dist/types/component.js +3 -0
  64. package/dist/types/component.js.map +1 -0
  65. package/dist/types/core.js +4 -0
  66. package/dist/types/core.js.map +1 -0
  67. package/dist/types/icon.js +4 -0
  68. package/dist/types/icon.js.map +1 -0
  69. package/dist/types/index.js +22 -0
  70. package/dist/types/index.js.map +1 -0
  71. package/dist/types/spacing.js +31 -0
  72. package/dist/types/spacing.js.map +1 -0
  73. package/dist/types/store.js +3 -0
  74. package/dist/types/store.js.map +1 -0
  75. package/dist/types/style.js +3 -0
  76. package/dist/types/style.js.map +1 -0
  77. package/dist/types/theme.js +3 -0
  78. package/dist/types/theme.js.map +1 -0
  79. package/dist/utils.js +105 -0
  80. package/dist/utils.js.map +1 -0
  81. package/dist/variants/borderCreator.js +30 -0
  82. package/dist/variants/borderCreator.js.map +1 -0
  83. package/dist/variants/createAppVariants.js +20 -0
  84. package/dist/variants/createAppVariants.js.map +1 -0
  85. package/dist/variants/defaultVariants.js +140 -0
  86. package/dist/variants/defaultVariants.js.map +1 -0
  87. package/dist/variants/dynamicVariants.js +93 -0
  88. package/dist/variants/dynamicVariants.js.map +1 -0
  89. package/dist/variants/index.js +23 -0
  90. package/dist/variants/index.js.map +1 -0
  91. package/dist/variants/mediaQuery.js +59 -0
  92. package/dist/variants/mediaQuery.js.map +1 -0
  93. package/dist/variants/spacing.js +84 -0
  94. package/dist/variants/spacing.js.map +1 -0
  95. package/package.json +3 -3
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cache = void 0;
4
+ const constants_1 = require("../constants");
5
+ const tools_1 = require("../tools");
6
+ /**
7
+ * Generates a stale time date by adding 7 days to the current date
8
+ * @returns {Date} The future date representing the stale time
9
+ */
10
+ function generateStaleTime() {
11
+ const time = 7;
12
+ let currentTime = new Date();
13
+ currentTime.setDate(currentTime.getDate() + time);
14
+ return currentTime;
15
+ }
16
+ /**
17
+ * Generic cache implementation with persistence and stale time management
18
+ * @template T - The type of values stored in the cache
19
+ */
20
+ class Cache {
21
+ /**
22
+ * Gets the persistence key for cache data
23
+ * @returns {string} The storage key for cache data
24
+ */
25
+ get persistKeyCache() {
26
+ return `@styles.caches.${this.registryName}.cache`;
27
+ }
28
+ /**
29
+ * Gets the persistence key for stale time
30
+ * @returns {string} The storage key for stale time
31
+ */
32
+ get persistKeyStaleTime() {
33
+ return `@styles.caches.${this.registryName}.staleTime`;
34
+ }
35
+ /**
36
+ * Creates a new Cache instance
37
+ * @param {CacheType} registryName - The name/type of the cache registry
38
+ * @param {StateStorage} [storage=null] - The storage implementation for persistence
39
+ * @param {boolean} [persistCache=!!storage] - Whether to persist cache to storage
40
+ */
41
+ constructor(registryName, storage = undefined, persistCache = !!storage) {
42
+ this.registryName = registryName;
43
+ this.storage = storage;
44
+ this.persistCache = persistCache;
45
+ /** In-memory cache storage */
46
+ this.cache = {};
47
+ /** Debounce timer for batch persistence */
48
+ this.persistTimer = null;
49
+ /** Debounce delay in milliseconds */
50
+ this.persistDelay = 4500;
51
+ if (!persistCache || !constants_1.StyleConstants.STORE_CACHE_ENABLED)
52
+ return;
53
+ const { persistedCache, persistedStaleTime } = this.loadStorage();
54
+ const currentTime = new Date();
55
+ const isStaled = currentTime > persistedStaleTime;
56
+ if (isStaled) {
57
+ this.clearStorage();
58
+ return;
59
+ }
60
+ if (constants_1.StyleConstants.LOG) {
61
+ console.log('Cache [constructor] ->', { persistedCache, persistedStaleTime, registryName });
62
+ }
63
+ this.setCache(persistedCache);
64
+ this.storeStaleTime(persistedStaleTime);
65
+ }
66
+ /**
67
+ * Generates a cache key and retrieves the cached value
68
+ * @param {string} cacheBaseKey - The base key for cache generation
69
+ * @param {Array<any> | any} data - The data to use for key generation
70
+ * @returns {{ key: string, value: T | null }} Object containing the cache key and value
71
+ */
72
+ keyFor(cacheBaseKey, data) {
73
+ var _a;
74
+ const values = [cacheBaseKey, data];
75
+ const cacheKey = (0, tools_1.hashKey)(values);
76
+ const cachedValue = (_a = this.cache[cacheKey]) !== null && _a !== void 0 ? _a : null;
77
+ return {
78
+ key: cacheKey,
79
+ value: cachedValue,
80
+ };
81
+ }
82
+ /**
83
+ * Stores a value in the cache and optionally persists it
84
+ * @param {string} key - The cache key
85
+ * @param {T} cache - The value to cache
86
+ * @returns {T} The cached value
87
+ */
88
+ cacheFor(key, cache) {
89
+ this.cache[key] = cache;
90
+ if (this.persistCache) {
91
+ this.schedulePersist();
92
+ }
93
+ return cache;
94
+ }
95
+ /**
96
+ * Replaces the entire cache with new data
97
+ * @param {Record<string, T>} cache - The new cache data
98
+ */
99
+ setCache(cache) {
100
+ this.cache = cache !== null && cache !== void 0 ? cache : {};
101
+ }
102
+ /**
103
+ * Clears both in-memory and persistent cache
104
+ */
105
+ clear() {
106
+ if (this.persistTimer) {
107
+ clearTimeout(this.persistTimer);
108
+ this.persistTimer = null;
109
+ }
110
+ this.cache = {};
111
+ this.clearStorage();
112
+ }
113
+ /**
114
+ * Schedules cache persistence with debounce
115
+ */
116
+ schedulePersist() {
117
+ if (this.persistTimer) {
118
+ clearTimeout(this.persistTimer);
119
+ }
120
+ this.persistTimer = setTimeout(() => {
121
+ this.storeCache();
122
+ this.persistTimer = null;
123
+ }, this.persistDelay);
124
+ }
125
+ /**
126
+ * Loads cache data and stale time from persistent storage
127
+ * @returns {{ persistedStaleTime: Date, persistedCache: any }} Loaded data from storage
128
+ */
129
+ loadStorage() {
130
+ if (!this.persistCache)
131
+ return { persistedStaleTime: generateStaleTime(), persistedCache: {} };
132
+ const persistedStaleTime = this.storage.getItem(this.persistKeyStaleTime);
133
+ const persistedCache = this.storage.getItem(this.persistKeyCache);
134
+ return {
135
+ persistedStaleTime: !persistedStaleTime ? generateStaleTime() : new Date(persistedStaleTime),
136
+ persistedCache,
137
+ };
138
+ }
139
+ /**
140
+ * Clears cache data from persistent storage
141
+ */
142
+ clearStorage() {
143
+ if (!this.persistCache)
144
+ return;
145
+ this.storage.removeItem(this.persistKeyStaleTime);
146
+ this.storage.removeItem(this.persistKeyCache);
147
+ }
148
+ /**
149
+ * Stores cache data to persistent storage
150
+ * @param {Record<string, T>} [cache=null] - Cache data to store (uses current cache if not provided)
151
+ */
152
+ storeCache(cache = undefined) {
153
+ if (!this.persistCache)
154
+ return;
155
+ const value = cache !== null && cache !== void 0 ? cache : this.cache;
156
+ this.storage.setItem(this.persistKeyCache, value);
157
+ }
158
+ /**
159
+ * Stores stale time to persistent storage
160
+ * @param {Date} staleTime - The stale time to store
161
+ */
162
+ storeStaleTime(staleTime) {
163
+ if (!this.persistCache)
164
+ return;
165
+ const value = staleTime.toISOString();
166
+ this.storage.setItem(this.persistKeyStaleTime, value);
167
+ }
168
+ }
169
+ exports.Cache = Cache;
170
+ //# sourceMappingURL=Cacher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cacher.js","sourceRoot":"","sources":["../../src/classes/Cacher.ts"],"names":[],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AAE,KAAK,CAAC,CAAA;IACpD,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,SAAe;QAC5B,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,OAAM;QAE9B,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;QACrC,IAAI,CAAC,OAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAA;IACxD,CAAC;CACF;AA9KD,sBA8KC"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StaleControl = void 0;
4
+ /**
5
+ * @UNUSED_IMPLEMENTATION - Class available for future use
6
+ * Stale data controller with temporal expiration system
7
+ *
8
+ * @description This implementation is complete but not currently being used.
9
+ * Developed for potential future need of time-based cache invalidation.
10
+ */
11
+ class StaleControl {
12
+ /**
13
+ * @param staleTime - Expiration time in minutes (default: 60 minutes)
14
+ * @param staleTimeIdentifier - Separator to identify timestamp in value (default: '//:')
15
+ * @param wiperInterval - Expired data check interval in milliseconds (default: 30 minutes)
16
+ */
17
+ constructor(staleTime = 60, // minutes
18
+ staleTimeIdentifier = '//:', wiperInterval = 30 * 60 * 1000) {
19
+ this.staleTime = staleTime;
20
+ this.staleTimeIdentifier = staleTimeIdentifier;
21
+ this.wiperInterval = wiperInterval;
22
+ this.wiperId = null;
23
+ }
24
+ /**
25
+ * Checks if a value is expired based on embedded timestamp
26
+ * @param value - Value with embedded timestamp
27
+ * @returns boolean indicating if value is expired
28
+ */
29
+ isStaled(value) {
30
+ const { staleTime } = this.extractStaleTime(value);
31
+ const currentTime = new Date();
32
+ const isStaled = currentTime > staleTime;
33
+ return isStaled;
34
+ }
35
+ /**
36
+ * Inserts expiration timestamp into a value
37
+ * @param value - Original value without timestamp
38
+ * @returns Value with expiration timestamp embedded
39
+ */
40
+ insertStaleTime(value) {
41
+ const currentTime = new Date();
42
+ currentTime.setMinutes(currentTime.getMinutes() + this.staleTime);
43
+ const staleTime = currentTime.toISOString();
44
+ const valueWithStaleTime = `${value}${this.staleTimeIdentifier}${staleTime}`;
45
+ return valueWithStaleTime;
46
+ }
47
+ /**
48
+ * Refreshes the expiration timestamp of a value
49
+ * @param value - Value with existing timestamp
50
+ * @returns Value with refreshed expiration timestamp
51
+ */
52
+ refreshStaleTime(value) {
53
+ const { value: extractedValue } = this.extractStaleTime(value);
54
+ const refreshedValue = this.insertStaleTime(extractedValue);
55
+ return refreshedValue;
56
+ }
57
+ /**
58
+ * Extracts expiration timestamp and original value
59
+ * @param value - Value with embedded timestamp
60
+ * @returns Object containing expiration date and original value
61
+ */
62
+ extractStaleTime(value) {
63
+ const [extractedValue, _staleTime] = (value === null || value === void 0 ? void 0 : value.split(this.staleTimeIdentifier)) || [];
64
+ const staleTime = new Date(_staleTime || 0);
65
+ return {
66
+ staleTime,
67
+ value: extractedValue || value,
68
+ };
69
+ }
70
+ /**
71
+ * Wipes expired cache; verifies isStaled values and removes them
72
+ * @throws Error indicating method is not implemented
73
+ */
74
+ cacheWiper() {
75
+ throw new Error('Cache Wiper not implemented - Requires storage integration for future use');
76
+ }
77
+ /**
78
+ * Registers periodic cache cleaning interval
79
+ */
80
+ registerCacheWiper() {
81
+ if (this.wiperId !== null) {
82
+ this.unregisterCacheWiper();
83
+ }
84
+ this.wiperId = setInterval(() => {
85
+ this.cacheWiper();
86
+ }, this.wiperInterval);
87
+ }
88
+ /**
89
+ * Unregisters periodic cache cleaning interval
90
+ */
91
+ unregisterCacheWiper() {
92
+ if (this.wiperId) {
93
+ clearInterval(this.wiperId);
94
+ this.wiperId = null;
95
+ }
96
+ }
97
+ /**
98
+ * Cleanup method to clear intervals when instance is no longer needed
99
+ */
100
+ destroy() {
101
+ this.unregisterCacheWiper();
102
+ }
103
+ }
104
+ exports.StaleControl = StaleControl;
105
+ //# sourceMappingURL=StaleControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StaleControl.js","sourceRoot":"","sources":["../../src/classes/Sta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AAM,CAAC,cAAc,EAAE,UAAU,CAAC,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,KAAI,EAAE,CAAA;QACjF,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,CAAA;QAE3C,OAAO;YACL,SAAS;YACT,KAAK,EAAE,cAAc,IAAI,KAAK;SAC/B,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAA;IAC9F,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,oBAAoB,EAAE,CAAA;QAC7B,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;YAC9B,IAAI,CAAC,UAAU,EAAE,CAAA;QACnB,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACxB,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACrB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,oBAAoB,EAAE,CAAA;IAC7B,CAAC;CACF;AA5GA,oCA4GA"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StyleCache = void 0;
4
+ const Cacher_1 = require("./Cacher");
5
+ const tools_1 = require("../tools");
6
+ const constants_1 = require("../constants");
7
+ /**
8
+ * Aggregates the six typed `Cache` buckets used by the style registry.
9
+ * Three buckets (`styles`, `compositions`, `responsive`) are in-memory only.
10
+ * Three buckets (`variants`, `common`, `components`) are backed by the
11
+ * provided `StateStorage` and survive page reloads until the stale window expires.
12
+ *
13
+ * All keys are derived from a `baseKey` that encodes the active color scheme,
14
+ * theme snapshot, and common variants — so switching color scheme automatically
15
+ * invalidates all cached values without an explicit `wipeCache` call.
16
+ */
17
+ class StyleCache {
18
+ /**
19
+ * Creates a new StyleCache instance
20
+ * @param storage - State storage instance for persistent caches
21
+ */
22
+ constructor(storage) {
23
+ /** Cache for style data */
24
+ this.styles = new Cacher_1.Cache('styles');
25
+ /** Cache for style compositions */
26
+ this.compositions = new Cacher_1.Cache('compositions');
27
+ /** Cache for responsive styles */
28
+ this.responsive = new Cacher_1.Cache('responsive');
29
+ this.variants = new Cacher_1.Cache('variants', storage);
30
+ this.common = new Cacher_1.Cache('common', storage);
31
+ this.components = new Cacher_1.Cache('components', storage);
32
+ }
33
+ /**
34
+ * Registers and generates a base key for cache operations
35
+ * @param keys - Array of values to include in base key generation
36
+ * @returns The generated base key hash
37
+ */
38
+ registerBaseKey(keys) {
39
+ keys.push(constants_1.StyleConstants.STORES_PERSIST_VERSION);
40
+ const baseKey = (0, tools_1.hashKey)(keys);
41
+ this.baseKey = baseKey;
42
+ return baseKey;
43
+ }
44
+ /**
45
+ * Clears all cache instances
46
+ */
47
+ wipeCache() {
48
+ this.components.clear();
49
+ this.responsive.clear();
50
+ this.compositions.clear();
51
+ this.variants.clear();
52
+ this.common.clear();
53
+ this.styles.clear();
54
+ }
55
+ /**
56
+ * Generates a cache key and retrieves cached value if exists
57
+ * @param type - The cache type to use
58
+ * @param keyData - Data to use for key generation (array or object)
59
+ * @returns Object containing the generated key and cached value (if any)
60
+ */
61
+ keyFor(type, keyData) {
62
+ var _a;
63
+ const cache = this[type];
64
+ const withFunctionsHash = Object.values(keyData).map((value) => {
65
+ if (typeof value === 'function') {
66
+ return value.toString();
67
+ }
68
+ return value;
69
+ });
70
+ const values = [this.baseKey, ...withFunctionsHash];
71
+ const cacheKey = (0, tools_1.hashKey)(values);
72
+ const cachedValue = tools_1.minifier.decompress((_a = cache.cache[cacheKey]) !== null && _a !== void 0 ? _a : null);
73
+ return {
74
+ key: cacheKey,
75
+ value: cachedValue,
76
+ };
77
+ }
78
+ /**
79
+ * Stores a value in the specified cache with compression
80
+ * @param type - The cache type to use
81
+ * @param key - Cache key
82
+ * @param value - Value to cache
83
+ * @returns The cached value (compressed if caching is enabled)
84
+ */
85
+ cacheFor(type, key, value) {
86
+ if (!constants_1.StyleConstants.CACHE_ENABLED) {
87
+ return value;
88
+ }
89
+ const cache = this[type];
90
+ const minifiedValue = tools_1.minifier.compress(value);
91
+ return cache.cacheFor(key, minifiedValue);
92
+ }
93
+ }
94
+ exports.StyleCache = StyleCache;
95
+ //# sourceMappingURL=StyleCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StyleCache.js","sourceRoot":"","sources":["../../src/classes/StyleCache.ts"],"names":[],"mappings":";;;AAAA,qCAAgC;AAChC,oCAA4C;AAC5C,4CAA6C;AAI7C;;;;;;;;;GASG;AACH,MAAa,UAAU;IAsBrB;;;OAGG;IACH,YAAY,OAAqB;QAtBjC,2BAA2B;QAC3B,WAAM,GAAG,IAAI,cAAK,CAAC,QAAQ,CAAC,CAAA;QAE5B,mCAAmC;QACnC,iBAAY,GAAG,IAAI,cAAK,CAAC,cAAc,CAAC,CAAA;QAExC,kCAAkC;QAClC,eAAU,GAAG,IAAI,cAAK,CAAC,YAAY,CAAC,CAAA;QAgBlC,IAAI,CAAC,QAAQ,GAAG,IAAI,cAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,cAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,UAAU,GAAG,IAAI,cAAK,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;IACpD,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,IAAgB;QAC9B,IAAI,CAAC,IAAI,CAAC,0BAAc,CAAC,sBAAsB,CAAC,CAAA;QAEhD,M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QAC/C,IAAI,CAAC,0BAAc,CAAC,aAAa,EAAE,CAAC;YAClC,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;QAExB,MAAM,aAAa,GAAG,gBAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAE9C,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;IAC3C,CAAC;CACF;AAzGD,gCAyGC"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StylePersistor = void 0;
4
+ const tools_1 = require("../tools");
5
+ const constants_1 = require("../constants");
6
+ /**
7
+ * Adapts a platform `StoragePersistor` to the `StateStorage` interface expected by
8
+ * `StyleCache`. All values are LZ-compressed on write and decompressed on read,
9
+ * substantially reducing storage footprint for large serialised style caches.
10
+ */
11
+ class StylePersistor {
12
+ /**
13
+ * Creates a new StylePersistor instance with compression capabilities
14
+ * @param {StoragePersistor} storage - The underlying storage implementation
15
+ */
16
+ constructor(storage) {
17
+ this.storage = storage;
18
+ }
19
+ /**
20
+ * Stores a value in the underlying storage with compression
21
+ *
22
+ * @param {string} name - Storage key identifier
23
+ * @param {string} value - Value to store (will be compressed)
24
+ * @returns {void}
25
+ * @throws {Error} If the underlying storage fails to set the value
26
+ */
27
+ setItem(name, value) {
28
+ const minifiedValue = tools_1.minifier.compress(value);
29
+ return this.storage.set(name, minifiedValue);
30
+ }
31
+ /**
32
+ * Retrieves and decompresses a value from storage
33
+ * Returns null if key doesn't exist, value is null/undefined, or decompression fails
34
+ *
35
+ * @param {string} name - Storage key identifier
36
+ * @returns {string | null} Decompressed value or null if not found/invalid
37
+ * @throws {Error} If the underlying storage fails to get the value
38
+ */
39
+ getItem(name) {
40
+ const persistedValue = this.storage.get(name);
41
+ if (constants_1.StyleConstants.LOG) {
42
+ console.log('StylePersistor [getItem] => ' + name, persistedValue);
43
+ }
44
+ return tools_1.minifier.decompress(persistedValue !== null && persistedValue !== void 0 ? persistedValue : null);
45
+ }
46
+ /**
47
+ * Removes an item from storage
48
+ *
49
+ * @param {string} name - Storage key identifier
50
+ * @returns {void}
51
+ * @throws {Error} If the underlying storage fails to delete the value
52
+ */
53
+ removeItem(name) {
54
+ return this.storage.del(name);
55
+ }
56
+ }
57
+ exports.StylePersistor = StylePersistor;
58
+ //# sourceMappingURL=StylePersistor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StylePersistor.js","sourceRoot":"","sources":["../../src/classes/StylePersistor.ts"],"names":[],"mappings":";;;AACA,oCAAmC;AACnC,4CAA6C;AAc7C;;;;GAIG;AACH,MAAa,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,gBAAQ,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,0BAAc,CAAC,GAAG,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,8BAA8B,GAAG,IAAI,EAAE,cAAc,CAAC,CAAA;QACpE,CAAC;QAED,OAAO,gBAAQ,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;AAnDD,wCAmDC"}