-
Notifications
You must be signed in to change notification settings - Fork 36
/
muboard.min.js
215 lines (189 loc) · 9.99 KB
/
muboard.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
!function(){"use strict";const i="Muboard",h="0.5.2";let d,a,r,e=null;const s={};const u={green:`
html {height: 100%}
body {
background: #eec; font-family: helvetica, arial, sans-serif;
line-height: 1.5; margin: 0; padding: 0.75em; box-sizing:
border-box; height: 100%;
}
main {
background: #255; color: #eed;
border: 0.75em ridge #933; padding: 1em; box-sizing: border-box;
width: 100%; height: 66%; resize: both; overflow: auto;
}
textarea {
background: #111; color: #9c9; display: block; margin-top: 0.75rem;
border-width: 0.125rem; padding: 0.375rem; box-sizing: border-box;
width: 100%; height: calc(34% - 0.75em);
}
pre, code, samp, kbd {color: #dec; font-family: monospace, monospace}
h1 {font-size: 1.5em}
h2 {font-size: 1.25em}
h1, h2, h3, h4, h5, h6 {margin: 1em 0 0.5em 0; line-height: 1.2}
main > :first-child, main > :first-child > :first-child {margin-top: 0}
section > :first-child, section > :first-child > :first-child {margin-top: 0}
a:link, a:visited {color: #ccf}
a:hover, a:active {color: #e76}
hr {border: 0; border-bottom: thin solid #fbc}
.center {text-align: center}
article {max-width: 40em; margin: 0 auto}
main > section {display: flex}
main > section > section {
display: block; flex-basis: 100%; padding: 0 0.5em;
}
main > section > section:first-child {padding-left: 0}
main > section > section:last-child {padding-right: 0}
table {border-collapse: collapse}
th, td {border: thin solid #bed; padding: 0.3em 0.4em; text-align: left}
footer {margin: 1em 0; text-align: center; display: none}
footer a {margin-right: 1em}
footer a:last-child {margin-right: 0}
footer a:link, footer a:visited {color: #03c}
footer a:hover, a:active {color: #06f}
`};function l(){a.innerHTML=window.texme.render(d.value),window.MathJax.texReset(0),window.MathJax.typeset()}function p(){c(),e=window.setTimeout(l,s.renderDelay)}function c(){null!==e&&(window.clearTimeout(e),e=null)}function m(e,t,o){var n=d.selectionStart,e=n-e.length,i=e+t.length;const a=d.value;c(),d.value=a.substr(0,e)+t+o+a.substr(n),d.setSelectionRange(i,i),c()}function w(e){var t=d.selectionStart;let o;o=t<=10?d.value.substr(0,t):d.value.substr(t-10,10);var n,t=o.lastIndexOf(",");if(-1!==t)switch(o.substr(t)){case",clear":c(),a.innerHTML=d.value="",l();break;case",i":m(",i","$ "," $"),l();break;case",d":m(",d","$$ "," $$"),l();break;case",align;":m(",align;","\\begin{align}\n","\n\\end{align}"),l();break;case",align*":m(",align*","\\begin{align*}\n","\n\\end{align*}"),l();break;case",article":m(",article","<article>\n\n","\n\n</article>"),l();break;case",split":m(",split","<section>\n<section>\n\n","\n\n</section>\n<section>\n\n\n\n</section>\n</section>"),l();break;case",section":m(",section","<section>\n\n","\n\n</section>"),l();break;case",center":m(",center",'<div class="center">\n\n',"\n\n</div>"),l();break;case",save":m(",save","",""),l(),setTimeout(b,10);break;case",load":m(",load","",""),l(),setTimeout(f,10);break;case",remove":m(",remove","",""),l(),setTimeout(g,10);break;case",list":if(m(",list","",""),l(),0!==window.localStorage.length){let t=`<article>
<h1>Saved Keys</h1>
<p>
The following Muboard keys are saved in the local storage of your
browser:
</p>
<ol>`;for(let e=0;e<window.localStorage.length;e++)t+="<li>"+window.localStorage.key(e)+"</li>";t+=`</ol>
<p>
Type <code>,load</code> to load any key.
</p>
</article>`,a.innerHTML=t}else a.innerHTML="<article><h1>No Keys Found</h1></article>";break;case",footer":m(",footer","",""),l(),n=r.style.display,r.style.display="none"===n?"block":"none";break;case",help":m(",help","",""),a.innerHTML=`
<article>
<h1>${i}</h1>
<p>
Muboard is a web-based mathematics display board. Muboard lets you
scribble mathematics using LaTeX and Markdown while presenting your
desktop screen.
</p>
<h2>Commands</h2>
<p>
The following commands that may be typed anywhere in the input text
field:
</p>
<dl>
<dt><code>,clear</code></dt>
<dd>Clear text input field and the board.</dd>
<dt><code>,i</code></dt>
<dd>Insert inline mathematics.</dd>
<dt><code>,d</code></dt>
<dd>Insert display mathematics.</dd>
<dt><code>,align;</code></dt>
<dd>Insert align envrionment.</dd>
<dt><code>,align*</code></dt>
<dd>Insert align* environment.</dd>
<dt><code>,article</code></dt>
<dd>
Insert article element. The article element is displayed as a
single column of text at the center of the board with a fixed
maximum width that makes the text easier to read. Recommended for
distributable boards.
</dd>
<dt><code>,split</code></dt>
<dd>
Split the board into two side-by-side columnar sections. More
columnar sections may be added with the next command.
</dd>
<dt><code>,section</code></dt>
<dd>Insert section element.</dd>
<dt><code>,center</code></dt>
<dd>Insert center-aligned text.</dd>
<dt><code>,save</code></dt>
<dd>Save current input to the browser's local storage.</dd>
<dt><code>,load</code></dt>
<dd>Load an input from the browser's local storage.</dd>
<dt><code>,remove</code></dt>
<dd>Remove an input from the browser's local storage.</dd>
<dt><code>,list</code></dt>
<dd>List all inputs saved in the browser's local storage.</dd>
<dt><code>,footer</code></dt>
<dd>Toggle the display of footer at the bottom of the page.</dd>
<dt><code>,help</code></dt>
<dd>Show this help message.</dd>
<dt><code>,example</code></dt>
<dd>Show demo example content on board.</dd>
<dt><code>,version</code></dt>
<dd>Show version and license information.</dd>
</dl>
<p>
You can type the above commands anywhere in the input text field to
invoke them. For example, type <code>,i</code> anywhere in input text
field and it will be immediately replaced with LaTeX delimiters for
inline math.
</p>
<p>
${i} can also be used to create distributable boards with Markdown
+ LaTeX content saved in it. See <a
href="https://github.com/susam/muboard">github.com/susam/muboard</a>
for more details.
</p>
<hr style="margin: 1em 0">
<div style="font-size: small; text-align: center">
<p>
${i} is created and maintained by <a
href="https://twitter.com/susam">Susam</a>.
</p>
<p>
The source code is available on
<a href="https://github.com/susam/muboard">GitHub</a>.
</p>
</div>
</article>
`;break;case",example":m(",example","",""),d.value=`<article>
# The Möbius function
For any positive integer $ n $, the Möbius function $ \\mu(n) $ is
defined as follows:
$$ \\mu(1) = 1; $$
If $ n > 1, $ write $ n = p_1^{a_1} \\dots p_k^{a_k} $ (prime
factorization). Then
\\begin{align*}
\\mu(n) & = (-1)^k \\text{ if } a_1 = a_2 = \\dots = a_k = 1, \\\\
\\mu(n) & = 0 \\text{ otherwise}.
\\end{align*}
If $ n \\ge 1, $ we have
$$
\\sum_{d \\mid n} \\mu(d) =
\\begin{cases}
1 & \\text{ if } n = 1, \\\\
0 & \\text{ if } n > 1.
\\end{cases}
$$
</article>`,l();break;case",version":m(",version","",""),a.innerHTML=`
<article>
<h1>${i} ${h}</h1>
<p>
Copyright © 2021-2022 Susam Pal
</p>
<p>
This is free and open source software. You can use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of it,
under the terms of the <a
href="https://github.com/susam/muboard/blob/master/LICENSE.md">MIT
License</a>.
</p>
<p>
This software is provided <em>"as is"</em>, <em>without
warranty of any kind</em>, express or implied. See the MIT License
for details.
</p>
</article>
`;break;default:p()}else p()}function o(){const e=window.document.getElementsByTagName("textarea"),t=(a=window.document.createElement("main"),d=window.document.createElement("textarea"),d.placeholder=`Write content in LaTeX + Markdown format here.
Type ,help for help.
Type ,example for demo.`,r=window.document.createElement("footer"),r.innerHTML=`
<a href="https://github.com/susam/muboard">GitHub</a>
<a href="https://twitter.com/intent/follow?screen_name=susam">Twitter</a>
<a href="https://github.com/susam/muboard/blob/master/LICENSE.md">License</a>
`,0<e.length?(d.value=e[0].value.trim(),e[0].remove()):(d.value=window.document.body.innerHTML.trim(),window.document.body.innerHTML=""),void 0!==window.document.title&&""!==window.document.title||(window.document.title=i),window.document.body.appendChild(a),window.document.body.appendChild(d),window.document.body.appendChild(r),d.focus(),window.document.createElement("style"));var o=u.green;t.appendChild(window.document.createTextNode(o)),window.document.head.appendChild(t);const n=window.document.createElement("meta");n.name="viewport",n.content="width=device-width, initial-scale=1.0",window.document.head.appendChild(n),s.footer&&(r.style.display="block"),l(),d.addEventListener("input",w)}function b(){const e="Provide a key name to save the current input to the browser's local storage.\n\nYou can use the same key to load the input later.";var t=window.prompt(e);if(null!==t)if(""!==t)if(/\s/.test(t))a.innerHTML=`<article>
<h1>Error</h1>
<p>Key cannot have whitespace.</p>
</article>`;else{if(null!==window.localStorage.getItem(t)){const e="A key with the given name already exists.\n\nDo you want to overwrite the same key?";if(!1===window.confirm("A key with the given name already exists.\n\nDo you want to overwrite the same key?"))return}window.localStorage.setItem(t,d.value)}else a.innerHTML=`<article>
<h1>Error</h1>
<p>Key cannot be empty string.</p>
</article>`}function f(){var e=window.prompt("Provide a key name to load input from the browser's local storage."),e=window.localStorage.getItem(e);null!==e?(d.value=e,l()):a.innerHTML=`<article>
<h1>Error</h1>
<p>Key does not exist.</p>
</article>`}function g(){var e=window.prompt("Provide name of key to remove from browser's local storage.");null!==window.localStorage.getItem(e)?window.localStorage.removeItem(e):a.innerHTML=`<article>
<h1>Error</h1>
<p>Key does not exist.</p>
</article>`}s.texmeURL="https://cdn.jsdelivr.net/npm/texme@1.0.0",s.renderDelay=200,s.footer=!1;{let e;for(e in s)"undefined"!=typeof window&&void 0!==window.muboard&&void 0!==window.muboard[e]&&(s[e]=window.muboard[e])}void 0===window.texme&&(window.texme={}),window.texme.renderOnLoad=!1;{var n=s.texmeURL,v=void 0;const t=window.document.createElement("script");t.src=n,t.onload=v,window.document.head.appendChild(t)}window.addEventListener("load",o)}();