vscode-colaview 0.3.2 → 0.4.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/.vscode/settings.json +1 -1
- package/CHANGELOG.md +30 -0
- package/README.md +311 -279
- package/README_CN.md +311 -279
- package/RELEASE_NOTES.md +56 -0
- package/esbuild.js +2 -0
- package/package.json +58 -19
- package/package.nls.json +14 -0
- package/package.nls.zh-cn.json +14 -0
- package/src/commands/commands.ts +48 -0
- package/src/docx/docx-builder.ts +241 -0
- package/src/export/docx-exporter.ts +961 -961
- package/src/export/html-exporter.ts +8 -2
- package/src/export/pdf-exporter.ts +65 -0
- package/src/export/pptx-exporter.ts +63 -0
- package/src/export/render-export-images.ts +386 -372
- package/src/export/theme-style.ts +195 -155
- package/src/pptx/pptx-builder.ts +249 -0
- package/src/pptx/zip.ts +158 -0
- package/src/present/presenter.ts +64 -0
- package/src/preview/preview-manager.ts +783 -541
- package/src/preview/webview/app.ts +588 -366
- package/src/preview/webview/index.html +167 -134
- package/src/slides/deck.ts +397 -0
- package/src/slides/markdown.ts +393 -0
- package/src/slides/render.ts +484 -0
- package/src/slides/slides.css +1082 -0
- package/src/themes/built-in/bear.css +89 -38
- package/src/themes/built-in/dark.css +87 -20
- package/src/themes/built-in/dracula.css +93 -38
- package/src/themes/built-in/elegant.css +109 -52
- package/src/themes/built-in/gruvbox.css +97 -42
- package/src/themes/built-in/light.css +80 -20
- package/src/themes/built-in/midnight.css +93 -31
- package/src/themes/built-in/nord.css +93 -38
- package/src/themes/built-in/notion.css +98 -48
- package/src/themes/built-in/sepia.css +99 -47
- package/src/themes/built-in/solarized-dark.css +94 -35
- package/src/themes/built-in/writer.css +99 -44
- package/src/themes/theme-manager.ts +207 -180
- package/src/types/colamd-renderer.d.ts +47 -47
- package/patches/@bytechain.cn+colamd+2.7.11.patch +0 -22
package/src/pptx/zip.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// 极简 ZIP 打包器 — 只做 STORE(不压缩),零依赖、同步、可复现。
|
|
2
|
+
// 供 .pptx 这类 OOXML 包使用:包内都是已经压过的小体积 XML。
|
|
3
|
+
|
|
4
|
+
/** 一个待写入 ZIP 的文件条目(只允许文件,不允许目录条目)。 */
|
|
5
|
+
export interface ZipEntry {
|
|
6
|
+
path: string;
|
|
7
|
+
data: Uint8Array;
|
|
8
|
+
/** 可选修改时间;缺省固定,保证同一输入产出同一份字节。 */
|
|
9
|
+
date?: Date;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const SIG_LOCAL = 0x04034b50;
|
|
13
|
+
const SIG_CENTRAL = 0x02014b50;
|
|
14
|
+
const SIG_EOCD = 0x06054b50;
|
|
15
|
+
const VERSION_NEEDED = 20;
|
|
16
|
+
/** 通用标志位 bit 11:文件名为 UTF-8。 */
|
|
17
|
+
const FLAG_UTF8 = 0x0800;
|
|
18
|
+
const DOS_DATE_1980 = 0x0021;
|
|
19
|
+
const DOS_TIME_MIDNIGHT = 0x0000;
|
|
20
|
+
const MIN_1980 = Date.UTC(1980, 0, 1);
|
|
21
|
+
const MAX_YEAR = 2107;
|
|
22
|
+
|
|
23
|
+
const CRC_TABLE = (() => {
|
|
24
|
+
const table = new Uint32Array(256);
|
|
25
|
+
for (let i = 0; i < 256; i++) {
|
|
26
|
+
let c = i;
|
|
27
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
28
|
+
c = (c & 1) === 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
29
|
+
}
|
|
30
|
+
table[i] = c >>> 0;
|
|
31
|
+
}
|
|
32
|
+
return table;
|
|
33
|
+
})();
|
|
34
|
+
|
|
35
|
+
function crc32(data: Uint8Array): number {
|
|
36
|
+
let c = 0xffffffff;
|
|
37
|
+
for (let i = 0; i < data.length; i++) {
|
|
38
|
+
c = CRC_TABLE[(c ^ data[i]) & 0xff] ^ (c >>> 8);
|
|
39
|
+
}
|
|
40
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 把条目路径规范成 ZIP 约定形式:正斜杠、无前导 `/` 或 `./`。 */
|
|
44
|
+
function cleanPath(raw: string): string {
|
|
45
|
+
let path = raw.replace(/\\/g, '/');
|
|
46
|
+
path = path.replace(/^\/+/, '').replace(/^(?:\.\/)+/, '');
|
|
47
|
+
if (path === '' || path.endsWith('/')) {
|
|
48
|
+
throw new Error(`zipStore: invalid file path "${raw}" (directories are not supported)`);
|
|
49
|
+
}
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toDos(date: Date | undefined): { time: number; date: number } {
|
|
54
|
+
if (date === undefined || Number.isNaN(date.getTime()) || date.getTime() < MIN_1980) {
|
|
55
|
+
return { time: DOS_TIME_MIDNIGHT, date: DOS_DATE_1980 };
|
|
56
|
+
}
|
|
57
|
+
const year = Math.min(date.getUTCFullYear(), MAX_YEAR);
|
|
58
|
+
const month = date.getUTCMonth() + 1;
|
|
59
|
+
const day = date.getUTCDate();
|
|
60
|
+
const hours = date.getUTCHours();
|
|
61
|
+
const minutes = date.getUTCMinutes();
|
|
62
|
+
const seconds = Math.floor(date.getUTCSeconds() / 2); // DOS 时间精度 2 秒
|
|
63
|
+
return {
|
|
64
|
+
time: (hours << 11) | (minutes << 5) | seconds,
|
|
65
|
+
date: ((year - 1980) << 9) | (month << 5) | day,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 把若干文件打成 ZIP(STORE,不压缩)。 */
|
|
70
|
+
export function zipStore(entries: readonly ZipEntry[]): Uint8Array {
|
|
71
|
+
if (entries.length > 0xffff) {
|
|
72
|
+
throw new Error(`zipStore: too many entries (${entries.length} > 65535)`);
|
|
73
|
+
}
|
|
74
|
+
const encoder = new TextEncoder();
|
|
75
|
+
const prepared = entries.map((entry) => {
|
|
76
|
+
const name = encoder.encode(cleanPath(entry.path));
|
|
77
|
+
return { name, data: entry.data, crc: crc32(entry.data), dt: toDos(entry.date), offset: 0 };
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
let total = 22; // EOCD
|
|
81
|
+
for (const item of prepared) {
|
|
82
|
+
total += 30 + item.name.length + item.data.length;
|
|
83
|
+
total += 46 + item.name.length;
|
|
84
|
+
}
|
|
85
|
+
if (total > 0xffffffff) {
|
|
86
|
+
throw new Error('zipStore: archive exceeds 4 GiB (ZIP64 is not supported)');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const out = new Uint8Array(total);
|
|
90
|
+
const view = new DataView(out.buffer);
|
|
91
|
+
let at = 0;
|
|
92
|
+
const u16 = (value: number): void => {
|
|
93
|
+
view.setUint16(at, value, true);
|
|
94
|
+
at += 2;
|
|
95
|
+
};
|
|
96
|
+
const u32 = (value: number): void => {
|
|
97
|
+
view.setUint32(at, value >>> 0, true);
|
|
98
|
+
at += 4;
|
|
99
|
+
};
|
|
100
|
+
const bytes = (chunk: Uint8Array): void => {
|
|
101
|
+
out.set(chunk, at);
|
|
102
|
+
at += chunk.length;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// 本地文件头 + 原始数据。
|
|
106
|
+
for (const item of prepared) {
|
|
107
|
+
item.offset = at;
|
|
108
|
+
u32(SIG_LOCAL);
|
|
109
|
+
u16(VERSION_NEEDED);
|
|
110
|
+
u16(FLAG_UTF8);
|
|
111
|
+
u16(0); // 方法 0 = STORE
|
|
112
|
+
u16(item.dt.time);
|
|
113
|
+
u16(item.dt.date);
|
|
114
|
+
u32(item.crc);
|
|
115
|
+
u32(item.data.length);
|
|
116
|
+
u32(item.data.length);
|
|
117
|
+
u16(item.name.length);
|
|
118
|
+
u16(0);
|
|
119
|
+
bytes(item.name);
|
|
120
|
+
bytes(item.data);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 中央目录。
|
|
124
|
+
const cdStart = at;
|
|
125
|
+
for (const item of prepared) {
|
|
126
|
+
u32(SIG_CENTRAL);
|
|
127
|
+
u16(VERSION_NEEDED);
|
|
128
|
+
u16(VERSION_NEEDED);
|
|
129
|
+
u16(FLAG_UTF8);
|
|
130
|
+
u16(0);
|
|
131
|
+
u16(item.dt.time);
|
|
132
|
+
u16(item.dt.date);
|
|
133
|
+
u32(item.crc);
|
|
134
|
+
u32(item.data.length);
|
|
135
|
+
u32(item.data.length);
|
|
136
|
+
u16(item.name.length);
|
|
137
|
+
u16(0);
|
|
138
|
+
u16(0);
|
|
139
|
+
u16(0);
|
|
140
|
+
u16(0);
|
|
141
|
+
u32(0);
|
|
142
|
+
u32(item.offset);
|
|
143
|
+
bytes(item.name);
|
|
144
|
+
}
|
|
145
|
+
const cdSize = at - cdStart;
|
|
146
|
+
|
|
147
|
+
// 中央目录结束记录。
|
|
148
|
+
u32(SIG_EOCD);
|
|
149
|
+
u16(0);
|
|
150
|
+
u16(0);
|
|
151
|
+
u16(prepared.length);
|
|
152
|
+
u16(prepared.length);
|
|
153
|
+
u32(cdSize);
|
|
154
|
+
u32(cdStart);
|
|
155
|
+
u16(0);
|
|
156
|
+
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// 全屏演示 — 把一份自包含 HTML 落到临时目录,交给系统默认浏览器打开。
|
|
2
|
+
// VS Code 的 WebView 面板拿不到真正的全屏,所以放映走浏览器(F11 / requestFullscreen
|
|
3
|
+
// 都可用,←/→ 翻页、F 切全屏由文档内嵌的放映脚本处理)。
|
|
4
|
+
import * as vscode from 'vscode';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import * as os from 'os';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
|
|
9
|
+
const PRESENT_DIR = path.join(os.tmpdir(), 'colaview-present');
|
|
10
|
+
const MAX_KEPT_FILES = 8;
|
|
11
|
+
|
|
12
|
+
/** 文件名去噪:保留中英文、数字、空格与短横线,其余替换成短横线。 */
|
|
13
|
+
function safeFilename(title: string, fallback = 'present'): string {
|
|
14
|
+
const cleaned = title
|
|
15
|
+
.trim()
|
|
16
|
+
.replace(/[\\/:*?"<>|]+/g, '-')
|
|
17
|
+
.replace(/\s+/g, '-')
|
|
18
|
+
.replace(/-{2,}/g, '-')
|
|
19
|
+
.replace(/^-|-$/g, '');
|
|
20
|
+
return cleaned === '' ? fallback : cleaned.slice(0, 60);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 只保留最近若干份放映文件,避免临时目录一直堆积。 */
|
|
24
|
+
function prunePresentDir(keep: string): void {
|
|
25
|
+
try {
|
|
26
|
+
const files = fs
|
|
27
|
+
.readdirSync(PRESENT_DIR, { withFileTypes: true })
|
|
28
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.html'))
|
|
29
|
+
.map((entry) => ({ name: entry.name, at: fs.statSync(path.join(PRESENT_DIR, entry.name)).mtimeMs }))
|
|
30
|
+
.sort((a, b) => b.at - a.at);
|
|
31
|
+
for (const file of files.slice(MAX_KEPT_FILES)) {
|
|
32
|
+
if (file.name === keep) continue;
|
|
33
|
+
try { fs.unlinkSync(path.join(PRESENT_DIR, file.name)); } catch { /* ignore */ }
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
/* 清理失败不影响放映 */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 用默认浏览器打开一份全屏演示文档。
|
|
42
|
+
* @param title 文档标题(用于文件名与提示)
|
|
43
|
+
* @param html 自包含 HTML(已内联全部 CSS,并已打入放映脚本)
|
|
44
|
+
*/
|
|
45
|
+
export async function openPresentWindow(title: string, html: string): Promise<void> {
|
|
46
|
+
fs.mkdirSync(PRESENT_DIR, { recursive: true });
|
|
47
|
+
const name = `${safeFilename(title)}-${Date.now()}.html`;
|
|
48
|
+
const filePath = path.join(PRESENT_DIR, name);
|
|
49
|
+
fs.writeFileSync(filePath, html, 'utf-8');
|
|
50
|
+
prunePresentDir(name);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const opened = await vscode.env.openExternal(vscode.Uri.file(filePath));
|
|
54
|
+
if (!opened) {
|
|
55
|
+
vscode.window.showWarningMessage(
|
|
56
|
+
`ColaView: 无法自动打开浏览器,请手动打开放映文件:${filePath}`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
vscode.window.showErrorMessage(
|
|
61
|
+
`ColaView: 打开放映窗口失败:${e instanceof Error ? e.message : String(e)}`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|