ui_utils.d.ts 9.6 KB

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