solarite 0.2.1 → 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.
- package/package.json +6 -5
- package/benchmarks/naive/Solarite.min.js +0 -4
- package/benchmarks/naive/index.html +0 -14
- package/benchmarks/naive/main.js +0 -339
- package/benchmarks/naive/package-lock.json +0 -13
- package/benchmarks/naive/package.json +0 -23
- package/benchmarks/readme.md +0 -48
- package/build/build.bat +0 -4
- package/build/build.js +0 -139
- package/build/lib/rollup.min.js +0 -11
- package/build/lib/source-map.min.js +0 -1
- package/build/lib/terser.min.js +0 -1
- package/docs/index.md +0 -883
- package/docs/js/Playground.js +0 -184
- package/docs/js/codemirror/codemirror6.js +0 -32513
- package/docs/js/codemirror/themeSolarIce.js +0 -312
- package/docs/js/documentation.js +0 -32
- package/docs/js/ui/CodeEditor.js +0 -978
- package/docs/js/ui/DarkToggle.js +0 -52
- package/docs/js/ui/FlexResizer.js +0 -152
- package/docs/js/util/Draggable2.js +0 -151
- package/docs/js/util/Errors.js +0 -20
- package/docs/js/util/Html.js +0 -147
- package/docs/js/util/Icons.js +0 -623
- package/docs/js/util/Input.js +0 -253
- package/docs/js/util/Util.js +0 -88
- package/docs/js/util/delve.js +0 -43
- package/docs/media/FiraCode400.woff2 +0 -0
- package/docs/media/cabin-latin-700.woff2 +0 -0
- package/docs/media/documentation.css +0 -96
- package/docs/media/eternium.css +0 -1123
- package/docs/media/solarite-machine.webp +0 -0
- package/index.html +0 -761
- package/tests/Benchmark.test.js +0 -319
- package/tests/Solarite.test.js +0 -3838
- package/tests/Testimony.js +0 -809
- package/tests/index.html +0 -46
- package/tests/run.bat +0 -2
package/docs/js/Playground.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import {r, Solarite} from "../../src/solarite/Solarite.js";
|
|
2
|
-
import "./ui/CodeEditor.js";
|
|
3
|
-
import "./ui/FlexResizer.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default class Playground extends Solarite {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param code
|
|
11
|
-
* @param language
|
|
12
|
-
* @param width
|
|
13
|
-
*
|
|
14
|
-
* @param maxHeight {int} If the editor is taller than the preview, and taller than this height, limit it the max of this height and the preview height.
|
|
15
|
-
* */
|
|
16
|
-
constructor({value, language='javascript', width=50, prefix='', maxHeight=620}={}) {
|
|
17
|
-
super({scripts: false});
|
|
18
|
-
value = value || (this.code ? this.code.querySelector('script')?.textContent : '');
|
|
19
|
-
this.value = value;
|
|
20
|
-
this.language = language;
|
|
21
|
-
this.width = width;
|
|
22
|
-
this.prefix2 = prefix;
|
|
23
|
-
this.maxHeight = maxHeight
|
|
24
|
-
this.render();
|
|
25
|
-
|
|
26
|
-
this.editor.onChange.push(() => {
|
|
27
|
-
this.run();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
this.run();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
run() {
|
|
34
|
-
let html;
|
|
35
|
-
if (this.language === 'javascript')
|
|
36
|
-
html = `<script type="module">${this.editor.getValue()}</script>`;
|
|
37
|
-
else if (this.language === 'html')
|
|
38
|
-
html = this.editor.getValue();
|
|
39
|
-
else {
|
|
40
|
-
this.editor.style.width = '100%';
|
|
41
|
-
this.editor.style.borderRight = 'none';
|
|
42
|
-
this.resizer.style.display = 'none';
|
|
43
|
-
this.preview.style.display = 'none';
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Create a new preview iframe and swap it for the old one once it's loaded.
|
|
48
|
-
let newIframe = r(`<iframe data-id="preview" frameborder="0" style="display: none; height: 0">`);
|
|
49
|
-
newIframe.onload = () => {
|
|
50
|
-
|
|
51
|
-
newIframe.contentWindow.document.open();
|
|
52
|
-
newIframe.contentWindow.onerror = (msg, url, line, col, error) => {
|
|
53
|
-
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
let message;
|
|
56
|
-
if (error instanceof newIframe.contentWindow.SyntaxError)
|
|
57
|
-
message = `${msg} on line ${line}:${col}`
|
|
58
|
-
else
|
|
59
|
-
message = shortenError(error)
|
|
60
|
-
|
|
61
|
-
let errorDiv = `<div style="color: red; font: 12px sans-serif; position: fixed; left: 0; bottom: 0;
|
|
62
|
-
width: 100%; padding: 5px; max-height: 50%; overflow-y: auto; background: white">${message}</div>`;
|
|
63
|
-
newIframe.contentWindow.document.body.append(r(errorDiv));
|
|
64
|
-
}, 0);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
newIframe.contentWindow.document.write(this.prefix2 + html);
|
|
68
|
-
|
|
69
|
-
newIframe.contentWindow.document.close();
|
|
70
|
-
newIframe.onload = null;
|
|
71
|
-
|
|
72
|
-
if (document.documentElement.hasAttribute('dark'))
|
|
73
|
-
newIframe.contentWindow.document.documentElement.setAttribute('dark', '');
|
|
74
|
-
// TODO use mutation observer to watch for change.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// TODO: Check to see when all links have a .sheet property with css rules.
|
|
81
|
-
// let dynamic = newIframe.contentWindow.document.querySelectorAll('link');
|
|
82
|
-
// for (let el of dynamic) {
|
|
83
|
-
// console.log(el)
|
|
84
|
-
// dynamic.onload = () => {
|
|
85
|
-
// console.log('loaded')
|
|
86
|
-
// console.log(el)
|
|
87
|
-
// }
|
|
88
|
-
// }
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Prevent flashing
|
|
93
|
-
//newIframe.contentWindow.document.addEventListener('load', () => {
|
|
94
|
-
setTimeout(() => {
|
|
95
|
-
//newIframe.contentWindow.requestAnimationFrame(() => {
|
|
96
|
-
this.preview.remove();
|
|
97
|
-
newIframe.style.display = '';
|
|
98
|
-
this.preview = newIframe;
|
|
99
|
-
|
|
100
|
-
// Resize iframe to height of content.
|
|
101
|
-
let newPreviewHeight = expandIframe(newIframe);
|
|
102
|
-
setTimeout(() => {
|
|
103
|
-
expandIframe(newIframe);
|
|
104
|
-
}, 500);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (this.maxHeight) {
|
|
108
|
-
|
|
109
|
-
// Get scroll position.
|
|
110
|
-
let scroller = this.editor.querySelector('.cm-editor > .cm-scroller');
|
|
111
|
-
let scroll = {x: scroller?.scrollLeft || 0, y: scroller?.scrollTop || 0};
|
|
112
|
-
|
|
113
|
-
// Don't let CodeEditor be taller than preview.
|
|
114
|
-
this.editor.style.height = '';
|
|
115
|
-
let editorHeight = this.editor.getBoundingClientRect().height;
|
|
116
|
-
if (editorHeight > newPreviewHeight && editorHeight > this.maxHeight)
|
|
117
|
-
this.editor.style.height = Math.max(newPreviewHeight, this.maxHeight) + 'px';
|
|
118
|
-
|
|
119
|
-
// Restore scroll position.
|
|
120
|
-
if (scroller) {
|
|
121
|
-
scroller.scrollTop = scroll.y;
|
|
122
|
-
scroller.scrollLeft = scroll.x;
|
|
123
|
-
requestAnimationFrame(() => {
|
|
124
|
-
scroller.scrollTop = scroll.y;
|
|
125
|
-
scroller.scrollLeft = scroll.x;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
//})
|
|
130
|
-
}, 10);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
this.insertBefore(newIframe, this.preview);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
render() {
|
|
138
|
-
r(this)`
|
|
139
|
-
<play-ground class="card row pad stretch-v pad-small-tablet col-mobile pad-tiny-mobile">
|
|
140
|
-
<style>
|
|
141
|
-
@media (width < 768px) { /* On mobile, put preview below code */
|
|
142
|
-
:host code-editor { max-height: 300px; border-bottom: var(--border) }
|
|
143
|
-
:host [data-id=preview] { margin: 0; min-width: 0; background: white }
|
|
144
|
-
:host flex-resizer { display: none }
|
|
145
|
-
}
|
|
146
|
-
@media (768px <= width) {
|
|
147
|
-
:host code-editor { width: ${this.width}%; border-right: var(--border) }
|
|
148
|
-
:host [data-id=preview] { width: ${100 - this.width}%; min-width: 0; margin: 0; background: white }
|
|
149
|
-
}
|
|
150
|
-
</style>
|
|
151
|
-
<code-editor data-id="editor" value=${this.value} language=${this.language} options=${{tabSize: 2}}></code-editor>
|
|
152
|
-
<flex-resizer data-id="resizer"></flex-resizer>
|
|
153
|
-
<iframe data-id="preview" frameborder="0"></iframe>
|
|
154
|
-
<slot data-id="code" style="display: none"></slot>
|
|
155
|
-
</play-ground>`
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
Playground.define('play-ground');
|
|
159
|
-
|
|
160
|
-
function shortenError(error, br='<br> ') {
|
|
161
|
-
if (typeof error === 'string')
|
|
162
|
-
return error;
|
|
163
|
-
|
|
164
|
-
return error.stack.replace(/\r?\n/g, br);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function expandIframe(iframe) {
|
|
168
|
-
if (!iframe.contentWindow)
|
|
169
|
-
return;
|
|
170
|
-
|
|
171
|
-
iframe.style.height = '0';
|
|
172
|
-
iframe.style.minHeight = '';
|
|
173
|
-
iframe.style.maxHeight = '0';
|
|
174
|
-
|
|
175
|
-
let previewHeight = iframe.contentWindow.document.documentElement.scrollHeight;
|
|
176
|
-
let newPreviewHeight = Math.ceil(previewHeight);
|
|
177
|
-
if (iframe.contentWindow.document.body.scrollWidth > iframe.clientWidth)
|
|
178
|
-
newPreviewHeight += 24; // If it has a scrollbar.
|
|
179
|
-
|
|
180
|
-
iframe.style.height = '';
|
|
181
|
-
iframe.style.minHeight = newPreviewHeight + 'px';
|
|
182
|
-
iframe.style.maxHeight = '100%';
|
|
183
|
-
return newPreviewHeight;
|
|
184
|
-
}
|