import type { RuntimeConfig } from '../types.ts' import { clientOption } from './features.ts' export const EDITOR_SIZE_VALUES = ['sm', 'md', 'lg', 'xl'] as const export const DEFAULT_EDITOR_SIZE: EditorSize = 'sm' export type EditorSize = (typeof EDITOR_SIZE_VALUES)[number] export type EditorSizeConfig = boolean | EditorSize export function isEditorSizeValue(value: unknown): value is EditorSize { return ( typeof value === 'string' && EDITOR_SIZE_VALUES.includes(value as EditorSize) ) } export function normalizeEditorSize( value: unknown, fallback: EditorSize = DEFAULT_EDITOR_SIZE ): EditorSize { return isEditorSizeValue(value) ? value : fallback } export function editorSizeOption(config: RuntimeConfig = {}): unknown { return clientOption(config, 'editorSize') } export function isEditorSizeEnabled(config: RuntimeConfig = {}): boolean { return editorSizeOption(config) !== false } export function configuredEditorSize(config: RuntimeConfig = {}): EditorSize { const value = editorSizeOption(config) if (value === undefined || value === true || value === false) { return DEFAULT_EDITOR_SIZE } return normalizeEditorSize(value) } export function editorSizeClassName(size: unknown): string { return `is-${normalizeEditorSize(size)}` } export function editorClassName(config: RuntimeConfig = {}): string { return `j-editor ${editorSizeClassName(configuredEditorSize(config))}` } export function assertEditorSizeConfig(config: RuntimeConfig = {}): void { const value = editorSizeOption(config) if ( value === undefined || value === true || value === false || isEditorSizeValue(value) ) { return } throw new Error('editorSize must be false, true, or one of: sm, md, lg, xl.') } export function editorSizeBootScript(config: RuntimeConfig = {}): string { if (!isEditorSizeEnabled(config)) return '' const fallback = configuredEditorSize(config) return `(function(d,n,z,f){function v(s){return z.indexOf(s)>-1?s:f}function p(){var c=d.cookie?d.cookie.split('; '):[],m='';for(var i=0;i