From af841a2052fa510969630f3a8be05dcd625c7451 Mon Sep 17 00:00:00 2001 From: Ritesh Kumar Date: Sat, 14 Feb 2026 01:13:47 +0530 Subject: [PATCH 1/2] refactor: extract buildCSSString into shared helper --- helpers/buildCSSString.ts | 18 ++++++++++++++++++ helpers/buildCSSToInject.ts | 36 ++++-------------------------------- 2 files changed, 22 insertions(+), 32 deletions(-) create mode 100644 helpers/buildCSSString.ts diff --git a/helpers/buildCSSString.ts b/helpers/buildCSSString.ts new file mode 100644 index 0000000..e2c22a9 --- /dev/null +++ b/helpers/buildCSSString.ts @@ -0,0 +1,18 @@ +import type { TStyle } from "./constants" + +export const buildCSSString = (css: TStyle): string => { + let globalStyles = "" + let paragraphStyles = "" + + for (const [key, value] of Object.entries(css)) { + if (key === "paragraph-spacing") { + paragraphStyles += `margin-bottom: ${value}em !important;` + } else if (key !== "line-height") { + globalStyles += `${key}: ${value !== "" ? `${value}em !important;` : value}` + } else { + globalStyles += `${key}: ${value !== "" ? `${value} !important;` : value}` + } + } + + return `* { ${globalStyles} } p { ${paragraphStyles} }` +} diff --git a/helpers/buildCSSToInject.ts b/helpers/buildCSSToInject.ts index a33ff67..00b77c8 100644 --- a/helpers/buildCSSToInject.ts +++ b/helpers/buildCSSToInject.ts @@ -1,42 +1,14 @@ import type { TStyle } from "./constants" -import t from "./t" +import { buildCSSString } from "./buildCSSString" export const buildCSSToInject = (css: TStyle | string, tabId: number) => { - let globalStyles = "" - let paragraphStyles = "" + const cssString = typeof css === "string" ? css : buildCSSString(css) - if (typeof css === "string") { - return { - target: { - tabId: tabId, - allFrames: true - }, - css - } - } - - for (const [key, value] of Object.entries(css)) { - // Parse style object and format CSS properties - if (key === "paragraph-spacing") { - paragraphStyles += `margin-bottom: ${value}em !important;` - } else if (key !== "line-height") { - globalStyles += `${key}: ${ - value !== "" ? `${value}em !important;` : value - }` - } else { - globalStyles += `${key}: ${ - value !== "" ? `${value} !important;` : value - }` - } - } - - const payload = { + return { target: { tabId: tabId, allFrames: true }, - css: `* { ${globalStyles} } p { ${paragraphStyles} }` + css: cssString } - - return payload } From e5140df635a5f3c4c57cfd9790bb3eea767f50fc Mon Sep 17 00:00:00 2001 From: Ritesh Kumar Date: Sat, 14 Feb 2026 01:55:20 +0530 Subject: [PATCH 2/2] feat: add shadow DOM support for text spacing styles Inject styles into open shadow DOM boundaries via a content script that walks the DOM, finds shadow roots, and injects