@pdfme/ui 1.0.2 → 1.0.5
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/index.js +1 -1
- package/dist/index.js.LICENSE.txt +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/helper.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/Paper.tsx +1 -0
- package/src/components/Preview/index.tsx +5 -2
- package/src/components/Root.tsx +0 -1
- package/src/components/Schemas/SchemaUI.tsx +1 -4
- package/src/components/Schemas/TextSchema.tsx +1 -1
- package/src/helper.ts +7 -0
package/dist/types/helper.d.ts
CHANGED
@@ -19,6 +19,7 @@ export declare const initShortCuts: (arg: {
|
|
19
19
|
}) => void;
|
20
20
|
export declare const destroyShortCuts: () => void;
|
21
21
|
export declare const readFiles: (files: FileList | null, type: 'text' | 'dataURL' | 'arrayBuffer') => Promise<string | ArrayBuffer>;
|
22
|
+
export declare const px2mm: (px: number) => number;
|
22
23
|
export declare const getPdfPageSizes: (pdfBlob: Blob) => Promise<{
|
23
24
|
height: number;
|
24
25
|
width: number;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/ui",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.5",
|
4
4
|
"author": "hand-dot",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
package/src/components/Paper.tsx
CHANGED
@@ -8,7 +8,7 @@ import Error from '../Error';
|
|
8
8
|
import Paper from '../Paper';
|
9
9
|
import SchemaUI from '../Schemas/SchemaUI';
|
10
10
|
import { useUIPreProcessor, useScrollPageCursor } from '../../hooks';
|
11
|
-
import { templateSchemas2SchemasList } from '../../helper';
|
11
|
+
import { templateSchemas2SchemasList, px2mm } from '../../helper';
|
12
12
|
|
13
13
|
const Preview = ({ template, inputs, size, onChangeInput }: PreviewReactProps) => {
|
14
14
|
const { backgrounds, pageSizes, scale, error } = useUIPreProcessor({
|
@@ -54,8 +54,11 @@ const Preview = ({ template, inputs, size, onChangeInput }: PreviewReactProps) =
|
|
54
54
|
<Root ref={rootRef} size={size} scale={scale}>
|
55
55
|
<div
|
56
56
|
style={{
|
57
|
-
height:
|
57
|
+
height:
|
58
|
+
pageSizes.reduce((acc, cur) => acc + (cur.height + px2mm(RULER_HEIGHT)) * scale, 0) +
|
59
|
+
'mm',
|
58
60
|
width: '100%',
|
61
|
+
top: 0,
|
59
62
|
position: 'absolute',
|
60
63
|
}}
|
61
64
|
>
|
package/src/components/Root.tsx
CHANGED
@@ -18,9 +18,6 @@ type Props = SchemaUIProps & {
|
|
18
18
|
onChangeHoveringSchemaId?: (id: string | null) => void;
|
19
19
|
};
|
20
20
|
|
21
|
-
const getBgc = (schema: SchemaForUI) =>
|
22
|
-
schema.type === 'text' && schema.backgroundColor ? schema.backgroundColor : 'transparent';
|
23
|
-
|
24
21
|
const Wrapper = ({
|
25
22
|
children,
|
26
23
|
border,
|
@@ -35,12 +32,12 @@ const Wrapper = ({
|
|
35
32
|
id={schema.id}
|
36
33
|
style={{
|
37
34
|
position: 'absolute',
|
35
|
+
cursor: 'pointer',
|
38
36
|
height: schema.height * ZOOM,
|
39
37
|
width: schema.width * ZOOM,
|
40
38
|
top: schema.position.y * ZOOM,
|
41
39
|
left: schema.position.x * ZOOM,
|
42
40
|
border,
|
43
|
-
backgroundColor: getBgc(schema),
|
44
41
|
}}
|
45
42
|
>
|
46
43
|
{children}
|
@@ -32,8 +32,8 @@ const TextSchemaUI = (
|
|
32
32
|
wordBreak: 'break-all',
|
33
33
|
background: 'transparent',
|
34
34
|
border: 'none',
|
35
|
-
outline: 'none',
|
36
35
|
color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
|
36
|
+
backgroundColor: schema.data && schema.backgroundColor ? schema.backgroundColor : 'transparent',
|
37
37
|
};
|
38
38
|
|
39
39
|
return editable ? (
|
package/src/helper.ts
CHANGED
@@ -233,6 +233,13 @@ const pt2mm = (pt: number) => {
|
|
233
233
|
return parseFloat(String(pt)) * mmRatio;
|
234
234
|
};
|
235
235
|
|
236
|
+
export const px2mm = (px: number) => {
|
237
|
+
// http://www.unitconversion.org/typography/millimeters-to-pixels-y-conversion.html
|
238
|
+
const mmRatio = 0.264583333;
|
239
|
+
|
240
|
+
return parseFloat(String(px)) * mmRatio;
|
241
|
+
};
|
242
|
+
|
236
243
|
export const getPdfPageSizes = async (pdfBlob: Blob) => {
|
237
244
|
const url = URL.createObjectURL(pdfBlob);
|
238
245
|
const pdfDoc = await getDocument({ url }).promise;
|