import { describe, expect, it } from "vitest";
import { hoistStyles, prioritize, rescope } from "@banes-lab/build-scripts/core/converters/style.converter.ts";
const ROOT_ID = "diagram-7";
const SOURCE = "flowchart LR\n a --> b";
const MARKUP = [
`",
].join("");
describe("rescope", () => {
it("moves the root id selector onto the shared vector class and derived ids onto the shared stem", () => {
const rescoped = rescope(`#${ROOT_ID}{a}#${ROOT_ID} .x{b}url(#${ROOT_ID}-gradient)#${ROOT_ID}`, ROOT_ID);
expect(rescoped.css).toBe(
".diagram-vector{a}.diagram-vector .x{b}url(#diagram-vector-gradient).diagram-vector",
);
expect([...rescoped.derived]).toStrictEqual(["-gradient"]);
});
it("leaves a block alone when the vector carries no root id", () => {
expect(rescope("#ccc{a}", "")).toStrictEqual({ css: "#ccc{a}", derived: new Set() });
});
});
describe("prioritize", () => {
it("marks every declaration important once, splitting only outside groups and quotes", () => {
expect(prioritize("fill:url(a;b); stroke:'x;y' !important;;")).toBe(
"fill:url(a;b) !important;stroke:'x;y' !important",
);
});
});
describe("hoistStyles", () => {
const hoisted = hoistStyles(new Map([[SOURCE, MARKUP]]));
const vector = hoisted.vectors.get(SOURCE) ?? "";
it("strips every style element and attribute from the vector and classes the root", () => {
expect(vector).not.toContain("