export const applyGlobalTextStrokeToEditorHost = (
host: HTMLElement,
textStroke: string | undefined,
zoomScale: number,
): void => {
const strokeStyle = host.style as CSSStyleDeclaration & {
webkitTextStroke?: string;
};
if (textStroke && textStroke !== "unset") {
host.style.paintOrder = "stroke fill";
strokeStyle.webkitTextStroke = scaleCssPxValues(textStroke, zoomScale);
} else {
host.style.paintOrder = "unset";
strokeStyle.webkitTextStroke = "unset";
}
};export const clearQuillEditorTextStroke = (qlEditor: HTMLElement | null): void => {
if (!qlEditor) return;
qlEditor.style.removeProperty("-webkit-text-stroke");
qlEditor.style.removeProperty("paint-order");
};const TYPOGRAPHY_STROKE_TAGS = new Set(["EM", "STRONG", "U", "S"]);
export const sanitizeTypographyTextStrokesForGlobal = (
root: ParentNode | null,
globalStroke: string | undefined,
zoomScale: number,
): void => {
if (!root || !globalStroke || globalStroke === "unset") return;
root.querySelectorAll<HTMLElement>("em, strong, u, s").forEach((el) => {
el.style.removeProperty("-webkit-text-stroke");
el.style.removeProperty("paint-order");
el.removeAttribute("data-htmltext-inline-text-stroke");
});
root.querySelectorAll<HTMLElement>("span[style]").forEach((el) => {
const stroke = (el.style as CSSStyleDeclaration & {
webkitTextStroke?: string;
}).webkitTextStroke;
if (!stroke || stroke === "unset" || stroke === "0px") return;
const scaledGlobal = scaleCssPxValues(globalStroke, zoomScale);
if (stroke === globalStroke || stroke === scaledGlobal) {
el.style.removeProperty("-webkit-text-stroke");
el.style.removeProperty("paint-order");
el.removeAttribute("data-htmltext-inline-text-stroke");
}
});
};export const scaleEditorInlineTextStrokes = (
root: ParentNode,
zoomScale: number,
): void => {
if (!Number.isFinite(zoomScale) || zoomScale <= 0) return;
root.querySelectorAll<HTMLElement>("[style]").forEach((el) => {
const style = el.style as CSSStyleDeclaration & {
webkitTextStroke?: string;
};
const originalStroke =
el.getAttribute("data-htmltext-inline-text-stroke") ||
style.webkitTextStroke;
if (!originalStroke || originalStroke === "unset" || originalStroke === "0px") return;
el.setAttribute("data-htmltext-inline-text-stroke", originalStroke);
style.webkitTextStroke = scaleCssPxValues(originalStroke, zoomScale);
style.paintOrder = "stroke fill";
});
};export const restoreEditorInlineTextStrokes = (root: ParentNode | null): void => {
if (!root) return;
root.querySelectorAll<HTMLElement>("[data-htmltext-inline-text-stroke]").forEach((el) => {
const originalStroke = el.getAttribute("data-htmltext-inline-text-stroke");
const style = el.style as CSSStyleDeclaration & {
webkitTextStroke?: string;
};
if (originalStroke) style.webkitTextStroke = originalStroke;
el.removeAttribute("data-htmltext-inline-text-stroke");
});
};