mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Convert globalScope
and isNodeJS
to proper modules
Slightly unrelated to the rest of the patch, but this also removes an out-of-place `globals` definition from the `web/viewer.js` file.
This commit is contained in:
parent
c2bd3a0bfb
commit
2817121bc1
20 changed files with 34 additions and 27 deletions
|
@ -21,7 +21,7 @@ import {
|
|||
} from '../shared/util';
|
||||
import { clearPrimitiveCaches, Ref } from './primitives';
|
||||
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
||||
import isNodeJS from '../shared/is_node';
|
||||
import { isNodeJS } from '../shared/is_node';
|
||||
import { MessageHandler } from '../shared/message_handler';
|
||||
import { PDFWorkerStream } from './worker_stream';
|
||||
import { XRefParseException } from './core_utils';
|
||||
|
|
|
@ -33,7 +33,7 @@ import {
|
|||
import { FontFaceObject, FontLoader } from './font_loader';
|
||||
import { apiCompatibilityParams } from './api_compatibility';
|
||||
import { CanvasGraphics } from './canvas';
|
||||
import globalScope from '../shared/global_scope';
|
||||
import { globalScope } from '../shared/global_scope';
|
||||
import { GlobalWorkerOptions } from './worker_options';
|
||||
import { MessageHandler } from '../shared/message_handler';
|
||||
import { Metadata } from './metadata';
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
let compatibilityParams = Object.create(null);
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
const isNodeJS = require('../shared/is_node');
|
||||
const { isNodeJS, } = require('../shared/is_node');
|
||||
|
||||
const userAgent =
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent) || '';
|
||||
|
|
|
@ -20,7 +20,7 @@ import {
|
|||
TextRenderingMode, Util, warn
|
||||
} from '../shared/util';
|
||||
import { DOMSVGFactory } from './display_utils';
|
||||
import isNodeJS from '../shared/is_node';
|
||||
import { isNodeJS } from '../shared/is_node';
|
||||
|
||||
let SVGGraphics = function() {
|
||||
throw new Error('Not implemented: SVGGraphics');
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
||||
import globalScope from '../shared/global_scope';
|
||||
import { globalScope } from '../shared/global_scope';
|
||||
|
||||
/**
|
||||
* Text layer render parameters.
|
||||
|
|
|
@ -31,7 +31,7 @@ let pdfjsDisplayWorkerOptions = require('./display/worker_options.js');
|
|||
let pdfjsDisplayAPICompatibility = require('./display/api_compatibility.js');
|
||||
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
const isNodeJS = require('./shared/is_node.js');
|
||||
const { isNodeJS, } = require('./shared/is_node.js');
|
||||
if (isNodeJS()) {
|
||||
let PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
||||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
/* eslint no-var: error */
|
||||
|
||||
const globalScope = require('./global_scope');
|
||||
const { globalScope, } = require('./global_scope');
|
||||
|
||||
// Skip compatibility checks for modern builds and if we already ran the module.
|
||||
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('SKIP_BABEL')) &&
|
||||
|
@ -22,7 +22,7 @@ if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('SKIP_BABEL')) &&
|
|||
|
||||
globalScope._pdfjsCompatibilityChecked = true;
|
||||
|
||||
const isNodeJS = require('./is_node');
|
||||
const { isNodeJS, } = require('./is_node');
|
||||
|
||||
const hasDOM = typeof window === 'object' && typeof document === 'object';
|
||||
|
||||
|
|
|
@ -12,10 +12,13 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals module */
|
||||
|
||||
module.exports =
|
||||
const globalScope =
|
||||
(typeof window !== 'undefined' && window.Math === Math) ? window :
|
||||
// eslint-disable-next-line no-undef
|
||||
(typeof global !== 'undefined' && global.Math === Math) ? global :
|
||||
(typeof self !== 'undefined' && self.Math === Math) ? self : {};
|
||||
|
||||
export {
|
||||
globalScope,
|
||||
};
|
||||
|
|
|
@ -12,13 +12,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals module, process */
|
||||
/* globals process */
|
||||
|
||||
module.exports = function isNodeJS() {
|
||||
function isNodeJS() {
|
||||
// NW.js / Electron is a browser context, but copies some Node.js objects; see
|
||||
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
|
||||
// https://electronjs.org/docs/api/process#processversionselectron
|
||||
return typeof process === 'object' &&
|
||||
process + '' === '[object process]' &&
|
||||
!process.versions['nw'] && !process.versions['electron'];
|
||||
}
|
||||
|
||||
export {
|
||||
isNodeJS,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue