UNPKG

@tldraw/tlschema

Version:

tldraw infinite canvas SDK (schema).

68 lines (67 loc) 1.96 kB
import { StyleProp } from "./StyleProp.mjs"; const defaultColorNames = [ "black", "grey", "light-violet", "violet", "blue", "light-blue", "yellow", "orange", "green", "light-green", "light-red", "red", "white" ]; const DefaultColorStyle = StyleProp.defineEnum("tldraw:color", { defaultValue: "black", values: defaultColorNames }); const DefaultLabelColorStyle = StyleProp.defineEnum("tldraw:labelColor", { defaultValue: "black", values: defaultColorNames }); function registerColorsFromThemes(definitions) { const colorNames = /* @__PURE__ */ new Set(); for (const def of Object.values(definitions)) { for (const colorPalette of [def.colors.light, def.colors.dark]) { for (const [key, value] of Object.entries(colorPalette)) { if (typeof value === "object" && value !== null) { colorNames.add(key); } } } } if (colorNames.size > 0) { DefaultColorStyle.addValues(...colorNames); DefaultLabelColorStyle.addValues(...colorNames); } const toRemove = DefaultColorStyle.values.filter((v) => !colorNames.has(v)); if (toRemove.length > 0) { DefaultColorStyle.removeValues(...toRemove); DefaultLabelColorStyle.removeValues(...toRemove); } if (process.env.NODE_ENV !== "production") { for (const def of Object.values(definitions)) { for (const color of colorNames) { if (!(color in def.colors.light)) { console.warn( `Theme '${def.id}' light palette is missing color '${color}'. Shapes using this color won't render correctly.` ); } if (!(color in def.colors.dark)) { console.warn( `Theme '${def.id}' dark palette is missing color '${color}'. Shapes using this color won't render correctly.` ); } } } } } export { DefaultColorStyle, DefaultLabelColorStyle, registerColorsFromThemes }; //# sourceMappingURL=TLColorStyle.mjs.map