@spidunno/desmos-types 1.13.3 → 1.13.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1947 @@
1
+ // AUTO-GENERATED by scripts/build-module-types.cjs from index.d.ts. Do not edit by hand.
2
+ // The public Desmos API v1.13 types, as a module.
3
+ //
4
+ // Unlike the default entry points, this declares no globals: `Desmos` exists
5
+ // only where you import it. Use it when the API object is not `window.Desmos`,
6
+ // for example when you load calculator.js into a scope of your own.
7
+
8
+ /// <reference lib="dom" />
9
+
10
+ // ---- types/common.d.ts ----
11
+
12
+ /**
13
+ * Shared primitive types and the observable-property mechanism used throughout
14
+ * the Desmos API.
15
+ */
16
+ declare namespace Desmos {
17
+ /**
18
+ * A LaTeX string in Desmos syntax, e.g. `'y=x^2'` or `'\\sin(x)'`.
19
+ *
20
+ * Remember that backslashes must be escaped in ordinary JS strings
21
+ * (`'\\pi'`), or use `String.raw` (`` String.raw`\pi` ``).
22
+ */
23
+ type Latex = string;
24
+
25
+ /** A CSS hex color such as `'#c74440'`. */
26
+ type HexColor = string;
27
+
28
+ /** A value that may be given either as a number or as LaTeX that evaluates to a number. */
29
+ type NumberOrLatex = number | Latex;
30
+
31
+ /**
32
+ * Identifier of an item in the expressions list. Should be a valid JS
33
+ * property name (letters, numbers and `_`).
34
+ */
35
+ type ExpressionId = string;
36
+
37
+ /**
38
+ * Language codes documented for v1.13. Translations must be requested when
39
+ * loading `calculator.js` (via the `lang` URL parameter) before they can be used;
40
+ * check {@link Desmos.supportedLanguages} at runtime.
41
+ */
42
+ type LanguageCode =
43
+ | 'de'
44
+ | 'en'
45
+ | 'es'
46
+ | 'et'
47
+ | 'fr'
48
+ | 'id'
49
+ | 'it'
50
+ | 'ja'
51
+ | 'ko'
52
+ | 'nl'
53
+ | 'pl'
54
+ | 'pt-BR'
55
+ | 'ru'
56
+ | 'sv-SE'
57
+ | 'th'
58
+ | 'tr'
59
+ | 'vi'
60
+ | 'zh-CN'
61
+ | 'zh-TW'
62
+ // Allow codes added in future patch releases while keeping autocompletion.
63
+ | (string & {});
64
+
65
+ /** Braille code used for input and output on refreshable Braille displays. */
66
+ type BrailleMode = 'nemeth' | 'ueb' | 'none';
67
+
68
+ // ---------------------------------------------------------------------------
69
+ // Observables
70
+ // ---------------------------------------------------------------------------
71
+
72
+ /**
73
+ * A property name accepted by `observe`/`unobserve`, optionally namespaced
74
+ * (`'xAxisLabel.myObserver'`) so individual observers can be removed.
75
+ */
76
+ type ObservableProperty<Props> =
77
+ | Extract<keyof Props, string>
78
+ | `${Extract<keyof Props, string>}.${string}`;
79
+
80
+ /**
81
+ * Called when an observed property changes. Receives the (un-namespaced)
82
+ * property name and the object that owns the property.
83
+ */
84
+ type ObserverCallback<Owner, Props> = (
85
+ propertyName: Extract<keyof Props, string>,
86
+ owner: Owner
87
+ ) => void;
88
+
89
+ /**
90
+ * An object whose properties can be observed for changes. See
91
+ * "Managing Observers" in the Desmos docs.
92
+ *
93
+ * @typeParam Props - the observable properties and their value types.
94
+ */
95
+ interface Observable<Props> {
96
+ /**
97
+ * Register `callback` to run whenever `property` changes. Several
98
+ * observers may be added to one property. Namespace the property
99
+ * (`'prop.name'`) to be able to remove a single observer later.
100
+ */
101
+ observe(property: ObservableProperty<Props>, callback: ObserverCallback<this, Props>): void;
102
+
103
+ /**
104
+ * Remove observers. `'prop'` removes every observer of `prop`;
105
+ * `'prop.name'` removes only the observer registered with that namespace.
106
+ */
107
+ unobserve(property: ObservableProperty<Props>): void;
108
+ }
109
+
110
+ /**
111
+ * An event name accepted by `observeEvent`/`unobserveEvent`, optionally
112
+ * namespaced (`'change.autosave'`).
113
+ */
114
+ type EventName<Name extends string> = Name | `${Name}.${string}`;
115
+ }
116
+ // ---- types/enums.d.ts ----
117
+
118
+ /**
119
+ * Enum-like constant objects exposed on the `Desmos` global, together with
120
+ * the union types of their values.
121
+ */
122
+ declare namespace Desmos {
123
+ // ---------------------------------------------------------------------------
124
+ // Colors
125
+ // ---------------------------------------------------------------------------
126
+
127
+ /** The default color palette. */
128
+ const Colors: {
129
+ /** `#c74440` */
130
+ readonly RED: HexColor;
131
+ /** `#2d70b3` */
132
+ readonly BLUE: HexColor;
133
+ /**
134
+ * `#348543` in the v1.13 bundle. (The documentation lists `#388c46`,
135
+ * which is still the color the calculator cycles through for new items.)
136
+ */
137
+ readonly GREEN: HexColor;
138
+ /** `#fa7e19` */
139
+ readonly ORANGE: HexColor;
140
+ /** `#6042a6` */
141
+ readonly PURPLE: HexColor;
142
+ /** `#000000` */
143
+ readonly BLACK: HexColor;
144
+ };
145
+
146
+ /**
147
+ * A color palette: names mapped to valid CSS colors. Used by the `colors`
148
+ * constructor option and exposed as `calculator.colors`.
149
+ */
150
+ type ColorPalette = Readonly<Record<string, string>>;
151
+
152
+ // ---------------------------------------------------------------------------
153
+ // Styles
154
+ // ---------------------------------------------------------------------------
155
+
156
+ /** Drawing styles for points and curves. */
157
+ const Styles: {
158
+ // Curves
159
+ readonly SOLID: 'SOLID';
160
+ readonly DASHED: 'DASHED';
161
+ readonly DOTTED: 'DOTTED';
162
+ // Points
163
+ readonly POINT: 'POINT';
164
+ readonly OPEN: 'OPEN';
165
+ readonly CROSS: 'CROSS';
166
+ readonly SQUARE: 'SQUARE';
167
+ readonly PLUS: 'PLUS';
168
+ readonly TRIANGLE: 'TRIANGLE';
169
+ readonly DIAMOND: 'DIAMOND';
170
+ readonly STAR: 'STAR';
171
+ };
172
+
173
+ /** A line style for curves and point-list segments. */
174
+ type LineStyle = 'SOLID' | 'DASHED' | 'DOTTED';
175
+
176
+ /** A point style for points and point lists. */
177
+ type PointStyle = 'POINT' | 'OPEN' | 'CROSS' | 'SQUARE' | 'PLUS' | 'TRIANGLE' | 'DIAMOND' | 'STAR';
178
+
179
+ // ---------------------------------------------------------------------------
180
+ // Column modes (deprecated)
181
+ // ---------------------------------------------------------------------------
182
+
183
+ /**
184
+ * @deprecated Since API v1.1, use the boolean `points` and `lines`
185
+ * properties of a table column instead.
186
+ */
187
+ const ColumnModes: {
188
+ readonly POINTS: 'POINTS';
189
+ readonly LINES: 'LINES';
190
+ readonly POINTS_AND_LINES: 'POINTS_AND_LINES';
191
+ };
192
+
193
+ /** @deprecated Use the `points` and `lines` table column properties instead. */
194
+ type ColumnMode = 'POINTS' | 'LINES' | 'POINTS_AND_LINES';
195
+
196
+ // ---------------------------------------------------------------------------
197
+ // Drag modes
198
+ // ---------------------------------------------------------------------------
199
+
200
+ /** Directions in which a point (or table column's points) can be dragged. */
201
+ const DragModes: {
202
+ readonly NONE: 'NONE';
203
+ readonly X: 'X';
204
+ readonly Y: 'Y';
205
+ readonly XY: 'XY';
206
+ /** Use the calculator's normal rules for deciding how a point can move. */
207
+ readonly AUTO: 'AUTO';
208
+ };
209
+
210
+ type DragMode = 'NONE' | 'X' | 'Y' | 'XY' | 'AUTO';
211
+
212
+ // ---------------------------------------------------------------------------
213
+ // Axis arrow modes
214
+ // ---------------------------------------------------------------------------
215
+
216
+ /** Whether arrows are drawn at one or both ends of an axis. */
217
+ const AxisArrowModes: {
218
+ readonly NONE: 'NONE';
219
+ readonly POSITIVE: 'POSITIVE';
220
+ readonly BOTH: 'BOTH';
221
+ };
222
+
223
+ type AxisArrowMode = 'NONE' | 'POSITIVE' | 'BOTH';
224
+
225
+ // ---------------------------------------------------------------------------
226
+ // Font sizes
227
+ // ---------------------------------------------------------------------------
228
+
229
+ /**
230
+ * Predefined values for the `fontSize` option. Any number is accepted;
231
+ * these are conveniences.
232
+ */
233
+ const FontSizes: {
234
+ readonly VERY_SMALL: 9;
235
+ readonly SMALL: 12;
236
+ readonly MEDIUM: 16;
237
+ readonly LARGE: 20;
238
+ readonly VERY_LARGE: 24;
239
+ };
240
+
241
+ // ---------------------------------------------------------------------------
242
+ // Label sizes
243
+ // ---------------------------------------------------------------------------
244
+
245
+ /**
246
+ * Predefined LaTeX values for the `labelSize` expression property.
247
+ *
248
+ * @remarks Undocumented: present in the v1.13 bundle but not in the docs.
249
+ */
250
+ const LabelSizes: {
251
+ readonly SMALL: '0.85';
252
+ readonly MEDIUM: '1';
253
+ readonly LARGE: '1.35';
254
+ };
255
+
256
+ // ---------------------------------------------------------------------------
257
+ // Label orientations
258
+ // ---------------------------------------------------------------------------
259
+
260
+ /**
261
+ * Positions of a point's label relative to the point. The docs list
262
+ * `ABOVE`, `BELOW`, `LEFT`, `RIGHT` and `DEFAULT`; the remaining values
263
+ * exist in the v1.13 bundle but are undocumented.
264
+ */
265
+ const LabelOrientations: {
266
+ /** Let the calculator position the label to keep it legible. */
267
+ readonly DEFAULT: 'default';
268
+ readonly ABOVE: 'above';
269
+ readonly BELOW: 'below';
270
+ readonly LEFT: 'left';
271
+ readonly RIGHT: 'right';
272
+ /** @remarks Undocumented. */
273
+ readonly CENTER: 'center';
274
+ /** @remarks Undocumented. */
275
+ readonly CENTER_AUTO: 'center_auto';
276
+ /** @remarks Undocumented. */
277
+ readonly AUTO_CENTER: 'auto_center';
278
+ /** @remarks Undocumented. */
279
+ readonly ABOVE_LEFT: 'above_left';
280
+ /** @remarks Undocumented. */
281
+ readonly ABOVE_RIGHT: 'above_right';
282
+ /** @remarks Undocumented. */
283
+ readonly ABOVE_AUTO: 'above_auto';
284
+ /** @remarks Undocumented. */
285
+ readonly BELOW_LEFT: 'below_left';
286
+ /** @remarks Undocumented. */
287
+ readonly BELOW_RIGHT: 'below_right';
288
+ /** @remarks Undocumented. */
289
+ readonly BELOW_AUTO: 'below_auto';
290
+ /** @remarks Undocumented. */
291
+ readonly AUTO_LEFT: 'auto_left';
292
+ /** @remarks Undocumented. */
293
+ readonly AUTO_RIGHT: 'auto_right';
294
+ };
295
+
296
+ type LabelOrientation = (typeof LabelOrientations)[keyof typeof LabelOrientations];
297
+ }
298
+ // ---- types/options/graphing.d.ts ----
299
+
300
+ /**
301
+ * Constructor options and settings for the graphing calculator. The geometry
302
+ * tool and the 3D calculator accept the same options.
303
+ */
304
+ declare namespace Desmos {
305
+ /**
306
+ * Custom handling for user-uploaded images. Store `file` somewhere with a
307
+ * public URL, then call `done(null, url)`, or `done(error)` on failure.
308
+ */
309
+ type ImageUploadCallback = (file: File, done: ImageUploadDone) => void;
310
+
311
+ /** The completion callback passed to an {@link ImageUploadCallback}. */
312
+ interface ImageUploadDone {
313
+ (error: null | undefined, url: string): void;
314
+ /** Any truthy value signals an error (the docs' example passes `true`). */
315
+ (error: unknown): void;
316
+ }
317
+
318
+ /**
319
+ * Configuration options. These belong to the calculator instance: they are
320
+ * not serialized in graph states and survive `setState()` / `setBlank()`.
321
+ */
322
+ interface GraphingCalculatorConfig {
323
+ /** Show the graphpaper. @defaultValue `true` */
324
+ graphpaper?: boolean;
325
+ /** Show the expressions list. @defaultValue `true` */
326
+ expressions?: boolean;
327
+ /** Show the settings wrench for changing graph display. @defaultValue `true` */
328
+ settingsMenu?: boolean;
329
+ /** Show onscreen zoom buttons. @defaultValue `true` */
330
+ zoomButtons?: boolean;
331
+ /** Show the onscreen keypad. @defaultValue `true` */
332
+ keypad?: boolean;
333
+ /**
334
+ * When `true`, the onscreen keypad opens whenever focus is in a math input.
335
+ * Ignored on touch devices, where the keypad is always activated.
336
+ * @defaultValue `false`
337
+ */
338
+ keypadActivated?: boolean;
339
+ /** If a default state is set, show an onscreen reset button. @defaultValue `false` */
340
+ showResetButtonOnGraphpaper?: boolean;
341
+ /** Show the bar on top of the expressions list. @defaultValue `true` */
342
+ expressionsTopbar?: boolean;
343
+ /** Show Points of Interest as clickable gray dots. @defaultValue `true` */
344
+ pointsOfInterest?: boolean;
345
+ /** Allow tracing curves and showing point coordinates on click. @defaultValue `true` */
346
+ trace?: boolean;
347
+ /** Add a subtle 1px gray border around the calculator. @defaultValue `true` */
348
+ border?: boolean;
349
+ /** Disable user panning and zooming of the graphpaper. @defaultValue `false` */
350
+ lockViewport?: boolean;
351
+ /** Collapse the expressions list. @defaultValue `false` */
352
+ expressionsCollapsed?: boolean;
353
+ /** Limit expressions to 500 LaTeX tokens and a nesting depth of 30. @defaultValue `false` */
354
+ capExpressionSize?: boolean;
355
+ /** Enable content-authoring features (secret folders, readonly expressions, ...). @defaultValue `false` */
356
+ authorFeatures?: boolean;
357
+ /** Allow adding images. @defaultValue `true` */
358
+ images?: boolean;
359
+ /** Custom processing for user-uploaded images. @defaultValue {@link Desmos.imageFileToDataURL} */
360
+ imageUploadCallback?: ImageUploadCallback;
361
+ /** Allow folders in the expressions list. @defaultValue `true` */
362
+ folders?: boolean;
363
+ /** Allow text notes in the expressions list. @defaultValue `true` */
364
+ notes?: boolean;
365
+ /** Allow sliders in the expressions list. @defaultValue `true` */
366
+ sliders?: boolean;
367
+ /**
368
+ * Allow Actions. With `'auto'`, actions are enabled but some UI only
369
+ * appears after the user enters a valid action.
370
+ * @defaultValue `'auto'`
371
+ */
372
+ actions?: boolean | 'auto';
373
+ /**
374
+ * Allow "with" substitutions and list comprehensions. Accepted as an option
375
+ * but not reflected on `calculator.settings`.
376
+ * @defaultValue `true`
377
+ */
378
+ substitutions?: boolean;
379
+ /** Allow hyperlinks in notes/folders and links to help documentation. @defaultValue `true` */
380
+ links?: boolean;
381
+ /** Show the keypad in QWERTY layout (`false` is alphabetical). @defaultValue `true` */
382
+ qwertyKeyboard?: boolean;
383
+ /** Enable distributions, univariate data visualizations and hypothesis tests. @defaultValue `true` */
384
+ distributions?: boolean;
385
+ /** Show a restricted menu of available functions. @defaultValue `false` */
386
+ restrictedFunctions?: boolean;
387
+ /** Keep `distance` and `midpoint` enabled even when `restrictedFunctions` is `true`. @defaultValue `false` */
388
+ forceEnableGeometryFunctions?: boolean;
389
+ /** When `false`, derivatives and integrals are disabled. @defaultValue `true` */
390
+ calculus?: boolean;
391
+ /** Import a graph when the user pastes a valid Desmos graph URL. @defaultValue `false` */
392
+ pasteGraphLink?: boolean;
393
+ /**
394
+ * Pause animations behind an opt-in cover when the user prefers reduced motion.
395
+ * @defaultValue `false`
396
+ */
397
+ showReducedMotionCover?: boolean;
398
+ /** Create a table (up to 50 rows) from pasted table data. @defaultValue `true` */
399
+ pasteTableData?: boolean;
400
+ /**
401
+ * When `true`, clearing the graph leaves the calculator in degree mode.
402
+ * @defaultValue matches `degreeMode` at instantiation
403
+ */
404
+ clearIntoDegreeMode?: boolean;
405
+ /** The color palette the calculator cycles through. @defaultValue {@link Desmos.Colors} */
406
+ colors?: ColorPalette;
407
+ /**
408
+ * Resize automatically when the container element's dimensions change.
409
+ * When `false`, call `.resize()` yourself.
410
+ * @defaultValue `true`
411
+ */
412
+ autosize?: boolean;
413
+ /** Plot inequalities. @defaultValue `true` */
414
+ plotInequalities?: boolean;
415
+ /** Plot implicit equations and inequalities. @defaultValue `true` */
416
+ plotImplicits?: boolean;
417
+ /** Plot single-variable implicit equations. @defaultValue `true` */
418
+ plotSingleVariableImplicitEquations?: boolean;
419
+ /** Increase font sizes and line thicknesses for legibility. @defaultValue `false` */
420
+ projectorMode?: boolean;
421
+ /** Let users toggle between decimal and fraction output. @defaultValue `true` */
422
+ decimalToFraction?: boolean;
423
+ /** Base font size in pixels. See {@link Desmos.FontSizes}. @defaultValue `16` */
424
+ fontSize?: number;
425
+ /**
426
+ * How touch and scroll gestures over the graphpaper are handled.
427
+ * `'cooperative'` requires a modifier or two fingers to pan/zoom.
428
+ * @defaultValue `'greedy'`
429
+ */
430
+ gestureHandling?: 'greedy' | 'cooperative';
431
+ /** Invert every displayed color. No longer recommended. @defaultValue `false` */
432
+ invertedColors?: boolean;
433
+ /** When `false`, hide the "Reverse Contrast" checkbox. @defaultValue `true` */
434
+ invertedColorsControl?: boolean;
435
+ /** **Beta.** Background color as a 3- or 6-digit hex string. @defaultValue `'#fff'` */
436
+ backgroundColor?: HexColor;
437
+ /** **Beta.** Text color as a 3- or 6-digit hex string. @defaultValue `'#000'` */
438
+ textColor?: HexColor;
439
+ /** **Beta.** Accent color for interactive UI elements. @defaultValue `'#2f72dc'` */
440
+ accentColor?: HexColor;
441
+ /** Display language. @defaultValue `'en'` */
442
+ language?: LanguageCode;
443
+ /** Braille code for input and output. @defaultValue `'none'` */
444
+ brailleMode?: BrailleMode;
445
+ /** Allow six-key Braille input on the home row. Requires a Braille mode. @defaultValue `false` */
446
+ sixKeyInput?: boolean;
447
+ /** Show Braille controls in the settings menu and enable Braille shortcut keys. @defaultValue `true` */
448
+ brailleControls?: boolean;
449
+ /** Allow the calculator to produce sound (tones, Audio Trace). @defaultValue `true` */
450
+ audio?: boolean;
451
+ /**
452
+ * Replace the generated description of the graph canvas. `''` removes it;
453
+ * `undefined` restores the generated text.
454
+ * @defaultValue `undefined`
455
+ */
456
+ graphDescription?: string | undefined;
457
+ /** Show a "zoom to fit" icon on tables and distributions. @defaultValue `true` */
458
+ zoomFit?: boolean;
459
+ /** Force log mode on linearizable regressions and hide its checkbox. @defaultValue `false` */
460
+ forceLogModeRegressions?: boolean;
461
+ /** Enable log mode on linearizable regressions by default. @defaultValue `false` */
462
+ defaultLogModeRegressions?: boolean;
463
+ /** Allow arbitrary regression models. @defaultValue `true` */
464
+ customRegressions?: boolean;
465
+ /**
466
+ * Allow regressions from a menu of models in the table column interface.
467
+ * Accepted as an option but not reflected on `calculator.settings`.
468
+ * @defaultValue `true`
469
+ */
470
+ regressionTemplates?: boolean;
471
+ /** Allow logarithmic axis scales. @defaultValue `true` */
472
+ logScales?: boolean;
473
+ /** Enable the `tone` command. @defaultValue `true` */
474
+ tone?: boolean;
475
+ /**
476
+ * Enable interval comprehension syntax. Accepted as an option but not
477
+ * reflected on `calculator.settings`.
478
+ * @defaultValue `true`
479
+ */
480
+ intervalComprehensions?: boolean;
481
+ /**
482
+ * Globally mute sound from `tone()`. Browsers block audio before user
483
+ * interaction, so unmute only in response to a user action.
484
+ * @defaultValue `true`
485
+ */
486
+ muted?: boolean;
487
+ /** Enable the "Complex Mode" toggle in the settings menu. @defaultValue `true` */
488
+ allowComplex?: boolean;
489
+ /** Allow matrices and matrix functions. @defaultValue `true` */
490
+ matrices?: boolean;
491
+ /**
492
+ * How object positions are reported to screen readers. `'default'` uses
493
+ * coordinates when an axis is visible, percentages otherwise.
494
+ * @defaultValue `'default'`
495
+ */
496
+ reportPosition?: 'coordinates' | 'percents' | 'default';
497
+ /** Show a button that copies an evaluation's LaTeX. @defaultValue `false` */
498
+ showEvaluationCopyButtons?: boolean;
499
+ /**
500
+ * Called with the evaluation LaTeX when a copy button is clicked.
501
+ * @defaultValue copy to the system clipboard
502
+ */
503
+ onEvaluationCopyClick?: (latex: Latex) => void;
504
+ /**
505
+ * Allow recursive functions. Accepted as an option but not reflected on
506
+ * `calculator.settings`.
507
+ * @defaultValue `true`
508
+ */
509
+ recursion?: boolean;
510
+ }
511
+
512
+ /**
513
+ * Graph settings. Unlike configuration options, these belong to the graph
514
+ * state: they are serialized by `getState()` and overwritten by
515
+ * `setState()` / `setBlank()`.
516
+ */
517
+ interface GraphSettings {
518
+ /** Trig functions take degrees instead of radians. @defaultValue `false` */
519
+ degreeMode?: boolean;
520
+ /** Show grid lines. @defaultValue `true` */
521
+ showGrid?: boolean;
522
+ /** Use a polar grid instead of a cartesian one. @defaultValue `false` */
523
+ polarMode?: boolean;
524
+ /** Show the x axis. @defaultValue `true` */
525
+ showXAxis?: boolean;
526
+ /** Show the y axis. @defaultValue `true` */
527
+ showYAxis?: boolean;
528
+ /** Show numeric tick labels on the x axis. @defaultValue `true` */
529
+ xAxisNumbers?: boolean;
530
+ /** Show numeric tick labels on the y axis. @defaultValue `true` */
531
+ yAxisNumbers?: boolean;
532
+ /** Show numeric tick labels at successive angles (polar mode only). @defaultValue `true` */
533
+ polarNumbers?: boolean;
534
+ /** Spacing between x-axis ticks. `0` chooses automatically. @defaultValue `0` */
535
+ xAxisStep?: number;
536
+ /** Spacing between y-axis ticks. `0` chooses automatically. @defaultValue `0` */
537
+ yAxisStep?: number;
538
+ /**
539
+ * Subdivisions between x-axis ticks, an integer from 0 to 5. `1` shows only
540
+ * major grid lines; `0` chooses automatically.
541
+ * @defaultValue `0`
542
+ */
543
+ xAxisMinorSubdivisions?: number;
544
+ /**
545
+ * Subdivisions between y-axis ticks, an integer from 0 to 5. `1` shows only
546
+ * major grid lines; `0` chooses automatically.
547
+ * @defaultValue `0`
548
+ */
549
+ yAxisMinorSubdivisions?: number;
550
+ /** Arrows on the x axis. @defaultValue `'NONE'` */
551
+ xAxisArrowMode?: AxisArrowMode;
552
+ /** Arrows on the y axis. @defaultValue `'NONE'` */
553
+ yAxisArrowMode?: AxisArrowMode;
554
+ /** Label placed below the x axis. @defaultValue `''` */
555
+ xAxisLabel?: string;
556
+ /** Label placed beside the y axis. @defaultValue `''` */
557
+ yAxisLabel?: string;
558
+ /** Scale of the x axis. @defaultValue `'linear'` */
559
+ xAxisScale?: AxisScale;
560
+ /** Scale of the y axis. @defaultValue `'linear'` */
561
+ yAxisScale?: AxisScale;
562
+ /**
563
+ * Global seed for the built-in `random()` function. Changing it
564
+ * re-randomizes every expression that uses `random()`.
565
+ * @defaultValue a random 128-bit hex string
566
+ */
567
+ randomSeed?: string;
568
+ }
569
+
570
+ type AxisScale = 'linear' | 'logarithmic';
571
+
572
+ /** Everything that can be passed to the `GraphingCalculator` constructor or `updateSettings()`. */
573
+ interface GraphingCalculatorOptions extends GraphingCalculatorConfig, GraphSettings {}
574
+
575
+ /** Options for `Desmos.Geometry`. Any graphing calculator option is accepted. */
576
+ type GeometryOptions = GraphingCalculatorOptions;
577
+
578
+ /** Options for `Desmos.Calculator3D`. Any graphing calculator option is accepted. */
579
+ type Calculator3DOptions = GraphingCalculatorOptions;
580
+
581
+ /** Options that are accepted but never appear on `calculator.settings`. */
582
+ type WriteOnlyGraphingOption =
583
+ | 'substitutions'
584
+ | 'regressionTemplates'
585
+ | 'intervalComprehensions'
586
+ | 'recursion';
587
+
588
+ /**
589
+ * Settings present on `calculator.settings` at runtime that the docs don't
590
+ * mention. They are read-only here because their behavior when set is not
591
+ * part of the public API.
592
+ *
593
+ * @remarks Undocumented: may change without notice.
594
+ */
595
+ interface UndocumentedGraphingSettings {
596
+ /** Whether Complex Mode is currently on. */
597
+ readonly complex: boolean;
598
+ readonly functionDefinition: boolean;
599
+ readonly restrictGridToFirstQuadrant: boolean;
600
+ readonly userLockedViewport: boolean;
601
+ readonly authorMode: boolean;
602
+ readonly advancedStyling: boolean;
603
+ readonly leftAlign3dViewportControls: boolean;
604
+ readonly translucentSurfaces: boolean;
605
+ readonly showKeyboardShortcutsInTooltips: boolean;
606
+ readonly showPerformanceMeter: boolean;
607
+ }
608
+
609
+ /** The current value of every documented option and graph setting. */
610
+ type GraphingCalculatorSettingsValues = {
611
+ readonly [K in Exclude<keyof GraphingCalculatorOptions, WriteOnlyGraphingOption | 'graphDescription'>]-?: NonNullable<
612
+ GraphingCalculatorOptions[K]
613
+ >;
614
+ } & {
615
+ readonly graphDescription: string | undefined;
616
+ } & UndocumentedGraphingSettings;
617
+
618
+ /**
619
+ * `calculator.settings`: the current settings, observable per property.
620
+ * Change them with `calculator.updateSettings()`.
621
+ *
622
+ * @example
623
+ * calculator.settings.observe('xAxisLabel', () => {
624
+ * console.log(calculator.settings.xAxisLabel);
625
+ * });
626
+ */
627
+ type GraphingCalculatorSettings = GraphingCalculatorSettingsValues & Observable<GraphingCalculatorSettingsValues>;
628
+ }
629
+ // ---- types/options/basic.d.ts ----
630
+
631
+ /**
632
+ * Constructor options and settings for the four-function and scientific
633
+ * calculators.
634
+ */
635
+ declare namespace Desmos {
636
+ /** Options shared by the four-function and scientific calculators. */
637
+ interface BasicCalculatorOptions {
638
+ /** Allow external hyperlinks (e.g. to Braille examples). @defaultValue `true` */
639
+ links?: boolean;
640
+ /** Base font size in pixels. @defaultValue `16` */
641
+ fontSize?: number;
642
+ /** Display an inverted color scheme. @defaultValue `false` */
643
+ invertedColors?: boolean;
644
+ /** When `false`, hide the "Reverse Contrast" checkbox. @defaultValue `true` */
645
+ invertedColorsControl?: boolean;
646
+ /** **Beta.** Background color as a 3- or 6-digit hex string. @defaultValue `'#fff'` */
647
+ backgroundColor?: HexColor;
648
+ /** **Beta.** Text color as a 3- or 6-digit hex string. @defaultValue `'#000'` */
649
+ textColor?: HexColor;
650
+ /** **Beta.** Accent color for interactive UI elements. @defaultValue `'#2f72dc'` */
651
+ accentColor?: HexColor;
652
+ /** Display the settings menu. @defaultValue `true` */
653
+ settingsMenu?: boolean;
654
+ /** Display language. @defaultValue `'en'` */
655
+ language?: LanguageCode;
656
+ /** Braille code for input and output. @defaultValue `'none'` */
657
+ brailleMode?: BrailleMode;
658
+ /** Allow six-key Braille input on the home row. Requires a Braille mode. @defaultValue `false` */
659
+ sixKeyInput?: boolean;
660
+ /** Let the user export a Braille rendering of the expression list. Requires a Braille mode. @defaultValue `true` */
661
+ brailleExpressionDownload?: boolean;
662
+ /** Display a larger font. @defaultValue `false` */
663
+ projectorMode?: boolean;
664
+ /**
665
+ * Let users toggle between decimal and fraction output.
666
+ * @defaultValue `false` (four-function), `true` (scientific)
667
+ */
668
+ decimalToFraction?: boolean;
669
+ /** Limit expressions to 500 LaTeX tokens and a nesting depth of 30. @defaultValue `false` */
670
+ capExpressionSize?: boolean;
671
+ }
672
+
673
+ /** An extra function button for the four-function calculator's top bar. */
674
+ type FourFunctionAdditionalFunction = 'exponent' | 'percent' | 'fraction' | 'sqrt';
675
+
676
+ interface FourFunctionCalculatorOptions extends BasicCalculatorOptions {
677
+ /**
678
+ * Extra function(s) shown in the top bar: at least 1, at most 2.
679
+ * @defaultValue `['sqrt']`
680
+ */
681
+ additionalFunctions?:
682
+ | FourFunctionAdditionalFunction
683
+ | readonly [FourFunctionAdditionalFunction]
684
+ | readonly [FourFunctionAdditionalFunction, FourFunctionAdditionalFunction];
685
+ /**
686
+ * Require numbers to be `0` or have magnitude in `[1e-7, 1e8)`; anything
687
+ * else is an error. Results never use scientific notation.
688
+ * @defaultValue `false`
689
+ */
690
+ limitNumberScale?: boolean;
691
+ }
692
+
693
+ interface ScientificCalculatorOptions extends BasicCalculatorOptions {
694
+ /** Show the keypad in QWERTY layout (`false` is alphabetical). @defaultValue `true` */
695
+ qwertyKeyboard?: boolean;
696
+ /** Trig functions take degrees instead of radians. @defaultValue `false` */
697
+ degreeMode?: boolean;
698
+ /** Allow function definitions such as `f(x) = 2x`. @defaultValue `true` */
699
+ functionDefinition?: boolean;
700
+ /**
701
+ * Resize automatically when the container element's dimensions change.
702
+ * When `false`, call `.resize()` yourself.
703
+ * @defaultValue `true`
704
+ */
705
+ autosize?: boolean;
706
+ /** Enable the "Complex Mode" toggle in the settings menu. @defaultValue `true` */
707
+ allowComplex?: boolean;
708
+ }
709
+
710
+ /**
711
+ * Option keys accepted by a basic calculator but not kept on its
712
+ * `settings` object at runtime.
713
+ */
714
+ type WriteOnlyBasicOption = 'additionalFunctions' | 'limitNumberScale' | 'autosize' | 'allowComplex';
715
+
716
+ /** The current value of each option of a basic calculator. */
717
+ type BasicCalculatorSettingsValues<TOptions extends BasicCalculatorOptions> = {
718
+ readonly [K in Exclude<keyof TOptions, WriteOnlyBasicOption>]-?: NonNullable<TOptions[K]>;
719
+ };
720
+
721
+ /**
722
+ * `calculator.settings` on a basic calculator: current settings, observable
723
+ * per property.
724
+ *
725
+ * @remarks Undocumented for basic calculators, but present at runtime.
726
+ */
727
+ type BasicCalculatorSettings<TOptions extends BasicCalculatorOptions> = BasicCalculatorSettingsValues<TOptions> &
728
+ Observable<BasicCalculatorSettingsValues<TOptions>>;
729
+ }
730
+ // ---- types/expressions.d.ts ----
731
+
732
+ /**
733
+ * Expression-list items: what `setExpression()` accepts, what
734
+ * `getExpressions()` returns, and the per-expression analysis.
735
+ */
736
+ declare namespace Desmos {
737
+ /** Bounds as LaTeX strings (numbers are coerced to strings). */
738
+ interface Domain {
739
+ min?: NumberOrLatex;
740
+ max?: NumberOrLatex;
741
+ }
742
+
743
+ /**
744
+ * Slider bounds. Bounds may use numbers and the constants `e`, `\pi` and
745
+ * `\tau`, but not variables. Omit `step` (or pass `''`) for a continuous slider.
746
+ */
747
+ interface SliderBounds extends Domain {
748
+ step?: NumberOrLatex;
749
+ }
750
+
751
+ // ---------------------------------------------------------------------------
752
+ // setExpression() input
753
+ // ---------------------------------------------------------------------------
754
+
755
+ /**
756
+ * A math expression. When `id` matches an existing expression, only the
757
+ * provided properties change; the rest are left as they were.
758
+ */
759
+ interface ExpressionState {
760
+ type?: 'expression';
761
+ id?: ExpressionId;
762
+ /** The expression, in Desmos LaTeX. */
763
+ latex?: Latex;
764
+ /** Defaults to cycling through the palette. */
765
+ color?: HexColor;
766
+ /** Line style for curves or point lists. */
767
+ lineStyle?: LineStyle;
768
+ /** Line width in pixels: a positive number or LaTeX evaluating to one. @defaultValue `2.5` */
769
+ lineWidth?: NumberOrLatex;
770
+ /** Line opacity from 0 to 1, or LaTeX evaluating to one. @defaultValue `0.9` */
771
+ lineOpacity?: NumberOrLatex;
772
+ /** Point style for points and point lists. */
773
+ pointStyle?: PointStyle;
774
+ /** Point diameter in pixels: a positive number or LaTeX evaluating to one. @defaultValue `9` */
775
+ pointSize?: NumberOrLatex;
776
+ /** Point opacity from 0 to 1, or LaTeX evaluating to one. @defaultValue `0.9` */
777
+ pointOpacity?: NumberOrLatex;
778
+ /** Draw a white outline around points to separate them from overlapping items. */
779
+ pointOutline?: boolean;
780
+ /** Fill opacity of a polygon or parametric curve, 0 to 1. @defaultValue `0.4` */
781
+ fillOpacity?: NumberOrLatex;
782
+ /** Plot points for point lists. */
783
+ points?: boolean;
784
+ /** Plot line segments for point lists. */
785
+ lines?: boolean;
786
+ /** Shade the interior of a polygon or parametric curve. */
787
+ fill?: boolean;
788
+ /** Don't draw the graph. @defaultValue `false` */
789
+ hidden?: boolean;
790
+ /** Hide the expression from the expressions list; doesn't affect the graph. @defaultValue `false` */
791
+ secret?: boolean;
792
+ /** Bounds of a slider. */
793
+ sliderBounds?: SliderBounds;
794
+ /** Animate the slider. @defaultValue `false` */
795
+ playing?: boolean;
796
+ /** Bounds of a parametric curve. */
797
+ parametricDomain?: Domain;
798
+ /** Bounds of a polar curve. */
799
+ polarDomain?: Domain;
800
+ /** How a point can be dragged. @defaultValue `'AUTO'` */
801
+ dragMode?: DragMode;
802
+ /** Text label of a point. `''` restores the default label (its coordinates). */
803
+ label?: string;
804
+ /** Show the point's label. */
805
+ showLabel?: boolean;
806
+ /**
807
+ * Label size as LaTeX, multiplying the standard label font size. See
808
+ * {@link Desmos.LabelSizes}.
809
+ * @defaultValue `'1'`
810
+ */
811
+ labelSize?: Latex;
812
+ /** Where the label sits relative to the point. @defaultValue `'default'` */
813
+ labelOrientation?: LabelOrientation;
814
+ /** Prevent the user from editing or deleting the expression (author feature). */
815
+ readonly?: boolean;
816
+ }
817
+
818
+ /** A column of a table. */
819
+ interface TableColumnState {
820
+ /** Column header: a variable, or an expression for computed columns. */
821
+ latex: Latex;
822
+ /** Cell values as LaTeX. Not needed for computed columns. */
823
+ values?: Latex[];
824
+ /** Ignored for the first column. */
825
+ color?: HexColor;
826
+ /** Ignored for the first column. @defaultValue `false` */
827
+ hidden?: boolean;
828
+ points?: boolean;
829
+ lines?: boolean;
830
+ lineStyle?: LineStyle;
831
+ /** @defaultValue `2.5` */
832
+ lineWidth?: NumberOrLatex;
833
+ /** @defaultValue `0.9` */
834
+ lineOpacity?: NumberOrLatex;
835
+ pointStyle?: PointStyle;
836
+ /** @defaultValue `9` */
837
+ pointSize?: NumberOrLatex;
838
+ /** @defaultValue `0.9` */
839
+ pointOpacity?: NumberOrLatex;
840
+ /** @deprecated Use `points` and `lines` instead. */
841
+ columnMode?: ColumnMode;
842
+ /** Only affects explicitly specified values, not computed ones. @defaultValue `'NONE'` */
843
+ dragMode?: DragMode;
844
+ }
845
+
846
+ interface TableState {
847
+ type: 'table';
848
+ id?: ExpressionId;
849
+ columns: TableColumnState[];
850
+ }
851
+
852
+ /** A text note. */
853
+ interface NoteState {
854
+ type: 'text';
855
+ id?: ExpressionId;
856
+ /** @defaultValue `''` */
857
+ text?: string;
858
+ }
859
+
860
+ /** Anything accepted by `setExpression()`. */
861
+ type SettableExpressionState = ExpressionState | TableState | NoteState;
862
+
863
+ // ---------------------------------------------------------------------------
864
+ // getExpressions() output
865
+ // ---------------------------------------------------------------------------
866
+
867
+ /** Bounds as returned by `getExpressions()`: `''` means "use the default". */
868
+ interface DomainItem {
869
+ min: Latex;
870
+ max: Latex;
871
+ }
872
+
873
+ /**
874
+ * An expression as returned by `getExpressions()`. Numeric styling values
875
+ * come back as LaTeX strings, with `''` meaning "use the default".
876
+ */
877
+ interface ExpressionItem {
878
+ type: 'expression';
879
+ id: ExpressionId;
880
+ latex: Latex;
881
+ color: HexColor;
882
+ lineStyle: LineStyle;
883
+ lineWidth: Latex;
884
+ lineOpacity: Latex;
885
+ pointStyle: PointStyle;
886
+ pointSize: Latex;
887
+ movablePointSize: Latex;
888
+ pointOpacity: Latex;
889
+ pointOutline?: boolean;
890
+ fillOpacity: Latex;
891
+ points?: boolean;
892
+ lines?: boolean;
893
+ fill?: boolean;
894
+ hidden: boolean;
895
+ secret: boolean;
896
+ dragMode: DragMode;
897
+ label: string;
898
+ showLabel: boolean;
899
+ labelSize: Latex;
900
+ labelOrientation: LabelOrientation;
901
+ interactiveLabel: boolean;
902
+ readonly: boolean;
903
+ /** Present only for sliders; omitted bounds were not set. */
904
+ sliderBounds?: { min?: Latex; max?: Latex; step?: Latex };
905
+ playing: boolean;
906
+ parametricDomain: DomainItem;
907
+ parametricDomain3Du: DomainItem;
908
+ parametricDomain3Dv: DomainItem;
909
+ parametricDomain3Dr: DomainItem;
910
+ parametricDomain3Dphi: DomainItem;
911
+ polarDomain: DomainItem;
912
+ domain: DomainItem;
913
+ }
914
+
915
+ interface TableColumnItem {
916
+ id: ExpressionId;
917
+ latex: Latex;
918
+ values: Latex[];
919
+ color: HexColor;
920
+ hidden: boolean;
921
+ points: boolean;
922
+ lines: boolean;
923
+ lineStyle: LineStyle;
924
+ lineWidth: Latex;
925
+ lineOpacity: Latex;
926
+ pointStyle: PointStyle;
927
+ pointOutline: boolean;
928
+ pointSize: Latex;
929
+ pointOpacity: Latex;
930
+ dragMode: DragMode;
931
+ }
932
+
933
+ interface TableItem {
934
+ type: 'table';
935
+ id: ExpressionId;
936
+ columns: TableColumnItem[];
937
+ }
938
+
939
+ interface NoteItem {
940
+ type: 'text';
941
+ id: ExpressionId;
942
+ text: string;
943
+ secret: boolean;
944
+ }
945
+
946
+ /**
947
+ * A folder. Cannot be created with `setExpression()`; folders come from
948
+ * the user or from `setState()`.
949
+ */
950
+ interface FolderItem {
951
+ type: 'folder';
952
+ id: ExpressionId;
953
+ title: string;
954
+ hidden: boolean;
955
+ secret: boolean;
956
+ }
957
+
958
+ /**
959
+ * An image. Only its identity and visibility are reported. Cannot be
960
+ * created with `setExpression()`.
961
+ */
962
+ interface ImageItem {
963
+ type: 'image';
964
+ id: ExpressionId;
965
+ hidden: boolean;
966
+ secret: boolean;
967
+ }
968
+
969
+ /** Any item returned by `getExpressions()`. */
970
+ type ExpressionListItem = ExpressionItem | TableItem | NoteItem | FolderItem | ImageItem;
971
+
972
+ // ---------------------------------------------------------------------------
973
+ // Analysis
974
+ // ---------------------------------------------------------------------------
975
+
976
+ type ExpressionEvaluation = { type: 'Number'; value: number } | { type: 'ListOfNumber'; value: number[] };
977
+
978
+ /**
979
+ * The calculator's analysis of one expression. Evaluation is asynchronous,
980
+ * so read this inside an `observe('expressionAnalysis', ...)` callback.
981
+ */
982
+ interface ExpressionAnalysis {
983
+ /** The expression can be plotted. */
984
+ isGraphable: boolean;
985
+ /** The expression produces an evaluation error. */
986
+ isError: boolean;
987
+ /** The localized error message, if any. */
988
+ errorMessage?: string;
989
+ /** Evaluation information is shown in the expressions list. */
990
+ evaluationDisplayed?: boolean;
991
+ /** Numeric value(s), when the expression evaluates to numbers. */
992
+ evaluation?: ExpressionEvaluation;
993
+ }
994
+ }
995
+ // ---- types/state.d.ts ----
996
+
997
+ /**
998
+ * Serialized calculator states and the options for loading them.
999
+ */
1000
+ declare namespace Desmos {
1001
+ /**
1002
+ * A serialized graph, as returned by `getState()` on a graphing, geometry
1003
+ * or 3D calculator. Safe to `JSON.stringify`.
1004
+ *
1005
+ * Treat states as opaque: modifying them by hand can produce a state that
1006
+ * `setState()` cannot load.
1007
+ */
1008
+ interface GraphState {
1009
+ /** State format version. */
1010
+ readonly version: number;
1011
+ readonly [key: string]: unknown;
1012
+ }
1013
+
1014
+ /**
1015
+ * A serialized four-function or scientific calculator state. Treat as opaque.
1016
+ */
1017
+ interface BasicCalculatorState {
1018
+ readonly [key: string]: unknown;
1019
+ }
1020
+
1021
+ interface SetBlankOptions {
1022
+ /** Keep the undo/redo history. @defaultValue `false` */
1023
+ allowUndo?: boolean;
1024
+ }
1025
+
1026
+ interface SetStateOptions extends SetBlankOptions {
1027
+ /**
1028
+ * Replace colors in the state with the perceptually closest colors in
1029
+ * the calculator's current palette (`calculator.colors`).
1030
+ * @defaultValue `false`
1031
+ */
1032
+ remapColors?: boolean;
1033
+ }
1034
+
1035
+ /**
1036
+ * A snapshot of the current state plus its undo/redo history, for use with
1037
+ * `restoreHistory()`. Not serializable.
1038
+ *
1039
+ * @remarks Undocumented: may change without notice.
1040
+ */
1041
+ interface CalculatorHistory {
1042
+ readonly currentState: GraphState;
1043
+ }
1044
+ }
1045
+ // ---- types/coordinates.d.ts ----
1046
+
1047
+ /**
1048
+ * Viewport bounds, coordinate conversion and screenshot options.
1049
+ */
1050
+ declare namespace Desmos {
1051
+ /** Viewport bounds in math coordinates. Requires `right > left` and `top > bottom`. */
1052
+ interface MathBounds {
1053
+ left: number;
1054
+ right: number;
1055
+ bottom: number;
1056
+ top: number;
1057
+ }
1058
+
1059
+ /**
1060
+ * Viewport bounds using `xmin`/`xmax`/`ymin`/`ymax` names. Accepted by
1061
+ * `setMathBounds()` in place of {@link MathBounds}.
1062
+ *
1063
+ * @remarks Undocumented alias.
1064
+ */
1065
+ interface ViewportBounds {
1066
+ xmin: number;
1067
+ xmax: number;
1068
+ ymin: number;
1069
+ ymax: number;
1070
+ }
1071
+
1072
+ /** 3D viewport bounds; `setMathBounds()` on a `Calculator3D` also accepts `zmin`/`zmax`. */
1073
+ interface ViewportBounds3D extends ViewportBounds {
1074
+ zmin: number;
1075
+ zmax: number;
1076
+ }
1077
+
1078
+ /** A rectangle in math or pixel coordinates. */
1079
+ interface Rect {
1080
+ top: number;
1081
+ bottom: number;
1082
+ left: number;
1083
+ right: number;
1084
+ width: number;
1085
+ height: number;
1086
+ }
1087
+
1088
+ /** Math coordinates of the graphpaper. Note `top > bottom`. */
1089
+ interface MathCoordinates extends Rect {
1090
+ xmin: number;
1091
+ xmax: number;
1092
+ ymin: number;
1093
+ ymax: number;
1094
+ /** Present on 3D calculators. */
1095
+ zmin?: number;
1096
+ /** Present on 3D calculators. */
1097
+ zmax?: number;
1098
+ }
1099
+
1100
+ /**
1101
+ * The graphpaper bounds. Pixel coordinates are relative to the top left of
1102
+ * the calculator's container element, so `pixelCoordinates.top <
1103
+ * pixelCoordinates.bottom` while `mathCoordinates.top > mathCoordinates.bottom`.
1104
+ */
1105
+ interface GraphpaperBounds {
1106
+ mathCoordinates: MathCoordinates;
1107
+ pixelCoordinates: Rect;
1108
+ }
1109
+
1110
+ /** A point with an `x` property, a `y` property, or both. */
1111
+ type PartialPoint = { x: number; y?: number } | { x?: number; y: number };
1112
+
1113
+ /** The result of a coordinate conversion: the same properties as the input. */
1114
+ type ConvertedPoint<T extends PartialPoint> = { [K in keyof T & ('x' | 'y')]: number };
1115
+
1116
+ // ---------------------------------------------------------------------------
1117
+ // Screenshots
1118
+ // ---------------------------------------------------------------------------
1119
+
1120
+ interface ScreenshotOptions {
1121
+ /** Width in pixels. @defaultValue current graphpaper width */
1122
+ width?: number;
1123
+ /** Height in pixels. @defaultValue current graphpaper height */
1124
+ height?: number;
1125
+ /**
1126
+ * Oversampling factor for high-density screens. With `2`, the image is
1127
+ * physically twice `width` × `height` but meant to be displayed at
1128
+ * `width` × `height`.
1129
+ * @defaultValue `1`
1130
+ */
1131
+ targetPixelRatio?: number;
1132
+ /**
1133
+ * Keep axis numbers on small images (below 256px in either dimension),
1134
+ * where they are normally removed.
1135
+ * @defaultValue `false`
1136
+ */
1137
+ preserveAxisNumbers?: boolean;
1138
+ /** Draw movable points with their interactive halo. @defaultValue `false` */
1139
+ showMovablePoints?: boolean;
1140
+ }
1141
+
1142
+ /**
1143
+ * How `asyncScreenshot()` computes the captured viewport:
1144
+ *
1145
+ * - `contain`: smallest box containing `mathBounds` that keeps the math aspect ratio.
1146
+ * - `stretch`: use `mathBounds` exactly; the aspect ratio is not kept.
1147
+ * - `preserveX`: use `left`/`right`, adjust `y` about the midline to keep the aspect ratio.
1148
+ * - `preserveY`: use `top`/`bottom`, adjust `x` about the midline to keep the aspect ratio.
1149
+ */
1150
+ type ScreenshotMode = 'contain' | 'stretch' | 'preserveX' | 'preserveY';
1151
+
1152
+ /**
1153
+ * Desired screenshot bounds. Any omitted property uses the current viewport,
1154
+ * but `top` requires `bottom` and `left` requires `right`.
1155
+ */
1156
+ type ScreenshotMathBounds = ({ top: number; bottom: number } | { top?: never; bottom?: never }) &
1157
+ ({ left: number; right: number } | { left?: never; right?: never });
1158
+
1159
+ interface AsyncScreenshotOptions extends ScreenshotOptions {
1160
+ /** Image format. @defaultValue `'png'` */
1161
+ format?: 'png' | 'svg';
1162
+ /**
1163
+ * Viewport strategy. The docs give `'contain'` as the default, but the
1164
+ * v1.13 bundle uses `'preserveX'` when the axes are square and `'stretch'`
1165
+ * otherwise. Pass a mode explicitly if it matters.
1166
+ */
1167
+ mode?: ScreenshotMode;
1168
+ /** Region to capture. Invalid bounds log a warning and use the current viewport. */
1169
+ mathBounds?: ScreenshotMathBounds;
1170
+ /** Include point labels. @defaultValue `false` */
1171
+ showLabels?: boolean;
1172
+ }
1173
+
1174
+ /**
1175
+ * Receives a PNG data URI or an SVG string, or `undefined` if the
1176
+ * screenshot failed.
1177
+ */
1178
+ type AsyncScreenshotCallback = (data: string | undefined) => void;
1179
+ }
1180
+ // ---- types/calculators/helper-expression.d.ts ----
1181
+
1182
+ /**
1183
+ * Helper expressions: evaluated like normal expressions but hidden from the
1184
+ * expressions list.
1185
+ */
1186
+ declare namespace Desmos {
1187
+ interface HelperExpressionObservables {
1188
+ /** The value, when the expression evaluates to a number. May be `NaN`. */
1189
+ numericValue: number | undefined;
1190
+ /** The values, when the expression evaluates to a list. */
1191
+ listValue: number[] | undefined;
1192
+ }
1193
+
1194
+ /** Created by `calculator.HelperExpression({ latex })`. */
1195
+ interface HelperExpression
1196
+ extends Observable<HelperExpressionObservables>,
1197
+ Readonly<HelperExpressionObservables> {
1198
+ /** The LaTeX being evaluated. */
1199
+ readonly latex: Latex;
1200
+ }
1201
+ }
1202
+ // ---- types/calculators/base.d.ts ----
1203
+
1204
+ /**
1205
+ * The API shared by the graphing calculator, the geometry tool and the 3D
1206
+ * calculator. All three are built on the same underlying class.
1207
+ */
1208
+ declare namespace Desmos {
1209
+ /** Events emitted by graphing-family calculators, mapped to their payloads. */
1210
+ interface GraphingCalculatorEventMap {
1211
+ /**
1212
+ * Any change that affects the persisted state, from the user or from API
1213
+ * calls. Useful for autosaving without polling.
1214
+ */
1215
+ change: { isUserInitiated: boolean };
1216
+ /** The user clicked "Delete All" or "Reset" in the expressions list top bar. */
1217
+ graphReset: unknown;
1218
+ }
1219
+
1220
+ type GraphingCalculatorEvent = Extract<keyof GraphingCalculatorEventMap, string>;
1221
+
1222
+ /**
1223
+ * Called when an observed calculator event fires. Receives the
1224
+ * un-namespaced event name (e.g. `'change'` even when observing
1225
+ * `'change.autosave'`) and the event payload.
1226
+ */
1227
+ type GraphingCalculatorEventCallback<K extends GraphingCalculatorEvent> = (
1228
+ eventName: K,
1229
+ event: GraphingCalculatorEventMap[K]
1230
+ ) => void;
1231
+
1232
+ /** Observable properties of a graphing-family calculator. */
1233
+ interface GraphingCalculatorObservables {
1234
+ /** Graphpaper bounds in math and pixel coordinates. Changes on pan and zoom. */
1235
+ graphpaperBounds: GraphpaperBounds;
1236
+ /** Analysis of each expression, keyed by expression id. */
1237
+ expressionAnalysis: Readonly<Record<ExpressionId, ExpressionAnalysis>>;
1238
+ /** `true` while an expression is selected. */
1239
+ isAnyExpressionSelected: boolean;
1240
+ /** Id of the selected expression, or `undefined` if none is selected. */
1241
+ selectedExpressionId: ExpressionId | undefined;
1242
+ /** `true` while audio trace mode is active. */
1243
+ isAudioTraceActive: boolean;
1244
+ }
1245
+
1246
+ /**
1247
+ * Members shared by {@link GraphingCalculator}, {@link Geometry} and
1248
+ * {@link Calculator3D}.
1249
+ */
1250
+ interface GraphingCalculatorBase
1251
+ extends Observable<GraphingCalculatorObservables>,
1252
+ Readonly<GraphingCalculatorObservables> {
1253
+ // -------------------------------------------------------------------------
1254
+ // Lifecycle
1255
+ // -------------------------------------------------------------------------
1256
+
1257
+ /**
1258
+ * Destroy the instance, unbind listeners and free resources. Call this
1259
+ * when the container element is removed from the DOM. Methods called
1260
+ * afterwards do nothing and log a warning.
1261
+ */
1262
+ destroy(): void;
1263
+
1264
+ /**
1265
+ * Resize the calculator to fill its container. Only needed when the
1266
+ * `autosize` option is `false`: call it whenever the container's size
1267
+ * changes or it is added to or removed from the DOM.
1268
+ */
1269
+ resize(): void;
1270
+
1271
+ // -------------------------------------------------------------------------
1272
+ // Saving and loading
1273
+ // -------------------------------------------------------------------------
1274
+
1275
+ /** The current state. Treat it as opaque; it can be serialized with `JSON.stringify`. */
1276
+ getState(): GraphState;
1277
+
1278
+ /** Load a state previously returned by `getState()`. */
1279
+ setState(state: GraphState, options?: SetStateOptions): void;
1280
+
1281
+ /** Reset to a blank state. */
1282
+ setBlank(options?: SetBlankOptions): void;
1283
+
1284
+ /**
1285
+ * Replace "Delete All" with a "Reset" button that restores `state`, and
1286
+ * make the "home" zoom button return to that state's viewport.
1287
+ */
1288
+ setDefaultState(state: GraphState): void;
1289
+
1290
+ /** Return to the previous state in the undo/redo history, if any. */
1291
+ undo(): void;
1292
+
1293
+ /** Advance to the next state in the undo/redo history, if any. */
1294
+ redo(): void;
1295
+
1296
+ /** Clear the undo/redo history without changing the current state. */
1297
+ clearHistory(): void;
1298
+
1299
+ /**
1300
+ * Run `callback` so that its changes replace the current history entry
1301
+ * instead of adding one. Keeps programmatic changes out of the user's undo stack.
1302
+ */
1303
+ withHistoryReplacement(callback: () => void): void;
1304
+
1305
+ /**
1306
+ * The current state together with its undo/redo history.
1307
+ * @remarks Undocumented: may change without notice.
1308
+ */
1309
+ getHistory(): CalculatorHistory;
1310
+
1311
+ /**
1312
+ * Restore a value returned by `getHistory()`, including its undo/redo history.
1313
+ * @remarks Undocumented: may change without notice.
1314
+ */
1315
+ restoreHistory(history: CalculatorHistory): void;
1316
+
1317
+ // -------------------------------------------------------------------------
1318
+ // Screenshots
1319
+ // -------------------------------------------------------------------------
1320
+
1321
+ /** A PNG data URI of the current graphpaper. */
1322
+ screenshot(options?: ScreenshotOptions): string;
1323
+
1324
+ /**
1325
+ * A 200×200 PNG data URI at `targetPixelRatio: 2`.
1326
+ * @remarks Undocumented: may change without notice.
1327
+ */
1328
+ makeThumbnail(): string;
1329
+
1330
+ // -------------------------------------------------------------------------
1331
+ // Events
1332
+ // -------------------------------------------------------------------------
1333
+
1334
+ /**
1335
+ * Listen for a calculator event. Namespace the name (`'change.autosave'`)
1336
+ * to be able to remove this observer on its own.
1337
+ *
1338
+ * @example
1339
+ * calculator.observeEvent('change', (eventName, event) => {
1340
+ * if (event.isUserInitiated) save(calculator.getState());
1341
+ * });
1342
+ */
1343
+ observeEvent<K extends GraphingCalculatorEvent>(
1344
+ event: EventName<K>,
1345
+ callback: GraphingCalculatorEventCallback<K>
1346
+ ): void;
1347
+
1348
+ /** Remove event observers; `'change'` removes all of them, `'change.ns'` just one. */
1349
+ unobserveEvent(event: EventName<GraphingCalculatorEvent>): void;
1350
+
1351
+ // -------------------------------------------------------------------------
1352
+ // Expressions
1353
+ // -------------------------------------------------------------------------
1354
+
1355
+ /**
1356
+ * Create an expression, or update the one with the same `id`. Only the
1357
+ * given properties change. An expression's `type` can't be changed;
1358
+ * remove it first. Invalid input is ignored.
1359
+ */
1360
+ setExpression(expression: SettableExpressionState): void;
1361
+
1362
+ /** Call `setExpression()` for each item. */
1363
+ setExpressions(expressions: readonly SettableExpressionState[]): void;
1364
+
1365
+ /** Remove the expression with the given `id`. */
1366
+ removeExpression(expression: { id: ExpressionId }): void;
1367
+
1368
+ /** Remove each expression with one of the given ids. */
1369
+ removeExpressions(expressions: ReadonlyArray<{ id: ExpressionId }>): void;
1370
+
1371
+ /** The items in the expressions list. */
1372
+ getExpressions(): ExpressionListItem[];
1373
+
1374
+ /**
1375
+ * Create a helper expression: evaluated like a normal expression but not
1376
+ * shown in the expressions list. Observe its `numericValue` or
1377
+ * `listValue` to react to changes.
1378
+ *
1379
+ * @example
1380
+ * const a = calculator.HelperExpression({ latex: 'a' });
1381
+ * a.observe('numericValue', () => console.log(a.numericValue));
1382
+ */
1383
+ HelperExpression(expression: { latex: Latex }): HelperExpression;
1384
+
1385
+ /**
1386
+ * All helper expressions created on this calculator.
1387
+ * @remarks Undocumented: may change without notice.
1388
+ */
1389
+ getHelperExpressions(): HelperExpression[];
1390
+
1391
+ // -------------------------------------------------------------------------
1392
+ // Settings
1393
+ // -------------------------------------------------------------------------
1394
+
1395
+ /**
1396
+ * Update options and graph settings. Properties that aren't given keep
1397
+ * their current value. Some combinations conflict and get adjusted:
1398
+ * avoid `graphpaper: false` with `expressionsCollapsed: true` or
1399
+ * `zoomButtons: true`, and `lockViewport: true` with `zoomButtons: true`.
1400
+ */
1401
+ updateSettings(settings: GraphingCalculatorOptions): void;
1402
+
1403
+ /** @deprecated Use {@link GraphingCalculatorBase.updateSettings} instead. */
1404
+ setGraphSettings(settings: GraphingCalculatorOptions): void;
1405
+
1406
+ /** Current settings, observable per property. */
1407
+ readonly settings: GraphingCalculatorSettings;
1408
+
1409
+ /** @deprecated Use {@link GraphingCalculatorBase.settings} instead. */
1410
+ readonly graphSettings: GraphingCalculatorSettings;
1411
+
1412
+ /** The palette in use: the `colors` option or the default palette. */
1413
+ readonly colors: ColorPalette;
1414
+
1415
+ /** Set `settings.randomSeed` to a new random value, re-randomizing `random()`. */
1416
+ newRandomSeed(): void;
1417
+
1418
+ // -------------------------------------------------------------------------
1419
+ // Viewport
1420
+ // -------------------------------------------------------------------------
1421
+
1422
+ /** Set the graphpaper bounds. Invalid bounds (`right <= left` or `top <= bottom`) are ignored. */
1423
+ setMathBounds(bounds: MathBounds | ViewportBounds): void;
1424
+
1425
+ /** Whether the projection is uniform (square math aspect ratio). */
1426
+ isProjectionUniform(): boolean;
1427
+
1428
+ // -------------------------------------------------------------------------
1429
+ // Selection and focus
1430
+ // -------------------------------------------------------------------------
1431
+
1432
+ /**
1433
+ * Focus the first expression. It isn't focused by default because the
1434
+ * browser would scroll it into view on page load.
1435
+ */
1436
+ focusFirstExpression(): void;
1437
+
1438
+ /**
1439
+ * Open the keypad, focusing the first expression if none is focused.
1440
+ * @deprecated Use the `keypadActivated` option, optionally followed by
1441
+ * `focusFirstExpression()`.
1442
+ */
1443
+ openKeypad(): void;
1444
+
1445
+ /** Select the expression with this id, as if the user had clicked it. */
1446
+ setSelectedExpressionId(id: ExpressionId): void;
1447
+
1448
+ /** Remove the selected expression. Returns its id, or `undefined` if nothing was selected. */
1449
+ removeSelected(): ExpressionId | undefined;
1450
+
1451
+ // -------------------------------------------------------------------------
1452
+ // Accessibility
1453
+ // -------------------------------------------------------------------------
1454
+
1455
+ /**
1456
+ * Open the audio-trace keypad for the selected expression, or the first
1457
+ * traceable expression if none is selected. Requires `audio: true`.
1458
+ */
1459
+ enterAudioTrace(): void;
1460
+
1461
+ /** Exit audio trace mode if it is active. */
1462
+ exitAudioTrace(): void;
1463
+ }
1464
+ }
1465
+ // ---- types/calculators/graphing.d.ts ----
1466
+
1467
+ /**
1468
+ * The 2D graphing calculator.
1469
+ */
1470
+ declare namespace Desmos {
1471
+ /**
1472
+ * A graphing calculator embedded in a DOM element. Create one with
1473
+ * `Desmos.GraphingCalculator(element, options)`.
1474
+ */
1475
+ interface GraphingCalculator extends GraphingCalculatorBase {
1476
+ /**
1477
+ * Asynchronous screenshot. Guarantees the state is fully evaluated
1478
+ * before capture, can capture regions outside the current viewport, and
1479
+ * can produce SVG.
1480
+ */
1481
+ asyncScreenshot(callback: AsyncScreenshotCallback): void;
1482
+ asyncScreenshot(options: AsyncScreenshotOptions, callback: AsyncScreenshotCallback): void;
1483
+
1484
+ /** Convert math coordinates to pixel coordinates. Returns the same properties as `coords`. */
1485
+ mathToPixels<T extends PartialPoint>(coords: T): ConvertedPoint<T>;
1486
+
1487
+ /** Convert pixel coordinates to math coordinates. Inverse of `mathToPixels`. */
1488
+ pixelsToMath<T extends PartialPoint>(coords: T): ConvertedPoint<T>;
1489
+ }
1490
+
1491
+ interface GraphingCalculatorConstructor {
1492
+ (element: HTMLElement, options?: GraphingCalculatorOptions): GraphingCalculator;
1493
+ new (element: HTMLElement, options?: GraphingCalculatorOptions): GraphingCalculator;
1494
+ readonly prototype: GraphingCalculator;
1495
+ }
1496
+
1497
+ /**
1498
+ * Create a graphing calculator in `element`. The calculator fills the
1499
+ * element; give the element a size.
1500
+ *
1501
+ * @throws If the graphing calculator isn't enabled for the API key.
1502
+ *
1503
+ * @example
1504
+ * const calculator = Desmos.GraphingCalculator(document.getElementById('calculator')!, {
1505
+ * keypad: false,
1506
+ * });
1507
+ */
1508
+ const GraphingCalculator: GraphingCalculatorConstructor;
1509
+
1510
+ /**
1511
+ * Alias of {@link Desmos.GraphingCalculator}.
1512
+ * @remarks Undocumented alias kept for backward compatibility.
1513
+ */
1514
+ const Calculator: GraphingCalculatorConstructor;
1515
+ }
1516
+ // ---- types/calculators/geometry.d.ts ----
1517
+
1518
+ /**
1519
+ * The geometry tool. Built on the graphing calculator and shares its API.
1520
+ */
1521
+ declare namespace Desmos {
1522
+ /**
1523
+ * A geometry tool instance. Create one with `Desmos.Geometry(element, options)`.
1524
+ *
1525
+ * With `authorFeatures: true`, the settings menu also lets authors
1526
+ * customize the toolbar. Toolbar customizations are saved in the state.
1527
+ */
1528
+ interface Geometry extends GraphingCalculator {}
1529
+
1530
+ interface GeometryConstructor {
1531
+ (element: HTMLElement, options?: GeometryOptions): Geometry;
1532
+ new (element: HTMLElement, options?: GeometryOptions): Geometry;
1533
+ readonly prototype: Geometry;
1534
+ }
1535
+
1536
+ /**
1537
+ * Create a geometry tool in `element`. It can be created before `element`
1538
+ * is in the DOM; the view appears once it is inserted. Call `destroy()`
1539
+ * when done.
1540
+ *
1541
+ * @throws If the geometry tool isn't enabled for the API key.
1542
+ */
1543
+ const Geometry: GeometryConstructor;
1544
+ }
1545
+ // ---- types/calculators/calculator3d.d.ts ----
1546
+
1547
+ /**
1548
+ * The 3D graphing calculator. Built on the graphing calculator and shares
1549
+ * most of its API.
1550
+ */
1551
+ declare namespace Desmos {
1552
+ /**
1553
+ * Camera orientation as two angles in radians: the tilt of the z-axis
1554
+ * toward the viewer, and the rotation about the z-axis. Inferred from the
1555
+ * v1.13 bundle.
1556
+ */
1557
+ type Orientation3D = [tilt: number, spin: number];
1558
+
1559
+ /**
1560
+ * A 3D calculator. Create one with `Desmos.Calculator3D(element, options)`.
1561
+ *
1562
+ * Compared with {@link GraphingCalculator}: `asyncScreenshot()` always
1563
+ * throws in v1.13 (use `screenshot()`), and `mathToPixels` / `pixelsToMath`
1564
+ * are `undefined`, so neither is declared here.
1565
+ */
1566
+ interface Calculator3D extends GraphingCalculatorBase {
1567
+ /** Set the bounds, including the z range. */
1568
+ setMathBounds(bounds: MathBounds | ViewportBounds | ViewportBounds3D): void;
1569
+
1570
+ /**
1571
+ * The current camera orientation.
1572
+ * @remarks Undocumented: may change without notice.
1573
+ */
1574
+ getOrientation(): Orientation3D;
1575
+
1576
+ /**
1577
+ * Set the camera orientation immediately and stop any auto-rotation.
1578
+ * Non-finite angles are ignored.
1579
+ * @remarks Undocumented: may change without notice.
1580
+ */
1581
+ setOrientation(tilt: number, spin: number): void;
1582
+
1583
+ /**
1584
+ * Animate the camera to an orientation. Non-finite angles are ignored.
1585
+ * @remarks Undocumented: may change without notice.
1586
+ */
1587
+ animateToOrientation(tilt: number, spin: number): void;
1588
+
1589
+ /**
1590
+ * Set the perspective distortion. `0` gives an orthographic projection;
1591
+ * the default is `1`. Values outside the supported range are ignored.
1592
+ * @remarks Undocumented: may change without notice.
1593
+ */
1594
+ setPerspectiveDistortion(value: number): void;
1595
+ }
1596
+
1597
+ interface Calculator3DConstructor {
1598
+ (element: HTMLElement, options?: Calculator3DOptions): Calculator3D;
1599
+ new (element: HTMLElement, options?: Calculator3DOptions): Calculator3D;
1600
+ readonly prototype: Calculator3D;
1601
+ }
1602
+
1603
+ /**
1604
+ * Create a 3D calculator in `element`. It can be created before `element`
1605
+ * is in the DOM; the view appears once it is inserted. Call `destroy()`
1606
+ * when done.
1607
+ *
1608
+ * @throws If the 3D calculator isn't enabled for the API key.
1609
+ */
1610
+ const Calculator3D: Calculator3DConstructor;
1611
+ }
1612
+ // ---- types/calculators/basic.d.ts ----
1613
+
1614
+ /**
1615
+ * The four-function and scientific calculators.
1616
+ */
1617
+ declare namespace Desmos {
1618
+ /**
1619
+ * A four-function or scientific calculator. Its methods behave like the
1620
+ * graphing calculator's, with a smaller set of settings.
1621
+ *
1622
+ * @typeParam TOptions - options accepted by `updateSettings()`.
1623
+ */
1624
+ interface BasicCalculator<TOptions extends BasicCalculatorOptions = BasicCalculatorOptions> {
1625
+ /** Destroy the instance, unbind listeners and free resources. */
1626
+ destroy(): void;
1627
+
1628
+ /** Resize to fill the container. Only needed when auto-sizing is off. */
1629
+ resize(): void;
1630
+
1631
+ /** The current state. Treat it as opaque; it can be serialized with `JSON.stringify`. */
1632
+ getState(): BasicCalculatorState;
1633
+
1634
+ /** Load a state previously returned by `getState()`. */
1635
+ setState(state: BasicCalculatorState, options?: SetBlankOptions): void;
1636
+
1637
+ /** Reset to a blank state. */
1638
+ setBlank(options?: SetBlankOptions): void;
1639
+
1640
+ undo(): void;
1641
+ redo(): void;
1642
+ clearHistory(): void;
1643
+
1644
+ focusFirstExpression(): void;
1645
+
1646
+ /** Update settings. Properties that aren't given keep their current value. */
1647
+ updateSettings(settings: TOptions): void;
1648
+
1649
+ /**
1650
+ * Current settings, observable per property.
1651
+ * @remarks Undocumented for basic calculators, but present at runtime.
1652
+ */
1653
+ readonly settings: BasicCalculatorSettings<TOptions>;
1654
+
1655
+ /** Listen for changes to the calculator's state. Supports namespacing (`'change.ns'`). */
1656
+ observeEvent(event: EventName<'change'>, callback: () => void): void;
1657
+
1658
+ /** Remove `'change'` observers. */
1659
+ unobserveEvent(event: EventName<'change'>): void;
1660
+ }
1661
+
1662
+ type FourFunctionCalculator = BasicCalculator<FourFunctionCalculatorOptions>;
1663
+ type ScientificCalculator = BasicCalculator<ScientificCalculatorOptions>;
1664
+
1665
+ interface FourFunctionCalculatorConstructor {
1666
+ (element: HTMLElement, options?: FourFunctionCalculatorOptions): FourFunctionCalculator;
1667
+ new (element: HTMLElement, options?: FourFunctionCalculatorOptions): FourFunctionCalculator;
1668
+ readonly prototype: FourFunctionCalculator;
1669
+ }
1670
+
1671
+ interface ScientificCalculatorConstructor {
1672
+ (element: HTMLElement, options?: ScientificCalculatorOptions): ScientificCalculator;
1673
+ new (element: HTMLElement, options?: ScientificCalculatorOptions): ScientificCalculator;
1674
+ readonly prototype: ScientificCalculator;
1675
+ }
1676
+
1677
+ /**
1678
+ * Create a four-function calculator in `element`.
1679
+ * @throws If the four-function calculator isn't enabled for the API key.
1680
+ */
1681
+ const FourFunctionCalculator: FourFunctionCalculatorConstructor;
1682
+
1683
+ /**
1684
+ * Create a scientific calculator in `element`.
1685
+ * @throws If the scientific calculator isn't enabled for the API key.
1686
+ */
1687
+ const ScientificCalculator: ScientificCalculatorConstructor;
1688
+ }
1689
+ // ---- types/abraham.d.ts ----
1690
+
1691
+ /**
1692
+ * Abraham: Desmos's library for translating between LaTeX and the Nemeth and
1693
+ * UEB Braille math codes, bundled into `calculator.js`.
1694
+ *
1695
+ * Documented at https://www.desmos.com/api/v1.13/docs/abraham.html. Desmos
1696
+ * asks that you contact partnerships@desmos.com before using it.
1697
+ */
1698
+ declare namespace Desmos {
1699
+ /** A position in the translator's input. */
1700
+ interface AbrahamLocation {
1701
+ first_line: number;
1702
+ last_line: number;
1703
+ first_column: number;
1704
+ last_column: number;
1705
+ }
1706
+
1707
+ /** A place where permissive Braille→LaTeX translation inserted a missing delimiter. */
1708
+ interface AbrahamWarning {
1709
+ location: AbrahamLocation;
1710
+ }
1711
+
1712
+ /** A successful LaTeX→Braille translation. */
1713
+ interface AbrahamBrailleSuccess {
1714
+ isError: false;
1715
+ /** Six-dot Unicode Braille. */
1716
+ value: string;
1717
+ }
1718
+
1719
+ /** A successful Braille→LaTeX translation. */
1720
+ interface AbrahamLatexSuccess {
1721
+ isError: false;
1722
+ value: Latex;
1723
+ /** Where missing delimiters were inserted. Always empty with `strict: true`. */
1724
+ warnings: AbrahamWarning[];
1725
+ }
1726
+
1727
+ /** A successful translation in either direction. */
1728
+ interface AbrahamSuccess {
1729
+ isError: false;
1730
+ value: string;
1731
+ /** Present on Braille→LaTeX results. */
1732
+ warnings?: AbrahamWarning[];
1733
+ }
1734
+
1735
+ /** A failed translation (a parse error). */
1736
+ interface AbrahamFailure {
1737
+ isError: true;
1738
+ error: {
1739
+ /** Where the parse error occurred. */
1740
+ location: AbrahamLocation;
1741
+ /** Developer diagnostics. Not part of the public API; its contents may change. */
1742
+ _diagnostic?: unknown;
1743
+ };
1744
+ }
1745
+
1746
+ /** The result of `latexToNemeth` / `latexToUeb`. */
1747
+ type AbrahamBrailleResult = AbrahamBrailleSuccess | AbrahamFailure;
1748
+
1749
+ /** The result of `nemethToLatex` / `uebToLatex`. */
1750
+ type AbrahamLatexResult = AbrahamLatexSuccess | AbrahamFailure;
1751
+
1752
+ /** The result of any translation. */
1753
+ type AbrahamResult = AbrahamSuccess | AbrahamFailure;
1754
+
1755
+ interface AbrahamLatexToBrailleOptions {
1756
+ /**
1757
+ * Operator names to recognize. Neither Braille code has a convention for
1758
+ * `\operatorname`, so these are written as plain letters.
1759
+ * @defaultValue Desmos's built-in list (`floor`, `mean`, `normaldist`, ...)
1760
+ */
1761
+ operatorNames?: readonly string[];
1762
+ }
1763
+
1764
+ interface AbrahamBrailleToLatexOptions {
1765
+ /**
1766
+ * Treat missing delimiters (e.g. an unclosed fraction or radical) as parse
1767
+ * errors instead of inserting them and reporting `warnings`.
1768
+ * @defaultValue `false`
1769
+ */
1770
+ strict?: boolean;
1771
+ /**
1772
+ * Operator names to recognize in the Braille input, e.g. `['blah']` turns
1773
+ * `blah(abc)` into `\operatorname{blah}(abc)`.
1774
+ * @defaultValue Desmos's built-in list (`floor`, `mean`, `normaldist`, ...)
1775
+ */
1776
+ operatorNames?: readonly string[];
1777
+ }
1778
+
1779
+ interface Abraham {
1780
+ /** Library version, e.g. `'1.0.3'`. */
1781
+ readonly version: string;
1782
+
1783
+ /**
1784
+ * LaTeX → Nemeth Braille.
1785
+ * @example Abraham.latexToNemeth('e_{f}^{x^{2}}') // { isError: false, value: '⠑⠰⠋⠘⠭⠘⠘⠆' }
1786
+ */
1787
+ latexToNemeth(latex: Latex, options?: AbrahamLatexToBrailleOptions): AbrahamBrailleResult;
1788
+
1789
+ /**
1790
+ * LaTeX → UEB Braille.
1791
+ * @example Abraham.latexToUeb('1+1') // { isError: false, value: '⠼⠁⠐⠖⠼⠁' }
1792
+ */
1793
+ latexToUeb(latex: Latex, options?: AbrahamLatexToBrailleOptions): AbrahamBrailleResult;
1794
+
1795
+ /**
1796
+ * Nemeth Braille → LaTeX. `braille` must be six-dot Unicode Braille; use
1797
+ * `UnicodeBraille.coerceToSixDotCells` to convert other formats first.
1798
+ * Unless `strict` is set, missing delimiters are inserted and reported in `warnings`.
1799
+ * @example Abraham.nemethToLatex('⠹⠂⠌⠆') // value '\\frac{1}{2}', with one warning
1800
+ */
1801
+ nemethToLatex(braille: string, options?: AbrahamBrailleToLatexOptions): AbrahamLatexResult;
1802
+
1803
+ /**
1804
+ * UEB Braille → LaTeX. `braille` must be six-dot Unicode Braille; use
1805
+ * `UnicodeBraille.coerceToSixDotCells` to convert other formats first.
1806
+ * Unless `strict` is set, missing delimiters are inserted and reported in `warnings`.
1807
+ * @example Abraham.uebToLatex('⠼⠁⠐⠖⠼⠁') // { isError: false, value: '1+1', warnings: [] }
1808
+ */
1809
+ uebToLatex(braille: string, options?: AbrahamBrailleToLatexOptions): AbrahamLatexResult;
1810
+
1811
+ /** Conversions between Unicode Braille and Braille ASCII. */
1812
+ readonly UnicodeBraille: {
1813
+ /**
1814
+ * Unicode Braille → Braille ASCII (upper case letters as a comma + letter digraph).
1815
+ * @example toBrailleAscii('⠼⠁⠐⠖⠼⠁') // '#A"6#A'
1816
+ */
1817
+ toBrailleAscii(braille: string): string;
1818
+ /**
1819
+ * Unicode Braille → Expanded Braille ASCII, the eight-dot encoding common
1820
+ * on refreshable displays.
1821
+ * @example toExpandedBrailleAscii('⠼⠁⠐⠖⠼⠁') // '#a"6#a'
1822
+ */
1823
+ toExpandedBrailleAscii(braille: string): string;
1824
+ /**
1825
+ * Coerce input to the six-dot Unicode Braille the translators expect:
1826
+ * converts Braille ASCII or Expanded Braille ASCII (ignoring case), and
1827
+ * strips the bottom pair of dots from eight-dot Unicode cells.
1828
+ * @example coerceToSixDotCells('#A"6#A') // '⠼⠁⠐⠖⠼⠁'
1829
+ */
1830
+ coerceToSixDotCells(input: string): string;
1831
+ };
1832
+ }
1833
+
1834
+ /** The Abraham Braille translation library. */
1835
+ const Abraham: Abraham;
1836
+ }
1837
+ // ---- types/mathquill.d.ts ----
1838
+
1839
+ /**
1840
+ * The MathQuill build bundled into `calculator.js`. It is Desmos's own fork,
1841
+ * and some standard MathQuill methods (such as `cmd`, `reflow` and `revert`)
1842
+ * are missing. Only methods present in the v1.13 bundle are declared.
1843
+ *
1844
+ * @remarks Undocumented: may change without notice.
1845
+ */
1846
+ declare namespace Desmos {
1847
+ /** A MathQuill config object. The option set of Desmos's fork is not documented. */
1848
+ type MathQuillConfig = Record<string, unknown>;
1849
+
1850
+ /** A static (read-only) math field. */
1851
+ interface MathQuillStaticMath {
1852
+ /** The field's root element. */
1853
+ el(): HTMLElement;
1854
+ /** The current LaTeX. */
1855
+ latex(): Latex;
1856
+ /** Replace the contents with `latex`. */
1857
+ latex(latex: Latex): this;
1858
+ /** A spoken-math description of the contents. */
1859
+ mathspeak(): string;
1860
+ focus(): this;
1861
+ blur(): this;
1862
+ getAriaLabel(): string;
1863
+ setAriaLabel(label: string): this;
1864
+ getAriaPostLabel(): string;
1865
+ setAriaPostLabel(label: string): this;
1866
+ }
1867
+
1868
+ /** An editable math field. */
1869
+ interface MathQuillMathField extends MathQuillStaticMath {
1870
+ /** Insert `latex` at the cursor. */
1871
+ write(latex: Latex): this;
1872
+ /** Simulate typing `text`. */
1873
+ typedText(text: string): this;
1874
+ /** Simulate a key press, e.g. `'Left'`, `'Shift-Left'` or `'Backspace'`. */
1875
+ keystroke(keys: string): this;
1876
+ /** Select the whole contents. */
1877
+ select(): this;
1878
+ clearSelection(): this;
1879
+ moveToLeftEnd(): this;
1880
+ moveToRightEnd(): this;
1881
+ }
1882
+
1883
+ interface MathQuill {
1884
+ /** The MathQuill API instance attached to `element`, if any. */
1885
+ (element: HTMLElement): MathQuillStaticMath | MathQuillMathField | null | undefined;
1886
+ /** Turn `element` into an editable math field. */
1887
+ MathField(element: HTMLElement, config?: MathQuillConfig): MathQuillMathField;
1888
+ /** Render `element`'s LaTeX text content as static math. */
1889
+ StaticMath(element: HTMLElement, config?: MathQuillConfig): MathQuillStaticMath;
1890
+ /** Set global MathQuill configuration. */
1891
+ config(config: MathQuillConfig): void;
1892
+ /** The MathQuill API instance attached to `element`, if any. */
1893
+ getApiInstanceForElement(element: HTMLElement): MathQuillStaticMath | MathQuillMathField | null | undefined;
1894
+ }
1895
+
1896
+ /** @remarks Undocumented: may change without notice. */
1897
+ const MathQuill: MathQuill;
1898
+ }
1899
+ // ---- types/desmos.d.ts ----
1900
+
1901
+ /**
1902
+ * Top-level values on the `Desmos` global that don't belong to a specific
1903
+ * calculator.
1904
+ */
1905
+ declare namespace Desmos {
1906
+ /**
1907
+ * Which calculators the API key allows. Calling a disabled calculator's
1908
+ * constructor throws.
1909
+ */
1910
+ interface EnabledFeatures {
1911
+ GraphingCalculator: boolean;
1912
+ FourFunctionCalculator: boolean;
1913
+ ScientificCalculator: boolean;
1914
+ GeometryCalculator: boolean;
1915
+ Calculator3D: boolean;
1916
+ }
1917
+
1918
+ /** Features enabled for the API key used to load `calculator.js`. */
1919
+ const enabledFeatures: Readonly<EnabledFeatures>;
1920
+
1921
+ /**
1922
+ * Language codes loaded into this copy of `calculator.js`. `'en'` is always
1923
+ * included; others must be requested with the `lang` URL parameter.
1924
+ */
1925
+ const supportedLanguages: readonly LanguageCode[];
1926
+
1927
+ /**
1928
+ * The default `imageUploadCallback`. Converts `file` to a data URL, taking
1929
+ * EXIF orientation into account and recompressing large images.
1930
+ * `dataURL` is set only when `error` is falsy.
1931
+ */
1932
+ function imageFileToDataURL(file: File, callback: (error: unknown, dataURL: string) => void): void;
1933
+
1934
+ /**
1935
+ * Build version, e.g. `'v1.13'` or `'v1.13-prerelease'`.
1936
+ * @remarks Undocumented.
1937
+ */
1938
+ const version: string;
1939
+
1940
+ /**
1941
+ * Git commit the build was made from.
1942
+ * @remarks Undocumented.
1943
+ */
1944
+ const commit: string;
1945
+ }
1946
+
1947
+ export = Desmos;