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