solarite 0.2.0 → 0.2.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 (38) hide show
  1. package/package.json +6 -5
  2. package/benchmarks/naive/Solarite.min.js +0 -4
  3. package/benchmarks/naive/index.html +0 -14
  4. package/benchmarks/naive/main.js +0 -339
  5. package/benchmarks/naive/package-lock.json +0 -13
  6. package/benchmarks/naive/package.json +0 -23
  7. package/benchmarks/readme.md +0 -48
  8. package/build/build.bat +0 -4
  9. package/build/build.js +0 -139
  10. package/build/lib/rollup.min.js +0 -11
  11. package/build/lib/source-map.min.js +0 -1
  12. package/build/lib/terser.min.js +0 -1
  13. package/docs/index.md +0 -883
  14. package/docs/js/Playground.js +0 -184
  15. package/docs/js/codemirror/codemirror6.js +0 -32513
  16. package/docs/js/codemirror/themeSolarIce.js +0 -312
  17. package/docs/js/documentation.js +0 -32
  18. package/docs/js/ui/CodeEditor.js +0 -978
  19. package/docs/js/ui/DarkToggle.js +0 -52
  20. package/docs/js/ui/FlexResizer.js +0 -152
  21. package/docs/js/util/Draggable2.js +0 -151
  22. package/docs/js/util/Errors.js +0 -20
  23. package/docs/js/util/Html.js +0 -147
  24. package/docs/js/util/Icons.js +0 -623
  25. package/docs/js/util/Input.js +0 -253
  26. package/docs/js/util/Util.js +0 -88
  27. package/docs/js/util/delve.js +0 -43
  28. package/docs/media/FiraCode400.woff2 +0 -0
  29. package/docs/media/cabin-latin-700.woff2 +0 -0
  30. package/docs/media/documentation.css +0 -96
  31. package/docs/media/eternium.css +0 -1123
  32. package/docs/media/solarite-machine.webp +0 -0
  33. package/index.html +0 -761
  34. package/tests/Benchmark.test.js +0 -319
  35. package/tests/Solarite.test.js +0 -3838
  36. package/tests/Testimony.js +0 -809
  37. package/tests/index.html +0 -46
  38. package/tests/run.bat +0 -2
