ui_utils.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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, start?: number): number;
  97. export const DEFAULT_SCALE: 1;
  98. export const DEFAULT_SCALE_DELTA: 1.1;
  99. export const DEFAULT_SCALE_VALUE: "auto";
  100. export const docStyle: CSSStyleDeclaration | null;
  101. /**
  102. * Get the active or focused element in current DOM.
  103. *
  104. * Recursively search for the truly active or focused element in case there are
  105. * shadow DOMs.
  106. *
  107. * @returns {Element} the truly active or focused element.
  108. */
  109. export function getActiveOrFocusedElement(): Element;
  110. /**
  111. * @typedef {Object} GetPageSizeInchesParameters
  112. * @property {number[]} view
  113. * @property {number} userUnit
  114. * @property {number} rotate
  115. */
  116. /**
  117. * @typedef {Object} PageSize
  118. * @property {number} width - In inches.
  119. * @property {number} height - In inches.
  120. */
  121. /**
  122. * Gets the size of the specified page, converted from PDF units to inches.
  123. * @param {GetPageSizeInchesParameters} params
  124. * @returns {PageSize}
  125. */
  126. export function getPageSizeInches({ view, userUnit, rotate }: GetPageSizeInchesParameters): PageSize;
  127. /**
  128. * @typedef {Object} GetVisibleElementsParameters
  129. * @property {HTMLElement} scrollEl - A container that can possibly scroll.
  130. * @property {Array} views - Objects with a `div` property that contains an
  131. * HTMLElement, which should all be descendants of `scrollEl` satisfying the
  132. * relevant layout assumptions.
  133. * @property {boolean} sortByVisibility - If `true`, the returned elements are
  134. * sorted in descending order of the percent of their padding box that is
  135. * visible. The default value is `false`.
  136. * @property {boolean} horizontal - If `true`, the elements are assumed to be
  137. * laid out horizontally instead of vertically. The default value is `false`.
  138. * @property {boolean} rtl - If `true`, the `scrollEl` container is assumed to
  139. * be in right-to-left mode. The default value is `false`.
  140. */
  141. /**
  142. * Generic helper to find out what elements are visible within a scroll pane.
  143. *
  144. * Well, pretty generic. There are some assumptions placed on the elements
  145. * referenced by `views`:
  146. * - If `horizontal`, no left of any earlier element is to the right of the
  147. * left of any later element.
  148. * - Otherwise, `views` can be split into contiguous rows where, within a row,
  149. * no top of any element is below the bottom of any other element, and
  150. * between rows, no bottom of any element in an earlier row is below the
  151. * top of any element in a later row.
  152. *
  153. * (Here, top, left, etc. all refer to the padding edge of the element in
  154. * question. For pages, that ends up being equivalent to the bounding box of the
  155. * rendering canvas. Earlier and later refer to index in `views`, not page
  156. * layout.)
  157. *
  158. * @param {GetVisibleElementsParameters}
  159. * @returns {Object} `{ first, last, views: [{ id, x, y, view, percent }] }`
  160. */
  161. export function getVisibleElements({ scrollEl, views, sortByVisibility, horizontal, rtl, }: GetVisibleElementsParameters): Object;
  162. export function isPortraitOrientation(size: any): boolean;
  163. export function isValidRotation(angle: any): boolean;
  164. export function isValidScrollMode(mode: any): boolean;
  165. export function isValidSpreadMode(mode: any): boolean;
  166. export const MAX_AUTO_SCALE: 1.25;
  167. export const MAX_SCALE: 10;
  168. export const MIN_SCALE: 0.1;
  169. /**
  170. * Event handler to suppress context menu.
  171. */
  172. export function noContextMenuHandler(evt: any): void;
  173. export function normalizeWheelEventDelta(evt: any): number;
  174. export function normalizeWheelEventDirection(evt: any): number;
  175. /**
  176. * Scale factors for the canvas, necessary with HiDPI displays.
  177. */
  178. export class OutputScale {
  179. /**
  180. * @type {number} Horizontal scale.
  181. */
  182. sx: number;
  183. /**
  184. * @type {number} Vertical scale.
  185. */
  186. sy: number;
  187. /**
  188. * @type {boolean} Returns `true` when scaling is required, `false` otherwise.
  189. */
  190. get scaled(): boolean;
  191. }
  192. /**
  193. * Helper function to parse query string (e.g. ?param1=value&param2=...).
  194. * @param {string}
  195. * @returns {Map}
  196. */
  197. export function parseQueryString(query: any): Map<any, any>;
  198. export namespace PresentationModeState {
  199. const UNKNOWN: number;
  200. const NORMAL: number;
  201. const CHANGING: number;
  202. const FULLSCREEN: number;
  203. }
  204. export class ProgressBar {
  205. constructor(id: any);
  206. set percent(arg: number);
  207. get percent(): number;
  208. setWidth(viewer: any): void;
  209. hide(): void;
  210. show(): void;
  211. #private;
  212. }
  213. /**
  214. * @param {string} str
  215. * @param {boolean} [replaceInvisible]
  216. */
  217. export function removeNullCharacters(str: string, replaceInvisible?: boolean | undefined): string;
  218. export const RendererType: {
  219. CANVAS: string;
  220. SVG: string;
  221. } | null;
  222. export namespace RenderingStates {
  223. const INITIAL: number;
  224. const RUNNING: number;
  225. const PAUSED: number;
  226. const FINISHED: number;
  227. }
  228. export function roundToDivide(x: any, div: any): any;
  229. export const SCROLLBAR_PADDING: 40;
  230. /**
  231. * Scrolls specified element into view of its parent.
  232. * @param {Object} element - The element to be visible.
  233. * @param {Object} spot - An object with optional top and left properties,
  234. * specifying the offset from the top left edge.
  235. * @param {boolean} [scrollMatches] - When scrolling search results into view,
  236. * ignore elements that either: Contains marked content identifiers,
  237. * or have the CSS-rule `overflow: hidden;` set. The default value is `false`.
  238. */
  239. export function scrollIntoView(element: Object, spot: Object, scrollMatches?: boolean | undefined): void;
  240. export namespace ScrollMode {
  241. const UNKNOWN_1: number;
  242. export { UNKNOWN_1 as UNKNOWN };
  243. export const VERTICAL: number;
  244. export const HORIZONTAL: number;
  245. export const WRAPPED: number;
  246. export const PAGE: number;
  247. }
  248. export namespace SidebarView {
  249. const UNKNOWN_2: number;
  250. export { UNKNOWN_2 as UNKNOWN };
  251. export const NONE: number;
  252. export const THUMBS: number;
  253. export const OUTLINE: number;
  254. export const ATTACHMENTS: number;
  255. export const LAYERS: number;
  256. }
  257. export namespace SpreadMode {
  258. const UNKNOWN_3: number;
  259. export { UNKNOWN_3 as UNKNOWN };
  260. const NONE_1: number;
  261. export { NONE_1 as NONE };
  262. export const ODD: number;
  263. export const EVEN: number;
  264. }
  265. export namespace TextLayerMode {
  266. const DISABLE: number;
  267. const ENABLE: number;
  268. }
  269. export const UNKNOWN_SCALE: 0;
  270. export const VERTICAL_PADDING: 5;
  271. /**
  272. * Helper function to start monitoring the scroll event and converting them into
  273. * PDF.js friendly one: with scroll debounce and scroll direction.
  274. */
  275. export function watchScroll(viewAreaElement: any, callback: any): {
  276. right: boolean;
  277. down: boolean;
  278. lastX: any;
  279. lastY: any;
  280. _eventHandler: (evt: any) => void;
  281. };