2
0

app_options.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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: false,
  62. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  63. },
  64. enableScripting: {
  65. value: false,
  66. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  67. },
  68. enableWebGL: {
  69. value: false,
  70. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  71. },
  72. externalLinkRel: {
  73. value: "noopener noreferrer nofollow",
  74. kind: OptionKind.VIEWER
  75. },
  76. externalLinkTarget: {
  77. value: 0,
  78. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  79. },
  80. historyUpdateUrl: {
  81. value: false,
  82. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  83. },
  84. ignoreDestinationZoom: {
  85. value: false,
  86. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  87. },
  88. imageResourcesPath: {
  89. value: "./images/",
  90. kind: OptionKind.VIEWER
  91. },
  92. maxCanvasPixels: {
  93. value: 16777216,
  94. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  95. kind: OptionKind.VIEWER
  96. },
  97. pdfBugEnabled: {
  98. value: false,
  99. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  100. },
  101. printResolution: {
  102. value: 150,
  103. kind: OptionKind.VIEWER
  104. },
  105. renderer: {
  106. value: "canvas",
  107. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  108. },
  109. renderInteractiveForms: {
  110. value: true,
  111. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  112. },
  113. sidebarViewOnLoad: {
  114. value: -1,
  115. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  116. },
  117. scrollModeOnLoad: {
  118. value: -1,
  119. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  120. },
  121. spreadModeOnLoad: {
  122. value: -1,
  123. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  124. },
  125. textLayerMode: {
  126. value: 1,
  127. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  128. },
  129. useOnlyCssZoom: {
  130. value: false,
  131. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  132. },
  133. viewerCssTheme: {
  134. value: 0,
  135. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  136. },
  137. viewOnLoad: {
  138. value: 0,
  139. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  140. },
  141. cMapPacked: {
  142. value: true,
  143. kind: OptionKind.API
  144. },
  145. cMapUrl: {
  146. value: "../web/cmaps/",
  147. kind: OptionKind.API
  148. },
  149. disableAutoFetch: {
  150. value: false,
  151. kind: OptionKind.API + OptionKind.PREFERENCE
  152. },
  153. disableFontFace: {
  154. value: false,
  155. kind: OptionKind.API + OptionKind.PREFERENCE
  156. },
  157. disableRange: {
  158. value: false,
  159. kind: OptionKind.API + OptionKind.PREFERENCE
  160. },
  161. disableStream: {
  162. value: false,
  163. kind: OptionKind.API + OptionKind.PREFERENCE
  164. },
  165. docBaseUrl: {
  166. value: "",
  167. kind: OptionKind.API
  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. verbosity: {
  186. value: 1,
  187. kind: OptionKind.API
  188. },
  189. workerPort: {
  190. value: null,
  191. kind: OptionKind.WORKER
  192. },
  193. workerSrc: {
  194. value: "../build/pdf.worker.js",
  195. kind: OptionKind.WORKER
  196. }
  197. };
  198. ;
  199. const userOptions = Object.create(null);
  200. class AppOptions {
  201. constructor() {
  202. throw new Error("Cannot initialize AppOptions.");
  203. }
  204. static get(name) {
  205. const userOption = userOptions[name];
  206. if (userOption !== undefined) {
  207. return userOption;
  208. }
  209. const defaultOption = defaultOptions[name];
  210. if (defaultOption !== undefined) {
  211. return defaultOption.compatibility || defaultOption.value;
  212. }
  213. return undefined;
  214. }
  215. static getAll(kind = null) {
  216. const options = Object.create(null);
  217. for (const name in defaultOptions) {
  218. const defaultOption = defaultOptions[name];
  219. if (kind) {
  220. if ((kind & defaultOption.kind) === 0) {
  221. continue;
  222. }
  223. if (kind === OptionKind.PREFERENCE) {
  224. const value = defaultOption.value,
  225. valueType = typeof value;
  226. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  227. options[name] = value;
  228. continue;
  229. }
  230. throw new Error(`Invalid type for preference: ${name}`);
  231. }
  232. }
  233. const userOption = userOptions[name];
  234. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility || defaultOption.value;
  235. }
  236. return options;
  237. }
  238. static set(name, value) {
  239. userOptions[name] = value;
  240. }
  241. static setAll(options) {
  242. for (const name in options) {
  243. userOptions[name] = options[name];
  244. }
  245. }
  246. static remove(name) {
  247. delete userOptions[name];
  248. }
  249. }
  250. exports.AppOptions = AppOptions;