app_options.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. disableCreateObjectURL: {
  49. value: false,
  50. compatibility: _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL,
  51. kind: OptionKind.VIEWER
  52. },
  53. disableHistory: {
  54. value: false,
  55. kind: OptionKind.VIEWER
  56. },
  57. disablePageLabels: {
  58. value: false,
  59. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  60. },
  61. enablePermissions: {
  62. value: false,
  63. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  64. },
  65. enablePrintAutoRotate: {
  66. value: false,
  67. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  68. },
  69. enableWebGL: {
  70. value: false,
  71. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  72. },
  73. externalLinkRel: {
  74. value: "noopener noreferrer nofollow",
  75. kind: OptionKind.VIEWER
  76. },
  77. externalLinkTarget: {
  78. value: 0,
  79. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  80. },
  81. historyUpdateUrl: {
  82. value: false,
  83. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  84. },
  85. ignoreDestinationZoom: {
  86. value: false,
  87. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  88. },
  89. imageResourcesPath: {
  90. value: "./images/",
  91. kind: OptionKind.VIEWER
  92. },
  93. maxCanvasPixels: {
  94. value: 16777216,
  95. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  96. kind: OptionKind.VIEWER
  97. },
  98. pdfBugEnabled: {
  99. value: false,
  100. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  101. },
  102. printResolution: {
  103. value: 150,
  104. kind: OptionKind.VIEWER
  105. },
  106. renderer: {
  107. value: "canvas",
  108. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  109. },
  110. renderInteractiveForms: {
  111. value: false,
  112. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  113. },
  114. sidebarViewOnLoad: {
  115. value: -1,
  116. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  117. },
  118. scrollModeOnLoad: {
  119. value: -1,
  120. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  121. },
  122. spreadModeOnLoad: {
  123. value: -1,
  124. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  125. },
  126. textLayerMode: {
  127. value: 1,
  128. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  129. },
  130. useOnlyCssZoom: {
  131. value: false,
  132. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  133. },
  134. viewOnLoad: {
  135. value: 0,
  136. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  137. },
  138. cMapPacked: {
  139. value: true,
  140. kind: OptionKind.API
  141. },
  142. cMapUrl: {
  143. value: "../web/cmaps/",
  144. kind: OptionKind.API
  145. },
  146. disableAutoFetch: {
  147. value: false,
  148. kind: OptionKind.API + OptionKind.PREFERENCE
  149. },
  150. disableFontFace: {
  151. value: false,
  152. kind: OptionKind.API + OptionKind.PREFERENCE
  153. },
  154. disableRange: {
  155. value: false,
  156. kind: OptionKind.API + OptionKind.PREFERENCE
  157. },
  158. disableStream: {
  159. value: false,
  160. kind: OptionKind.API + OptionKind.PREFERENCE
  161. },
  162. docBaseUrl: {
  163. value: "",
  164. kind: OptionKind.API
  165. },
  166. fontExtraProperties: {
  167. value: false,
  168. kind: OptionKind.API
  169. },
  170. isEvalSupported: {
  171. value: true,
  172. kind: OptionKind.API
  173. },
  174. maxImageSize: {
  175. value: -1,
  176. kind: OptionKind.API
  177. },
  178. pdfBug: {
  179. value: false,
  180. kind: OptionKind.API
  181. },
  182. verbosity: {
  183. value: 1,
  184. kind: OptionKind.API
  185. },
  186. workerPort: {
  187. value: null,
  188. kind: OptionKind.WORKER
  189. },
  190. workerSrc: {
  191. value: "../build/pdf.worker.js",
  192. kind: OptionKind.WORKER
  193. }
  194. };
  195. ;
  196. const userOptions = Object.create(null);
  197. class AppOptions {
  198. constructor() {
  199. throw new Error("Cannot initialize AppOptions.");
  200. }
  201. static get(name) {
  202. const userOption = userOptions[name];
  203. if (userOption !== undefined) {
  204. return userOption;
  205. }
  206. const defaultOption = defaultOptions[name];
  207. if (defaultOption !== undefined) {
  208. return defaultOption.compatibility || defaultOption.value;
  209. }
  210. return undefined;
  211. }
  212. static getAll(kind = null) {
  213. const options = Object.create(null);
  214. for (const name in defaultOptions) {
  215. const defaultOption = defaultOptions[name];
  216. if (kind) {
  217. if ((kind & defaultOption.kind) === 0) {
  218. continue;
  219. }
  220. if (kind === OptionKind.PREFERENCE) {
  221. const value = defaultOption.value,
  222. valueType = typeof value;
  223. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  224. options[name] = value;
  225. continue;
  226. }
  227. throw new Error(`Invalid type for preference: ${name}`);
  228. }
  229. }
  230. const userOption = userOptions[name];
  231. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility || defaultOption.value;
  232. }
  233. return options;
  234. }
  235. static set(name, value) {
  236. userOptions[name] = value;
  237. }
  238. static remove(name) {
  239. delete userOptions[name];
  240. }
  241. }
  242. exports.AppOptions = AppOptions;