sokko-g/website/src/features/toolboxes/modules/notepadUtils.js
Shinuwa b0e340efc7
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Fix Notepad synchronization across pages and external updates
2026-09-12 12:36:31 +02:00

37 lines
1.1 KiB
JavaScript

// Rôle : regroupe les constantes et helpers DOM du Bloc Note riche.
export { DRAWING_COLORS as TEXT_COLORS, DRAWING_WIDTHS } from "../../../utils/drawingOptions.js";
export const HIGHLIGHT_COLORS = ["#f6c453", "#22d3ee", "#8b5cf6", "#d946ef", "#202745"];
export function getPlainText(element) {
return (element?.innerText || "").replace(/\n{3,}/g, "\n\n").trim();
}
export function isHtmlEmpty(html, text) {
return !text && !String(html || "").replace(/<br\s*\/?>/gi, "").replace(/<[^>]*>/g, "").replace(/&nbsp;/gi, " ").trim();
}
export function formatUpdatedAt(value) {
if (!value) return "";
const date = new Date(value);
if (Number.isNaN(date.getTime())) return "";
return new Intl.DateTimeFormat("fr-FR", {
dateStyle: "short",
timeStyle: "short"
}).format(date);
}
export function queryCommandState(command) {
try {
return document.queryCommandState(command);
} catch {
return false;
}
}
export function queryBlockFormat() {
try {
return String(document.queryCommandValue("formatBlock") || "").replace(/[<>]/g, "").toLowerCase();
} catch {
return "";
}
}