@codeplex-sac/documentos 0.1.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/README.md +46 -0
- package/index.d.ts +1 -0
- package/index.js +136 -0
- package/lib/visor-pdf/visor-pdf.d.ts +17 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @codeplex-sac/documentos
|
|
2
|
+
|
|
3
|
+
Componentes para la **visualización de documentos** en aplicaciones React. Construido sobre [PDFSlick](https://pdfslick.dev) + [PDF.js](https://mozilla.github.io/pdf.js/), con API declarativa en español y controles estilizados con **Material UI**.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @codeplex-sac/documentos @pdfslick/core @pdfslick/react @mui/material @emotion/react @emotion/styled
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> [!IMPORTANT]
|
|
12
|
+
> Importa los estilos del visor una sola vez y envuelve la app con `CodeplexProveedorTema` de `@codeplex-sac/tema`.
|
|
13
|
+
>
|
|
14
|
+
> ```tsx
|
|
15
|
+
> import '@pdfslick/react/dist/pdf_viewer.css';
|
|
16
|
+
> ```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Componentes
|
|
21
|
+
|
|
22
|
+
### CodeplexVisorPdf
|
|
23
|
+
|
|
24
|
+
Visor de PDF interactivo con barra de controles (navegación, zoom, rotación y descarga).
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { CodeplexVisorPdf } from '@codeplex-sac/documentos';
|
|
28
|
+
import '@pdfslick/react/dist/pdf_viewer.css';
|
|
29
|
+
|
|
30
|
+
export const Ejemplo = () => (
|
|
31
|
+
<CodeplexVisorPdf archivo="/documentos/factura.pdf" ajuste="ancho" alto={600} />
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Props:**
|
|
36
|
+
|
|
37
|
+
| Propiedad | Tipo | Por defecto | Descripción |
|
|
38
|
+
| :--- | :--- | :--- | :--- |
|
|
39
|
+
| `archivo` | `string \| URL \| ArrayBuffer` | — | Ruta, URL o contenido binario del PDF. |
|
|
40
|
+
| `paginaUnica` | `boolean` | `false` | Una página a la vez en lugar de scroll continuo. |
|
|
41
|
+
| `ajuste` | `'pagina' \| 'ancho' \| 'auto' \| number` | `'pagina'` | Ajuste de zoom inicial. |
|
|
42
|
+
| `alto` | `number \| string` | `560` | Altura del visor. |
|
|
43
|
+
| `controles` | `boolean` | `true` | Muestra la barra de controles. |
|
|
44
|
+
| `miniaturas` | `boolean` | `false` | Muestra la barra lateral de miniaturas de páginas. |
|
|
45
|
+
|
|
46
|
+
Documentación detallada en [`readmes/documentos/visor-pdf.md`](../../readmes/documentos/visor-pdf.md).
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/visor-pdf/visor-pdf';
|
package/index.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsxs as d, jsx as e, Fragment as M } from "react/jsx-runtime";
|
|
2
|
+
import { useState as _ } from "react";
|
|
3
|
+
import { useTheme as $, Box as r, Tooltip as t, IconButton as o, Divider as x, Typography as g } from "@mui/material";
|
|
4
|
+
import { ViewSidebar as E, NavigateBefore as O, NavigateNext as T, ZoomOut as V, ZoomIn as B, RotateRight as F, Print as L, Download as W } from "@mui/icons-material";
|
|
5
|
+
import { usePDFSlick as H } from "@pdfslick/react";
|
|
6
|
+
const U = {
|
|
7
|
+
pagina: "page-fit",
|
|
8
|
+
ancho: "page-width",
|
|
9
|
+
auto: "auto"
|
|
10
|
+
};
|
|
11
|
+
function Z(a) {
|
|
12
|
+
return typeof a == "number" ? String(a) : U[a];
|
|
13
|
+
}
|
|
14
|
+
const J = {
|
|
15
|
+
display: "flex",
|
|
16
|
+
flexDirection: "column",
|
|
17
|
+
width: "100%",
|
|
18
|
+
borderRadius: 2,
|
|
19
|
+
overflow: "hidden",
|
|
20
|
+
border: (a) => `1px solid ${a.palette.divider}`,
|
|
21
|
+
bgcolor: "background.paper"
|
|
22
|
+
}, j = {
|
|
23
|
+
display: "flex",
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
gap: 0.5,
|
|
26
|
+
px: 1.5,
|
|
27
|
+
py: 0.75,
|
|
28
|
+
borderBottom: (a) => `1px solid ${a.palette.divider}`,
|
|
29
|
+
bgcolor: (a) => a.palette.mode === "dark" ? "rgba(255,255,255,0.03)" : "rgba(0,0,0,0.02)"
|
|
30
|
+
}, q = {
|
|
31
|
+
width: 180,
|
|
32
|
+
flexShrink: 0,
|
|
33
|
+
position: "relative",
|
|
34
|
+
borderRight: (a) => `1px solid ${a.palette.divider}`,
|
|
35
|
+
bgcolor: (a) => a.palette.mode === "dark" ? "rgba(255,255,255,0.02)" : "rgba(0,0,0,0.015)",
|
|
36
|
+
"& .pdfSlick__thumbs": { p: 1.5 }
|
|
37
|
+
}, ee = ({
|
|
38
|
+
archivo: a,
|
|
39
|
+
paginaUnica: S = !1,
|
|
40
|
+
ajuste: k = "pagina",
|
|
41
|
+
alto: R = 560,
|
|
42
|
+
controles: P = !0,
|
|
43
|
+
miniaturas: m = !1
|
|
44
|
+
}) => {
|
|
45
|
+
const { viewerRef: v, thumbsRef: y, usePDFSlickStore: n, PDFSlickViewer: z, PDFSlickThumbnails: C } = H(
|
|
46
|
+
a,
|
|
47
|
+
{
|
|
48
|
+
singlePageViewer: S,
|
|
49
|
+
scaleValue: Z(k),
|
|
50
|
+
thumbnailWidth: 160
|
|
51
|
+
}
|
|
52
|
+
), l = n((i) => i.pdfSlick), s = n((i) => i.pageNumber), c = n((i) => i.numPages), b = n((i) => i.scale), w = n((i) => i.pagesRotation), [f, A] = _(m), p = $().palette.mode;
|
|
53
|
+
return /* @__PURE__ */ d(r, { sx: { ...J, height: R, colorScheme: p }, children: [
|
|
54
|
+
P && /* @__PURE__ */ d(r, { sx: j, children: [
|
|
55
|
+
m && /* @__PURE__ */ d(M, { children: [
|
|
56
|
+
/* @__PURE__ */ e(t, { title: "Miniaturas", children: /* @__PURE__ */ e(
|
|
57
|
+
o,
|
|
58
|
+
{
|
|
59
|
+
size: "small",
|
|
60
|
+
"aria-label": "Mostrar u ocultar miniaturas",
|
|
61
|
+
color: f ? "primary" : "default",
|
|
62
|
+
onClick: () => A((i) => !i),
|
|
63
|
+
children: /* @__PURE__ */ e(E, { fontSize: "small" })
|
|
64
|
+
}
|
|
65
|
+
) }),
|
|
66
|
+
/* @__PURE__ */ e(x, { orientation: "vertical", flexItem: !0, sx: { mx: 0.5 } })
|
|
67
|
+
] }),
|
|
68
|
+
/* @__PURE__ */ e(t, { title: "Página anterior", children: /* @__PURE__ */ e("span", { children: /* @__PURE__ */ e(
|
|
69
|
+
o,
|
|
70
|
+
{
|
|
71
|
+
size: "small",
|
|
72
|
+
"aria-label": "Página anterior",
|
|
73
|
+
disabled: !l || s <= 1,
|
|
74
|
+
onClick: () => l?.gotoPage(Math.max(1, s - 1)),
|
|
75
|
+
children: /* @__PURE__ */ e(O, { fontSize: "small" })
|
|
76
|
+
}
|
|
77
|
+
) }) }),
|
|
78
|
+
/* @__PURE__ */ e(g, { variant: "body2", sx: { minWidth: 78, textAlign: "center", userSelect: "none" }, children: c ? `${s} / ${c}` : "—" }),
|
|
79
|
+
/* @__PURE__ */ e(t, { title: "Página siguiente", children: /* @__PURE__ */ e("span", { children: /* @__PURE__ */ e(
|
|
80
|
+
o,
|
|
81
|
+
{
|
|
82
|
+
size: "small",
|
|
83
|
+
"aria-label": "Página siguiente",
|
|
84
|
+
disabled: !l || s >= c,
|
|
85
|
+
onClick: () => l?.gotoPage(Math.min(c, s + 1)),
|
|
86
|
+
children: /* @__PURE__ */ e(T, { fontSize: "small" })
|
|
87
|
+
}
|
|
88
|
+
) }) }),
|
|
89
|
+
/* @__PURE__ */ e(r, { sx: { flex: 1 } }),
|
|
90
|
+
/* @__PURE__ */ e(t, { title: "Reducir", children: /* @__PURE__ */ e("span", { children: /* @__PURE__ */ e(o, { size: "small", "aria-label": "Reducir zoom", disabled: !l, onClick: () => l?.decreaseScale(), children: /* @__PURE__ */ e(V, { fontSize: "small" }) }) }) }),
|
|
91
|
+
/* @__PURE__ */ e(g, { variant: "body2", sx: { minWidth: 48, textAlign: "center", userSelect: "none", color: "text.secondary" }, children: b ? `${Math.round(b * 100)}%` : "—" }),
|
|
92
|
+
/* @__PURE__ */ e(t, { title: "Ampliar", children: /* @__PURE__ */ e("span", { children: /* @__PURE__ */ e(o, { size: "small", "aria-label": "Ampliar zoom", disabled: !l, onClick: () => l?.increaseScale(), children: /* @__PURE__ */ e(B, { fontSize: "small" }) }) }) }),
|
|
93
|
+
/* @__PURE__ */ e(x, { orientation: "vertical", flexItem: !0, sx: { mx: 0.5 } }),
|
|
94
|
+
/* @__PURE__ */ e(t, { title: "Rotar", children: /* @__PURE__ */ e("span", { children: /* @__PURE__ */ e(o, { size: "small", "aria-label": "Rotar páginas", disabled: !l, onClick: () => l?.setRotation((w + 90) % 360), children: /* @__PURE__ */ e(F, { fontSize: "small" }) }) }) }),
|
|
95
|
+
/* @__PURE__ */ e(t, { title: "Imprimir", children: /* @__PURE__ */ e("span", { children: /* @__PURE__ */ e(o, { size: "small", "aria-label": "Imprimir documento", disabled: !l, onClick: () => l?.triggerPrinting(), children: /* @__PURE__ */ e(L, { fontSize: "small" }) }) }) }),
|
|
96
|
+
/* @__PURE__ */ e(t, { title: "Descargar", children: /* @__PURE__ */ e("span", { children: /* @__PURE__ */ e(o, { size: "small", "aria-label": "Descargar documento", disabled: !l, onClick: () => l?.downloadOrSave(), children: /* @__PURE__ */ e(W, { fontSize: "small" }) }) }) })
|
|
97
|
+
] }),
|
|
98
|
+
/* @__PURE__ */ d(r, { sx: { display: "flex", flex: 1, minHeight: 0 }, children: [
|
|
99
|
+
m && f && /* @__PURE__ */ e(r, { sx: q, children: /* @__PURE__ */ e(C, { thumbsRef: y, usePDFSlickStore: n, className: "pdfSlick__thumbs", children: ({ pageNumber: i, src: u, width: I, height: N, loaded: D }) => /* @__PURE__ */ d(
|
|
100
|
+
r,
|
|
101
|
+
{
|
|
102
|
+
onClick: () => l?.gotoPage(i),
|
|
103
|
+
sx: {
|
|
104
|
+
cursor: "pointer",
|
|
105
|
+
borderRadius: 1,
|
|
106
|
+
p: 0.5,
|
|
107
|
+
border: (h) => `2px solid ${i === s ? h.palette.primary.main : "transparent"}`,
|
|
108
|
+
transition: "border-color 120ms ease",
|
|
109
|
+
"&:hover": { borderColor: (h) => h.palette.primary.light }
|
|
110
|
+
},
|
|
111
|
+
children: [
|
|
112
|
+
D && u ? /* @__PURE__ */ e("img", { src: u, width: I, height: N, alt: `Página ${i}`, style: { width: "100%", height: "auto", display: "block", borderRadius: 4 } }) : /* @__PURE__ */ e(r, { sx: { width: "100%", aspectRatio: "0.77", bgcolor: "action.hover", borderRadius: 1 } }),
|
|
113
|
+
/* @__PURE__ */ e(g, { variant: "caption", sx: { display: "block", textAlign: "center", mt: 0.5, color: i === s ? "primary.main" : "text.secondary" }, children: i })
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
) }) }),
|
|
117
|
+
/* @__PURE__ */ e(
|
|
118
|
+
r,
|
|
119
|
+
{
|
|
120
|
+
className: "pdfSlick",
|
|
121
|
+
sx: {
|
|
122
|
+
position: "relative",
|
|
123
|
+
flex: 1,
|
|
124
|
+
minHeight: 0,
|
|
125
|
+
bgcolor: p === "dark" ? "#2a2a2e" : "#f3f4f6",
|
|
126
|
+
"& .pdfSlickContainer": { bgcolor: p === "dark" ? "#2a2a2e" : "#f3f4f6" }
|
|
127
|
+
},
|
|
128
|
+
children: /* @__PURE__ */ e(z, { viewerRef: v, usePDFSlickStore: n })
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
] })
|
|
132
|
+
] });
|
|
133
|
+
};
|
|
134
|
+
export {
|
|
135
|
+
ee as CodeplexVisorPdf
|
|
136
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type CodeplexAjustePdf = 'pagina' | 'ancho' | 'auto' | number;
|
|
3
|
+
export interface CodeplexVisorPdfProps {
|
|
4
|
+
/** Ruta, URL o contenido binario del documento PDF. */
|
|
5
|
+
archivo: string | URL | ArrayBuffer;
|
|
6
|
+
/** Muestra una sola página a la vez en lugar de desplazamiento continuo. */
|
|
7
|
+
paginaUnica?: boolean;
|
|
8
|
+
/** Ajuste de zoom inicial del documento. */
|
|
9
|
+
ajuste?: CodeplexAjustePdf;
|
|
10
|
+
/** Altura del visor. */
|
|
11
|
+
alto?: number | string;
|
|
12
|
+
/** Muestra la barra de controles (navegación, zoom, descarga, rotación). */
|
|
13
|
+
controles?: boolean;
|
|
14
|
+
/** Muestra la barra lateral de miniaturas de páginas. */
|
|
15
|
+
miniaturas?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const CodeplexVisorPdf: React.FC<CodeplexVisorPdfProps>;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codeplex-sac/documentos",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"module": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"import": "./index.js",
|
|
12
|
+
"require": "./index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^19.0.0",
|
|
20
|
+
"react-dom": "^19.0.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@mui/material": "^7.3.6",
|
|
24
|
+
"@mui/icons-material": "^7.3.6",
|
|
25
|
+
"@mui/system": "^7.3.7",
|
|
26
|
+
"@emotion/react": "^11.14.0",
|
|
27
|
+
"@emotion/styled": "^11.14.1",
|
|
28
|
+
"@pdfslick/core": "^4.0.0",
|
|
29
|
+
"@pdfslick/react": "^4.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|