@alveole/components 0.34.9 → 0.35.1
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/dist/pdfjs/pdf.min.mjs +21 -0
- package/dist/pdfjs/pdf.worker.min.mjs +21 -0
- package/dist/scripts/sync-pdfjs-web-assets.mjs +16 -0
- package/dist/ui/Breadcrumbs/Breadcrumbs.d.ts.map +1 -1
- package/dist/ui/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/ui/DocumentViewer/DocumentViewerPDF.d.ts +1 -1
- package/dist/ui/DocumentViewer/DocumentViewerPDF.d.ts.map +1 -1
- package/dist/ui/DocumentViewer/DocumentViewerPDF.js +1 -1
- package/dist/ui/DocumentViewer/DocumentViewerPDF.native.d.ts +14 -0
- package/dist/ui/DocumentViewer/DocumentViewerPDF.native.d.ts.map +1 -0
- package/dist/ui/DocumentViewer/DocumentViewerPDF.native.js +14 -0
- package/dist/ui/DocumentViewer/DocumentViewerPDF.web.d.ts +38 -0
- package/dist/ui/DocumentViewer/DocumentViewerPDF.web.d.ts.map +1 -0
- package/dist/ui/DocumentViewer/DocumentViewerPDF.web.js +156 -0
- package/dist/ui/ListItem/ListItem.stories.js +1 -1
- package/package.json +7 -4
- package/scripts/postinstall.mjs +26 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { copyFileSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const packageRoot = resolve(import.meta.dirname, '../..');
|
|
5
|
+
const files = [
|
|
6
|
+
['dist/pdfjs/pdf.min.mjs', 'public/pdf.min.mjs'],
|
|
7
|
+
['dist/pdfjs/pdf.worker.min.mjs', 'public/pdf.worker.min.mjs'],
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
for (const [source, target] of files) {
|
|
11
|
+
const absoluteSource = resolve(packageRoot, source);
|
|
12
|
+
const absoluteTarget = resolve(process.cwd(), target);
|
|
13
|
+
mkdirSync(dirname(absoluteTarget), { recursive: true });
|
|
14
|
+
copyFileSync(absoluteSource, absoluteTarget);
|
|
15
|
+
console.log(`synced ${target}`);
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breadcrumbs.d.ts","sourceRoot":"","sources":["../../../src/ui/Breadcrumbs/Breadcrumbs.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAMF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACrD,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACrE,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,gBAAgB,
|
|
1
|
+
{"version":3,"file":"Breadcrumbs.d.ts","sourceRoot":"","sources":["../../../src/ui/Breadcrumbs/Breadcrumbs.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAMF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACrD,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACrE,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,gBAAgB,4CA+ClD,CAAC"}
|
|
@@ -36,5 +36,5 @@ export const Breadcrumbs = (props) => {
|
|
|
36
36
|
isCurrent: index === segments.length - 1,
|
|
37
37
|
})),
|
|
38
38
|
];
|
|
39
|
-
return (_jsx(Box, { style: styles.container, children: items.map((item, index) => (_jsxs(Box, { style: { flexDirection: 'row', alignItems: 'center' }, children: [index > 0 && _jsx(Typography, { style: styles.separator, children: " > " }), item.isCurrent ? (_jsx(Typography, { style: styles.current, children: item.label })) : (_jsx(A, { href: item.href, style: styles.link, hoverStyle: styles.linkHover, children: item.label }))] }, `${item.href}-${index}`))) }));
|
|
39
|
+
return (_jsx(Box, { style: styles.container, children: items.map((item, index) => (_jsxs(Box, { style: { flexDirection: 'row', alignItems: 'center' }, children: [index > 0 && _jsx(Typography, { style: styles.separator, children: " > " }), item.isCurrent ? (_jsx(Typography, { style: styles.current, children: item.label })) : (_jsx(A, { href: item.href, style: styles.link, hoverStyle: styles.linkHover, children: _jsx(Typography, { style: styles.link, hoverStyle: styles.linkHover, children: item.label }) }))] }, `${item.href}-${index}`))) }));
|
|
40
40
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BoxProps } from '@alveole/components';
|
|
2
2
|
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
|
3
|
-
import 'pdfjs-dist/build/pdf.worker.
|
|
3
|
+
import 'pdfjs-dist/legacy/build/pdf.worker.min.mjs';
|
|
4
4
|
import { DocumentViewerRotation } from './DocumentViewer';
|
|
5
5
|
export type DocumentViewerPDFProps = {
|
|
6
6
|
source: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentViewerPDF.d.ts","sourceRoot":"","sources":["../../../src/ui/DocumentViewer/DocumentViewerPDF.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,
|
|
1
|
+
{"version":3,"file":"DocumentViewerPDF.d.ts","sourceRoot":"","sources":["../../../src/ui/DocumentViewer/DocumentViewerPDF.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,4CAA4C,CAAC;AAGpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC7C,CAAC;AAWF,eAAO,MAAM,iBAAiB,GAAI,OAAO,sBAAsB,4CA6J9D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box } from '@alveole/components';
|
|
3
3
|
import * as pdfjs from 'pdfjs-dist';
|
|
4
|
-
import 'pdfjs-dist/build/pdf.worker.
|
|
4
|
+
import 'pdfjs-dist/legacy/build/pdf.worker.min.mjs';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { Platform } from 'react-native';
|
|
7
7
|
import { useStyles } from './DocumentViewer.styles';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type BoxProps } from '@alveole/components';
|
|
2
|
+
import { DocumentViewerRotation } from './DocumentViewer';
|
|
3
|
+
export type DocumentViewerPDFProps = {
|
|
4
|
+
source: string;
|
|
5
|
+
page: number;
|
|
6
|
+
height?: BoxProps['height'];
|
|
7
|
+
rotation: DocumentViewerRotation;
|
|
8
|
+
scale?: number;
|
|
9
|
+
onReady?: (_state: {
|
|
10
|
+
numPages: number;
|
|
11
|
+
}) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const DocumentViewerPDF: (props: DocumentViewerPDFProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=DocumentViewerPDF.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentViewerPDF.native.d.ts","sourceRoot":"","sources":["../../../src/ui/DocumentViewer/DocumentViewerPDF.native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,QAAQ,EAAc,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAClD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,OAAO,sBAAsB,4CAsB9D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Typography } from '@alveole/components';
|
|
3
|
+
import { useStyles } from './DocumentViewer.styles';
|
|
4
|
+
export const DocumentViewerPDF = (props) => {
|
|
5
|
+
const { height = '100%' } = props;
|
|
6
|
+
const styles = useStyles();
|
|
7
|
+
return (_jsx(Box, { tag: "document-viewer-pdf", width: '100%', height: height, style: styles.viewerPdfContent, children: _jsx(Box, { width: '100%', height: '100%', p: '1V', style: [
|
|
8
|
+
styles.viewerPdfStage,
|
|
9
|
+
{
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
},
|
|
13
|
+
], children: _jsx(Typography, { children: "Not implemented" }) }) }));
|
|
14
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type BoxProps } from '@alveole/components';
|
|
2
|
+
import { DocumentViewerRotation } from './DocumentViewer';
|
|
3
|
+
type PDFDocumentProxyLike = {
|
|
4
|
+
destroy?: () => void | Promise<void>;
|
|
5
|
+
getPage: (page: number) => Promise<{
|
|
6
|
+
getViewport: (options: {
|
|
7
|
+
scale: number;
|
|
8
|
+
rotation: DocumentViewerRotation;
|
|
9
|
+
}) => {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
render: (options: {
|
|
14
|
+
canvasContext: CanvasRenderingContext2D;
|
|
15
|
+
viewport: {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
transform?: [number, number, number, number, number, number];
|
|
20
|
+
}) => {
|
|
21
|
+
promise: Promise<void>;
|
|
22
|
+
cancel?: () => void;
|
|
23
|
+
} | null;
|
|
24
|
+
cleanup?: () => void;
|
|
25
|
+
}>;
|
|
26
|
+
numPages: number;
|
|
27
|
+
};
|
|
28
|
+
export type DocumentViewerPDFProps = {
|
|
29
|
+
source: string;
|
|
30
|
+
page: number;
|
|
31
|
+
height?: BoxProps['height'];
|
|
32
|
+
rotation: DocumentViewerRotation;
|
|
33
|
+
scale?: number;
|
|
34
|
+
onReady?: (state: PDFDocumentProxyLike) => void;
|
|
35
|
+
};
|
|
36
|
+
export declare const DocumentViewerPDF: (props: DocumentViewerPDFProps) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=DocumentViewerPDF.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentViewerPDF.web.d.ts","sourceRoot":"","sources":["../../../src/ui/DocumentViewer/DocumentViewerPDF.web.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,KAAK,oBAAoB,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;QACjC,WAAW,EAAE,CAAC,OAAO,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,sBAAsB,CAAA;SAAE,KAAK;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC;QACjH,MAAM,EAAE,CAAC,OAAO,EAAE;YAChB,aAAa,EAAE,wBAAwB,CAAC;YACxC,QAAQ,EAAE;gBAAE,KAAK,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAA;aAAE,CAAC;YAC5C,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;SAC9D,KAAK;YAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;SAAE,GAAG,IAAI,CAAC;QAC7D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;KACtB,CAAC,CAAC;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAUF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACjD,CAAC;AAmCF,eAAO,MAAM,iBAAiB,GAAI,OAAO,sBAAsB,4CAsK9D,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from '@alveole/components';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useStyles } from './DocumentViewer.styles';
|
|
5
|
+
const isPdfCancellationError = (error) => {
|
|
6
|
+
if (!(error instanceof Error))
|
|
7
|
+
return false;
|
|
8
|
+
return (['RenderingCancelledException', 'AbortException', 'UnknownErrorException'].includes(error.name) ||
|
|
9
|
+
error.message.includes('Worker was terminated'));
|
|
10
|
+
};
|
|
11
|
+
const loadPdfJs = (() => {
|
|
12
|
+
let promise = null;
|
|
13
|
+
return () => {
|
|
14
|
+
if (typeof window === 'undefined') {
|
|
15
|
+
return Promise.reject(new Error('PDF.js is only available in the browser.'));
|
|
16
|
+
}
|
|
17
|
+
if (promise)
|
|
18
|
+
return promise;
|
|
19
|
+
const dynamicImport = new Function('url', 'return import(url);');
|
|
20
|
+
promise = dynamicImport('/pdf.min.mjs').then(module => {
|
|
21
|
+
const pdfjs = (module.default ?? module);
|
|
22
|
+
pdfjs.GlobalWorkerOptions.workerSrc = `${window.location.origin}/pdf.worker.min.mjs`;
|
|
23
|
+
return pdfjs;
|
|
24
|
+
});
|
|
25
|
+
return promise;
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
export const DocumentViewerPDF = (props) => {
|
|
29
|
+
const { source, page, rotation, height = '100%', scale = 1, onReady } = props;
|
|
30
|
+
const styles = useStyles();
|
|
31
|
+
const [pdf, setPdf] = React.useState(null);
|
|
32
|
+
const [viewerSize, setViewerSize] = React.useState({ width: 0, height: 0 });
|
|
33
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
34
|
+
const [transformOrigin, setTransformOrigin] = React.useState('50% 50%');
|
|
35
|
+
const [renderedPageSize, setRenderedPageSize] = React.useState({ width: 0, height: 0 });
|
|
36
|
+
const canvasRef = React.useRef(null);
|
|
37
|
+
const onReadyRef = React.useRef(onReady);
|
|
38
|
+
const hoveredScale = isHovered ? 2 : 1;
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
onReadyRef.current = onReady;
|
|
41
|
+
}, [onReady]);
|
|
42
|
+
const onPdfLoadedSuccess = React.useCallback((documentPdf, active) => {
|
|
43
|
+
if (!active)
|
|
44
|
+
return void documentPdf.destroy?.();
|
|
45
|
+
setPdf(currentPdf => {
|
|
46
|
+
void currentPdf?.destroy?.();
|
|
47
|
+
return documentPdf;
|
|
48
|
+
});
|
|
49
|
+
onReadyRef.current?.(documentPdf);
|
|
50
|
+
}, []);
|
|
51
|
+
const onPdfLoadedError = React.useCallback((active) => {
|
|
52
|
+
if (!active)
|
|
53
|
+
return;
|
|
54
|
+
setPdf(null);
|
|
55
|
+
}, []);
|
|
56
|
+
const onPageLoadedSuccess = React.useCallback(async (pagePdf, active) => {
|
|
57
|
+
if (!active || !canvasRef.current)
|
|
58
|
+
return null;
|
|
59
|
+
const baseViewport = pagePdf.getViewport({ scale: 1, rotation });
|
|
60
|
+
const fittedScale = Math.min(viewerSize.width / baseViewport.width, viewerSize.height / baseViewport.height);
|
|
61
|
+
const viewport = pagePdf.getViewport({ scale: fittedScale * scale, rotation });
|
|
62
|
+
const canvas = canvasRef.current;
|
|
63
|
+
const context = canvas.getContext('2d');
|
|
64
|
+
if (context == null)
|
|
65
|
+
return null;
|
|
66
|
+
const pixelRatio = window.devicePixelRatio || 1;
|
|
67
|
+
canvas.width = Math.floor(viewport.width * pixelRatio);
|
|
68
|
+
canvas.height = Math.floor(viewport.height * pixelRatio);
|
|
69
|
+
canvas.style.width = `${viewport.width}px`;
|
|
70
|
+
canvas.style.height = `${viewport.height}px`;
|
|
71
|
+
setRenderedPageSize({ width: viewport.width, height: viewport.height });
|
|
72
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
73
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
74
|
+
return pagePdf.render({
|
|
75
|
+
canvasContext: context,
|
|
76
|
+
viewport,
|
|
77
|
+
transform: pixelRatio === 1 ? undefined : [pixelRatio, 0, 0, pixelRatio, 0, 0],
|
|
78
|
+
});
|
|
79
|
+
}, [rotation, scale, viewerSize.height, viewerSize.width]);
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
let isActive = true;
|
|
82
|
+
let loadingTask = null;
|
|
83
|
+
loadPdfJs()
|
|
84
|
+
.then(pdfjs => {
|
|
85
|
+
if (!isActive)
|
|
86
|
+
return;
|
|
87
|
+
loadingTask = pdfjs.getDocument(source);
|
|
88
|
+
return loadingTask.promise
|
|
89
|
+
.then(nextPdf => onPdfLoadedSuccess(nextPdf, isActive))
|
|
90
|
+
.catch(error => {
|
|
91
|
+
if (!isActive || isPdfCancellationError(error))
|
|
92
|
+
return;
|
|
93
|
+
onPdfLoadedError(true);
|
|
94
|
+
});
|
|
95
|
+
})
|
|
96
|
+
.catch(error => {
|
|
97
|
+
if (!isActive || isPdfCancellationError(error))
|
|
98
|
+
return;
|
|
99
|
+
onPdfLoadedError(true);
|
|
100
|
+
});
|
|
101
|
+
return () => {
|
|
102
|
+
isActive = false;
|
|
103
|
+
loadingTask?.destroy();
|
|
104
|
+
};
|
|
105
|
+
}, [source, onPdfLoadedError, onPdfLoadedSuccess]);
|
|
106
|
+
React.useEffect(() => {
|
|
107
|
+
if (!pdf || !canvasRef.current || viewerSize.width <= 0 || viewerSize.height <= 0)
|
|
108
|
+
return;
|
|
109
|
+
let isActive = true;
|
|
110
|
+
let renderTask = null;
|
|
111
|
+
pdf
|
|
112
|
+
.getPage(page)
|
|
113
|
+
.then(async (pdfPage) => {
|
|
114
|
+
renderTask = await onPageLoadedSuccess(pdfPage, isActive);
|
|
115
|
+
return renderTask?.promise.then(() => {
|
|
116
|
+
if (!isActive)
|
|
117
|
+
return;
|
|
118
|
+
pdfPage.cleanup?.();
|
|
119
|
+
});
|
|
120
|
+
})
|
|
121
|
+
.catch(error => {
|
|
122
|
+
if (!isActive || isPdfCancellationError(error))
|
|
123
|
+
return;
|
|
124
|
+
onPdfLoadedError(true);
|
|
125
|
+
});
|
|
126
|
+
return () => {
|
|
127
|
+
isActive = false;
|
|
128
|
+
renderTask?.cancel?.();
|
|
129
|
+
};
|
|
130
|
+
}, [pdf, page, rotation, scale, viewerSize, onPageLoadedSuccess, onPdfLoadedError]);
|
|
131
|
+
const handleLayout = React.useCallback((event) => {
|
|
132
|
+
const nextWidth = event?.nativeEvent?.layout?.width;
|
|
133
|
+
const nextHeight = event?.nativeEvent?.layout?.height;
|
|
134
|
+
if (typeof nextWidth === 'number' && nextWidth > 0 && typeof nextHeight === 'number' && nextHeight > 0) {
|
|
135
|
+
setViewerSize({ width: nextWidth, height: nextHeight });
|
|
136
|
+
}
|
|
137
|
+
}, []);
|
|
138
|
+
const handlePointerMove = React.useCallback((event) => {
|
|
139
|
+
const rect = event.currentTarget?.getBoundingClientRect?.();
|
|
140
|
+
if (!rect)
|
|
141
|
+
return;
|
|
142
|
+
const x = ((event.clientX - rect.left) / rect.width) * 100;
|
|
143
|
+
const y = ((event.clientY - rect.top) / rect.height) * 100;
|
|
144
|
+
setTransformOrigin(`${Math.max(0, Math.min(100, x))}% ${Math.max(0, Math.min(100, y))}%`);
|
|
145
|
+
}, []);
|
|
146
|
+
React.useEffect(() => () => void pdf?.destroy?.(), [pdf]);
|
|
147
|
+
return (_jsx(Box, { tag: "document-viewer-pdf", width: '100%', height: height, onLayout: handleLayout, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), onPointerEnter: () => setIsHovered(true), onPointerLeave: () => setIsHovered(false), onPointerMove: handlePointerMove, style: styles.viewerPdfContent, children: _jsx(Box, { width: '100%', height: '100%', p: '1V', style: styles.viewerPdfStage, children: _jsx(Box, { style: [
|
|
148
|
+
styles.viewerPdfCanvasWrapper,
|
|
149
|
+
{
|
|
150
|
+
width: renderedPageSize.width,
|
|
151
|
+
height: renderedPageSize.height,
|
|
152
|
+
transformOrigin,
|
|
153
|
+
transform: [{ scale: hoveredScale }],
|
|
154
|
+
},
|
|
155
|
+
], children: _jsx("canvas", { ref: canvasRef, style: styles.viewerPdfCanvas }) }) }) }));
|
|
156
|
+
};
|
|
@@ -36,4 +36,4 @@ export const WithAvatar = () => (_jsx(ListItem, { title: "Titre", description: "
|
|
|
36
36
|
export const WithPreviewImage = () => (_jsx(ListItem, { title: "Titre", description: "Description", preview_url: "https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=400", onPress: () => {
|
|
37
37
|
window.alert('click !');
|
|
38
38
|
} }));
|
|
39
|
-
export const withoutHover = (_jsxs(Box, { children: [_jsx(Typography, { children: "Sans props openPress, l
|
|
39
|
+
export const withoutHover = (_jsxs(Box, { children: [_jsx(Typography, { children: "Sans props openPress, l\u2019effet de Hover n\u2019apparait pas" }), _jsx(ListItem, { title: "Titre", description: "Description" })] }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alveole/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.1",
|
|
4
4
|
"description": "Shared UI components.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,16 +13,19 @@
|
|
|
13
13
|
"types": "./dist/stories/index.d.ts",
|
|
14
14
|
"default": "./dist/stories/index.js"
|
|
15
15
|
},
|
|
16
|
-
"./package.json": "./package.json"
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
"./sync-pdfjs-web-assets": "./dist/scripts/sync-pdfjs-web-assets.mjs"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
21
|
+
"scripts/postinstall.mjs",
|
|
20
22
|
"README.md"
|
|
21
23
|
],
|
|
22
24
|
"sideEffects": false,
|
|
23
25
|
"scripts": {
|
|
24
|
-
"build": "tsc -p tsconfig.build.json",
|
|
26
|
+
"build": "tsc -p tsconfig.build.json && node ./scripts/prepare-pdfjs-web-assets.mjs",
|
|
25
27
|
"lint": "eslint .",
|
|
28
|
+
"postinstall": "node ./scripts/postinstall.mjs",
|
|
26
29
|
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
@@ -62,7 +65,7 @@
|
|
|
62
65
|
"expo-linear-gradient": "*",
|
|
63
66
|
"expo-constants": "*",
|
|
64
67
|
"lottie-react-native": "*",
|
|
65
|
-
"pdfjs-dist": "^
|
|
68
|
+
"pdfjs-dist": "^4.0.0",
|
|
66
69
|
"@lottiefiles/dotlottie-react": "*"
|
|
67
70
|
},
|
|
68
71
|
"publishConfig": {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const packageRoot = resolve(import.meta.dirname, '..');
|
|
5
|
+
const projectRoot = process.env.INIT_CWD ? resolve(process.env.INIT_CWD) : null;
|
|
6
|
+
|
|
7
|
+
if (projectRoot == null || projectRoot === packageRoot) {
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const files = [
|
|
12
|
+
['dist/pdfjs/pdf.min.mjs', 'public/pdf.min.mjs'],
|
|
13
|
+
['dist/pdfjs/pdf.worker.min.mjs', 'public/pdf.worker.min.mjs'],
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
for (const [source, target] of files) {
|
|
17
|
+
const absoluteSource = resolve(packageRoot, source);
|
|
18
|
+
if (!existsSync(absoluteSource)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const absoluteTarget = resolve(projectRoot, target);
|
|
23
|
+
mkdirSync(dirname(absoluteTarget), { recursive: true });
|
|
24
|
+
copyFileSync(absoluteSource, absoluteTarget);
|
|
25
|
+
console.log(`synced ${target}`);
|
|
26
|
+
}
|