options.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. import { I18N } from '../constants/i18n';
  2. /**
  3. * The interface for options.
  4. *
  5. * @since 3.0.0
  6. */
  7. export interface Options extends ResponsiveOptions {
  8. /**
  9. * The type of the slider.
  10. * - 'slide': A slider with the slide transition
  11. * - 'loop' : A carousel slider
  12. * - 'fade' : A slider with the fade transition. This does not support the perPage option.
  13. */
  14. type?: string;
  15. /**
  16. * The `role` attribute for the root element.
  17. * If the tag is `<section>`, this value will not be used. The default value is `'region'`.
  18. */
  19. role?: string;
  20. /**
  21. * Determines whether to disable any actions while the slider is transitioning.
  22. * Even if `false`, the slider forcibly waits for transition on the loop points.
  23. */
  24. waitForTransition?: boolean;
  25. /**
  26. * If `true`, the width of slides are determined by their width.
  27. * The `perPage` and `perMove` options should be `1`.
  28. */
  29. autoWidth?: boolean;
  30. /**
  31. * If `true`, the height of slides are determined by their height.
  32. * The `perPage` and `perMove` options should be `1`.
  33. */
  34. autoHeight?: boolean;
  35. /**
  36. * The start index.
  37. */
  38. start?: number;
  39. /**
  40. * Changes the arrow SVG path, like 'm7.61 0.807-2.12...'.
  41. */
  42. arrowPath?: string;
  43. /**
  44. * Determines whether to activate autoplay or not.
  45. * If `paused`, it will not begin when the slider becomes active.
  46. * You need to provided play/pause buttons or manually start it by `Autoplay#play()`.
  47. */
  48. autoplay?: boolean | 'pause';
  49. /**
  50. * The autoplay interval in milliseconds.
  51. */
  52. interval?: number;
  53. /**
  54. * Determines whether to pause autoplay on mouseover.
  55. */
  56. pauseOnHover?: boolean;
  57. /**
  58. * Determines whether to pause autoplay when the slider contains the active element (focused element).
  59. * This should be `true` for accessibility.
  60. */
  61. pauseOnFocus?: boolean;
  62. /**
  63. * Determines whether to reset the autoplay progress when it is requested to start again.
  64. */
  65. resetProgress?: boolean;
  66. /**
  67. * Enables lazy loading.
  68. * Provide the `src` by the `data-splide-lazy` or the `srcset` by the `data-splide-lazy-srcset`.
  69. * You may also provide `src` for the placeholder, but the value must be different with the data.
  70. *
  71. * - `false`: Disables lazy loading
  72. * - `'nearby'`: Starts loading only images around the active slide (page)
  73. * - `'sequential'`: Loads images sequentially
  74. */
  75. lazyLoad?: boolean | 'nearby' | 'sequential';
  76. /**
  77. * Determine how many pages (not slides) around the active slide should be loaded beforehand.
  78. * This only works when the `lazyLoad` option is `'nearby'`.
  79. */
  80. preloadPages?: number;
  81. /**
  82. * Enables keyboard shortcuts for the slider control.
  83. * - `true` or `'global'`: Listens to the `keydown` event of the document.
  84. * - 'focused': Listens to the `keydown` event of the slider root element with adding `tabindex="0"` to it.
  85. * - `false`: Disables keyboard shortcuts (default).
  86. */
  87. keyboard?: boolean | string;
  88. /**
  89. * Enables navigation by the mouse wheel.
  90. * Set `waitForTransition` to `ture` or provide the `wheelSleep` duration.
  91. */
  92. wheel?: boolean;
  93. /**
  94. * The threshold to cut off the small delta produced by inertia scroll.
  95. */
  96. wheelMinThreshold?: number;
  97. /**
  98. * The sleep time in milliseconds until accepting next wheel.
  99. * The timer starts when the transition begins.
  100. */
  101. wheelSleep?: number;
  102. /**
  103. * Determines whether to release the wheel event when the slider reaches the first or last slide.
  104. */
  105. releaseWheel?: boolean;
  106. /**
  107. * The direction of the slider.
  108. * - 'ltr': Left to right
  109. * - 'rtl': Right to left
  110. * - 'ttb': Top to bottom
  111. */
  112. direction?: 'ltr' | 'rtl' | 'ttb';
  113. /**
  114. * Converts the image `src` to the css `background-image` URL of the parent element.
  115. * This requires `fixedHeight` or `heightRatio` option.
  116. */
  117. cover?: boolean;
  118. /**
  119. * Determines whether to add `tabindex="0"` to visible slides or not.
  120. */
  121. slideFocus?: boolean;
  122. /**
  123. * If `true`, the slider makes slides clickable to navigate another slider.
  124. * Use `Splide#sync()` to sync multiple sliders.
  125. */
  126. isNavigation?: boolean;
  127. /**
  128. * Determines whether to trim spaces before/after the slider if the `focus` option is available.
  129. * - `true`: Trims spaces. The slider may stay on the same location even when requested to move.
  130. * - `'move'`: Trims spaces and focuses to move the slider when requested.
  131. */
  132. trimSpace?: boolean | 'move';
  133. /**
  134. * Updates the `is-active` status of slides just before moving the slider.
  135. */
  136. updateOnMove?: boolean;
  137. /**
  138. * If `min`, the media query for breakpoints will be `min-width`, or otherwise, `max-width`.
  139. */
  140. mediaQuery?: 'min' | 'max';
  141. /**
  142. * The selector to get focusable elements
  143. * where `tabindex="-1"` will be assigned when their ascendant slide is hidden.
  144. */
  145. focusableNodes?: string;
  146. /**
  147. * The selector for nodes that cannot be dragged.
  148. */
  149. noDrag?: string;
  150. /**
  151. * Enables the live region by `aria-live`.
  152. * If `true`, screen readers will read a content of each slide whenever slide changes.
  153. */
  154. live?: boolean;
  155. /**
  156. * Determines whether to use the Transition component or not.
  157. */
  158. useScroll?: boolean;
  159. /**
  160. * Options for specific breakpoints.
  161. *
  162. * @example
  163. * ```ts
  164. * {
  165. * 1000: {
  166. * perPage: 3,
  167. * gap : 20
  168. * },
  169. * 600: {
  170. * perPage: 1,
  171. * gap : 5,
  172. * },
  173. * }
  174. * ```
  175. */
  176. breakpoints?: Record<string | number, ResponsiveOptions>,
  177. /**
  178. * The collection of class names.
  179. */
  180. classes?: Record<string, string>;
  181. /**
  182. * The collection of i18n strings.
  183. */
  184. i18n?: Record<keyof typeof I18N | string, string>;
  185. }
  186. /**
  187. * The interface for options that can correspond with breakpoints.
  188. *
  189. * @since 3.0.0
  190. */
  191. export interface ResponsiveOptions {
  192. /**
  193. * Accepts arbitrary properties for extensions, although it's not ideal typing.
  194. */
  195. [ key: string ]: any;
  196. /**
  197. * The transition speed in milliseconds.
  198. */
  199. speed?: number;
  200. /**
  201. * Determines whether to rewind the slider or not.
  202. */
  203. rewind?: boolean;
  204. /**
  205. * The transition speed on rewind in milliseconds.
  206. */
  207. rewindSpeed?: number;
  208. /**
  209. * Allows to rewind by drag.
  210. * The slider `type` must be `slide` (or `undefined`) and the `drag` option must be enabled.
  211. */
  212. rewindByDrag?: boolean;
  213. /**
  214. * Defines the slider max width, accepting the CSS format such as 10em, 80vw.
  215. */
  216. width?: number | string;
  217. /**
  218. * Defines the slider height, accepting the CSS format.
  219. */
  220. height?: number | string;
  221. /**
  222. * Fixes width of slides, accepting the CSS format.
  223. * The slider will ignore the `perPage` option if you provide this value.
  224. */
  225. fixedWidth?: number | string;
  226. /**
  227. * Fixes height of slides, accepting the CSS format.
  228. * The slider will ignore the `heightRatio` option if you provide this value.
  229. */
  230. fixedHeight?: number | string;
  231. /**
  232. * Determines height of slides by the ratio to the slider width.
  233. * For example, when the slider width is `1000` and the ratio is `0.5`, the height will be `500`.
  234. */
  235. heightRatio?: number;
  236. /**
  237. * Determines the number of slides to display in a page.
  238. */
  239. perPage?: number;
  240. /**
  241. * Determines the number of slides to move at once.
  242. */
  243. perMove?: number;
  244. /**
  245. * Determine the number of clones on each side of the slider.
  246. * In most cases, you don't need to provide this value.
  247. */
  248. clones?: number;
  249. /**
  250. * Determines whether to clone status classes for clones or not.
  251. */
  252. cloneStatus?: boolean;
  253. /**
  254. * Determines which slide should be active if there are multiple slides in a page.
  255. * Numbers and `'center'` are acceptable.
  256. */
  257. focus?: number | 'center';
  258. /**
  259. * The gap between slides. The CSS format is acceptable, such as `1em`.
  260. */
  261. gap?: number | string;
  262. /**
  263. * Sets padding left/right or top/bottom of the slider.
  264. * The CSS format is acceptable, such as `1em`.
  265. *
  266. * @example
  267. * ```ts
  268. * // By number
  269. * padding: 10,
  270. *
  271. * // By the CSS format
  272. * padding: '1rem',
  273. *
  274. * // Specifies each value for a horizontal slider
  275. * padding: { left: 10, right: 20 },
  276. * padding: { left: '1rem', right: '2rem' },
  277. *
  278. * // Specified each value for a vertical slider
  279. * padding: { top: 10, bottom: 20 },
  280. * ```
  281. */
  282. padding?:
  283. | number
  284. | string
  285. | { left?: number | string, right?: number | string }
  286. | { top?: number | string, bottom?: number | string };
  287. /**
  288. * Determines whether to create/find arrows or not.
  289. */
  290. arrows?: boolean;
  291. /**
  292. * Determines whether to create pagination (indicator dots) or not.
  293. */
  294. pagination?: boolean;
  295. /**
  296. * Determines whether to enable keyboard shortcuts for pagination when it contains focus.
  297. * The default value is `true`.
  298. */
  299. paginationKeyboard?: boolean;
  300. /**
  301. * Explicitly sets the pagination direction that does not only affect appearance but also shortcuts and ARIA attributes.
  302. * The default value is same with the carousel direction.
  303. */
  304. paginationDirection?: Options['direction'];
  305. /**
  306. * The timing function for the CSS transition. For example, `linear`, ease or `cubic-bezier()`.
  307. */
  308. easing?: string;
  309. /**
  310. * The easing function for the drag free mode.
  311. * The default function is the `easeOutQuart` interpolation.
  312. */
  313. easingFunc?: ( t: number ) => number;
  314. /**
  315. * Allows to drag the slider by a mouse or swipe.
  316. * If `free`, the slider does not snap to a slide after drag.
  317. */
  318. drag?: boolean | 'free';
  319. /**
  320. * Snaps the closest slide in the drag-free mode.
  321. */
  322. snap?: boolean;
  323. /**
  324. * The required distance to start moving the slider by the touch action.
  325. * If you want to define the threshold for the mouse, provide an object.
  326. */
  327. dragMinThreshold?: number | { mouse: number, touch: number };
  328. /**
  329. * Determine the power of "flick". The larger number this is, the farther the slider runs.
  330. * Around 500 is recommended.
  331. */
  332. flickPower?: number;
  333. /**
  334. * Limits the number of pages to move by "flick".
  335. */
  336. flickMaxPages?: number;
  337. /**
  338. * Destroys the slider.
  339. */
  340. destroy?: boolean | 'completely';
  341. }