-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05f1631
commit ca0566b
Showing
8 changed files
with
92 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Document, Packer, Paragraph, TextRun, AlignmentType } from 'docx' | ||
import { Segment } from './transcript' | ||
import { formatDuration } from '~/components/HtmlView' | ||
|
||
export async function toDocx(title: string, segments: Segment[], direction: 'rtl' | 'ltr') { | ||
const doc = new Document({ | ||
sections: [ | ||
{ | ||
properties: { | ||
page: { | ||
textDirection: direction === 'rtl' ? 'lrTb' : 'tbRl', | ||
}, | ||
}, | ||
children: [ | ||
// Add the title as a centered paragraph | ||
new Paragraph({ | ||
alignment: AlignmentType.CENTER, | ||
children: [ | ||
new TextRun({ | ||
text: title, | ||
color: '1565C0', | ||
size: 36 * 1.5, | ||
bold: true, | ||
}), | ||
], | ||
}), | ||
// Add an empty paragraph for spacing after the title | ||
new Paragraph({}), | ||
...segments.map((segment) => { | ||
const duration = formatDuration(segment.start, segment.stop, direction) | ||
return new Paragraph({ | ||
alignment: direction === 'rtl' ? AlignmentType.RIGHT : AlignmentType.LEFT, | ||
children: [new TextRun({ text: duration, bold: true }), new TextRun({ text: `\n${segment.text}`, break: 1 })], | ||
}) | ||
}), | ||
], | ||
}, | ||
], | ||
}) | ||
|
||
const blob = await Packer.toBlob(doc) | ||
return blob | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters