Files
DeepTutor/web/lib/geogebra-commands.ts
Bingxi Zhao (Frank) 857a82e74a feat(notes): add block notebooks with inline reviews and linked favorites
Add rich text and learning blocks, media uploads, page trees, and revisioned notebook storage. Present AI suggestions at their target blocks with durable accept and dismiss actions.

Unify saved outputs as Favorites with typed expandable blocks, stable source links, atomic batch insertion, nesting, dragging, and undo/redo.

Validation: 99 frontend tests and 99 backend tests pass in an isolated snapshot, along with TypeScript, scoped ESLint, dependency architecture, and locale parity checks.
2026-10-17 23:15:23 +08:00

39 lines
1.4 KiB
TypeScript

export interface GeoGebraCommandAPI {
evalCommand: (command: string) => boolean
setColor?: (object: string, red: number, green: number, blue: number) => void
setLineThickness?: (object: string, thickness: number) => void
exists?: (object: string) => boolean
}
/** Styling commands have no algebra result; apply their documented API form. */
export function runGeoGebraCommand(api: GeoGebraCommandAPI, command: string): boolean {
const thickness = command.match(/^SetLineThickness\(\s*([^,()]+)\s*,\s*(-?\d+)\s*\)$/i)
if (thickness && api.setLineThickness) {
const value = Number(thickness[2])
const object = thickness[1].trim()
if (value === -1 || (value >= 1 && value <= 13)) {
if (api.exists && !api.exists(object)) return false
api.setLineThickness(object, value)
return true
}
}
const color = command.match(
/^SetColou?r\(\s*([^,()]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i
)
if (color && api.setColor) {
const rgb = color.slice(2).map(Number)
const object = color[1].trim()
if (rgb.every(value => Number.isFinite(value) && value >= 0 && value <= 1)) {
if (api.exists && !api.exists(object)) return false
api.setColor(
object,
Math.round(rgb[0] * 255),
Math.round(rgb[1] * 255),
Math.round(rgb[2] * 255)
)
return true
}
}
return api.evalCommand(command)
}