Repository navigation
Releases
Releases · pengtang1024/dsh-paste-image
v0.4.1
[0.4.1] - 2026-11-23
修复
- 配置页不再拖累粘贴链路(
client.js):模块工厂不再返回inject: ['slots', 'locale'],apply()一进来就先ctx.effect(install, 'paste-image')挂上 paste/drop 监听,再尽力注册配置页——slots/locale已就绪时内联注册,否则用ctx.inject(['slots', 'locale'], cb)等服务到达后延迟注册,两者都没有就跳过。UI 服务缺失或注册抛错时,粘贴依旧可用。 - 不再吞掉原生粘贴:
handle()只有拿到真正的[data-composer-card]才 claim 并preventDefault()/stopPropagation();卡片不存在时直接返回,浏览器原生 paste/drop 路径继续执行,不再把合成 drop 派发到document.body。 - 声明宿主要求:
package.json新增engines.dsh(>=0.2.0-rc.2 || >=0.2.1-rc.2 || >=0.2.2-rc.1),插件详情页不再显示“未声明宿主要求”。 - 展示描述同步实际行为:
package.json与八种locale/*.json的简介从「只转 PNG」改为「PNG / JPEG / WebP(默认 PNG)」,并补充文件数与长边上限可配。 - 测试:补充监听立即安装、
ctx.inject延迟注册、缺少[data-composer-card]时不接管三条用例,套件共 90 个测试(90 通过、0 失败)。
v0.4.0
新增
- 配置页面:注册到插件管理器的
plugins.row.config槽位(key = dsh-paste-image#paste-image),入口是“设置 → 插件 → dsh-paste-image → 配置”。插件行显示一行状态摘要,页面提供 6 个复选框(启用、XPM / BMP-DIB / SVG / ICO-CUR 转换开关、控制台日志)、1 个输出格式下拉框(PNG / JPEG / WebP)、3 个数字输入(单次最大文件数 1–8、长边 512–8192、质量 0.1–1,选 PNG 时禁用)、保存与恢复默认。 - 运行时设置:新增
getSettings()/applySettings()/resetSettings(),默认值等同于 0.3.1 的行为;normalize()读取转换开关与输出格式/质量,canvasOf()读取长边上限,handle()读取总开关与文件数上限,日志由logConversions控制。保存后立即生效,无需重载页面;关掉某种格式后该格式原样交给原生通道,关掉总开关后监听器保留、粘贴与拖拽完全走原生路径。 - 输出格式:新增
outputFormat(png/jpeg/webp,默认png)与quality(0.1–1,默认 0.92,仅 JPEG / WebP 生效);JPEG 编码前把透明像素合成到白底,PNG 无损、WebP 保留透明;浏览器不支持所选编码器时以实际blob.type为准回退,识别不了就回到 PNG,文件名扩展名同步。 - 持久化:设置按浏览器保存在
localStorage的dsh-paste-image.settings.v1键下,不上传、不写宿主;localStorage不可用或内容损坏时回退到默认值/内存,不影响粘贴。 - 测试:新增 26 个用例(
tests/settings.test.mjs),覆盖默认值、范围钳制、持久化与损坏回退、恢复默认、行为接线、输出格式/质量与页面注册契约;测试总数从 61 增加到 87。 - 文档:新增输出格式实测(
docs/output-formats.md,英文docs/en/output-formats.md),记录真实 Chromium 下五个夹具的 PNG / JPEG / WebP 体积与编码耗时(q=0.92 与 q=0.8),结论是体积比例取决于内容、没有通用百分比——照片用 JPEG/WebP 约小 82%,UI 截图用 JPEG 反而比 PNG 大 49%、PNG 仍可能更小,透明图必须避开 JPEG;README 配置节补了 4 行速查表并链接完整实测。
v0.3.1
性能
normalize()先用file.slice()读取至多 1 KiB 头做嗅探;嗅探结果是原生格式(PNG/JPEG/WebP/GIF)且声明 MIME 与之一致时直接返回null,不再对整文件调用arrayBuffer()。20 MiB PNG 直通基准从 3.803–3.929 ms/op、每次全量读取 20,971,520 字节,降到 0.0038–0.0063 ms/op、全量读取 0 字节;只有声明类型为空需要重包、或确实要转码时才读全量。resolveColor()复用一个 1×1 canvas 与 2D context,不再为每个调色板颜色新建画布;XPM 在cpp === 1时用字符码Map代替逐像素row.slice()。512×512 XPM 基准从 4.712–4.837 ms/op 降到 3.35–3.95 ms/op(约 -24%,观测区间 -18%~-29%)。BMP→PNG 转换仍在约 3.9–4.0 ms/op,decodeBmp在运行噪声内不变。- 优化只发生在原有的同步渲染进程代码里:没有新增 worker,没有网络请求,处理时机与行为不变。
npm run bench可复现完整基准,--quick为 CI 规模的冒烟运行。
兼容性
- 缺少
AbortController时install()退回不带signal的监听,disposer 用removeEventListener精确卸载两个 handler。 - 缺少
canvas.toBlob时toPngBlob()回退到toDataURL(),再把 base64 解码成Blob。 - 缺少
DataTransfer/DragEvent时handle()在 claim 事件与preventDefault()之前返回,保留浏览器原生 paste/drop 路径,不会吞掉事件。 - 缺少
file.slice()/file.size的类File对象无法只读文件头,退回原有的全量读取路径。
测试
- 61 个测试:41 个客户端/多语言用例,加上 20 个兼容性用例——无头 DIB、1/4/8/16/24/32 位 BMP、RLE4/RLE8、BITFIELDS、OS/2 core header、TIFF/HEIC/AVIF 嗅探、MIME 别名直通、BMP 冒充 PNG、8 文件上限、非图片透传,以及上述三条降级路径。CI 矩阵扩展到 Node 20/22/24,并新增
node bench/bench.mjs --quick冒烟任务。
v0.3.0
新增
- 插件转为以中文为主:
README.md是简体中文,README.en.md是英文版,另有README.ja.md、README.es.md、README.fr.md、README.de.md、README.ru.md、README.pt.md六种译文。每份 README 顶部都有同一行八语言切换链接,并新增「多语言」说明小节。 locale/目录为 DSH 界面支持的八种语言提供展示元数据:locale/en.json、locale/zh.json、locale/ja.json、locale/es.json、locale/fr.json、locale/de.json、locale/ru.json、locale/pt.json,各自携带本地化的meta.title、meta.description,以及指向对应语言 README 的meta.detail——中文指向README.md,英文指向README.en.md。插件列表行与详情页因此按界面语言显示,而不是回退到 manifest 名称和英文文案。- 技术文档改为以中文为主:
docs/how-it-works.md、docs/formats.md、docs/troubleshooting.md、docs/releasing.md均为中文,英文版位于docs/en/下的同名文件。 CONTRIBUTING.md、CHANGELOG.md、SECURITY.md同样以中文为主,英文版分别为CONTRIBUTING.en.md、CHANGELOG.en.md、SECURITY.en.md;CODE_OF_CONDUCT.md保留 Contributor Covenant 英文原文。贡献指南新增「翻译」小节,说明中文是源语言、改动时需要同步哪些文件,以及新增一种语言时如何扩展测试中的LOCALES。
变更
files发布README*.md,不再写死两份 README;package.json新增i18n、localization、multilingual关键词,版本为0.3.0。- 英文版 README 不再直接引用只存在于中文里的错误提示;该错误改为可翻译的散文描述,使各语言译文都基于同一段英文说明。
- 发布清单(
docs/releasing.md)与格式文档(docs/formats.md)同步要求更新全部译文:发版时检查每种语言都仍有 locale 文件和 README,包内容检查期望全部八个 locale 与每一份译好的 README;格式文档的新增格式清单也要求同步更新各语言 README。文档之间的相对链接按语言指向中文页或docs/en/下的英文页。
测试
- 37 个测试:对八种语言逐语言校验元数据——各有一个可用的 locale 文件、标题、40 到 600 字符的简介,以及指向该语言 README 的
meta.detail;meta.detail与 README 互链,每份 README 必须以# dsh-paste-image开头并链接全部八种译文;此外还检查 locale 集合与打包声明(files中的README*.md、locale/*.json,以及./locale/*.json导出),并确认 README 与文档里的每个相对链接都指向真实存在的文件。图标与打包检查仍期望README*.md和每个 locale 文件。
v0.2.3 — one paste inserts one image
dsh-paste-image 0.2.3
Fixed
- One paste could insert the same image several times: every copy of the client bundle that had been loaded added another document-level listener, and the old
install()returned a no-op disposer so nothing was ever removed. Five loaded copies produced five identical attachments.install()is now idempotent, returns a reference-counted, abort-based disposer that removes both listeners once the last holder releases them, and each source paste/drop event is claimed once, so duplicate listeners can no longer convert and re-route the same event twice.
Tests
- 21 tests: the new one installs twice, asserts a single paste/drop listener pair, disposes, and installs again.
v0.2.2 — Plugin Manager metadata
Added
- Plugin Manager display metadata:
locale/en.jsonandlocale/zh.jsonshipmeta.titleandmeta.description, so plugin rows and the detail page describe the capability instead of falling back to the manifest name and README. - A package-root
icon(./assets/icon-180.png) and a./locale/*.jsonexport; the icon and locales now travel inside the npm tarball. .github/workflows/release.ymlpublishes GitHub Releases to npm through OIDC trusted publishing, with no stored token.
Changed
dsh-paste-image@0.2.1is the first npm release; both READMEs now lead withdsh plugin --profile <profile> add dsh-paste-imageand keep the GitHub install as the no-registry alternative.
Tests
- 20 tests: the four new ones assert both locale files carry usable
meta.title/meta.description, the icon is a PNG under 256 KiB, and the locales plus icon are packaged and exported.
v0.2.1
Fixed
- The release checklist in
docs/releasing.mdreported the 0.2.0 test count; it now matches the suite (16 tests).
v0.2.0 — full BMP/DIB, SVG and ICO support
Added
- Full BMP/DIB coverage in
decodeBmp(): 1/4/8/16/24/32-bit pixels,BI_RLE8/BI_RLE4,BI_BITFIELDS/BI_ALPHABITFIELDS,BITMAPCOREHEADER,BITMAPV2/V3/V4/V5HEADER, OS/2 v2 headers and headerless DIBs (theCF_DIBshape). - Embedded JPEG/PNG payloads (
BI_JPEG/BI_PNG) are unwrapped and handed to the browser decoder. - SVG pastes are rasterised through an
<img>element;viewBoxprovides the size whenwidth/heightare missing. - ICO/CUR fall back to the largest PNG-compressed directory entry when the browser cannot decode the icon.
- Magic-byte detection for AVIF, HEIC/HEIF, ICO/CUR, SVG and headerless DIBs.
- MIME alias table so
image/jpg,image/x-png,image/x-bmp,image/x-xpixmap,image/svg+xmland friends are treated as the canonical type. MAX_PIXELSguard (64 Mi px) before a BMP/XPM canvas is allocated.docs/formats.md: the decision pipeline, the full format matrix, the BMP variant grid and the checklist for adding a format.docs/releasing.md: version policy, release checklist, npm publish steps and marketplace sync.- Open-source scaffolding:
.github/CODEOWNERS, issue-template contact links, README badges, and a Community section linking contributing, conduct, security, changelog and releases.
Changed
- A native image with an empty declared type is re-wrapped with the sniffed type instead of being passed through and rejected by the host.
- Row stride, palette entries, bit masks and alpha handling in the BMP decoder are shared by every pixel depth instead of being hard-coded for 24/32-bit.
- BMP files using
BI_CMYKcompression (11/12/13) are rejected withbmp: unsupported compressioninstead of being decoded as RGB.
Fixed
- 32-bit BMPs whose encoder leaves the alpha channel at zero no longer export as a fully transparent PNG.
- Palette BMP entries are loaded with the correct entry size (3 bytes for the OS/2 core header, 4 otherwise), and a zero alpha byte in a palette entry no longer makes that colour transparent.
cordis.patch.ymlis now part of the publishedfileslist. GitHub (and future npm) installs used to omit the loader patch, so the bundle entry never mounted; CI checks the tarball for the file.