nattoppet 2.1.1 → 4.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shiwei Zhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,94 @@
1
+ [require]=
2
+ const {opts: [id], args: [file]} = std_call()
3
+ const content = read(file)
4
+ switch (extname(file)) {
5
+ case 'less':
6
+ `<style ${id ? `id="${id}"` : ''}>${render_less(content)}</style>`; break
7
+ case 'css':
8
+ `<style ${id ? `id="${id}"` : ''}>${content}</style>`; break
9
+ case 'coffee':
10
+ `<script ${id ? `id="${id}"` : ''}>${render_coffee(content, { bare: true })}</script>`; break
11
+ case 'js':
12
+ `<script ${id ? `id="${id}"` : ''}>${content}</script>`; break
13
+ case 'md':
14
+ render_markdown(content); break
15
+ case 'wasm':
16
+ `<script ${id ? `id="${id}"` : ''}>
17
+ const ready = (async () => {
18
+ const raw = await fetch("data:application/octet-stream;base64,${read(file, 'compressed-base64')}")
19
+ const blob = await raw.blob()
20
+ const decompressed = await blob.stream().pipeThrough(new DecompressionStream("deflate-raw"))
21
+ const response = new Response(decompressed, { headers: { 'Content-Type': 'application/wasm' } })
22
+ const x = await WebAssembly.instantiateStreaming(response, {})
23
+ window.${file.match(/([^\/]+).wasm$/)[1]} = x.instance.exports
24
+ })()
25
+ window.wasm_ready = window.wasm_ready ? Promise.all([window.wasm_ready, ready]) : ready
26
+ </script>`; break
27
+ case 'json':
28
+ `<script ${id ? `id="${id}"` : ''}>
29
+ const ready = (async () => {
30
+ const raw = await fetch("data:application/octet-stream;base64,${read(file, 'compressed-base64')}")
31
+ const blob = await raw.blob()
32
+ const decompressed = await blob.stream().pipeThrough(new DecompressionStream("deflate-raw"))
33
+ const response = new Response(decompressed, { headers: { 'Content-Type': 'application/json' } })
34
+ window.${file.match(/([^\/]+).json$/)[1]} = await response.json()
35
+ })()
36
+ window.json_ready = window.json_ready ? Promise.all([window.json_ready, ready]) : ready
37
+ </script>`; break
38
+ default:
39
+ content; break
40
+ }
41
+
42
+ [img]=
43
+ const {opts, args: [file, alt]} = std_call()
44
+ const classes = opts.join(' ')
45
+ const mimesuf = extname(file) == 'svg' ? 'svg+xml' : extname(file)
46
+ const content = `data:image/${mimesuf};base64,` + read(file, 'base64')
47
+ const htmltag = `<img class="${classes}" src="${content}" alt="${alt || ''}"/>`
48
+ opts.includes('center') ? `<div style="text-align:center">${htmltag}</div>` : htmltag
49
+
50
+ [h2]= `<h2>${interpret(capture_until('\n'))}</h2>`
51
+ [h3]= `<h3>${interpret(capture_until('\n'))}</h3>`
52
+ [h4]= `<h4>${interpret(capture_until('\n'))}</h4>`
53
+
54
+ [quote]=
55
+ const {opts, block} = std_call(true)
56
+ ;`<blockquote class="${opts.join(' ')}">${interpret(block)}</blockquote>`
57
+
58
+ [#]= std_call(true), ''
59
+
60
+ [-]=
61
+ const {opts, block} = std_call(true)
62
+ ;`<li class="${opts.join(' ')}">${interpret(block)}</li>`
63
+
64
+ [file]=
65
+ const {args: [file, text]} = std_call()
66
+ const content = "data:application/octet-stream;base64," + read(file, 'base64')
67
+ ;`<a download="${basename(file)}" href="${content}">${text ? interpret(text) : basename(file)}</a>`
68
+
69
+ [code]=
70
+ const {opts: [language], args: [content], block} = std_call()
71
+ const code = `<code ${language ? `class="language-${language}"` : ''}>${content || block.slice(1)}</code>`
72
+ content ? code : `<pre>${code}</pre>`
73
+
74
+ [link]=
75
+ const {opts: [id], args: [href, text]} = std_call()
76
+ const content = text || capture_until('\n').trim() || href
77
+ ;`<a ${id ? `id="${id}"` : ''} href="${href}">${interpret(content)}</a>`
78
+
79
+ [sup]=
80
+ const {args: [text]} = std_call()
81
+ ;`<sup>${interpret(text)}</sup>`
82
+
83
+ [eval]=
84
+ const {block} = std_call(true)
85
+ eval(block)
86
+
87
+ [eval*]=
88
+ const {block} = std_call(true)
89
+ eval(block); ''
90
+
91
+ [cn]=
92
+ interpret(std_call().block)
93
+ .replace(/([\u4E00-\u9FCC\u3400-\u4DB5\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\ud840-\ud868][\udc00-\udfff]|\ud869[\udc00-\uded6\udf00-\udfff]|[\ud86a-\ud86c][\udc00-\udfff]|\ud86d[\udc00-\udf34\udf40-\udfff]|\ud86e[\udc00-\udc1d])\r?\n(?=\S)/g, '$1')
94
+ .replace(/(?<=\S)\r?\n([\u4E00-\u9FCC\u3400-\u4DB5\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\ud840-\ud868][\udc00-\udfff]|\ud869[\udc00-\uded6\udf00-\udfff]|[\ud86a-\ud86c][\udc00-\udfff]|\ud86d[\udc00-\udf34\udf40-\udfff]|\ud86e[\udc00-\udc1d])/g, '$1')
package/dist/form.css ADDED
@@ -0,0 +1,87 @@
1
+ html {
2
+ font-family: sans-serif;
3
+ font-size: 16px;
4
+ line-height: 1.5;
5
+ text-align: justify;
6
+ hyphens: auto;
7
+ color: #33333d;
8
+ }
9
+ @media (max-width: 425px) {
10
+ html {
11
+ font-size: 15px;
12
+ }
13
+ }
14
+ body {
15
+ max-width: 625px;
16
+ margin: 0 auto;
17
+ padding: 1rem 1rem;
18
+ }
19
+ @media (max-width: 425px) {
20
+ body {
21
+ padding: 0 0.8rem;
22
+ }
23
+ }
24
+ h3 {
25
+ margin: 2rem 0 1rem;
26
+ position: relative;
27
+ border-bottom: #bbb 1px solid;
28
+ }
29
+ label {
30
+ display: block;
31
+ font-weight: 500;
32
+ font-size: 0.9rem;
33
+ }
34
+ label input:not([type]),
35
+ label input[type="text"],
36
+ label input[type="number"] {
37
+ display: block;
38
+ width: 100%;
39
+ margin: 0.1rem 0 1rem;
40
+ padding: 0.4rem;
41
+ border: 1px solid #bbb;
42
+ border-radius: 3px;
43
+ font-size: 0.9rem;
44
+ box-sizing: border-box;
45
+ }
46
+ label input[type="checkbox"] {
47
+ margin: 0.1rem 0.5rem 1rem 0;
48
+ transform: translateY(0.1rem);
49
+ }
50
+ button {
51
+ display: inline-block;
52
+ appearance: none;
53
+ background-color: transparent;
54
+ border: 1px solid #bbb;
55
+ border-radius: 0.375rem;
56
+ cursor: pointer;
57
+ line-height: 100%;
58
+ padding: 0.6rem 0.8rem;
59
+ }
60
+ button:active {
61
+ border-color: #4a4a4a;
62
+ outline: 0;
63
+ }
64
+ button:focus {
65
+ border-color: #485fc7;
66
+ outline: 0;
67
+ }
68
+ button:hover {
69
+ border-color: #b5b5b5;
70
+ }
71
+ button:focus:not(:active) {
72
+ box-shadow: rgba(72, 95, 199, 0.25) 0 0 0 0.125rem;
73
+ }
74
+ pre {
75
+ clear: both;
76
+ margin-top: 1rem;
77
+ font-family: monospace;
78
+ color: #222;
79
+ border: 1px solid #bcd;
80
+ background-color: #ebf1f5;
81
+ padding: 0.8rem;
82
+ overflow-x: auto;
83
+ font-size: 0.8rem;
84
+ }
85
+ .hidden {
86
+ opacity: 0;
87
+ }
package/dist/form.js ADDED
@@ -0,0 +1,64 @@
1
+ function gather_inputs() {
2
+ const args = Object.create(null)
3
+
4
+ for (const e of document.querySelectorAll('input')) {
5
+ switch (e.type) {
6
+ case 'text':
7
+ args[e.name] = e.value
8
+ break;
9
+ case 'number':
10
+ args[e.name] = parseFloat(e.value)
11
+ break;
12
+ case 'checkbox':
13
+ args[e.name] = e.checked
14
+ break;
15
+ }
16
+ }
17
+
18
+ return args
19
+ }
20
+
21
+ window.addEventListener('load', async () => {
22
+ document.querySelector('button').addEventListener('click', async () => {
23
+ document.querySelector('pre').classList.remove('hidden')
24
+ document.querySelector('button').disabled = true
25
+ await new Promise(res => setTimeout(res, 0))
26
+
27
+ const args = gather_inputs()
28
+
29
+ try {
30
+ const result = await run(args)
31
+ if (result)
32
+ document.querySelector('pre').textContent = result
33
+ } catch (e) {
34
+ document.querySelector('pre').textContent = "Error: " + (e.message ?? e)
35
+ throw e
36
+ } finally {
37
+ document.querySelector('button').disabled = false
38
+ await new Promise(res => setTimeout(res, 0))
39
+ }
40
+ })
41
+
42
+ document.body.addEventListener('input', () => {
43
+ const url_params = new URLSearchParams(gather_inputs())
44
+ history.replaceState(null, '', '#' + url_params.toString())
45
+ })
46
+
47
+ if (location.hash.length > 1) {
48
+ const url_params = new URLSearchParams(location.hash.slice(1))
49
+ for (const [name, value] of url_params.entries()) {
50
+ const e = document.querySelector(`input[name="${name}"]`)
51
+ if (!e) continue
52
+
53
+ switch (e.type) {
54
+ case 'text':
55
+ case 'number':
56
+ e.value = value
57
+ break;
58
+ case 'checkbox':
59
+ e.checked = value == 'true'
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ })
package/dist/form.ymd ADDED
@@ -0,0 +1,36 @@
1
+ <!doctype html>
2
+ <meta name=viewport content="width=device-width, initial-scale=1.0">
3
+ <meta name=author content="ylxdzsw@gmail.com">
4
+ <meta charset="utf-8">
5
+ <title>[title] | ylxdzsw's blog</title>
6
+
7
+ <style>
8
+ [mixin] form.css
9
+ </style>
10
+
11
+ <script>
12
+ [mixin] form.js
13
+ </script>
14
+
15
+ [#slot]
16
+
17
+ <button>Run</button>
18
+ <pre class="hidden"></pre>
19
+
20
+ [h3]=
21
+ const {block: content} = std_call(true)
22
+ ;`<h3>${content}</h3>`
23
+
24
+ [text]=
25
+ const {opts: [name], args: [attr=""], block: desc} = std_call(true)
26
+ ;`<label>${interpret(desc).trim()}<input name="${name}" ${attr}></input></label>`
27
+
28
+ [number]=
29
+ const {opts: [name], args: [attr=""], block: desc} = std_call(true)
30
+ ;`<label>${interpret(desc).trim()}<input type="number" name="${name}" ${attr}></input></label>`
31
+
32
+ [checkbox]=
33
+ const {opts: [name], args: [attr=""], block: desc} = std_call(true)
34
+ ;`<label><input type="checkbox" name="${name}" ${attr}></input>${interpret(desc).trim()}</label>`
35
+
36
+ [mixin] common.ymd