تخطَّ إلى المحتوى الرئيسي

السمات

تُدار سمات Clepit بواسطة متغيرات CSS. اضبط theme: "auto" | "light" | "dark"، أو مرّر themeOverrides صريحة.

theme

TypeScript
// EditorConfig / RendererConfig
theme?: 'auto' | 'light' | 'dark'

يتبع الإعداد المسبق auto نظام ألوان نظام التشغيل عبر prefers-color-scheme ويتبدّل فورًا عند التغيير.

TypeScript
import { Editor } from '@clepit/core';

Editor.create({ containerId: 'editor', theme: 'auto' });

ThemeTokens

جميع الرموز الـ 22 اختيارية. أي شيء تحذفه يعود إلى الإعداد المسبق المحدّد.

الرمزما يتحكم فيه
bgلون الخلفية الرئيسي للمحرر/العارض
surfaceسطح ثانوي: لوحات الأوامر ورأسيات شريط الوضع
surface2سطح ثلاثي: خلفيات القوائم المحوّمة
textلون النص الأساسي
textMutedنص ثانوي: التسميات، الفقرات الاحتياطية
textSubtleنص خافت: عناصر نائمة، علامات التاريخ
borderلون الحدود الرئيسية
borderSubtleحدود خفية: مقسّمات غير قياسية
primaryلون العلامة التجارية الأساسي: الأزرار والروابط
primaryHoverاللون الأساسي عند التحويم: حالة hover/focus للأزرار
primaryBgخلفية اللون الأساسي الفاتحة: حلقة التركيز
markerلون تمييز النص: أداة التظليل
selectionBgخلفية تحديد النص
blockHighlightBgخلفية الكتلة النشطة
successلون نص/أيقونة حالة النجاح
successBgخلفية حالة النجاح الفاتحة: صناديق الإشعارات
warningلون نص/أيقونة حالة التحذير
warningBgخلفية حالة التحذير الفاتحة
errorلون نص/أيقونة حالة الخطأ
errorBgخلفية حالة الخطأ الفاتحة
infoلون نص/أيقونة حالة المعلومات
infoBgخلفية حالة المعلومات الفاتحة

themeOverrides

تجاوز أي مجموعة فرعية من الرموز. يحقنها المحرر كمتغيرات CSS مقصورة على حاويته.

TypeScript
// themeOverrides accepts separate light and dark token sets.
// Both keys are optional — omit one to use the preset for that mode.
Editor.create({
  containerId: 'editor',
  theme: 'auto',
  themeOverrides: {
    light: {
      primary: '#5b5bff',
      primaryHover: '#4747e6',
      bg: '#ffffff',
      text: '#0a0a0a',
    },
    dark: {
      primary: '#7c7cff',
      primaryHover: '#9494ff',
      bg: '#161b22',
      text: 'rgba(240, 246, 252, 0.92)',
    },
  },
});

خصائص CSS المخصّصة

يرتبط كل رمز بمتغير ‎--clepit-*‎ مقصور على حاوية المحرر. يمكنك قراءتها أو توسيعها من ورقة الأنماط الخاصة بك.

CSS
/* Every ThemeToken maps to a --clepit-* CSS variable.
   Variables are scoped to .clepit-editor, .clepit-renderer-content, and body[data-clepit-theme]. */

--clepit-bg
--clepit-surface
--clepit-surface-2
--clepit-text
--clepit-text-muted
--clepit-text-subtle
--clepit-border
--clepit-border-subtle
--clepit-primary
--clepit-primary-hover
--clepit-primary-bg
--clepit-marker
--clepit-selection-bg
--clepit-block-highlight-bg
--clepit-success
--clepit-success-bg
--clepit-warning
--clepit-warning-bg
--clepit-error
--clepit-error-bg
--clepit-info
--clepit-info-bg
CSS
#editor {
  color: var(--clepit-text);
  background: var(--clepit-bg);
  --my-surface: var(--clepit-surface-2);
  border: 1px solid var(--clepit-border);
}

styles و classNames لكل كتلة

يمرر RendererConfig.styles خصائص CSS مستقلة عن الإطار مباشرةً إلى عنصر الجذر للمكوّن. يضيف RendererConfig.classNames أسماء CSS إضافية دون التأثير على الأنماط المدمجة. يمكن الجمع بين الاثنين.

TypeScript
import { Renderer } from '@clepit/core';
import type { BlockStyles, BlockClassNames } from '@clepit/core';

const styles: BlockStyles = {
  // alert block — keyed by variant
  alert: {
    error: { borderRadius: '8px', padding: '12px 16px' },
    info: { borderRadius: '8px', padding: '12px 16px' },
  },
  // header block — keyed by level
  header: {
    h1: { fontFamily: 'Georgia, serif' },
    h2: { fontFamily: 'Georgia, serif' },
  },
  // paragraph block — flat CSSProperties
  paragraph: { lineHeight: '1.75' },
  // table block — sub-element keys
  table: { cell: { padding: '8px 12px' } },
  // code block — sub-element keys
  code: { container: { borderRadius: '6px' } },
};

const classNames: BlockClassNames = {
  paragraph: 'prose-paragraph',
  header: { h1: 'prose-h1', h2: 'prose-h2' },
  alert: { info: 'alert-info', error: 'alert-error' },
};

Renderer.create({ containerId: 'output', data, styles, classNames });

StyleManager.subscribe

اشترك في تغييرات الرموز أثناء التشغيل. مفيد لمزامنة واجهة المستخدم المحيطة مع عمليات تبديل سمة المحرر.

TypeScript
import { StyleManager } from '@clepit/core';

const unsubscribe = StyleManager.subscribe(theme => {
  // theme is 'light' | 'dark' — sync surrounding UI
  document.documentElement.setAttribute('data-theme', theme);
});

// later — clean up when the component unmounts
unsubscribe();
يتيح توفير themeOverrides لكل عملية تركيب أن يشحن التطبيق نفسه عدة محررات بسمات مختلفة على الصفحة نفسها.