solarite 0.5.2 → 0.7.0

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 +2823 -1856
  3. package/dist/Solarite.js +2779 -1824
  4. package/dist/Solarite.min.js +2 -4
  5. package/package.json +16 -3
  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,98 +0,0 @@
1
-
2
-
3
-
4
- /**
5
- * An array that keeps track of how many elements are in-use.
6
- * In-use elements are always at the beginning of the array. */
7
- export class InUseArray extends Array {
8
-
9
- /**
10
- * @type {int} Everything before this number is in-use. */
11
- count = 0;
12
-
13
-
14
- /**
15
- * Get a value and mark it as in-use.
16
- * @param val {undefined|*} Optional. If set, find this specific value. Otherwise find any value.
17
- * @return {undefined|*} The value that is now marked as in-use. */
18
- use(val=undefined) {
19
- if (val) {
20
- // If val doesn't exist or is already in-use, return undefined.
21
- let index = this.indexOf(val);
22
- if (index === -1 || index < this.count)
23
- return undefined;
24
-
25
- // Swap the first available with val.
26
- this[index] = this[this.count];
27
- this[this.count] = val;
28
- this.count++;
29
- return val;
30
- }
31
-
32
- // Try to get last available.
33
- else {
34
- if (this.count >= this.length)
35
- return undefined;
36
- let result = this[this.count];
37
- this.count++;
38
- return result;
39
- }
40
- }
41
-
42
- free() {
43
- this.count = 0;
44
- }
45
-
46
- reset() {
47
- this.length = 0;
48
- }
49
- }
50
-
51
- /**
52
- *
53
- */
54
- export class InUseMap {
55
-
56
- /** @type {Object<string, InUseArray>} */
57
- data = {};
58
-
59
- // Set a new value for a key
60
- add(key, value) {
61
- let data = this.data;
62
- let array = data[key]
63
- if (!array) {
64
- array = new InUseArray();
65
- data[key] = array;
66
- }
67
- array.push(value);
68
- }
69
-
70
- // Get all values for a key
71
- getAll(key) {
72
- return this.data[key] || [];
73
- }
74
-
75
- // Find a value matching the given key, mark it as inUse, and return it.
76
- use(key, val=undefined) {
77
- return this.data[key]?.use(val) || undefined
78
- }
79
-
80
- // temporary
81
- delete(key, val=undefined) {
82
- return this.data[key]?.use(val) || undefined
83
- }
84
-
85
- freeAll() {
86
- for (let key in this.data)
87
- this.data[key].free();
88
- }
89
-
90
- hasValue(val) {
91
- let data = this.data;
92
- let names = [];
93
- for (let name in data)
94
- if (data[name].includes(val))
95
- names.push(name)
96
- return names;
97
- }
98
- }
@@ -1,117 +0,0 @@
1
- export default class LinkedList {
2
-
3
- constructor(input) {
4
- this.head = null;
5
- this.tail = null;
6
- this.map = new Map();
7
-
8
- if (Array.isArray(input)) {
9
- input.forEach(val => this.push(val));
10
- } else if (input instanceof LinkedList) {
11
- for (let val of input) {
12
- this.push(val);
13
- }
14
- }
15
- }
16
-
17
- push(value) {
18
- if (!this.head) {
19
- this.head = value;
20
- this.tail = value;
21
- return;
22
- }
23
-
24
- this.map.set(value, { prev: this.tail, next: null });
25
- this.map.set(this.tail, { ...this.map.get(this.tail), next: value });
26
- this.tail = value;
27
- }
28
-
29
- unshift(value) {
30
- if (!this.head) {
31
- this.push(value);
32
- return;
33
- }
34
-
35
- this.map.set(value, { prev: null, next: this.head });
36
- this.map.set(this.head, { ...this.map.get(this.head), prev: value });
37
- this.head = value;
38
- }
39
-
40
- shift() {
41
- if (!this.head) return;
42
-
43
- const secondNode = this.map.get(this.head).next;
44
-
45
- if (secondNode) {
46
- this.map.set(secondNode, { ...this.map.get(secondNode), prev: null });
47
- } else {
48
- this.tail = null;
49
- }
50
-
51
- this.head = secondNode;
52
- }
53
-
54
- pop() {
55
- if (!this.tail) return;
56
-
57
- const penultimate = this.map.get(this.tail).prev;
58
-
59
- if (penultimate) {
60
- this.map.set(penultimate, { ...this.map.get(penultimate), next: null });
61
- } else {
62
- this.head = null;
63
- }
64
-
65
- this.tail = penultimate;
66
- }
67
-
68
- *[Symbol.iterator]() {
69
- let currentNode = this.head;
70
-
71
- while (currentNode) {
72
- yield currentNode;
73
- const mapData = this.map.get(currentNode);
74
- currentNode = mapData ? mapData.next : null;
75
- }
76
- }
77
-
78
- slice(start, end) {
79
- const newList = new LinkedList();
80
- let currentNode = start;
81
-
82
- while (currentNode && currentNode !== end) {
83
- newList.push(currentNode);
84
- currentNode = this.map.get(currentNode).next;
85
- }
86
- if (end) {
87
- newList.push(end);
88
- }
89
-
90
- return newList;
91
- }
92
-
93
-
94
- splice(start, end, newList) {
95
- // TODO: assert items in newList aren't already in our list.
96
-
97
- const firstNewNode = newList instanceof LinkedList ? newList.head : newList[0];
98
- const lastNewNode = newList instanceof LinkedList ? newList.tail : newList[newList.length - 1];
99
-
100
- if (firstNewNode) {
101
- this.map.set(start, { ...this.map.get(start), next: firstNewNode });
102
- this.map.set(firstNewNode, { ...this.map.get(firstNewNode), prev: start });
103
- }
104
-
105
- const afterEnd = end ? this.map.get(end).next : null;
106
- if (lastNewNode) {
107
- this.map.set(lastNewNode, { ...this.map.get(lastNewNode), next: afterEnd });
108
- if (afterEnd) {
109
- this.map.set(afterEnd, { ...this.map.get(afterEnd), prev: lastNewNode });
110
- } else {
111
- this.tail = lastNewNode;
112
- }
113
- } else if (afterEnd) {
114
- this.map.set(afterEnd, { ...this.map.get(afterEnd), prev: start });
115
- }
116
- }
117
- }
@@ -1,115 +0,0 @@
1
- import Testimony, {assert} from "../../tests/Testimony.js";
2
- import LinkedList from "./LinkedList.js";
3
-
4
- Testimony.test('LinkedList.constructor with Array input', () => {
5
- const linkedList = new LinkedList(['A', 'B', 'C']);
6
- assert.eq([...linkedList], ['A', 'B', 'C']);
7
- });
8
-
9
- Testimony.test('LinkedList.constructor with LinkedList input', () => {
10
- const originalList = new LinkedList(['X', 'Y', 'Z']);
11
- const copiedList = new LinkedList(originalList);
12
- assert.eq([...copiedList], ['X', 'Y', 'Z']);
13
- });
14
-
15
- Testimony.test('LinkedList.constructor with mixed input', () => {
16
- const originalList = new LinkedList(['D', 'E']);
17
- const extendedList = new LinkedList([...originalList, 'F', 'G']);
18
- assert.eq([...extendedList], ['D', 'E', 'F', 'G']);
19
- });
20
-
21
- Testimony.test('LinkedList.constructor with no input', () => {
22
- const emptyList = new LinkedList();
23
- assert.eq([...emptyList], []);
24
- });
25
-
26
-
27
- Testimony.test('LinkedList.push', () => {
28
- const linkedList = new LinkedList();
29
- linkedList.push("A");
30
- linkedList.push("B");
31
- assert.eq([...linkedList], ['A', 'B']);
32
- });
33
-
34
- Testimony.test('LinkedList.unshift', () => {
35
- const linkedList = new LinkedList();
36
- linkedList.unshift("B");
37
- linkedList.unshift("A");
38
- assert.eq([...linkedList], ['A', 'B']);
39
- });
40
-
41
- Testimony.test('LinkedList.shift', () => {
42
- const linkedList = new LinkedList();
43
- linkedList.push("A");
44
- linkedList.push("B");
45
- linkedList.shift();
46
- assert.eq([...linkedList], ['B']);
47
- linkedList.shift();
48
- assert.eq([...linkedList], []);
49
- });
50
-
51
- Testimony.test('LinkedList.pop', () => {
52
- const linkedList = new LinkedList();
53
- linkedList.push("A");
54
- linkedList.push("B");
55
- linkedList.pop();
56
- assert.eq([...linkedList], ['A']);
57
- linkedList.pop();
58
- assert.eq([...linkedList], []);
59
- });
60
-
61
- Testimony.test('LinkedList.slice', () => {
62
- const linkedList = new LinkedList();
63
- linkedList.push("A");
64
- linkedList.push("B");
65
- linkedList.push("C");
66
- const subList = linkedList.slice("A", "B");
67
- assert.eq([...subList], ['A', 'B']);
68
- });
69
-
70
- Testimony.test('LinkedList._splice', () => {
71
- const linkedList = new LinkedList();
72
- linkedList.push("A");
73
- linkedList.push("B");
74
- linkedList.splice("A", null, ["X", "Y"]);
75
- assert.eq([...linkedList], ['A', 'X', 'Y', 'B']);
76
- linkedList.splice("X", "Y");
77
- assert.eq([...linkedList], ['B']);
78
- });
79
-
80
-
81
-
82
-
83
- function buildData(count = rowCount) {
84
- function _random(max) {
85
- return Math.round(Math.random()*1000)%max;
86
- }
87
-
88
- var adjectives = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"];
89
- var colours = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
90
- var nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"];
91
- var data = [];
92
- for (let i=0; i<count; i++)
93
- data.push({id: i, label: adjectives[_random(adjectives.length)] + " " + colours[_random(colours.length)] + " " + nouns[_random(nouns.length)] });
94
- return data;
95
- }
96
-
97
-
98
- Testimony.test('LinkedList.benchmark', () => {
99
-
100
- let data = buildData(10_000)
101
- let start = performance.now()
102
- let list = new LinkedList(data);
103
- console.log(performance.now() - start)
104
-
105
- start = performance.now()
106
- let i = 0;
107
- for (let item in list) {
108
- i++;
109
- }
110
- console.log(i)
111
- console.log(performance.now() - start)
112
-
113
-
114
-
115
- });
@@ -1,13 +0,0 @@
1
- var Misc = {
2
- weakMemoize(obj, callback) {
3
- let result = weakMemoizeInputs.get(obj);
4
- if (!result) {
5
- result = callback(obj);
6
- weakMemoizeInputs.set(obj, result);
7
- }
8
- return result;
9
- }
10
- };
11
-
12
-
13
- let weakMemoizeInputs = new WeakMap();
@@ -1,47 +0,0 @@
1
- var Perf = {
2
- _timers: {},
3
-
4
- /**
5
- * Start a timer with a given name.
6
- * @param timerName {string}
7
- */
8
- start(timerName) {
9
- if (!Perf._timers[timerName]) {
10
- Perf._timers[timerName] = {
11
- startTime: null,
12
- elapsedTime: 0
13
- };
14
- }
15
- Perf._timers[timerName].startTime = performance.now();
16
- },
17
-
18
- /**
19
- * Stop a timer with a given name and calculate the elapsed time.
20
- * @param timerName {string}
21
- */
22
- stop(timerName) {
23
- if (Perf._timers[timerName] && Perf._timers[timerName].startTime !== null) {
24
- let stopTime = performance.now();
25
- Perf._timers[timerName].elapsedTime += stopTime - Perf._timers[timerName].startTime;
26
- Perf._timers[timerName].startTime = null; // Reset start time
27
- }
28
- },
29
-
30
- /**
31
- * Get the total time elapsed for each timer.
32
- * @return {string[]}
33
- */
34
- getReport() {
35
- let report = [];
36
- for (let timerName in Perf._timers) {
37
- report.push(`${timerName}: ${Perf._timers[timerName].elapsedTime.toFixed(2)} ms`);
38
- }
39
- return report;
40
- },
41
-
42
- clear() {
43
- this._timers = {};
44
- }
45
- }
46
-
47
- export default Perf;
@@ -1,54 +0,0 @@
1
-
2
- export default class TrackedArray extends Array {
3
- constructor(...args) {
4
- super(...args);
5
- this.ops = [];
6
- }
7
-
8
- // Intercepting 'push' as 'insert'
9
- push(...items) {
10
- const startIdx = this.length;
11
- super.push(...items);
12
- this.ops.push({ op: 'insert', index: startIdx, values: items });
13
- return this.length;
14
- }
15
-
16
- // Intercepting 'pop' as 'remove'
17
- pop() {
18
- const removedIndex = this.length - 1;
19
- const removedItem = super.pop();
20
- this.ops.push({ op: 'remove', index: removedIndex, length: 1 });
21
- return removedItem;
22
- }
23
-
24
- // Intercepting 'shift' as 'remove'
25
- shift() {
26
- const removedItem = super.shift();
27
- this.ops.push({ op: 'remove', index: 0, length: 1 });
28
- return removedItem;
29
- }
30
-
31
- // Intercepting 'unshift' as 'insert'
32
- unshift(...items) {
33
- super.unshift(...items);
34
- this.ops.push({ op: 'insert', index: 0, values: items });
35
- return this.length;
36
- }
37
-
38
- // Intercepting 'splice' for insert, update, or remove
39
- splice(start, deleteCount, ...items) {
40
- const removedItems = super.splice(start, deleteCount, ...items);
41
-
42
- if (deleteCount > 0) {
43
- this.ops.push({ op: 'remove', index: start, length: deleteCount });
44
- }
45
- if (items.length > 0) {
46
- const operation = deleteCount > 0 ? 'update' : 'insert';
47
- this.ops.push({ op, index: start, values: items });
48
- }
49
-
50
- return removedItems;
51
- }
52
-
53
- // TODO: reverse, sorty, copyWithin, fill
54
- }
@@ -1,33 +0,0 @@
1
- export default class WeakArray {
2
- constructor() {
3
- this.items = [];
4
- }
5
-
6
- push(...items) {
7
- for (let item of items) {
8
- if (typeof item === 'object' && item)
9
- this.items.push(new WeakRef(item));
10
- else
11
- throw new TypeError("Only objects can be added to a WeakArray");
12
- }
13
- }
14
-
15
- get(index) {
16
- const ref = this.items[index];
17
- if (ref)
18
- return ref.deref();
19
- return undefined;
20
- }
21
-
22
- cleanup() {
23
- this.items = this.items.filter(ref => ref.deref() !== undefined);
24
- }
25
-
26
- *[Symbol.iterator]() {
27
- for (const ref of this.items) {
28
- const value = ref.deref();
29
- if (value !== undefined)
30
- yield value;
31
- }
32
- }
33
- }