2
0

ui_utils.d.ts 12 KB

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