diff --git a/studio/ui/src/lib/components/inspect/text-editor.svelte b/studio/ui/src/lib/components/inspect/text-editor.svelte new file mode 100644 index 0000000..9031b4b --- /dev/null +++ b/studio/ui/src/lib/components/inspect/text-editor.svelte @@ -0,0 +1,91 @@ + + + diff --git a/studio/ui/src/lib/components/inspect/text-inspector.svelte b/studio/ui/src/lib/components/inspect/text-inspector.svelte index a188f25..8ab7f2a 100644 --- a/studio/ui/src/lib/components/inspect/text-inspector.svelte +++ b/studio/ui/src/lib/components/inspect/text-inspector.svelte @@ -2,10 +2,10 @@ import { project } from '$lib/project.svelte'; import Input from '../ui/input/input.svelte'; import Button from '../ui/button/button.svelte'; - import MiniMessageEditor from '../minimessage/editor.svelte'; import { tick } from 'svelte'; import * as DropdownMenu from '../ui/dropdown-menu/index.js'; import ChevronDownIcon from '@lucide/svelte/icons/chevron-down'; + import TextEditor from './text-editor.svelte'; const TEXT_SIZES = [8, 12, 16, 24, 32, 48, 64] as const; @@ -20,7 +20,7 @@ return TEXT_SIZES.includes(size as (typeof TEXT_SIZES)[number]) ? size : 8; }); - let editorRef: MiniMessageEditor | null = $state(null); + let editorRef: TextEditor | null = $state(null); $effect(() => { void project.focusEditorTick; @@ -42,7 +42,7 @@
Text Content - +
Size
@@ -51,7 +51,7 @@ value={textSize} min={8} max={64} - class="h-8 w-14 rounded-r-none border-r-0 text-center [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" + class="h-8 w-14 [appearance:textfield] rounded-r-none border-r-0 text-center [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" onblur={(e) => { const val = Math.max(8, Math.min(64, Number((e.target as HTMLInputElement).value) || 8)); updateTextSize(val); diff --git a/studio/ui/src/lib/components/minimessage/advanced-editor.svelte b/studio/ui/src/lib/components/minimessage/advanced-editor.svelte deleted file mode 100644 index e19ba85..0000000 --- a/studio/ui/src/lib/components/minimessage/advanced-editor.svelte +++ /dev/null @@ -1,464 +0,0 @@ - - -
-
- - - -
- - {#if parseResult.errors.length > 0} -
- {#each parseResult.errors as error} -
- {error.severity}: - {error.message} -
- {/each} -
- {/if} -
- - diff --git a/studio/ui/src/lib/components/minimessage/color-picker.svelte b/studio/ui/src/lib/components/minimessage/color-picker.svelte deleted file mode 100644 index f7ec4d1..0000000 --- a/studio/ui/src/lib/components/minimessage/color-picker.svelte +++ /dev/null @@ -1,153 +0,0 @@ - - - - - {#snippet child({ props })} - - {/snippet} - - -
-
- {#each MINECRAFT_COLORS as color} - - {/each} -
- -
- -
- - -
-
-
-
-
- - diff --git a/studio/ui/src/lib/components/minimessage/editor.svelte b/studio/ui/src/lib/components/minimessage/editor.svelte deleted file mode 100644 index 20648e0..0000000 --- a/studio/ui/src/lib/components/minimessage/editor.svelte +++ /dev/null @@ -1,63 +0,0 @@ - - -
-
- -
-
- - diff --git a/studio/ui/src/lib/components/minimessage/preview.svelte b/studio/ui/src/lib/components/minimessage/preview.svelte deleted file mode 100644 index 0764609..0000000 --- a/studio/ui/src/lib/components/minimessage/preview.svelte +++ /dev/null @@ -1,87 +0,0 @@ - - -
-
- {@html renderedHtml} -
- - {#if hasErrors || hasWarnings} -
- {#each parseResult.errors as error} -
- {error.severity}: - {error.message} - @ {error.position} -
- {/each} -
- {/if} -
- - diff --git a/studio/ui/src/lib/components/minimessage/toolbar.svelte b/studio/ui/src/lib/components/minimessage/toolbar.svelte deleted file mode 100644 index 627a469..0000000 --- a/studio/ui/src/lib/components/minimessage/toolbar.svelte +++ /dev/null @@ -1,98 +0,0 @@ - - -
- -
- {#each formatButtons as btn} - - {/each} -
- - - insertTag('color', color)} /> - - -
- {#each effectButtons as btn} - - {/each} - - -
- - - -
- - diff --git a/studio/ui/src/lib/components/minimessage/warning.md b/studio/ui/src/lib/components/minimessage/warning.md deleted file mode 100644 index 309faa0..0000000 --- a/studio/ui/src/lib/components/minimessage/warning.md +++ /dev/null @@ -1,5 +0,0 @@ -# WARNING! - -Vibecoded code ahead. -So far not many bugs, but I would NEVER expect any PRs to this part! -You should not have to read AI generated code. It is my decision to use the tools but it shouldn't be a burden to you. diff --git a/studio/ui/src/lib/minimessage/effects/gradient.ts b/studio/ui/src/lib/minimessage/effects/gradient.ts deleted file mode 100644 index 269d588..0000000 --- a/studio/ui/src/lib/minimessage/effects/gradient.ts +++ /dev/null @@ -1,86 +0,0 @@ -// Color Utilities for Gradient Interpolation - -export interface RGB { - r: number; - g: number; - b: number; -} - -/** - * Convert hex color to RGB - */ -export function hexToRgb(hex: string): RGB { - const clean = hex.replace('#', ''); - const r = parseInt(clean.substring(0, 2), 16); - const g = parseInt(clean.substring(2, 4), 16); - const b = parseInt(clean.substring(4, 6), 16); - - return { r, g, b }; -} - -/** - * Convert RGB to hex color - */ -export function rgbToHex(rgb: RGB): string { - const r = Math.round(rgb.r).toString(16).padStart(2, '0'); - const g = Math.round(rgb.g).toString(16).padStart(2, '0'); - const b = Math.round(rgb.b).toString(16).padStart(2, '0'); - - return `#${r}${g}${b}`; -} - -/** - * Linear interpolation between two values - */ -function lerp(a: number, b: number, t: number): number { - return a + (b - a) * t; -} - -/** - * Interpolate between two RGB colors - */ -function lerpColor(color1: RGB, color2: RGB, t: number): RGB { - return { - r: lerp(color1.r, color2.r, t), - g: lerp(color1.g, color2.g, t), - b: lerp(color1.b, color2.b, t) - }; -} - -/** - * Interpolate colors across a gradient - * @param colors Array of hex colors - * @param position Position in gradient (0 to 1) - * @param phase Optional phase offset (-1 to 1) - */ -export function interpolateGradient(colors: string[], position: number, phase: number = 0): string { - if (colors.length === 0) return '#FFFFFF'; - if (colors.length === 1) return colors[0]; - - let pos = position + phase; - pos = pos - Math.floor(pos); - - const scaledPos = pos * (colors.length - 1); - const index1 = Math.floor(scaledPos); - const index2 = Math.min(index1 + 1, colors.length - 1); - const t = scaledPos - index1; - - const rgb1 = hexToRgb(colors[index1]); - const rgb2 = hexToRgb(colors[index2]); - const result = lerpColor(rgb1, rgb2, t); - - return rgbToHex(result); -} - -/** - * Apply gradient to text (character-by-character) - */ -export function applyGradient(text: string, colors: string[], phase: number = 0): string[] { - const chars = Array.from(text); // Handle Unicode correctly - if (chars.length === 0) return []; - - return chars.map((char, i) => { - const position = chars.length === 1 ? 0 : i / (chars.length - 1); - return interpolateGradient(colors, position, phase); - }); -} diff --git a/studio/ui/src/lib/minimessage/effects/obfuscation.svelte.ts b/studio/ui/src/lib/minimessage/effects/obfuscation.svelte.ts deleted file mode 100644 index 43e0fbd..0000000 --- a/studio/ui/src/lib/minimessage/effects/obfuscation.svelte.ts +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Obfuscation effect - randomizes characters Minecraft-style - */ - -const OBFUSCATION_CHARS = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?'; - -export class ObfuscationEffect { - private intervalId: number | undefined; - private chars: { element: HTMLElement; original: string }[] = []; - - constructor( - private container: HTMLElement, - private charset: string = OBFUSCATION_CHARS - ) { - const charElements = container.querySelectorAll('.mm-obfuscated-char'); - - charElements.forEach((el) => { - const original = el.getAttribute('data-original') || el.textContent || ''; - this.chars.push({ - element: el as HTMLElement, - original - }); - }); - } - - start() { - if (this.intervalId) return; // Already running - - this.intervalId = window.setInterval(() => { - this.update(); - }, 50); // Update every 50ms - } - - stop() { - if (this.intervalId) { - clearInterval(this.intervalId); - this.intervalId = undefined; - } - - this.chars.forEach(({ element, original }) => { - element.textContent = original; - }); - } - - private update() { - this.chars.forEach(({ element, original }) => { - if (original.trim() === '') { - element.textContent = original; - return; - } - - const randomChar = this.charset[Math.floor(Math.random() * this.charset.length)]; - element.textContent = randomChar; - }); - } - - destroy() { - this.stop(); - this.chars = []; - } -} - -/** - * Initialize all obfuscation effects on the page - */ -export function initObfuscationEffects( - rootElement: HTMLElement = document.body -): ObfuscationEffect[] { - const effects: ObfuscationEffect[] = []; - const obfuscatedContainers = rootElement.querySelectorAll('.mm-obfuscated'); - - obfuscatedContainers.forEach((container) => { - const effect = new ObfuscationEffect(container as HTMLElement); - effect.start(); - effects.push(effect); - }); - - return effects; -} - -/** - * Stop and destroy all obfuscation effects - */ -export function destroyObfuscationEffects(effects: ObfuscationEffect[]) { - effects.forEach((effect) => effect.destroy()); -} diff --git a/studio/ui/src/lib/minimessage/effects/rainbow.svelte.ts b/studio/ui/src/lib/minimessage/effects/rainbow.svelte.ts deleted file mode 100644 index 747c810..0000000 --- a/studio/ui/src/lib/minimessage/effects/rainbow.svelte.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Rainbow effect - animates character colors through the rainbow spectrum - */ - -export class RainbowEffect { - private intervalId: number | undefined; - private chars: HTMLElement[] = []; - private currentPhase: number = 0; - - constructor( - private container: HTMLElement, - private initialPhase: number = 0, - private reverse: boolean = false - ) { - this.currentPhase = initialPhase; - this.chars = Array.from(container.querySelectorAll('.mm-rainbow-char')); - } - - start() { - if (this.intervalId) return; // Already running - - this.intervalId = window.setInterval(() => { - this.update(); - }, 50); // Update every 50ms for smooth animation - } - - stop() { - if (this.intervalId) { - clearInterval(this.intervalId); - this.intervalId = undefined; - } - } - - private update() { - this.chars.forEach((char, i) => { - const baseHue = this.reverse ? 360 - this.currentPhase : this.currentPhase; - const hue = (baseHue + i * 15) % 360; - - char.style.color = `hsl(${hue}, 100%, 60%)`; - }); - - this.currentPhase = (this.currentPhase + 2) % 360; - } - - destroy() { - this.stop(); - this.chars = []; - } -} - -/** - * Initialize all rainbow effects on the page - */ -export function initRainbowEffects(rootElement: HTMLElement = document.body): RainbowEffect[] { - const effects: RainbowEffect[] = []; - const rainbowContainers = rootElement.querySelectorAll('.mm-rainbow'); - - rainbowContainers.forEach((container) => { - const phase = parseFloat(container.getAttribute('data-phase') || '0'); - const reverse = container.getAttribute('data-reverse') === 'true'; - - const effect = new RainbowEffect(container as HTMLElement, phase, reverse); - effect.start(); - effects.push(effect); - }); - - return effects; -} - -/** - * Stop and destroy all rainbow effects - */ -export function destroyRainbowEffects(effects: RainbowEffect[]) { - effects.forEach((effect) => effect.destroy()); -} diff --git a/studio/ui/src/lib/minimessage/effects/transition.ts b/studio/ui/src/lib/minimessage/effects/transition.ts deleted file mode 100644 index 887b40e..0000000 --- a/studio/ui/src/lib/minimessage/effects/transition.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { interpolateGradient } from './gradient'; - -/** - * Transition effect - all characters are the same color, which transitions between colors based on phase - * Unlike gradient which spreads colors across text, transition applies one solid color that changes over time - * - * @param colors Array of hex colors to transition between - * @param phase Phase offset (0 to 1) - determines which color in the sequence - */ -export function applyTransition(text: string, colors: string[], phase: number = 0): string { - if (colors.length === 0) return '#FFFFFF'; - if (colors.length === 1) return colors[0]; - - let normalizedPhase = phase; - if (normalizedPhase < 0) normalizedPhase = 0; - if (normalizedPhase > 1) normalizedPhase = 1; - - const color = interpolateGradient(colors, normalizedPhase, 0); - - return color; -} - -/** - * Apply transition to all characters (returns array of same color repeated) - */ -export function applyTransitionToChars(text: string, colors: string[], phase: number = 0): string[] { - const chars = Array.from(text); - const color = applyTransition(text, colors, phase); - - return chars.map(() => color); -} diff --git a/studio/ui/src/lib/minimessage/index.ts b/studio/ui/src/lib/minimessage/index.ts deleted file mode 100644 index f09187a..0000000 --- a/studio/ui/src/lib/minimessage/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -export { MiniMessageParser } from './parser'; -export { MiniMessageRenderer } from './renderer'; -export { MiniMessageSerializer } from './serializer'; -export { stripMiniMessageTags, escapeMiniMessageText } from './strip'; - -export type { - ASTNode, - RootNode, - TagNode, - TextNode, - TagArguments, - ParserOptions, - ParseResult, - ParseError, - SerializeOptions, - RenderOptions -} from './types'; - -export { interpolateGradient, applyGradient } from './effects/gradient'; -export { applyTransition } from './effects/transition'; - -export { - RainbowEffect, - initRainbowEffects, - destroyRainbowEffects -} from './effects/rainbow.svelte'; -export { - ObfuscationEffect, - initObfuscationEffects, - destroyObfuscationEffects -} from './effects/obfuscation.svelte'; diff --git a/studio/ui/src/lib/minimessage/parser.ts b/studio/ui/src/lib/minimessage/parser.ts deleted file mode 100644 index 3d09aaf..0000000 --- a/studio/ui/src/lib/minimessage/parser.ts +++ /dev/null @@ -1,432 +0,0 @@ -import { - TokenType, - type Token, - type ParserOptions, - type ParseResult, - type RootNode, - type TagNode, - type TextNode, - type ASTNode, - type ParseError -} from './types'; -import { TagRegistry } from './tag-registry'; - -const DEFAULT_OPTIONS: ParserOptions = { - mode: 'lenient', - maxNestingDepth: 50 -}; - -export class MiniMessageParser { - private registry: TagRegistry; - private options: ParserOptions; - - constructor(options: Partial = {}) { - this.registry = new TagRegistry(); - this.options = { ...DEFAULT_OPTIONS, ...options }; - } - - parse(input: string): ParseResult { - const errors: ParseError[] = []; - - try { - const tokens = this.tokenize(input); - const ast = this.buildAST(tokens, errors); - - return { - ast, - errors, - success: errors.every((e) => e.severity !== 'error') - }; - } catch (error) { - errors.push({ - message: error instanceof Error ? error.message : 'Unknown parsing error', - position: 0, - severity: 'error' - }); - - return { - ast: { type: 'root', children: [], start: 0, end: input.length }, - errors, - success: false - }; - } - } - - private tokenize(input: string): Token[] { - const tokens: Token[] = []; - let pos = 0; - let textBuffer = ''; - let textStart = 0; - - const flushText = () => { - if (textBuffer.length > 0) { - tokens.push({ - type: TokenType.TEXT, - value: textBuffer, - position: textStart - }); - textBuffer = ''; - } - }; - - while (pos < input.length) { - const char = input[pos]; - - if (char === '\\' && pos + 1 < input.length) { - const nextChar = input[pos + 1]; - if (nextChar === '<' || nextChar === '>' || nextChar === '\\') { - if (textBuffer.length === 0) textStart = pos; - textBuffer += nextChar; - pos += 2; - continue; - } - } - - if (char === '<') { - flushText(); - - const tagResult = this.parseTag(input, pos); - if (tagResult) { - tokens.push(tagResult.token); - pos = tagResult.newPos; - continue; - } else { - if (textBuffer.length === 0) textStart = pos; - textBuffer += char; - pos++; - } - } else { - if (textBuffer.length === 0) textStart = pos; - textBuffer += char; - pos++; - } - } - - flushText(); - - tokens.push({ - type: TokenType.EOF, - value: '', - position: pos - }); - - return tokens; - } - - private parseTag( - input: string, - startPos: number - ): { token: Token; newPos: number } | null { - let pos = startPos + 1; - - if (pos < input.length && input[pos] === '/') { - pos++; - const closeResult = this.parseTagName(input, pos); - if (!closeResult) return null; - - pos = closeResult.newPos; - while (pos < input.length && (input[pos] === ' ' || input[pos] === '\t')) pos++; - - if (pos >= input.length || input[pos] !== '>') return null; - - return { - token: { - type: TokenType.TAG_CLOSE, - value: closeResult.name, - position: startPos - }, - newPos: pos + 1 - }; - } - - const isNegation = pos < input.length && input[pos] === '!'; - if (isNegation) pos++; - - const nameResult = this.parseTagName(input, pos); - if (!nameResult) return null; - - let tagName = nameResult.name; - pos = nameResult.newPos; - - while (pos < input.length && (input[pos] === ' ' || input[pos] === '\t')) pos++; - - if (pos + 1 < input.length && input[pos] === '/' && input[pos + 1] === '>') { - return { - token: { - type: TokenType.TAG_SELF_CLOSE, - value: tagName, - position: startPos, - args: [] - }, - newPos: pos + 2 - }; - } - - let args: string[] = []; - if (pos < input.length && input[pos] === ':') { - pos++; - const argsResult = this.parseArguments(input, pos); - if (argsResult) { - args = argsResult.args; - pos = argsResult.newPos; - } - } - - while (pos < input.length && (input[pos] === ' ' || input[pos] === '\t')) pos++; - if (pos >= input.length || input[pos] !== '>') return null; - - if (isNegation && args.length === 0) { - args = ['false']; - } - - return { - token: { - type: TokenType.TAG_OPEN, - value: tagName, - position: startPos, - args - }, - newPos: pos + 1 - }; - } - - private parseTagName(input: string, startPos: number): { name: string; newPos: number } | null { - let pos = startPos; - let name = ''; - - while ( - pos < input.length && - /[a-zA-Z0-9_#]/.test(input[pos]) - ) { - name += input[pos]; - pos++; - } - - if (name.length === 0) return null; - - return { name, newPos: pos }; - } - - private parseArguments( - input: string, - startPos: number - ): { args: string[]; newPos: number } | null { - const args: string[] = []; - let pos = startPos; - let currentArg = ''; - let inQuotes = false; - let quoteChar = ''; - - while (pos < input.length) { - const char = input[pos]; - - if (!inQuotes && char === '>') { - if (currentArg.length > 0) { - args.push(currentArg); - } - break; - } - - if ((char === '"' || char === "'") && (pos === startPos || input[pos - 1] !== '\\')) { - if (!inQuotes) { - inQuotes = true; - quoteChar = char; - pos++; - continue; - } else if (char === quoteChar) { - inQuotes = false; - quoteChar = ''; - pos++; - continue; - } - } - - if (!inQuotes && char === ':') { - args.push(currentArg); - currentArg = ''; - pos++; - continue; - } - - if (inQuotes && char === '\\' && pos + 1 < input.length) { - const nextChar = input[pos + 1]; - if (nextChar === quoteChar || nextChar === '\\') { - currentArg += nextChar; - pos += 2; - continue; - } - } - - currentArg += char; - pos++; - } - - return { args, newPos: pos }; - } - - private buildAST(tokens: Token[], errors: ParseError[]): RootNode { - const root: RootNode = { - type: 'root', - children: [], - start: 0, - end: tokens[tokens.length - 1]?.position || 0 - }; - - const stack: TagNode[] = []; - let currentParent: RootNode | TagNode = root; - let depth = 0; - - for (let i = 0; i < tokens.length; i++) { - const token = tokens[i]; - - if (token.type === TokenType.TEXT) { - const textNode: TextNode = { - type: 'text', - content: token.value, - start: token.position, - end: token.position + token.value.length - }; - currentParent.children.push(textNode); - } else if (token.type === TokenType.TAG_OPEN) { - depth++; - if (depth > this.options.maxNestingDepth!) { - errors.push({ - message: `Maximum nesting depth exceeded (${this.options.maxNestingDepth})`, - position: token.position, - severity: 'error' - }); - continue; - } - - const tagDef = this.registry.get(token.value); - if (!tagDef) { - if (this.options.mode === 'strict') { - errors.push({ - message: `Unknown tag: ${token.value}`, - position: token.position, - severity: 'error' - }); - continue; - } else { - const textNode: TextNode = { - type: 'text', - content: `<${token.value}${token.args?.length ? ':' + token.args.join(':') : ''}>`, - start: token.position, - end: token.position - }; - currentParent.children.push(textNode); - depth--; - continue; - } - } - - const argsString = token.args?.join(':') || ''; - const tagArgs = tagDef.parseArgs(argsString); - - const tagNode: TagNode = { - type: 'tag', - tagName: tagDef.name, - args: tagArgs, - children: [], - selfClosing: false, - start: token.position, - end: token.position - }; - - currentParent.children.push(tagNode); - - if (tagDef.canHaveChildren) { - stack.push(tagNode); - currentParent = tagNode; - } else { - depth--; - } - } else if (token.type === TokenType.TAG_CLOSE) { - depth--; - - const matchIndex = this.findMatchingTag(stack, token.value); - - if (matchIndex === -1) { - if (this.options.mode === 'strict') { - errors.push({ - message: `Unmatched closing tag: `, - position: token.position, - severity: 'error' - }); - } - continue; - } - - if (matchIndex < stack.length - 1 && this.options.mode === 'strict') { - errors.push({ - message: `Tag closed out of order: `, - position: token.position, - severity: 'error' - }); - } - - const closedTags = stack.splice(matchIndex); - for (const tag of closedTags) { - tag.end = token.position; - } - - currentParent = stack.length > 0 ? stack[stack.length - 1] : root; - } else if (token.type === TokenType.TAG_SELF_CLOSE) { - const tagDef = this.registry.get(token.value); - if (!tagDef) { - if (this.options.mode === 'strict') { - errors.push({ - message: `Unknown tag: ${token.value}`, - position: token.position, - severity: 'error' - }); - } - continue; - } - - const argsString = token.args?.join(':') || ''; - const tagArgs = tagDef.parseArgs(argsString); - - const tagNode: TagNode = { - type: 'tag', - tagName: tagDef.name, - args: tagArgs, - children: [], - selfClosing: true, - start: token.position, - end: token.position - }; - - currentParent.children.push(tagNode); - } - } - - if (stack.length > 0) { - if (this.options.mode === 'strict') { - for (const tag of stack) { - errors.push({ - message: `Unclosed tag: <${tag.tagName}>`, - position: tag.start, - severity: 'error' - }); - } - } else { - const lastPos = tokens[tokens.length - 1].position; - for (const tag of stack) { - tag.end = lastPos; - } - } - } - - return root; - } - - private findMatchingTag(stack: TagNode[], tagName: string): number { - for (let i = stack.length - 1; i >= 0; i--) { - if (stack[i].tagName.toLowerCase() === tagName.toLowerCase()) { - return i; - } - } - return -1; - } -} diff --git a/studio/ui/src/lib/minimessage/renderer.ts b/studio/ui/src/lib/minimessage/renderer.ts deleted file mode 100644 index bc8f86b..0000000 --- a/studio/ui/src/lib/minimessage/renderer.ts +++ /dev/null @@ -1,334 +0,0 @@ -import type { RootNode, ASTNode, TagNode, TextNode, StyleContext } from './types'; -// Type assertions are used in renderNode and extractText because TypeScript's -// control flow analysis doesn't narrow the discriminated union in all cases -import { applyGradient } from './effects/gradient'; -import { applyTransitionToChars } from './effects/transition'; - -export class MiniMessageRenderer { - render(ast: RootNode): string { - const ctx: StyleContext = { - colors: [], - shadow: false, - shadowColor: undefined, - shadowAlpha: undefined, - decorations: new Set(), - classes: new Set(), - inlineStyles: new Map() - }; - - return this.renderChildren(ast.children, ctx); - } - - private renderChildren(children: ASTNode[], ctx: StyleContext): string { - return children.map((child) => this.renderNode(child, ctx)).join(''); - } - - private renderNode(node: ASTNode, ctx: StyleContext): string { - if (node.type === 'text') { - return this.renderText(node as TextNode, ctx); - } - - if (node.type === 'tag') { - return this.renderTag(node as TagNode, ctx); - } - - if (node.type === 'root') { - return this.renderChildren((node as RootNode).children, ctx); - } - - return ''; - } - - private renderText(node: TextNode, ctx: StyleContext): string { - const text = this.escapeHtml(node.content); - if (text.length === 0) return ''; - - const styles = this.buildStyles(ctx); - const classes = Array.from(ctx.classes).join(' '); - - if (styles || classes) { - const styleAttr = styles ? ` style="${styles}"` : ''; - const classAttr = classes ? ` class="${classes}"` : ''; - return `${text}`; - } - - return text; - } - - private renderTag(node: TagNode, ctx: StyleContext): string { - const newCtx = this.cloneContext(ctx); - - this.applyTagStyles(node, newCtx); - - if (node.args.type === 'reset') { - newCtx.colors = []; - newCtx.shadow = false; - newCtx.shadowColor = undefined; - newCtx.shadowAlpha = undefined; - newCtx.decorations.clear(); - newCtx.classes.clear(); - newCtx.inlineStyles.clear(); - - return this.renderChildren(node.children, newCtx); - } - - if (node.args.type === 'gradient') { - return this.renderGradient(node, newCtx); - } - - if (node.args.type === 'rainbow') { - return this.renderRainbow(node, newCtx); - } - - if (node.args.type === 'transition') { - return this.renderTransition(node, newCtx); - } - - if (newCtx.decorations.has('obfuscated')) { - return this.renderObfuscated(node, newCtx); - } - - return this.renderChildren(node.children, newCtx); - } - - private renderGradient(node: TagNode, ctx: StyleContext): string { - if (node.args.type !== 'gradient') return ''; - - const text = this.extractText(node.children); - if (text.length === 0) return ''; - - const { colors, phase } = node.args; - const charColors = applyGradient(text, colors, phase || 0); - - const chars = Array.from(text); - const spans = chars.map((char, i) => { - const newCtx = this.cloneContext(ctx); - newCtx.colors = [charColors[i]]; - - const styles = this.buildStyles(newCtx); - const classes = Array.from(newCtx.classes).join(' '); - - const escapedChar = this.escapeHtml(char); - const styleAttr = styles ? ` style="${styles}"` : ''; - const classAttr = classes ? ` class="${classes}"` : ''; - - return `${escapedChar}`; - }); - - return spans.join(''); - } - - private renderRainbow(node: TagNode, ctx: StyleContext): string { - if (node.args.type !== 'rainbow') return ''; - - const text = this.extractText(node.children); - if (text.length === 0) return ''; - - const { phase, reverse } = node.args; - const chars = Array.from(text); - - const dataPhase = phase !== undefined ? ` data-phase="${phase}"` : ''; - const dataReverse = reverse ? ' data-reverse="true"' : ''; - - const charSpans = chars.map((char, i) => { - const newCtx = this.cloneContext(ctx); - const styles = this.buildStyles(newCtx); - const classes = Array.from(newCtx.classes).join(' '); - - const escapedChar = this.escapeHtml(char); - const styleAttr = styles ? ` style="${styles}"` : ''; - const classAttr = classes ? ` class="mm-rainbow-char ${classes}"` : ' class="mm-rainbow-char"'; - const dataIndex = ` data-index="${i}"`; - - return `${escapedChar}`; - }); - - return `${charSpans.join('')}`; - } - - private renderTransition(node: TagNode, ctx: StyleContext): string { - if (node.args.type !== 'transition') return ''; - - const text = this.extractText(node.children); - if (text.length === 0) return ''; - - const { colors, phase } = node.args; - const charColors = applyTransitionToChars(text, colors, phase || 0); - - const chars = Array.from(text); - const spans = chars.map((char, i) => { - const newCtx = this.cloneContext(ctx); - newCtx.colors = [charColors[i]]; - - const styles = this.buildStyles(newCtx); - const classes = Array.from(newCtx.classes).join(' '); - - const escapedChar = this.escapeHtml(char); - const styleAttr = styles ? ` style="${styles}"` : ''; - const classAttr = classes ? ` class="${classes}"` : ''; - - return `${escapedChar}`; - }); - - return spans.join(''); - } - - private renderObfuscated(node: TagNode, ctx: StyleContext): string { - const text = this.extractText(node.children); - if (text.length === 0) return ''; - - const chars = Array.from(text); - - const charSpans = chars.map((char) => { - const newCtx = this.cloneContext(ctx); - const styles = this.buildStyles(newCtx); - const classes = Array.from(newCtx.classes).join(' '); - - const escapedChar = this.escapeHtml(char); - const styleAttr = styles ? ` style="${styles}"` : ''; - const classAttr = classes ? ` class="mm-obfuscated-char ${classes}"` : ' class="mm-obfuscated-char"'; - - return `${escapedChar}`; - }); - - return `${charSpans.join('')}`; - } - - private applyTagStyles(node: TagNode, ctx: StyleContext): void { - const args = node.args; - - switch (args.type) { - case 'color': - ctx.colors.push(args.value); - break; - - case 'shadow': - ctx.shadow = args.enabled; - if (args.enabled) { - ctx.shadowColor = args.color; - ctx.shadowAlpha = args.alpha; - } - break; - - case 'decoration': - if (args.state === false) { - ctx.decorations.delete(args.name); - ctx.classes.delete(`mm-${args.name}`); - } else { - ctx.decorations.add(args.name); - ctx.classes.add(`mm-${args.name}`); - } - break; - - case 'click': - case 'hover': - break; - } - } - - private buildStyles(ctx: StyleContext): string { - const styles: string[] = []; - - if (ctx.colors.length > 0) { - const color = ctx.colors[ctx.colors.length - 1]; - styles.push(`color: ${color}`); - } - - if (ctx.shadow) { - const alpha = ctx.shadowAlpha !== undefined ? ctx.shadowAlpha : 1.0; - - let colorStr = ctx.shadowColor; - - if (!colorStr) { - const textColor = ctx.colors.length > 0 ? ctx.colors[ctx.colors.length - 1] : '#FFFFFF'; - colorStr = this.calculateAutoShadowColor(textColor); - } - - const rgb = this.hexToRgba(colorStr, alpha); - styles.push(`text-shadow: 2px 2px ${rgb}`); - } - - for (const [key, value] of ctx.inlineStyles) { - styles.push(`${key}: ${value}`); - } - - return styles.join('; '); - } - - private cloneContext(ctx: StyleContext): StyleContext { - return { - colors: [...ctx.colors], - shadow: ctx.shadow, - shadowColor: ctx.shadowColor, - shadowAlpha: ctx.shadowAlpha, - decorations: new Set(ctx.decorations), - classes: new Set(ctx.classes), - inlineStyles: new Map(ctx.inlineStyles) - }; - } - - private extractText(nodes: ASTNode[]): string { - let text = ''; - - for (const node of nodes) { - if (node.type === 'text') { - text += (node as TextNode).content; - } else if (node.type === 'tag') { - text += this.extractText((node as TagNode).children); - } - } - - return text; - } - - private escapeHtml(text: string): string { - return text - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); - } - - private calculateAutoShadowColor(hex: string): string { - let r = 0; - let g = 0; - let b = 0; - - if (hex.startsWith('#')) { - if (hex.length === 9) { - r = parseInt(hex.substring(1, 3), 16); - g = parseInt(hex.substring(3, 5), 16); - b = parseInt(hex.substring(5, 7), 16); - } else { - r = parseInt(hex.substring(1, 3), 16); - g = parseInt(hex.substring(3, 5), 16); - b = parseInt(hex.substring(5, 7), 16); - } - } else { - return '#333333'; - } - - r = Math.floor(r * 0.25); - g = Math.floor(g * 0.25); - b = Math.floor(b * 0.25); - - const toHex = (n: number) => n.toString(16).padStart(2, '0'); - return `#${toHex(r)}${toHex(g)}${toHex(b)}`; - } - - private hexToRgba(hex: string, alpha: number): string { - if (hex.length === 9) { - const r = parseInt(hex.substring(1, 3), 16); - const g = parseInt(hex.substring(3, 5), 16); - const b = parseInt(hex.substring(5, 7), 16); - const a = parseInt(hex.substring(7, 9), 16) / 255; - return `rgba(${r}, ${g}, ${b}, ${a})`; - } - - const r = parseInt(hex.substring(1, 3), 16); - const g = parseInt(hex.substring(3, 5), 16); - const b = parseInt(hex.substring(5, 7), 16); - return `rgba(${r}, ${g}, ${b}, ${alpha})`; - } -} diff --git a/studio/ui/src/lib/minimessage/serializer.ts b/studio/ui/src/lib/minimessage/serializer.ts deleted file mode 100644 index 20d028c..0000000 --- a/studio/ui/src/lib/minimessage/serializer.ts +++ /dev/null @@ -1,155 +0,0 @@ -import type { RootNode, ASTNode, TagNode, TextNode, SerializeOptions } from './types'; - -const DEFAULT_OPTIONS: SerializeOptions = { - minimize: false, - preferShorthand: true, - indent: false -}; - -export class MiniMessageSerializer { - serialize(ast: RootNode, options: Partial = {}): string { - const opts = { ...DEFAULT_OPTIONS, ...options }; - return this.serializeNode(ast, opts); - } - - private serializeNode(node: ASTNode, opts: SerializeOptions): string { - if (node.type === 'text') { - return this.escapeText((node as TextNode).content); - } - - if (node.type === 'tag') { - return this.serializeTag(node as TagNode, opts); - } - - if (node.type === 'root') { - return (node as RootNode).children.map((child) => this.serializeNode(child, opts)).join(''); - } - - return ''; - } - - private serializeTag(node: TagNode, opts: SerializeOptions): string { - if (node.selfClosing || node.args.type === 'reset') { - const tagName = this.getTagName(node, opts); - return `<${tagName}/>`; - } - - const tagName = this.getTagName(node, opts); - const args = this.serializeArgs(node, opts); - const openTag = args ? `<${tagName}:${args}>` : `<${tagName}>`; - - const children = node.children.map((child) => this.serializeNode(child, opts)).join(''); - - const closeTag = ``; - - if (opts.minimize && children.length === 0) { - return ''; - } - - return `${openTag}${children}${closeTag}`; - } - - private getTagName(node: TagNode, opts: SerializeOptions): string { - const args = node.args; - - if (opts.preferShorthand && args.type === 'color') { - const namedColor = this.getNamedColor(args.value); - if (namedColor) { - return namedColor; - } - } - - return node.tagName; - } - - private serializeArgs(node: TagNode, opts: SerializeOptions): string { - const args = node.args; - - switch (args.type) { - case 'color': - if (!opts.preferShorthand || !this.getNamedColor(args.value)) { - return args.value; - } - return ''; - - case 'shadow': - if (args.color === '#00000000' || args.alpha === 0) { - return ''; // case - } - if (args.alpha !== undefined && args.alpha !== 0.25) { - return `${args.color}:${args.alpha}`; - } - return args.color ?? ''; - - case 'decoration': - if (args.state === false) { - return 'false'; - } - return ''; - - case 'gradient': - const gradientParts = [...args.colors]; - if (args.phase !== undefined) { - gradientParts.push(args.phase.toString()); - } - return gradientParts.join(':'); - - case 'rainbow': - const rainbowParts: string[] = []; - if (args.reverse) { - rainbowParts.push('!'); - } - if (args.phase !== undefined) { - rainbowParts.push(args.phase.toString()); - } - return rainbowParts.join(''); - - case 'transition': - const transitionParts = [...args.colors]; - if (args.phase !== undefined) { - transitionParts.push(args.phase.toString()); - } - return transitionParts.join(':'); - - case 'click': - return `${args.action}:${args.value}`; - - case 'hover': - return `${args.action}:${args.value}`; - - case 'reset': - case 'empty': - return ''; - - default: - return ''; - } - } - - private getNamedColor(hex: string): string | null { - const NAMED_COLORS: Record = { - '#000000': 'black', - '#0000AA': 'dark_blue', - '#00AA00': 'dark_green', - '#00AAAA': 'dark_aqua', - '#AA0000': 'dark_red', - '#AA00AA': 'dark_purple', - '#FFAA00': 'gold', - '#AAAAAA': 'gray', - '#555555': 'dark_gray', - '#5555FF': 'blue', - '#55FF55': 'green', - '#55FFFF': 'aqua', - '#FF5555': 'red', - '#FF55FF': 'light_purple', - '#FFFF55': 'yellow', - '#FFFFFF': 'white' - }; - - return NAMED_COLORS[hex.toUpperCase()] || null; - } - - private escapeText(text: string): string { - return text.replace(/\\/g, '\\\\').replace(//g, '\\>'); - } -} diff --git a/studio/ui/src/lib/minimessage/strip.ts b/studio/ui/src/lib/minimessage/strip.ts deleted file mode 100644 index c98e659..0000000 --- a/studio/ui/src/lib/minimessage/strip.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { MiniMessageParser } from './parser'; -import type { ASTNode, RootNode, TagNode, TextNode } from './types'; - -const parser = new MiniMessageParser(); - -function collectText(node: ASTNode, out: string[]) { - if (node.type === 'text') { - out.push((node as TextNode).content); - return; - } - const children = (node as RootNode | TagNode).children; - if (!children) return; - for (const child of children) collectText(child, out); -} - -/** - * The visible text of a MiniMessage string. Uses the real parser so invalid - * markup (e.g. an unclosed `<`) stays visible as literal text, exactly as it - * renders on the canvas. - */ -export function stripMiniMessageTags(value: string): string { - const out: string[] = []; - collectText(parser.parse(value).ast, out); - return out.join(''); -} - -/** - * Escape plain text so it round-trips through MiniMessage. Mirrors - * MiniMessageSerializer.escapeText: `\` first, then `<` and `>`. - */ -export function escapeMiniMessageText(text: string): string { - return text.replace(/\\/g, '\\\\').replace(//g, '\\>'); -} diff --git a/studio/ui/src/lib/minimessage/tag-registry.ts b/studio/ui/src/lib/minimessage/tag-registry.ts deleted file mode 100644 index 6fae884..0000000 --- a/studio/ui/src/lib/minimessage/tag-registry.ts +++ /dev/null @@ -1,349 +0,0 @@ -import type { TagArguments } from './types'; - - -export interface TagDefinition { - name: string; - aliases?: string[]; - parseArgs: (argString: string) => TagArguments; - canHaveChildren: boolean; - requiresClosing: boolean; // False for self-closing tags like -} - - -const NAMED_COLORS: Record = { - black: '#000000', - dark_blue: '#0000AA', - dark_green: '#00AA00', - dark_aqua: '#00AAAA', - dark_red: '#AA0000', - dark_purple: '#AA00AA', - gold: '#FFAA00', - gray: '#AAAAAA', - grey: '#AAAAAA', - dark_gray: '#555555', - dark_grey: '#555555', - blue: '#5555FF', - green: '#55FF55', - aqua: '#55FFFF', - red: '#FF5555', - light_purple: '#FF55FF', - yellow: '#FFFF55', - white: '#FFFFFF' -}; - - -function parseColorValue(value: string): string { - const normalized = value.toLowerCase().replace(/-/g, '_'); - if (NAMED_COLORS[normalized]) { - return NAMED_COLORS[normalized]; - } - - if (value.startsWith('#')) { - return value; - } - - return '#FFFFFF'; -} - -function parsePhase(phaseStr: string | undefined): number | undefined { - if (!phaseStr) return undefined; - const num = parseFloat(phaseStr); - return isNaN(num) ? undefined : num; -} - - -function parseColorArgs(argString: string): TagArguments { - return { - type: 'color', - value: parseColorValue(argString) - }; -} - -function parseShadowArgs(argString: string): TagArguments { - if (argString === 'false') { - return { - type: 'shadow', - enabled: false - }; - } - - if (!argString) { - return { - type: 'shadow', - enabled: true, - color: undefined, - alpha: 1.0 - }; - } - - const parts = argString.split(':'); - const color = parseColorValue(parts[0]); - const alpha = parts[1] ? parseFloat(parts[1]) : 0.25; - - return { - type: 'shadow', - enabled: true, - color, - alpha: isNaN(alpha) ? 0.25 : alpha - }; -} - -function parseDecorationArgs( - decorationName: 'bold' | 'italic' | 'underlined' | 'strikethrough' | 'obfuscated', - argString: string -): TagArguments { - const state = argString !== 'false'; - - return { - type: 'decoration', - name: decorationName, - state - }; -} - -function parseGradientArgs(argString: string): TagArguments { - if (!argString) { - return { - type: 'gradient', - colors: ['#FFFFFF', '#000000'] - }; - } - - const parts = argString.split(':'); - const colors: string[] = []; - let phase: number | undefined; - - for (const part of parts) { - const num = parseFloat(part); - if (!isNaN(num) && (num >= -1 && num <= 1)) { - phase = num; - } else { - colors.push(parseColorValue(part)); - } - } - - if (colors.length === 0) { - colors.push('#FFFFFF', '#000000'); - } else if (colors.length === 1) { - colors.push('#000000'); - } - - return { - type: 'gradient', - colors, - phase - }; -} - -function parseRainbowArgs(argString: string): TagArguments { - if (!argString) { - return { - type: 'rainbow' - }; - } - - const reverse = argString.startsWith('!'); - const phaseStr = reverse ? argString.slice(1) : argString; - const phase = parsePhase(phaseStr); - - return { - type: 'rainbow', - phase, - reverse - }; -} - -function parseTransitionArgs(argString: string): TagArguments { - if (!argString) { - return { - type: 'transition', - colors: ['#FFFFFF', '#000000'] - }; - } - - const parts = argString.split(':'); - const colors: string[] = []; - let phase: number | undefined; - - for (const part of parts) { - const num = parseFloat(part); - if (!isNaN(num) && num >= -1 && num <= 1) { - phase = num; - } else { - colors.push(parseColorValue(part)); - } - } - - if (colors.length === 0) { - colors.push('#FFFFFF', '#000000'); - } else if (colors.length === 1) { - colors.push('#000000'); - } - - return { - type: 'transition', - colors, - phase - }; -} - -function parseClickArgs(argString: string): TagArguments { - const parts = argString.split(':'); - const action = parts[0] || 'run_command'; - const value = parts.slice(1).join(':') || ''; - - return { - type: 'click', - action, - value - }; -} - -function parseHoverArgs(argString: string): TagArguments { - const parts = argString.split(':'); - const action = parts[0] || 'show_text'; - const value = parts.slice(1).join(':') || ''; - - return { - type: 'hover', - action, - value - }; -} - -function parseEmptyArgs(): TagArguments { - return { type: 'empty' }; -} - -function parseResetArgs(): TagArguments { - return { type: 'reset' }; -} - - -const TAG_DEFINITIONS: TagDefinition[] = [ - ...Object.keys(NAMED_COLORS).map((colorName) => ({ - name: colorName, - parseArgs: () => parseColorArgs(colorName), - canHaveChildren: true, - requiresClosing: true - })), - - { - name: 'color', - aliases: ['c', 'colour'], - parseArgs: parseColorArgs, - canHaveChildren: true, - requiresClosing: true - }, - - { - name: 'shadow', - parseArgs: parseShadowArgs, - canHaveChildren: true, - requiresClosing: true - }, - - { - name: 'bold', - aliases: ['b'], - parseArgs: (args) => parseDecorationArgs('bold', args), - canHaveChildren: true, - requiresClosing: true - }, - { - name: 'italic', - aliases: ['i', 'em'], - parseArgs: (args) => parseDecorationArgs('italic', args), - canHaveChildren: true, - requiresClosing: true - }, - { - name: 'underlined', - aliases: ['u'], - parseArgs: (args) => parseDecorationArgs('underlined', args), - canHaveChildren: true, - requiresClosing: true - }, - { - name: 'strikethrough', - aliases: ['st'], - parseArgs: (args) => parseDecorationArgs('strikethrough', args), - canHaveChildren: true, - requiresClosing: true - }, - { - name: 'obfuscated', - aliases: ['obf'], - parseArgs: (args) => parseDecorationArgs('obfuscated', args), - canHaveChildren: true, - requiresClosing: true - }, - - { - name: 'reset', - parseArgs: parseResetArgs, - canHaveChildren: false, - requiresClosing: false - }, - - { - name: 'gradient', - parseArgs: parseGradientArgs, - canHaveChildren: true, - requiresClosing: true - }, - { - name: 'rainbow', - parseArgs: parseRainbowArgs, - canHaveChildren: true, - requiresClosing: true - }, - { - name: 'transition', - parseArgs: parseTransitionArgs, - canHaveChildren: true, - requiresClosing: true - }, - - { - name: 'click', - parseArgs: parseClickArgs, - canHaveChildren: true, - requiresClosing: true - }, - { - name: 'hover', - parseArgs: parseHoverArgs, - canHaveChildren: true, - requiresClosing: true - } -]; - - -export class TagRegistry { - private tags = new Map(); - - constructor() { - for (const tag of TAG_DEFINITIONS) { - this.register(tag); - } - } - - register(def: TagDefinition): void { - this.tags.set(def.name.toLowerCase(), def); - - if (def.aliases) { - for (const alias of def.aliases) { - this.tags.set(alias.toLowerCase(), def); - } - } - } - - get(name: string): TagDefinition | undefined { - return this.tags.get(name.toLowerCase()); - } - - has(name: string): boolean { - return this.tags.has(name.toLowerCase()); - } -} diff --git a/studio/ui/src/lib/minimessage/types.ts b/studio/ui/src/lib/minimessage/types.ts deleted file mode 100644 index 9da254b..0000000 --- a/studio/ui/src/lib/minimessage/types.ts +++ /dev/null @@ -1,145 +0,0 @@ -export interface ASTNode { - type: 'text' | 'tag' | 'root'; - start: number; - end: number; -} - -export interface RootNode extends ASTNode { - type: 'root'; - children: ASTNode[]; -} - -export interface TextNode extends ASTNode { - type: 'text'; - content: string; -} - -export interface TagNode extends ASTNode { - type: 'tag'; - tagName: string; - args: TagArguments; - children: ASTNode[]; - selfClosing: boolean; -} - -export type TagArguments = - | ColorArgs - | ShadowArgs - | DecorationArgs - | GradientArgs - | RainbowArgs - | TransitionArgs - | ResetArgs - | ClickArgs - | HoverArgs - | EmptyArgs; - -export interface ColorArgs { - type: 'color'; - value: string; // Named color, hex (#RRGGBB), or rgb -} - -export interface ShadowArgs { - type: 'shadow'; - color?: string; // undefined = auto (25% brightness of text color) - alpha?: number; // 0-1, default 1.0 if auto-colored, 0.25 otherwise - enabled: boolean; -} - -export interface DecorationArgs { - type: 'decoration'; - name: 'bold' | 'italic' | 'underlined' | 'strikethrough' | 'obfuscated'; - state?: boolean; // true = enable, false = disable (for syntax) -} - -export interface GradientArgs { - type: 'gradient'; - colors: string[]; - phase?: number; // -1 to 1 -} - -export interface RainbowArgs { - type: 'rainbow'; - phase?: number; - reverse?: boolean; // ! prefix -} - -export interface TransitionArgs { - type: 'transition'; - colors: string[]; - phase?: number; // -1 to 1 -} - -export interface ResetArgs { - type: 'reset'; -} - -export interface ClickArgs { - type: 'click'; - action: string; // open_url, run_command, suggest_command, copy_to_clipboard - value: string; -} - -export interface HoverArgs { - type: 'hover'; - action: string; // show_text, show_item, show_entity - value: string; -} - -export interface EmptyArgs { - type: 'empty'; -} - -export interface ParserOptions { - mode: 'strict' | 'lenient'; - maxNestingDepth?: number; // Default: 50 -} - -export interface ParseResult { - ast: RootNode; - errors: ParseError[]; - success: boolean; -} - -export interface ParseError { - message: string; - position: number; - severity: 'error' | 'warning'; -} - -export enum TokenType { - TEXT = 'TEXT', - TAG_OPEN = 'TAG_OPEN', - TAG_CLOSE = 'TAG_CLOSE', - TAG_SELF_CLOSE = 'TAG_SELF_CLOSE', - EOF = 'EOF' -} - -export interface Token { - type: TokenType; - value: string; - position: number; - args?: string[]; // For tags with arguments -} - -export interface SerializeOptions { - minimize?: boolean; // Remove unnecessary tags - preferShorthand?: boolean; // Use instead of - indent?: boolean; // Pretty-print (not typical for MiniMessage) -} - -export interface RenderOptions { - enableAnimations?: boolean; // Enable rainbow/obfuscation - obfuscationCharset?: string; - obfuscationInterval?: number; // ms between updates -} - -export interface StyleContext { - colors: string[]; // Stack of colors (last = current) - shadow: boolean; - shadowColor?: string; - shadowAlpha?: number; - decorations: Set; - classes: Set; - inlineStyles: Map; -}