@bendyline/squisq 1.0.1 → 1.1.1
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/dist/ContentContainer-DNx460y8.d.ts +88 -0
- package/dist/{Doc-1hmT1LZl.d.ts → Doc-Cvt2lyzn.d.ts} +56 -4
- package/dist/MediaProvider-wpSe21B3.d.ts +66 -0
- package/dist/__tests__/contentContainer.test.d.ts +2 -0
- package/dist/__tests__/contentContainer.test.d.ts.map +1 -0
- package/dist/__tests__/contentContainer.test.js +234 -0
- package/dist/__tests__/contentContainer.test.js.map +1 -0
- package/dist/__tests__/markdownToDoc.test.js +75 -0
- package/dist/__tests__/markdownToDoc.test.js.map +1 -1
- package/dist/{chunk-PJ7AODIM.js → chunk-3WBJAZZ5.js} +394 -52
- package/dist/chunk-3WBJAZZ5.js.map +1 -0
- package/dist/chunk-4CRBS35L.js +292 -0
- package/dist/chunk-4CRBS35L.js.map +1 -0
- package/dist/{chunk-6YJPI6VI.js → chunk-4X3JQXNM.js} +1 -1
- package/dist/{chunk-S4F2RY37.js → chunk-CORGFIFU.js} +1 -1
- package/dist/chunk-CORGFIFU.js.map +1 -0
- package/dist/chunk-DNJKBAI7.js +1 -0
- package/dist/chunk-DNJKBAI7.js.map +1 -0
- package/dist/{chunk-VP5SZTZ2.js → chunk-MIBRIRGJ.js} +2 -139
- package/dist/chunk-MIBRIRGJ.js.map +1 -0
- package/dist/{chunk-URU6QMLY.js → chunk-NJLL5XYC.js} +15 -8
- package/dist/chunk-NJLL5XYC.js.map +1 -0
- package/dist/chunk-OFU53HI7.js +165 -0
- package/dist/chunk-OFU53HI7.js.map +1 -0
- package/dist/chunk-TSG2OSE6.js +145 -0
- package/dist/chunk-TSG2OSE6.js.map +1 -0
- package/dist/{chunk-O5HCIUAD.js → chunk-TVPKD76V.js} +81 -187
- package/dist/chunk-TVPKD76V.js.map +1 -0
- package/dist/contentExtractor-BNfVJV2U.d.ts +113 -0
- package/dist/doc/audioMapping.d.ts +36 -0
- package/dist/doc/audioMapping.d.ts.map +1 -0
- package/dist/doc/audioMapping.js +279 -0
- package/dist/doc/audioMapping.js.map +1 -0
- package/dist/doc/index.d.ts +1 -0
- package/dist/doc/index.d.ts.map +1 -1
- package/dist/doc/index.js +1 -0
- package/dist/doc/index.js.map +1 -1
- package/dist/doc/markdownToDoc.d.ts.map +1 -1
- package/dist/doc/markdownToDoc.js +126 -1
- package/dist/doc/markdownToDoc.js.map +1 -1
- package/dist/doc/templates/comparisonBar.d.ts.map +1 -1
- package/dist/doc/templates/comparisonBar.js +23 -5
- package/dist/doc/templates/comparisonBar.js.map +1 -1
- package/dist/doc/templates/coverBlock.d.ts.map +1 -1
- package/dist/doc/templates/coverBlock.js +3 -0
- package/dist/doc/templates/coverBlock.js.map +1 -1
- package/dist/doc/templates/dateEvent.d.ts.map +1 -1
- package/dist/doc/templates/dateEvent.js +4 -0
- package/dist/doc/templates/dateEvent.js.map +1 -1
- package/dist/doc/templates/definitionCard.d.ts.map +1 -1
- package/dist/doc/templates/definitionCard.js +4 -1
- package/dist/doc/templates/definitionCard.js.map +1 -1
- package/dist/doc/templates/factCard.d.ts.map +1 -1
- package/dist/doc/templates/factCard.js +4 -0
- package/dist/doc/templates/factCard.js.map +1 -1
- package/dist/doc/templates/fullBleedQuote.d.ts.map +1 -1
- package/dist/doc/templates/fullBleedQuote.js +2 -1
- package/dist/doc/templates/fullBleedQuote.js.map +1 -1
- package/dist/doc/templates/imageWithCaption.d.ts.map +1 -1
- package/dist/doc/templates/imageWithCaption.js +4 -0
- package/dist/doc/templates/imageWithCaption.js.map +1 -1
- package/dist/doc/templates/listBlock.d.ts.map +1 -1
- package/dist/doc/templates/listBlock.js +3 -0
- package/dist/doc/templates/listBlock.js.map +1 -1
- package/dist/doc/templates/mapBlock.d.ts.map +1 -1
- package/dist/doc/templates/mapBlock.js +3 -0
- package/dist/doc/templates/mapBlock.js.map +1 -1
- package/dist/doc/templates/photoGrid.d.ts.map +1 -1
- package/dist/doc/templates/photoGrid.js +3 -0
- package/dist/doc/templates/photoGrid.js.map +1 -1
- package/dist/doc/templates/pullQuote.d.ts.map +1 -1
- package/dist/doc/templates/pullQuote.js +4 -0
- package/dist/doc/templates/pullQuote.js.map +1 -1
- package/dist/doc/templates/quoteBlock.d.ts.map +1 -1
- package/dist/doc/templates/quoteBlock.js +4 -0
- package/dist/doc/templates/quoteBlock.js.map +1 -1
- package/dist/doc/templates/sectionHeader.d.ts.map +1 -1
- package/dist/doc/templates/sectionHeader.js +3 -2
- package/dist/doc/templates/sectionHeader.js.map +1 -1
- package/dist/doc/templates/statHighlight.d.ts.map +1 -1
- package/dist/doc/templates/statHighlight.js +4 -1
- package/dist/doc/templates/statHighlight.js.map +1 -1
- package/dist/doc/templates/titleBlock.d.ts.map +1 -1
- package/dist/doc/templates/titleBlock.js +3 -0
- package/dist/doc/templates/titleBlock.js.map +1 -1
- package/dist/doc/templates/twoColumn.d.ts.map +1 -1
- package/dist/doc/templates/twoColumn.js +7 -1
- package/dist/doc/templates/twoColumn.js.map +1 -1
- package/dist/doc/templates/videoPullQuote.d.ts.map +1 -1
- package/dist/doc/templates/videoPullQuote.js +4 -0
- package/dist/doc/templates/videoPullQuote.js.map +1 -1
- package/dist/doc/templates/videoWithCaption.d.ts.map +1 -1
- package/dist/doc/templates/videoWithCaption.js +3 -0
- package/dist/doc/templates/videoWithCaption.js.map +1 -1
- package/dist/doc/utils/themeUtils.d.ts +9 -0
- package/dist/doc/utils/themeUtils.d.ts.map +1 -1
- package/dist/doc/utils/themeUtils.js +26 -0
- package/dist/doc/utils/themeUtils.js.map +1 -1
- package/dist/markdown/convert.d.ts.map +1 -1
- package/dist/markdown/convert.js +16 -7
- package/dist/markdown/convert.js.map +1 -1
- package/dist/markdown/types.d.ts +4 -2
- package/dist/markdown/types.d.ts.map +1 -1
- package/dist/schemas/BlockTemplates.d.ts +2 -2
- package/dist/schemas/BlockTemplates.d.ts.map +1 -1
- package/dist/schemas/BlockTemplates.js +2 -2
- package/dist/schemas/BlockTemplates.js.map +1 -1
- package/dist/schemas/Doc.d.ts +52 -0
- package/dist/schemas/Doc.d.ts.map +1 -1
- package/dist/schemas/Doc.js.map +1 -1
- package/dist/schemas/themeLibrary.d.ts +2 -2
- package/dist/schemas/themeLibrary.d.ts.map +1 -1
- package/dist/schemas/themeLibrary.js +91 -26
- package/dist/schemas/themeLibrary.js.map +1 -1
- package/dist/storage/ContentContainer.d.ts +87 -0
- package/dist/storage/ContentContainer.d.ts.map +1 -0
- package/dist/storage/ContentContainer.js +122 -0
- package/dist/storage/ContentContainer.js.map +1 -0
- package/dist/storage/MediaProviderFromContainer.d.ts +21 -0
- package/dist/storage/MediaProviderFromContainer.d.ts.map +1 -0
- package/dist/storage/MediaProviderFromContainer.js +79 -0
- package/dist/storage/MediaProviderFromContainer.js.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -1
- package/dist/story/index.d.ts +50 -5
- package/dist/story/index.js +15 -5
- package/dist/{themeLibrary-DR1VRo-8.d.ts → themeLibrary-VOHfPzRB.d.ts} +3 -3
- package/dist/transform/applyTransform.d.ts +22 -0
- package/dist/transform/applyTransform.d.ts.map +1 -0
- package/dist/transform/applyTransform.js +68 -0
- package/dist/transform/applyTransform.js.map +1 -0
- package/dist/transform/blockAnalyzer.d.ts +48 -0
- package/dist/transform/blockAnalyzer.d.ts.map +1 -0
- package/dist/transform/blockAnalyzer.js +135 -0
- package/dist/transform/blockAnalyzer.js.map +1 -0
- package/dist/transform/index.d.ts +6 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/transform/registry.d.ts +19 -0
- package/dist/transform/registry.d.ts.map +1 -0
- package/dist/transform/registry.js +41 -0
- package/dist/transform/registry.js.map +1 -0
- package/dist/transform/styles/dataDriven.d.ts +4 -0
- package/dist/transform/styles/dataDriven.d.ts.map +1 -0
- package/dist/transform/styles/dataDriven.js +15 -0
- package/dist/transform/styles/dataDriven.js.map +1 -0
- package/dist/transform/styles/documentary.d.ts +4 -0
- package/dist/transform/styles/documentary.d.ts.map +1 -0
- package/dist/transform/styles/documentary.js +15 -0
- package/dist/transform/styles/documentary.js.map +1 -0
- package/dist/transform/styles/index.d.ts +6 -0
- package/dist/transform/styles/index.d.ts.map +1 -0
- package/dist/transform/styles/index.js +6 -0
- package/dist/transform/styles/index.js.map +1 -0
- package/dist/transform/styles/magazine.d.ts +4 -0
- package/dist/transform/styles/magazine.d.ts.map +1 -0
- package/dist/transform/styles/magazine.js +15 -0
- package/dist/transform/styles/magazine.js.map +1 -0
- package/dist/transform/styles/minimal.d.ts +4 -0
- package/dist/transform/styles/minimal.d.ts.map +1 -0
- package/dist/transform/styles/minimal.js +15 -0
- package/dist/transform/styles/minimal.js.map +1 -0
- package/dist/transform/styles/narrative.d.ts +4 -0
- package/dist/transform/styles/narrative.d.ts.map +1 -0
- package/dist/transform/styles/narrative.js +15 -0
- package/dist/transform/styles/narrative.js.map +1 -0
- package/dist/transform/templateSelector.d.ts +30 -0
- package/dist/transform/templateSelector.d.ts.map +1 -0
- package/dist/transform/templateSelector.js +218 -0
- package/dist/transform/templateSelector.js.map +1 -0
- package/dist/transform/timingAllocator.d.ts +21 -0
- package/dist/transform/timingAllocator.d.ts.map +1 -0
- package/dist/transform/timingAllocator.js +111 -0
- package/dist/transform/timingAllocator.js.map +1 -0
- package/dist/transform/types.d.ts +86 -0
- package/dist/transform/types.d.ts.map +1 -0
- package/dist/transform/types.js +9 -0
- package/dist/transform/types.js.map +1 -0
- package/dist/{types-DHiv_Pnm.d.ts → types-DYAzisMG.d.ts} +4 -2
- package/package.json +6 -1
- package/src/__tests__/contentContainer.test.ts +282 -0
- package/src/__tests__/markdownToDoc.test.ts +96 -0
- package/src/doc/audioMapping.ts +346 -0
- package/src/doc/index.ts +1 -0
- package/src/doc/markdownToDoc.ts +136 -2
- package/src/doc/templates/comparisonBar.ts +23 -5
- package/src/doc/templates/coverBlock.ts +3 -0
- package/src/doc/templates/dateEvent.ts +4 -0
- package/src/doc/templates/definitionCard.ts +4 -1
- package/src/doc/templates/factCard.ts +4 -0
- package/src/doc/templates/fullBleedQuote.ts +2 -1
- package/src/doc/templates/imageWithCaption.ts +4 -0
- package/src/doc/templates/listBlock.ts +3 -0
- package/src/doc/templates/mapBlock.ts +3 -0
- package/src/doc/templates/photoGrid.ts +3 -0
- package/src/doc/templates/pullQuote.ts +4 -0
- package/src/doc/templates/quoteBlock.ts +4 -0
- package/src/doc/templates/sectionHeader.ts +3 -2
- package/src/doc/templates/statHighlight.ts +4 -1
- package/src/doc/templates/titleBlock.ts +3 -0
- package/src/doc/templates/twoColumn.ts +7 -1
- package/src/doc/templates/videoPullQuote.ts +4 -0
- package/src/doc/templates/videoWithCaption.ts +3 -0
- package/src/doc/utils/themeUtils.ts +29 -0
- package/src/markdown/convert.ts +17 -7
- package/src/markdown/types.ts +4 -2
- package/src/schemas/BlockTemplates.ts +2 -2
- package/src/schemas/Doc.ts +60 -0
- package/src/schemas/themeLibrary.ts +95 -26
- package/src/storage/ContentContainer.ts +200 -0
- package/src/storage/MediaProviderFromContainer.ts +92 -0
- package/src/storage/index.ts +3 -0
- package/src/transform/applyTransform.ts +83 -0
- package/src/transform/blockAnalyzer.ts +181 -0
- package/src/transform/index.ts +20 -0
- package/src/transform/registry.ts +47 -0
- package/src/transform/styles/dataDriven.ts +16 -0
- package/src/transform/styles/documentary.ts +16 -0
- package/src/transform/styles/index.ts +5 -0
- package/src/transform/styles/magazine.ts +16 -0
- package/src/transform/styles/minimal.ts +16 -0
- package/src/transform/styles/narrative.ts +16 -0
- package/src/transform/templateSelector.ts +294 -0
- package/src/transform/timingAllocator.ts +126 -0
- package/src/transform/types.ts +105 -0
- package/dist/chunk-O5HCIUAD.js.map +0 -1
- package/dist/chunk-PJ7AODIM.js.map +0 -1
- package/dist/chunk-S4F2RY37.js.map +0 -1
- package/dist/chunk-URU6QMLY.js.map +0 -1
- package/dist/chunk-VJN7UB2Z.js +0 -145
- package/dist/chunk-VJN7UB2Z.js.map +0 -1
- package/dist/chunk-VP5SZTZ2.js.map +0 -1
- /package/dist/{chunk-6YJPI6VI.js.map → chunk-4X3JQXNM.js.map} +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Selector
|
|
3
|
+
*
|
|
4
|
+
* Selects which extracted elements to promote to visual template blocks
|
|
5
|
+
* and handles color scheme rotation, image interleaving, and template
|
|
6
|
+
* variety. Ported and generalized from qualla-internal's TemplateSelector.
|
|
7
|
+
*/
|
|
8
|
+
import { mapElementToBlock } from '../generate/templateMapper.js';
|
|
9
|
+
import { SeededRandom } from '../random/SeededRandom.js';
|
|
10
|
+
/** Accent positions to rotate through. */
|
|
11
|
+
const ACCENT_POSITIONS = [
|
|
12
|
+
'left-strip',
|
|
13
|
+
'right-strip',
|
|
14
|
+
'bottom-strip',
|
|
15
|
+
'corner-inset',
|
|
16
|
+
];
|
|
17
|
+
/** Ambient motions to rotate on image blocks. */
|
|
18
|
+
const AMBIENT_MOTIONS = [
|
|
19
|
+
'zoomIn',
|
|
20
|
+
'zoomOut',
|
|
21
|
+
'panLeft',
|
|
22
|
+
'panRight',
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Select extractions and build a transformed block sequence.
|
|
26
|
+
*
|
|
27
|
+
* @param analyzed - Analyzed blocks from blockAnalyzer.
|
|
28
|
+
* @param config - The transform style configuration.
|
|
29
|
+
* @param images - Available images for interleaving.
|
|
30
|
+
* @param seed - Random seed for deterministic output.
|
|
31
|
+
*/
|
|
32
|
+
export function selectAndBuild(analyzed, config, images, seed) {
|
|
33
|
+
const rng = new SeededRandom(seed);
|
|
34
|
+
// 1. Collect all extractions across all blocks, filtered by config
|
|
35
|
+
const candidates = collectCandidates(analyzed, config);
|
|
36
|
+
// 2. Determine how many blocks to transform
|
|
37
|
+
const maxTransforms = Math.max(1, Math.floor(analyzed.length * config.transformRatio));
|
|
38
|
+
const selected = candidates.slice(0, maxTransforms);
|
|
39
|
+
// 3. Build the output block sequence
|
|
40
|
+
const result = buildBlockSequence(analyzed, selected, config, images, rng);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Collect candidate extractions from all analyzed blocks, sorted by
|
|
45
|
+
* a combined score of confidence and type preference.
|
|
46
|
+
*/
|
|
47
|
+
function collectCandidates(analyzed, config) {
|
|
48
|
+
const candidates = [];
|
|
49
|
+
for (let i = 0; i < analyzed.length; i++) {
|
|
50
|
+
const ab = analyzed[i];
|
|
51
|
+
// Skip blocks with no meaningful text
|
|
52
|
+
if (ab.bodyWordCount < 5)
|
|
53
|
+
continue;
|
|
54
|
+
for (const element of ab.extractions) {
|
|
55
|
+
if (element.confidence < config.minConfidence)
|
|
56
|
+
continue;
|
|
57
|
+
candidates.push({
|
|
58
|
+
element,
|
|
59
|
+
sourceBlock: ab.block,
|
|
60
|
+
sourceIndex: i,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Sort by: preferred type rank (lower = better), then confidence (higher = better)
|
|
65
|
+
const typeRank = new Map(config.preferredTypes.map((t, i) => [t, i]));
|
|
66
|
+
const maxRank = config.preferredTypes.length;
|
|
67
|
+
candidates.sort((a, b) => {
|
|
68
|
+
const rankA = typeRank.get(a.element.type) ?? maxRank;
|
|
69
|
+
const rankB = typeRank.get(b.element.type) ?? maxRank;
|
|
70
|
+
if (rankA !== rankB)
|
|
71
|
+
return rankA - rankB;
|
|
72
|
+
return b.element.confidence - a.element.confidence;
|
|
73
|
+
});
|
|
74
|
+
// Deduplicate: if the same extracted text appears multiple times
|
|
75
|
+
// (e.g., from overlapping parent/child blocks), keep only the
|
|
76
|
+
// highest-ranked occurrence.
|
|
77
|
+
const seenTexts = new Set();
|
|
78
|
+
const deduplicated = [];
|
|
79
|
+
for (const candidate of candidates) {
|
|
80
|
+
const key = candidate.element.text.trim().toLowerCase();
|
|
81
|
+
if (seenTexts.has(key))
|
|
82
|
+
continue;
|
|
83
|
+
seenTexts.add(key);
|
|
84
|
+
deduplicated.push(candidate);
|
|
85
|
+
}
|
|
86
|
+
return deduplicated;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Build the output block sequence, replacing source blocks with template
|
|
90
|
+
* blocks where extractions were selected, and interleaving images.
|
|
91
|
+
*/
|
|
92
|
+
function buildBlockSequence(analyzed, selected, config, images, rng) {
|
|
93
|
+
// Map: sourceIndex → list of selected extractions for that block
|
|
94
|
+
const blockExtractions = new Map();
|
|
95
|
+
for (const sel of selected) {
|
|
96
|
+
const list = blockExtractions.get(sel.sourceIndex) ?? [];
|
|
97
|
+
list.push(sel);
|
|
98
|
+
blockExtractions.set(sel.sourceIndex, list);
|
|
99
|
+
}
|
|
100
|
+
// Limit extractions per block: cap at blocksPerSection.max and ensure
|
|
101
|
+
// template type variety within each block (no two same-type extractions).
|
|
102
|
+
for (const [idx, list] of blockExtractions) {
|
|
103
|
+
const diverse = [];
|
|
104
|
+
const usedTypes = new Set();
|
|
105
|
+
for (const sel of list) {
|
|
106
|
+
if (usedTypes.has(sel.element.type))
|
|
107
|
+
continue;
|
|
108
|
+
usedTypes.add(sel.element.type);
|
|
109
|
+
diverse.push(sel);
|
|
110
|
+
if (diverse.length >= config.blocksPerSection.max)
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
blockExtractions.set(idx, diverse);
|
|
114
|
+
}
|
|
115
|
+
const blocks = [];
|
|
116
|
+
let transformedCount = 0;
|
|
117
|
+
let insertedCount = 0;
|
|
118
|
+
let colorIndex = 0;
|
|
119
|
+
let blockIdCounter = 0;
|
|
120
|
+
let imageIndex = 0;
|
|
121
|
+
let accentPositionIndex = 0;
|
|
122
|
+
let elementsSinceImage = 0;
|
|
123
|
+
let prevTemplateType = '';
|
|
124
|
+
// Calculate image interleaving interval
|
|
125
|
+
const totalTransformed = Array.from(blockExtractions.values()).reduce((sum, list) => sum + list.length, 0);
|
|
126
|
+
const imageInterval = config.interleaveImages && images.length > 0 && totalTransformed > 0
|
|
127
|
+
? Math.max(2, Math.floor(totalTransformed / (images.length + 1)))
|
|
128
|
+
: Infinity;
|
|
129
|
+
for (let i = 0; i < analyzed.length; i++) {
|
|
130
|
+
const ab = analyzed[i];
|
|
131
|
+
const extractions = blockExtractions.get(i);
|
|
132
|
+
if (!extractions || extractions.length === 0) {
|
|
133
|
+
// Keep the original block unchanged
|
|
134
|
+
blocks.push(ab.block);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
// Insert section header before a group of transformed blocks (if enabled)
|
|
138
|
+
if (config.insertSectionHeaders && ab.block.title) {
|
|
139
|
+
const headerBlock = {
|
|
140
|
+
template: 'sectionHeader',
|
|
141
|
+
id: `transform-header-${blockIdCounter++}`,
|
|
142
|
+
duration: ab.block.duration > 0 ? Math.min(3, ab.block.duration * 0.2) : 3,
|
|
143
|
+
audioSegment: ab.block.audioSegment,
|
|
144
|
+
title: ab.block.title,
|
|
145
|
+
colorScheme: config.colorSchemes[colorIndex % config.colorSchemes.length],
|
|
146
|
+
};
|
|
147
|
+
blocks.push(headerBlock);
|
|
148
|
+
insertedCount++;
|
|
149
|
+
}
|
|
150
|
+
// Convert each selected extraction to a template block.
|
|
151
|
+
// Track the last template used globally (not just within this block)
|
|
152
|
+
// to avoid consecutive same-template slides across the entire output.
|
|
153
|
+
for (const sel of extractions) {
|
|
154
|
+
const colorScheme = config.colorSchemes[colorIndex % config.colorSchemes.length];
|
|
155
|
+
// Build accent image if we have images in the pool
|
|
156
|
+
let accentImage;
|
|
157
|
+
if (images.length > 0 && config.interleaveImages) {
|
|
158
|
+
const img = images[imageIndex % images.length];
|
|
159
|
+
accentImage = {
|
|
160
|
+
src: img.src,
|
|
161
|
+
alt: img.alt ?? '',
|
|
162
|
+
position: ACCENT_POSITIONS[accentPositionIndex % ACCENT_POSITIONS.length],
|
|
163
|
+
ambientMotion: rng.pick(AMBIENT_MOTIONS) ?? 'zoomIn',
|
|
164
|
+
credit: img.credit,
|
|
165
|
+
license: img.license,
|
|
166
|
+
};
|
|
167
|
+
accentPositionIndex++;
|
|
168
|
+
}
|
|
169
|
+
const templateBlock = mapElementToBlock(sel.element, {
|
|
170
|
+
id: `transform-${blockIdCounter++}`,
|
|
171
|
+
duration: ab.block.duration > 0 ? ab.block.duration / extractions.length : 6,
|
|
172
|
+
audioSegment: ab.block.audioSegment,
|
|
173
|
+
colorScheme,
|
|
174
|
+
accentImage,
|
|
175
|
+
sourceStartTime: sel.element.sourcePosition,
|
|
176
|
+
});
|
|
177
|
+
// Apply transition based on style
|
|
178
|
+
if (config.transitionStyle !== 'cut') {
|
|
179
|
+
templateBlock.transition = {
|
|
180
|
+
type: config.transitionStyle === 'mixed'
|
|
181
|
+
? (rng.pick(['fade', 'dissolve']) ?? 'fade')
|
|
182
|
+
: config.transitionStyle,
|
|
183
|
+
duration: 0.5,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// Avoid consecutive same-template blocks by bumping color for variety
|
|
187
|
+
if (templateBlock.template === prevTemplateType) {
|
|
188
|
+
colorIndex++;
|
|
189
|
+
}
|
|
190
|
+
prevTemplateType = templateBlock.template;
|
|
191
|
+
blocks.push(templateBlock);
|
|
192
|
+
transformedCount++;
|
|
193
|
+
colorIndex++;
|
|
194
|
+
elementsSinceImage++;
|
|
195
|
+
// Interleave standalone image at intervals
|
|
196
|
+
if (config.interleaveImages &&
|
|
197
|
+
imageIndex < images.length &&
|
|
198
|
+
elementsSinceImage >= imageInterval) {
|
|
199
|
+
const img = images[imageIndex];
|
|
200
|
+
const imageBlock = {
|
|
201
|
+
template: 'imageWithCaption',
|
|
202
|
+
id: `transform-img-${blockIdCounter++}`,
|
|
203
|
+
duration: 4,
|
|
204
|
+
audioSegment: ab.block.audioSegment,
|
|
205
|
+
imageSrc: img.src,
|
|
206
|
+
imageAlt: img.alt ?? '',
|
|
207
|
+
ambientMotion: rng.pick(AMBIENT_MOTIONS) ?? 'zoomIn',
|
|
208
|
+
};
|
|
209
|
+
blocks.push(imageBlock);
|
|
210
|
+
imageIndex++;
|
|
211
|
+
insertedCount++;
|
|
212
|
+
elementsSinceImage = 0;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { blocks, transformedCount, insertedCount };
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=templateSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateSelector.js","sourceRoot":"","sources":["../../src/transform/templateSelector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,0CAA0C;AAC1C,MAAM,gBAAgB,GAAqB;IACzC,YAAY;IACZ,aAAa;IACb,cAAc;IACd,cAAc;CACf,CAAC;AAEF,iDAAiD;AACjD,MAAM,eAAe,GAAyD;IAC5E,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;CACX,CAAC;AAoBF;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAyB,EACzB,MAA4B,EAC5B,MAAwB,EACxB,IAAY;IAEZ,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAEnC,mEAAmE;IACnE,MAAM,UAAU,GAAG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEvD,4CAA4C;IAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;IACvF,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;I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OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timing Allocator
|
|
3
|
+
*
|
|
4
|
+
* Distributes timing (startTime, duration) across transformed blocks.
|
|
5
|
+
* When the source Doc has audio, blocks are fitted to the overall duration.
|
|
6
|
+
* When no audio is present, uses reading-time estimation.
|
|
7
|
+
*/
|
|
8
|
+
import type { Block } from '../schemas/Doc.js';
|
|
9
|
+
import type { TemplateBlock } from '../schemas/BlockTemplates.js';
|
|
10
|
+
/**
|
|
11
|
+
* Allocate startTime and duration across a mixed array of blocks and
|
|
12
|
+
* template blocks. Template blocks get timing assigned; existing blocks
|
|
13
|
+
* retain their original timing when possible.
|
|
14
|
+
*
|
|
15
|
+
* @param blocks - The output from templateSelector (mixed Block | TemplateBlock).
|
|
16
|
+
* @param totalDuration - The Doc's total duration (from audio or estimation).
|
|
17
|
+
* @returns A new array of Blocks with consistent timing. Template blocks
|
|
18
|
+
* are returned as Blocks (with startTime/duration set, layers empty).
|
|
19
|
+
*/
|
|
20
|
+
export declare function allocateTiming(blocks: Array<Block | TemplateBlock>, totalDuration: number): Block[];
|
|
21
|
+
//# sourceMappingURL=timingAllocator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timingAllocator.d.ts","sourceRoot":"","sources":["../../src/transform/timingAllocator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAUlE;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,KAAK,CAAC,KAAK,GAAG,aAAa,CAAC,EACpC,aAAa,EAAE,MAAM,GACpB,KAAK,EAAE,CA0DT"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timing Allocator
|
|
3
|
+
*
|
|
4
|
+
* Distributes timing (startTime, duration) across transformed blocks.
|
|
5
|
+
* When the source Doc has audio, blocks are fitted to the overall duration.
|
|
6
|
+
* When no audio is present, uses reading-time estimation.
|
|
7
|
+
*/
|
|
8
|
+
import { isTemplateBlock } from '../schemas/BlockTemplates.js';
|
|
9
|
+
/** Minimum block duration in seconds. */
|
|
10
|
+
const MIN_BLOCK_DURATION = 3;
|
|
11
|
+
/** Maximum block duration in seconds. */
|
|
12
|
+
const MAX_BLOCK_DURATION = 20;
|
|
13
|
+
/** Default duration when no timing info is available. */
|
|
14
|
+
const DEFAULT_BLOCK_DURATION = 6;
|
|
15
|
+
/**
|
|
16
|
+
* Allocate startTime and duration across a mixed array of blocks and
|
|
17
|
+
* template blocks. Template blocks get timing assigned; existing blocks
|
|
18
|
+
* retain their original timing when possible.
|
|
19
|
+
*
|
|
20
|
+
* @param blocks - The output from templateSelector (mixed Block | TemplateBlock).
|
|
21
|
+
* @param totalDuration - The Doc's total duration (from audio or estimation).
|
|
22
|
+
* @returns A new array of Blocks with consistent timing. Template blocks
|
|
23
|
+
* are returned as Blocks (with startTime/duration set, layers empty).
|
|
24
|
+
*/
|
|
25
|
+
export function allocateTiming(blocks, totalDuration) {
|
|
26
|
+
if (blocks.length === 0)
|
|
27
|
+
return [];
|
|
28
|
+
const effectiveDuration = totalDuration > 0 ? totalDuration : estimateDefaultDuration(blocks);
|
|
29
|
+
// First pass: assign raw durations
|
|
30
|
+
const durations = blocks.map((block) => {
|
|
31
|
+
if (!isTemplateBlock(block) && block.duration > 0) {
|
|
32
|
+
// Existing block with known duration — keep it
|
|
33
|
+
return block.duration;
|
|
34
|
+
}
|
|
35
|
+
if (isTemplateBlock(block) && block.duration > 0) {
|
|
36
|
+
return block.duration;
|
|
37
|
+
}
|
|
38
|
+
return DEFAULT_BLOCK_DURATION;
|
|
39
|
+
});
|
|
40
|
+
// Scale durations to fit the total
|
|
41
|
+
const rawTotal = durations.reduce((sum, d) => sum + d, 0);
|
|
42
|
+
if (rawTotal > 0 && effectiveDuration > 0) {
|
|
43
|
+
const scale = effectiveDuration / rawTotal;
|
|
44
|
+
for (let i = 0; i < durations.length; i++) {
|
|
45
|
+
durations[i] = clampDuration(durations[i] * scale);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Second pass: assign startTimes and build output Blocks
|
|
49
|
+
let currentTime = 0;
|
|
50
|
+
const result = [];
|
|
51
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
52
|
+
const block = blocks[i];
|
|
53
|
+
const duration = durations[i];
|
|
54
|
+
if (isTemplateBlock(block)) {
|
|
55
|
+
// Convert TemplateBlock to Block shell, preserving all template-specific
|
|
56
|
+
// fields (stat, quote, description, etc.) so they survive through to
|
|
57
|
+
// the player's template expansion step.
|
|
58
|
+
const outputBlock = {
|
|
59
|
+
...block,
|
|
60
|
+
startTime: currentTime,
|
|
61
|
+
duration,
|
|
62
|
+
title: getTemplateTitle(block),
|
|
63
|
+
};
|
|
64
|
+
result.push(outputBlock);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Existing block — update timing
|
|
68
|
+
result.push({
|
|
69
|
+
...block,
|
|
70
|
+
startTime: currentTime,
|
|
71
|
+
duration,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
currentTime += duration;
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/** Clamp a duration to the min/max range. */
|
|
79
|
+
function clampDuration(d) {
|
|
80
|
+
return Math.max(MIN_BLOCK_DURATION, Math.min(MAX_BLOCK_DURATION, d));
|
|
81
|
+
}
|
|
82
|
+
/** Estimate a total duration from block contents when no audio is available. */
|
|
83
|
+
function estimateDefaultDuration(blocks) {
|
|
84
|
+
let totalSeconds = 0;
|
|
85
|
+
for (const block of blocks) {
|
|
86
|
+
if (!isTemplateBlock(block) && block.duration > 0) {
|
|
87
|
+
totalSeconds += block.duration;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
totalSeconds += DEFAULT_BLOCK_DURATION;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return Math.max(totalSeconds, blocks.length * MIN_BLOCK_DURATION);
|
|
94
|
+
}
|
|
95
|
+
/** Extract a display title from a template block if available. */
|
|
96
|
+
function getTemplateTitle(block) {
|
|
97
|
+
if ('title' in block && typeof block.title === 'string') {
|
|
98
|
+
return block.title;
|
|
99
|
+
}
|
|
100
|
+
if ('stat' in block && typeof block.stat === 'string') {
|
|
101
|
+
return block.stat;
|
|
102
|
+
}
|
|
103
|
+
if ('fact' in block && typeof block.fact === 'string') {
|
|
104
|
+
return block.fact;
|
|
105
|
+
}
|
|
106
|
+
if ('quote' in block && typeof block.quote === 'string') {
|
|
107
|
+
return block.quote.slice(0, 60);
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=timingAllocator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timingAllocator.js","sourceRoot":"","sources":["../../src/transform/timingAllocator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,yCAAyC;AACzC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,yCAAyC;AACzC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,yDAAyD;AACzD,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAoC,EACpC,aAAqB;IAErB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,MAAM,iBAAiB,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAE9F,mCAAmC;IACnC,MA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D,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IACD,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the type system for doc block transforms — algorithms that take
|
|
5
|
+
* an existing Doc and produce a new Doc with blocks optimized for visual
|
|
6
|
+
* presentation. Transforms are read-only on the input and deterministic.
|
|
7
|
+
*/
|
|
8
|
+
import type { Doc } from '../schemas/Doc.js';
|
|
9
|
+
import type { ExtractionType } from '../generate/contentExtractor.js';
|
|
10
|
+
import type { ColorScheme } from '../schemas/BlockTemplates.js';
|
|
11
|
+
/** Identifier for a registered transform style. */
|
|
12
|
+
export type TransformStyleId = string;
|
|
13
|
+
/** Summary info for UI dropdowns (mirrors getThemeSummaries pattern). */
|
|
14
|
+
export interface TransformStyleSummary {
|
|
15
|
+
id: TransformStyleId;
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
}
|
|
19
|
+
/** Declarative configuration controlling how a style transforms content. */
|
|
20
|
+
export interface TransformStyleConfig {
|
|
21
|
+
/** Unique style identifier. */
|
|
22
|
+
id: TransformStyleId;
|
|
23
|
+
/** Human-readable name for UI display. */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Short description for UI tooltips. */
|
|
26
|
+
description: string;
|
|
27
|
+
/**
|
|
28
|
+
* Minimum confidence for extracted elements to become template blocks (0–1).
|
|
29
|
+
* Higher values = fewer but higher-quality transformations.
|
|
30
|
+
*/
|
|
31
|
+
minConfidence: number;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum fraction of blocks that get transformed (0–1).
|
|
34
|
+
* 0.2 = light touch, 0.8 = aggressive restructuring.
|
|
35
|
+
*/
|
|
36
|
+
transformRatio: number;
|
|
37
|
+
/** Which extraction types this style prefers, in priority order. */
|
|
38
|
+
preferredTypes: ExtractionType[];
|
|
39
|
+
/** Color schemes to rotate through on template blocks. */
|
|
40
|
+
colorSchemes: ColorScheme[];
|
|
41
|
+
/** Whether to insert sectionHeader blocks between groups. */
|
|
42
|
+
insertSectionHeaders: boolean;
|
|
43
|
+
/** Whether to interleave imageWithCaption blocks when images are available. */
|
|
44
|
+
interleaveImages: boolean;
|
|
45
|
+
/** Target density of template blocks per section. */
|
|
46
|
+
blocksPerSection: {
|
|
47
|
+
min: number;
|
|
48
|
+
max: number;
|
|
49
|
+
};
|
|
50
|
+
/** Transition style preference for transformed blocks. */
|
|
51
|
+
transitionStyle: 'cut' | 'fade' | 'dissolve' | 'mixed';
|
|
52
|
+
}
|
|
53
|
+
/** Image metadata for image interleaving. */
|
|
54
|
+
export interface TransformImage {
|
|
55
|
+
/** Image source path or URL. */
|
|
56
|
+
src: string;
|
|
57
|
+
/** Alt text for accessibility. */
|
|
58
|
+
alt?: string;
|
|
59
|
+
/** Photo credit. */
|
|
60
|
+
credit?: string;
|
|
61
|
+
/** License identifier. */
|
|
62
|
+
license?: string;
|
|
63
|
+
}
|
|
64
|
+
/** Options passed to `applyTransform()`. */
|
|
65
|
+
export interface TransformOptions {
|
|
66
|
+
/** Deterministic seed. Default: hash of doc.articleId. */
|
|
67
|
+
seed?: number;
|
|
68
|
+
/** Available images for image interleaving / accent images. */
|
|
69
|
+
images?: TransformImage[];
|
|
70
|
+
/** Theme ID to embed in the output Doc. */
|
|
71
|
+
themeId?: string;
|
|
72
|
+
/** Override specific style config values. */
|
|
73
|
+
overrides?: Partial<TransformStyleConfig>;
|
|
74
|
+
}
|
|
75
|
+
/** Result of applying a transform. */
|
|
76
|
+
export interface TransformResult {
|
|
77
|
+
/** The transformed Doc. Input doc is NOT mutated. */
|
|
78
|
+
doc: Doc;
|
|
79
|
+
/** Statistics about what changed. */
|
|
80
|
+
stats: {
|
|
81
|
+
totalInputBlocks: number;
|
|
82
|
+
transformedBlocks: number;
|
|
83
|
+
insertedBlocks: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/transform/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAIhE,mDAAmD;AACnD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,gBAAgB,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAID,4EAA4E;AAC5E,MAAM,WAAW,oBAAoB;IACnC,+BAA+B;IAC/B,EAAE,EAAE,gBAAgB,CAAC;IACrB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB,oEAAoE;IACpE,cAAc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ms — algorithms that take
|
|
5
|
+
* an existing Doc and produce a new Doc with blocks optimized for visual
|
|
6
|
+
* presentation. Transforms are read-only on the input and deterministic.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/transform/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -93,8 +93,10 @@ interface MarkdownNodeBase {
|
|
|
93
93
|
* → `{ template: 'chart', params: { colorScheme: 'blue' } }`
|
|
94
94
|
*/
|
|
95
95
|
interface HeadingTemplateAnnotation {
|
|
96
|
-
/** Template name (first token inside `{[…]}`)
|
|
97
|
-
|
|
96
|
+
/** Template name (first token inside `{[…]}`).
|
|
97
|
+
* Optional when the annotation contains only key=value pairs
|
|
98
|
+
* (e.g., `{[audio=intro.mp3]}`). */
|
|
99
|
+
template?: string;
|
|
98
100
|
/** Optional key-value parameters (remaining `key=value` tokens) */
|
|
99
101
|
params?: Record<string, string>;
|
|
100
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/squisq",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Headless utilities for doc/block rendering, spatial math, Markdown, and storage",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bendyline",
|
|
@@ -80,6 +80,11 @@
|
|
|
80
80
|
"types": "./dist/generate/index.d.ts",
|
|
81
81
|
"import": "./dist/generate/index.js",
|
|
82
82
|
"default": "./dist/generate/index.js"
|
|
83
|
+
},
|
|
84
|
+
"./transform": {
|
|
85
|
+
"types": "./dist/transform/index.d.ts",
|
|
86
|
+
"import": "./dist/transform/index.js",
|
|
87
|
+
"default": "./dist/transform/index.js"
|
|
83
88
|
}
|
|
84
89
|
},
|
|
85
90
|
"scripts": {
|