app_options.js 5.8 KB

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