fconvert 0.1.2 → 0.1.4
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 +3 -0
- package/dist/convert +0 -0
- package/dist/fconvert-picker +0 -0
- package/package.json +1 -1
- package/src/cli/output-picker.ts +3 -1
- package/src/formats/aliases.ts +16 -0
- package/src/formats/common.ts +123 -53
- package/src/handlers/bridges/text.ts +24 -2
- package/src/handlers/native/ffmpeg.ts +37 -3
- package/src/handlers/native/imagemagick.ts +25 -1
- package/src/handlers/native/pandoc.ts +17 -0
- package/src/handlers/native/sevenzip.ts +11 -9
- package/test/unit/planner.test.ts +32 -1
- package/tools/format-picker/main.go +35 -9
package/README.md
CHANGED
package/dist/convert
CHANGED
|
Binary file
|
package/dist/fconvert-picker
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/cli/output-picker.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { FormatRegistry } from "../formats/registry.ts";
|
|
|
9
9
|
interface PickerPayload {
|
|
10
10
|
prompt: string;
|
|
11
11
|
query: string;
|
|
12
|
+
preferred: string;
|
|
12
13
|
options: Array<{
|
|
13
14
|
id: string;
|
|
14
15
|
name: string;
|
|
@@ -110,7 +111,8 @@ export async function pickOutputFormatInteractive(
|
|
|
110
111
|
|
|
111
112
|
const payload: PickerPayload = {
|
|
112
113
|
prompt: "output format",
|
|
113
|
-
query:
|
|
114
|
+
query: "",
|
|
115
|
+
preferred: extname(inputPath).replace(/^\./, ""),
|
|
114
116
|
options: registry.all().map((format) => ({
|
|
115
117
|
id: format.id,
|
|
116
118
|
name: format.name,
|
package/src/formats/aliases.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
export const FORMAT_ALIASES: Record<string, string> = {
|
|
2
2
|
jpg: "jpeg",
|
|
3
3
|
jpeg: "jpeg",
|
|
4
|
+
tif: "tiff",
|
|
5
|
+
tiff: "tiff",
|
|
6
|
+
htm: "html",
|
|
7
|
+
html: "html",
|
|
4
8
|
markdown: "md",
|
|
9
|
+
md: "md",
|
|
5
10
|
yml: "yaml",
|
|
11
|
+
yaml: "yaml",
|
|
12
|
+
oga: "ogg",
|
|
13
|
+
mpg: "mpeg",
|
|
14
|
+
m2ts: "ts",
|
|
15
|
+
mts: "ts",
|
|
16
|
+
f4v: "flv",
|
|
17
|
+
asciidoc: "adoc",
|
|
18
|
+
texi: "texinfo",
|
|
6
19
|
text: "txt",
|
|
7
20
|
binary: "bin",
|
|
21
|
+
midi: "mid",
|
|
22
|
+
jsonl: "json",
|
|
23
|
+
ndjson: "json",
|
|
8
24
|
};
|
package/src/formats/common.ts
CHANGED
|
@@ -1,69 +1,139 @@
|
|
|
1
1
|
import type { Category, FormatDefinition } from "../core/types.ts";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
id: string
|
|
5
|
-
name: string
|
|
6
|
-
extension: string
|
|
7
|
-
mime: string[]
|
|
8
|
-
category: Category[]
|
|
9
|
-
aliases
|
|
10
|
-
|
|
3
|
+
interface FormatSeed {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
extension: string;
|
|
7
|
+
mime: string[];
|
|
8
|
+
category: Category[];
|
|
9
|
+
aliases?: string[];
|
|
10
|
+
extraExtensions?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function defineFormat(seed: FormatSeed): FormatDefinition {
|
|
14
|
+
const aliases = (seed.aliases ?? []).map((value) => value.toLowerCase());
|
|
15
|
+
const extensions = [seed.extension, ...(seed.extraExtensions ?? [])].map((value) => value.toLowerCase());
|
|
11
16
|
return {
|
|
12
|
-
id,
|
|
13
|
-
name,
|
|
14
|
-
extension,
|
|
15
|
-
extensions
|
|
16
|
-
mime,
|
|
17
|
-
category,
|
|
17
|
+
id: seed.id.toLowerCase(),
|
|
18
|
+
name: seed.name,
|
|
19
|
+
extension: seed.extension.toLowerCase(),
|
|
20
|
+
extensions,
|
|
21
|
+
mime: seed.mime,
|
|
22
|
+
category: seed.category,
|
|
18
23
|
aliases,
|
|
19
24
|
};
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
export const COMMON_FORMATS: FormatDefinition[] = [
|
|
23
|
-
defineFormat("png", "Portable Network Graphics", "png", ["image/png"], ["image"]),
|
|
24
|
-
defineFormat("jpeg", "JPEG Image", "jpg", ["image/jpeg"], ["image"], ["jpg"]),
|
|
25
|
-
defineFormat("webp", "WebP Image", "webp", ["image/webp"], ["image"]),
|
|
26
|
-
defineFormat("gif", "Graphics Interchange Format", "gif", ["image/gif"], ["image", "video"]),
|
|
27
|
-
defineFormat("bmp", "Bitmap Image", "bmp", ["image/bmp"], ["image"]),
|
|
28
|
-
defineFormat("tiff", "Tagged Image File Format", "tiff", ["image/tiff"], ["image"], ["tif"]),
|
|
29
|
-
defineFormat("svg", "Scalable Vector Graphics", "svg", ["image/svg+xml"], ["image", "vector", "document"]),
|
|
28
|
+
defineFormat({ id: "png", name: "Portable Network Graphics", extension: "png", mime: ["image/png"], category: ["image"] }),
|
|
29
|
+
defineFormat({ id: "jpeg", name: "JPEG Image", extension: "jpg", extraExtensions: ["jpeg", "jpe"], mime: ["image/jpeg"], category: ["image"], aliases: ["jpg", "jpeg"] }),
|
|
30
|
+
defineFormat({ id: "webp", name: "WebP Image", extension: "webp", mime: ["image/webp"], category: ["image"] }),
|
|
31
|
+
defineFormat({ id: "gif", name: "Graphics Interchange Format", extension: "gif", mime: ["image/gif"], category: ["image", "video"] }),
|
|
32
|
+
defineFormat({ id: "bmp", name: "Bitmap Image", extension: "bmp", mime: ["image/bmp"], category: ["image"] }),
|
|
33
|
+
defineFormat({ id: "tiff", name: "Tagged Image File Format", extension: "tiff", extraExtensions: ["tif"], mime: ["image/tiff"], category: ["image"], aliases: ["tif"] }),
|
|
34
|
+
defineFormat({ id: "svg", name: "Scalable Vector Graphics", extension: "svg", mime: ["image/svg+xml"], category: ["image", "vector", "document"] }),
|
|
35
|
+
defineFormat({ id: "avif", name: "AVIF Image", extension: "avif", mime: ["image/avif"], category: ["image"] }),
|
|
36
|
+
defineFormat({ id: "heic", name: "HEIC Image", extension: "heic", extraExtensions: ["heif"], mime: ["image/heic"], category: ["image"], aliases: ["heif"] }),
|
|
37
|
+
defineFormat({ id: "ico", name: "Icon Image", extension: "ico", mime: ["image/x-icon"], category: ["image"] }),
|
|
38
|
+
defineFormat({ id: "jp2", name: "JPEG 2000", extension: "jp2", extraExtensions: ["j2k"], mime: ["image/jp2"], category: ["image"], aliases: ["j2k"] }),
|
|
39
|
+
defineFormat({ id: "psd", name: "Photoshop Document", extension: "psd", mime: ["image/vnd.adobe.photoshop"], category: ["image", "document"] }),
|
|
40
|
+
defineFormat({ id: "tga", name: "Targa Image", extension: "tga", mime: ["image/x-tga"], category: ["image"] }),
|
|
41
|
+
defineFormat({ id: "dds", name: "DirectDraw Surface", extension: "dds", mime: ["image/vnd.ms-dds"], category: ["image"] }),
|
|
42
|
+
defineFormat({ id: "hdr", name: "Radiance HDR", extension: "hdr", mime: ["image/vnd.radiance"], category: ["image"] }),
|
|
43
|
+
defineFormat({ id: "exr", name: "OpenEXR", extension: "exr", mime: ["image/aces"], category: ["image"] }),
|
|
44
|
+
defineFormat({ id: "pnm", name: "Portable Anymap", extension: "pnm", mime: ["image/x-portable-anymap"], category: ["image"] }),
|
|
45
|
+
defineFormat({ id: "pbm", name: "Portable Bitmap", extension: "pbm", mime: ["image/x-portable-bitmap"], category: ["image"] }),
|
|
46
|
+
defineFormat({ id: "pgm", name: "Portable Graymap", extension: "pgm", mime: ["image/x-portable-graymap"], category: ["image"] }),
|
|
47
|
+
defineFormat({ id: "ppm", name: "Portable Pixmap", extension: "ppm", mime: ["image/x-portable-pixmap"], category: ["image"] }),
|
|
48
|
+
defineFormat({ id: "apng", name: "Animated PNG", extension: "apng", mime: ["image/apng"], category: ["image", "video"] }),
|
|
30
49
|
|
|
31
|
-
defineFormat("wav", "Waveform Audio", "wav", ["audio/wav"], ["audio"]),
|
|
32
|
-
defineFormat("mp3", "MP3 Audio", "mp3", ["audio/mpeg"], ["audio"]),
|
|
33
|
-
defineFormat("flac", "FLAC Audio", "flac", ["audio/flac"], ["audio"]),
|
|
34
|
-
defineFormat("ogg", "Ogg Audio", "ogg", ["audio/ogg"], ["audio"]),
|
|
50
|
+
defineFormat({ id: "wav", name: "Waveform Audio", extension: "wav", mime: ["audio/wav"], category: ["audio"] }),
|
|
51
|
+
defineFormat({ id: "mp3", name: "MP3 Audio", extension: "mp3", mime: ["audio/mpeg"], category: ["audio"] }),
|
|
52
|
+
defineFormat({ id: "flac", name: "FLAC Audio", extension: "flac", mime: ["audio/flac"], category: ["audio"] }),
|
|
53
|
+
defineFormat({ id: "ogg", name: "Ogg Audio", extension: "ogg", extraExtensions: ["oga"], mime: ["audio/ogg"], category: ["audio"], aliases: ["oga"] }),
|
|
54
|
+
defineFormat({ id: "aac", name: "AAC Audio", extension: "aac", mime: ["audio/aac"], category: ["audio"] }),
|
|
55
|
+
defineFormat({ id: "m4a", name: "MPEG-4 Audio", extension: "m4a", mime: ["audio/mp4"], category: ["audio"] }),
|
|
56
|
+
defineFormat({ id: "wma", name: "Windows Media Audio", extension: "wma", mime: ["audio/x-ms-wma"], category: ["audio"] }),
|
|
57
|
+
defineFormat({ id: "aiff", name: "Audio Interchange File Format", extension: "aiff", extraExtensions: ["aif"], mime: ["audio/aiff"], category: ["audio"], aliases: ["aif"] }),
|
|
58
|
+
defineFormat({ id: "opus", name: "Opus Audio", extension: "opus", mime: ["audio/opus"], category: ["audio"] }),
|
|
59
|
+
defineFormat({ id: "amr", name: "AMR Audio", extension: "amr", mime: ["audio/amr"], category: ["audio"] }),
|
|
60
|
+
defineFormat({ id: "ac3", name: "Dolby Digital AC-3", extension: "ac3", mime: ["audio/ac3"], category: ["audio"] }),
|
|
61
|
+
defineFormat({ id: "dts", name: "Digital Theater Systems Audio", extension: "dts", mime: ["audio/vnd.dts"], category: ["audio"] }),
|
|
62
|
+
defineFormat({ id: "mka", name: "Matroska Audio", extension: "mka", mime: ["audio/x-matroska"], category: ["audio"] }),
|
|
63
|
+
defineFormat({ id: "mid", name: "MIDI Sequence", extension: "mid", extraExtensions: ["midi"], mime: ["audio/midi"], category: ["audio"], aliases: ["midi"] }),
|
|
35
64
|
|
|
36
|
-
defineFormat("mp4", "MPEG-4 Video", "mp4", ["video/mp4"], ["video"]),
|
|
37
|
-
defineFormat("
|
|
38
|
-
defineFormat("
|
|
39
|
-
defineFormat("
|
|
65
|
+
defineFormat({ id: "mp4", name: "MPEG-4 Video", extension: "mp4", mime: ["video/mp4"], category: ["video"] }),
|
|
66
|
+
defineFormat({ id: "m4v", name: "MPEG-4 Video", extension: "m4v", mime: ["video/x-m4v"], category: ["video"] }),
|
|
67
|
+
defineFormat({ id: "mov", name: "QuickTime MOV", extension: "mov", mime: ["video/quicktime"], category: ["video"] }),
|
|
68
|
+
defineFormat({ id: "webm", name: "WebM Video", extension: "webm", mime: ["video/webm"], category: ["video"] }),
|
|
69
|
+
defineFormat({ id: "wmv", name: "Windows Media Video", extension: "wmv", mime: ["video/x-ms-wmv"], category: ["video"] }),
|
|
70
|
+
defineFormat({ id: "mkv", name: "Matroska Video", extension: "mkv", mime: ["video/x-matroska"], category: ["video"] }),
|
|
71
|
+
defineFormat({ id: "avi", name: "Audio Video Interleave", extension: "avi", mime: ["video/x-msvideo"], category: ["video"] }),
|
|
72
|
+
defineFormat({ id: "mpeg", name: "MPEG Video", extension: "mpeg", extraExtensions: ["mpg"], mime: ["video/mpeg"], category: ["video"], aliases: ["mpg"] }),
|
|
73
|
+
defineFormat({ id: "3gp", name: "3GPP Video", extension: "3gp", mime: ["video/3gpp"], category: ["video"] }),
|
|
74
|
+
defineFormat({ id: "3g2", name: "3GPP2 Video", extension: "3g2", mime: ["video/3gpp2"], category: ["video"] }),
|
|
75
|
+
defineFormat({ id: "flv", name: "Flash Video", extension: "flv", extraExtensions: ["f4v"], mime: ["video/x-flv"], category: ["video"], aliases: ["f4v"] }),
|
|
76
|
+
defineFormat({ id: "ts", name: "MPEG Transport Stream", extension: "ts", extraExtensions: ["m2ts", "mts"], mime: ["video/mp2t"], category: ["video"], aliases: ["m2ts", "mts"] }),
|
|
77
|
+
defineFormat({ id: "vob", name: "DVD Video Object", extension: "vob", mime: ["video/dvd"], category: ["video"] }),
|
|
78
|
+
defineFormat({ id: "ogv", name: "Ogg Video", extension: "ogv", mime: ["video/ogg"], category: ["video"] }),
|
|
79
|
+
defineFormat({ id: "asf", name: "Advanced Systems Format", extension: "asf", mime: ["video/x-ms-asf"], category: ["video"] }),
|
|
40
80
|
|
|
41
|
-
defineFormat("txt", "Plain Text", "txt", ["text/plain"], ["text"]),
|
|
42
|
-
defineFormat("md", "Markdown", "md", ["text/markdown"], ["text", "document"], ["markdown"]),
|
|
43
|
-
defineFormat("html", "HyperText Markup Language", "html", ["text/html"], ["text", "document"]),
|
|
44
|
-
defineFormat("
|
|
45
|
-
defineFormat("
|
|
46
|
-
defineFormat("
|
|
47
|
-
defineFormat("
|
|
48
|
-
defineFormat("
|
|
49
|
-
defineFormat("
|
|
50
|
-
defineFormat("
|
|
81
|
+
defineFormat({ id: "txt", name: "Plain Text", extension: "txt", mime: ["text/plain"], category: ["text"] }),
|
|
82
|
+
defineFormat({ id: "md", name: "Markdown", extension: "md", extraExtensions: ["markdown"], mime: ["text/markdown"], category: ["text", "document"], aliases: ["markdown"] }),
|
|
83
|
+
defineFormat({ id: "html", name: "HyperText Markup Language", extension: "html", extraExtensions: ["htm"], mime: ["text/html"], category: ["text", "document"], aliases: ["htm"] }),
|
|
84
|
+
defineFormat({ id: "xhtml", name: "XHTML", extension: "xhtml", mime: ["application/xhtml+xml"], category: ["text", "document"] }),
|
|
85
|
+
defineFormat({ id: "json", name: "JSON", extension: "json", extraExtensions: ["jsonl", "ndjson"], mime: ["application/json"], category: ["data", "text"], aliases: ["jsonl", "ndjson"] }),
|
|
86
|
+
defineFormat({ id: "xml", name: "XML", extension: "xml", mime: ["application/xml", "text/xml"], category: ["data", "text"] }),
|
|
87
|
+
defineFormat({ id: "yaml", name: "YAML", extension: "yml", extraExtensions: ["yaml"], mime: ["application/yaml", "text/yaml"], category: ["data", "text"], aliases: ["yaml"] }),
|
|
88
|
+
defineFormat({ id: "toml", name: "TOML", extension: "toml", mime: ["application/toml"], category: ["data", "text"] }),
|
|
89
|
+
defineFormat({ id: "ini", name: "INI Config", extension: "ini", mime: ["text/plain"], category: ["data", "text"] }),
|
|
90
|
+
defineFormat({ id: "csv", name: "Comma Separated Values", extension: "csv", mime: ["text/csv"], category: ["data", "text"] }),
|
|
91
|
+
defineFormat({ id: "tsv", name: "Tab Separated Values", extension: "tsv", mime: ["text/tab-separated-values"], category: ["data", "text"] }),
|
|
92
|
+
defineFormat({ id: "css", name: "Cascading Style Sheets", extension: "css", mime: ["text/css"], category: ["code", "text"] }),
|
|
93
|
+
defineFormat({ id: "js", name: "JavaScript", extension: "js", mime: ["text/javascript"], category: ["code", "text"] }),
|
|
94
|
+
defineFormat({ id: "py", name: "Python Script", extension: "py", mime: ["text/x-python"], category: ["code", "text"] }),
|
|
95
|
+
defineFormat({ id: "sh", name: "Shell Script", extension: "sh", mime: ["application/x-sh"], category: ["code", "text"] }),
|
|
96
|
+
defineFormat({ id: "bat", name: "Batch Script", extension: "bat", mime: ["application/x-bat"], category: ["code", "text"] }),
|
|
97
|
+
defineFormat({ id: "ps1", name: "PowerShell Script", extension: "ps1", mime: ["text/plain"], category: ["code", "text"] }),
|
|
98
|
+
defineFormat({ id: "rst", name: "reStructuredText", extension: "rst", mime: ["text/x-rst"], category: ["text", "document"] }),
|
|
99
|
+
defineFormat({ id: "tex", name: "LaTeX", extension: "tex", mime: ["application/x-tex"], category: ["text", "document"] }),
|
|
100
|
+
defineFormat({ id: "adoc", name: "AsciiDoc", extension: "adoc", extraExtensions: ["asciidoc"], mime: ["text/plain"], category: ["text", "document"], aliases: ["asciidoc"] }),
|
|
101
|
+
defineFormat({ id: "bbcode", name: "BBCode", extension: "bbcode", mime: ["text/plain"], category: ["text", "document"] }),
|
|
102
|
+
defineFormat({ id: "org", name: "Org Mode", extension: "org", mime: ["text/plain"], category: ["text", "document"] }),
|
|
51
103
|
|
|
52
|
-
defineFormat("pdf", "Portable Document Format", "pdf", ["application/pdf"], ["document"]),
|
|
53
|
-
defineFormat("docx", "Word Document", "docx", ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], ["document"]),
|
|
54
|
-
defineFormat("
|
|
55
|
-
defineFormat("
|
|
104
|
+
defineFormat({ id: "pdf", name: "Portable Document Format", extension: "pdf", mime: ["application/pdf"], category: ["document"] }),
|
|
105
|
+
defineFormat({ id: "docx", name: "Word Document", extension: "docx", mime: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], category: ["document"] }),
|
|
106
|
+
defineFormat({ id: "odt", name: "OpenDocument Text", extension: "odt", mime: ["application/vnd.oasis.opendocument.text"], category: ["document"] }),
|
|
107
|
+
defineFormat({ id: "rtf", name: "Rich Text Format", extension: "rtf", mime: ["application/rtf"], category: ["document", "text"] }),
|
|
108
|
+
defineFormat({ id: "epub", name: "EPUB eBook", extension: "epub", mime: ["application/epub+zip"], category: ["document"] }),
|
|
109
|
+
defineFormat({ id: "fb2", name: "FictionBook", extension: "fb2", mime: ["application/x-fictionbook+xml"], category: ["document", "text"] }),
|
|
110
|
+
defineFormat({ id: "pptx", name: "PowerPoint Presentation", extension: "pptx", mime: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"], category: ["presentation", "document"] }),
|
|
111
|
+
defineFormat({ id: "xlsx", name: "Excel Workbook", extension: "xlsx", mime: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], category: ["spreadsheet", "document"] }),
|
|
112
|
+
defineFormat({ id: "ods", name: "OpenDocument Spreadsheet", extension: "ods", mime: ["application/vnd.oasis.opendocument.spreadsheet"], category: ["spreadsheet", "document"] }),
|
|
113
|
+
defineFormat({ id: "odp", name: "OpenDocument Presentation", extension: "odp", mime: ["application/vnd.oasis.opendocument.presentation"], category: ["presentation", "document"] }),
|
|
114
|
+
defineFormat({ id: "docbook", name: "DocBook", extension: "docbook", mime: ["application/xml"], category: ["document", "text"] }),
|
|
115
|
+
defineFormat({ id: "jats", name: "JATS XML", extension: "jats", mime: ["application/xml"], category: ["document", "text"] }),
|
|
116
|
+
defineFormat({ id: "texinfo", name: "Texinfo", extension: "texi", extraExtensions: ["texinfo"], mime: ["text/plain"], category: ["document", "text"], aliases: ["texi"] }),
|
|
117
|
+
defineFormat({ id: "eps", name: "Encapsulated PostScript", extension: "eps", mime: ["application/postscript"], category: ["vector", "document"] }),
|
|
118
|
+
defineFormat({ id: "ps", name: "PostScript", extension: "ps", mime: ["application/postscript"], category: ["vector", "document"] }),
|
|
56
119
|
|
|
57
|
-
defineFormat("zip", "ZIP Archive", "zip", ["application/zip"], ["archive"]),
|
|
58
|
-
defineFormat("tar", "TAR Archive", "tar", ["application/x-tar"], ["archive"]),
|
|
59
|
-
defineFormat("7z", "7-Zip Archive", "7z", ["application/x-7z-compressed"], ["archive"]),
|
|
120
|
+
defineFormat({ id: "zip", name: "ZIP Archive", extension: "zip", mime: ["application/zip"], category: ["archive"] }),
|
|
121
|
+
defineFormat({ id: "tar", name: "TAR Archive", extension: "tar", mime: ["application/x-tar"], category: ["archive"] }),
|
|
122
|
+
defineFormat({ id: "7z", name: "7-Zip Archive", extension: "7z", mime: ["application/x-7z-compressed"], category: ["archive"] }),
|
|
123
|
+
defineFormat({ id: "gz", name: "Gzip Archive", extension: "gz", mime: ["application/gzip"], category: ["archive"] }),
|
|
124
|
+
defineFormat({ id: "bz2", name: "Bzip2 Archive", extension: "bz2", mime: ["application/x-bzip2"], category: ["archive"] }),
|
|
125
|
+
defineFormat({ id: "xz", name: "XZ Archive", extension: "xz", mime: ["application/x-xz"], category: ["archive"] }),
|
|
126
|
+
defineFormat({ id: "rar", name: "RAR Archive", extension: "rar", mime: ["application/vnd.rar"], category: ["archive"] }),
|
|
127
|
+
defineFormat({ id: "cab", name: "Cabinet Archive", extension: "cab", mime: ["application/vnd.ms-cab-compressed"], category: ["archive"] }),
|
|
128
|
+
defineFormat({ id: "iso", name: "ISO Disk Image", extension: "iso", mime: ["application/x-iso9660-image"], category: ["archive", "binary"] }),
|
|
60
129
|
|
|
61
|
-
defineFormat("ttf", "TrueType Font", "ttf", ["font/ttf"], ["font"]),
|
|
62
|
-
defineFormat("otf", "OpenType Font", "otf", ["font/otf"], ["font"]),
|
|
63
|
-
defineFormat("woff", "Web Open Font Format", "woff", ["font/woff"], ["font"]),
|
|
64
|
-
defineFormat("woff2", "Web Open Font Format 2", "woff2", ["font/woff2"], ["font"]),
|
|
130
|
+
defineFormat({ id: "ttf", name: "TrueType Font", extension: "ttf", mime: ["font/ttf"], category: ["font"] }),
|
|
131
|
+
defineFormat({ id: "otf", name: "OpenType Font", extension: "otf", mime: ["font/otf"], category: ["font"] }),
|
|
132
|
+
defineFormat({ id: "woff", name: "Web Open Font Format", extension: "woff", mime: ["font/woff"], category: ["font"] }),
|
|
133
|
+
defineFormat({ id: "woff2", name: "Web Open Font Format 2", extension: "woff2", mime: ["font/woff2"], category: ["font"] }),
|
|
134
|
+
defineFormat({ id: "eot", name: "Embedded OpenType", extension: "eot", mime: ["application/vnd.ms-fontobject"], category: ["font"] }),
|
|
65
135
|
|
|
66
|
-
defineFormat("base64", "Base64 Text", "b64", ["text/plain"], ["data", "text"]),
|
|
67
|
-
defineFormat("hex", "Hex Text", "hex", ["text/plain"], ["data", "text"]),
|
|
68
|
-
defineFormat("bin", "Binary Blob", "bin", ["application/octet-stream"], ["binary"]),
|
|
136
|
+
defineFormat({ id: "base64", name: "Base64 Text", extension: "b64", mime: ["text/plain"], category: ["data", "text"] }),
|
|
137
|
+
defineFormat({ id: "hex", name: "Hex Text", extension: "hex", mime: ["text/plain"], category: ["data", "text"] }),
|
|
138
|
+
defineFormat({ id: "bin", name: "Binary Blob", extension: "bin", mime: ["application/octet-stream"], category: ["binary"] }),
|
|
69
139
|
];
|
|
@@ -3,7 +3,29 @@ import { dirname } from "node:path";
|
|
|
3
3
|
import type { ConversionHandler, ConvertRequest, HandlerContext, HandlerResult, HandlerRule } from "../base.ts";
|
|
4
4
|
import { toFileArtifact } from "../../artifacts/file.ts";
|
|
5
5
|
|
|
6
|
-
const TEXTISH = [
|
|
6
|
+
const TEXTISH = [
|
|
7
|
+
"txt",
|
|
8
|
+
"md",
|
|
9
|
+
"html",
|
|
10
|
+
"xhtml",
|
|
11
|
+
"json",
|
|
12
|
+
"xml",
|
|
13
|
+
"yaml",
|
|
14
|
+
"toml",
|
|
15
|
+
"ini",
|
|
16
|
+
"csv",
|
|
17
|
+
"tsv",
|
|
18
|
+
"rst",
|
|
19
|
+
"adoc",
|
|
20
|
+
"bbcode",
|
|
21
|
+
"org",
|
|
22
|
+
"tex",
|
|
23
|
+
"docbook",
|
|
24
|
+
"jats",
|
|
25
|
+
"base64",
|
|
26
|
+
"hex",
|
|
27
|
+
"bin",
|
|
28
|
+
];
|
|
7
29
|
|
|
8
30
|
function textRules(): HandlerRule[] {
|
|
9
31
|
const rules: HandlerRule[] = [];
|
|
@@ -66,7 +88,7 @@ function fromStructuredToText(inputFormat: string, text: string): string {
|
|
|
66
88
|
}
|
|
67
89
|
}
|
|
68
90
|
|
|
69
|
-
if (inputFormat === "html" || inputFormat === "xml") {
|
|
91
|
+
if (inputFormat === "html" || inputFormat === "xhtml" || inputFormat === "xml") {
|
|
70
92
|
return text.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
71
93
|
}
|
|
72
94
|
|
|
@@ -5,9 +5,43 @@ import { runCommand } from "../exec.ts";
|
|
|
5
5
|
import { CliError, ExitCode } from "../../core/errors.ts";
|
|
6
6
|
import { toFileArtifact } from "../../artifacts/file.ts";
|
|
7
7
|
|
|
8
|
-
const AUDIO = [
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const AUDIO = [
|
|
9
|
+
"wav",
|
|
10
|
+
"mp3",
|
|
11
|
+
"flac",
|
|
12
|
+
"ogg",
|
|
13
|
+
"aac",
|
|
14
|
+
"m4a",
|
|
15
|
+
"wma",
|
|
16
|
+
"aiff",
|
|
17
|
+
"opus",
|
|
18
|
+
"amr",
|
|
19
|
+
"ac3",
|
|
20
|
+
"dts",
|
|
21
|
+
"mka",
|
|
22
|
+
"mid",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const VIDEO = [
|
|
26
|
+
"mp4",
|
|
27
|
+
"m4v",
|
|
28
|
+
"mov",
|
|
29
|
+
"webm",
|
|
30
|
+
"wmv",
|
|
31
|
+
"mkv",
|
|
32
|
+
"avi",
|
|
33
|
+
"mpeg",
|
|
34
|
+
"3gp",
|
|
35
|
+
"3g2",
|
|
36
|
+
"flv",
|
|
37
|
+
"ts",
|
|
38
|
+
"vob",
|
|
39
|
+
"ogv",
|
|
40
|
+
"asf",
|
|
41
|
+
"gif",
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const IMAGE = ["png", "jpeg", "webp", "bmp", "tiff", "gif", "avif", "jp2", "apng"];
|
|
11
45
|
|
|
12
46
|
function pairRules(from: string[], to: string[], cost: number): HandlerRule[] {
|
|
13
47
|
const rules: HandlerRule[] = [];
|
|
@@ -5,7 +5,31 @@ import { runCommand } from "../exec.ts";
|
|
|
5
5
|
import { CliError, ExitCode } from "../../core/errors.ts";
|
|
6
6
|
import { toFileArtifact } from "../../artifacts/file.ts";
|
|
7
7
|
|
|
8
|
-
const IMAGE_DOC = [
|
|
8
|
+
const IMAGE_DOC = [
|
|
9
|
+
"png",
|
|
10
|
+
"jpeg",
|
|
11
|
+
"webp",
|
|
12
|
+
"bmp",
|
|
13
|
+
"tiff",
|
|
14
|
+
"gif",
|
|
15
|
+
"svg",
|
|
16
|
+
"avif",
|
|
17
|
+
"heic",
|
|
18
|
+
"ico",
|
|
19
|
+
"jp2",
|
|
20
|
+
"psd",
|
|
21
|
+
"tga",
|
|
22
|
+
"dds",
|
|
23
|
+
"hdr",
|
|
24
|
+
"exr",
|
|
25
|
+
"pnm",
|
|
26
|
+
"pbm",
|
|
27
|
+
"pgm",
|
|
28
|
+
"ppm",
|
|
29
|
+
"pdf",
|
|
30
|
+
"eps",
|
|
31
|
+
"ps",
|
|
32
|
+
];
|
|
9
33
|
|
|
10
34
|
function imageRules(): HandlerRule[] {
|
|
11
35
|
const rules: HandlerRule[] = [];
|
|
@@ -8,15 +8,32 @@ import { toFileArtifact } from "../../artifacts/file.ts";
|
|
|
8
8
|
const DOC_TEXT_DATA = [
|
|
9
9
|
"txt",
|
|
10
10
|
"md",
|
|
11
|
+
"rst",
|
|
12
|
+
"adoc",
|
|
13
|
+
"bbcode",
|
|
14
|
+
"org",
|
|
15
|
+
"tex",
|
|
16
|
+
"texinfo",
|
|
11
17
|
"html",
|
|
18
|
+
"xhtml",
|
|
12
19
|
"json",
|
|
13
20
|
"xml",
|
|
14
21
|
"yaml",
|
|
22
|
+
"toml",
|
|
15
23
|
"csv",
|
|
24
|
+
"tsv",
|
|
16
25
|
"pdf",
|
|
17
26
|
"docx",
|
|
27
|
+
"odt",
|
|
28
|
+
"rtf",
|
|
29
|
+
"epub",
|
|
30
|
+
"fb2",
|
|
18
31
|
"pptx",
|
|
19
32
|
"xlsx",
|
|
33
|
+
"ods",
|
|
34
|
+
"odp",
|
|
35
|
+
"docbook",
|
|
36
|
+
"jats",
|
|
20
37
|
];
|
|
21
38
|
|
|
22
39
|
function pandocRules(): HandlerRule[] {
|
|
@@ -5,7 +5,9 @@ import { runCommand } from "../exec.ts";
|
|
|
5
5
|
import { CliError, ExitCode } from "../../core/errors.ts";
|
|
6
6
|
import { toFileArtifact } from "../../artifacts/file.ts";
|
|
7
7
|
|
|
8
|
-
const ARCHIVES = new Set(["zip", "tar", "7z"]);
|
|
8
|
+
const ARCHIVES = new Set(["zip", "tar", "7z", "gz", "bz2", "xz", "rar", "cab", "iso"]);
|
|
9
|
+
const WRITE_ARCHIVES = ["zip", "tar", "7z", "gz", "bz2", "xz", "rar", "cab", "iso"];
|
|
10
|
+
const READ_ARCHIVES = ["zip", "tar", "7z", "gz", "bz2", "xz", "rar", "cab", "iso"];
|
|
9
11
|
|
|
10
12
|
async function findFirstFile(root: string): Promise<string | undefined> {
|
|
11
13
|
const entries = await readdir(root, { withFileTypes: true });
|
|
@@ -25,14 +27,14 @@ async function findFirstFile(root: string): Promise<string | undefined> {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
function sevenZipRules(): HandlerRule[] {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{ from: "*", to:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{ from:
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const rules: HandlerRule[] = [];
|
|
31
|
+
for (const archive of WRITE_ARCHIVES) {
|
|
32
|
+
rules.push({ from: "*", to: archive, cost: 95, lossless: false });
|
|
33
|
+
}
|
|
34
|
+
for (const archive of READ_ARCHIVES) {
|
|
35
|
+
rules.push({ from: archive, to: "*", cost: 145, lossless: false });
|
|
36
|
+
}
|
|
37
|
+
return rules;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export class SevenZipHandler implements ConversionHandler {
|
|
@@ -3,6 +3,7 @@ import { FormatRegistry } from "../../src/formats/registry.ts";
|
|
|
3
3
|
import { ConversionGraph } from "../../src/planner/graph.ts";
|
|
4
4
|
import { findRoutes } from "../../src/planner/search.ts";
|
|
5
5
|
import type { ConversionHandler, ConvertRequest, HandlerContext, HandlerResult } from "../../src/handlers/base.ts";
|
|
6
|
+
import type { FormatDefinition } from "../../src/core/types.ts";
|
|
6
7
|
|
|
7
8
|
class MockHandler implements ConversionHandler {
|
|
8
9
|
readonly name: string;
|
|
@@ -25,7 +26,37 @@ class MockHandler implements ConversionHandler {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
test("planner prefers meaningful route over wildcard", () => {
|
|
28
|
-
const
|
|
29
|
+
const smallSet: FormatDefinition[] = [
|
|
30
|
+
{
|
|
31
|
+
id: "png",
|
|
32
|
+
name: "Portable Network Graphics",
|
|
33
|
+
extension: "png",
|
|
34
|
+
extensions: ["png"],
|
|
35
|
+
mime: ["image/png"],
|
|
36
|
+
category: ["image"],
|
|
37
|
+
aliases: [],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "wav",
|
|
41
|
+
name: "Waveform Audio",
|
|
42
|
+
extension: "wav",
|
|
43
|
+
extensions: ["wav"],
|
|
44
|
+
mime: ["audio/wav"],
|
|
45
|
+
category: ["audio"],
|
|
46
|
+
aliases: [],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "mp3",
|
|
50
|
+
name: "MP3 Audio",
|
|
51
|
+
extension: "mp3",
|
|
52
|
+
extensions: ["mp3"],
|
|
53
|
+
mime: ["audio/mpeg"],
|
|
54
|
+
category: ["audio"],
|
|
55
|
+
aliases: [],
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const registry = new FormatRegistry(smallSet);
|
|
29
60
|
|
|
30
61
|
const handlers: ConversionHandler[] = [
|
|
31
62
|
new MockHandler("image-audio-bridge", [{ from: "png", to: "wav", cost: 10 }]),
|
|
@@ -18,9 +18,10 @@ type option struct {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
type payload struct {
|
|
21
|
-
Prompt
|
|
22
|
-
Query
|
|
23
|
-
|
|
21
|
+
Prompt string `json:"prompt"`
|
|
22
|
+
Query string `json:"query"`
|
|
23
|
+
Preferred string `json:"preferred"`
|
|
24
|
+
Options []option `json:"options"`
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
type scoredOption struct {
|
|
@@ -31,6 +32,7 @@ type scoredOption struct {
|
|
|
31
32
|
type model struct {
|
|
32
33
|
prompt string
|
|
33
34
|
query string
|
|
35
|
+
preferred string
|
|
34
36
|
all []option
|
|
35
37
|
filtered []option
|
|
36
38
|
cursor int
|
|
@@ -93,6 +95,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
93
95
|
func (m model) View() string {
|
|
94
96
|
var builder strings.Builder
|
|
95
97
|
builder.WriteString(fmt.Sprintf("%s > %s\n", m.prompt, m.query))
|
|
98
|
+
if m.query == "" && m.preferred != "" {
|
|
99
|
+
builder.WriteString(fmt.Sprintf(" hint: original extension '.%s' is ranked first\n", m.preferred))
|
|
100
|
+
}
|
|
96
101
|
|
|
97
102
|
if len(m.filtered) == 0 {
|
|
98
103
|
builder.WriteString(" no matches\n")
|
|
@@ -139,7 +144,7 @@ func (m *model) refilter() {
|
|
|
139
144
|
scored := make([]scoredOption, 0, len(m.all))
|
|
140
145
|
|
|
141
146
|
for _, item := range m.all {
|
|
142
|
-
score := fuzzyScore(query, item)
|
|
147
|
+
score := fuzzyScore(query, item, m.preferred)
|
|
143
148
|
if score < 0 {
|
|
144
149
|
continue
|
|
145
150
|
}
|
|
@@ -166,9 +171,19 @@ func (m *model) refilter() {
|
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
173
|
|
|
169
|
-
func fuzzyScore(query string, item option) int {
|
|
174
|
+
func fuzzyScore(query string, item option, preferred string) int {
|
|
170
175
|
if query == "" {
|
|
171
|
-
|
|
176
|
+
score := 1
|
|
177
|
+
if preferred != "" {
|
|
178
|
+
normalizedPreferred := strings.ToLower(preferred)
|
|
179
|
+
if strings.EqualFold(item.Extension, normalizedPreferred) {
|
|
180
|
+
score += 25
|
|
181
|
+
}
|
|
182
|
+
if strings.EqualFold(item.ID, normalizedPreferred) {
|
|
183
|
+
score += 20
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return score
|
|
172
187
|
}
|
|
173
188
|
|
|
174
189
|
candidate := strings.ToLower(item.ID + " " + item.Extension + " " + item.Name)
|
|
@@ -207,6 +222,16 @@ func fuzzyScore(query string, item option) int {
|
|
|
207
222
|
if strings.HasPrefix(strings.ToLower(item.ID), query) {
|
|
208
223
|
score += 15
|
|
209
224
|
}
|
|
225
|
+
if preferred != "" {
|
|
226
|
+
normalizedPreferred := strings.ToLower(preferred)
|
|
227
|
+
if strings.EqualFold(item.Extension, normalizedPreferred) {
|
|
228
|
+
score += 8
|
|
229
|
+
}
|
|
230
|
+
if strings.EqualFold(item.ID, normalizedPreferred) {
|
|
231
|
+
score += 6
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
210
235
|
return score
|
|
211
236
|
}
|
|
212
237
|
|
|
@@ -244,9 +269,10 @@ func main() {
|
|
|
244
269
|
}
|
|
245
270
|
|
|
246
271
|
picker := model{
|
|
247
|
-
prompt:
|
|
248
|
-
query:
|
|
249
|
-
|
|
272
|
+
prompt: data.Prompt,
|
|
273
|
+
query: data.Query,
|
|
274
|
+
preferred: strings.TrimSpace(data.Preferred),
|
|
275
|
+
all: data.Options,
|
|
250
276
|
}
|
|
251
277
|
picker.refilter()
|
|
252
278
|
|