@atlaskit/media-document-viewer 0.1.0
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.
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +11 -0
- package/README.md +9 -0
- package/dist/cjs/documentViewer.compiled.css +9 -0
- package/dist/cjs/documentViewer.js +56 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/page.compiled.css +11 -0
- package/dist/cjs/page.js +162 -0
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/usePageContent.js +81 -0
- package/dist/cjs/utils/getDocumentRoot.js +20 -0
- package/dist/cjs/utils/useCachedGetImage.js +57 -0
- package/dist/cjs/utils/useIntersectionObserver.js +65 -0
- package/dist/cjs/utils/useStaticCallback.js +14 -0
- package/dist/es2019/documentViewer.compiled.css +9 -0
- package/dist/es2019/documentViewer.js +46 -0
- package/dist/es2019/index.js +2 -0
- package/dist/es2019/page.compiled.css +11 -0
- package/dist/es2019/page.js +146 -0
- package/dist/es2019/types.js +0 -0
- package/dist/es2019/usePageContent.js +47 -0
- package/dist/es2019/utils/getDocumentRoot.js +14 -0
- package/dist/es2019/utils/useCachedGetImage.js +20 -0
- package/dist/es2019/utils/useIntersectionObserver.js +55 -0
- package/dist/es2019/utils/useStaticCallback.js +6 -0
- package/dist/esm/documentViewer.compiled.css +9 -0
- package/dist/esm/documentViewer.js +47 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/page.compiled.css +11 -0
- package/dist/esm/page.js +153 -0
- package/dist/esm/types.js +0 -0
- package/dist/esm/usePageContent.js +74 -0
- package/dist/esm/utils/getDocumentRoot.js +14 -0
- package/dist/esm/utils/useCachedGetImage.js +50 -0
- package/dist/esm/utils/useIntersectionObserver.js +58 -0
- package/dist/esm/utils/useStaticCallback.js +8 -0
- package/dist/types/documentViewer.d.ts +10 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/page.d.ts +16 -0
- package/dist/types/types.d.ts +42 -0
- package/dist/types/usePageContent.d.ts +15 -0
- package/dist/types/utils/getDocumentRoot.d.ts +2 -0
- package/dist/types/utils/useCachedGetImage.d.ts +1 -0
- package/dist/types/utils/useIntersectionObserver.d.ts +5 -0
- package/dist/types/utils/useStaticCallback.d.ts +1 -0
- package/dist/types-ts4.5/documentViewer.d.ts +10 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/page.d.ts +16 -0
- package/dist/types-ts4.5/types.d.ts +42 -0
- package/dist/types-ts4.5/usePageContent.d.ts +15 -0
- package/dist/types-ts4.5/utils/getDocumentRoot.d.ts +2 -0
- package/dist/types-ts4.5/utils/useCachedGetImage.d.ts +1 -0
- package/dist/types-ts4.5/utils/useIntersectionObserver.d.ts +5 -0
- package/dist/types-ts4.5/utils/useStaticCallback.d.ts +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { useStaticCallback } from "./useStaticCallback";
|
|
4
|
+
export var useIntersectionObserver = function useIntersectionObserver(options, onVisible) {
|
|
5
|
+
var staticOnVisible = useStaticCallback(onVisible);
|
|
6
|
+
var observerRef = useRef(null);
|
|
7
|
+
var timeoutRef = useRef(null);
|
|
8
|
+
var isVisibleRef = useRef(false);
|
|
9
|
+
var currentNodeRef = useRef(null);
|
|
10
|
+
var observedRef = useStaticCallback(function (node) {
|
|
11
|
+
currentNodeRef.current = node;
|
|
12
|
+
if (observerRef.current) {
|
|
13
|
+
observerRef.current.disconnect();
|
|
14
|
+
}
|
|
15
|
+
if (timeoutRef.current) {
|
|
16
|
+
clearTimeout(timeoutRef.current);
|
|
17
|
+
timeoutRef.current = null;
|
|
18
|
+
}
|
|
19
|
+
if (node) {
|
|
20
|
+
observerRef.current = new IntersectionObserver(function (_ref) {
|
|
21
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
22
|
+
entry = _ref2[0];
|
|
23
|
+
if (entry.isIntersecting && !isVisibleRef.current) {
|
|
24
|
+
isVisibleRef.current = true;
|
|
25
|
+
timeoutRef.current = setTimeout(function () {
|
|
26
|
+
if (isVisibleRef.current) {
|
|
27
|
+
staticOnVisible();
|
|
28
|
+
timeoutRef.current = null;
|
|
29
|
+
}
|
|
30
|
+
}, 100);
|
|
31
|
+
}
|
|
32
|
+
if (!entry.isIntersecting && isVisibleRef.current) {
|
|
33
|
+
isVisibleRef.current = false;
|
|
34
|
+
}
|
|
35
|
+
if (!entry.isIntersecting && isVisibleRef.current && timeoutRef.current) {
|
|
36
|
+
isVisibleRef.current = false;
|
|
37
|
+
clearTimeout(timeoutRef.current);
|
|
38
|
+
timeoutRef.current = null;
|
|
39
|
+
}
|
|
40
|
+
}, options);
|
|
41
|
+
observerRef.current.observe(node);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
return function () {
|
|
46
|
+
if (observerRef.current) {
|
|
47
|
+
observerRef.current.disconnect();
|
|
48
|
+
}
|
|
49
|
+
if (timeoutRef.current) {
|
|
50
|
+
clearTimeout(timeoutRef.current);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
return {
|
|
55
|
+
observedRef: observedRef,
|
|
56
|
+
isVisibleRef: isVisibleRef
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
export var useStaticCallback = function useStaticCallback(callback) {
|
|
3
|
+
var callbackRef = useRef(callback);
|
|
4
|
+
callbackRef.current = callback;
|
|
5
|
+
return useCallback(function () {
|
|
6
|
+
return callbackRef.current.apply(callbackRef, arguments);
|
|
7
|
+
}, []);
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type PageRangeContent } from './types';
|
|
3
|
+
type DocumentViewerProps = {
|
|
4
|
+
getContent: (pageStart: number, pageEnd: number) => Promise<PageRangeContent>;
|
|
5
|
+
getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>;
|
|
6
|
+
paginationSize?: number;
|
|
7
|
+
zoom: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const DocumentViewer: ({ getContent, getPageImageUrl, paginationSize, zoom }: DocumentViewerProps) => JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type Font, type PageContent } from './types';
|
|
3
|
+
type PageProps = {
|
|
4
|
+
getPageSrc: (pageIndex: number, zoom: number) => Promise<string>;
|
|
5
|
+
content?: PageContent;
|
|
6
|
+
fonts: readonly Font[];
|
|
7
|
+
pageIndex: number;
|
|
8
|
+
zoom: number;
|
|
9
|
+
defaultDimensions?: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
onVisible: () => void;
|
|
14
|
+
};
|
|
15
|
+
export declare const Page: ({ getPageSrc, content, fonts, pageIndex, zoom, defaultDimensions, onVisible }: PageProps) => JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type Font = {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
weight: number;
|
|
5
|
+
is_all_caps: boolean;
|
|
6
|
+
is_bold_reenforced: boolean;
|
|
7
|
+
is_cursive: boolean;
|
|
8
|
+
is_fixed_pitch: boolean;
|
|
9
|
+
is_italic: boolean;
|
|
10
|
+
is_non_symbolic: boolean;
|
|
11
|
+
is_proportional_pitch: boolean;
|
|
12
|
+
is_sans_serif: boolean;
|
|
13
|
+
is_serif: boolean;
|
|
14
|
+
is_small_caps: boolean;
|
|
15
|
+
is_symbolic: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type Span = {
|
|
18
|
+
text: string;
|
|
19
|
+
fi: number;
|
|
20
|
+
r: number;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
h: number;
|
|
24
|
+
l: number;
|
|
25
|
+
};
|
|
26
|
+
export type Line = {
|
|
27
|
+
r: number;
|
|
28
|
+
spans: readonly Span[];
|
|
29
|
+
};
|
|
30
|
+
export type PageContent = {
|
|
31
|
+
rotation: number;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
lines: readonly Line[];
|
|
35
|
+
};
|
|
36
|
+
export type PageRangeContent = {
|
|
37
|
+
start_index: number;
|
|
38
|
+
end_index: number;
|
|
39
|
+
total_pages: number;
|
|
40
|
+
fonts: readonly Font[];
|
|
41
|
+
pages: readonly PageContent[];
|
|
42
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PageRangeContent } from "./types";
|
|
2
|
+
export declare function usePageContent(getContent: (startIndex: number, endIndex: number) => Promise<PageRangeContent>, paginationSize: number): {
|
|
3
|
+
getPageContent: (pageInd: number) => {
|
|
4
|
+
page: import("./types").PageContent;
|
|
5
|
+
fonts: readonly import("./types").Font[];
|
|
6
|
+
};
|
|
7
|
+
loadPageContent: (pageInd: number) => Promise<void>;
|
|
8
|
+
documentMetadata: {
|
|
9
|
+
defaultDimensions: {
|
|
10
|
+
height: number;
|
|
11
|
+
width: number;
|
|
12
|
+
} | undefined;
|
|
13
|
+
pageCount: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>) => (pageNumber: number, zoom: number) => Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useStaticCallback: <Params extends any[], Result>(callback: (...args: Params) => Result) => (...args: Params) => Result;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type PageRangeContent } from './types';
|
|
3
|
+
type DocumentViewerProps = {
|
|
4
|
+
getContent: (pageStart: number, pageEnd: number) => Promise<PageRangeContent>;
|
|
5
|
+
getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>;
|
|
6
|
+
paginationSize?: number;
|
|
7
|
+
zoom: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const DocumentViewer: ({ getContent, getPageImageUrl, paginationSize, zoom }: DocumentViewerProps) => JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type Font, type PageContent } from './types';
|
|
3
|
+
type PageProps = {
|
|
4
|
+
getPageSrc: (pageIndex: number, zoom: number) => Promise<string>;
|
|
5
|
+
content?: PageContent;
|
|
6
|
+
fonts: readonly Font[];
|
|
7
|
+
pageIndex: number;
|
|
8
|
+
zoom: number;
|
|
9
|
+
defaultDimensions?: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
onVisible: () => void;
|
|
14
|
+
};
|
|
15
|
+
export declare const Page: ({ getPageSrc, content, fonts, pageIndex, zoom, defaultDimensions, onVisible }: PageProps) => JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type Font = {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
weight: number;
|
|
5
|
+
is_all_caps: boolean;
|
|
6
|
+
is_bold_reenforced: boolean;
|
|
7
|
+
is_cursive: boolean;
|
|
8
|
+
is_fixed_pitch: boolean;
|
|
9
|
+
is_italic: boolean;
|
|
10
|
+
is_non_symbolic: boolean;
|
|
11
|
+
is_proportional_pitch: boolean;
|
|
12
|
+
is_sans_serif: boolean;
|
|
13
|
+
is_serif: boolean;
|
|
14
|
+
is_small_caps: boolean;
|
|
15
|
+
is_symbolic: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type Span = {
|
|
18
|
+
text: string;
|
|
19
|
+
fi: number;
|
|
20
|
+
r: number;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
h: number;
|
|
24
|
+
l: number;
|
|
25
|
+
};
|
|
26
|
+
export type Line = {
|
|
27
|
+
r: number;
|
|
28
|
+
spans: readonly Span[];
|
|
29
|
+
};
|
|
30
|
+
export type PageContent = {
|
|
31
|
+
rotation: number;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
lines: readonly Line[];
|
|
35
|
+
};
|
|
36
|
+
export type PageRangeContent = {
|
|
37
|
+
start_index: number;
|
|
38
|
+
end_index: number;
|
|
39
|
+
total_pages: number;
|
|
40
|
+
fonts: readonly Font[];
|
|
41
|
+
pages: readonly PageContent[];
|
|
42
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PageRangeContent } from "./types";
|
|
2
|
+
export declare function usePageContent(getContent: (startIndex: number, endIndex: number) => Promise<PageRangeContent>, paginationSize: number): {
|
|
3
|
+
getPageContent: (pageInd: number) => {
|
|
4
|
+
page: import("./types").PageContent;
|
|
5
|
+
fonts: readonly import("./types").Font[];
|
|
6
|
+
};
|
|
7
|
+
loadPageContent: (pageInd: number) => Promise<void>;
|
|
8
|
+
documentMetadata: {
|
|
9
|
+
defaultDimensions: {
|
|
10
|
+
height: number;
|
|
11
|
+
width: number;
|
|
12
|
+
} | undefined;
|
|
13
|
+
pageCount: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>) => (pageNumber: number, zoom: number) => Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useStaticCallback: <Params extends any[], Result>(callback: (...args: Params) => Result) => (...args: Params) => Result;
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"atlassian": {
|
|
3
|
+
"team": "Media Exif",
|
|
4
|
+
"runReact18": true,
|
|
5
|
+
"website": {
|
|
6
|
+
"name": "MediaDocumentViewer",
|
|
7
|
+
"category": "Layout and structure"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"repository": "https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo",
|
|
11
|
+
"main": "dist/cjs/index.js",
|
|
12
|
+
"module": "dist/esm/index.js",
|
|
13
|
+
"module:es2019": "dist/es2019/index.js",
|
|
14
|
+
"types": "dist/types/index.d.ts",
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
">=4.5 <5.4": {
|
|
17
|
+
"*": [
|
|
18
|
+
"dist/types-ts4.5/*",
|
|
19
|
+
"dist/types-ts4.5/index.d.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"*.compiled.css"
|
|
25
|
+
],
|
|
26
|
+
"atlaskit:src": "src/index.ts",
|
|
27
|
+
"af:exports": {
|
|
28
|
+
".": "./src/index.ts"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@atlaskit/css": "^0.10.0",
|
|
32
|
+
"@atlaskit/primitives": "^14.8.0",
|
|
33
|
+
"@atlaskit/tokens": "^5.1.0",
|
|
34
|
+
"@babel/runtime": "^7.0.0",
|
|
35
|
+
"@compiled/react": "^0.18.3"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^18.2.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@af/integration-testing": "workspace:^",
|
|
42
|
+
"@af/visual-regression": "workspace:^",
|
|
43
|
+
"@atlaskit/ssr": "workspace:^",
|
|
44
|
+
"@atlaskit/visual-regression": "workspace:^",
|
|
45
|
+
"@testing-library/react": "^13.4.0",
|
|
46
|
+
"react-dom": "^18.2.0",
|
|
47
|
+
"typescript": "~5.4.2"
|
|
48
|
+
},
|
|
49
|
+
"techstack": {
|
|
50
|
+
"@atlassian/frontend": {
|
|
51
|
+
"import-structure": [
|
|
52
|
+
"atlassian-conventions"
|
|
53
|
+
],
|
|
54
|
+
"circular-dependencies": [
|
|
55
|
+
"file-and-folder-level"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"@repo/internal": {
|
|
59
|
+
"dom-events": "use-bind-event-listener",
|
|
60
|
+
"analytics": [
|
|
61
|
+
"analytics-next"
|
|
62
|
+
],
|
|
63
|
+
"design-tokens": [
|
|
64
|
+
"color"
|
|
65
|
+
],
|
|
66
|
+
"theming": [
|
|
67
|
+
"react-context"
|
|
68
|
+
],
|
|
69
|
+
"ui-components": [
|
|
70
|
+
"lite-mode"
|
|
71
|
+
],
|
|
72
|
+
"deprecation": [
|
|
73
|
+
"no-deprecated-imports"
|
|
74
|
+
],
|
|
75
|
+
"styling": [
|
|
76
|
+
"static",
|
|
77
|
+
"compiled"
|
|
78
|
+
],
|
|
79
|
+
"imports": [
|
|
80
|
+
"import-no-extraneous-disable-for-examples-and-docs"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"name": "@atlaskit/media-document-viewer",
|
|
85
|
+
"version": "0.1.0",
|
|
86
|
+
"description": "Modern and fast document viewer",
|
|
87
|
+
"author": "Atlassian Pty Ltd",
|
|
88
|
+
"license": "Apache-2.0",
|
|
89
|
+
"publishConfig": {
|
|
90
|
+
"registry": "https://registry.npmjs.org/"
|
|
91
|
+
}
|
|
92
|
+
}
|