ui_utils.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. export type GetVisibleElementsParameters = {
  2. /**
  3. * - A container that can possibly scroll.
  4. */
  5. scrollEl: HTMLElement;
  6. /**
  7. * - Objects with a `div` property that contains an
  8. * HTMLElement, which should all be descendants of `scrollEl` satisfying the
  9. * relevant layout assumptions.
  10. */
  11. views: any[];
  12. /**
  13. * - If `true`, the returned elements are
  14. * sorted in descending order of the percent of their padding box that is
  15. * visible. The default value is `false`.
  16. */
  17. sortByVisibility: boolean;
  18. /**
  19. * - If `true`, the elements are assumed to be
  20. * laid out horizontally instead of vertically. The default value is `false`.
  21. */
  22. horizontal: boolean;
  23. /**
  24. * - If `true`, the `scrollEl` container is assumed to
  25. * be in right-to-left mode. The default value is `false`.
  26. */
  27. rtl: boolean;
  28. };
  29. export type WaitOnEventOrTimeoutParameters = {
  30. /**
  31. * - The event target, can for example be:
  32. * `window`, `document`, a DOM element, or an {EventBus} instance.
  33. */
  34. target: Object;
  35. /**
  36. * - The name of the event.
  37. */
  38. name: string;
  39. /**
  40. * - The delay, in milliseconds, after which the
  41. * timeout occurs (if the event wasn't already dispatched).
  42. */
  43. delay: number;
  44. };
  45. /**
  46. * Promise that is resolved when DOM window becomes visible.
  47. */
  48. export const animationStarted: Promise<any>;
  49. /**
  50. * Converts API PageLayout values to the format used by `BaseViewer`.
  51. * NOTE: This is supported to the extent that the viewer implements the
  52. * necessary Scroll/Spread modes (since SinglePage, TwoPageLeft,
  53. * and TwoPageRight all suggests using non-continuous scrolling).
  54. * @param {string} mode - The API PageLayout value.
  55. * @returns {number} A value from {SpreadMode}.
  56. */
  57. export function apiPageLayoutToSpreadMode(layout: any): number;
  58. /**
  59. * Converts API PageMode values to the format used by `PDFSidebar`.
  60. * NOTE: There's also a "FullScreen" parameter which is not possible to support,
  61. * since the Fullscreen API used in browsers requires that entering
  62. * fullscreen mode only occurs as a result of a user-initiated event.
  63. * @param {string} mode - The API PageMode value.
  64. * @returns {number} A value from {SidebarView}.
  65. */
  66. export function apiPageModeToSidebarView(mode: string): number;
  67. /**
  68. * Approximates float number as a fraction using Farey sequence (max order
  69. * of 8).
  70. * @param {number} x - Positive float number.
  71. * @returns {Array} Estimated fraction: the first array item is a numerator,
  72. * the second one is a denominator.
  73. */
  74. export function approximateFraction(x: number): any[];
  75. export const AutoPrintRegExp: RegExp;
  76. /**
  77. * Helper function for getVisibleElements.
  78. *
  79. * @param {number} index - initial guess at the first visible element
  80. * @param {Array} views - array of pages, into which `index` is an index
  81. * @param {number} top - the top of the scroll pane
  82. * @returns {number} less than or equal to `index` that is definitely at or
  83. * before the first visible element in `views`, but not by too much. (Usually,
  84. * this will be the first element in the first partially visible row in
  85. * `views`, although sometimes it goes back one row further.)
  86. */
  87. export function backtrackBeforeAllVisibleElements(index: number, views: any[], top: number): number;
  88. /**
  89. * Use binary search to find the index of the first item in a given array which
  90. * passes a given condition. The items are expected to be sorted in the sense
  91. * that if the condition is true for one item in the array, then it is also true
  92. * for all following items.
  93. *
  94. * @returns {number} Index of the first array element to pass the test,
  95. * or |items.length| if no such element exists.
  96. */
  97. export function binarySearchFirstItem(items: any, condition: any): number;
  98. export const CSS_UNITS: number;
  99. export const DEFAULT_SCALE: 1;
  100. export const DEFAULT_SCALE_VALUE: "auto";
  101. /**
  102. * Simple event bus for an application. Listeners are attached using the `on`
  103. * and `off` methods. To raise an event, the `dispatch` method shall be used.
  104. */
  105. export class EventBus {
  106. constructor(options: any);
  107. _listeners: any;
  108. _isInAutomation: boolean | undefined;
  109. /**
  110. * @param {string} eventName
  111. * @param {function} listener
  112. * @param {Object} [options]
  113. */
  114. on(eventName: string, listener: Function, options?: Object | undefined): void;
  115. /**
  116. * @param {string} eventName
  117. * @param {function} listener
  118. * @param {Object} [options]
  119. */
  120. off(eventName: string, listener: Function, options?: Object | undefined): void;
  121. dispatch(eventName: any, ...args: any[]): void;
  122. /**
  123. * @ignore
  124. */
  125. _on(eventName: any, listener: any, options?: any): void;
  126. /**
  127. * @ignore
  128. */
  129. _off(eventName: any, listener: any, options?: any): void;
  130. }
  131. /**
  132. * Get the active or focused element in current DOM.
  133. *
  134. * Recursively search for the truly active or focused element in case there are
  135. * shadow DOMs.
  136. *
  137. * @returns {Element} the truly active or focused element.
  138. */
  139. export function getActiveOrFocusedElement(): Element;
  140. /**
  141. * Returns scale factor for the canvas. It makes sense for the HiDPI displays.
  142. * @returns {Object} The object with horizontal (sx) and vertical (sy)
  143. * scales. The scaled property is set to false if scaling is
  144. * not required, true otherwise.
  145. */
  146. export function getOutputScale(ctx: any): Object;
  147. /**
  148. * Gets the size of the specified page, converted from PDF units to inches.
  149. * @param {Object} An Object containing the properties: {Array} `view`,
  150. * {number} `userUnit`, and {number} `rotate`.
  151. * @returns {Object} An Object containing the properties: {number} `width`
  152. * and {number} `height`, given in inches.
  153. */
  154. export function getPageSizeInches({ view, userUnit, rotate }: Object): Object;
  155. /**
  156. * @typedef {Object} GetVisibleElementsParameters
  157. * @property {HTMLElement} scrollEl - A container that can possibly scroll.
  158. * @property {Array} views - Objects with a `div` property that contains an
  159. * HTMLElement, which should all be descendants of `scrollEl` satisfying the
  160. * relevant layout assumptions.
  161. * @property {boolean} sortByVisibility - If `true`, the returned elements are
  162. * sorted in descending order of the percent of their padding box that is
  163. * visible. The default value is `false`.
  164. * @property {boolean} horizontal - If `true`, the elements are assumed to be
  165. * laid out horizontally instead of vertically. The default value is `false`.
  166. * @property {boolean} rtl - If `true`, the `scrollEl` container is assumed to
  167. * be in right-to-left mode. The default value is `false`.
  168. */
  169. /**
  170. * Generic helper to find out what elements are visible within a scroll pane.
  171. *
  172. * Well, pretty generic. There are some assumptions placed on the elements
  173. * referenced by `views`:
  174. * - If `horizontal`, no left of any earlier element is to the right of the
  175. * left of any later element.
  176. * - Otherwise, `views` can be split into contiguous rows where, within a row,
  177. * no top of any element is below the bottom of any other element, and
  178. * between rows, no bottom of any element in an earlier row is below the
  179. * top of any element in a later row.
  180. *
  181. * (Here, top, left, etc. all refer to the padding edge of the element in
  182. * question. For pages, that ends up being equivalent to the bounding box of the
  183. * rendering canvas. Earlier and later refer to index in `views`, not page
  184. * layout.)
  185. *
  186. * @param {GetVisibleElementsParameters}
  187. * @returns {Object} `{ first, last, views: [{ id, x, y, view, percent }] }`
  188. */
  189. export function getVisibleElements({ scrollEl, views, sortByVisibility, horizontal, rtl, }: GetVisibleElementsParameters): Object;
  190. export function isPortraitOrientation(size: any): boolean;
  191. export function isValidRotation(angle: any): boolean;
  192. export function isValidScrollMode(mode: any): boolean;
  193. export function isValidSpreadMode(mode: any): boolean;
  194. export const MAX_AUTO_SCALE: 1.25;
  195. export const MAX_SCALE: 10;
  196. export const MIN_SCALE: 0.1;
  197. /**
  198. * Moves all elements of an array that satisfy condition to the end of the
  199. * array, preserving the order of the rest.
  200. */
  201. export function moveToEndOfArray(arr: any, condition: any): void;
  202. /**
  203. * Event handler to suppress context menu.
  204. */
  205. export function noContextMenuHandler(evt: any): void;
  206. export function normalizeWheelEventDelta(evt: any): number;
  207. export function normalizeWheelEventDirection(evt: any): number;
  208. /**
  209. * Helper function to parse query string (e.g. ?param1=value&parm2=...).
  210. */
  211. export function parseQueryString(query: any): any;
  212. export namespace PresentationModeState {
  213. const UNKNOWN: number;
  214. const NORMAL: number;
  215. const CHANGING: number;
  216. const FULLSCREEN: number;
  217. }
  218. export class ProgressBar {
  219. constructor(id: any, { height, width, units }?: {
  220. height: any;
  221. width: any;
  222. units: any;
  223. });
  224. visible: boolean;
  225. div: Element | null;
  226. bar: (Node & ParentNode) | null;
  227. height: any;
  228. width: any;
  229. units: any;
  230. set percent(arg: any);
  231. get percent(): any;
  232. _updateBar(): void;
  233. _indeterminate: boolean | undefined;
  234. _percent: any;
  235. setWidth(viewer: any): void;
  236. hide(): void;
  237. show(): void;
  238. }
  239. export namespace RendererType {
  240. const CANVAS: string;
  241. const SVG: string;
  242. }
  243. export function roundToDivide(x: any, div: any): any;
  244. export const SCROLLBAR_PADDING: 40;
  245. /**
  246. * Scrolls specified element into view of its parent.
  247. * @param {Object} element - The element to be visible.
  248. * @param {Object} spot - An object with optional top and left properties,
  249. * specifying the offset from the top left edge.
  250. * @param {boolean} [scrollMatches] - When scrolling search results into view,
  251. * ignore elements that either: Contains marked content identifiers,
  252. * or have the CSS-rule `overflow: hidden;` set. The default value is `false`.
  253. */
  254. export function scrollIntoView(element: Object, spot: Object, scrollMatches?: boolean | undefined): void;
  255. export namespace ScrollMode {
  256. const UNKNOWN_1: number;
  257. export { UNKNOWN_1 as UNKNOWN };
  258. export const VERTICAL: number;
  259. export const HORIZONTAL: number;
  260. export const WRAPPED: number;
  261. }
  262. export namespace SidebarView {
  263. const UNKNOWN_2: number;
  264. export { UNKNOWN_2 as UNKNOWN };
  265. export const NONE: number;
  266. export const THUMBS: number;
  267. export const OUTLINE: number;
  268. export const ATTACHMENTS: number;
  269. export const LAYERS: number;
  270. }
  271. export namespace SpreadMode {
  272. const UNKNOWN_3: number;
  273. export { UNKNOWN_3 as UNKNOWN };
  274. const NONE_1: number;
  275. export { NONE_1 as NONE };
  276. export const ODD: number;
  277. export const EVEN: number;
  278. }
  279. export namespace TextLayerMode {
  280. const DISABLE: number;
  281. const ENABLE: number;
  282. const ENABLE_ENHANCE: number;
  283. }
  284. export const UNKNOWN_SCALE: 0;
  285. export const VERTICAL_PADDING: 5;
  286. /**
  287. * @typedef {Object} WaitOnEventOrTimeoutParameters
  288. * @property {Object} target - The event target, can for example be:
  289. * `window`, `document`, a DOM element, or an {EventBus} instance.
  290. * @property {string} name - The name of the event.
  291. * @property {number} delay - The delay, in milliseconds, after which the
  292. * timeout occurs (if the event wasn't already dispatched).
  293. */
  294. /**
  295. * Allows waiting for an event or a timeout, whichever occurs first.
  296. * Can be used to ensure that an action always occurs, even when an event
  297. * arrives late or not at all.
  298. *
  299. * @param {WaitOnEventOrTimeoutParameters}
  300. * @returns {Promise} A promise that is resolved with a {WaitOnType} value.
  301. */
  302. export function waitOnEventOrTimeout({ target, name, delay }: WaitOnEventOrTimeoutParameters): Promise<any>;
  303. export namespace WaitOnType {
  304. const EVENT: string;
  305. const TIMEOUT: string;
  306. }
  307. /**
  308. * Helper function to start monitoring the scroll event and converting them into
  309. * PDF.js friendly one: with scroll debounce and scroll direction.
  310. */
  311. export function watchScroll(viewAreaElement: any, callback: any): {
  312. right: boolean;
  313. down: boolean;
  314. lastX: any;
  315. lastY: any;
  316. _eventHandler: (evt: any) => void;
  317. };