CPDFOptions.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. * Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
  3. *
  4. * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  5. * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  6. * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  7. * This notice may not be removed from this file.
  8. */
  9. export const CPDFViewMode = {
  10. /**
  11. * Viewer mode, allows viewing PDF only, cannot edit annotations, forms, etc.
  12. */
  13. VIEWER: 'viewer',
  14. /**
  15. * Annotations mode, allows annotation editing
  16. */
  17. ANNOTATIONS: 'annotations',
  18. /**
  19. * Content editor mode, allows editing text, images of PDF document
  20. */
  21. CONTENT_EDITOR: 'contentEditor',
  22. /**
  23. * Forms mode, allows adding text fields, signature fields, list boxes, etc.
  24. */
  25. FORMS: 'forms',
  26. /**
  27. * Signatures mode, allows adding signature fields for electronic signing, digital signing, verifying digital signatures
  28. */
  29. SIGNATURES: 'signatures'
  30. } as const
  31. export type CPDFViewMode = ValueOf<typeof CPDFViewMode>;
  32. /**
  33. * Toolbar actions supported in the displayed PDF view
  34. */
  35. export const CPDFToolbarAction = {
  36. /**
  37. * Back button, exits the displayed PDF interface when clicked.
  38. * for Android platform, it will be shown only on the far left of the toolbar.
  39. * for iOS platform, it will be displayed according to the configuration position.
  40. */
  41. BACK: 'back',
  42. /**
  43. * Thumbnail list
  44. */
  45. THUMBNAIL: 'thumbnail',
  46. /**
  47. * PDF text search functionality
  48. */
  49. SEARCH: 'search',
  50. /**
  51. * Display related content in the PDF document
  52. *
  53. * b: Bookmark list
  54. * o: Outline list
  55. * t: Thumbnail list
  56. * a: Annotation list
  57. */
  58. BOTA: 'bota',
  59. /**
  60. * Menu button
  61. */
  62. MENU: 'menu'
  63. } as const
  64. export type CPDFToolbarAction = ValueOf<typeof CPDFToolbarAction>;
  65. /**
  66. * Configure the menu options opened in the top toolbar {@link CPDFToolbarAction.MENU}
  67. *
  68. */
  69. export const CPDFToolbarMenuAction = {
  70. /**
  71. * Open the settings view and set the scrolling direction,
  72. * display mode, theme color and other related settings for reading PDF.
  73. */
  74. VIEW_SETTINGS: 'viewSettings',
  75. /**
  76. * Open the document thumbnail list, and you can delete, rotate, and add document pages in the view.
  77. */
  78. DOCUMENT_EDITOR: 'documentEditor',
  79. /**
  80. * Open the document information view to display basic document information and permission information.
  81. */
  82. DOCUMENT_INFO: 'documentInfo',
  83. /**
  84. * Open the watermark editing view to add text and image watermarks and save them as a new document.
  85. */
  86. WATERMARK: 'watermark',
  87. /**
  88. * Open the security settings view, set the document opening password and set the permission password
  89. */
  90. SECURITY: 'security',
  91. /**
  92. * Flatten the annotations in the document, and the annotations will not be editable.
  93. */
  94. FLATTENED: 'flattened',
  95. /**
  96. * save pdf document.
  97. */
  98. SAVE: 'save',
  99. /**
  100. * Turn on system sharing function.
  101. */
  102. SHARE: 'share',
  103. /**
  104. * Open the system file selector and open a new pdf document.
  105. */
  106. OPEN_DOCUMENT: 'openDocument',
  107. /**
  108. * The PDF capture function allows you to capture an area
  109. * in the PDF document and convert it into an image.
  110. */
  111. SNIP: 'snip'
  112. } as const
  113. export type CPDFToolbarMenuAction = ValueOf<typeof CPDFToolbarMenuAction>;
  114. /**
  115. * annotations type.
  116. * Please note that {@link PENCIL} is only available on ios platform.
  117. */
  118. export const CPDFAnnotationType = {
  119. UNKNOWN: 'unknown',
  120. NOTE: 'note',
  121. HIGHLIGHT: 'highlight',
  122. UNDERLINE: 'underline',
  123. SQUIGGLY: 'squiggly',
  124. STRIKEOUT: 'strikeout',
  125. INK: 'ink',
  126. /**
  127. * only ios platform.
  128. */
  129. PENCIL: "pencil",
  130. CIRCLE: 'circle',
  131. SQUARE: 'square',
  132. ARROW: 'arrow',
  133. LINE: 'line',
  134. FREETEXT: 'freetext',
  135. SIGNATURE: 'signature',
  136. STAMP: 'stamp',
  137. PICTURES: 'pictures',
  138. LINK: 'link',
  139. SOUND: 'sound'
  140. } as const
  141. export type CPDFAnnotationType = ValueOf<typeof CPDFAnnotationType>;
  142. /**
  143. * {@link CPDFViewMode.ANNOTATIONS}, {@link CPDFViewMode.CONTENT_EDITOR},{@link CPDFViewMode.FORMS} function tools.
  144. * {@link CPDFConfigTool.SETTING} is not available in form functionality.
  145. *
  146. */
  147. export const CPDFConfigTool = {
  148. /**
  149. * Set button, corresponding to open the selected annotation, text or picture property panel.
  150. */
  151. SETTING: 'setting',
  152. /**
  153. * Undo annotation, content editing, form operations
  154. */
  155. UNDO: 'undo',
  156. /**
  157. * Redo an undone action
  158. */
  159. REDO: 'redo'
  160. } as const
  161. export type CPDFConfigTool = ValueOf<typeof CPDFConfigTool>;
  162. /**
  163. * Shape annotation border style, default {@link CPDFBorderStyle.SOLID}.
  164. * shape:
  165. * * {@link CPDFAnnotationType.SQUARE}
  166. * * {@link CPDFAnnotationType.CIRCLE}
  167. * * {@link CPDFAnnotationType.ARROW}
  168. * * {@link CPDFAnnotationType.LINE}
  169. */
  170. export const CPDFBorderStyle = {
  171. SOLID: 'solid',
  172. DASHED: 'dashed'
  173. } as const
  174. export type CPDFBorderStyle = ValueOf<typeof CPDFBorderStyle>;
  175. /**
  176. * Arrow annotation, start and tail shapes
  177. */
  178. export const CPDFLineType = {
  179. NONE: 'none',
  180. OPEN_ARROW: 'openArrow',
  181. CLOSE_ARROW: 'closedArrow',
  182. SQUARE: 'square',
  183. CIRCLE: 'circle',
  184. DIAMOND: 'diamond'
  185. }
  186. export type CPDFLineType = ValueOf<typeof CPDFLineType>;
  187. /**
  188. * text alignment
  189. */
  190. export const CPDFAlignment = {
  191. LEFT: 'left',
  192. CENTER: 'center',
  193. RIGHT: 'right'
  194. } as const
  195. export type CPDFAlignment = ValueOf<typeof CPDFAlignment>;
  196. export const CPDFTypeface = {
  197. COURIER: 'Courier',
  198. HELVETICA: 'Helvetica',
  199. TIMES_ROMAN: 'Times-Roman'
  200. } as const
  201. export type CPDFTypeface = ValueOf<typeof CPDFTypeface>;
  202. export const CPDFContentEditorType = {
  203. EDITOR_TEXT: 'editorText',
  204. EDITOR_IMAGE: 'editorImage'
  205. }
  206. export type CPDFContentEditorType = ValueOf<typeof CPDFContentEditorType>;
  207. /**
  208. * form types
  209. * @deprecated please use 'CPDFWidgetType' instead.
  210. */
  211. export const CPDFFormType = {
  212. TEXT_FIELD: 'textField',
  213. CHECKBOX: 'checkBox',
  214. RADIO_BUTTON: 'radioButton',
  215. LISTBOX: 'listBox',
  216. COMBOBOX: 'comboBox',
  217. SIGNATURES_FIELDS: 'signaturesFields',
  218. PUSH_BUTTON: 'pushButton',
  219. UNKNOWN: 'unknown'
  220. } as const
  221. /**
  222. * @deprecated Please use `CPDFWidgetType` instead.
  223. */
  224. export type CPDFFormType = ValueOf<typeof CPDFFormType>;
  225. /**
  226. * New widget type definition, recommended for use.
  227. */
  228. export const CPDFWidgetType = { ...CPDFFormType } as const;
  229. export type CPDFWidgetType = ValueOf<typeof CPDFWidgetType>;
  230. export const CPDFCheckStyle = {
  231. CHECK: 'check',
  232. CIRCLE: 'circle',
  233. CROSS: 'cross',
  234. DIAMOND: 'diamond',
  235. SQUARE: 'square',
  236. STAR: 'star'
  237. }
  238. export type CPDFCheckStyle = ValueOf<typeof CPDFCheckStyle>;
  239. export const CPDFDisplayMode = {
  240. SINGLE_PAGE: 'singlePage',
  241. DOUBLE_PAGE: 'doublePage',
  242. COVER_PAGE: 'coverPage'
  243. }
  244. export type CPDFDisplayMode = ValueOf<typeof CPDFDisplayMode>;
  245. export const CPDFThemes = {
  246. /**
  247. * Bright mode, readerview background is white
  248. */
  249. LIGHT: 'light',
  250. /**
  251. * dark mode, readerview background is black
  252. */
  253. DARK: 'dark',
  254. /**
  255. * brown paper color
  256. */
  257. SEPIA: 'sepia',
  258. /**
  259. * Light green, eye protection mode
  260. */
  261. RESEDA: 'reseda'
  262. }
  263. export type CPDFThemes = ValueOf<typeof CPDFThemes>;
  264. /**
  265. * Set UI theme modes, including light, dark, and follow system modes
  266. * Default: Follow system
  267. */
  268. export const CPDFThemeMode = {
  269. /**
  270. * Light mode, with a primarily white UI
  271. */
  272. LIGHT: 'light',
  273. /**
  274. * Dark night mode, with a primarily black UI
  275. */
  276. DARK: 'dark',
  277. /**
  278. * Follow the current system setting
  279. */
  280. SYSTEM: 'system'
  281. }
  282. export type CPDFThemeMode = ValueOf<typeof CPDFThemeMode>;
  283. /**
  284. * Represents the permissions available for the currently opened document.
  285. */
  286. export const CPDFDocumentPermissions = {
  287. /**
  288. * No restrictions. The document does not have an open password or owner permission password.
  289. */
  290. NONE: 'none',
  291. /**
  292. * User permissions. The document can only be viewed and has an owner password set.
  293. */
  294. USER: 'user',
  295. /**
  296. * Owner permissions. The current viewer is identified as the owner of the document.
  297. */
  298. OWNER: 'owner',
  299. };
  300. export type CPDFDocumentPermissions = ValueOf<typeof CPDFDocumentPermissions>;
  301. /**
  302. * Specifies the encryption algorithms supported for a PDF document.
  303. */
  304. export const CPDFDocumentEncryptAlgo = {
  305. /**
  306. * RC4 encryption algorithm.
  307. */
  308. RC4: 'rc4',
  309. /**
  310. * AES 128-bit encryption algorithm.
  311. */
  312. AES128: 'aes128',
  313. /**
  314. * AES 256-bit encryption algorithm.
  315. */
  316. AES256: 'aes256',
  317. /**
  318. * Indicates that no encryption algorithm is applied.
  319. */
  320. NO_ENCRYPT_ALGO: 'noEncryptAlgo',
  321. };
  322. export type CPDFDocumentEncryptAlgo = ValueOf<typeof CPDFDocumentEncryptAlgo>;
  323. export type AnyCase<T extends string> =
  324. string extends T ? string :
  325. T extends `${infer F1}${infer F2}${infer R}` ? (
  326. `${Uppercase<F1> | Lowercase<F1>}${Uppercase<F2> | Lowercase<F2>}${AnyCase<R>}`
  327. ) :
  328. T extends `${infer F}${infer R}` ? `${Uppercase<F> | Lowercase<F>}${AnyCase<R>}` :
  329. "";
  330. type ValueOf<T> = T[keyof T];
  331. type BuildPowersOf2LengthArrays<N extends number, R extends never[][]> =
  332. R[0][N] extends never ? R : BuildPowersOf2LengthArrays<N, [[...R[0], ...R[0]], ...R]>;
  333. type ConcatLargestUntilDone<N extends number, R extends never[][], B extends never[]> =
  334. B["length"] extends N ? B : [...R[0], ...B][N] extends never
  335. ? ConcatLargestUntilDone<N, R extends [R[0], ...infer U] ? U extends never[][] ? U : never : never, B>
  336. : ConcatLargestUntilDone<N, R extends [R[0], ...infer U] ? U extends never[][] ? U : never : never, [...R[0], ...B]>;
  337. type Replace<R extends any[], T> = { [K in keyof R]: T }
  338. type TupleOf<T, N extends number> = number extends N ? T[] : {
  339. [K in N]:
  340. BuildPowersOf2LengthArrays<K, [[never]]> extends infer U ? U extends never[][]
  341. ? Replace<ConcatLargestUntilDone<K, U, []>, T> : never : never;
  342. }[N]
  343. type RangeOf<N extends number> = Partial<TupleOf<unknown, N>>["length"];
  344. type RangeOf2<From extends number, To extends number> = Exclude<RangeOf<To>, RangeOf<From>> | From;
  345. export type ColorAlpha = RangeOf2<0,255>
  346. export type BorderWidth = RangeOf2<1, 10>
  347. export type DashGap = RangeOf2<0.0, 10.0>
  348. export type HexColor = `#${string}`;
  349. export type FontSize = RangeOf2<0,100>