@bendyline/squisq 1.5.1 → 2.0.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/README.md +63 -10
- package/dist/{Doc-BBVGq1_9.d.ts → Doc-ylqWKDc_.d.ts} +248 -37
- package/dist/{ImageEditDoc-FuyGtt6o.d.ts → ImageEditDoc-D828IXJ1.d.ts} +1 -1
- package/dist/annotationCoercion-Dr_DY9Hx.d.ts +86 -0
- package/dist/{chunk-VWUFZ6ZG.js → chunk-3E5F2XMR.js} +2 -29
- package/dist/chunk-3E5F2XMR.js.map +1 -0
- package/dist/chunk-4X3JQXNM.js +35 -0
- package/dist/chunk-4X3JQXNM.js.map +1 -0
- package/dist/{chunk-2OIBZYKP.js → chunk-5DKBFXPY.js} +31 -121
- package/dist/chunk-5DKBFXPY.js.map +1 -0
- package/dist/{chunk-DLXZMS5K.js → chunk-5J4HKRJF.js} +51 -3
- package/dist/chunk-5J4HKRJF.js.map +1 -0
- package/dist/chunk-5UYI3RJB.js +2503 -0
- package/dist/chunk-5UYI3RJB.js.map +1 -0
- package/dist/{chunk-TEEEILMP.js → chunk-66QO7XFB.js} +19 -292
- package/dist/chunk-66QO7XFB.js.map +1 -0
- package/dist/{chunk-KKNUBQ6Y.js → chunk-6PJRB2CF.js} +156 -91
- package/dist/chunk-6PJRB2CF.js.map +1 -0
- package/dist/{chunk-HWVFJAAH.js → chunk-AMIR72JP.js} +28 -10
- package/dist/chunk-AMIR72JP.js.map +1 -0
- package/dist/chunk-FVJUUTEM.js +74 -0
- package/dist/chunk-FVJUUTEM.js.map +1 -0
- package/dist/{chunk-LH7I6SH7.js → chunk-GF3BVNLU.js} +6360 -5723
- package/dist/chunk-GF3BVNLU.js.map +1 -0
- package/dist/{chunk-Q3ROPT5H.js → chunk-GZY66SDN.js} +1 -1
- package/dist/{chunk-Q3ROPT5H.js.map → chunk-GZY66SDN.js.map} +1 -1
- package/dist/chunk-JOQYPRDZ.js +127 -0
- package/dist/chunk-JOQYPRDZ.js.map +1 -0
- package/dist/{chunk-A4O7GIWE.js → chunk-LYNJEOAC.js} +10 -73
- package/dist/chunk-LYNJEOAC.js.map +1 -0
- package/dist/{chunk-LDQ2HJIX.js → chunk-PXLVXTLW.js} +252 -54
- package/dist/chunk-PXLVXTLW.js.map +1 -0
- package/dist/{chunk-TQWLI6S2.js → chunk-Q7LROV2H.js} +4 -2
- package/dist/{chunk-TQWLI6S2.js.map → chunk-Q7LROV2H.js.map} +1 -1
- package/dist/{chunk-T5UK6YOB.js → chunk-QTSJOY54.js} +60 -17
- package/dist/chunk-QTSJOY54.js.map +1 -0
- package/dist/chunk-QVANWDPH.js +2358 -0
- package/dist/chunk-QVANWDPH.js.map +1 -0
- package/dist/{chunk-6ATE2PSM.js → chunk-R2GC6RLD.js} +7 -7
- package/dist/chunk-R2GC6RLD.js.map +1 -0
- package/dist/chunk-R2YZTCLO.js +292 -0
- package/dist/chunk-R2YZTCLO.js.map +1 -0
- package/dist/chunk-S7A5D7ZJ.js +174 -0
- package/dist/chunk-S7A5D7ZJ.js.map +1 -0
- package/dist/chunk-T3TI7GSZ.js +884 -0
- package/dist/chunk-T3TI7GSZ.js.map +1 -0
- package/dist/{chunk-RUDYOTA6.js → chunk-TUWMK62B.js} +110 -4
- package/dist/chunk-TUWMK62B.js.map +1 -0
- package/dist/{chunk-IMSCRLLV.js → chunk-VR7UPJ7C.js} +35 -25
- package/dist/chunk-VR7UPJ7C.js.map +1 -0
- package/dist/doc/index.d.ts +2334 -5
- package/dist/doc/index.js +134 -34
- package/dist/generate/index.d.ts +7 -2
- package/dist/generate/index.js +1 -1
- package/dist/imageEdit/index.d.ts +9 -6
- package/dist/imageEdit/index.js +3 -3
- package/dist/index.d.ts +12 -10
- package/dist/index.js +253 -81
- package/dist/jsonForm/index.d.ts +7 -3
- package/dist/jsonForm/index.js +9 -4
- package/dist/markdown/index.d.ts +6 -70
- package/dist/markdown/index.js +13 -9
- package/dist/narration/index.d.ts +618 -0
- package/dist/narration/index.js +82 -0
- package/dist/recommend/index.d.ts +15 -1
- package/dist/recommend/index.js +2 -2
- package/dist/schemas/index.d.ts +28 -6
- package/dist/schemas/index.js +15 -13
- package/dist/spatial/index.d.ts +0 -1
- package/dist/spatial/index.js +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/{themeLibrary-CehcJhzz.d.ts → themeLibrary-RjVgLpUi.d.ts} +10 -11
- package/dist/timing/index.js +5 -3
- package/dist/transform/index.d.ts +35 -24
- package/dist/transform/index.js +9 -10
- package/dist/{types-DlAZ7MW4.d.ts → types-BwMPl2CB.d.ts} +1 -1
- package/dist/{types-D98li1gV.d.ts → types-C4kiRn_k.d.ts} +3 -1
- package/dist/versions/index.d.ts +2 -1
- package/dist/versions/index.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/applyNarrationTiming.test.ts +190 -0
- package/src/__tests__/applyRenderStyle.test.ts +3 -3
- package/src/__tests__/asciiDiagramBattle.test.ts +246 -0
- package/src/__tests__/asciiDiagramDetect.test.ts +162 -0
- package/src/__tests__/asciiDiagramMapping.test.ts +38 -0
- package/src/__tests__/asciiDiagramParse.test.ts +233 -0
- package/src/__tests__/asciiDiagramPipeline.test.ts +273 -0
- package/src/__tests__/asciiDiagramRender.test.ts +162 -0
- package/src/__tests__/asciiDiagramRepair.test.ts +84 -0
- package/src/__tests__/asciiTimelineDetect.test.ts +157 -0
- package/src/__tests__/asciiTimelineParse.test.ts +205 -0
- package/src/__tests__/asciiTimelinePipeline.test.ts +349 -0
- package/src/__tests__/asciiTimelineRender.test.ts +376 -0
- package/src/__tests__/attrTokens.test.ts +5 -0
- package/src/__tests__/contentContainer.test.ts +43 -0
- package/src/__tests__/coverBlock.test.ts +33 -2
- package/src/__tests__/customTemplatesFrontmatter.test.ts +0 -15
- package/src/__tests__/dataTable.test.ts +25 -15
- package/src/__tests__/diagramBlock.test.ts +3 -3
- package/src/__tests__/diagramText.test.ts +26 -0
- package/src/__tests__/docToMarkdownMedia.test.ts +83 -0
- package/src/__tests__/drawingBlock.test.ts +3 -3
- package/src/__tests__/fixtures/asciiDiagramBattle.ts +512 -0
- package/src/__tests__/fixtures/asciiDiagrams.ts +287 -0
- package/src/__tests__/fixtures/asciiTimelines.ts +35 -0
- package/src/__tests__/fixtures/treeviewFixtures.ts +243 -0
- package/src/__tests__/getLayers.test.ts +32 -18
- package/src/__tests__/getLayersFallback.test.ts +8 -8
- package/src/__tests__/imageEditVersions.test.ts +2 -0
- package/src/__tests__/jsonForm.pointer.test.ts +47 -1
- package/src/__tests__/layoutBlock.test.ts +3 -3
- package/src/__tests__/majorApiTypes.test.ts +18 -0
- package/src/__tests__/markdown.test.ts +41 -0
- package/src/__tests__/markdownToDoc.test.ts +5 -2
- package/src/__tests__/matchFontFamily.test.ts +114 -0
- package/src/__tests__/materializeBlockLayers.test.ts +135 -0
- package/src/__tests__/materializeTestUtils.ts +17 -0
- package/src/__tests__/narrationAlign.test.ts +150 -0
- package/src/__tests__/narrationFeatures.test.ts +71 -0
- package/src/__tests__/narrationNuclei.test.ts +45 -0
- package/src/__tests__/narrationPacing.test.ts +189 -0
- package/src/__tests__/narrationScript.test.ts +149 -0
- package/src/__tests__/narrationSessionRepro.test.ts +62 -0
- package/src/__tests__/narrationSidecar.test.ts +88 -0
- package/src/__tests__/narrationSyllables.test.ts +65 -0
- package/src/__tests__/narrationTestSignals.ts +167 -0
- package/src/__tests__/narrationVad.test.ts +66 -0
- package/src/__tests__/resolveDocTheme.test.ts +16 -2
- package/src/__tests__/rootExports.test.ts +18 -0
- package/src/__tests__/scopedContentContainer.test.ts +20 -0
- package/src/__tests__/shapeGeometry.test.ts +49 -0
- package/src/__tests__/templateAnnotationParse.test.ts +10 -0
- package/src/__tests__/templateInputs.test.ts +69 -0
- package/src/__tests__/templateMetadata.test.ts +2 -1
- package/src/__tests__/templates.test.ts +143 -17
- package/src/__tests__/themeCompile.test.ts +49 -22
- package/src/__tests__/transformProvenance.test.ts +160 -0
- package/src/__tests__/transformV2.test.ts +40 -14
- package/src/__tests__/treeviewBattle.test.ts +76 -0
- package/src/__tests__/treeviewDetect.test.ts +168 -0
- package/src/__tests__/treeviewParse.test.ts +118 -0
- package/src/__tests__/treeviewPipeline.test.ts +183 -0
- package/src/__tests__/treeviewRender.test.ts +91 -0
- package/src/__tests__/versions.test.ts +44 -0
- package/src/doc/applyNarrationTiming.ts +244 -0
- package/src/doc/asciiDiagram/chars.ts +210 -0
- package/src/doc/asciiDiagram/detect.ts +175 -0
- package/src/doc/asciiDiagram/index.ts +38 -0
- package/src/doc/asciiDiagram/mapping.ts +225 -0
- package/src/doc/asciiDiagram/parse.ts +1095 -0
- package/src/doc/asciiDiagram/render.ts +963 -0
- package/src/doc/asciiDiagram/repair.ts +400 -0
- package/src/doc/asciiDiagram/types.ts +65 -0
- package/src/doc/asciiTimeline/detect.ts +138 -0
- package/src/doc/asciiTimeline/index.ts +26 -0
- package/src/doc/asciiTimeline/mapping.ts +43 -0
- package/src/doc/asciiTimeline/parse.ts +870 -0
- package/src/doc/asciiTimeline/render.ts +427 -0
- package/src/doc/asciiTimeline/types.ts +73 -0
- package/src/doc/asciiTimeline/wrappedFlow.ts +427 -0
- package/src/doc/audioMapping.ts +60 -46
- package/src/doc/customTemplatesFrontmatter.ts +0 -41
- package/src/doc/docToMarkdown.ts +126 -39
- package/src/doc/index.ts +76 -4
- package/src/doc/markdownToDoc.ts +135 -1
- package/src/doc/materializeBlockLayers.ts +304 -0
- package/src/doc/mediaAnnotations.ts +20 -0
- package/src/doc/resolveDocTheme.ts +8 -7
- package/src/doc/templateInputs.ts +185 -2
- package/src/doc/templates/__tests__/customTemplateRegistry.test.ts +22 -8
- package/src/doc/templates/coverBlock.ts +49 -13
- package/src/doc/templates/diagramBlock.ts +237 -38
- package/src/doc/templates/drawingBlock.ts +2 -2
- package/src/doc/templates/fallbackBlock.ts +1 -1
- package/src/doc/templates/index.ts +134 -279
- package/src/doc/templates/inputDescriptors.ts +20 -1
- package/src/doc/templates/metadata.ts +10 -0
- package/src/doc/templates/persistentLayers.ts +12 -126
- package/src/doc/templates/registry.ts +88 -0
- package/src/doc/templates/templateNames.ts +22 -0
- package/src/doc/templates/timelineBlock.ts +613 -0
- package/src/doc/templates/treeBlock.ts +131 -0
- package/src/doc/treeview/chars.ts +72 -0
- package/src/doc/treeview/detect.ts +145 -0
- package/src/doc/treeview/index.ts +30 -0
- package/src/doc/treeview/mapping.ts +95 -0
- package/src/doc/treeview/parse.ts +201 -0
- package/src/doc/treeview/render.ts +41 -0
- package/src/doc/treeview/types.ts +43 -0
- package/src/doc/utils/applyRenderStyle.ts +2 -9
- package/src/doc/utils/diagramText.ts +78 -0
- package/src/doc/utils/shapeGeometry.ts +157 -7
- package/src/doc/validate.ts +1 -1
- package/src/generate/templateMapper.ts +7 -0
- package/src/imageEdit/export.ts +6 -5
- package/src/imageEdit/versionPaths.ts +13 -26
- package/src/imageEdit/versions.ts +21 -100
- package/src/index.ts +1 -0
- package/src/internal/immutable.ts +58 -0
- package/src/jsonForm/index.ts +9 -1
- package/src/jsonForm/pointer.ts +68 -23
- package/src/markdown/attrTokens.ts +7 -5
- package/src/markdown/convert.ts +11 -1
- package/src/markdown/index.ts +1 -0
- package/src/markdown/stringify.ts +4 -9
- package/src/markdown/utils.ts +36 -14
- package/src/narration/align.ts +514 -0
- package/src/narration/features.ts +231 -0
- package/src/narration/index.ts +86 -0
- package/src/narration/nuclei.ts +118 -0
- package/src/narration/pacing.ts +211 -0
- package/src/narration/script.ts +239 -0
- package/src/narration/session.ts +100 -0
- package/src/narration/sidecar.ts +187 -0
- package/src/narration/syllables.ts +85 -0
- package/src/narration/trace.ts +50 -0
- package/src/narration/types.ts +299 -0
- package/src/narration/vad.ts +131 -0
- package/src/recommend/numberHighlight.ts +25 -0
- package/src/recommend/templates.ts +108 -12
- package/src/schemas/BlockTemplates.ts +156 -7
- package/src/schemas/Doc.ts +72 -9
- package/src/schemas/Media.ts +12 -2
- package/src/schemas/Theme.ts +45 -25
- package/src/schemas/Viewport.ts +2 -2
- package/src/schemas/fontStacks.ts +79 -0
- package/src/schemas/themeCompile.ts +15 -0
- package/src/schemas/themeConstants.ts +2 -0
- package/src/schemas/themeLibrary.ts +25 -19
- package/src/schemas/themeValidator.ts +1 -1
- package/src/spatial/Geohash.ts +0 -3
- package/src/storage/ContentContainer.ts +17 -9
- package/src/storage/ScopedContentContainer.ts +45 -15
- package/src/transform/applyTransform.ts +5 -5
- package/src/transform/index.ts +3 -1
- package/src/transform/registry.ts +169 -49
- package/src/transform/templateSelector.ts +21 -2
- package/src/transform/timingAllocator.ts +152 -21
- package/src/transform/types.ts +14 -1
- package/src/versions/gitignore.ts +34 -0
- package/src/versions/index.ts +2 -0
- package/src/versions/operations.ts +18 -104
- package/src/versions/paths.ts +13 -28
- package/src/versions/snapshotStore.ts +202 -0
- package/src/versions/types.ts +3 -1
- package/dist/chunk-2OIBZYKP.js.map +0 -1
- package/dist/chunk-6ATE2PSM.js.map +0 -1
- package/dist/chunk-A4O7GIWE.js.map +0 -1
- package/dist/chunk-DLXZMS5K.js.map +0 -1
- package/dist/chunk-HWVFJAAH.js.map +0 -1
- package/dist/chunk-IMSCRLLV.js.map +0 -1
- package/dist/chunk-JELIRVDP.js +0 -24
- package/dist/chunk-JELIRVDP.js.map +0 -1
- package/dist/chunk-KKNUBQ6Y.js.map +0 -1
- package/dist/chunk-LDQ2HJIX.js.map +0 -1
- package/dist/chunk-LH7I6SH7.js.map +0 -1
- package/dist/chunk-RUDYOTA6.js.map +0 -1
- package/dist/chunk-T5UK6YOB.js.map +0 -1
- package/dist/chunk-TEEEILMP.js.map +0 -1
- package/dist/chunk-UY7KGQ5R.js +0 -192
- package/dist/chunk-UY7KGQ5R.js.map +0 -1
- package/dist/chunk-VLJJHDAC.js +0 -218
- package/dist/chunk-VLJJHDAC.js.map +0 -1
- package/dist/chunk-VWUFZ6ZG.js.map +0 -1
- package/dist/story/index.d.ts +0 -1777
- package/dist/story/index.js +0 -273
- package/src/doc/getLayers.ts +0 -195
- /package/dist/{story → narration}/index.js.map +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types + tuning configs for the narration engine.
|
|
3
|
+
*
|
|
4
|
+
* The engine is pure TypeScript with zero dependencies and no DOM/Node
|
|
5
|
+
* APIs: audio arrives as mono `Float32Array` PCM (the editor decodes
|
|
6
|
+
* WebM/MP4 on its side), and every stage is a deterministic step
|
|
7
|
+
* function `(state, input, config) → state` so the whole pipeline is
|
|
8
|
+
* unit-testable in Node with synthetic signals. No `Date.now`, no
|
|
9
|
+
* `Math.random`, no timers anywhere in this module.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** One word of the teleprompter script, positioned inside {@link NarrationScript.sourceText}. */
|
|
13
|
+
export interface ScriptToken {
|
|
14
|
+
/** The word as displayed (no surrounding whitespace). */
|
|
15
|
+
text: string;
|
|
16
|
+
/** Start offset into {@link NarrationScript.sourceText}. */
|
|
17
|
+
charOffset: number;
|
|
18
|
+
/** Exclusive end offset into {@link NarrationScript.sourceText}. */
|
|
19
|
+
charEnd: number;
|
|
20
|
+
/** Id of the doc block this word belongs to. */
|
|
21
|
+
blockId: string;
|
|
22
|
+
/** Index into {@link NarrationScript.blocks}. */
|
|
23
|
+
blockIndex: number;
|
|
24
|
+
/** Estimated syllable count (≥ 1 for spoken tokens; 0 when `spoken` is false). */
|
|
25
|
+
syllables: number;
|
|
26
|
+
/** Spoken-word equivalents (numbers count as several words; 0 when not spoken). */
|
|
27
|
+
spokenWordEquiv: number;
|
|
28
|
+
/**
|
|
29
|
+
* Pause class after this token:
|
|
30
|
+
* 0 none · 1 clause/sentence punctuation · 2 paragraph break · 3 block boundary.
|
|
31
|
+
*/
|
|
32
|
+
pauseAfter: 0 | 1 | 2 | 3;
|
|
33
|
+
/**
|
|
34
|
+
* Whether this token is actually spoken. Standalone punctuation runs —
|
|
35
|
+
* an em-dash, a lone bullet, `···` — tokenize on whitespace like words
|
|
36
|
+
* but carry no letters or digits: they DISPLAY in the prompter yet must
|
|
37
|
+
* never be the highlighted active word, are never paused on, and add no
|
|
38
|
+
* syllables to the pacing/alignment model.
|
|
39
|
+
*/
|
|
40
|
+
spoken: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The token/char span of one doc block inside the script. */
|
|
44
|
+
export interface ScriptBlockRange {
|
|
45
|
+
blockId: string;
|
|
46
|
+
/** The block's heading text, when present. */
|
|
47
|
+
heading?: string;
|
|
48
|
+
/** Inclusive index into {@link NarrationScript.tokens}. */
|
|
49
|
+
tokenStart: number;
|
|
50
|
+
/** Exclusive index into {@link NarrationScript.tokens}. */
|
|
51
|
+
tokenEnd: number;
|
|
52
|
+
/** Start offset into {@link NarrationScript.sourceText} (includes the spoken title). */
|
|
53
|
+
charStart: number;
|
|
54
|
+
/** Exclusive end offset into {@link NarrationScript.sourceText}. */
|
|
55
|
+
charEnd: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The teleprompter script derived from a Doc. `sourceText` is canonical:
|
|
60
|
+
* it is stored verbatim in the timing sidecar, and every `charOffset`
|
|
61
|
+
* indexes into it. Building is deterministic — the same Doc always
|
|
62
|
+
* yields a byte-identical script.
|
|
63
|
+
*/
|
|
64
|
+
export interface NarrationScript {
|
|
65
|
+
sourceText: string;
|
|
66
|
+
tokens: ScriptToken[];
|
|
67
|
+
blocks: ScriptBlockRange[];
|
|
68
|
+
totalSyllables: number;
|
|
69
|
+
/**
|
|
70
|
+
* Prefix sums: `cumulativeSyllables[i]` = syllables of `tokens[0..i-1]`.
|
|
71
|
+
* Length is `tokens.length + 1`.
|
|
72
|
+
*/
|
|
73
|
+
cumulativeSyllables: number[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Per-frame acoustic features extracted from PCM. */
|
|
77
|
+
export interface FrameFeatures {
|
|
78
|
+
/** Frame CENTER time in seconds from the start of the signal. */
|
|
79
|
+
tSec: number;
|
|
80
|
+
/** Full-band root-mean-square of the frame. */
|
|
81
|
+
rms: number;
|
|
82
|
+
/** Mean square of the 250–3000 Hz bandpassed frame (speech band energy). */
|
|
83
|
+
bandEnergy: number;
|
|
84
|
+
/** Zero crossings / (frameLength − 1), in [0, 1]. */
|
|
85
|
+
zcr: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── Configs ──────────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
export interface FeatureConfig {
|
|
91
|
+
/** Analysis frame length in samples (~21 ms @ 48 kHz). */
|
|
92
|
+
frameSize: number;
|
|
93
|
+
/** Hop between frame starts in seconds (live 0.02; the aligner uses 0.01). */
|
|
94
|
+
hopSec: number;
|
|
95
|
+
/** Bandpass high-pass corner (Hz). */
|
|
96
|
+
bandLowHz: number;
|
|
97
|
+
/** Bandpass low-pass corner (Hz). */
|
|
98
|
+
bandHighHz: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const DEFAULT_FEATURE_CONFIG: FeatureConfig = Object.freeze({
|
|
102
|
+
frameSize: 1024,
|
|
103
|
+
hopSec: 0.02,
|
|
104
|
+
bandLowHz: 250,
|
|
105
|
+
bandHighHz: 3000,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
export interface VadConfig {
|
|
109
|
+
/** Floor-seeding period before any speech decision (ms). */
|
|
110
|
+
warmupMs: number;
|
|
111
|
+
/** Floor attack toward minima (per-frame EMA alpha when energy < floor). */
|
|
112
|
+
alphaDown: number;
|
|
113
|
+
/** Floor release (per-frame EMA alpha when energy ≥ floor; frozen while speaking). */
|
|
114
|
+
alphaUp: number;
|
|
115
|
+
/** Enter speech when energy > floor × enterRatio for enterFrames frames. */
|
|
116
|
+
enterRatio: number;
|
|
117
|
+
/**
|
|
118
|
+
* Exit hysteresis: sub-exit frames only count once energy < floor ×
|
|
119
|
+
* exitRatio. The floor is a LOW-percentile tracker, so steady room
|
|
120
|
+
* noise runs ~1.8–2.3× above it — exitRatio must sit above that band
|
|
121
|
+
* (and below enterRatio) or silence never registers.
|
|
122
|
+
*/
|
|
123
|
+
exitRatio: number;
|
|
124
|
+
/** Consecutive supra-enter frames required to enter speech. */
|
|
125
|
+
enterFrames: number;
|
|
126
|
+
/** Sub-exit dwell required to leave speech (ms). */
|
|
127
|
+
hangoverMs: number;
|
|
128
|
+
/**
|
|
129
|
+
* Dip-starved rebaseline: real speech dips below enterRatio × floor
|
|
130
|
+
* between syllables; a "speech" that stays strongly above the floor
|
|
131
|
+
* for this long with zero dips is a shifted noise floor — adopt it
|
|
132
|
+
* and exit. Guards against a step change in room noise wedging the
|
|
133
|
+
* VAD open forever (the floor is otherwise frozen while speaking).
|
|
134
|
+
*/
|
|
135
|
+
noiseRebaselineSec: number;
|
|
136
|
+
/** Absolute floor clamp guarding digital silence. */
|
|
137
|
+
floorMin: number;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const DEFAULT_VAD_CONFIG: VadConfig = Object.freeze({
|
|
141
|
+
warmupMs: 200,
|
|
142
|
+
alphaDown: 0.3,
|
|
143
|
+
alphaUp: 0.005,
|
|
144
|
+
enterRatio: 3.0,
|
|
145
|
+
exitRatio: 2.5,
|
|
146
|
+
enterFrames: 2,
|
|
147
|
+
hangoverMs: 300,
|
|
148
|
+
noiseRebaselineSec: 1.5,
|
|
149
|
+
floorMin: 1e-9,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export interface NucleiConfig {
|
|
153
|
+
/** One-pole low-pass cutoff for the amplitude envelope (Hz). */
|
|
154
|
+
envelopeHz: number;
|
|
155
|
+
/** Minimum spacing between accepted syllable onsets (ms) — caps ~8.3 syl/s. */
|
|
156
|
+
minInterOnsetMs: number;
|
|
157
|
+
/** Peak must exceed valley-since-last-peak × this ratio. */
|
|
158
|
+
prominenceRatio: number;
|
|
159
|
+
/** Peak must exceed the decaying loudness reference × this fraction. */
|
|
160
|
+
minRelPeak: number;
|
|
161
|
+
/** Decay time constant of the loudness reference (s). */
|
|
162
|
+
peakRefTauSec: number;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export const DEFAULT_NUCLEI_CONFIG: NucleiConfig = Object.freeze({
|
|
166
|
+
// Continuous reading blurs adjacent syllables together: a 10 Hz envelope
|
|
167
|
+
// over-smooths 5–7 Hz syllable structure and a 1.6× prominence gate
|
|
168
|
+
// rejects the shallow dips between connected syllables — both cause the
|
|
169
|
+
// detector to UNDER-count, which makes the prompter lag. A higher
|
|
170
|
+
// envelope cutoff preserves per-syllable peaks and a gentler prominence
|
|
171
|
+
// gate accepts them; the min-spacing gate still rejects true doublets.
|
|
172
|
+
envelopeHz: 16,
|
|
173
|
+
minInterOnsetMs: 110,
|
|
174
|
+
prominenceRatio: 1.3,
|
|
175
|
+
minRelPeak: 0.1,
|
|
176
|
+
peakRefTauSec: 3.0,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
export interface PacingConfig {
|
|
180
|
+
/** The user's base speaking rate (words per minute). */
|
|
181
|
+
baseWpm: number;
|
|
182
|
+
/**
|
|
183
|
+
* How strongly the detected voice rate steers the cruise velocity vs.
|
|
184
|
+
* the user's set pace, in [0, 1]. The speaking-cruise velocity is
|
|
185
|
+
* `voiceBlend·voiceRate + (1 − voiceBlend)·baseRate`, so the WPM slider
|
|
186
|
+
* is ALWAYS felt (it never fully cancels) and an under-counting detector
|
|
187
|
+
* can't drag the prompter to a crawl. 1 = pure voice-follow (the old
|
|
188
|
+
* behavior, where WPM only mattered at the clamps); 0 = ignore the voice.
|
|
189
|
+
*/
|
|
190
|
+
voiceBlend: number;
|
|
191
|
+
/** Clamp on the cruise velocity as a fraction of the set pace. */
|
|
192
|
+
minRateMult: number;
|
|
193
|
+
maxRateMult: number;
|
|
194
|
+
/** EMA time constant for the detected syllable rate (s). */
|
|
195
|
+
rateEmaTauSec: number;
|
|
196
|
+
/** Velocity slew time constant while speaking (s). */
|
|
197
|
+
velSlewTauSec: number;
|
|
198
|
+
/** Velocity decay time constant in silence (s) — halted within ~250 ms. */
|
|
199
|
+
haltTauSec: number;
|
|
200
|
+
/** Proportional gain of the forward-only catch-up boost (per syllable behind). */
|
|
201
|
+
kP: number;
|
|
202
|
+
/** Integral gain of the forward-only boost (per syllable·second behind). */
|
|
203
|
+
kI: number;
|
|
204
|
+
/** Anti-windup clamp on the (≤ 0) behind-error integral (syllable·seconds). */
|
|
205
|
+
intClamp: number;
|
|
206
|
+
/** Max fraction the catch-up boost may ADD to the cruise velocity. */
|
|
207
|
+
maxCorrection: number;
|
|
208
|
+
/** Window (words ahead) used for the local expected syllables-per-word. */
|
|
209
|
+
sylWindowWords: number;
|
|
210
|
+
/** Reader-ahead error beyond this hard-resyncs the prompter FORWARD. */
|
|
211
|
+
resyncSyllables: number;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export const DEFAULT_PACING_CONFIG: PacingConfig = Object.freeze({
|
|
215
|
+
baseWpm: 150,
|
|
216
|
+
voiceBlend: 0.6,
|
|
217
|
+
minRateMult: 0.5,
|
|
218
|
+
maxRateMult: 3.0,
|
|
219
|
+
rateEmaTauSec: 0.7,
|
|
220
|
+
velSlewTauSec: 0.15,
|
|
221
|
+
haltTauSec: 0.085,
|
|
222
|
+
kP: 0.14,
|
|
223
|
+
kI: 0.02,
|
|
224
|
+
intClamp: 4,
|
|
225
|
+
maxCorrection: 0.6,
|
|
226
|
+
sylWindowWords: 8,
|
|
227
|
+
resyncSyllables: 8,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
export interface AlignConfig {
|
|
231
|
+
/** Fine analysis hop for the offline pass (s). */
|
|
232
|
+
hopSec: number;
|
|
233
|
+
/** Non-speech runs at least this long become GAP events (s). */
|
|
234
|
+
gapMinSec: number;
|
|
235
|
+
/** Sakoe-Chiba band half-width around the live-trace prior (s). */
|
|
236
|
+
bandRadiusSec: number;
|
|
237
|
+
/** Band half-width when no trace exists (s); also floored at 10% of take length. */
|
|
238
|
+
bandRadiusNoTraceSec: number;
|
|
239
|
+
/** Cost weight for |Δt| on syllable↔syllable matches (normalized by band radius). */
|
|
240
|
+
matchTimeWeight: number;
|
|
241
|
+
/** Cost of matching an expected pause slot to a detected syllable (reader didn't pause). */
|
|
242
|
+
pauseToSylCost: number;
|
|
243
|
+
/** Cost of matching an expected syllable slot to a detected gap (mid-sentence hesitation). */
|
|
244
|
+
sylToGapCost: number;
|
|
245
|
+
/** Cost of skipping an expected slot (merged/unspoken syllable). */
|
|
246
|
+
deleteCost: number;
|
|
247
|
+
/** Cost of skipping a detected event (filler word, breath, click). */
|
|
248
|
+
insertCost: number;
|
|
249
|
+
/** Snap a block start to a silence-gap end within this window before it (s). */
|
|
250
|
+
blockSnapWindowSec: number;
|
|
251
|
+
/** Padding after the last speech for the final block's end (s). */
|
|
252
|
+
tailPadSec: number;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const DEFAULT_ALIGN_CONFIG: AlignConfig = Object.freeze({
|
|
256
|
+
hopSec: 0.01,
|
|
257
|
+
gapMinSec: 0.35,
|
|
258
|
+
bandRadiusSec: 1.5,
|
|
259
|
+
bandRadiusNoTraceSec: 3,
|
|
260
|
+
matchTimeWeight: 1.0,
|
|
261
|
+
pauseToSylCost: 2.0,
|
|
262
|
+
sylToGapCost: 1.5,
|
|
263
|
+
deleteCost: 0.8,
|
|
264
|
+
insertCost: 0.8,
|
|
265
|
+
blockSnapWindowSec: 0.8,
|
|
266
|
+
tailPadSec: 0.4,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// ── Alignment outputs ────────────────────────────────────────────────
|
|
270
|
+
|
|
271
|
+
/** Refined timestamp of one script token. */
|
|
272
|
+
export interface WordTiming {
|
|
273
|
+
tokenIndex: number;
|
|
274
|
+
/** Seconds into the take when the word begins. Monotonically non-decreasing. */
|
|
275
|
+
tSec: number;
|
|
276
|
+
/** True when this word had no matched syllable and was interpolated. */
|
|
277
|
+
interpolated: boolean;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Narration time range of one doc block. Ranges are CONTIGUOUS: endSec === next.startSec. */
|
|
281
|
+
export interface NarrationBlockRange {
|
|
282
|
+
blockId: string;
|
|
283
|
+
heading?: string;
|
|
284
|
+
blockIndex: number;
|
|
285
|
+
charStart: number;
|
|
286
|
+
charEnd: number;
|
|
287
|
+
startSec: number;
|
|
288
|
+
endSec: number;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface NarrationAlignment {
|
|
292
|
+
/** One entry per script token, monotonic in time. */
|
|
293
|
+
words: WordTiming[];
|
|
294
|
+
blocks: NarrationBlockRange[];
|
|
295
|
+
/** Total syllable onsets detected in the take (diagnostics). */
|
|
296
|
+
detectedSyllables: number;
|
|
297
|
+
/** Total DTW path cost (diagnostics/QA). */
|
|
298
|
+
cost: number;
|
|
299
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adaptive voice-activity detection over frame features.
|
|
3
|
+
*
|
|
4
|
+
* The noise floor is an asymmetric EMA of band energy that hugs minima
|
|
5
|
+
* (≈ a 5th-percentile tracker): fast attack toward quieter frames, slow
|
|
6
|
+
* release upward, and FROZEN upward while speaking so long speech can't
|
|
7
|
+
* inflate it. Speech enters via a ratio threshold with a
|
|
8
|
+
* consecutive-frame debounce and exits after a continuous sub-exit
|
|
9
|
+
* dwell (hangover) — the hangover also bridges trailing fricatives and
|
|
10
|
+
* inter-word dips. A dip-starved rebaseline escape keeps a step change
|
|
11
|
+
* in room noise from wedging the detector open: real speech dips below
|
|
12
|
+
* the enter threshold between syllables, steady noise never does.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { FrameFeatures, VadConfig } from './types.js';
|
|
16
|
+
import { DEFAULT_VAD_CONFIG } from './types.js';
|
|
17
|
+
|
|
18
|
+
export interface VadState {
|
|
19
|
+
/** Adaptive noise-floor estimate (band-energy units). */
|
|
20
|
+
noiseFloor: number;
|
|
21
|
+
/** The VAD decision — the stage's output. */
|
|
22
|
+
speaking: boolean;
|
|
23
|
+
/** Consecutive supra-enter frames observed while silent. */
|
|
24
|
+
enterStreak: number;
|
|
25
|
+
/** tSec when the current sub-exit dwell began (while speaking), else null. */
|
|
26
|
+
subExitSince: number | null;
|
|
27
|
+
/** tSec when the current zero-dip run began (while speaking), else null. */
|
|
28
|
+
noDipSince: number | null;
|
|
29
|
+
/** No speech decisions before this time (floor seeding). */
|
|
30
|
+
warmupUntilSec: number;
|
|
31
|
+
/** False until the first frame seeds the floor. */
|
|
32
|
+
seeded: boolean;
|
|
33
|
+
lastTSec: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createVadState(config?: Partial<VadConfig>): VadState {
|
|
37
|
+
const merged = { ...DEFAULT_VAD_CONFIG, ...config };
|
|
38
|
+
return {
|
|
39
|
+
noiseFloor: merged.floorMin,
|
|
40
|
+
speaking: false,
|
|
41
|
+
enterStreak: 0,
|
|
42
|
+
subExitSince: null,
|
|
43
|
+
noDipSince: null,
|
|
44
|
+
warmupUntilSec: merged.warmupMs / 1000,
|
|
45
|
+
seeded: false,
|
|
46
|
+
lastTSec: 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Pure per-frame step. `state.speaking` on the returned state is the decision for this frame. */
|
|
51
|
+
export function vadStep(
|
|
52
|
+
state: VadState,
|
|
53
|
+
frame: FrameFeatures,
|
|
54
|
+
config?: Partial<VadConfig>,
|
|
55
|
+
): VadState {
|
|
56
|
+
const c = { ...DEFAULT_VAD_CONFIG, ...config };
|
|
57
|
+
const energy = Math.max(0, frame.bandEnergy);
|
|
58
|
+
|
|
59
|
+
let floor = state.seeded ? state.noiseFloor : Math.max(energy, c.floorMin);
|
|
60
|
+
if (state.seeded) {
|
|
61
|
+
if (!state.speaking) {
|
|
62
|
+
const alpha = energy < floor ? c.alphaDown : c.alphaUp;
|
|
63
|
+
floor += (energy - floor) * alpha;
|
|
64
|
+
} else if (energy < floor) {
|
|
65
|
+
// Downward adaptation stays safe while speaking; only upward is frozen.
|
|
66
|
+
floor += (energy - floor) * c.alphaDown;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (floor < c.floorMin) floor = c.floorMin;
|
|
70
|
+
|
|
71
|
+
let speaking = state.speaking;
|
|
72
|
+
let enterStreak = state.enterStreak;
|
|
73
|
+
let subExitSince = state.subExitSince;
|
|
74
|
+
let noDipSince = state.noDipSince;
|
|
75
|
+
|
|
76
|
+
if (frame.tSec < state.warmupUntilSec) {
|
|
77
|
+
speaking = false;
|
|
78
|
+
enterStreak = 0;
|
|
79
|
+
subExitSince = null;
|
|
80
|
+
noDipSince = null;
|
|
81
|
+
} else if (!speaking) {
|
|
82
|
+
noDipSince = null;
|
|
83
|
+
if (energy > floor * c.enterRatio) {
|
|
84
|
+
enterStreak += 1;
|
|
85
|
+
if (enterStreak >= c.enterFrames) {
|
|
86
|
+
speaking = true;
|
|
87
|
+
subExitSince = null;
|
|
88
|
+
noDipSince = frame.tSec;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
enterStreak = 0;
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
// Hangover: leave speech only after a continuous sub-exit dwell.
|
|
95
|
+
if (energy >= floor * c.exitRatio) {
|
|
96
|
+
subExitSince = null;
|
|
97
|
+
} else {
|
|
98
|
+
if (subExitSince === null) subExitSince = frame.tSec;
|
|
99
|
+
if (frame.tSec - subExitSince >= c.hangoverMs / 1000) {
|
|
100
|
+
speaking = false;
|
|
101
|
+
subExitSince = null;
|
|
102
|
+
noDipSince = null;
|
|
103
|
+
enterStreak = 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Dip-starved rebaseline: a signal that never dips near the floor
|
|
107
|
+
// is a new noise floor, not speech.
|
|
108
|
+
if (speaking) {
|
|
109
|
+
if (energy <= floor * c.enterRatio) {
|
|
110
|
+
noDipSince = frame.tSec;
|
|
111
|
+
} else if (noDipSince !== null && frame.tSec - noDipSince >= c.noiseRebaselineSec) {
|
|
112
|
+
floor = Math.max(energy, c.floorMin);
|
|
113
|
+
speaking = false;
|
|
114
|
+
subExitSince = null;
|
|
115
|
+
noDipSince = null;
|
|
116
|
+
enterStreak = 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
noiseFloor: floor,
|
|
123
|
+
speaking,
|
|
124
|
+
enterStreak,
|
|
125
|
+
subExitSince,
|
|
126
|
+
noDipSince,
|
|
127
|
+
warmupUntilSec: state.warmupUntilSec,
|
|
128
|
+
seeded: true,
|
|
129
|
+
lastTSec: frame.tSec,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches a prominent number suitable for a Stat Highlight block. Qualifies
|
|
3
|
+
* on currency prefixes, common unit suffixes, and standalone large numbers.
|
|
4
|
+
* Plain small numbers (`42`) intentionally do not qualify.
|
|
5
|
+
*/
|
|
6
|
+
const NUMBER_HIGHLIGHT_RE =
|
|
7
|
+
/(?:[$€£¥]\s?\d+(?:[.,]\d+)*(?:\s?(?:[MBK]|million|billion|thousand))?|\d+(?:[.,]\d+)*\s?(?:%|‰|x|×|[MBK]|million|billion|thousand|percent|years?|days?|hours?)|\d{3,}(?:[.,]\d+)*)/i;
|
|
8
|
+
|
|
9
|
+
/** A prominent number found inside a short stat-like string. */
|
|
10
|
+
export interface NumberHighlightMatch {
|
|
11
|
+
value: string;
|
|
12
|
+
index: number;
|
|
13
|
+
end: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Find the prominent number phrase inside a string, if one exists. */
|
|
17
|
+
export function matchNumberHighlight(text: string): NumberHighlightMatch | null {
|
|
18
|
+
const match = NUMBER_HIGHLIGHT_RE.exec(text);
|
|
19
|
+
if (!match || match.index === undefined) return null;
|
|
20
|
+
return {
|
|
21
|
+
value: match[0],
|
|
22
|
+
index: match.index,
|
|
23
|
+
end: match.index + match[0].length,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -13,9 +13,22 @@ import type {
|
|
|
13
13
|
HtmlElement,
|
|
14
14
|
HtmlNode,
|
|
15
15
|
MarkdownBlockNode,
|
|
16
|
+
MarkdownCodeBlock,
|
|
16
17
|
MarkdownHtmlBlock,
|
|
17
18
|
MarkdownNode,
|
|
18
19
|
} from '../markdown/types.js';
|
|
20
|
+
import {
|
|
21
|
+
detectAsciiDiagram,
|
|
22
|
+
isEligibleAsciiFenceLang,
|
|
23
|
+
isExplicitDiagramLang,
|
|
24
|
+
} from '../doc/asciiDiagram/detect.js';
|
|
25
|
+
import {
|
|
26
|
+
detectAsciiTimeline,
|
|
27
|
+
isEligibleAsciiTimelineFenceLang,
|
|
28
|
+
isExplicitTimelineLang,
|
|
29
|
+
} from '../doc/asciiTimeline/detect.js';
|
|
30
|
+
import { detectTree, isEligibleTreeFenceLang, isExplicitTreeLang } from '../doc/treeview/detect.js';
|
|
31
|
+
import { matchNumberHighlight } from './numberHighlight.js';
|
|
19
32
|
|
|
20
33
|
export interface BlockContentProfile {
|
|
21
34
|
hasImage: boolean;
|
|
@@ -27,6 +40,20 @@ export interface BlockContentProfile {
|
|
|
27
40
|
hasDate: boolean;
|
|
28
41
|
hasNumberHighlight: boolean;
|
|
29
42
|
wordCount: number;
|
|
43
|
+
/**
|
|
44
|
+
* True when the body is dominated by exactly one code fence whose content
|
|
45
|
+
* is an ASCII box-and-line diagram (see `doc/asciiDiagram/detect.ts`).
|
|
46
|
+
* Optional so externally-constructed profiles keep compiling.
|
|
47
|
+
*/
|
|
48
|
+
hasAsciiDiagram?: boolean;
|
|
49
|
+
/** True when a dominant code fence is an authored marker+axis timeline. */
|
|
50
|
+
hasTimeline?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* True when the body is dominated by exactly one code fence whose content
|
|
53
|
+
* is an ASCII file-tree / outline (see `doc/treeview/detect.ts`). Mutually
|
|
54
|
+
* exclusive with `hasAsciiDiagram`.
|
|
55
|
+
*/
|
|
56
|
+
hasTree?: boolean;
|
|
30
57
|
}
|
|
31
58
|
|
|
32
59
|
export interface RecommendationResult {
|
|
@@ -57,17 +84,6 @@ const DATE_PATTERNS: RegExp[] = [
|
|
|
57
84
|
/\b\d{1,2}(st|nd|rd|th)\s+century\b/i,
|
|
58
85
|
];
|
|
59
86
|
|
|
60
|
-
/**
|
|
61
|
-
* Matches a "highlight number" — a prominent figure suitable for a Stat
|
|
62
|
-
* Highlight block. Qualifies on any of:
|
|
63
|
-
* - currency prefix: `$2.3M`, `€500`, `¥1,234`
|
|
64
|
-
* - unit suffix: `50%`, `100 years`, `5×`, `2.3M`
|
|
65
|
-
* - standalone large: `1,234`, `5000`, `12,345`
|
|
66
|
-
* Plain small numbers (`42`) intentionally don't qualify.
|
|
67
|
-
*/
|
|
68
|
-
const NUMBER_HIGHLIGHT_RE =
|
|
69
|
-
/(?:[$€£¥]\s?\d+(?:[.,]\d+)*(?:\s?(?:[MBK]|million|billion|thousand))?|\d+(?:[.,]\d+)*\s?(?:%|‰|x|×|[MBK]|million|billion|thousand|percent|years?|days?|hours?)|\d{3,}(?:[.,]\d+)*)/i;
|
|
70
|
-
|
|
71
87
|
const VIDEO_HOST_RE = /(youtube\.com|youtu\.be|vimeo\.com|wistia\.|loom\.com)/i;
|
|
72
88
|
|
|
73
89
|
function htmlElementsByTag(root: MarkdownNode, tagNames: Set<string>): HtmlElement[] {
|
|
@@ -161,7 +177,7 @@ export function profileBlockContents(nodes: MarkdownBlockNode[]): BlockContentPr
|
|
|
161
177
|
if (n.type !== 'paragraph') return;
|
|
162
178
|
const text = extractPlainText(n).trim();
|
|
163
179
|
if (!text) return true;
|
|
164
|
-
const m = text
|
|
180
|
+
const m = matchNumberHighlight(text);
|
|
165
181
|
if (!m) return true;
|
|
166
182
|
// Paragraph qualifies when its word count is small AND a prominent
|
|
167
183
|
// number occupies a meaningful chunk of it. Keeps "the company grew
|
|
@@ -171,6 +187,65 @@ export function profileBlockContents(nodes: MarkdownBlockNode[]): BlockContentPr
|
|
|
171
187
|
return true;
|
|
172
188
|
});
|
|
173
189
|
|
|
190
|
+
// ASCII diagram: exactly one code fence with an eligible (inert) language
|
|
191
|
+
// whose content detects as box-and-line art, in a body it dominates — no
|
|
192
|
+
// competing table/image/video signal and at most a little surrounding
|
|
193
|
+
// prose. The diagram template replaces the whole slide, so hiding a real
|
|
194
|
+
// table or a second fence is the costly failure this guards against.
|
|
195
|
+
let hasAsciiDiagram = false;
|
|
196
|
+
const codeNodes: MarkdownCodeBlock[] = [];
|
|
197
|
+
for (const node of nodes) codeNodes.push(...findNodesByType<MarkdownCodeBlock>(node, 'code'));
|
|
198
|
+
if (
|
|
199
|
+
codeNodes.length === 1 &&
|
|
200
|
+
isEligibleAsciiFenceLang(codeNodes[0].lang) &&
|
|
201
|
+
!hasTable &&
|
|
202
|
+
imageCount === 0 &&
|
|
203
|
+
!hasVideo
|
|
204
|
+
) {
|
|
205
|
+
const nonCodeChars = Math.max(0, plainText.length - codeNodes[0].value.length);
|
|
206
|
+
const explicit = isExplicitDiagramLang(codeNodes[0].lang);
|
|
207
|
+
if (nonCodeChars <= 400 && detectAsciiDiagram(codeNodes[0].value, { explicit }).isDiagram) {
|
|
208
|
+
hasAsciiDiagram = true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ASCII timeline: after the more specific closed-box diagram gate and
|
|
213
|
+
// before tree connector detection.
|
|
214
|
+
let hasTimeline = false;
|
|
215
|
+
if (
|
|
216
|
+
!hasAsciiDiagram &&
|
|
217
|
+
codeNodes.length === 1 &&
|
|
218
|
+
isEligibleAsciiTimelineFenceLang(codeNodes[0].lang) &&
|
|
219
|
+
!hasTable &&
|
|
220
|
+
imageCount === 0 &&
|
|
221
|
+
!hasVideo
|
|
222
|
+
) {
|
|
223
|
+
const nonCodeChars = Math.max(0, plainText.length - codeNodes[0].value.length);
|
|
224
|
+
const explicit = isExplicitTimelineLang(codeNodes[0].lang);
|
|
225
|
+
if (nonCodeChars <= 400 && detectAsciiTimeline(codeNodes[0].value, { explicit }).isTimeline) {
|
|
226
|
+
hasTimeline = true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Tree detection comes last: timeline callout elbows can otherwise look
|
|
231
|
+
// like connector branches to the deliberately lenient tree parser.
|
|
232
|
+
let hasTree = false;
|
|
233
|
+
if (
|
|
234
|
+
!hasAsciiDiagram &&
|
|
235
|
+
!hasTimeline &&
|
|
236
|
+
codeNodes.length === 1 &&
|
|
237
|
+
isEligibleTreeFenceLang(codeNodes[0].lang) &&
|
|
238
|
+
!hasTable &&
|
|
239
|
+
imageCount === 0 &&
|
|
240
|
+
!hasVideo
|
|
241
|
+
) {
|
|
242
|
+
const nonCodeChars = Math.max(0, plainText.length - codeNodes[0].value.length);
|
|
243
|
+
const explicit = isExplicitTreeLang(codeNodes[0].lang);
|
|
244
|
+
if (nonCodeChars <= 400 && detectTree(codeNodes[0].value, { explicit }).isTree) {
|
|
245
|
+
hasTree = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
174
249
|
return {
|
|
175
250
|
hasImage: imageCount > 0,
|
|
176
251
|
imageCount,
|
|
@@ -181,6 +256,9 @@ export function profileBlockContents(nodes: MarkdownBlockNode[]): BlockContentPr
|
|
|
181
256
|
hasDate,
|
|
182
257
|
hasNumberHighlight,
|
|
183
258
|
wordCount,
|
|
259
|
+
hasAsciiDiagram,
|
|
260
|
+
hasTimeline,
|
|
261
|
+
hasTree,
|
|
184
262
|
};
|
|
185
263
|
}
|
|
186
264
|
|
|
@@ -198,6 +276,21 @@ function recommendedNamesForProfile(profile: BlockContentProfile): string[] {
|
|
|
198
276
|
const names = new Set<string>();
|
|
199
277
|
let anyContentSignal = false;
|
|
200
278
|
|
|
279
|
+
if (profile.hasAsciiDiagram) {
|
|
280
|
+
anyContentSignal = true;
|
|
281
|
+
names.add('diagram');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (profile.hasTimeline) {
|
|
285
|
+
anyContentSignal = true;
|
|
286
|
+
names.add('timeline');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (profile.hasTree) {
|
|
290
|
+
anyContentSignal = true;
|
|
291
|
+
names.add('tree');
|
|
292
|
+
}
|
|
293
|
+
|
|
201
294
|
if (profile.hasImage) {
|
|
202
295
|
anyContentSignal = true;
|
|
203
296
|
names.add('imageWithCaption');
|
|
@@ -266,6 +359,9 @@ function recommendedNamesForProfile(profile: BlockContentProfile): string[] {
|
|
|
266
359
|
* the editor's template-picker UI instead.
|
|
267
360
|
*/
|
|
268
361
|
export function pickAutoTemplate(profile: BlockContentProfile, blockIndex = 0): string | undefined {
|
|
362
|
+
if (profile.hasAsciiDiagram) return 'diagram';
|
|
363
|
+
if (profile.hasTimeline) return 'timeline';
|
|
364
|
+
if (profile.hasTree) return 'tree';
|
|
269
365
|
if (profile.hasTable) return 'dataTable';
|
|
270
366
|
if (profile.imageCount >= 2) return 'photoGrid';
|
|
271
367
|
if (profile.hasImage) return blockIndex % 2 === 0 ? 'leftFeature' : 'rightFeature';
|