@capyclaw/ppt-workbench 0.0.0-stage → 2.4.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/LICENSE +21 -0
- package/README.md +126 -3
- package/THIRD_PARTY_NOTICES.md +21 -0
- package/contract/ppt-contract.json +1529 -0
- package/cordis.patch.yml +25 -0
- package/core/audit.js +500 -0
- package/core/chart.js +199 -0
- package/core/color.js +80 -0
- package/core/deck-layout.js +195 -0
- package/core/formula.js +80 -0
- package/core/hfmath/hershey.js +1763 -0
- package/core/hfmath/index.js +1176 -0
- package/core/hfmath/stretch.js +41 -0
- package/core/hfmath/symbols.js +408 -0
- package/core/ops/browser.js +28 -0
- package/core/ops/chart.js +64 -0
- package/core/ops/deck.js +21 -0
- package/core/ops/dispatcher.js +2 -0
- package/core/ops/element.js +55 -0
- package/core/ops/history.js +11 -0
- package/core/ops/import.js +95 -0
- package/core/ops/index.js +39 -0
- package/core/ops/playback.js +9 -0
- package/core/ops/recolor.js +33 -0
- package/core/ops/slide.js +66 -0
- package/core/ops/table.js +85 -0
- package/core/ops/text.js +35 -0
- package/core/ops/view.js +13 -0
- package/core/ops.js +12 -0
- package/core/quick.js +52 -0
- package/core/shape-library.js +122 -0
- package/core/table.js +178 -0
- package/core/text.js +200 -0
- package/editor/app.js +5366 -0
- package/editor/heartbeat-worker.js +116 -0
- package/editor/index.html +89 -0
- package/editor/ppt-full-app.js +376 -0
- package/lib/host.mjs +98 -0
- package/package.json +53 -6
- package/server/audit.mjs +2 -0
- package/server/bridge-client.mjs +174 -0
- package/server/constants.mjs +20 -0
- package/server/contract-snapshots.mjs +62 -0
- package/server/contract.mjs +24 -0
- package/server/deck-layout.mjs +2 -0
- package/server/http-utils.mjs +2 -0
- package/server/infra/http.mjs +113 -0
- package/server/infra/runtime/context.mjs +128 -0
- package/server/infra/store/blob-store.mjs +109 -0
- package/server/infra/tuning.mjs +82 -0
- package/server/infra/util/fs-lock.mjs +132 -0
- package/server/infra/workspace/manager.mjs +657 -0
- package/server/mcp/dispatch.mjs +2 -0
- package/server/mcp/handler.mjs +2 -0
- package/server/mcp/instructions.mjs +40 -0
- package/server/mcp-http.mjs +3 -0
- package/server/ppt-shim.mjs +156 -0
- package/server/relay.mjs +245 -0
- package/server/routes/assets.mjs +2 -0
- package/server/routes/bridge.mjs +47 -0
- package/server/routes/editor.mjs +9 -0
- package/server/routes/import.mjs +258 -0
- package/server/routes/mcp.mjs +17 -0
- package/server/runtime/recovery.mjs +9 -0
- package/server/runtime/watch.mjs +17 -0
- package/server/shared/SHARED_MANIFEST.json +47 -0
- package/server/shared/asset-service.mjs +217 -0
- package/server/shared/editor-host.mjs +125 -0
- package/server/shared/kit/editor/lease.mjs +139 -0
- package/server/shared/kit/service/api.mjs +45 -0
- package/server/shared/kit/service/http.mjs +113 -0
- package/server/shared/kit/service/mcp-http.mjs +142 -0
- package/server/shared/kit/service/single-instance.mjs +72 -0
- package/server/shared/kit/tools/validate.mjs +115 -0
- package/server/shared/kit/tuning.mjs +82 -0
- package/server/shared/kit/util/fs-lock.mjs +132 -0
- package/server/shared/service-host.mjs +511 -0
- package/server/shared/state-service.mjs +249 -0
- package/server/shared/tool-host.mjs +341 -0
- package/server/shared/tuning.mjs +63 -0
- package/server/single-instance.mjs +2 -0
- package/server/store/backends/file-backend.mjs +13 -0
- package/server/store/checkpoints.mjs +28 -0
- package/server/store/doc.mjs +52 -0
- package/server/store/index.mjs +34 -0
- package/server/store/journal.mjs +9 -0
- package/server/store/lease.mjs +2 -0
- package/server/store/sanitize.mjs +32 -0
- package/server/store.mjs +2 -0
- package/server/tools/capabilities/apply.mjs +33 -0
- package/server/tools/capabilities/audit.mjs +24 -0
- package/server/tools/capabilities/chart.mjs +83 -0
- package/server/tools/capabilities/compose.mjs +97 -0
- package/server/tools/capabilities/contract.mjs +34 -0
- package/server/tools/capabilities/deck.mjs +27 -0
- package/server/tools/capabilities/element.mjs +67 -0
- package/server/tools/capabilities/export.mjs +95 -0
- package/server/tools/capabilities/formula.mjs +72 -0
- package/server/tools/capabilities/history.mjs +29 -0
- package/server/tools/capabilities/image.mjs +152 -0
- package/server/tools/capabilities/imagesearch.mjs +152 -0
- package/server/tools/capabilities/import.mjs +180 -0
- package/server/tools/capabilities/index.mjs +58 -0
- package/server/tools/capabilities/line.mjs +58 -0
- package/server/tools/capabilities/notes.mjs +33 -0
- package/server/tools/capabilities/present.mjs +34 -0
- package/server/tools/capabilities/recolor.mjs +60 -0
- package/server/tools/capabilities/screenshot.mjs +86 -0
- package/server/tools/capabilities/shape.mjs +64 -0
- package/server/tools/capabilities/slide.mjs +81 -0
- package/server/tools/capabilities/style.mjs +48 -0
- package/server/tools/capabilities/table.mjs +127 -0
- package/server/tools/capabilities/task.mjs +52 -0
- package/server/tools/capabilities/text.mjs +82 -0
- package/server/tools/domains/color.mjs +4 -0
- package/server/tools/domains/image.mjs +49 -0
- package/server/tools/domains/index.mjs +7 -0
- package/server/tools/domains/pptx-export.mjs +566 -0
- package/server/tools/domains/recolor.mjs +25 -0
- package/server/tools/domains/remote-image.mjs +291 -0
- package/server/tools/domains/slide.mjs +21 -0
- package/server/tools/domains/text-style.mjs +11 -0
- package/server/tools/domains/tooling.mjs +13 -0
- package/server/tools/index.mjs +14 -0
- package/server/tools/kernel/define.mjs +5 -0
- package/server/tools/kernel/ports.mjs +42 -0
- package/server/tools/kernel/registry.mjs +17 -0
- package/server/tools.mjs +18 -0
- package/server/tuning.mjs +86 -0
- package/server/validate.mjs +2 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** 文本能力:按页/元素改文本,文字槽位填充。 */
|
|
2
|
+
import { clamp, normalizeSlides, okText } from '../domains/tooling.mjs'
|
|
3
|
+
import { normalizeTextStyle } from '../domains/text-style.mjs'
|
|
4
|
+
import { defineCapability, defineTool } from '../kernel/define.mjs'
|
|
5
|
+
|
|
6
|
+
export const textCapability = defineCapability({
|
|
7
|
+
id: 'text',
|
|
8
|
+
title: '文字与槽位',
|
|
9
|
+
tags: ['write', 'content'],
|
|
10
|
+
requires: ['deck'],
|
|
11
|
+
features: ['deck.write'],
|
|
12
|
+
tools: [
|
|
13
|
+
defineTool({
|
|
14
|
+
name: 'ppt_text',
|
|
15
|
+
description: '改文字:某页或某几页(缺省全部页)的首个文本,或指定 element_id 的文本;可同时改字号/颜色/加粗/对齐。首个文本优先取 text 元素,纯图形文字页回退到带文字的 shape。',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
text: { type: 'string', maxLength: 2000 },
|
|
20
|
+
slide: { type: 'integer', description: '0 起页号' },
|
|
21
|
+
slides: { type: 'array', maxItems: 100, items: { type: 'integer' }, description: '0 起页号数组(缺省=全部)' },
|
|
22
|
+
element_id: { type: 'string', description: '元素 id(缺省=首个文本)' },
|
|
23
|
+
font_size: { type: 'integer' },
|
|
24
|
+
color: { type: 'string', description: 'CSS 颜色或中文色名' },
|
|
25
|
+
bold: { type: 'boolean' },
|
|
26
|
+
align: { type: 'string', enum: ['left', 'center', 'right', 'justify'] },
|
|
27
|
+
},
|
|
28
|
+
required: ['text'],
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
},
|
|
31
|
+
kind: 'write',
|
|
32
|
+
since: '1.0.0',
|
|
33
|
+
handler: async ({ text, slide, slides, element_id, ...style }, ctx) => {
|
|
34
|
+
const base = { text: String(text ?? '') }
|
|
35
|
+
if (element_id) base.elementId = String(element_id)
|
|
36
|
+
Object.assign(base, normalizeTextStyle(style))
|
|
37
|
+
const targets = normalizeSlides(slides)
|
|
38
|
+
|| (slide !== undefined && slide !== null ? [clamp(Number(slide) | 0, 0, 999)] : null)
|
|
39
|
+
if (targets) {
|
|
40
|
+
const r = await ctx.deck.write(targets.map(i => Object.assign({ op: 'set-text', id: i }, base)))
|
|
41
|
+
return okText(r, `已改 ${targets.length} 页文本`)
|
|
42
|
+
}
|
|
43
|
+
const doc = await ctx.deck.read()
|
|
44
|
+
const n = doc.deck && Array.isArray(doc.deck.slides) ? doc.deck.slides.length : 0
|
|
45
|
+
if (!n) throw new Error('桥上没有 deck')
|
|
46
|
+
const r = await ctx.deck.write(Array.from({ length: n }, (_, i) => Object.assign({ op: 'set-text', id: i }, base)))
|
|
47
|
+
return okText(r, `已改全部 ${n} 页文本`)
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
defineTool({
|
|
51
|
+
name: 'ppt_fill',
|
|
52
|
+
description: '填充文字槽位:把某页的第 slot 个文字载体(0 起,含带文字的 shape)改成 text,可带字号/颜色/加粗/对齐。保留原版式。',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
slide: { type: 'integer', description: '0 起页号' },
|
|
57
|
+
slot: { type: 'integer', description: '该页第几个文字载体(0 起,含图形内文字)' },
|
|
58
|
+
text: { type: 'string' },
|
|
59
|
+
font_size: { type: 'integer' },
|
|
60
|
+
color: { type: 'string' },
|
|
61
|
+
bold: { type: 'boolean' },
|
|
62
|
+
align: { type: 'string' },
|
|
63
|
+
},
|
|
64
|
+
required: ['slide', 'slot', 'text'],
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
},
|
|
67
|
+
kind: 'write',
|
|
68
|
+
since: '1.0.0',
|
|
69
|
+
handler: async ({ slide, slot, text, ...style }, ctx) => {
|
|
70
|
+
const cmd = {
|
|
71
|
+
op: 'fill-slot',
|
|
72
|
+
slide: clamp(Number(slide) | 0, 0, 999),
|
|
73
|
+
slot: clamp(Number(slot) | 0, 0, 99),
|
|
74
|
+
text: String(text ?? ''),
|
|
75
|
+
...normalizeTextStyle(style),
|
|
76
|
+
}
|
|
77
|
+
const r = await ctx.deck.write([cmd])
|
|
78
|
+
return okText(r, `已填第 ${slide} 页槽位 ${slot}`)
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
82
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** 图片域:字节嗅探 / 尺寸解析 / 聊天附件定位(实际落盘由 assets 端口负责)。 */
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
export function imageMime(buf) {
|
|
6
|
+
if (buf[0] === 0x89 && buf[1] === 0x50) return 'image/png'
|
|
7
|
+
if (buf[0] === 0xff && buf[1] === 0xd8) return 'image/jpeg'
|
|
8
|
+
if (buf.slice(0, 3).toString('ascii') === 'GIF') return 'image/gif'
|
|
9
|
+
if (buf.slice(8, 12).toString('ascii') === 'WEBP') return 'image/webp'
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function imageSize(buf) {
|
|
14
|
+
if (buf[0] === 0x89 && buf[1] === 0x50 && buf.length > 24) {
|
|
15
|
+
return [buf.readUInt32BE(16), buf.readUInt32BE(20)]
|
|
16
|
+
}
|
|
17
|
+
if (buf.slice(0, 3).toString('ascii') === 'GIF' && buf.length > 10) {
|
|
18
|
+
return [buf.readUInt16LE(6), buf.readUInt16LE(8)]
|
|
19
|
+
}
|
|
20
|
+
if (buf[0] === 0xff && buf[1] === 0xd8) {
|
|
21
|
+
let i = 2
|
|
22
|
+
while (i + 8 < buf.length) {
|
|
23
|
+
if (buf[i] !== 0xff) { i++; continue }
|
|
24
|
+
const m = buf[i + 1]
|
|
25
|
+
i += 2
|
|
26
|
+
if (m === 0xd8 || m === 0xd9 || m === 0x01) continue
|
|
27
|
+
const len = buf.readUInt16BE(i)
|
|
28
|
+
if ([0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf].includes(m)) {
|
|
29
|
+
return [buf.readUInt16BE(i + 5), buf.readUInt16BE(i + 3)]
|
|
30
|
+
}
|
|
31
|
+
i += len
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function resolveAttachmentFile(id) {
|
|
38
|
+
const hex = String(id || '').replace(/^sha256:/i, '')
|
|
39
|
+
if (!/^[0-9a-f]{64}$/i.test(hex)) throw new Error('attachment_id 必须是 sha256:<64位hex>')
|
|
40
|
+
const roots = []
|
|
41
|
+
if (process.env.DSH_HOME) roots.push(path.join(process.env.DSH_HOME, 'attachments', 'v1', 'objects'))
|
|
42
|
+
if (process.env.DSH_ATTACHMENTS_DIR) roots.push(process.env.DSH_ATTACHMENTS_DIR)
|
|
43
|
+
if (process.env.USERPROFILE) roots.push(path.join(process.env.USERPROFILE, '.dsh', 'attachments', 'v1', 'objects'))
|
|
44
|
+
for (const root of roots) {
|
|
45
|
+
const p = path.join(root, hex.slice(0, 2), hex)
|
|
46
|
+
if (fs.existsSync(p)) return p
|
|
47
|
+
}
|
|
48
|
+
throw new Error('找不到聊天附件:' + id + '(请在聊天里重新粘贴图片)')
|
|
49
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** 工具域辅助桶:只给 tools.mjs 兼容导出用,能力模块按需直接 import 具体文件。 */
|
|
2
|
+
export { COLORS, resolveColor, parseColor, contrastColor, relativeLuminance } from './color.mjs'
|
|
3
|
+
export { expandRecolorOps, resolveForeground } from './recolor.mjs'
|
|
4
|
+
export { simpleSlide } from './slide.mjs'
|
|
5
|
+
export { imageMime, imageSize, resolveAttachmentFile } from './image.mjs'
|
|
6
|
+
export { clamp, sleep, okText, normalizeSlides } from './tooling.mjs'
|
|
7
|
+
export { normalizeTextStyle } from './text-style.mjs'
|