decklight 0.9.0 → 0.11.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/NOTICE +2 -0
- package/PLATFORM.md +61 -3
- package/README.md +58 -28
- package/SPEC.md +1326 -85
- package/cli/agent-review.mjs +5 -4
- package/cli/agents.mjs +148 -18
- package/cli/bundle-audio.mjs +10 -3
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +125 -7
- package/cli/cast.mjs +86 -19
- package/cli/check-fixes.mjs +194 -0
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +491 -75
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-flow.mjs +7 -3
- package/cli/commit-message.mjs +35 -8
- package/cli/commit-split.mjs +125 -25
- package/cli/deck-refs.mjs +8 -3
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/design-system-refs.mjs +263 -6
- package/cli/design-system.mjs +82 -14
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +23 -6
- package/cli/edit-handover.mjs +257 -40
- package/cli/edit-look.mjs +293 -6
- package/cli/edit-open.mjs +143 -0
- package/cli/edit-slides.mjs +1043 -67
- package/cli/edit-translate.mjs +243 -0
- package/cli/edit.mjs +3680 -319
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +157 -27
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/git.mjs +13 -0
- package/cli/init.mjs +101 -22
- package/cli/keep-awake.mjs +68 -0
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +250 -13
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +121 -5
- package/cli/open.mjs +53 -15
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +88 -10
- package/cli/pptx-export.mjs +10 -5
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +86 -15
- package/cli/remote.mjs +32 -6
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +9 -6
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +251 -10
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +282 -15
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme-refs.mjs +14 -2
- package/cli/theme.mjs +3 -2
- package/cli/translate-core.mjs +466 -0
- package/cli/translate-files.mjs +149 -0
- package/cli/translate.mjs +458 -0
- package/cli/units.mjs +75 -7
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2506 -113
- package/dist/decklight.js +385 -175
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +9 -2
- package/docs/WRITING_RESEARCH.md +327 -0
- package/package.json +5 -3
- package/themes/coastal.css +3 -0
- package/themes/metropolis.css +2 -0
- package/themes/reveal-blood.css +3 -0
- package/themes/reveal-league.css +2 -0
- package/themes/reveal-moon.css +2 -0
- package/themes/reveal-serif.css +1 -0
- package/themes/reveal-sky.css +1 -0
- package/themes/reveal-solarized.css +4 -0
- package/tools/brand-palette.mjs +6 -1
- package/tools/build-groups.mjs +28 -8
- package/tools/cdp.mjs +176 -0
- package/tools/chart-spec.mjs +242 -0
- package/tools/click-match.mjs +70 -0
- package/tools/code-options.mjs +174 -0
- package/tools/conversation.mjs +49 -0
- package/tools/deck-family.mjs +101 -0
- package/tools/deck-html.mjs +212 -15
- package/tools/design-system-format.mjs +40 -1
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/exec.mjs +10 -2
- package/tools/face-clip.mjs +96 -0
- package/tools/face-layout.mjs +94 -0
- package/tools/gemini-tts.mjs +1 -1
- package/tools/invisible-in-print.mjs +27 -0
- package/tools/lipsync-auto.mjs +197 -0
- package/tools/lipsync-config.mjs +16 -0
- package/tools/lipsync-engines.mjs +22 -4
- package/tools/lipsync-server.mjs +8 -5
- package/tools/lipsync.mjs +122 -30
- package/tools/local-voice.mjs +1 -1
- package/tools/mouth-file.mjs +26 -0
- package/tools/mouth.mjs +320 -0
- package/tools/narration-manifest.mjs +100 -6
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/site-clip.mjs +114 -0
- package/tools/starters.mjs +402 -0
- package/tools/steps.mjs +118 -0
- package/tools/take-check.mjs +146 -0
- package/tools/template-theme.mjs +3 -1
- package/tools/test-impact.mjs +36 -12
- package/tools/theme-check.mjs +196 -1
- package/tools/tone-cue.mjs +108 -0
- package/tools/tts-cache.mjs +9 -3
- package/tools/tts-engines.mjs +100 -11
- package/tools/video-cache.mjs +93 -0
- package/tools/video-live.mjs +349 -0
- package/tools/video-options.mjs +11 -0
- package/tools/video.mjs +825 -117
- package/tools/viseme-fit.mjs +27 -0
- package/tools/viseme-match.mjs +77 -0
- package/tools/vocabulary.mjs +397 -0
- package/tools/voice-renumber.mjs +605 -0
- package/tools/voiceover-server.mjs +42 -11
- package/tools/voiceover.mjs +48 -20
- package/dist/build-info.json +0 -1
package/cli/runtime-link.mjs
CHANGED
|
@@ -291,23 +291,194 @@ export function setDeckConcepts(html, concepts) {
|
|
|
291
291
|
clean[name] = v;
|
|
292
292
|
}
|
|
293
293
|
const valueText = Object.keys(clean).length ? '{ ' + Object.entries(clean).map(([k, v]) => `"${k}": ${JSON.stringify(v)}`).join(', ') + ' }' : null;
|
|
294
|
+
return withDeckConfigText(html, (text) => withObjectKey(text, 'concepts', valueText));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Where this deck carries its configuration, so it can be rewritten in place:
|
|
299
|
+
* `{ kind: 'block', block }` for the configuration block (a deck that is
|
|
300
|
+
* data), `{ kind: 'boot', boot }` for a bundle's `Decklight.init({…})` whose
|
|
301
|
+
* argument is a plain-data literal; or `{ why }`, one sentence saying why it
|
|
302
|
+
* cannot be (a block that is not JSON, an init call that is code or booted
|
|
303
|
+
* from a separate script, no configuration at all).
|
|
304
|
+
*/
|
|
305
|
+
export function deckConfigSource(html) {
|
|
294
306
|
const block = configBlock(html);
|
|
295
|
-
if (block) {
|
|
296
|
-
if (!block.config) return null;
|
|
297
|
-
const inner = withObjectKey(block.inner, 'concepts', valueText);
|
|
298
|
-
if (inner === null) return null;
|
|
299
|
-
return html.slice(0, block.innerStart) + inner + html.slice(block.innerEnd);
|
|
300
|
-
}
|
|
307
|
+
if (block) return block.config ? { kind: 'block', block, config: block.config } : { why: `its configuration block cannot be read: ${block.error}` };
|
|
301
308
|
const boot = bootCall(html);
|
|
302
|
-
if (!boot)
|
|
309
|
+
if (!boot) {
|
|
310
|
+
return /<script\b[^>]*\bsrc\s*=[^>]*>/i.test(html) && /Decklight\s*\.\s*init\b/.test(html) === false
|
|
311
|
+
? { why: 'it is booted from a separate script, so its configuration is not in this file' }
|
|
312
|
+
: { why: 'its configuration is not in a form this editor rewrites: no configuration block, and no Decklight.init({…}) of plain data' };
|
|
313
|
+
}
|
|
303
314
|
const lit = parseLiteral(boot.arg);
|
|
304
|
-
if (!lit
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
315
|
+
if (!lit) return { why: 'its Decklight.init(…) is code, not plain data, so it is the author’s to edit' };
|
|
316
|
+
return { kind: 'boot', boot, config: lit.value };
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* `html` with its configuration's text rewritten by `edit(text)` (the block's
|
|
321
|
+
* JSON, or the init call's literal), spliced in place so nothing else in the
|
|
322
|
+
* file moves. Null when the deck carries its configuration in neither way, or
|
|
323
|
+
* `edit` gives null.
|
|
324
|
+
*/
|
|
325
|
+
function withDeckConfigText(html, edit) {
|
|
326
|
+
const src = deckConfigSource(html);
|
|
327
|
+
if (src.kind === 'block') {
|
|
328
|
+
const inner = edit(src.block.inner);
|
|
329
|
+
return inner === null ? null : html.slice(0, src.block.innerStart) + inner + html.slice(src.block.innerEnd);
|
|
330
|
+
}
|
|
331
|
+
if (src.kind === 'boot') {
|
|
332
|
+
const { boot } = src;
|
|
333
|
+
const call = html.slice(boot.start, boot.end);
|
|
334
|
+
const argStart = call.indexOf(boot.arg);
|
|
335
|
+
if (argStart === -1) return null;
|
|
336
|
+
const arg = edit(boot.arg);
|
|
337
|
+
if (arg === null) return null;
|
|
338
|
+
return html.slice(0, boot.start) + call.slice(0, argStart) + arg + call.slice(argStart + boot.arg.length) + html.slice(boot.end);
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* `html` with each top-level configuration key in `set` written (a JSON
|
|
345
|
+
* value) or taken off (null), in the block or the init literal, spliced in
|
|
346
|
+
* place. Null when the deck carries its configuration in neither way. For
|
|
347
|
+
* keys Deck settings… does not own (`languages`, `translationOf`: SPEC
|
|
348
|
+
* TRANSLATIONS), so there is no rule here about what each takes.
|
|
349
|
+
*/
|
|
350
|
+
export function withConfigKeys(html, set) {
|
|
351
|
+
return withDeckConfigText(html, (text) => {
|
|
352
|
+
let next = text;
|
|
353
|
+
for (const [key, value] of Object.entries(set)) {
|
|
354
|
+
next = withObjectKey(next, key, value === null || value === undefined ? null : JSON.stringify(value));
|
|
355
|
+
if (next === null) return null;
|
|
356
|
+
}
|
|
357
|
+
return next;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** The value text of top-level `key` in an object literal's `text` (from after its colon), or null. */
|
|
362
|
+
function valueTextOf(text, key) {
|
|
363
|
+
const span = keySpan(text, key);
|
|
364
|
+
if (!span || span.keyStart === null) return null;
|
|
365
|
+
const colon = text.indexOf(':', span.keyStart);
|
|
366
|
+
let from = colon + 1;
|
|
367
|
+
while (/\s/.test(text[from])) from++;
|
|
368
|
+
return { from, to: span.valueEnd, text: text.slice(from, span.valueEnd) };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* What Deck settings… writes (PRESENTING_EDITING), each key with the one
|
|
373
|
+
* shape it takes and its default: a value set back to its default takes the
|
|
374
|
+
* key off the file. `narration.*` are the keys of the `narration` object;
|
|
375
|
+
* the object goes when its last key does.
|
|
376
|
+
*/
|
|
377
|
+
const LOGO_KEYS = ['onLight', 'onDark', 'src', 'height', 'position'];
|
|
378
|
+
const LOGO_POSITIONS = ['bottom-left', 'top-left', 'top-right', 'bottom-right'];
|
|
379
|
+
const relPath = (v) => typeof v === 'string' && v.length <= 200 && !/^(?:[a-z][a-z0-9+.-]*:|\/|#|<)/i.test(v) && !/(?:^|\/)\.\.(?:\/|$)/.test(v) && !/["'<>\\]/.test(v);
|
|
380
|
+
const pause = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 60;
|
|
381
|
+
export const DECK_SETTINGS = {
|
|
382
|
+
transition: { ok: (v) => ['none', 'fade', 'slide', 'scale', 'flip'].includes(v), dflt: 'fade' },
|
|
383
|
+
slideNumber: { ok: (v) => v === false || v === 'n' || v === 'n/N', dflt: false },
|
|
384
|
+
controls: { ok: (v) => typeof v === 'boolean', dflt: true },
|
|
385
|
+
pinTitles: { ok: (v) => typeof v === 'boolean' || (typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 2000), dflt: true },
|
|
386
|
+
logo: {
|
|
387
|
+
ok: (v) => v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).every((k) => LOGO_KEYS.includes(k))
|
|
388
|
+
&& ['onLight', 'onDark', 'src'].every((k) => v[k] === undefined || relPath(v[k]))
|
|
389
|
+
&& (v.onLight || v.onDark || v.src)
|
|
390
|
+
&& (v.height === undefined || (typeof v.height === 'number' && v.height >= 8 && v.height <= 400))
|
|
391
|
+
&& (v.position === undefined || LOGO_POSITIONS.includes(v.position)),
|
|
392
|
+
dflt: undefined,
|
|
393
|
+
},
|
|
394
|
+
'narration.character.position': { ok: (v) => ['br', 'bl', 'tl', 'tr'].includes(v), dflt: 'br' },
|
|
395
|
+
'narration.slidePause': { ok: pause, dflt: 1 },
|
|
396
|
+
'narration.beatPause': { ok: pause, dflt: 0.5 },
|
|
397
|
+
'narration.sentencePause': { ok: pause, dflt: 0.25 },
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* The deck's settings (`set`: `{ key: value | null }`, DECK_SETTINGS), each
|
|
402
|
+
* written in its place in the configuration block or the init literal: a
|
|
403
|
+
* value its default (or null) takes the key off. Throws on a key or a value
|
|
404
|
+
* it does not write; null when the deck's configuration cannot be rewritten
|
|
405
|
+
* (deckConfigSource says why).
|
|
406
|
+
*/
|
|
407
|
+
export function setDeckConfig(html, set) {
|
|
408
|
+
if (!set || typeof set !== 'object' || Array.isArray(set) || !Object.keys(set).length) throw new Error('bad set');
|
|
409
|
+
for (const [key, v] of Object.entries(set)) {
|
|
410
|
+
const rule = Object.hasOwn(DECK_SETTINGS, key) ? DECK_SETTINGS[key] : null;
|
|
411
|
+
if (!rule) throw new Error(`not a deck setting this server writes: ${String(key).slice(0, 40)}`);
|
|
412
|
+
if (v !== null && !rule.ok(v)) throw new Error(`not a value ${key} takes: ${JSON.stringify(v)?.slice(0, 60)}`);
|
|
413
|
+
}
|
|
414
|
+
const off = (key, v) => v === null || JSON.stringify(v) === JSON.stringify(DECK_SETTINGS[key].dflt);
|
|
415
|
+
return withDeckConfigText(html, (text) => {
|
|
416
|
+
let next = text;
|
|
417
|
+
for (const [key, value] of Object.entries(set)) {
|
|
418
|
+
next = withConfigKey(next, key.split('.'), off(key, value) ? null : JSON.stringify(value));
|
|
419
|
+
if (next === null) return null;
|
|
420
|
+
}
|
|
421
|
+
return next;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Splice a setting through its parent objects, pruning an emptied parent. */
|
|
426
|
+
function withConfigKey(text, [key, ...path], valueText) {
|
|
427
|
+
if (!path.length) return withObjectKey(text, key, valueText);
|
|
428
|
+
const had = valueTextOf(text, key);
|
|
429
|
+
if (had && !had.text.startsWith('{')) return null;
|
|
430
|
+
const next = withConfigKey(had?.text ?? '{}', path, valueText);
|
|
431
|
+
if (next === null) return null;
|
|
432
|
+
if (/^\{\s*\}$/.test(next)) return withObjectKey(text, key, null);
|
|
433
|
+
if (had) return text.slice(0, had.from) + next + text.slice(had.to);
|
|
434
|
+
return withObjectKey(text, key, next);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Text as it goes between `<title>` and `</title>`: `&` and `<` escaped, one line. */
|
|
438
|
+
const titleText = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* The page's `<title>`, set in place (the hud, a commit message and an export
|
|
442
|
+
* read it), or added at the top of `<head>`; an empty one is left empty.
|
|
443
|
+
*/
|
|
444
|
+
export function setDeckTitle(html, title) {
|
|
445
|
+
const t = String(title ?? '');
|
|
446
|
+
if (t.length > 200 || /[\u0000-\u001f\u007f]/.test(t)) throw new Error('a title is one line of up to 200 characters');
|
|
447
|
+
const masked = maskComments(html);
|
|
448
|
+
const m = /<title\b[^>]*>([\s\S]*?)<\/title>/i.exec(masked);
|
|
449
|
+
if (m) {
|
|
450
|
+
const at = m.index + m[0].indexOf('>') + 1;
|
|
451
|
+
return html.slice(0, at) + titleText(t) + html.slice(at + m[1].length);
|
|
452
|
+
}
|
|
453
|
+
const head = /<head\b[^>]*>/i.exec(masked);
|
|
454
|
+
if (!head) throw new Error('the deck has no <head> to put a title in');
|
|
455
|
+
const at = head.index + head[0].length;
|
|
456
|
+
const indent = /\n([ \t]*)\S/.exec(html.slice(at))?.[1] ?? ' ';
|
|
457
|
+
return html.slice(0, at) + `\n${indent}<title>${titleText(t)}</title>` + html.slice(at);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** The page's title as text (entities read), or ''. */
|
|
461
|
+
export function deckTitle(html) {
|
|
462
|
+
const m = /<title\b[^>]*>([\s\S]*?)<\/title>/i.exec(maskComments(html));
|
|
463
|
+
if (!m) return '';
|
|
464
|
+
const raw = html.slice(m.index, m.index + m[0].length).replace(/^<title\b[^>]*>/i, '').replace(/<\/title>$/i, '');
|
|
465
|
+
return raw.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, '&').trim();
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* What Deck settings… shows: the title, each setting as the file says it (the
|
|
470
|
+
* default where it says nothing), and whether it can be written here, with
|
|
471
|
+
* the one sentence saying why not.
|
|
472
|
+
*/
|
|
473
|
+
export function deckSettings(html) {
|
|
474
|
+
const src = deckConfigSource(html);
|
|
475
|
+
const cfg = src.config ?? {};
|
|
476
|
+
const values = {};
|
|
477
|
+
for (const [key, rule] of Object.entries(DECK_SETTINGS)) {
|
|
478
|
+
const v = key.split('.').reduce((obj, part) => obj?.[part], cfg);
|
|
479
|
+
values[key] = v === undefined ? (rule.dflt ?? null) : v;
|
|
480
|
+
}
|
|
481
|
+
return { title: deckTitle(html), values, editable: !src.why, why: src.why ?? null };
|
|
311
482
|
}
|
|
312
483
|
|
|
313
484
|
/**
|
|
@@ -378,9 +549,36 @@ export function firstExecutableScript(html) {
|
|
|
378
549
|
return null;
|
|
379
550
|
}
|
|
380
551
|
|
|
552
|
+
/**
|
|
553
|
+
* Does the document open with a doctype? Read past a byte-order mark,
|
|
554
|
+
* whitespace and comments, case-insensitively, as the HTML parser does.
|
|
555
|
+
* Without one a browser lays the page out in quirks mode, where a `<table>`
|
|
556
|
+
* takes neither the colour nor the size of the text around it (#1190).
|
|
557
|
+
*/
|
|
558
|
+
export function hasDoctype(html) {
|
|
559
|
+
const lead = /^\uFEFF?(?:\s|<!--[\s\S]*?-->)*/.exec(html)[0].length;
|
|
560
|
+
return /^<!doctype\s+html\b/i.test(html.slice(lead));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/** Where the document's prolog ends: past a byte-order mark, comments, whitespace and the doctype. */
|
|
564
|
+
const prologEnd = (html) => /^\uFEFF?(?:\s|<!--[\s\S]*?-->|<!doctype\b[^>]*>)*/i.exec(html)[0].length;
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* The document with `<!doctype html>` in front, after any byte-order mark,
|
|
568
|
+
* and unchanged when it already has one. Every server and every render adds
|
|
569
|
+
* it to a deck through `linkRuntime`, so a deck written as only its slides
|
|
570
|
+
* renders in standards mode; `bundle` keeps it in the file it writes.
|
|
571
|
+
*/
|
|
572
|
+
export function withDoctype(html) {
|
|
573
|
+
if (hasDoctype(html)) return html;
|
|
574
|
+
const bom = html.startsWith('\uFEFF') ? 1 : 0;
|
|
575
|
+
return `${html.slice(0, bom)}<!doctype html>\n${html.slice(bom)}`;
|
|
576
|
+
}
|
|
577
|
+
|
|
381
578
|
/**
|
|
382
579
|
* The document with the runtime referenced — and unchanged when it already
|
|
383
|
-
* is, or when it is not a deck.
|
|
580
|
+
* is, or when it is not a deck. A deck with no doctype gets one either way
|
|
581
|
+
* (`withDoctype`). Idempotent and ordered: the stylesheet and
|
|
384
582
|
* the theme go at the end of `<head>` (each only when the document has none
|
|
385
583
|
* of its own), the engine before the first script that executes — an
|
|
386
584
|
* author's own script, or a `Decklight.init` call kept as the JS API's
|
|
@@ -389,7 +587,9 @@ export function firstExecutableScript(html) {
|
|
|
389
587
|
* package (`packageAsset`), the same ones `init` used to write (#517).
|
|
390
588
|
*/
|
|
391
589
|
export function linkRuntime(html, { theme = null } = {}) {
|
|
392
|
-
if (!isDeck(html)
|
|
590
|
+
if (!isDeck(html)) return html;
|
|
591
|
+
html = withDoctype(html);
|
|
592
|
+
if (hasRuntime(html)) return html;
|
|
393
593
|
const head = [];
|
|
394
594
|
if (!hasRuntimeCss(html)) head.push('<link rel="stylesheet" href="decklight.css" data-decklight-runtime="css">');
|
|
395
595
|
if (!hasTheme(html)) head.push(`<link rel="stylesheet" href="themes/${theme ?? baseTheme(html)}.css">`);
|
|
@@ -398,7 +598,8 @@ export function linkRuntime(html, { theme = null } = {}) {
|
|
|
398
598
|
const masked = maskComments(out);
|
|
399
599
|
const headEnd = masked.search(/<\/head>/i);
|
|
400
600
|
const bodyAt = masked.search(/<body\b/i);
|
|
401
|
-
|
|
601
|
+
// with neither, after the doctype: anything ahead of it is quirks mode
|
|
602
|
+
const at = headEnd !== -1 ? headEnd : bodyAt !== -1 ? bodyAt : prologEnd(out);
|
|
402
603
|
out = `${out.slice(0, at)}${head.join('\n')}\n${out.slice(at)}`;
|
|
403
604
|
}
|
|
404
605
|
const engine = '<script src="decklight.js" data-decklight-runtime="js"></script>';
|
package/cli/serve.mjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { createServer } from 'node:http';
|
|
15
15
|
import { readFileSync, existsSync, statSync, createReadStream } from 'node:fs';
|
|
16
|
-
import { resolve, extname, sep } from 'node:path';
|
|
16
|
+
import { resolve, extname, sep, dirname, basename } from 'node:path';
|
|
17
17
|
import { timingSafeEqual } from 'node:crypto';
|
|
18
18
|
import { networkInterfaces } from 'node:os';
|
|
19
19
|
import { createInterface } from 'node:readline/promises';
|
|
@@ -227,7 +227,7 @@ function rangeOf(header, size) {
|
|
|
227
227
|
* this machine and never the network. Nothing else escapes root or answers
|
|
228
228
|
* for a missing path — a probe still learns nothing from a 404.
|
|
229
229
|
*/
|
|
230
|
-
export function staticFiles(root, { index = '/index.html', html: rewriteHtml = null, knownTypesOnly = false } = {}) {
|
|
230
|
+
export function staticFiles(root, { index = '/index.html', html: rewriteHtml = null, knownTypesOnly = false, media = null } = {}) {
|
|
231
231
|
return (req, res, url) => {
|
|
232
232
|
if (req.method !== 'GET') return false;
|
|
233
233
|
const rel = url.pathname === '/' ? index : decodeURIComponent(url.pathname);
|
|
@@ -239,7 +239,10 @@ export function staticFiles(root, { index = '/index.html', html: rewriteHtml = n
|
|
|
239
239
|
// else's package, so its namespace is TERMINAL: it is answered from the
|
|
240
240
|
// package or not at all, and every refusal is the same plain 404.
|
|
241
241
|
const owner = namespacedKind(rel);
|
|
242
|
-
if (
|
|
242
|
+
if (media?.has(rel)) {
|
|
243
|
+
file = media.get(rel);
|
|
244
|
+
type = MIME[extname(file).toLowerCase()];
|
|
245
|
+
} else if (owner) {
|
|
243
246
|
const asset = !dotted && owner.asset(rel);
|
|
244
247
|
if (!asset) { res.writeHead(404); res.end('not found'); return true; }
|
|
245
248
|
file = asset.file; type = asset.type; extra = asset.headers;
|
|
@@ -283,7 +286,7 @@ export function staticFiles(root, { index = '/index.html', html: rewriteHtml = n
|
|
|
283
286
|
// is a page; everything else streams below.
|
|
284
287
|
if (type === MIME['.html']) {
|
|
285
288
|
const text = readFileSync(file).toString('utf8');
|
|
286
|
-
const body = Buffer.from(linkReferences(linkRuntime(rewriteHtml ? rewriteHtml(text, file) : text)), 'utf8');
|
|
289
|
+
const body = Buffer.from(linkReferences(linkRuntime(rewriteHtml ? rewriteHtml(text, file) : text), { dir: dirname(file), deck: basename(file) }), 'utf8');
|
|
287
290
|
const want = rangeOf(req.headers.range, body.length);
|
|
288
291
|
if (want && !want.satisfiable) {
|
|
289
292
|
res.writeHead(416, { 'content-range': `bytes */${body.length}` });
|
|
@@ -479,8 +482,8 @@ export const CSP = [
|
|
|
479
482
|
* Returns `{ origin, close }` — `origin` is `http://127.0.0.1:<port>`, `close`
|
|
480
483
|
* resolves when the listener is shut.
|
|
481
484
|
*/
|
|
482
|
-
export async function serveForRender(root, { html = null } = {}) {
|
|
483
|
-
const files = staticFiles(root, { html });
|
|
485
|
+
export async function serveForRender(root, { html = null, media = null } = {}) {
|
|
486
|
+
const files = staticFiles(root, { html, media });
|
|
484
487
|
|
|
485
488
|
const server = createServer(withHeaders({ 'content-security-policy': CSP }, (req, res) => {
|
|
486
489
|
let url;
|
package/cli/setup.mjs
CHANGED
|
@@ -33,12 +33,12 @@ export const USAGE = `usage: decklight setup <voice | face> …
|
|
|
33
33
|
save exactly these, no questions: what used to be a flag on every
|
|
34
34
|
decklight <deck> run. A new --engine drops the old engine's voice,
|
|
35
35
|
model, format, stability and data dir.
|
|
36
|
-
EXAMPLE: decklight setup voice --engine elevenlabs --model
|
|
36
|
+
EXAMPLE: decklight setup voice --engine elevenlabs --model eleven_v4 --stability natural
|
|
37
37
|
|
|
38
38
|
decklight setup face --portrait me=<photo.jpg | clip.mp4> [--wav2lip-dir <checkout>
|
|
39
39
|
--wav2lip-ckpt <wav2lip_gan.pth>] [--sadtalker-dir <checkout>]
|
|
40
40
|
[--python <its venv python>]
|
|
41
|
-
remember a talking head for the narrator (V →
|
|
41
|
+
remember a talking head for the narrator (V → who is on screen): the portrait
|
|
42
42
|
and the local lip-sync models. Saved; decklight <deck> starts the
|
|
43
43
|
lip-sync bridge with it. A clip can also be filmed in the deck.
|
|
44
44
|
Also saved when given: --cache-dir, --rhubarb, and --veo (animate the
|