Skip to content

Commit

Permalink
Update compiled files
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jul 19, 2017
1 parent aaee759 commit 528f76f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 30 deletions.
16 changes: 7 additions & 9 deletions build/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ var Document = function (_Component) {
_this.setState({ pdf: null });

if (!source) {
return;
return null;
}

PDFJS.getDocument(source).then(_this.onLoadSuccess).catch(_this.onLoadError);
return PDFJS.getDocument(source).then(_this.onLoadSuccess).catch(_this.onLoadError);
}, _this.onSourceError = function (error) {
(0, _util.callIfDefined)(_this.props.onSourceError, error);

Expand Down Expand Up @@ -89,9 +89,7 @@ var Document = function (_Component) {

// File is a string
if ((0, _util.isString)(file)) {
if (_util.isLocalFileSystem) {
// @TODO: Display CORS warning
}
(0, _util.displayCORSWarning)();

return resolve(file);
}
Expand All @@ -110,8 +108,8 @@ var Document = function (_Component) {
var _fileBlobURL = (0, _util.dataURItoURL)(modifiedFile.url);

modifiedFile.url = _fileBlobURL;
} else if (_util.isLocalFileSystem) {
// @TODO: Display CORS warning
} else {
(0, _util.displayCORSWarning)();
}
}

Expand Down Expand Up @@ -205,7 +203,7 @@ var Document = function (_Component) {
value: function loadDocument() {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;

this.findDocumentSource(props).then(this.onSourceSuccess).catch(this.onSourceError);
return this.findDocumentSource(props).then(this.onSourceSuccess).catch(this.onSourceError);
}

/**
Expand Down Expand Up @@ -310,8 +308,8 @@ Document.propTypes = {
})]),
loading: _propTypes2.default.node,
noData: _propTypes2.default.node,
onLoadSuccess: _propTypes2.default.func,
onLoadError: _propTypes2.default.func,
onLoadSuccess: _propTypes2.default.func,
onSourceError: _propTypes2.default.func,
onSourceSuccess: _propTypes2.default.func,
rotate: _propTypes2.default.number
Expand Down
10 changes: 8 additions & 2 deletions build/Outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// eslint-disable-next-line no-underscore-dangle
if (!window._babelPolyfill) {
// eslint-disable-next-line global-require
require('babel-polyfill');
}

var Ref = function () {
function Ref(_ref) {
var num = _ref.num,
Expand Down Expand Up @@ -72,7 +78,7 @@ var Outline = function (_Component) {
}, _this.onLoadSuccess = function (outline) {
(0, _util.callIfDefined)(_this.props.onLoadSuccess);

_this.parseOutline(outline).then(_this.onParseSuccess).catch(_this.onParseError);
return _this.parseOutline(outline).then(_this.onParseSuccess).catch(_this.onParseError);
}, _this.onLoadError = function (error) {
(0, _util.callIfDefined)(_this.props.onLoadError, error);

Expand Down Expand Up @@ -350,7 +356,7 @@ var Outline = function (_Component) {
this.setState({ outline: null });
}

pdf.getOutline().then(this.onLoadSuccess).catch(this.onLoadError);
return pdf.getOutline().then(this.onLoadSuccess).catch(this.onLoadError);
}
}, {
key: 'renderOutline',
Expand Down
6 changes: 1 addition & 5 deletions build/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ var Page = function (_Component) {
}

if ((0, _util.isProvided)(props.pageNumber)) {
// @TODO: Page number isn't always the same
return props.pageNumber - 1;
}

Expand All @@ -128,7 +127,6 @@ var Page = function (_Component) {
}

if ((0, _util.isProvided)(props.pageIndex)) {
// @TODO: Page index isn't always the same
return props.pageIndex + 1;
}

Expand All @@ -150,7 +148,7 @@ var Page = function (_Component) {
this.setState({ page: null });
}

pdf.getPage(pageNumber).then(this.onLoadSuccess).catch(this.onLoadError);
return pdf.getPage(pageNumber).then(this.onLoadSuccess).catch(this.onLoadError);
}
}, {
key: 'render',
Expand Down Expand Up @@ -205,7 +203,6 @@ var Page = function (_Component) {
}, {
key: 'pageNumber',
get: function get() {
// @TODO: Page numer isn't always the same
return this.getPageNumber();
}
}, {
Expand Down Expand Up @@ -263,7 +260,6 @@ Page.propTypes = {
onLoadSuccess: _propTypes2.default.func,
onRenderError: _propTypes2.default.func,
onRenderSuccess: _propTypes2.default.func,
// @TODO: Check if > 0, < pdf.numPages
pageIndex: _propTypes2.default.number, // eslint-disable-line react/no-unused-prop-types
pageNumber: _propTypes2.default.number, // eslint-disable-line react/no-unused-prop-types
pdf: _propTypes2.default.shape({
Expand Down
4 changes: 2 additions & 2 deletions build/PageCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var PageCanvas = function (_Component) {
(0, _util.callIfDefined)(_this.props.onRenderError, error);
}, _this.drawPageOnCanvas = function (canvas) {
if (!canvas) {
return;
return null;
}

var page = _this.props.page;
Expand Down Expand Up @@ -77,7 +77,7 @@ var PageCanvas = function (_Component) {

_this.renderer = page.render(renderContext);

_this.renderer.then(_this.onRenderSuccess).catch(function (dismiss) {
return _this.renderer.then(_this.onRenderSuccess).catch(function (dismiss) {
if (dismiss === 'cancelled') {
// Everything's alright
return;
Expand Down
8 changes: 7 additions & 1 deletion build/PageTextContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

// eslint-disable-next-line no-underscore-dangle
if (!window._babelPolyfill) {
// eslint-disable-next-line global-require
require('babel-polyfill');
}

// Render disproportion above which font will be considered broken and fallback will be used
var BROKEN_FONT_ALARM_THRESHOLD = 0.1;

Expand Down Expand Up @@ -126,7 +132,7 @@ var PageTextContent = function (_Component) {
this.setState({ textItems: null });
}

page.getTextContent().then(this.onGetTextSuccess).catch(this.onGetTextError);
return page.getTextContent().then(this.onGetTextSuccess).catch(this.onGetTextError);
}
}, {
key: 'getFontData',
Expand Down
11 changes: 10 additions & 1 deletion build/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ var _Page = require('./Page');

var _Page2 = _interopRequireDefault(_Page);

var _util = require('./shared/util');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

require('pdfjs-dist');
if (_util.isLocalFileSystem) {
// eslint-disable-next-line no-console
(0, _util.warnOnDev)('You are running React-PDF from your local file system. PDF.js Worker may fail to load due to browser\'s security policies. If you\'re on Google Chrome, you can use --allow-file-access-from-files flag for debugging purposes.');
}

var pdfjs = require('pdfjs-dist');
require('pdfjs-dist/web/compatibility');

pdfjs.PDFJS.workerSrc = 'pdf.worker.js';

exports.Document = _Document2.default;
exports.Outline = _Outline2.default;
exports.Page = _Page2.default;
29 changes: 29 additions & 0 deletions build/entry.noworker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Page = exports.Outline = exports.Document = undefined;

var _Document = require('./Document');

var _Document2 = _interopRequireDefault(_Document);

var _Outline = require('./Outline');

var _Outline2 = _interopRequireDefault(_Outline);

var _Page = require('./Page');

var _Page2 = _interopRequireDefault(_Page);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var pdfjs = require('pdfjs-dist/build/pdf.combined');
require('pdfjs-dist/web/compatibility');

pdfjs.PDFJS.disableWorker = true;

exports.Document = _Document2.default;
exports.Outline = _Outline2.default;
exports.Page = _Page2.default;
4 changes: 2 additions & 2 deletions build/entry.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ var _util = require('./shared/util');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

if ((0, _util.isLocalFileSystem)()) {
if (_util.isLocalFileSystem) {
// eslint-disable-next-line no-console
console.warn('You are running React-PDF from your local file system. PDF.js Worker may fail to load due to browser\'s security policies. If you\'re on Google Chrome, you can use --allow-file-access-from-files flag for debugging purposes.');
(0, _util.warnOnDev)('You are running React-PDF from your local file system. PDF.js Worker may fail to load due to browser\'s security policies. If you\'re on Google Chrome, you can use --allow-file-access-from-files flag for debugging purposes.');
}

require('pdfjs-dist/webpack');
Expand Down
31 changes: 23 additions & 8 deletions build/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ Object.defineProperty(exports, "__esModule", {
/**
* Checks if we're running in a browser environment.
*/
var isBrowser = exports.isBrowser = function isBrowser() {
return typeof window !== 'undefined';
};
var isBrowser = exports.isBrowser = typeof window !== 'undefined';

/**
* Checks whether we're running from a local file system.
*/
var isLocalFileSystem = exports.isLocalFileSystem = function isLocalFileSystem() {
return isBrowser() && window.location.protocol === 'file:';
};
var isLocalFileSystem = exports.isLocalFileSystem = isBrowser && window.location.protocol === 'file:';

/**
* Checks whether we're running on a production build or not.
*/
var isProduction = exports.isProduction = process.env.NODE_ENV === 'production';

/**
* Checks whether a variable is defined.
Expand Down Expand Up @@ -59,7 +60,7 @@ var isArrayBuffer = exports.isArrayBuffer = function isArrayBuffer(variable) {
* @param {*} variable Variable to check
*/
var isBlob = exports.isBlob = function isBlob(variable) {
if (!isBrowser()) {
if (!isBrowser) {
throw new Error('Attempted to check if a variable is a Blob on a non-browser environment.');
}

Expand All @@ -72,7 +73,7 @@ var isBlob = exports.isBlob = function isBlob(variable) {
* @param {*} variable Variable to check
*/
var isFile = exports.isFile = function isFile(variable) {
if (!isBrowser()) {
if (!isBrowser) {
throw new Error('Attempted to check if a variable is a Blob on a non-browser environment.');
}

Expand Down Expand Up @@ -149,4 +150,18 @@ var callIfDefined = exports.callIfDefined = function callIfDefined(fn, args) {

var getPixelRatio = exports.getPixelRatio = function getPixelRatio() {
return window.devicePixelRatio || 1;
};

var warnOnDev = exports.warnOnDev = function warnOnDev(message) {
if (!isProduction) {
// eslint-disable-next-line no-console
console.warn(message);
}
};

var displayCORSWarning = exports.displayCORSWarning = function displayCORSWarning() {
if (isLocalFileSystem) {
// eslint-disable-next-line no-console
warnOnDev('Loading PDF as base64 strings/URLs might not work on protocols other than HTTP/HTTPS. On Google Chrome, you can use --allow-file-access-from-files flag for debugging purposes.');
}
};

0 comments on commit 528f76f

Please sign in to comment.