ui_utils.d.ts 10 KB

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