mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-08-28 17:21:05 +00:00
refactor: consolidate and debloat calendar sync implementation
Merge duplicated Google/Outlook engines, background handlers, and API layers into shared calendarSync modules to cut complexity without changing user-facing sync behavior.
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
extractSolidColor,
|
||||
normalizeCssColorString,
|
||||
parseCssColor,
|
||||
} from "./parseCssColor";
|
||||
import { extractSolidColor, normalizeCssColorString } from "./parseCssColor";
|
||||
|
||||
describe("normalizeCssColorString", () => {
|
||||
it("lowercases uppercase RGBA/RGB function names", () => {
|
||||
@@ -28,19 +24,3 @@ describe("extractSolidColor", () => {
|
||||
).toBe("rgba(201,61,0,1)");
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseCssColor", () => {
|
||||
it("parses uppercase RGBA without throwing", () => {
|
||||
const parsed = parseCssColor("RGBA(3, 29, 11, 0.58)");
|
||||
expect(parsed.alpha()).toBeCloseTo(0.58, 2);
|
||||
expect(parsed.red()).toBe(3);
|
||||
expect(parsed.green()).toBe(29);
|
||||
expect(parsed.blue()).toBe(11);
|
||||
});
|
||||
|
||||
it("falls back when the value is not a colour", () => {
|
||||
expect(parseCssColor("not-a-color", "#007bff").hex().toLowerCase()).toBe(
|
||||
"#007bff",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import Color from "color";
|
||||
|
||||
type ColorInstance = ReturnType<typeof Color>;
|
||||
|
||||
/**
|
||||
* SEQTA themes and user gradients often use uppercase `RGBA()` / `RGB()`.
|
||||
* The `color` package only accepts lowercase function names.
|
||||
@@ -32,34 +28,3 @@ export function extractSolidColor(value: string): string | null {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Parse a CSS colour for the `color` library; never throws. */
|
||||
export function parseCssColor(value: string, fallback = "#007bff"): ColorInstance {
|
||||
const candidates = [
|
||||
extractSolidColor(value),
|
||||
normalizeCssColorString(value),
|
||||
].filter((candidate): candidate is string => Boolean(candidate));
|
||||
|
||||
for (const candidate of candidates) {
|
||||
try {
|
||||
return Color(candidate);
|
||||
} catch {
|
||||
// try next strategy
|
||||
}
|
||||
|
||||
const rgbaMatch = candidate.match(
|
||||
/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)/i,
|
||||
);
|
||||
if (rgbaMatch) {
|
||||
try {
|
||||
const [, r, g, b, a] = rgbaMatch;
|
||||
const rgb = Color.rgb(Number(r), Number(g), Number(b));
|
||||
return a !== undefined ? rgb.alpha(Number(a)) : rgb;
|
||||
} catch {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Color(fallback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user