-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
403 lines (340 loc) · 16.3 KB
/
index.html
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1' />
<title>JSY Code Playground</title>
<link crossorigin rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/lib/codemirror.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/theme/base16-light.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/theme/base16-dark.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/theme/lucario.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/theme/material.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/theme/monokai.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/theme/midnight.css' />
<link crossorigin rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/theme/solarized.css' />
<style>
.CodeMirror { height: auto; font-size: 10pt; }
.doc_codeHighlight { font-size: 10pt; }
.doc_about { box-shadow: 0px 0px 15px 0px rgba(0.7,0.7,0.7,0.2) }
.doc_about>.container.content { max-width: 46em }
</style>
<script defer src='https://cdn.jsdelivr.net/npm/jsy-transpile/umd/index.js'></script>
<script defer crossorigin src='https://cdn.jsdelivr.net/npm/[email protected]/lib/codemirror.min.js'></script>
<script defer crossorigin src='https://cdn.jsdelivr.net/npm/[email protected]/mode/javascript/javascript.js'></script>
<script defer crossorigin src='https://cdn.jsdelivr.net/npm/[email protected]/addon/runmode/runmode.js'></script>
<script defer crossorigin src='https://cdn.jsdelivr.net/npm/[email protected]/keymap/vim.js'></script>
<script defer src='./js/mode/jsy/jsy.js'></script>
<script defer crossorigin src='https://cdn.jsdelivr.net/npm/[email protected]/libs/lz-string.min.js'></script>
<script defer src='https://cdn.jsdelivr.net/npm/[email protected]/standalone.js'></script>
<script defer src='https://cdn.jsdelivr.net/npm/[email protected]/parser-babylon.js'></script>
<script>
window.jsy_transpile_options = JSON.parse(localStorage.getItem('jsy_transpile_options') || '{}')
window.local_editor_options = JSON.parse(localStorage.getItem('editor_options') || '{}')
window.local_hightlight_options = JSON.parse(localStorage.getItem('hightlight_options') || '{}')
window.default_jsy_src =
`const apiUrl = 'http://api.example.com'
class ExampleApi extends SomeBaseClass ::
constructor( credentials ) ::
const apiCall = async ( pathName, body ) => ::
const res = await fetch @ \`\$\{apiUrl}/\$\{pathName}\`, @{}
method: 'POST'
headers: @{}
'Content-Type': 'application/json'
body: JSON.stringify @ body
return await res.json()
Object.assign @ this, @{}
add: data => apiCall @ 'add', data
modify: data => apiCall @ 'send', data
retrieve: data => apiCall @ 'get', data
`
</script>
</head>
<body>
<section class='section'>
<div class='columns is-desktop'>
<div class='column is-half-desktop'>
<h3 class='is-size-3'>JSY Dialect
<em class='is-size-6'>(edit me!)</em></h3>
</h3>
<textarea id='edit_jsy' class='is-invisible'></textarea>
<div class='columns'>
<div class='column'>
<div class='field is-grouped' style='padding-top: 6px'>
<div class='control'>
<label class='checkbox'>
<input id='vim_mode' type='checkbox' name='keyMap' value='vim' onchange='changeEditorOption({keyMap: this.checked ? this.value : "default"})' />
VIM mode
<script>Promise.resolve().then(() => {
const el = document.getElementById('vim_mode')
el.checked = el.value === window.local_editor_options.keyMap })
</script>
</label>
</div>
<div class='control'>
<div class='select is-small'>
<select onchange='changeEditorOption({theme: this.value || "default"})' >
<option selected value='default'>Theme</option>
<option>default</option>
<option>base16-light</option>
<option>base16-dark</option>
<option>lucario</option>
<option>material</option>
<option>monokai</option>
<option>midnight</option>
<option>solarized light</option>
<option>solarized dark</option>
</select>
</div>
</div>
<a class='button is-small is-warning' onclick='resetEditor(), false'>reset editor</a>
</div>
</div>
<div class='column is-narrow has-text-right'>
<p class='is-size-4'>
the <a target='_blank' href='https://github.com/jsy-lang/jsy-lang-docs#readme'>JSY dialect</a>
</p>
</div>
</div>
</div>
<div class='column is-half-desktop'>
<h3 class='is-size-3'>JavaScript</h3>
<textarea id='edit_javascript' class='is-invisible'></textarea>
<div class='columns'>
<div class='column'>
<div class='field is-grouped' style='padding-top: 6px'>
<div class='control'>
<label class='checkbox'>
<input id='use_prettier' type='checkbox' onchange='changeHighlightOption({use_prettier: this.checked})' />
<a target='_blank' href='https://prettier.io'>Prettier</a>
<script>Promise.resolve().then(() => {
const el = document.getElementById('use_prettier')
el.checked = window.local_hightlight_options.use_prettier })
</script>
</label>
</div>
</div>
</div>
<div class='column'>
<p class='is-size-4 has-text-right'>
from <a target='_blank' href='https://www.npmjs.com/package/jsy-transpile'>jsy-transpile</a>
</p>
</div>
</div>
</div>
</section>
<section class='doc_about section is-medium has-background-light'>
<div class='container content is-size-4-desktop'>
<p>
<a target='_blank' href='https://github.com/jsy-lang/jsy-lang-docs#readme'>JSY</a> is <b>an indented (offside) JavaScript dialect</b>. We believe indentation is
better at describing code blocks instead of painstakingly matching open/close
sections <code>{ } () []</code>.
</p>
<p>
Think modern JavaScript — ES6, ES2018 — indented similar
to <a target='_blank' href='https://www.python.org'>Python</a>
or <a target='_blank' href='https://coffeescript.org'>CoffeeScript</a>.
</p>
<p>
Inspired by <a target='_blank' href='http://www.draketo.de/english/wisp'>Wisp</a>, JSY
primarily operates as a scanner-pass syntax transformation to change
indented (offside) code into the corresponding open/close matching token
code. Thus the internal scanning parser only has to be aware of
<code>/* comments */</code> and <code>"string literals"</code> rules to
successfully transform code. Thus, as a JavaScript dialect,
<b>JSY automatically keeps pace with modern JavaScript editions!</b>
</p>
<br />
<p>
JSY has over <a target='_blank' href='./unittest.html'>5,000 JSY unit tests</a>
and <a title='Build Status' target='_blank' href='https://travis-ci.org/jsy-lang/jsy-transpile'>continuous testing <img alt='Build Status' src='https://travis-ci.org/jsy-lang/jsy-transpile.svg?branch=master' border='0' /></a>
to insure consistency and stability.
There are plugins for <a target='_blank' href='https://github.com/jsy-lang/rollup-plugin-jsy-lite#readme'>Rollup</a>,
<a target='_blank' href='https://github.com/jsy-lang/parcel-plugin-jsy#readme'>Parcel 1.x</a>,
<a target='_blank' href='https://github.com/jsy-lang/parcel-transform-jsy#readme'>Parcel 2.x</a>,
as well as <a target='_blank' href='https://github.com/jsy-lang/babel-plugin-jsy-lite#readme'>Babel 6 & 7</a>,
and <a target='_blank' href='https://github.com/jsy-lang/jsy-lang-docs#ecosystem'>more</a>.
</p>
<p>
Try JSY out on <a target='_blank' href='https://babeljs.io/en/repl'>Babel's REPL</a>
or in a <a target='_blank' href='https://codesandbox.io/'>CodeSandbox</a>
— just add the <a target='_blank' href='https://www.npmjs.com/package/babel-plugin-jsy-lite'><samp>babel-plugin-jsy-lite</samp></a>
to the configured Babel plugin list.
</p>
</div>
</section>
<section class='section'>
<div class='columns is-desktop'>
<div class='column is-half-desktop'>
<h4 class='is-size-4'>JSY Highlighted</h3>
<pre id='output_jsy' class='doc_codeHighlight CodeMirror cm-s-base16-light'></pre>
<div class='field is-grouped' style='padding-top: 6px'>
<div class='control'>
<div class='select is-small'>
<select onchange='changeHighlightOption({theme: this.value || "default"})' >
<option selected value='default'>Theme</option>
<option>default</option>
<option>base16-light</option>
<option>base16-dark</option>
<option>lucario</option>
<option>material</option>
<option>monokai</option>
<option>midnight</option>
<option>solarized light</option>
<option>solarized dark</option>
</select>
</div>
</div>
</div>
</div>
<div class='column is-half-desktop'>
<h4 class='is-size-4'>JavaScript Highlighted</h3>
<pre id='output_javascript' class='doc_codeHighlight cm-s-base16-light'></pre>
</div>
</div>
</section>
<script>
function get_jsy_src() {
const hash = window.location.hash.slice(1)
return ! hash ? default_jsy_src :
LZString.decompressFromEncodedURIComponent(hash) }
function set_jsy_src(jsy_src) {
window.location.hash = (false === jsy_src || default_jsy_src == jsy_src) ? '' :
LZString.compressToEncodedURIComponent(jsy_src) }
window.addEventListener('hashchange', () => on_jsy_updated(), false)
const editor_options = {
lineNumbers: true,
theme: 'base16-dark',
inputStyle: 'contenteditable',
}
const jsy_editor_options = Object.assign(
{}, editor_options, window.local_editor_options,
{ autofocus: true, tabindex: 1, mode: 'jsy' })
const javascript_editor_options = Object.assign(
{}, editor_options, window.local_editor_options,
{ readOnly: true, tabindex: 2, mode: 'javascript'})
const doc_editors = window.doc_editors = {}
const page_loaded = new Promise(resolve => {
window.addEventListener('DOMContentLoaded', () => resolve(), false)
window.addEventListener('load', () => resolve(), false)
})
page_loaded
.then(get_jsy_src)
.then(function(jsy_src) {
if (! window.jsy_transpile) throw new Error('jsy_transpile not loaded')
if (! window.CodeMirror) throw new Error('CodeMirror not loaded')
const ed_jsy = doc_editors.jsy = CodeMirror.fromTextArea(
document.getElementById('edit_jsy'), jsy_editor_options)
const ed_javascript = doc_editors.javascript = CodeMirror.fromTextArea(
document.getElementById('edit_javascript'), javascript_editor_options)
ed_jsy.setValue(jsy_src)
ed_jsy.on('change', () => set_jsy_src(doc_editors.jsy.getValue()))
on_jsy_updated(true)
return true
})
function resetEditor() {
set_jsy_src(false)
changeEditorOption({keyMap:'default', theme: 'base16-dark'})
localStorage.removeItem('editor_options')
on_jsy_updated(true)
}
function changeEditorOption(changed_options) {
const merged = Object.assign(
JSON.parse(localStorage.getItem('editor_options') || '{}'),
changed_options)
localStorage.setItem('editor_options', JSON.stringify(merged))
window.local_editor_options = merged
for (const [k, v] of Object.entries(changed_options))
for (const ed of Object.values(doc_editors))
ed.setOption(k, v)
on_jsy_updated()
return merged }
function on_jsy_updated(force) {
on_jsy_updated.tid = clearTimeout(on_jsy_updated.tid)
if (!force) {
on_jsy_updated.tid = setTimeout(on_jsy_updated, 200, true)
return
}
const jsy_src = get_jsy_src()
if (jsy_src != doc_editors.jsy.getValue())
doc_editors.jsy.setValue(jsy_src)
let js_vanilla = ''
try {
js_vanilla = jsy_transpile(jsy_src, window.jsy_transpile_options)
} catch (err) {
console.warn('JSY-Transpile Error:', err.message)
js_vanilla = `// ERROR: ${err.message}`
}
if (window.prettier) {
const opt = Object.assign({},
window.local_hightlight_options.prettier,
{ parser: 'babylon', plugins: prettierPlugins })
let js_prettier
try {
js_prettier = window.prettier.format(js_vanilla, opt)
if (window.local_hightlight_options.use_prettier) {
js_vanilla = js_prettier
}
} catch (err) {
js_vanilla += `\n\n// ${err.toString().replace(/\n/g, '\n// ')}\n`
}
}
doc_editors.javascript.setValue(js_vanilla)
doJSYHighlight(jsy_src, js_vanilla)
}
function doJSYHighlight(jsy_src, js_vanilla) {
CodeMirror.runMode(jsy_src, 'jsy', document.getElementById('output_jsy'))
CodeMirror.runMode(js_vanilla, 'javascript', document.getElementById('output_javascript'))
const theme = window.local_hightlight_options.theme || 'base16-light'
const theme_class = theme.split(/\s+/).map(n => 'cm-s-'+n).join(' ')
for (const el of document.querySelectorAll('.doc_codeHighlight')) {
el.className = 'doc_codeHighlight CodeMirror ' + theme_class
}
}
function changeHighlightOption(changed_options) {
const merged = Object.assign(
JSON.parse(localStorage.getItem('hightlight_options') || '{}'),
changed_options)
if (changed_options)
localStorage.setItem('hightlight_options', JSON.stringify(merged))
window.local_hightlight_options = merged
on_jsy_updated(true)
return merged
}
function prettierOptions(prettier) {
changeHighlightOption({prettier: Object.assign({}, prettier)})
}
console.log(`To Change Prettier Options:
prettierOptions({insertPragma: true}
prettierOptions({semi: true, singleQuote: false})
prettierOptions({useTabs: false, tabWidth: 4})
prettierOptions({trailingComma: 'all', arrowParens: 'always'})
`)
console.log(`To JSY Transpile Options:
jsy_transpile_options.defines = {PLAT_WEB: true}
`)
</script>
<footer class='footer'>
<div class='content columns'>
<div class='column has-text-left'>
<p>
Built with <a target='_blank' href='https://codemirror.net/'>CodeMirror</a>
and <a target='_blank' href='https://bulma.io'>Bulma</a>.
</p>
</div>
<div class='column has-text-centered'>
<p>
Copyright (©) 2018 <a target='_blank' href='http://shaneholloway.com'>Shane Holloway</a>.<br/>
Content and examples are licensed under <br/>
<a target='_blank' href='https://github.com/jsy-lang/jsy-lang-docs/blob/master/LICENSE'>BSD 2-Clause or CC by SA 4.0</a> as applicable.
</p>
</div>
<div class='column has-text-right'>
<a title='JSDeliver' target='_blank' href='https://www.jsdelivr.com/package/npm/jsy-transpile'><img alt='JSDeliver' src='https://data.jsdelivr.com/v1/package/npm/jsy-transpile/badge' border='0' /></a>
<br />
<a title='Clicky' target='_blank' href='http://clicky.com/101137747'><img alt='Clicky: Real Time Web Analytics' src='https://static.getclicky.com/media/links/badge.gif' border='0' /><img alt='Clicky' width='1' height='1' src='https://in.getclicky.com/101137747ns.gif' /></a>
</div>
</div>
</footer>
</body>
</html>