UNPKG

5.99 kBJavaScriptView Raw
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
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.OptionKind = exports.AppOptions = void 0;
28
29var _pdf = require("../pdf");
30
31var _viewer_compatibility = require("./viewer_compatibility.js");
32
33const OptionKind = {
34 VIEWER: 0x02,
35 API: 0x04,
36 WORKER: 0x08,
37 PREFERENCE: 0x80
38};
39exports.OptionKind = OptionKind;
40const defaultOptions = {
41 cursorToolOnLoad: {
42 value: 0,
43 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
44 },
45 defaultUrl: {
46 value: "compressed.tracemonkey-pldi-09.pdf",
47 kind: OptionKind.VIEWER
48 },
49 defaultZoomValue: {
50 value: "",
51 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
52 },
53 disableHistory: {
54 value: false,
55 kind: OptionKind.VIEWER
56 },
57 disablePageLabels: {
58 value: false,
59 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
60 },
61 enablePrintAutoRotate: {
62 value: false,
63 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
64 },
65 enableWebGL: {
66 value: false,
67 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
68 },
69 eventBusDispatchToDOM: {
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 renderer: {
103 value: "canvas",
104 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
105 },
106 renderInteractiveForms: {
107 value: false,
108 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
109 },
110 sidebarViewOnLoad: {
111 value: -1,
112 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
113 },
114 scrollModeOnLoad: {
115 value: -1,
116 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
117 },
118 spreadModeOnLoad: {
119 value: -1,
120 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
121 },
122 textLayerMode: {
123 value: 1,
124 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
125 },
126 useOnlyCssZoom: {
127 value: false,
128 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
129 },
130 viewOnLoad: {
131 value: 0,
132 kind: OptionKind.VIEWER + OptionKind.PREFERENCE
133 },
134 cMapPacked: {
135 value: true,
136 kind: OptionKind.API
137 },
138 cMapUrl: {
139 value: "../web/cmaps/",
140 kind: OptionKind.API
141 },
142 disableAutoFetch: {
143 value: false,
144 kind: OptionKind.API + OptionKind.PREFERENCE
145 },
146 disableCreateObjectURL: {
147 value: false,
148 compatibility: _pdf.apiCompatibilityParams.disableCreateObjectURL,
149 kind: OptionKind.API
150 },
151 disableFontFace: {
152 value: false,
153 kind: OptionKind.API + OptionKind.PREFERENCE
154 },
155 disableRange: {
156 value: false,
157 kind: OptionKind.API + OptionKind.PREFERENCE
158 },
159 disableStream: {
160 value: false,
161 kind: OptionKind.API + OptionKind.PREFERENCE
162 },
163 docBaseUrl: {
164 value: "",
165 kind: OptionKind.API
166 },
167 isEvalSupported: {
168 value: true,
169 kind: OptionKind.API
170 },
171 maxImageSize: {
172 value: -1,
173 kind: OptionKind.API
174 },
175 pdfBug: {
176 value: false,
177 kind: OptionKind.API
178 },
179 verbosity: {
180 value: 1,
181 kind: OptionKind.API
182 },
183 workerPort: {
184 value: null,
185 kind: OptionKind.WORKER
186 },
187 workerSrc: {
188 value: "../build/pdf.worker.js",
189 kind: OptionKind.WORKER
190 }
191};
192;
193const userOptions = Object.create(null);
194
195class AppOptions {
196 constructor() {
197 throw new Error("Cannot initialize AppOptions.");
198 }
199
200 static get(name) {
201 const userOption = userOptions[name];
202
203 if (userOption !== undefined) {
204 return userOption;
205 }
206
207 const defaultOption = defaultOptions[name];
208
209 if (defaultOption !== undefined) {
210 return defaultOption.compatibility || defaultOption.value;
211 }
212
213 return undefined;
214 }
215
216 static getAll(kind = null) {
217 const options = Object.create(null);
218
219 for (const name in defaultOptions) {
220 const defaultOption = defaultOptions[name];
221
222 if (kind) {
223 if ((kind & defaultOption.kind) === 0) {
224 continue;
225 }
226
227 if (kind === OptionKind.PREFERENCE) {
228 const value = defaultOption.value,
229 valueType = typeof value;
230
231 if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
232 options[name] = value;
233 continue;
234 }
235
236 throw new Error(`Invalid type for preference: ${name}`);
237 }
238 }
239
240 const userOption = userOptions[name];
241 options[name] = userOption !== undefined ? userOption : defaultOption.compatibility || defaultOption.value;
242 }
243
244 return options;
245 }
246
247 static set(name, value) {
248 userOptions[name] = value;
249 }
250
251 static remove(name) {
252 delete userOptions[name];
253 }
254
255}
256
257exports.AppOptions = AppOptions;
\No newline at end of file