app_options.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 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 = undefined;
  27. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  28. var _pdf = require('../pdf');
  29. var _viewer_compatibility = require('./viewer_compatibility');
  30. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31. var OptionKind = {
  32. VIEWER: 'viewer',
  33. API: 'api',
  34. WORKER: 'worker'
  35. };
  36. var defaultOptions = {
  37. cursorToolOnLoad: {
  38. value: 0,
  39. kind: OptionKind.VIEWER
  40. },
  41. defaultUrl: {
  42. value: 'compressed.tracemonkey-pldi-09.pdf',
  43. kind: OptionKind.VIEWER
  44. },
  45. defaultZoomValue: {
  46. value: '',
  47. kind: OptionKind.VIEWER
  48. },
  49. disableFullscreen: {
  50. value: _viewer_compatibility.viewerCompatibilityParams.disableFullscreen || false,
  51. kind: OptionKind.VIEWER
  52. },
  53. disableHistory: {
  54. value: false,
  55. kind: OptionKind.VIEWER
  56. },
  57. disablePageLabels: {
  58. value: false,
  59. kind: OptionKind.VIEWER
  60. },
  61. disablePageMode: {
  62. value: false,
  63. kind: OptionKind.VIEWER
  64. },
  65. enablePrintAutoRotate: {
  66. value: false,
  67. kind: OptionKind.VIEWER
  68. },
  69. enableWebGL: {
  70. value: false,
  71. kind: OptionKind.VIEWER
  72. },
  73. externalLinkRel: {
  74. value: 'noopener noreferrer nofollow',
  75. kind: OptionKind.VIEWER
  76. },
  77. externalLinkTarget: {
  78. value: 0,
  79. kind: OptionKind.VIEWER
  80. },
  81. imageResourcesPath: {
  82. value: './images/',
  83. kind: OptionKind.VIEWER
  84. },
  85. locale: {
  86. value: typeof navigator !== 'undefined' ? navigator.language : 'en-US',
  87. kind: OptionKind.VIEWER
  88. },
  89. maxCanvasPixels: {
  90. value: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216,
  91. kind: OptionKind.VIEWER
  92. },
  93. pdfBugEnabled: {
  94. value: false,
  95. kind: OptionKind.VIEWER
  96. },
  97. renderer: {
  98. value: 'canvas',
  99. kind: OptionKind.VIEWER
  100. },
  101. renderInteractiveForms: {
  102. value: false,
  103. kind: OptionKind.VIEWER
  104. },
  105. showPreviousViewOnLoad: {
  106. value: true,
  107. kind: OptionKind.VIEWER
  108. },
  109. sidebarViewOnLoad: {
  110. value: 0,
  111. kind: OptionKind.VIEWER
  112. },
  113. textLayerMode: {
  114. value: 1,
  115. kind: OptionKind.VIEWER
  116. },
  117. useOnlyCssZoom: {
  118. value: false,
  119. kind: OptionKind.VIEWER
  120. },
  121. cMapPacked: {
  122. value: true,
  123. kind: OptionKind.API
  124. },
  125. cMapUrl: {
  126. value: '../web/cmaps/',
  127. kind: OptionKind.API
  128. },
  129. disableAutoFetch: {
  130. value: false,
  131. kind: OptionKind.API
  132. },
  133. disableCreateObjectURL: {
  134. value: _pdf.apiCompatibilityParams.disableCreateObjectURL || false,
  135. kind: OptionKind.API
  136. },
  137. disableFontFace: {
  138. value: false,
  139. kind: OptionKind.API
  140. },
  141. disableRange: {
  142. value: _pdf.apiCompatibilityParams.disableRange || false,
  143. kind: OptionKind.API
  144. },
  145. disableStream: {
  146. value: _pdf.apiCompatibilityParams.disableStream || false,
  147. kind: OptionKind.API
  148. },
  149. isEvalSupported: {
  150. value: true,
  151. kind: OptionKind.API
  152. },
  153. maxImageSize: {
  154. value: -1,
  155. kind: OptionKind.API
  156. },
  157. pdfBug: {
  158. value: false,
  159. kind: OptionKind.API
  160. },
  161. postMessageTransfers: {
  162. value: true,
  163. kind: OptionKind.API
  164. },
  165. verbosity: {
  166. value: 1,
  167. kind: OptionKind.API
  168. },
  169. workerPort: {
  170. value: null,
  171. kind: OptionKind.WORKER
  172. },
  173. workerSrc: {
  174. value: '../build/pdf.worker.js',
  175. kind: OptionKind.WORKER
  176. }
  177. };
  178. var userOptions = Object.create(null);
  179. var AppOptions = function () {
  180. function AppOptions() {
  181. _classCallCheck(this, AppOptions);
  182. throw new Error('Cannot initialize AppOptions.');
  183. }
  184. _createClass(AppOptions, null, [{
  185. key: 'get',
  186. value: function get(name) {
  187. var defaultOption = defaultOptions[name],
  188. userOption = userOptions[name];
  189. if (userOption !== undefined) {
  190. return userOption;
  191. }
  192. return defaultOption !== undefined ? defaultOption.value : undefined;
  193. }
  194. }, {
  195. key: 'getAll',
  196. value: function getAll() {
  197. var kind = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  198. var options = Object.create(null);
  199. for (var name in defaultOptions) {
  200. var defaultOption = defaultOptions[name],
  201. userOption = userOptions[name];
  202. if (kind && defaultOption.kind !== kind) {
  203. continue;
  204. }
  205. options[name] = userOption !== undefined ? userOption : defaultOption.value;
  206. }
  207. return options;
  208. }
  209. }, {
  210. key: 'set',
  211. value: function set(name, value) {
  212. userOptions[name] = value;
  213. }
  214. }, {
  215. key: 'remove',
  216. value: function remove(name) {
  217. delete userOptions[name];
  218. }
  219. }]);
  220. return AppOptions;
  221. }();
  222. exports.AppOptions = AppOptions;
  223. exports.OptionKind = OptionKind;