/** * SwDocShell — loads and stores documents through the filters * (sw/source/uibase/app/docsh.cxx: ConvertFrom / ConvertTo). The UI flow * around it (dialogs, "save changes?") is in the view's object shell slots. */ import { strFromU8, strToU8 } from "fflate"; import { filterForPath, WRITER_FILTERS, type SfxFilter, } from "../../../../filter/source/config/fragments/filters"; import type { SwDoc } from "../../../inc/doc"; import { importText } from "../../filter/ascii/parasc"; import { exportText } from "../../filter/ascii/wrtasc"; import { exportHtml } from "../../filter/html/wrthtml"; import { importFlatOdt, importOdt } from "../../filter/xml/swxml"; import { exportFlatOdt, exportOdt } from "../../filter/xml/wrtxml"; const byName = (name: string) => WRITER_FILTERS.find((f) => f.name === name)!; /** Type detection (like filter/source/config type detection): extension, then content sniffing. */ export function detectFilter(path: string, bytes: Uint8Array): SfxFilter { if (bytes[0] === 0x50 && bytes[1] === 0x4b) return byName("writer8"); // "PK" zip const byExt = filterForPath(path); if (byExt?.import) return byExt; const head = strFromU8(bytes.subarray(0, 512)); if (head.includes("