@tldraw/tlschema
Version:
tldraw infinite canvas SDK (schema).
52 lines (51 loc) • 1.6 kB
JavaScript
import { StyleProp } from "./StyleProp.mjs";
const DefaultFontStyle = StyleProp.defineEnum("tldraw:font", {
defaultValue: "draw",
values: ["draw", "sans", "serif", "mono"]
});
const DefaultFontFamilies = {
draw: "'tldraw_draw', sans-serif",
sans: "'tldraw_sans', sans-serif",
serif: "'tldraw_serif', serif",
mono: "'tldraw_mono', monospace"
};
function isFontEntry(value) {
return typeof value === "object" && value !== null && "fontFamily" in value;
}
function registerFontsFromThemes(definitions) {
const fontNames = /* @__PURE__ */ new Set();
for (const def of Object.values(definitions)) {
if (!def.fonts) continue;
for (const [key, value] of Object.entries(def.fonts)) {
if (isFontEntry(value)) {
fontNames.add(key);
}
}
}
const toAdd = [...fontNames].filter((v) => !DefaultFontStyle.values.includes(v));
if (toAdd.length > 0) {
DefaultFontStyle.addValues(...toAdd);
}
const toRemove = DefaultFontStyle.values.filter((v) => !fontNames.has(v));
if (toRemove.length > 0) {
DefaultFontStyle.removeValues(...toRemove);
}
if (process.env.NODE_ENV !== "production") {
for (const def of Object.values(definitions)) {
for (const font of fontNames) {
if (!def.fonts || !(font in def.fonts)) {
console.warn(
`Theme '${def.id}' is missing font '${font}'. Shapes using this font won't render correctly in this theme.`
);
}
}
}
}
}
export {
DefaultFontFamilies,
DefaultFontStyle,
isFontEntry,
registerFontsFromThemes
};
//# sourceMappingURL=TLFontStyle.mjs.map