solarite 0.5.2 → 0.7.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Solarite-debug.js +4847 -3878
  3. package/dist/Solarite.js +4583 -3626
  4. package/dist/Solarite.min.js +2 -4
  5. package/package.json +19 -6
  6. package/readme.md +58 -11
  7. package/src/Globals.js +54 -72
  8. package/src/HtmlParser.js +90 -90
  9. package/src/MultiValueMap.js +57 -105
  10. package/src/NodeGroup.js +624 -470
  11. package/src/Path.js +224 -211
  12. package/src/PathToAttribValue.js +401 -261
  13. package/src/PathToAttribs.js +113 -80
  14. package/src/PathToComment.js +7 -7
  15. package/src/PathToComponent.js +183 -188
  16. package/src/PathToEvent.js +76 -64
  17. package/src/PathToKey.js +19 -0
  18. package/src/PathToNodes.js +1053 -566
  19. package/src/RootNodeGroup.js +120 -8
  20. package/src/Shell.js +570 -348
  21. package/src/Solarite.d.ts +134 -113
  22. package/src/Solarite.js +243 -286
  23. package/src/Template.js +195 -274
  24. package/src/Util.js +353 -351
  25. package/src/assert.js +10 -10
  26. package/src/assignAttributes.js +63 -0
  27. package/src/delve.js +55 -43
  28. package/src/h.js +220 -138
  29. package/src/jsx-dev-runtime.d.ts +1 -0
  30. package/src/jsx-dev-runtime.js +5 -0
  31. package/src/jsx-runtime.d.ts +21 -0
  32. package/src/jsx-runtime.js +84 -0
  33. package/src/jsx.js +194 -0
  34. package/src/toEl.js +77 -82
  35. package/dist/udomdiff-license.txt +0 -18
  36. package/src/getArg.js +0 -137
  37. package/src/hash.js +0 -89
  38. package/src/udomdiff.js +0 -176
  39. package/src/unused/FastLookupArray.js +0 -54
  40. package/src/unused/Hashes.js +0 -339
  41. package/src/unused/InUse.test.js +0 -92
  42. package/src/unused/InUseMap.js +0 -98
  43. package/src/unused/LinkedList.js +0 -117
  44. package/src/unused/LinkedList.test.js +0 -115
  45. package/src/unused/Misc.js +0 -13
  46. package/src/unused/Perf.js +0 -47
  47. package/src/unused/TrackedArray.js +0 -54
  48. package/src/unused/WeakArray.js +0 -33
  49. package/src/watch.js +0 -543
@@ -1,105 +1,57 @@
1
- export default class MultiValueMap {
2
-
3
- /** @type {Record<string, Set>} */
4
- data = {};
5
-
6
- // Set a new value for a key
7
- add(key, value) {
8
- let data = this.data;
9
- let set = data[key]
10
- if (!set) {
11
- set = new Set();
12
- data[key] = set;
13
- }
14
- set.add(value);
15
- }
16
-
17
- isEmpty() {
18
- for (let key in this.data)
19
- return true;
20
- return false;
21
- }
22
-
23
- /**
24
- * Get all values for a key.
25
- * @param key {string}
26
- * @returns {Set|*[]} */
27
- getAll(key) {
28
- return this.data[key] || [];
29
- }
30
-
31
- /**
32
- * Remove one value from a key, and return it.
33
- * @param key {string}
34
- * @param val If specified, make sure we delete this specific value, if a key exists more than once.
35
- * @returns {*|undefined} The deleted item. */
36
- delete(key, val=undefined) {
37
- let data = this.data;
38
- let result;
39
- let set = data[key];
40
- if (!set)
41
- return undefined;
42
-
43
- // Delete any value.
44
- if (val === undefined) {
45
- [result] = set; // Get the first value from the set.
46
- set.delete(result);
47
- }
48
-
49
- // Delete a specific value.
50
- else {
51
- set.delete(val);
52
- result = val;
53
- }
54
-
55
- if (set.size === 0)
56
- delete data[key];
57
-
58
- return result;
59
- }
60
-
61
- /**
62
- * Remove any one value from a key, and return it.
63
- * @param key {string}
64
- * @returns {*|undefined} The deleted item. */
65
- deleteAny(key) {
66
- let data = this.data;
67
- let result;
68
- let set = data[key];
69
- if (!set) // slower than pre-check.
70
- return undefined;
71
-
72
- [result] = set; // Get the first value from the set.
73
- set.delete(result);
74
-
75
- if (set.size === 0)
76
- delete data[key];
77
-
78
- return result;
79
- }
80
-
81
- deleteSpecific(key, val) {
82
- let data = this.data;
83
- let result;
84
- let set = data[key];
85
- if (!set)
86
- return undefined;
87
-
88
- set.delete(val);
89
- result = val;
90
-
91
- if (set.size === 0)
92
- delete data[key];
93
-
94
- return result;
95
- }
96
-
97
- hasValue(val) {
98
- let data = this.data;
99
- let names = [];
100
- for (let name in data)
101
- if (data[name].has(val)) // TODO: iterate twice to pre-size array?
102
- names.push(name)
103
- return names;
104
- }
105
- }
1
+ /**
2
+ * Maps a string key to multiple values.
3
+ * Values are stored in arrays because pushing them is much faster than Set operations,
4
+ * and deleteAny() needs no iterator allocation.
5
+ * deleteAny() returns values first-in-first-out by advancing a head index (array.head)
6
+ * instead of calling shift(), which would be O(n). */
7
+ export default class MultiValueMap {
8
+
9
+ /** @type {Record<string, Array>} */
10
+ data = {};
11
+
12
+ // Add a new value for a key
13
+ add(key, value) {
14
+ let data = this.data;
15
+ let array = data[key]
16
+ if (!array)
17
+ data[key] = [value];
18
+ else
19
+ array.push(value);
20
+ }
21
+
22
+ /**
23
+ * Add a new value for a key, unless the key already holds max values.
24
+ * Used to bound pooled NodeGroup memory.
25
+ * @param key {string}
26
+ * @param value
27
+ * @param max {int} */
28
+ addCapped(key, value, max) {
29
+ let data = this.data;
30
+ let array = data[key]
31
+ if (!array)
32
+ data[key] = [value];
33
+ else if (array.length - (array.head || 0) < max)
34
+ array.push(value);
35
+ }
36
+
37
+ /**
38
+ * Remove the oldest value from a key, and return it.
39
+ * @param key {string}
40
+ * @returns {*|undefined} The deleted item. */
41
+ deleteAny(key) {
42
+ let data = this.data;
43
+ let array = data[key];
44
+ if (!array) // slower than pre-check.
45
+ return undefined;
46
+
47
+ let head = array.head || 0;
48
+ let result = array[head];
49
+ head++;
50
+ if (head >= array.length)
51
+ delete data[key];
52
+ else
53
+ array.head = head;
54
+
55
+ return result;
56
+ }
57
+ }