diff --git a/types/helpers/helpers.options.d.ts b/types/helpers/helpers.options.d.ts index 1b760161c57..65a00faa9cf 100644 --- a/types/helpers/helpers.options.d.ts +++ b/types/helpers/helpers.options.d.ts @@ -1,16 +1,7 @@ import { TRBL, TRBLCorners } from '../geometric'; +import { FontSpec } from '../index.esm'; -// Should be the same as FontSpec from the index.esm.ts -// Duplicate because the default one is scriptable and this one is not -interface NonScriptableFontSpec { - family: string; - size: number; - style: 'normal' | 'italic' | 'oblique' | 'initial' | 'inherit'; - weight: string | null; - lineHeight: number | string; -} - -export interface CanvasFontSpec extends NonScriptableFontSpec { +export interface CanvasFontSpec extends FontSpec { string: string; } /** @@ -18,7 +9,7 @@ export interface CanvasFontSpec extends NonScriptableFontSpec { * @param {object} options - A object that contains font options to be parsed. * @return {object} The font object. */ -export function toFont(options: Partial): CanvasFontSpec; +export function toFont(options: Partial): CanvasFontSpec; /** * Converts the given line height `value` in pixels for a specific font `size`. diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index 951b922ab20..8878cfc20b6 100644 --- a/types/index.esm.d.ts +++ b/types/index.esm.d.ts @@ -38,6 +38,7 @@ export interface ScriptableLineSegmentContext { export type Scriptable = T | ((ctx: TContext, options: AnyObject) => T | undefined); export type ScriptableOptions = { [P in keyof T]: Scriptable }; +export type ScriptableOrScriptableOptions = Scriptable | ScriptableOptions; export type ScriptableAndArray = readonly T[] | Scriptable; export type ScriptableAndArrayOptions = { [P in keyof T]: ScriptableAndArray }; @@ -1467,7 +1468,7 @@ export interface CoreChartOptions extends ParsingOption * base font * @see Defaults.font */ - font: Partial>; + font: Partial; /** * Resizes the chart canvas when its container does (important note...). * @default true @@ -1637,31 +1638,31 @@ export type AnimationOptions = { transitions: TransitionsSpec; }; -export interface FontSpec { +export interface FontSpec{ /** * Default font family for all text, follows CSS font-family options. * @default "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif" */ - family: Scriptable; + family: string; /** * Default font size (in px) for text. Does not apply to radialLinear scale point labels. * @default 12 */ - size: Scriptable; + size: number; /** * Default font style. Does not apply to tooltip title or footer. Does not apply to chart title. Follows CSS font-style options (i.e. normal, italic, oblique, initial, inherit) * @default 'normal' */ - style: Scriptable<'normal' | 'italic' | 'oblique' | 'initial' | 'inherit', ScriptableFontContext>; + style: 'normal' | 'italic' | 'oblique' | 'initial' | 'inherit'; /** * Default font weight (boldness). (see MDN). */ - weight: Scriptable; + weight: string | null; /** * Height of an individual line of text (see MDN). * @default 1.2 */ - lineHeight: Scriptable; + lineHeight: number | string; } export type TextAlign = 'left' | 'center' | 'right'; @@ -2303,7 +2304,7 @@ export interface LegendOptions { * Font of label * @see Defaults.font */ - font: Partial>; + font: ScriptableOrScriptableOptions, ScriptableChartContext>; /** * Padding between rows of colored boxes. * @default 10 @@ -2364,7 +2365,7 @@ export interface LegendOptions { /** * see Fonts */ - font: Partial>; + font: ScriptableOrScriptableOptions, ScriptableChartContext>; position: 'center' | 'start' | 'end'; padding?: number | ChartArea; /** @@ -2398,7 +2399,7 @@ export interface TitleOptions { * @see Defaults.color */ color: Color; - font: Partial>; + font: ScriptableOrScriptableOptions, ScriptableChartContext>; /** * Marks that this box should take the full width/height of the canvas (moving other boxes). If set to `false`, places the box above/beside the @@ -2629,7 +2630,7 @@ export interface TooltipOptions extends Cor * See Fonts * @default {weight: 'bold'} */ - titleFont: Scriptable>>, ScriptableTooltipContext>; + titleFont: ScriptableOrScriptableOptions, ScriptableTooltipContext>; /** * Spacing to add to top and bottom of each title line. * @default 2 @@ -2659,7 +2660,7 @@ export interface TooltipOptions extends Cor * See Fonts. * @default {} */ - bodyFont: Scriptable>>, ScriptableTooltipContext>; + bodyFont: ScriptableOrScriptableOptions, ScriptableTooltipContext>; /** * Horizontal alignment of the body text lines. * @default 'left' @@ -2684,7 +2685,7 @@ export interface TooltipOptions extends Cor * See Fonts * @default {weight: 'bold'} */ - footerFont: Scriptable>>, ScriptableTooltipContext>; + footerFont: ScriptableOrScriptableOptions, ScriptableTooltipContext>; /** * Horizontal alignment of the footer text lines. * @default 'left' @@ -2919,7 +2920,7 @@ export interface TickOptions { /** * see Fonts */ - font: Scriptable>, ScriptableScaleContext>; + font: ScriptableOrScriptableOptions, ScriptableScaleContext>; /** * Sets the offset of the tick labels from the axis */ @@ -3092,7 +3093,7 @@ export interface CartesianScaleOptions extends CoreScaleOptions { /** Color of the axis label. */ color: Color; /** Information about the axis title font. */ - font: Partial>; + font: ScriptableOrScriptableOptions, ScriptableCartesianScaleContext>; /** Padding to apply around scale labels. */ padding: number | { /** Padding on the (relative) top side of this axis label. */ @@ -3409,7 +3410,7 @@ export type RadialLinearScaleOptions = CoreScaleOptions & { color: Scriptable; /** */ - font: Scriptable>, ScriptableScalePointLabelContext>; + font: ScriptableOrScriptableOptions, ScriptableScalePointLabelContext>; /** * Callback function to transform data labels to point labels. The default implementation simply returns the current string.