import { getRealImageUrl, getBaseUrl, getSvgUrl, getDataUrl, getImageSizeModern, isLabeledSVG } from "@khanacademy/perseus-core"; import type { Coord, Range } from "@khanacademy/perseus-core"; import type * as React from "react"; type WordPosition = { start: number; end: number; }; type WordAndPosition = { string: string; pos: WordPosition; }; export type ParsedValue = { value: number; exact: boolean; }; export type GridDimensions = { scale: number; tickStep: number; unityLabel: boolean; }; type QueryParams = { [param: string]: string; }; export type Position = { top: number; left: number; }; type TouchHandlers = { pointerDown: boolean; currentTouchIdentifier: string | null | undefined; }; /** * Used to compare equality of two input paths, which are represented as * arrays of strings. */ declare function inputPathsEqual(a?: ReadonlyArray | null, b?: ReadonlyArray | null): boolean; /** * Return the first valid interpretation of 'text' as a number, in the form * {value: 2.3, exact: true}. */ declare function firstNumericalParse(text: string): ParsedValue | null | undefined; declare function stringArrayOfSize(size: number): string[]; declare function stringArrayOfSize2D(opt: { rows: number; columns: number; }): string[][]; /** * For a graph's x or y dimension, given the tick step, * the ranges extent (e.g. [-10, 10]), the pixel dimension constraint, * and the grid step, return a bunch of configurations for that dimension. * * Example: * gridDimensionConfig(10, [-50, 50], 400, 5) * * Returns: { * scale: 4, * snap: 2.5, * tickStep: 2, * unityLabel: true * }; */ declare function gridDimensionConfig(absTickStep: number, extent: Coord, dimensionConstraint: number, gridStep: number): GridDimensions; /** * Given the range, step, and boxSize, calculate the reasonable gridStep. * Used for when one was not given explicitly. * * Example: * getGridStep([[-10, 10], [-10, 10]], [1, 1], 340) * * Returns: [1, 1] */ declare function getGridStep(range: [Coord, Coord], step: Coord, boxSize: number): Coord; declare function snapStepFromGridStep(gridStep: [number, number]): [number, number]; /** * Given the tickStep and the graph's scale, find a * grid step. * Example: * gridStepFromTickStep(200, 0.2) // returns 100 */ declare function gridStepFromTickStep(tickStep: number, scale: number): number | null | undefined; /** * Given the range and a dimension, come up with the appropriate * scale. * Example: * scaleFromExtent([-25, 25], 500) // returns 10 */ declare function scaleFromExtent(extent: Coord, dimensionConstraint: number): number; /** * Return a reasonable tick step given extent and dimension. * (extent is [begin, end] of the domain.) * Example: * tickStepFromExtent([-10, 10], 300) // returns 2 */ declare function tickStepFromExtent(extent: Coord, dimensionConstraint: number): number; /** * Find a good tick step for the desired number of ticks in the range * Modified from d3.scale.linear: d3_scale_linearTickRange. * Thanks, mbostock! * Example: * tickStepFromNumTicks(50, 6) // returns 10 */ declare function tickStepFromNumTicks(span: number, numTicks: number): number; /** * Constrain tick steps intended for desktop size graphs * to something more suitable for mobile size graphs. * Specifically, we aim for 10 or fewer ticks per graph axis. */ declare function constrainedTickStepsFromTickSteps(tickSteps: [number, number], ranges: [Range, Range]): Coord; /** * Query String Parser * * Original from: * http://stackoverflow.com/questions/901115/get-querystring-values-in-javascript/2880929#2880929 */ declare function parseQueryString(query: string): QueryParams; /** * Query string adder * Works for URLs without #. * Original from: * http://stackoverflow.com/questions/5999118/add-or-update-query-string-parameter */ declare function updateQueryString(uri: string, key: string, value: string): string; /** * A more strict encodeURIComponent that escapes `()'!`s * Especially useful for creating URLs that are embeddable in markdown * * Adapted from * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent * This function and the above original available under the * CC-BY-SA 2.5 license. */ declare function strongEncodeURIComponent(str: string): string; declare function resetTouchHandlers(): void; /** * Extracts the location of a touch or mouse event, allowing you to pass * in a "mouseup", "mousedown", or "mousemove" event and receive the * correct coordinates. Shouldn't be used with "vmouse" events. */ declare function extractPointerLocation(event: any): Position | null | undefined; /** * Pass this function as the touchstart for an element to * avoid sending the touch to the mobile scratchpad */ declare function captureScratchpadTouchStart(e: React.TouchEvent): void; declare function getImageSize(url: string, callback: (width: number, height: number) => void): void; /** * Gets the word right before where the textarea cursor is * * @param {Element} textarea - The textarea DOM element * @return {JSON} - An object with the word and its starting and ending positions in the textarea */ declare function getWordBeforeCursor(textarea: HTMLTextAreaElement): WordAndPosition; /** * Moves the textarea cursor at the specified position * * @param {Element} textarea - The textarea DOM element * @param {int} pos - The position where the cursor will be moved */ declare function moveCursor(textarea: HTMLTextAreaElement, pos: number): void; declare const Util: { readonly inputPathsEqual: typeof inputPathsEqual; readonly nestedMap: (children: T | ReadonlyArray, func: (arg1: T) => M, context: unknown) => M | ReadonlyArray; readonly rWidgetRule: RegExp; readonly rTypeFromWidgetId: RegExp; readonly rWidgetParts: RegExp; readonly snowman: "☃"; readonly firstNumericalParse: typeof firstNumericalParse; readonly stringArrayOfSize: typeof stringArrayOfSize; readonly stringArrayOfSize2D: typeof stringArrayOfSize2D; readonly gridDimensionConfig: typeof gridDimensionConfig; readonly getGridStep: typeof getGridStep; readonly snapStepFromGridStep: typeof snapStepFromGridStep; readonly scaleFromExtent: typeof scaleFromExtent; readonly tickStepFromExtent: typeof tickStepFromExtent; readonly gridStepFromTickStep: typeof gridStepFromTickStep; readonly tickStepFromNumTicks: typeof tickStepFromNumTicks; readonly constrainedTickStepsFromTickSteps: typeof constrainedTickStepsFromTickSteps; readonly parseQueryString: typeof parseQueryString; readonly updateQueryString: typeof updateQueryString; readonly strongEncodeURIComponent: typeof strongEncodeURIComponent; readonly touchHandlers: TouchHandlers; readonly resetTouchHandlers: typeof resetTouchHandlers; readonly extractPointerLocation: typeof extractPointerLocation; readonly supportsPassiveEvents: () => boolean; readonly captureScratchpadTouchStart: typeof captureScratchpadTouchStart; readonly getImageSize: typeof getImageSize; readonly getImageSizeModern: typeof getImageSizeModern; readonly getRealImageUrl: typeof getRealImageUrl; readonly isLabeledSVG: typeof isLabeledSVG; readonly getBaseUrl: typeof getBaseUrl; readonly getSvgUrl: typeof getSvgUrl; readonly getDataUrl: typeof getDataUrl; readonly textarea: { readonly getWordBeforeCursor: typeof getWordBeforeCursor; readonly moveCursor: typeof moveCursor; }; readonly unescapeMathMode: (label: string) => string; }; export default Util;