mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:09:49 +08:00
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.
39 lines
1.4 KiB
TypeScript
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)
|
|
}
|