UNPKG

highcharts

Version:
1,318 lines (1,311 loc) 666 kB
/** * @license Highcharts JS v11.3.0 (2024-01-10) * * Accessibility module * * (c) 2010-2024 Highsoft AS * Author: Oystein Moseng * * License: www.highcharts.com/license */ (function (factory) { if (typeof module === 'object' && module.exports) { factory['default'] = factory; module.exports = factory; } else if (typeof define === 'function' && define.amd) { define('highcharts/modules/accessibility', ['highcharts'], function (Highcharts) { factory(Highcharts); factory.Highcharts = Highcharts; return factory; }); } else { factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined); } }(function (Highcharts) { 'use strict'; var _modules = Highcharts ? Highcharts._modules : {}; function _registerModule(obj, path, args, fn) { if (!obj.hasOwnProperty(path)) { obj[path] = fn.apply(null, args); if (typeof CustomEvent === 'function') { window.dispatchEvent(new CustomEvent( 'HighchartsModuleLoaded', { detail: { path: path, module: obj[path] } } )); } } } _registerModule(_modules, 'Accessibility/Utils/HTMLUtilities.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) { /* * * * (c) 2009-2024 Øystein Moseng * * Utility functions for accessibility module. * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { doc, win } = H; const { css } = U; /* * * * Constants * * */ const simulatedEventTarget = win.EventTarget && new win.EventTarget() || 'none'; /* * * * Functions * * */ /* eslint-disable valid-jsdoc */ /** * @private * @param {Highcharts.HTMLDOMElement} el * @param {string} className * @return {void} */ function addClass(el, className) { if (el.classList) { el.classList.add(className); } else if (el.className.indexOf(className) < 0) { // Note: Dumb check for class name exists, should be fine for practical // use cases, but will return false positives if the element has a class // that contains the className. el.className += ' ' + className; } } /** * @private * @param {Highcharts.HTMLDOMElement} el * @param {string} className * @return {void} */ function removeClass(el, className) { if (el.classList) { el.classList.remove(className); } else { // Note: Dumb logic that will break if the element has a class name that // consists of className plus something else. el.className = el.className.replace(new RegExp(className, 'g'), ''); } } /** * Utility function to clone a mouse event for re-dispatching. * @private */ function cloneMouseEvent(e) { if (typeof win.MouseEvent === 'function') { return new win.MouseEvent(e.type, e); } // No MouseEvent support, try using initMouseEvent if (doc.createEvent) { const evt = doc.createEvent('MouseEvent'); if (evt.initMouseEvent) { evt.initMouseEvent(e.type, e.bubbles, // #10561, #12161 e.cancelable, e.view || win, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget); return evt; } } return getFakeMouseEvent(e.type); } /** * Utility function to clone a touch event for re-dispatching. * @private */ function cloneTouchEvent(e) { const touchListToTouchArray = (l) => { const touchArray = []; for (let i = 0; i < l.length; ++i) { const item = l.item(i); if (item) { touchArray.push(item); } } return touchArray; }; if (typeof win.TouchEvent === 'function') { const newEvent = new win.TouchEvent(e.type, { touches: touchListToTouchArray(e.touches), targetTouches: touchListToTouchArray(e.targetTouches), changedTouches: touchListToTouchArray(e.changedTouches), ctrlKey: e.ctrlKey, shiftKey: e.shiftKey, altKey: e.altKey, metaKey: e.metaKey, bubbles: e.bubbles, cancelable: e.cancelable, composed: e.composed, detail: e.detail, view: e.view }); if (e.defaultPrevented) { newEvent.preventDefault(); } return newEvent; } const fakeEvt = cloneMouseEvent(e); fakeEvt.touches = e.touches; fakeEvt.changedTouches = e.changedTouches; fakeEvt.targetTouches = e.targetTouches; return fakeEvt; } /** * @private */ function escapeStringForHTML(str) { return str .replace(/&/g, '&amp;') .replace(/</g, '&lt;') .replace(/>/g, '&gt;') .replace(/"/g, '&quot;') .replace(/'/g, '&#x27;') .replace(/\//g, '&#x2F;'); } /** * Get an element by ID * @private */ function getElement(id) { return doc.getElementById(id); } /** * Get a fake mouse event of a given type. If relatedTarget is not given, * it will point to simulatedEventTarget, as an indicator that the event * is fake. * @private */ function getFakeMouseEvent(type, position, relatedTarget) { const pos = position || { x: 0, y: 0 }; if (typeof win.MouseEvent === 'function') { return new win.MouseEvent(type, { bubbles: true, cancelable: true, composed: true, button: 0, buttons: 1, relatedTarget: relatedTarget || simulatedEventTarget, view: win, detail: type === 'click' ? 1 : 0, screenX: pos.x, screenY: pos.y, clientX: pos.x, clientY: pos.y }); } // No MouseEvent support, try using initMouseEvent if (doc.createEvent) { const evt = doc.createEvent('MouseEvent'); if (evt.initMouseEvent) { evt.initMouseEvent(type, true, // Bubble true, // Cancel win, // View type === 'click' ? 1 : 0, // Detail // Coords pos.x, pos.y, pos.x, pos.y, // Pressed keys false, false, false, false, 0, // button null // related target ); return evt; } } return { type: type }; } /** * Get an appropriate heading level for an element. Corresponds to the * heading level below the previous heading in the DOM. * * Note: Only detects previous headings in the DOM that are siblings, * ancestors, or previous siblings of ancestors. Headings that are nested below * siblings of ancestors (cousins et.al) are not picked up. This is because it * is ambiguous whether or not the nesting is for layout purposes or indicates a * separate section. * * @private * @param {Highcharts.HTMLDOMElement} [element] * @return {string} The heading tag name (h1, h2 etc). * If no nearest heading is found, "p" is returned. */ function getHeadingTagNameForElement(element) { const getIncreasedHeadingLevel = (tagName) => { const headingLevel = parseInt(tagName.slice(1), 10), newLevel = Math.min(6, headingLevel + 1); return 'h' + newLevel; }; const isHeading = (tagName) => /H[1-6]/.test(tagName); const getPreviousSiblingsHeading = (el) => { let sibling = el; while (sibling = sibling.previousSibling) { // eslint-disable-line const tagName = sibling.tagName || ''; if (isHeading(tagName)) { return tagName; } } return ''; }; const getHeadingRecursive = (el) => { const prevSiblingsHeading = getPreviousSiblingsHeading(el); if (prevSiblingsHeading) { return getIncreasedHeadingLevel(prevSiblingsHeading); } // No previous siblings are headings, try parent node const parent = el.parentElement; if (!parent) { return 'p'; } const parentTagName = parent.tagName; if (isHeading(parentTagName)) { return getIncreasedHeadingLevel(parentTagName); } return getHeadingRecursive(parent); }; return getHeadingRecursive(element); } /** * Remove an element from the DOM. * @private * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} [element] * @return {void} */ function removeElement(element) { if (element && element.parentNode) { element.parentNode.removeChild(element); } } /** * Remove all child nodes from an element. * @private * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} [element] * @return {void} */ function removeChildNodes(element) { while (element.lastChild) { element.removeChild(element.lastChild); } } /** * Utility function. Reverses child nodes of a DOM element. * @private */ function reverseChildNodes(node) { let i = node.childNodes.length; while (i--) { node.appendChild(node.childNodes[i]); } } /** * Used for aria-label attributes, painting on a canvas will fail if the * text contains tags. * @private */ function stripHTMLTagsFromString(str, isForExport = false) { return (typeof str === 'string') ? (isForExport ? str.replace(/<\/?[^>]+(>|$)/g, '') : str.replace(/<\/?(?!\s)[^>]+(>|$)/g, '')) : str; } /** * Utility function for hiding an element visually, but still keeping it * available to screen reader users. * @private */ function visuallyHideElement(element) { css(element, { position: 'absolute', width: '1px', height: '1px', overflow: 'hidden', whiteSpace: 'nowrap', clip: 'rect(1px, 1px, 1px, 1px)', marginTop: '-3px', '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=1)', filter: 'alpha(opacity=1)', opacity: 0.01 }); } /* * * * Default Export * * */ const HTMLUtilities = { addClass, cloneMouseEvent, cloneTouchEvent, escapeStringForHTML, getElement, getFakeMouseEvent, getHeadingTagNameForElement, removeChildNodes, removeClass, removeElement, reverseChildNodes, simulatedEventTarget, stripHTMLTagsFromString, visuallyHideElement }; return HTMLUtilities; }); _registerModule(_modules, 'Accessibility/A11yI18n.js', [_modules['Core/Templating.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (F, H, U) { /* * * * Accessibility module - internationalization support * * (c) 2010-2024 Highsoft AS * Author: Øystein Moseng * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { format } = F; const { composed } = H; const { getNestedProperty, pick, pushUnique } = U; /* * * * Composition * * */ var A11yI18nComposition; (function (A11yI18nComposition) { /* * * * Declarations * * */ /* * * * Functions * * */ /** * @private */ function compose(ChartClass) { if (pushUnique(composed, compose)) { const chartProto = ChartClass.prototype; chartProto.langFormat = langFormat; } } A11yI18nComposition.compose = compose; /** * i18n utility function. Format a single array or plural statement in a * format string. If the statement is not an array or plural statement, * returns the statement within brackets. Invalid array statements return * an empty string. * * @private * @function formatExtendedStatement * @param {string} statement * @param {Highcharts.Dictionary<*>} ctx * Context to apply to the format string. */ function formatExtendedStatement(statement, ctx) { const eachStart = statement.indexOf('#each('), pluralStart = statement.indexOf('#plural('), indexStart = statement.indexOf('['), indexEnd = statement.indexOf(']'); let arr, result; // Dealing with an each-function? if (eachStart > -1) { const eachEnd = statement.slice(eachStart).indexOf(')') + eachStart, preEach = statement.substring(0, eachStart), postEach = statement.substring(eachEnd + 1), eachStatement = statement.substring(eachStart + 6, eachEnd), eachArguments = eachStatement.split(','); let lenArg = Number(eachArguments[1]), len; result = ''; arr = getNestedProperty(eachArguments[0], ctx); if (arr) { lenArg = isNaN(lenArg) ? arr.length : lenArg; len = lenArg < 0 ? arr.length + lenArg : Math.min(lenArg, arr.length); // Overshoot // Run through the array for the specified length for (let i = 0; i < len; ++i) { result += preEach + arr[i] + postEach; } } return result.length ? result : ''; } // Dealing with a plural-function? if (pluralStart > -1) { const pluralEnd = (statement.slice(pluralStart).indexOf(')') + pluralStart), pluralStatement = statement.substring(pluralStart + 8, pluralEnd), pluralArguments = pluralStatement.split(','), num = Number(getNestedProperty(pluralArguments[0], ctx)); switch (num) { case 0: result = pick(pluralArguments[4], pluralArguments[1]); break; case 1: result = pick(pluralArguments[2], pluralArguments[1]); break; case 2: result = pick(pluralArguments[3], pluralArguments[1]); break; default: result = pluralArguments[1]; } return result ? stringTrim(result) : ''; } // Array index if (indexStart > -1) { const arrayName = statement.substring(0, indexStart), ix = Number(statement.substring(indexStart + 1, indexEnd)); let val; arr = getNestedProperty(arrayName, ctx); if (!isNaN(ix) && arr) { if (ix < 0) { val = arr[arr.length + ix]; // Handle negative overshoot if (typeof val === 'undefined') { val = arr[0]; } } else { val = arr[ix]; // Handle positive overshoot if (typeof val === 'undefined') { val = arr[arr.length - 1]; } } } return typeof val !== 'undefined' ? val : ''; } // Standard substitution, delegate to format or similar return '{' + statement + '}'; } /* eslint-disable max-len */ /** * i18n formatting function. Extends Highcharts.format() functionality by * also handling arrays and plural conditionals. Arrays can be indexed as * follows: * * - Format: 'This is the first index: {myArray[0]}. The last: {myArray[-1]}.' * * - Context: { myArray: [0, 1, 2, 3, 4, 5] } * * - Result: 'This is the first index: 0. The last: 5.' * * * They can also be iterated using the #each() function. This will repeat * the contents of the bracket expression for each element. Example: * * - Format: 'List contains: {#each(myArray)cm }' * * - Context: { myArray: [0, 1, 2] } * * - Result: 'List contains: 0cm 1cm 2cm ' * * * The #each() function optionally takes a length parameter. If positive, * this parameter specifies the max number of elements to iterate through. * If negative, the function will subtract the number from the length of the * array. Use this to stop iterating before the array ends. Example: * * - Format: 'List contains: {#each(myArray, -1) }and {myArray[-1]}.' * * - Context: { myArray: [0, 1, 2, 3] } * * - Result: 'List contains: 0, 1, 2, and 3.' * * * Use the #plural() function to pick a string depending on whether or not a * context object is 1. Arguments are #plural(obj, plural, singular). * Example: * * - Format: 'Has {numPoints} {#plural(numPoints, points, point}.' * * - Context: { numPoints: 5 } * * - Result: 'Has 5 points.' * * * Optionally there are additional parameters for dual and none: * #plural(obj, plural, singular, dual, none). Example: * * - Format: 'Has {#plural(numPoints, many points, one point, two points, * none}.' * * - Context: { numPoints: 2 } * * - Result: 'Has two points.' * * * The dual or none parameters will take precedence if they are supplied. * * @requires modules/accessibility * * @function Highcharts.i18nFormat * * @param {string} formatString * The string to format. * * @param {Highcharts.Dictionary<*>} context * Context to apply to the format string. * * @param {Highcharts.Chart} chart * A `Chart` instance with a time object and numberFormatter, passed on to * format(). * * @deprecated * * @return {string} * The formatted string. */ function i18nFormat(formatString, context, chart) { const getFirstBracketStatement = (sourceStr, offset) => { const str = sourceStr.slice(offset || 0), startBracket = str.indexOf('{'), endBracket = str.indexOf('}'); if (startBracket > -1 && endBracket > startBracket) { return { statement: str.substring(startBracket + 1, endBracket), begin: offset + startBracket + 1, end: offset + endBracket }; } }, tokens = []; let bracketRes, constRes, cursor = 0; // Tokenize format string into bracket statements and constants do { bracketRes = getFirstBracketStatement(formatString, cursor); constRes = formatString.substring(cursor, bracketRes && bracketRes.begin - 1); // If we have constant content before this bracket statement, add it if (constRes.length) { tokens.push({ value: constRes, type: 'constant' }); } // Add the bracket statement if (bracketRes) { tokens.push({ value: bracketRes.statement, type: 'statement' }); } cursor = bracketRes ? bracketRes.end + 1 : cursor + 1; } while (bracketRes); // Perform the formatting. The formatArrayStatement function returns // the statement in brackets if it is not an array statement, which // means it gets picked up by format below. tokens.forEach((token) => { if (token.type === 'statement') { token.value = formatExtendedStatement(token.value, context); } }); // Join string back together and pass to format to pick up non-array // statements. return format(tokens.reduce((acc, cur) => acc + cur.value, ''), context, chart); } A11yI18nComposition.i18nFormat = i18nFormat; /* eslint-enable max-len */ /** * Apply context to a format string from lang options of the chart. * * @requires modules/accessibility * * @function Highcharts.Chart#langFormat * * @param {string} langKey * Key (using dot notation) into lang option structure. * * @param {Highcharts.Dictionary<*>} context * Context to apply to the format string. * * @return {string} * The formatted string. */ function langFormat(langKey, context) { const keys = langKey.split('.'); let formatString = this.options.lang, i = 0; for (; i < keys.length; ++i) { formatString = formatString && formatString[keys[i]]; } return typeof formatString === 'string' ? i18nFormat(formatString, context, this) : ''; } /** * @private * @function stringTrim * * @param {string} str * The input string * * @return {string} * The trimmed string */ function stringTrim(str) { return str.trim && str.trim() || str.replace(/^\s+|\s+$/g, ''); } })(A11yI18nComposition || (A11yI18nComposition = {})); /* * * * Default Export * * */ return A11yI18nComposition; }); _registerModule(_modules, 'Accessibility/Utils/ChartUtilities.js', [_modules['Core/Globals.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Core/Utilities.js']], function (H, HU, U) { /* * * * (c) 2009-2024 Øystein Moseng * * Utils for dealing with charts. * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { doc } = H; const { stripHTMLTagsFromString: stripHTMLTags } = HU; const { defined, find, fireEvent } = U; /* * * * Functions * * */ /* eslint-disable valid-jsdoc */ /** * Fire an event on an element that is either wrapped by Highcharts, * or a DOM element. * @private */ function fireEventOnWrappedOrUnwrappedElement(el, eventObject) { const type = eventObject.type; const hcEvents = el.hcEvents; if (!!doc.createEvent && (el.dispatchEvent || el.fireEvent)) { if (el.dispatchEvent) { el.dispatchEvent(eventObject); } else { el.fireEvent(type, eventObject); } } else if (hcEvents && hcEvents[type]) { fireEvent(el, type, eventObject); } else if (el.element) { fireEventOnWrappedOrUnwrappedElement(el.element, eventObject); } } /** * @private */ function getChartTitle(chart) { return stripHTMLTags(chart.options.title.text || chart.langFormat('accessibility.defaultChartTitle', { chart: chart }), chart.renderer.forExport); } /** * Return string with the axis name/title. * @private */ function getAxisDescription(axis) { return axis && (axis.options.accessibility?.description || axis.axisTitle?.textStr || axis.options.id || axis.categories && 'categories' || axis.dateTime && 'Time' || 'values'); } /** * Return string with text description of the axis range. * @private * @param {Highcharts.Axis} axis * The axis to get range desc of. * @return {string} * A string with the range description for the axis. */ function getAxisRangeDescription(axis) { const axisOptions = axis.options || {}; // Handle overridden range description if (axisOptions.accessibility && typeof axisOptions.accessibility.rangeDescription !== 'undefined') { return axisOptions.accessibility.rangeDescription; } // Handle category axes if (axis.categories) { return getCategoryAxisRangeDesc(axis); } // Use time range, not from-to? if (axis.dateTime && (axis.min === 0 || axis.dataMin === 0)) { return getAxisTimeLengthDesc(axis); } // Just use from and to. // We have the range and the unit to use, find the desc format return getAxisFromToDescription(axis); } /** * Describe the range of a category axis. * @private */ function getCategoryAxisRangeDesc(axis) { const chart = axis.chart; if (axis.dataMax && axis.dataMin) { return chart.langFormat('accessibility.axis.rangeCategories', { chart: chart, axis: axis, numCategories: axis.dataMax - axis.dataMin + 1 }); } return ''; } /** * Describe the length of the time window shown on an axis. * @private */ function getAxisTimeLengthDesc(axis) { const chart = axis.chart, range = {}, min = axis.dataMin || axis.min || 0, max = axis.dataMax || axis.max || 0; let rangeUnit = 'Seconds'; range.Seconds = (max - min) / 1000; range.Minutes = range.Seconds / 60; range.Hours = range.Minutes / 60; range.Days = range.Hours / 24; ['Minutes', 'Hours', 'Days'].forEach(function (unit) { if (range[unit] > 2) { rangeUnit = unit; } }); const rangeValue = range[rangeUnit].toFixed(rangeUnit !== 'Seconds' && rangeUnit !== 'Minutes' ? 1 : 0 // Use decimals for days/hours ); // We have the range and the unit to use, find the desc format return chart.langFormat('accessibility.axis.timeRange' + rangeUnit, { chart: chart, axis: axis, range: rangeValue.replace('.0', '') }); } /** * Describe an axis from-to range. * @private */ function getAxisFromToDescription(axis) { const chart = axis.chart, options = chart.options, dateRangeFormat = (options && options.accessibility && options.accessibility.screenReaderSection.axisRangeDateFormat || ''), extremes = { min: axis.dataMin || axis.min || 0, max: axis.dataMax || axis.max || 0 }, format = function (key) { return axis.dateTime ? chart.time.dateFormat(dateRangeFormat, extremes[key]) : extremes[key].toString(); }; return chart.langFormat('accessibility.axis.rangeFromTo', { chart: chart, axis: axis, rangeFrom: format('min'), rangeTo: format('max') }); } /** * Get the DOM element for the first point in the series. * @private * @param {Highcharts.Series} series * The series to get element for. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined} * The DOM element for the point. */ function getSeriesFirstPointElement(series) { if (series.points && series.points.length) { const firstPointWithGraphic = find(series.points, (p) => !!p.graphic); return (firstPointWithGraphic && firstPointWithGraphic.graphic && firstPointWithGraphic.graphic.element); } } /** * Get the DOM element for the series that we put accessibility info on. * @private * @param {Highcharts.Series} series * The series to get element for. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined} * The DOM element for the series */ function getSeriesA11yElement(series) { const firstPointEl = getSeriesFirstPointElement(series); return (firstPointEl && firstPointEl.parentNode || series.graph && series.graph.element || series.group && series.group.element); // Could be tracker series depending on series type } /** * Remove aria-hidden from element. Also unhides parents of the element, and * hides siblings that are not explicitly unhidden. * @private */ function unhideChartElementFromAT(chart, element) { element.setAttribute('aria-hidden', false); if (element === chart.renderTo || !element.parentNode || element.parentNode === doc.body // #16126: Full screen printing ) { return; } // Hide siblings unless their hidden state is already explicitly set Array.prototype.forEach.call(element.parentNode.childNodes, function (node) { if (!node.hasAttribute('aria-hidden')) { node.setAttribute('aria-hidden', true); } }); // Repeat for parent unhideChartElementFromAT(chart, element.parentNode); } /** * Hide series from screen readers. * @private */ function hideSeriesFromAT(series) { const seriesEl = getSeriesA11yElement(series); if (seriesEl) { seriesEl.setAttribute('aria-hidden', true); } } /** * Get series objects by series name. * @private */ function getSeriesFromName(chart, name) { if (!name) { return chart.series; } return (chart.series || []).filter(function (s) { return s.name === name; }); } /** * Get point in a series from x/y values. * @private */ function getPointFromXY(series, x, y) { let i = series.length, res; while (i--) { res = find(series[i].points || [], function (p) { return p.x === x && p.y === y; }); if (res) { return res; } } } /** * Get relative position of point on an x/y axis from 0 to 1. * @private */ function getRelativePointAxisPosition(axis, point) { if (!defined(axis.dataMin) || !defined(axis.dataMax)) { return 0; } const axisStart = axis.toPixels(axis.dataMin), axisEnd = axis.toPixels(axis.dataMax), // We have to use pixel position because of axis breaks, log axis etc. positionProp = axis.coll === 'xAxis' ? 'x' : 'y', pointPos = axis.toPixels(point[positionProp] || 0); return (pointPos - axisStart) / (axisEnd - axisStart); } /** * Get relative position of point on an x/y axis from 0 to 1. * @private */ function scrollAxisToPoint(point) { const xAxis = point.series.xAxis, yAxis = point.series.yAxis, axis = (xAxis && xAxis.scrollbar ? xAxis : yAxis), scrollbar = (axis && axis.scrollbar); if (scrollbar && defined(scrollbar.to) && defined(scrollbar.from)) { const range = scrollbar.to - scrollbar.from; const pos = getRelativePointAxisPosition(axis, point); scrollbar.updatePosition(pos - range / 2, pos + range / 2); fireEvent(scrollbar, 'changed', { from: scrollbar.from, to: scrollbar.to, trigger: 'scrollbar', DOMEvent: null }); } } /* * * * Default Export * * */ const ChartUtilities = { fireEventOnWrappedOrUnwrappedElement, getChartTitle, getAxisDescription, getAxisRangeDescription, getPointFromXY, getSeriesFirstPointElement, getSeriesFromName, getSeriesA11yElement, unhideChartElementFromAT, hideSeriesFromAT, scrollAxisToPoint }; return ChartUtilities; }); _registerModule(_modules, 'Accessibility/Utils/DOMElementProvider.js', [_modules['Core/Globals.js'], _modules['Accessibility/Utils/HTMLUtilities.js']], function (H, HU) { /* * * * (c) 2009-2024 Øystein Moseng * * Class that can keep track of elements added to DOM and clean them up on * destroy. * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { doc } = H; const { removeElement } = HU; /* * * * Class * * */ /** * @private */ class DOMElementProvider { /* * * * Constructor * * */ constructor() { this.elements = []; } /** * Create an element and keep track of it for later removal. * Same args as document.createElement * @private */ createElement() { const el = doc.createElement.apply(doc, arguments); this.elements.push(el); return el; } /** * Destroy all created elements, removing them from the DOM. * @private */ destroyCreatedElements() { this.elements.forEach(function (element) { removeElement(element); }); this.elements = []; } } /* * * * Default Export * * */ return DOMElementProvider; }); _registerModule(_modules, 'Accessibility/Utils/EventProvider.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) { /* * * * (c) 2009-2024 Øystein Moseng * * Class that can keep track of events added, and clean them up on destroy. * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { addEvent } = U; /* * * * Class * * */ /** * @private */ class EventProvider { /* * * * Constructor * * */ constructor() { this.eventRemovers = []; } /** * Add an event to an element and keep track of it for later removal. * Same args as Highcharts.addEvent. * @private */ addEvent() { const remover = addEvent.apply(H, arguments); this.eventRemovers.push(remover); return remover; } /** * Remove all added events. * @private */ removeAddedEvents() { this.eventRemovers.forEach((remover) => remover()); this.eventRemovers = []; } } /* * * * Default Export * * */ return EventProvider; }); _registerModule(_modules, 'Accessibility/AccessibilityComponent.js', [_modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Utils/DOMElementProvider.js'], _modules['Accessibility/Utils/EventProvider.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Core/Utilities.js']], function (CU, DOMElementProvider, EventProvider, HU, U) { /* * * * (c) 2009-2024 Øystein Moseng * * Accessibility component class definition * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { fireEventOnWrappedOrUnwrappedElement } = CU; const { getFakeMouseEvent } = HU; const { extend } = U; /* * * * Class * * */ /** * The AccessibilityComponent base class, representing a part of the chart that * has accessibility logic connected to it. This class can be inherited from to * create a custom accessibility component for a chart. * * Components should take care to destroy added elements and unregister event * handlers on destroy. This is handled automatically if using this.addEvent and * this.createElement. * * @sample highcharts/accessibility/custom-component * Custom accessibility component * * @requires module:modules/accessibility * @class * @name Highcharts.AccessibilityComponent */ class AccessibilityComponent { /* * * * Functions * * */ /** * Initialize the class * @private * @param {Highcharts.Chart} chart The chart object * @param {Highcharts.ProxyProvider} proxyProvider The proxy provider of the accessibility module */ initBase(chart, proxyProvider) { this.chart = chart; this.eventProvider = new EventProvider(); this.domElementProvider = new DOMElementProvider(); this.proxyProvider = proxyProvider; // Key code enum for common keys this.keyCodes = { left: 37, right: 39, up: 38, down: 40, enter: 13, space: 32, esc: 27, tab: 9, pageUp: 33, pageDown: 34, end: 35, home: 36 }; } /** * Add an event to an element and keep track of it for later removal. * See EventProvider for details. * @private */ addEvent(el, type, fn, options) { return this.eventProvider.addEvent(el, type, fn, options); } /** * Create an element and keep track of it for later removal. * See DOMElementProvider for details. * @private */ createElement(tagName, options) { return this.domElementProvider.createElement(tagName, options); } /** * Fire a fake click event on an element. It is useful to have this on * AccessibilityComponent for users of custom components. */ fakeClickEvent(el) { const fakeEvent = getFakeMouseEvent('click'); fireEventOnWrappedOrUnwrappedElement(el, fakeEvent); } /** * Remove traces of the component. * @private */ destroyBase() { this.domElementProvider.destroyCreatedElements(); this.eventProvider.removeAddedEvents(); } } extend(AccessibilityComponent.prototype, /** @lends Highcharts.AccessibilityComponent */ { /** * Called on component initialization. */ init() { }, /** * Get keyboard navigation handler for this component. * @private */ getKeyboardNavigation: function () { }, /** * Called on updates to the chart, including options changes. * Note that this is also called on first render of chart. */ onChartUpdate() { }, /** * Called on every chart render. */ onChartRender() { }, /** * Called when accessibility is disabled or chart is destroyed. */ destroy() { } }); /* * * * Default Export * * */ return AccessibilityComponent; }); _registerModule(_modules, 'Accessibility/KeyboardNavigationHandler.js', [_modules['Core/Utilities.js']], function (U) { /* * * * (c) 2009-2024 Øystein Moseng * * Keyboard navigation handler base class definition * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { find } = U; /* * * * Class * * */ /** * Define a keyboard navigation handler for use with a * Highcharts.AccessibilityComponent instance. This functions as an abstraction * layer for keyboard navigation, and defines a map of keyCodes to handler * functions. * * @requires module:modules/accessibility * * @sample highcharts/accessibility/custom-component * Custom accessibility component * * @class * @name Highcharts.KeyboardNavigationHandler * * @param {Highcharts.Chart} chart * The chart this module should act on. * * @param {Highcharts.KeyboardNavigationHandlerOptionsObject} options * Options for the keyboard navigation handler. */ class KeyboardNavigationHandler { /* * * * Constructor * * */ constructor(chart, options) { this.chart = chart; this.keyCodeMap = options.keyCodeMap || []; this.validate = options.validate; this.init = options.init; this.terminate = options.terminate; // Response enum this.response = { success: 1, prev: 2, next: 3, noHandler: 4, fail: 5 // Handler failed }; } /* * * * Functions * * */ /** * Find handler function(s) for key code in the keyCodeMap and run it. * * @function KeyboardNavigationHandler#run * @param {global.KeyboardEvent} e * @return {number} Returns a response code indicating whether the run was * a success/fail/unhandled, or if we should move to next/prev module. */ run(e) { const keyCode = e.which || e.keyCode; let response = this.response.noHandler; const handlerCodeSet = find(this.keyCodeMap, function (codeSet) { return codeSet[0].indexOf(keyCode) > -1; }); if (handlerCodeSet) { response = handlerCodeSet[1].call(this, keyCode, e); } else if (keyCode === 9) { // Default tab handler, move to next/prev module response = this.response[e.shiftKey ? 'prev' : 'next']; } return response; } } /* * * * Default Export * * */ /* * * * API Declarations * * */ /** * Options for the keyboard navigation handler. * * @interface Highcharts.KeyboardNavigationHandlerOptionsObject */ /** * An array containing pairs of an array of keycodes, mapped to a handler * function. When the keycode is received, the handler is called with the * keycode as parameter. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#keyCodeMap * @type {Array<Array<Array<number>, Function>>} */ /** * Function to run on initialization of module. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#init * @type {Function} */ /** * Function to run before moving to next/prev module. Receives moving direction * as parameter: +1 for next, -1 for previous. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#terminate * @type {Function|undefined} */ /** * Function to run to validate module. Should return