asma-doc-viewer 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/.idea/workspace.xml +51 -5
  2. package/CHANGELOG.md +293 -0
  3. package/build/components/DocumentNav.d.ts +2 -0
  4. package/build/components/DocumentNav.js +64 -0
  5. package/build/components/FileName.d.ts +2 -0
  6. package/build/components/FileName.js +61 -0
  7. package/build/components/HeaderBar.d.ts +2 -0
  8. package/build/components/HeaderBar.js +58 -0
  9. package/build/components/ProxyRenderer.d.ts +2 -0
  10. package/build/components/ProxyRenderer.js +80 -0
  11. package/build/components/common/Button.d.ts +11 -0
  12. package/build/components/common/Button.js +38 -0
  13. package/build/components/common/index.d.ts +1 -0
  14. package/build/components/common/index.js +17 -0
  15. package/build/components/icons/index.d.ts +9 -0
  16. package/build/components/icons/index.js +45 -0
  17. package/build/index.d.ts +26 -0
  18. package/build/index.js +89 -0
  19. package/build/plugins/bmp/index.d.ts +3 -0
  20. package/build/plugins/bmp/index.js +22 -0
  21. package/build/plugins/html/index.d.ts +3 -0
  22. package/build/plugins/html/index.js +60 -0
  23. package/build/plugins/image/index.d.ts +3 -0
  24. package/build/plugins/image/index.js +34 -0
  25. package/build/plugins/index.d.ts +1 -0
  26. package/build/plugins/index.js +26 -0
  27. package/build/plugins/jpg/index.d.ts +3 -0
  28. package/build/plugins/jpg/index.js +22 -0
  29. package/build/plugins/msdoc/index.d.ts +3 -0
  30. package/build/plugins/msdoc/index.js +54 -0
  31. package/build/plugins/pdf/components/PDFControls.d.ts +3 -0
  32. package/build/plugins/pdf/components/PDFControls.js +73 -0
  33. package/build/plugins/pdf/components/PDFPagination.d.ts +3 -0
  34. package/build/plugins/pdf/components/PDFPagination.js +57 -0
  35. package/build/plugins/pdf/components/icons/index.d.ts +10 -0
  36. package/build/plugins/pdf/components/icons/index.js +79 -0
  37. package/build/plugins/pdf/components/pages/PDFAllPages.d.ts +6 -0
  38. package/build/plugins/pdf/components/pages/PDFAllPages.js +41 -0
  39. package/build/plugins/pdf/components/pages/PDFPages.d.ts +3 -0
  40. package/build/plugins/pdf/components/pages/PDFPages.js +56 -0
  41. package/build/plugins/pdf/components/pages/PDFSinglePage.d.ts +6 -0
  42. package/build/plugins/pdf/components/pages/PDFSinglePage.js +53 -0
  43. package/build/plugins/pdf/index.d.ts +3 -0
  44. package/build/plugins/pdf/index.js +55 -0
  45. package/build/plugins/pdf/state/actions.d.ts +25 -0
  46. package/build/plugins/pdf/state/actions.js +31 -0
  47. package/build/plugins/pdf/state/index.d.ts +13 -0
  48. package/build/plugins/pdf/state/index.js +47 -0
  49. package/build/plugins/pdf/state/reducer.d.ts +12 -0
  50. package/build/plugins/pdf/state/reducer.js +45 -0
  51. package/build/plugins/png/index.d.ts +3 -0
  52. package/build/plugins/png/index.js +29 -0
  53. package/build/plugins/tiff/index.d.ts +3 -0
  54. package/build/plugins/tiff/index.js +77 -0
  55. package/build/plugins/tiff/tiffToCanvas.d.ts +1 -0
  56. package/build/plugins/tiff/tiffToCanvas.js +602 -0
  57. package/build/plugins/txt/index.d.ts +3 -0
  58. package/build/plugins/txt/index.js +24 -0
  59. package/build/plugins/webp/index.d.ts +3 -0
  60. package/build/plugins/webp/index.js +59 -0
  61. package/build/state/actions.d.ts +42 -0
  62. package/build/state/actions.js +45 -0
  63. package/build/state/index.d.ts +10 -0
  64. package/build/state/index.js +54 -0
  65. package/build/state/reducer.d.ts +14 -0
  66. package/build/state/reducer.js +64 -0
  67. package/build/theme/index.d.ts +2 -0
  68. package/build/theme/index.js +12 -0
  69. package/build/types/index.d.ts +41 -0
  70. package/build/types/index.js +2 -0
  71. package/build/utils/fileLoaders.d.ts +12 -0
  72. package/build/utils/fileLoaders.js +105 -0
  73. package/build/utils/useDocumentLoader.d.ts +12 -0
  74. package/build/utils/useDocumentLoader.js +82 -0
  75. package/build/utils/useRendererSelector.d.ts +7 -0
  76. package/build/utils/useRendererSelector.js +40 -0
  77. package/build/utils/useWindowSize.d.ts +4 -0
  78. package/build/utils/useWindowSize.js +34 -0
  79. package/package.json +17 -17
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ var react_1 = __importDefault(require("react"));
11
+ var styled_components_1 = __importDefault(require("styled-components"));
12
+ var fileLoaders_1 = require("../../utils/fileLoaders");
13
+ var TXTRenderer = function (_a) {
14
+ var currentDocument = _a.mainState.currentDocument;
15
+ if (!currentDocument || !currentDocument.fileData)
16
+ return null;
17
+ return react_1.default.createElement(Container, { id: "txt-renderer" }, currentDocument.fileData);
18
+ };
19
+ exports.default = TXTRenderer;
20
+ TXTRenderer.fileTypes = ["txt", "text/plain"];
21
+ TXTRenderer.weight = 0;
22
+ TXTRenderer.fileLoader = fileLoaders_1.textFileLoader;
23
+ var Container = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n width: 100%;\n padding: 30px;\n"], ["\n display: flex;\n flex-direction: column;\n width: 100%;\n padding: 30px;\n"])));
24
+ var templateObject_1;
@@ -0,0 +1,3 @@
1
+ import { DocRenderer } from "../../types";
2
+ declare const WEBPRenderer: DocRenderer;
3
+ export default WEBPRenderer;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ var react_1 = __importStar(require("react"));
41
+ var image_1 = __importDefault(require("../image"));
42
+ var WEBPRenderer = function (props) {
43
+ var _a;
44
+ var _b = (0, react_1.useState)(), imageUrl = _b[0], setImageUrl = _b[1];
45
+ var webpBuffer = (_a = props.mainState.currentDocument) === null || _a === void 0 ? void 0 : _a.fileData;
46
+ (0, react_1.useEffect)(function () {
47
+ if (webpBuffer) {
48
+ var blob = new Blob([webpBuffer], { type: 'image/webp' });
49
+ var url = URL.createObjectURL(blob);
50
+ setImageUrl(url);
51
+ }
52
+ }, [webpBuffer]);
53
+ return (react_1.default.createElement(image_1.default, __assign({}, props),
54
+ react_1.default.createElement("picture", null,
55
+ react_1.default.createElement("source", { srcSet: imageUrl }))));
56
+ };
57
+ WEBPRenderer.fileTypes = ["webp", "image/webp"];
58
+ WEBPRenderer.weight = 0;
59
+ exports.default = WEBPRenderer;
@@ -0,0 +1,42 @@
1
+ import { IConfig, IDocument } from "../types";
2
+ export declare const SET_ALL_DOCUMENTS: string;
3
+ export interface SetAllDocuments {
4
+ type: typeof SET_ALL_DOCUMENTS;
5
+ documents: IDocument[];
6
+ }
7
+ export declare const setAllDocuments: (documents: IDocument[]) => SetAllDocuments;
8
+ export declare const SET_DOCUMENT_LOADING: string;
9
+ export interface SetDocumentLoading {
10
+ type: typeof SET_DOCUMENT_LOADING;
11
+ value: boolean;
12
+ }
13
+ export declare const setDocumentLoading: (value: boolean) => SetDocumentLoading;
14
+ export declare const NEXT_DOCUMENT: string;
15
+ export interface NextDocument {
16
+ type: typeof NEXT_DOCUMENT;
17
+ }
18
+ export declare const nextDocument: () => NextDocument;
19
+ export declare const PREVIOUS_DOCUMENT: string;
20
+ export interface PreviousDocument {
21
+ type: typeof PREVIOUS_DOCUMENT;
22
+ }
23
+ export declare const previousDocument: () => PreviousDocument;
24
+ export declare const UPDATE_CURRENT_DOCUMENT: string;
25
+ export interface UpdateCurrentDocument {
26
+ type: typeof UPDATE_CURRENT_DOCUMENT;
27
+ document: IDocument;
28
+ }
29
+ export declare const updateCurrentDocument: (document: IDocument) => UpdateCurrentDocument;
30
+ export declare const SET_RENDERER_RECT: string;
31
+ export interface SetRendererRect {
32
+ type: typeof SET_RENDERER_RECT;
33
+ rect: DOMRect;
34
+ }
35
+ export declare const setRendererRect: (rect: DOMRect) => SetRendererRect;
36
+ export declare const SET_MAIN_CONFIG: string;
37
+ export interface SetMainConfig {
38
+ type: typeof SET_MAIN_CONFIG;
39
+ config: IConfig;
40
+ }
41
+ export declare const setMainConfig: (config: IConfig) => SetMainConfig;
42
+ export type MainStateActions = SetAllDocuments | SetDocumentLoading | NextDocument | PreviousDocument | UpdateCurrentDocument | SetRendererRect | SetMainConfig;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setMainConfig = exports.SET_MAIN_CONFIG = exports.setRendererRect = exports.SET_RENDERER_RECT = exports.updateCurrentDocument = exports.UPDATE_CURRENT_DOCUMENT = exports.previousDocument = exports.PREVIOUS_DOCUMENT = exports.nextDocument = exports.NEXT_DOCUMENT = exports.setDocumentLoading = exports.SET_DOCUMENT_LOADING = exports.setAllDocuments = exports.SET_ALL_DOCUMENTS = void 0;
4
+ // SET_DOCUMENTS
5
+ exports.SET_ALL_DOCUMENTS = "SET_ALL_DOCUMENTS";
6
+ var setAllDocuments = function (documents) { return ({
7
+ type: exports.SET_ALL_DOCUMENTS,
8
+ documents: documents,
9
+ }); };
10
+ exports.setAllDocuments = setAllDocuments;
11
+ // SET_DOCUMENT_LOADING
12
+ exports.SET_DOCUMENT_LOADING = "SET_DOCUMENT_LOADING";
13
+ var setDocumentLoading = function (value) { return ({
14
+ type: exports.SET_DOCUMENT_LOADING,
15
+ value: value,
16
+ }); };
17
+ exports.setDocumentLoading = setDocumentLoading;
18
+ // NEXT_DOCUMENT
19
+ exports.NEXT_DOCUMENT = "NEXT_DOCUMENT";
20
+ var nextDocument = function () { return ({ type: exports.NEXT_DOCUMENT }); };
21
+ exports.nextDocument = nextDocument;
22
+ // PREVIOUS_DOCUMENT
23
+ exports.PREVIOUS_DOCUMENT = "PREVIOUS_DOCUMENT";
24
+ var previousDocument = function () { return ({
25
+ type: exports.PREVIOUS_DOCUMENT,
26
+ }); };
27
+ exports.previousDocument = previousDocument;
28
+ // UPDATE_CURRENT_DOCUMENT
29
+ exports.UPDATE_CURRENT_DOCUMENT = "UPDATE_CURRENT_DOCUMENT";
30
+ var updateCurrentDocument = function (document) { return ({ type: exports.UPDATE_CURRENT_DOCUMENT, document: document }); };
31
+ exports.updateCurrentDocument = updateCurrentDocument;
32
+ // SET_RENDERER_RECT
33
+ exports.SET_RENDERER_RECT = "SET_RENDERER_RECT";
34
+ var setRendererRect = function (rect) { return ({
35
+ type: exports.SET_RENDERER_RECT,
36
+ rect: rect,
37
+ }); };
38
+ exports.setRendererRect = setRendererRect;
39
+ // SET_MAIN_CONFIG
40
+ exports.SET_MAIN_CONFIG = "SET_MAIN_CONFIG";
41
+ var setMainConfig = function (config) { return ({
42
+ type: exports.SET_MAIN_CONFIG,
43
+ config: config,
44
+ }); };
45
+ exports.setMainConfig = setMainConfig;
@@ -0,0 +1,10 @@
1
+ import React, { Dispatch, FC } from "react";
2
+ import { DocViewerProps } from "..";
3
+ import { MainStateActions } from "./actions";
4
+ import { IMainState } from "./reducer";
5
+ declare const DocViewerContext: React.Context<{
6
+ state: IMainState;
7
+ dispatch: Dispatch<MainStateActions>;
8
+ }>;
9
+ declare const AppProvider: FC<DocViewerProps>;
10
+ export { DocViewerContext, AppProvider };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.AppProvider = exports.DocViewerContext = void 0;
38
+ var react_1 = __importStar(require("react"));
39
+ var actions_1 = require("./actions");
40
+ var reducer_1 = require("./reducer");
41
+ var DocViewerContext = (0, react_1.createContext)({ state: reducer_1.initialState, dispatch: function () { return null; } });
42
+ exports.DocViewerContext = DocViewerContext;
43
+ var AppProvider = function (props) {
44
+ var children = props.children, documents = props.documents, config = props.config, pluginRenderers = props.pluginRenderers;
45
+ var _a = (0, react_1.useReducer)(reducer_1.mainStateReducer, __assign(__assign({}, reducer_1.initialState), { documents: documents || [], currentDocument: documents && documents.length ? documents[0] : undefined, config: config, pluginRenderers: pluginRenderers })), state = _a[0], dispatch = _a[1];
46
+ // On inital load, and whenever they change,
47
+ // replace documents with the new props passed in
48
+ (0, react_1.useEffect)(function () {
49
+ dispatch((0, actions_1.setAllDocuments)(documents));
50
+ config && dispatch((0, actions_1.setMainConfig)(config));
51
+ }, [documents]);
52
+ return (react_1.default.createElement(DocViewerContext.Provider, { value: { state: state, dispatch: dispatch } }, children));
53
+ };
54
+ exports.AppProvider = AppProvider;
@@ -0,0 +1,14 @@
1
+ import { DocRenderer, IConfig, IDocument } from "../types";
2
+ import { MainStateActions } from "./actions";
3
+ export type IMainState = {
4
+ currentFileNo: number;
5
+ documents: IDocument[];
6
+ documentLoading?: boolean;
7
+ currentDocument?: IDocument;
8
+ rendererRect?: DOMRect;
9
+ config?: IConfig;
10
+ pluginRenderers?: DocRenderer[];
11
+ };
12
+ export declare const initialState: IMainState;
13
+ export type MainStateReducer = (state: IMainState, action: MainStateActions) => IMainState;
14
+ export declare const mainStateReducer: MainStateReducer;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.mainStateReducer = exports.initialState = void 0;
15
+ var actions_1 = require("./actions");
16
+ exports.initialState = {
17
+ currentFileNo: 0,
18
+ documents: [],
19
+ documentLoading: true,
20
+ currentDocument: undefined,
21
+ rendererRect: undefined,
22
+ config: {},
23
+ pluginRenderers: [],
24
+ };
25
+ var mainStateReducer = function (state, action) {
26
+ if (state === void 0) { state = exports.initialState; }
27
+ switch (action.type) {
28
+ case actions_1.SET_ALL_DOCUMENTS: {
29
+ var documents = action.documents;
30
+ return __assign(__assign({}, state), { documents: documents, currentDocument: documents[0] || null });
31
+ }
32
+ case actions_1.SET_DOCUMENT_LOADING: {
33
+ var value = action.value;
34
+ return __assign(__assign({}, state), { documentLoading: value });
35
+ }
36
+ case actions_1.NEXT_DOCUMENT: {
37
+ if (state.currentFileNo >= state.documents.length - 1)
38
+ return state;
39
+ var nextDocumentNo = state.currentFileNo + 1;
40
+ return __assign(__assign({}, state), { currentFileNo: nextDocumentNo, currentDocument: state.documents[nextDocumentNo], documentLoading: true });
41
+ }
42
+ case actions_1.PREVIOUS_DOCUMENT: {
43
+ if (state.currentFileNo <= 0)
44
+ return state;
45
+ var prevDocumentNo = state.currentFileNo - 1;
46
+ return __assign(__assign({}, state), { currentFileNo: state.currentFileNo - 1, currentDocument: state.documents[prevDocumentNo], documentLoading: true });
47
+ }
48
+ case actions_1.UPDATE_CURRENT_DOCUMENT: {
49
+ var document_1 = action.document;
50
+ return __assign(__assign({}, state), { currentDocument: document_1 });
51
+ }
52
+ case actions_1.SET_RENDERER_RECT: {
53
+ var rect = action.rect;
54
+ return __assign(__assign({}, state), { rendererRect: rect });
55
+ }
56
+ case actions_1.SET_MAIN_CONFIG: {
57
+ var config = action.config;
58
+ return __assign(__assign({}, state), { config: config });
59
+ }
60
+ default:
61
+ return state;
62
+ }
63
+ };
64
+ exports.mainStateReducer = mainStateReducer;
@@ -0,0 +1,2 @@
1
+ import { ITheme } from "../types";
2
+ export declare const defaultTheme: ITheme;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultTheme = void 0;
4
+ exports.defaultTheme = {
5
+ primary: "#fff",
6
+ secondary: "#000",
7
+ tertiary: "#ffffff99",
8
+ text_primary: "#000",
9
+ text_secondary: "#fff",
10
+ text_tertiary: "#00000044",
11
+ disableThemeScrollbar: false,
12
+ };
@@ -0,0 +1,41 @@
1
+ import { FC, ReactElement } from 'react';
2
+ import { ThemedStyledProps } from 'styled-components';
3
+ import { IMainState } from '../state/reducer';
4
+ import { FileLoaderFunction } from '../utils/fileLoaders';
5
+ export interface IConfig {
6
+ header?: IHeaderConfig;
7
+ }
8
+ export interface IHeaderConfig {
9
+ disableHeader?: boolean;
10
+ disableFileName?: boolean;
11
+ retainURLParams?: boolean;
12
+ overrideComponent?: IHeaderOverride;
13
+ }
14
+ export type IHeaderOverride = (state: IMainState, previousDocument: () => void, nextDocument: () => void) => ReactElement<any, any> | null;
15
+ export interface ITheme {
16
+ primary?: string;
17
+ secondary?: string;
18
+ tertiary?: string;
19
+ text_primary?: string;
20
+ text_secondary?: string;
21
+ text_tertiary?: string;
22
+ disableThemeScrollbar?: boolean;
23
+ }
24
+ export interface IStyledProps extends ThemedStyledProps<any, any> {
25
+ theme: ITheme;
26
+ }
27
+ export interface IDocument {
28
+ uri: string;
29
+ fileType?: string;
30
+ fileData?: string | ArrayBuffer;
31
+ fileName?: string;
32
+ }
33
+ export interface DocRendererProps {
34
+ mainState: IMainState;
35
+ children?: ReactElement<any, any> | null;
36
+ }
37
+ export interface DocRenderer extends FC<DocRendererProps> {
38
+ fileTypes: string[];
39
+ weight: number;
40
+ fileLoader?: FileLoaderFunction | null | undefined;
41
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ export interface FileLoaderFuncProps {
2
+ documentURI: string;
3
+ signal: AbortSignal;
4
+ fileLoaderComplete: FileLoaderComplete;
5
+ }
6
+ export type FileLoaderComplete = (fileReader?: FileReader) => void;
7
+ export type FileLoaderFunction = (props: FileLoaderFuncProps) => void;
8
+ export declare const arrayBufferFileLoader: FileLoaderFunction;
9
+ export declare const dataURLFileLoader: FileLoaderFunction;
10
+ export declare const textFileLoader: FileLoaderFunction;
11
+ export declare const binaryStringFileLoader: FileLoaderFunction;
12
+ export declare const defaultFileLoader: FileLoaderFunction;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.defaultFileLoader = exports.binaryStringFileLoader = exports.textFileLoader = exports.dataURLFileLoader = exports.arrayBufferFileLoader = void 0;
51
+ var _fileLoader = function (_a) {
52
+ var documentURI = _a.documentURI, signal = _a.signal, fileLoaderComplete = _a.fileLoaderComplete, readerTypeFunction = _a.readerTypeFunction;
53
+ return fetch(documentURI, { signal: signal })
54
+ .then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
55
+ var blob, fileReader;
56
+ return __generator(this, function (_a) {
57
+ switch (_a.label) {
58
+ case 0: return [4 /*yield*/, res.blob()];
59
+ case 1:
60
+ blob = _a.sent();
61
+ fileReader = new FileReader();
62
+ fileReader.addEventListener("loadend", function () {
63
+ return fileLoaderComplete(fileReader);
64
+ });
65
+ switch (readerTypeFunction) {
66
+ case "arrayBuffer":
67
+ fileReader.readAsArrayBuffer(blob);
68
+ break;
69
+ case "binaryString":
70
+ fileReader.readAsBinaryString(blob);
71
+ break;
72
+ case "dataURL":
73
+ fileReader.readAsDataURL(blob);
74
+ break;
75
+ case "text":
76
+ fileReader.readAsText(blob);
77
+ break;
78
+ default:
79
+ break;
80
+ }
81
+ return [2 /*return*/];
82
+ }
83
+ });
84
+ }); })
85
+ .catch(function (e) {
86
+ return e;
87
+ });
88
+ };
89
+ var arrayBufferFileLoader = function (props) {
90
+ return _fileLoader(__assign(__assign({}, props), { readerTypeFunction: "arrayBuffer" }));
91
+ };
92
+ exports.arrayBufferFileLoader = arrayBufferFileLoader;
93
+ var dataURLFileLoader = function (props) {
94
+ return _fileLoader(__assign(__assign({}, props), { readerTypeFunction: "dataURL" }));
95
+ };
96
+ exports.dataURLFileLoader = dataURLFileLoader;
97
+ var textFileLoader = function (props) {
98
+ return _fileLoader(__assign(__assign({}, props), { readerTypeFunction: "text" }));
99
+ };
100
+ exports.textFileLoader = textFileLoader;
101
+ var binaryStringFileLoader = function (props) {
102
+ return _fileLoader(__assign(__assign({}, props), { readerTypeFunction: "binaryString" }));
103
+ };
104
+ exports.binaryStringFileLoader = binaryStringFileLoader;
105
+ exports.defaultFileLoader = exports.dataURLFileLoader;
@@ -0,0 +1,12 @@
1
+ import { Dispatch } from "react";
2
+ import { MainStateActions } from "../state/actions";
3
+ import { IMainState } from "../state/reducer";
4
+ import { DocRenderer } from "../types";
5
+ /**
6
+ * Custom Hook for loading the current document into context
7
+ */
8
+ export declare const useDocumentLoader: () => {
9
+ state: IMainState;
10
+ dispatch: Dispatch<MainStateActions>;
11
+ CurrentRenderer: DocRenderer | null | undefined;
12
+ };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.useDocumentLoader = void 0;
15
+ var react_1 = require("react");
16
+ var state_1 = require("../state");
17
+ var actions_1 = require("../state/actions");
18
+ var fileLoaders_1 = require("./fileLoaders");
19
+ var useRendererSelector_1 = require("./useRendererSelector");
20
+ /**
21
+ * Custom Hook for loading the current document into context
22
+ */
23
+ var useDocumentLoader = function () {
24
+ var _a = (0, react_1.useContext)(state_1.DocViewerContext), state = _a.state, dispatch = _a.dispatch;
25
+ var currentFileNo = state.currentFileNo, currentDocument = state.currentDocument;
26
+ var CurrentRenderer = (0, useRendererSelector_1.useRendererSelector)().CurrentRenderer;
27
+ var documentURI = (currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.uri) || "";
28
+ (0, react_1.useEffect)(function () {
29
+ if (!currentDocument)
30
+ return;
31
+ if (currentDocument.fileType !== undefined)
32
+ return;
33
+ var controller = new AbortController();
34
+ var signal = controller.signal;
35
+ fetch(documentURI, { method: "HEAD", signal: signal }).then(function (response) {
36
+ var contentTypeRaw = response.headers.get("content-type");
37
+ var contentTypes = (contentTypeRaw === null || contentTypeRaw === void 0 ? void 0 : contentTypeRaw.split(";")) || [];
38
+ var contentType = contentTypes.length ? contentTypes[0] : undefined;
39
+ dispatch((0, actions_1.updateCurrentDocument)(__assign(__assign({}, currentDocument), { fileType: contentType || undefined })));
40
+ });
41
+ return function () {
42
+ controller.abort();
43
+ };
44
+ },
45
+ // eslint ignore added, because a warning appears for dispatch to
46
+ // be a dependancy of the useEffect
47
+ // eslint-disable-next-line react-hooks/exhaustive-deps
48
+ [currentFileNo, documentURI]);
49
+ (0, react_1.useEffect)(function () {
50
+ var _a;
51
+ if (!currentDocument || CurrentRenderer === undefined)
52
+ return;
53
+ var controller = new AbortController();
54
+ var signal = controller.signal;
55
+ var fileLoaderComplete = function (fileReader) {
56
+ if (!currentDocument || !fileReader) {
57
+ dispatch((0, actions_1.setDocumentLoading)(false));
58
+ return;
59
+ }
60
+ var updatedDocument = __assign({}, currentDocument);
61
+ if (fileReader.result !== null) {
62
+ updatedDocument.fileData = fileReader.result;
63
+ }
64
+ dispatch((0, actions_1.updateCurrentDocument)(updatedDocument));
65
+ dispatch((0, actions_1.setDocumentLoading)(false));
66
+ };
67
+ if (CurrentRenderer === null) {
68
+ dispatch((0, actions_1.setDocumentLoading)(false));
69
+ }
70
+ else if (CurrentRenderer.fileLoader !== undefined) {
71
+ (_a = CurrentRenderer.fileLoader) === null || _a === void 0 ? void 0 : _a.call(CurrentRenderer, { documentURI: documentURI, signal: signal, fileLoaderComplete: fileLoaderComplete });
72
+ }
73
+ else {
74
+ (0, fileLoaders_1.defaultFileLoader)({ documentURI: documentURI, signal: signal, fileLoaderComplete: fileLoaderComplete });
75
+ }
76
+ return function () {
77
+ controller.abort();
78
+ };
79
+ }, [CurrentRenderer]);
80
+ return { state: state, dispatch: dispatch, CurrentRenderer: CurrentRenderer };
81
+ };
82
+ exports.useDocumentLoader = useDocumentLoader;
@@ -0,0 +1,7 @@
1
+ import { DocRenderer } from "../types";
2
+ /**
3
+ * Custom Hook for loading the current document into context
4
+ */
5
+ export declare const useRendererSelector: () => {
6
+ CurrentRenderer: DocRenderer | null | undefined;
7
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRendererSelector = void 0;
4
+ var react_1 = require("react");
5
+ var state_1 = require("../state");
6
+ /**
7
+ * Custom Hook for loading the current document into context
8
+ */
9
+ var useRendererSelector = function () {
10
+ var _a = (0, react_1.useContext)(state_1.DocViewerContext).state, currentDocument = _a.currentDocument, pluginRenderers = _a.pluginRenderers;
11
+ var _b = (0, react_1.useState)(), CurrentRenderer = _b[0], setCurrentRenderer = _b[1];
12
+ (0, react_1.useEffect)(function () {
13
+ if (!currentDocument)
14
+ return;
15
+ // Do not advance if the document does not yet have a fileType
16
+ // This prevents prematurely showing 'no renderer' message
17
+ if (!currentDocument.fileType) {
18
+ setCurrentRenderer(undefined);
19
+ return;
20
+ }
21
+ var matchingRenderers = [];
22
+ pluginRenderers === null || pluginRenderers === void 0 ? void 0 : pluginRenderers.map(function (r) {
23
+ if (currentDocument.fileType === undefined)
24
+ return;
25
+ if (r.fileTypes.indexOf(currentDocument.fileType) >= 0) {
26
+ matchingRenderers.push(r);
27
+ }
28
+ });
29
+ // Compute prefered Renderer based on weight
30
+ var SelectedRenderer = matchingRenderers.sort(function (a, b) { return b.weight - a.weight; })[0];
31
+ if (SelectedRenderer && SelectedRenderer !== undefined) {
32
+ setCurrentRenderer(function () { return SelectedRenderer; });
33
+ }
34
+ else {
35
+ setCurrentRenderer(null);
36
+ }
37
+ }, [currentDocument]);
38
+ return { CurrentRenderer: CurrentRenderer };
39
+ };
40
+ exports.useRendererSelector = useRendererSelector;
@@ -0,0 +1,4 @@
1
+ export declare const useWindowSize: () => {
2
+ width: number | undefined;
3
+ height: number | undefined;
4
+ };