sdocs-dev 1.1.1 → 1.2.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 +21 -0
- package/bin/sdocs-dev.js +93 -12
- package/package.json +4 -1
- package/public/brotli-wasm.js +519 -0
- package/public/brotli_wasm_bg.wasm +0 -0
- package/public/css/layout.css +4 -1
- package/public/css/mobile.css +1 -1
- package/public/css/rendered.css +12 -1
- package/public/css/tokens.css +5 -2
- package/public/default.md +123 -94
- package/public/fonts/inter-400.woff2 +0 -0
- package/public/fonts/inter-500.woff2 +0 -0
- package/public/fonts/inter-600.woff2 +0 -0
- package/public/images/examples.png +0 -0
- package/public/index.html +21 -7
- package/public/sdocs-app.js +79 -31
- package/public/sdocs-controls.js +26 -39
- package/public/sdocs-export.js +2 -1
- package/public/sdocs-styles.js +85 -1
- package/public/sdocs-theme.js +7 -1
- package/public/sw.js +108 -0
- package/public/vendor/marked.min.js +6 -0
- package/server.js +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Josh Summers
|
|
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.
|
package/bin/sdocs-dev.js
CHANGED
|
@@ -14,8 +14,51 @@ const path = require('path');
|
|
|
14
14
|
const zlib = require('zlib');
|
|
15
15
|
const { execSync } = require('child_process');
|
|
16
16
|
const SDocYaml = require('../public/sdocs-yaml.js');
|
|
17
|
+
const SDocStyles = require('../public/sdocs-styles.js');
|
|
18
|
+
|
|
19
|
+
const https = require('https');
|
|
20
|
+
const os = require('os');
|
|
17
21
|
|
|
18
22
|
const DEFAULT_URL = 'https://sdocs.dev';
|
|
23
|
+
const VERSION = require('../package.json').version;
|
|
24
|
+
|
|
25
|
+
// ── Update check (cached, every 3 days) ──────────────────
|
|
26
|
+
|
|
27
|
+
const UPDATE_CACHE = path.join(os.homedir(), '.config', 'sdocs-dev', 'update-check.json');
|
|
28
|
+
const THREE_DAYS = 3 * 86400000;
|
|
29
|
+
|
|
30
|
+
function checkForUpdate() {
|
|
31
|
+
if (!process.stdout.isTTY || process.env.NO_UPDATE_NOTIFIER || process.env.CI) return;
|
|
32
|
+
|
|
33
|
+
// Skip if checked recently
|
|
34
|
+
try {
|
|
35
|
+
if (Date.now() - fs.statSync(UPDATE_CACHE).mtimeMs < THREE_DAYS) return;
|
|
36
|
+
} catch (_) {}
|
|
37
|
+
|
|
38
|
+
console.log('Checking for updates...');
|
|
39
|
+
https.get('https://registry.npmjs.org/-/package/sdocs-dev/dist-tags', { timeout: 3000 }, res => {
|
|
40
|
+
let data = '';
|
|
41
|
+
res.on('data', chunk => { data += chunk; });
|
|
42
|
+
res.on('end', () => {
|
|
43
|
+
try {
|
|
44
|
+
const latest = JSON.parse(data).latest;
|
|
45
|
+
// Update cache timestamp
|
|
46
|
+
fs.mkdirSync(path.dirname(UPDATE_CACHE), { recursive: true });
|
|
47
|
+
fs.writeFileSync(UPDATE_CACHE, JSON.stringify({ latest }));
|
|
48
|
+
|
|
49
|
+
const a = latest.split('.').map(Number);
|
|
50
|
+
const b = VERSION.split('.').map(Number);
|
|
51
|
+
let newer = false;
|
|
52
|
+
for (let i = 0; i < 3; i++) { if (a[i] > b[i]) { newer = true; break; } if (a[i] < b[i]) break; }
|
|
53
|
+
if (newer) {
|
|
54
|
+
console.log(`Update available: ${VERSION} \u2192 ${latest} \u2014 run \`npm i -g sdocs-dev\` to update`);
|
|
55
|
+
} else {
|
|
56
|
+
console.log(`Up to date (v${VERSION})`);
|
|
57
|
+
}
|
|
58
|
+
} catch (_) {}
|
|
59
|
+
});
|
|
60
|
+
}).on('error', () => {}).on('timeout', function () { this.destroy(); });
|
|
61
|
+
}
|
|
19
62
|
|
|
20
63
|
// ── Help ───────────────────────────────────────────────────
|
|
21
64
|
const HELP = `
|
|
@@ -46,6 +89,8 @@ MODE FLAGS
|
|
|
46
89
|
|
|
47
90
|
OPTIONS
|
|
48
91
|
--section <heading> Scroll to heading section on load
|
|
92
|
+
--light Open in light theme
|
|
93
|
+
--dark Open in dark theme
|
|
49
94
|
--url <base> Custom base URL (default: https://sdocs.dev)
|
|
50
95
|
--mode <m> Alias for --read / --write / --style / --raw
|
|
51
96
|
|
|
@@ -84,7 +129,7 @@ GENERAL
|
|
|
84
129
|
baseFontSize number Base font size in px. All rem/em values scale from this.
|
|
85
130
|
Default: 16
|
|
86
131
|
background string Page background color (hex).
|
|
87
|
-
Default: "#ffffff" (light) / "#
|
|
132
|
+
Default: "#ffffff" (light) / "#2c2a26" (dark)
|
|
88
133
|
color string Master body text color (hex). Cascades to headings,
|
|
89
134
|
paragraphs, and lists unless those are overridden.
|
|
90
135
|
Default: "#1c1917"
|
|
@@ -135,6 +180,7 @@ BLOCKQUOTE
|
|
|
135
180
|
blockquote:
|
|
136
181
|
borderColor string Left border accent color. Default: "#2563eb"
|
|
137
182
|
borderWidth number Left border thickness (px). Default: 3
|
|
183
|
+
background string Quote background color. Default: "#f7f5f2"
|
|
138
184
|
color string Quote text color. Default: "#6b6560"
|
|
139
185
|
|
|
140
186
|
COLOR CASCADE
|
|
@@ -158,7 +204,7 @@ THEME COLORS
|
|
|
158
204
|
h1: { color: "#c0392b" }
|
|
159
205
|
link: { color: "#2563eb" }
|
|
160
206
|
dark:
|
|
161
|
-
background: "#
|
|
207
|
+
background: "#2c2a26"
|
|
162
208
|
color: "#e7e5e2"
|
|
163
209
|
h1: { color: "#ef6f5e" }
|
|
164
210
|
link: { color: "#60a5fa" }
|
|
@@ -190,7 +236,7 @@ EXAMPLE — editorial article with colored heading tiers
|
|
|
190
236
|
h2: { color: "#8e44ad" }
|
|
191
237
|
h3: { color: "#16a085" }
|
|
192
238
|
link: { color: "#e67e22", decoration: "underline" }
|
|
193
|
-
blockquote: { borderColor: "#c0392b",
|
|
239
|
+
blockquote: { borderColor: "#c0392b", background: "#faf0eb", color: "#7f8c8d" }
|
|
194
240
|
dark:
|
|
195
241
|
background: "#1a1520"
|
|
196
242
|
color: "#e7e5e2"
|
|
@@ -199,25 +245,41 @@ EXAMPLE — editorial article with colored heading tiers
|
|
|
199
245
|
h2: { color: "#c490e4" }
|
|
200
246
|
h3: { color: "#5ed4b8" }
|
|
201
247
|
link: { color: "#f0a860", decoration: "underline" }
|
|
202
|
-
blockquote: { borderColor: "#ef6f5e",
|
|
248
|
+
blockquote: { borderColor: "#ef6f5e", background: "#221a28", color: "#9e9590" }
|
|
203
249
|
---
|
|
204
250
|
`;
|
|
205
251
|
|
|
206
|
-
// ── Compression (
|
|
252
|
+
// ── Compression (brotli + base64url) ─────────────────
|
|
207
253
|
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
return deflated.toString('base64')
|
|
254
|
+
function toBase64Url(buf) {
|
|
255
|
+
return Buffer.from(buf).toString('base64')
|
|
211
256
|
.replace(/\+/g, '-')
|
|
212
257
|
.replace(/\//g, '_')
|
|
213
258
|
.replace(/=+$/, '');
|
|
214
259
|
}
|
|
215
260
|
|
|
216
|
-
function
|
|
261
|
+
function fromBase64Url(b64url) {
|
|
217
262
|
let b64 = b64url.replace(/-/g, '+').replace(/_/g, '/');
|
|
218
263
|
const pad = (4 - b64.length % 4) % 4;
|
|
219
264
|
b64 += '='.repeat(pad);
|
|
220
|
-
return
|
|
265
|
+
return Buffer.from(b64, 'base64');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function compressToBase64Url(text) {
|
|
269
|
+
const compressed = zlib.brotliCompressSync(Buffer.from(text, 'utf-8'), {
|
|
270
|
+
params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 11 }
|
|
271
|
+
});
|
|
272
|
+
return toBase64Url(compressed);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function decompressFromBase64Url(b64url) {
|
|
276
|
+
const buf = fromBase64Url(b64url);
|
|
277
|
+
// Try brotli first, fall back to deflate for old URLs
|
|
278
|
+
try {
|
|
279
|
+
return zlib.brotliDecompressSync(buf).toString('utf-8');
|
|
280
|
+
} catch (_) {
|
|
281
|
+
return zlib.inflateRawSync(buf).toString('utf-8');
|
|
282
|
+
}
|
|
221
283
|
}
|
|
222
284
|
|
|
223
285
|
// ── Slugify ───────────────────────────────────────────────
|
|
@@ -237,6 +299,7 @@ function parseArgs(argv) {
|
|
|
237
299
|
let url = null;
|
|
238
300
|
let subcommand = null;
|
|
239
301
|
let section = null;
|
|
302
|
+
let theme = null;
|
|
240
303
|
let resetFlag = false;
|
|
241
304
|
|
|
242
305
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -251,6 +314,8 @@ function parseArgs(argv) {
|
|
|
251
314
|
if (arg === '--style') { mode = 'style'; continue; }
|
|
252
315
|
if (arg === '--raw') { mode = 'raw'; continue; }
|
|
253
316
|
if (arg === '--read') { mode = 'read'; continue; }
|
|
317
|
+
if (arg === '--light') { theme = 'light'; continue; }
|
|
318
|
+
if (arg === '--dark') { theme = 'dark'; continue; }
|
|
254
319
|
|
|
255
320
|
// Long-form --mode
|
|
256
321
|
if (arg === '--mode' || arg === '-m') {
|
|
@@ -280,7 +345,7 @@ function parseArgs(argv) {
|
|
|
280
345
|
if (!file) { file = arg; continue; }
|
|
281
346
|
}
|
|
282
347
|
|
|
283
|
-
return { file, mode, url, subcommand, section, resetFlag };
|
|
348
|
+
return { file, mode, url, subcommand, section, theme, resetFlag };
|
|
284
349
|
}
|
|
285
350
|
|
|
286
351
|
// ── Build URL ─────────────────────────────────────────────
|
|
@@ -290,6 +355,17 @@ function buildUrl(content, opts) {
|
|
|
290
355
|
const params = new URLSearchParams();
|
|
291
356
|
|
|
292
357
|
if (content) {
|
|
358
|
+
// Strip default style values to produce shorter URLs
|
|
359
|
+
const parsed = SDocYaml.parseFrontMatter(content);
|
|
360
|
+
if (parsed.meta && parsed.meta.styles) {
|
|
361
|
+
const stripped = SDocStyles.stripStyleDefaults(parsed.meta.styles);
|
|
362
|
+
if (Object.keys(stripped).length > 0) {
|
|
363
|
+
parsed.meta.styles = stripped;
|
|
364
|
+
} else {
|
|
365
|
+
delete parsed.meta.styles;
|
|
366
|
+
}
|
|
367
|
+
content = SDocYaml.serializeFrontMatter(parsed.meta) + '\n' + parsed.body;
|
|
368
|
+
}
|
|
293
369
|
params.set('md', compressToBase64Url(content));
|
|
294
370
|
} else if (opts.defaultStyles) {
|
|
295
371
|
const stylesJson = JSON.stringify(opts.defaultStyles);
|
|
@@ -299,6 +375,8 @@ function buildUrl(content, opts) {
|
|
|
299
375
|
const mode = opts.mode || (content ? 'read' : 'style');
|
|
300
376
|
if (mode && mode !== 'read') params.set('mode', mode);
|
|
301
377
|
|
|
378
|
+
if (opts.theme) params.set('theme', opts.theme);
|
|
379
|
+
|
|
302
380
|
if (opts.section) {
|
|
303
381
|
params.set('sec', slugify(opts.section));
|
|
304
382
|
}
|
|
@@ -457,6 +535,7 @@ if (require.main === module) {
|
|
|
457
535
|
const url = buildUrl(content, {
|
|
458
536
|
url: opts.url,
|
|
459
537
|
mode: opts.mode,
|
|
538
|
+
theme: opts.theme,
|
|
460
539
|
defaultStyles: !content ? defaults : null,
|
|
461
540
|
section: opts.section,
|
|
462
541
|
});
|
|
@@ -473,12 +552,14 @@ if (require.main === module) {
|
|
|
473
552
|
} catch (_) {
|
|
474
553
|
process.stdout.write(url + '\n');
|
|
475
554
|
}
|
|
476
|
-
|
|
555
|
+
checkForUpdate();
|
|
556
|
+
return;
|
|
477
557
|
}
|
|
478
558
|
|
|
479
559
|
// Default: open browser
|
|
480
560
|
openBrowser(url);
|
|
481
561
|
console.log(`SDocs → ${url.length > 80 ? url.slice(0, 77) + '...' : url}`);
|
|
562
|
+
checkForUpdate();
|
|
482
563
|
})().catch(e => {
|
|
483
564
|
console.error('sdoc:', e.message);
|
|
484
565
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdocs-dev",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Open, share, and style markdown files from the terminal",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://sdocs.dev",
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"brotli": "^1.3.3",
|
|
36
|
+
"brotli-dec-wasm": "^2.3.2",
|
|
37
|
+
"brotli-wasm": "^3.0.1",
|
|
35
38
|
"marked": "^11.0.0"
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|