ui_utils.d.ts 10 KB

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