2
0

app_options.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. enableWebGL: {
  65. value: false,
  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 + OptionKind.PREFERENCE
  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. viewOnLoad: {
  130. value: 0,
  131. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  132. },
  133. cMapPacked: {
  134. value: true,
  135. kind: OptionKind.API
  136. },
  137. cMapUrl: {
  138. value: "../web/cmaps/",
  139. kind: OptionKind.API
  140. },
  141. disableAutoFetch: {
  142. value: false,
  143. kind: OptionKind.API + OptionKind.PREFERENCE
  144. },
  145. disableFontFace: {
  146. value: false,
  147. kind: OptionKind.API + OptionKind.PREFERENCE
  148. },
  149. disableRange: {
  150. value: false,
  151. kind: OptionKind.API + OptionKind.PREFERENCE
  152. },
  153. disableStream: {
  154. value: false,
  155. kind: OptionKind.API + OptionKind.PREFERENCE
  156. },
  157. docBaseUrl: {
  158. value: "",
  159. kind: OptionKind.API
  160. },
  161. fontExtraProperties: {
  162. value: false,
  163. kind: OptionKind.API
  164. },
  165. isEvalSupported: {
  166. value: true,
  167. kind: OptionKind.API
  168. },
  169. maxImageSize: {
  170. value: -1,
  171. kind: OptionKind.API
  172. },
  173. pdfBug: {
  174. value: false,
  175. kind: OptionKind.API
  176. },
  177. verbosity: {
  178. value: 1,
  179. kind: OptionKind.API
  180. },
  181. workerPort: {
  182. value: null,
  183. kind: OptionKind.WORKER
  184. },
  185. workerSrc: {
  186. value: "../build/pdf.worker.js",
  187. kind: OptionKind.WORKER
  188. }
  189. };
  190. ;
  191. const userOptions = Object.create(null);
  192. class AppOptions {
  193. constructor() {
  194. throw new Error("Cannot initialize AppOptions.");
  195. }
  196. static get(name) {
  197. const userOption = userOptions[name];
  198. if (userOption !== undefined) {
  199. return userOption;
  200. }
  201. const defaultOption = defaultOptions[name];
  202. if (defaultOption !== undefined) {
  203. return defaultOption.compatibility || defaultOption.value;
  204. }
  205. return undefined;
  206. }
  207. static getAll(kind = null) {
  208. const options = Object.create(null);
  209. for (const name in defaultOptions) {
  210. const defaultOption = defaultOptions[name];
  211. if (kind) {
  212. if ((kind & defaultOption.kind) === 0) {
  213. continue;
  214. }
  215. if (kind === OptionKind.PREFERENCE) {
  216. const value = defaultOption.value,
  217. valueType = typeof value;
  218. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  219. options[name] = value;
  220. continue;
  221. }
  222. throw new Error(`Invalid type for preference: ${name}`);
  223. }
  224. }
  225. const userOption = userOptions[name];
  226. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility || defaultOption.value;
  227. }
  228. return options;
  229. }
  230. static set(name, value) {
  231. userOptions[name] = value;
  232. }
  233. static remove(name) {
  234. delete userOptions[name];
  235. }
  236. }
  237. exports.AppOptions = AppOptions;