Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

1.6 KB
Raw Blame
import type { BrushPresetId, DecorationCategory } from '../types/editor';
import type { BuiltinBrushDefinition, BuiltinBrushSection } from './presetBrushes';

export const DECORATION_BRUSH_SECTIONS: BuiltinBrushSection[] = [
  { id: 'deco-background', label: 'Background' },
  { id: 'deco-clothing', label: 'Clothing' },
  { id: 'deco-effect', label: 'Effect' },
];

export const DECORATION_CATEGORY_SET = new Set<string>(
  DECORATION_BRUSH_SECTIONS.map((s) => s.id)
);

export const DEFAULT_DECORATION_PRESET_ID: BrushPresetId = '';

export function isDecorationCategory(category: string | undefined): category is DecorationCategory {
  return Boolean(category && DECORATION_CATEGORY_SET.has(category));
}

export function resolveStaticBrushAssetUrl(assetPath: string): string {
  if (!assetPath) return '';
  if (
    assetPath.startsWith('data:') ||
    assetPath.startsWith('http://') ||
    assetPath.startsWith('https://') ||
    assetPath.startsWith('blob:')
  ) {
    return assetPath;
  }
  const base =
    typeof import.meta !== 'undefined' &&
    import.meta.env &&
    typeof import.meta.env.BASE_URL === 'string'
      ? import.meta.env.BASE_URL
      : '/';
  const cleanBase = base.endsWith('/') ? base : `${base}/`;
  const cleanPath = assetPath.replace(/^\/+/, '');
  return `${cleanBase}${cleanPath}`;
}

export const DECORATION_BRUSHES: BuiltinBrushDefinition[] = [];

const DECORATION_PRESET_ID_SET = new Set<string>(DECORATION_BRUSHES.map((b) => b.id));

export function isDecorationPresetId(presetId: string | undefined | null): boolean {
  return Boolean(presetId && DECORATION_PRESET_ID_SET.has(presetId));
}