@@ -1,253 +0,0 @@
1
- import Html from "./Html.js";
2
-
3
-
4
- var keys = {
5
- specialKeys: {
6
- 8: "backspace", 9: "tab", 10: "return", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause",
7
- 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home",
8
- 37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del", 59: ";", 61: "=",
9
- 96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7",
10
- 104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/",
11
- 112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8",
12
- 120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 173: "-", 186: ";", 187: "=",
13
- 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'"
14
- },
15
- shiftNums: {
16
- "`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&",
17
- "8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<",
18
- ".": ">", "/": "?", "\\": "|"
19
- },
20
-
21
- nonEditing: ['ctrl', 'alt', 'shift', 'capslock', 'numlock', 'esc',
22
- 'up', 'down', 'left', 'right', 'home', 'end', 'insert', 'pageup', 'pagedown', 'scroll', 'pause',
23
- 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12',
24
- 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f20', 'f21', 'f22', 'f23', 'f24']
25
- };
26
-
27
- var Input = {
28
-
29
- /**
30
- * Write the text to the clipboard.
31
- * @param text {string} */
32
- copyText(text) {
33
- let input = document.createElement('textarea');
34
- input.style.width = 0;
35
- input.innerHTML = text;
36
- document.body.appendChild(input);
37
- input.select();
38
- let result = document.execCommand('copy');
39
- document.body.removeChild(input);
40
- return result;
41
- },
42
-
43
- /**
44
- * Force the element to have focus so it can receive keyboard and paste events.
45
- * calling .focus() on it isn't enough.
46
- * @param el {HTMLElement} Must have a tabindex property. */
47
- forceFocus(el) {
48
- let input = el.ownerDocument.createElement('input');
49
- input.style.height = '0';
50
- input.style.width = '0';
51
- el.append(input);
52
- input.focus();
53
- el.focus();
54
- input.remove()
55
- },
56
-
57
-
58
- /**
59
- * Is the KeyboardEvent something that will produce text input?
60
- * @param e {KeyboardEvent}
61
- * @return {boolean} */
62
- isInput(e) {
63
- if (e.ctrlKey || e.altKey || e.metaKey) // we allow shift b/c it's for capital letters.
64
- return false;
65
-
66
- return !this.isKey(e, keys.nonEditing) && e.key?.length === 1; // Filter out other keys like 'MediaPlay'
67
- },
68
-
69
- /**
70
- * @example Hotkey.is(e, ['ctrl+y', 'ctrl+z']); // returns true if it's one of these events.
71
- * @param e {KeyboardEvent}
72
- * @param types {string|string[]}
73
- * @param ignoreModifierKeys {boolean=false}
74
- * @return {boolean} */
75
- isKey(e, types, ignoreModifierKeys) {
76
- //#IFDEV
77
- if (!types)
78
- throw new Error('Missing types argument');
79
- //#ENDIF
80
- if (!Array.isArray(types))
81
- types = [types];
82
-
83
- var special = keys.specialKeys[e.keyCode],
84
- character = String.fromCharCode(e.which).toLowerCase(),
85
- modif = '', possible = {};
86
-
87
- for (let specialKey of [ "alt", "ctrl", "meta", "shift" ]) {
88
- if (e[specialKey + 'Key'] && special !== specialKey)
89
- modif += specialKey + '+';
90
- }
91
- modif = modif.replace('alt+ctrl+meta+shift', 'hyper');
92
- if (special) {
93
- possible[ modif + special ] = true;
94
- if (special === 'return')
95
- possible[modif + 'enter'] = true;
96
- if (ignoreModifierKeys) {
97
- possible[special] = true;
98
- if (special === 'return')
99
- possible['enter'] = true;
100
- }
101
- }
102
-
103
- if (character) {
104
- possible[modif + character] = true;
105
- if (ignoreModifierKeys)
106
- possible[character] = true;
107
- possible[modif + keys.shiftNums[character]] = true;
108
- if (ignoreModifierKeys)
109
- possible[ keys.shiftNums[character]] = true;
110
-
111
- // "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
112
- if (modif === 'shift+')
113
- possible[ keys.shiftNums[character]] = true;
114
- }
115
- for (var i=0, l=types.length; i<l; i++)
116
- if (possible[types[i]])
117
- return true;
118
-
119
- return false;
120
- },
121
-
122
- /**
123
- * @deprecated for Util.on()
124
- * Add a filtered event listener and return a function to remove that listener.
125
- * Supports {once: true} as an option.
126
- * Then move this outside of Input?
127
- * @param div {HTMLElement}
128
- * @param type {string}
129
- * @param key {null|string|function(Event)}
130
- * If a string and a KeyboardEvent, only if the event matches this key.
131
- * If a function, only if the function returns true when called with an event of any type.
132
- * @param callback {function(Event)|Object|boolean}
133
- * @param options {Object|boolean=} Can include {once: true}
134
- * @return {function} Call this function to unbind. */
135
- on(div, type, key=null, callback, options) {
136
-
137
- // We handle "once" ourselves.
138
- let once = options?.once;
139
- if (once)
140
- delete options.once;
141
-
142
- let internalCallback = e => {
143
- if (!key || (e instanceof KeyboardEvent && e.key === key || Input.isKey(e, key)) || (typeof key === 'function' && key(e))) {
144
- callback(e);
145
- if (once)
146
- div.removeEventListener(type, internalCallback, options);
147
- }
148
- };
149
- div.addEventListener(type, internalCallback, options);
150
-
151
- return () => div.removeEventListener(type, internalCallback, options);
152
- },
153
-
154
- /**
155
- * Restrict each typed letter to the pattern Regex.
156
- * Also see Input.pasteAsPlainText() which is often used along with this function.
157
- * @param {KeyboardEvent|Node} event
158
- * @param {RegExp} allowed
159
- * @example
160
- * <input onkeydown="Input.limitKeys(event, /[A-Za-z_0-9]/)"> */
161
- limitKeys(event, allowed) {
162
- if (event instanceof Node)
163
- event.addEventListener('keydown', e=>Input.limitKeys(e, allowed));
164
- else {
165
- // Allow ctrl+a, ctrl+c, etc.
166
- if (event.ctrlKey)
167
- return true;
168
-
169
-
170
- // Always allow keycodes that don't insert characters
171
- var k = event.keyCode;
172
-
173
- // Allow keys that don't add a character:
174
- // all keycodes listed here: https://github.com/wesbos/keycodes/blob/gh-pages/scripts.js
175
- if ((k < 48 && ![9, 12, 13, 32].includes(k)) || // all of the lower keycodes except tab, enter, space
176
- [91, 92, 93, 95,].includes(k) || // left windows/⌘ key, right windows key, windows menu, sleep
177
- (112 <= k && k <= 151) || // F1-F32, numlock, scroll-lock, airplane mode
178
- [166, 167, 168, 169].includes(k) || // page back, page forward, refresh
179
- (172 <= k && k <= 183) || // home key, media keys
180
- [224, 230, 233, 234, 251, 255].includes(k) // ⌘ key firefox, gnome compose key, XF86 Forwared, XF86 Back, unlock trackpad, toggle touchpad.
181
- )
182
- return true;
183
-
184
- //console.log(String.fromCharCode(event.keyCode));
185
- // We use event.key because String.fromCharCode(event.keyCode) will return '4' for '$' and other keys entered through modifiers.
186
- let key = event.key;
187
- if (key === 'Enter') // Why does "Enter" appear as text instead of the literal '\n' ?
188
- key = '\n';
189
- if (!allowed.test(key)) {
190
- event.preventDefault();
191
- return false;
192
- }
193
-
194
- return true;
195
- }
196
- },
197
-
198
- /**
199
- * Also see Input.limitKeys() which is often used along with this function.
200
- *
201
- * @param item {ClipboardEvent|Event|Node} If a node, a paste event listener will be assigned to it.
202
- * Otherwise, insert clipboard data from the paste event to the element that has focus.
203
- * @param allowLn
204
- * @param allowed {?RegExp} If set, only allow characters that match this regex. Must be a global /g regex.
205
- *
206
- * @example
207
- * <div contenteditable onpaste="Input.pasteAsPlainText(event)">
208
- *
209
- * @example
210
- * Input.pasteAsPlainText(document.getElementById('notes')); */
211
- pasteAsPlainText(item, allowLn=true, allowed=null) {
212
- if (item instanceof Node)
213
- item.addEventListener('paste', e=> Input.pasteAsPlainText(e, allowLn));
214
-
215
- else {
216
- let event = item;
217
- event.preventDefault();
218
- let text = (event.originalEvent || event).clipboardData.getData('text/plain');
219
- text = Html.encode(text);
220
- if (allowed) {
221
- let copy = '';
222
- text.replaceAll(allowed, match => {
223
- copy += match
224
- });
225
- text = copy;
226
- }
227
-
228
- if (allowLn)
229
- text = text.replace(/\r?\n/g, '<br>');
230
-
231
- // The target element already has focus, so the command puts the text there.
232
- document.execCommand("insertHTML", false, text);
233
- return false;
234
- }
235
- },
236
-
237
- /**
238
- * Select all the text in an element.
239
- * @param el {HTMLElement|HTMLInputElement} */
240
- selectAll(el) {
241
- if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA')
242
- el.select();
243
- else {
244
- let range = document.createRange();
245
- range.selectNodeContents(el);
246
- let sel = window.getSelection();
247
- sel.removeAllRanges();
248
- sel.addRange(range);
249
- }
250
- }
251
- };
252
-
253
- export default Input;
@@ -1,88 +0,0 @@
1
-
2
-
3
-
4
- /**
5
- * @typedef {Array|function(...*)} Callbacks
6
- * @property {function(function)} push
7
- * @property {function()} remove
8
- * @property {function()} pause
9
- * @property {function()} resume
10
- * */
11
-
12
-
13
- /**
14
- * A place for functions that have no other home. */
15
- var Util = {
16
-
17
- /**
18
- * Create an array-like object that stores a group of callbacks.
19
- * Supports all array functions and properties like push() and .length.
20
- * Can be called directly.
21
- *
22
- * @param functions {function[]}
23
- * @return {Callbacks|function}
24
- *
25
- * @example
26
- * var c = Util.callback();
27
- * var f = () => console.log(3);
28
- * c.push(f);
29
- * c();
30
- * c.remove(f);
31
- * c();
32
- */
33
- callback(...functions) {
34
- var paused = false;
35
-
36
- // Make it callable. When we call it, call all callbacks() with the given args.
37
- let result = async function(...args) {
38
- let result2 = [];
39
- if (!paused)
40
- for (let i=0; i<result.length; i++)
41
- result2.push(result[i](...args));
42
- return await Promise.all(result2);
43
- };
44
-
45
- // Make it iterable.
46
- result[Symbol.iterator] = function() {
47
- let index = 0;
48
- return {
49
- next: () => index < result.length
50
- ? {value: result[index++], done: false}
51
- : {done: true}
52
- };
53
- };
54
-
55
- // Use properties from Array
56
- for (let prop of Object.getOwnPropertyNames(Array.prototype))
57
- if (prop !== 'length' && prop !== 'constructor')
58
- result[prop] = Array.prototype[prop];
59
-
60
- result.l = 0; // Internal length
61
- Object.defineProperty(result, 'length', {
62
- get() { return result.l },
63
- set(val) { result.l = val}
64
- });
65
-
66
- // Add the remove() function.
67
- result.remove = func => {
68
- let idx = result.findIndex(item => item === func);
69
- if (idx !== -1)
70
- result.splice(idx, 1);
71
- };
72
- result.pause = () => paused = true;
73
-
74
- result.resume = () => paused = false;
75
-
76
- // Add initial functions
77
- for (let f of functions)
78
- result.push(f);
79
-
80
- return result;
81
- },
82
-
83
-
84
-
85
- };
86
-
87
-
88
- export default Util;
@@ -1,43 +0,0 @@
1
- /**
2
- * Follow a path into an object.
3
- * @param obj {object}
4
- * @param path {string[]}
5
- * @param createVal {*} If set, non-existant paths will be created and value at path will be set to createVal.
6
- * @return {*} The value, or undefined if it can't be reached. */
7
- export default function delve(obj, path, createVal = delveDontCreate) {
8
- let isCreate = createVal !== delveDontCreate;
9
-
10
- let len = path.length;
11
- if (!obj && !isCreate && len)
12
- return undefined;
13
-
14
- let i = 0;
15
- for (let srcProp of path) {
16
-
17
- // If the path is undefined and we're not to the end yet:
18
- if (obj[srcProp] === undefined) {
19
-
20
- // If the next index is an integer or integer string.
21
- if (isCreate) {
22
- if (i < len - 1) {
23
- // If next level path is a number, create as an array
24
- let isArray = (path[i + 1] + '').match(/^\d+$/);
25
- obj[srcProp] = isArray ? [] : {};
26
- }
27
- } else
28
- return undefined; // can't traverse
29
- }
30
-
31
- // If last item in path
32
- if (isCreate && i === len - 1)
33
- obj[srcProp] = createVal;
34
-
35
- // Traverse deeper along destination object.
36
- obj = obj[srcProp];
37
- i++;
38
- }
39
-
40
- return obj;
41
- }
42
-
43
- let delveDontCreate = {};
Binary file
Binary file
@@ -1,96 +0,0 @@
1
- @font-face {
2
- font-family: "Cabin";
3
- font-weight: 700;
4
- src: url("cabin-latin-700.woff2") format("woff")
5
- }
6
- @font-face {
7
- font-family: "Fira Code";
8
- font-weight: 400;
9
- src: url("FiraCode400.woff2") format("woff")
10
- }
11
- html[dark] {
12
- /*--card-background: #0b0e12 !important;*/
13
- --card-border: #1a1c1e !important;
14
- }
15
- html { background: var(--background) !important; font-size: 18px !important }
16
- body::before { content: ''; position: fixed; inset: 0;
17
- opacity: .03; filter: grayscale(75%);
18
- background: url('solarite-machine.webp') no-repeat -200px -200px / 140% auto ; }
19
-
20
- .typora-export-show-outline .typora-export-content { margin: 0 !important }
21
- .typora-export-sidebar { position: relative; width: 200px !important; background: black; color: #a0a4a8; margin: 0 !important; font-size: 16px !important ; }
22
-
23
- [dark] .typora-export-sidebar { background: var(--shade2) }
24
- .typora-export-sidebar .outline-content { display: flex; flex-direction: column;
25
- width: 200px !important; padding: 10px 10px 0 0 !important; overflow: visible !important }
26
- .typora-export-sidebar .outline-content > li { overflow-x: hidden; overflow-y: auto }
27
-
28
-
29
- .typora-export-sidebar .outline-content:before { content: ''; display: block; width: 210px; min-height: 210px;
30
- background: url('solarite-machine.webp'); background-size: cover; margin-bottom: 10px; }
31
- .typora-export-sidebar .outline-expander { width: 0 }
32
-
33
- #write { max-width: 860px; margin: 0 !important; padding-left: 20px }
34
- #write h1 { font: 700 350% Cabin; line-height: 1; margin: 0; padding: 0; color: var(--invert);
35
- border-bottom: 0 solid transparent; width: 140%; max-width: calc(100vw - 75px); }
36
-
37
- #write h2 { font-family: Cabin, sans-serif; font-size: 220%; line-height: 1; margin: 2em 0 .25em 0 }
38
-
39
- #write h3 { margin-top: 1.5em; margin-bottom: .3em; font-size: 140%; line-height: 1.1; font-family: Cabin, sans-serif }
40
- html:not([dark]) #write h3 { color: #678; }
41
-
42
- #write h4 { font-size: 105%; font-weight: bold; margin-top: .75em; margin-bottom: 0 }
43
- #write h5 { font-size: 100%; font-weight: bold; margin-top: .75em; margin-bottom: 0 }
44
- #write h6 { font-size: 100%; font-weight: normal; margin-top: .75em; margin-bottom: 0; text-decoration: underline }
45
-
46
-
47
- #write :is(p, h2, h3, h4, h5, h6, ol, ul) { max-width: 800px }
48
- #write p { text-align: justify }
49
- #write a, #write a:visited { color: #08c; text-decoration: none}
50
- #write a:hover { color: #08c; text-decoration: underline }
51
- #write ul { padding-left: 20px }
52
- #write code { display: inline-block; background: #e0e8ef; font: 11px 'Fira Code'; border-radius: 4px; padding: 2px 4px }
53
- [dark] #write code { background: #303336 }
54
-
55
- #write play-ground { width: calc(100vw - 260px); max-width: 1200px }
56
-
57
- #write code-editor[data-style="1"] .cm-scroller { font: 11px 'Fira Code' !important}
58
-
59
- body.typora-export { padding: 0 !important }
60
-
61
- :is(td, th):not(:first-of-type) { padding: 6px 8px 6px 0 }
62
- :is(td, th):not(:first-of-type) { padding-left: 5px }
63
- code { white-space: nowrap; border: none !important }
64
-
65
- .outline-h1 > .outline-item { color: white; font-size: 22px }
66
- .outline-h2 > .outline-item { color: white }
67
-
68
-
69
- table :is(th, td) {
70
- border-color: var(--shade1) !important
71
- }
72
- table tr:nth-child(2n), thead {
73
- background-color: transparent !important
74
- }
75
-
76
-
77
- @media screen and (width < 1085px) {
78
- .typora-export-sidebar, .typora-export-sidebar .outline-content {
79
- display: none
80
- }
81
- #write play-ground { width: calc(100vw - 60px) }
82
- }
83
- @media screen and (width < 768px) {
84
- #write { padding: 10px !important }
85
- #write play-ground { width: calc(100vw - 36px) }
86
- }
87
-
88
- @media screen and (width < 512px) {
89
- body { font-size: 14px }
90
- table :is(th, td) { padding: 2px 4px !important }
91
- #write { padding: 6px !important }
92
- table { font-size: 85% }
93
- code { white-space: wrap }
94
- }
95
-
96
-