@tldraw/tlschema
Version:
tldraw infinite canvas SDK (schema).
72 lines (71 loc) • 2.63 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var TLFontStyle_exports = {};
__export(TLFontStyle_exports, {
DefaultFontFamilies: () => DefaultFontFamilies,
DefaultFontStyle: () => DefaultFontStyle,
isFontEntry: () => isFontEntry,
registerFontsFromThemes: () => registerFontsFromThemes
});
module.exports = __toCommonJS(TLFontStyle_exports);
var import_StyleProp = require("./StyleProp");
const DefaultFontStyle = import_StyleProp.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.`
);
}
}
}
}
}
//# sourceMappingURL=TLFontStyle.js.map