app_options.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.OptionKind = exports.AppOptions = void 0;
  27. var _viewer_compatibility = require("./viewer_compatibility.js");
  28. const OptionKind = {
  29. VIEWER: 0x02,
  30. API: 0x04,
  31. WORKER: 0x08,
  32. PREFERENCE: 0x80
  33. };
  34. exports.OptionKind = OptionKind;
  35. const defaultOptions = {
  36. cursorToolOnLoad: {
  37. value: 0,
  38. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  39. },
  40. defaultUrl: {
  41. value: "compressed.tracemonkey-pldi-09.pdf",
  42. kind: OptionKind.VIEWER
  43. },
  44. defaultZoomValue: {
  45. value: "",
  46. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  47. },
  48. disableHistory: {
  49. value: false,
  50. kind: OptionKind.VIEWER
  51. },
  52. disablePageLabels: {
  53. value: false,
  54. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  55. },
  56. enablePermissions: {
  57. value: false,
  58. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  59. },
  60. enablePrintAutoRotate: {
  61. value: true,
  62. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  63. },
  64. enableScripting: {
  65. value: true,
  66. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  67. },
  68. externalLinkRel: {
  69. value: "noopener noreferrer nofollow",
  70. kind: OptionKind.VIEWER
  71. },
  72. externalLinkTarget: {
  73. value: 0,
  74. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  75. },
  76. historyUpdateUrl: {
  77. value: false,
  78. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  79. },
  80. ignoreDestinationZoom: {
  81. value: false,
  82. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  83. },
  84. imageResourcesPath: {
  85. value: "./images/",
  86. kind: OptionKind.VIEWER
  87. },
  88. maxCanvasPixels: {
  89. value: 16777216,
  90. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  91. kind: OptionKind.VIEWER
  92. },
  93. pdfBugEnabled: {
  94. value: false,
  95. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  96. },
  97. printResolution: {
  98. value: 150,
  99. kind: OptionKind.VIEWER
  100. },
  101. renderer: {
  102. value: "canvas",
  103. kind: OptionKind.VIEWER
  104. },
  105. renderInteractiveForms: {
  106. value: true,
  107. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  108. },
  109. sidebarViewOnLoad: {
  110. value: -1,
  111. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  112. },
  113. scrollModeOnLoad: {
  114. value: -1,
  115. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  116. },
  117. spreadModeOnLoad: {
  118. value: -1,
  119. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  120. },
  121. textLayerMode: {
  122. value: 1,
  123. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  124. },
  125. useOnlyCssZoom: {
  126. value: false,
  127. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  128. },
  129. viewerCssTheme: {
  130. value: 0,
  131. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  132. },
  133. viewOnLoad: {
  134. value: 0,
  135. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  136. },
  137. cMapPacked: {
  138. value: true,
  139. kind: OptionKind.API
  140. },
  141. cMapUrl: {
  142. value: "../web/cmaps/",
  143. kind: OptionKind.API
  144. },
  145. disableAutoFetch: {
  146. value: false,
  147. kind: OptionKind.API + OptionKind.PREFERENCE
  148. },
  149. disableFontFace: {
  150. value: false,
  151. kind: OptionKind.API + OptionKind.PREFERENCE
  152. },
  153. disableRange: {
  154. value: false,
  155. kind: OptionKind.API + OptionKind.PREFERENCE
  156. },
  157. disableStream: {
  158. value: false,
  159. kind: OptionKind.API + OptionKind.PREFERENCE
  160. },
  161. docBaseUrl: {
  162. value: "",
  163. kind: OptionKind.API
  164. },
  165. enableXfa: {
  166. value: false,
  167. kind: OptionKind.API + OptionKind.PREFERENCE
  168. },
  169. fontExtraProperties: {
  170. value: false,
  171. kind: OptionKind.API
  172. },
  173. isEvalSupported: {
  174. value: true,
  175. kind: OptionKind.API
  176. },
  177. maxImageSize: {
  178. value: -1,
  179. kind: OptionKind.API
  180. },
  181. pdfBug: {
  182. value: false,
  183. kind: OptionKind.API
  184. },
  185. standardFontDataUrl: {
  186. value: "../web/standard_fonts/",
  187. kind: OptionKind.API
  188. },
  189. verbosity: {
  190. value: 1,
  191. kind: OptionKind.API
  192. },
  193. workerPort: {
  194. value: null,
  195. kind: OptionKind.WORKER
  196. },
  197. workerSrc: {
  198. value: "../build/pdf.worker.js",
  199. kind: OptionKind.WORKER
  200. }
  201. };
  202. {
  203. defaultOptions.disablePreferences = {
  204. value: false,
  205. kind: OptionKind.VIEWER
  206. };
  207. defaultOptions.locale = {
  208. value: typeof navigator !== "undefined" ? navigator.language : "en-US",
  209. kind: OptionKind.VIEWER
  210. };
  211. defaultOptions.sandboxBundleSrc = {
  212. value: "../build/pdf.sandbox.js",
  213. kind: OptionKind.VIEWER
  214. };
  215. defaultOptions.renderer.kind += OptionKind.PREFERENCE;
  216. }
  217. const userOptions = Object.create(null);
  218. class AppOptions {
  219. constructor() {
  220. throw new Error("Cannot initialize AppOptions.");
  221. }
  222. static get(name) {
  223. const userOption = userOptions[name];
  224. if (userOption !== undefined) {
  225. return userOption;
  226. }
  227. const defaultOption = defaultOptions[name];
  228. if (defaultOption !== undefined) {
  229. return defaultOption.compatibility ?? defaultOption.value;
  230. }
  231. return undefined;
  232. }
  233. static getAll(kind = null) {
  234. const options = Object.create(null);
  235. for (const name in defaultOptions) {
  236. const defaultOption = defaultOptions[name];
  237. if (kind) {
  238. if ((kind & defaultOption.kind) === 0) {
  239. continue;
  240. }
  241. if (kind === OptionKind.PREFERENCE) {
  242. const value = defaultOption.value,
  243. valueType = typeof value;
  244. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  245. options[name] = value;
  246. continue;
  247. }
  248. throw new Error(`Invalid type for preference: ${name}`);
  249. }
  250. }
  251. const userOption = userOptions[name];
  252. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  253. }
  254. return options;
  255. }
  256. static set(name, value) {
  257. userOptions[name] = value;
  258. }
  259. static setAll(options) {
  260. for (const name in options) {
  261. userOptions[name] = options[name];
  262. }
  263. }
  264. static remove(name) {
  265. delete userOptions[name];
  266. }
  267. }
  268. exports.AppOptions = AppOptions;