pulse-js-framework 1.5.0 → 1.5.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/package.json +5 -2
- package/runtime/lru-cache.js +22 -26
- package/runtime/utils.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pulse-js-framework",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A declarative DOM framework with CSS selector-based structure and reactive pulsations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"LICENSE"
|
|
76
76
|
],
|
|
77
77
|
"scripts": {
|
|
78
|
-
"test": "npm run test:compiler && npm run test:sourcemap && npm run test:pulse && npm run test:dom && npm run test:router && npm run test:store && npm run test:hmr && npm run test:lint && npm run test:format && npm run test:analyze",
|
|
78
|
+
"test": "npm run test:compiler && npm run test:sourcemap && npm run test:pulse && npm run test:dom && npm run test:router && npm run test:store && npm run test:hmr && npm run test:lint && npm run test:format && npm run test:analyze && npm run test:lru-cache && npm run test:utils && npm run test:docs",
|
|
79
79
|
"test:compiler": "node test/compiler.test.js",
|
|
80
80
|
"test:sourcemap": "node test/sourcemap.test.js",
|
|
81
81
|
"test:pulse": "node test/pulse.test.js",
|
|
@@ -86,6 +86,9 @@
|
|
|
86
86
|
"test:lint": "node test/lint.test.js",
|
|
87
87
|
"test:format": "node test/format.test.js",
|
|
88
88
|
"test:analyze": "node test/analyze.test.js",
|
|
89
|
+
"test:lru-cache": "node test/lru-cache.test.js",
|
|
90
|
+
"test:utils": "node test/utils.test.js",
|
|
91
|
+
"test:docs": "node test/docs.test.js",
|
|
89
92
|
"build:netlify": "node scripts/build-netlify.js",
|
|
90
93
|
"version": "node scripts/sync-version.js",
|
|
91
94
|
"docs": "node cli/index.js dev docs"
|
package/runtime/lru-cache.js
CHANGED
|
@@ -8,15 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* LRU Cache implementation
|
|
11
|
+
* Uses Map's insertion order for O(1) operations.
|
|
11
12
|
* @template K, V
|
|
12
13
|
*/
|
|
13
14
|
export class LRUCache {
|
|
14
|
-
/** @type {number} */
|
|
15
|
-
#capacity;
|
|
16
|
-
|
|
17
|
-
/** @type {Map<K, V>} */
|
|
18
|
-
#cache = new Map();
|
|
19
|
-
|
|
20
15
|
/**
|
|
21
16
|
* Create an LRU cache
|
|
22
17
|
* @param {number} capacity - Maximum number of items to store
|
|
@@ -25,7 +20,8 @@ export class LRUCache {
|
|
|
25
20
|
if (capacity <= 0) {
|
|
26
21
|
throw new Error('LRU cache capacity must be greater than 0');
|
|
27
22
|
}
|
|
28
|
-
this
|
|
23
|
+
this._capacity = capacity;
|
|
24
|
+
this._cache = new Map();
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
/**
|
|
@@ -35,14 +31,14 @@ export class LRUCache {
|
|
|
35
31
|
* @returns {V|undefined} The cached value or undefined if not found
|
|
36
32
|
*/
|
|
37
33
|
get(key) {
|
|
38
|
-
if (!this
|
|
34
|
+
if (!this._cache.has(key)) {
|
|
39
35
|
return undefined;
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
// Move to end (most recently used) by re-inserting
|
|
43
|
-
const value = this
|
|
44
|
-
this
|
|
45
|
-
this
|
|
39
|
+
const value = this._cache.get(key);
|
|
40
|
+
this._cache.delete(key);
|
|
41
|
+
this._cache.set(key, value);
|
|
46
42
|
return value;
|
|
47
43
|
}
|
|
48
44
|
|
|
@@ -55,15 +51,15 @@ export class LRUCache {
|
|
|
55
51
|
*/
|
|
56
52
|
set(key, value) {
|
|
57
53
|
// If key exists, delete first to update position
|
|
58
|
-
if (this
|
|
59
|
-
this
|
|
60
|
-
} else if (this
|
|
54
|
+
if (this._cache.has(key)) {
|
|
55
|
+
this._cache.delete(key);
|
|
56
|
+
} else if (this._cache.size >= this._capacity) {
|
|
61
57
|
// Remove oldest (first item in Map)
|
|
62
|
-
const oldest = this
|
|
63
|
-
this
|
|
58
|
+
const oldest = this._cache.keys().next().value;
|
|
59
|
+
this._cache.delete(oldest);
|
|
64
60
|
}
|
|
65
61
|
|
|
66
|
-
this
|
|
62
|
+
this._cache.set(key, value);
|
|
67
63
|
return this;
|
|
68
64
|
}
|
|
69
65
|
|
|
@@ -74,7 +70,7 @@ export class LRUCache {
|
|
|
74
70
|
* @returns {boolean} True if key exists
|
|
75
71
|
*/
|
|
76
72
|
has(key) {
|
|
77
|
-
return this
|
|
73
|
+
return this._cache.has(key);
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
/**
|
|
@@ -83,14 +79,14 @@ export class LRUCache {
|
|
|
83
79
|
* @returns {boolean} True if item was deleted
|
|
84
80
|
*/
|
|
85
81
|
delete(key) {
|
|
86
|
-
return this
|
|
82
|
+
return this._cache.delete(key);
|
|
87
83
|
}
|
|
88
84
|
|
|
89
85
|
/**
|
|
90
86
|
* Clear all items from the cache
|
|
91
87
|
*/
|
|
92
88
|
clear() {
|
|
93
|
-
this
|
|
89
|
+
this._cache.clear();
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
/**
|
|
@@ -98,7 +94,7 @@ export class LRUCache {
|
|
|
98
94
|
* @returns {number} Current size
|
|
99
95
|
*/
|
|
100
96
|
get size() {
|
|
101
|
-
return this
|
|
97
|
+
return this._cache.size;
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
/**
|
|
@@ -106,7 +102,7 @@ export class LRUCache {
|
|
|
106
102
|
* @returns {number} Maximum capacity
|
|
107
103
|
*/
|
|
108
104
|
get capacity() {
|
|
109
|
-
return this
|
|
105
|
+
return this._capacity;
|
|
110
106
|
}
|
|
111
107
|
|
|
112
108
|
/**
|
|
@@ -114,7 +110,7 @@ export class LRUCache {
|
|
|
114
110
|
* @returns {IterableIterator<K>} Iterator of keys
|
|
115
111
|
*/
|
|
116
112
|
keys() {
|
|
117
|
-
return this
|
|
113
|
+
return this._cache.keys();
|
|
118
114
|
}
|
|
119
115
|
|
|
120
116
|
/**
|
|
@@ -122,7 +118,7 @@ export class LRUCache {
|
|
|
122
118
|
* @returns {IterableIterator<V>} Iterator of values
|
|
123
119
|
*/
|
|
124
120
|
values() {
|
|
125
|
-
return this
|
|
121
|
+
return this._cache.values();
|
|
126
122
|
}
|
|
127
123
|
|
|
128
124
|
/**
|
|
@@ -130,7 +126,7 @@ export class LRUCache {
|
|
|
130
126
|
* @returns {IterableIterator<[K, V]>} Iterator of [key, value] pairs
|
|
131
127
|
*/
|
|
132
128
|
entries() {
|
|
133
|
-
return this
|
|
129
|
+
return this._cache.entries();
|
|
134
130
|
}
|
|
135
131
|
|
|
136
132
|
/**
|
|
@@ -138,7 +134,7 @@ export class LRUCache {
|
|
|
138
134
|
* @param {function(V, K, LRUCache): void} callback - Called for each entry
|
|
139
135
|
*/
|
|
140
136
|
forEach(callback) {
|
|
141
|
-
this
|
|
137
|
+
this._cache.forEach((value, key) => callback(value, key, this));
|
|
142
138
|
}
|
|
143
139
|
}
|
|
144
140
|
|
package/runtime/utils.js
CHANGED
|
@@ -191,9 +191,9 @@ export function sanitizeUrl(url, options = {}) {
|
|
|
191
191
|
return null;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
// Check for data: protocol
|
|
195
|
-
if (
|
|
196
|
-
return null;
|
|
194
|
+
// Check for data: protocol
|
|
195
|
+
if (lowerUrl.startsWith('data:')) {
|
|
196
|
+
return allowData ? trimmed : null;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
// Allow relative URLs
|