UNPKG

spread-diff-patch

Version:
78 lines (77 loc) 2.16 kB
// src/formatter/index.ts var Formatter = class { /** * Creates an instance of Formatter. * @param {Function} patcher - The patcher function used to generate the patched string. */ constructor(patcher = (actual, expected) => { let patchedString = ""; if (actual) patchedString += `[-][${actual}]`; if (actual && expected) patchedString += " "; if (expected) patchedString += `[+][${expected}]`; return patchedString; }) { this.patch = patcher; } /** * Formats the diff array of arrays. * @param diffAOA - The diff array of arrays to be formatted. * @returns The formatted string. */ format(diffAOA) { throw new Error("Method not implemented."); } }; // src/formatter/html.ts import fs from "fs"; import escapeHTML from "escape-html"; import path from "path"; var HTML = class extends Formatter { constructor(patcher = (actual, expected) => { let patchedString = ""; if (actual) patchedString += `<span style="background:#ffbbbb;"><s>${actual}</s></span>`; if (actual && expected) patchedString += " "; if (expected) patchedString += `<span style="background:#bbffbb;">${expected}</span>`; return patchedString; }) { super(patcher); this.patch = patcher; } format(diffAOA) { const script = fs.readFileSync(path.resolve(__dirname, "./script.js"), "utf8"); const patchedAOA = diffAOA.map((row) => { return row.map((cell) => { if (Array.isArray(cell)) { return this.patch(cell[0], cell[1]); } return cell; }); }); return ` <div id="spread-diff-patch"> <style> * { box-sizing: border-box; margin: 0; padding: 0; } </style> <div id="spread-diff-patch-data" data-raw-diffAOA='${escapeHTML(JSON.stringify(patchedAOA))}'></div> <script src="https://unpkg.com/canvas-datagrid"></script> <script> ${script} </script> </div> `; } }; export { HTML }; //# sourceMappingURL=html.mjs.map