app_options.js 5.8 KB

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