@pdfme/ui 1.1.5 → 1.1.6
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/class.d.ts +1 -1
- package/dist/types/components/Designer/Main/Moveable.d.ts +14 -13
- package/dist/types/components/Designer/index.d.ts +1 -1
- package/dist/types/contexts.d.ts +1 -1
- package/dist/types/helper.d.ts +0 -1
- package/dist/types/index.d.ts +4 -3
- package/package.json +1 -1
- package/src/components/Designer/Main/Moveable.tsx +27 -15
- package/src/components/Designer/Main/index.tsx +46 -29
- package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +3 -3
- package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +13 -0
- package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +2 -1
- package/src/components/Root.tsx +11 -10
- package/src/components/Schemas/ImageSchema.tsx +2 -2
- package/src/components/Schemas/SchemaUI.tsx +1 -0
- package/src/helper.ts +0 -10
- package/src/index.ts +42 -3
- package/webpack.config.js +4 -18
- package/vite.config.ts +0 -0
package/dist/types/class.d.ts
CHANGED
@@ -12,7 +12,7 @@ export declare abstract class BaseUIClass {
|
|
12
12
|
protected getFont(): Record<string, {
|
13
13
|
fallback?: boolean | undefined;
|
14
14
|
subset?: boolean | undefined;
|
15
|
-
data: ArrayBuffer | Uint8Array;
|
15
|
+
data: string | ArrayBuffer | Uint8Array;
|
16
16
|
}>;
|
17
17
|
getTemplate(): {
|
18
18
|
columns?: string[] | undefined;
|
@@ -1,5 +1,11 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { OnDrag,
|
2
|
+
import { OnDrag, OnDragEnd, OnDragGroupEnd, OnResize, OnResizeEnd, OnResizeGroupEnd, OnRotate, OnRotateEnd, OnRotateGroupEnd, OnClick } from 'react-moveable';
|
3
|
+
declare type tgtFunc = ({ target }: {
|
4
|
+
target: HTMLElement | SVGElement;
|
5
|
+
}) => void;
|
6
|
+
declare type tgtsFunc = ({ targets }: {
|
7
|
+
targets: (HTMLElement | SVGElement)[];
|
8
|
+
}) => void;
|
3
9
|
declare type Props = {
|
4
10
|
target: HTMLElement[];
|
5
11
|
bounds: {
|
@@ -12,19 +18,14 @@ declare type Props = {
|
|
12
18
|
verticalGuidelines: number[];
|
13
19
|
keepRatio: boolean;
|
14
20
|
onDrag: ((e: OnDrag) => void) & (({ target, left, top }: OnDrag) => void);
|
15
|
-
onDragEnd: ((e: OnDragEnd) => void) &
|
16
|
-
|
17
|
-
}) => void);
|
18
|
-
onDragGroupEnd: ((e: OnDragGroupEnd) => void) & (({ targets }: {
|
19
|
-
targets: (HTMLElement | SVGElement)[];
|
20
|
-
}) => void);
|
21
|
+
onDragEnd: ((e: OnDragEnd) => void) & tgtFunc;
|
22
|
+
onDragGroupEnd: ((e: OnDragGroupEnd) => void) & tgtsFunc;
|
21
23
|
onResize: ((e: OnResize) => void) & (({ target, width, height, direction }: OnResize) => void);
|
22
|
-
onResizeEnd: ((e: OnResizeEnd) => void) &
|
23
|
-
|
24
|
-
}) => void);
|
25
|
-
|
26
|
-
|
27
|
-
}) => void);
|
24
|
+
onResizeEnd: ((e: OnResizeEnd) => void) & tgtFunc;
|
25
|
+
onResizeGroupEnd: ((e: OnResizeGroupEnd) => void) & tgtsFunc;
|
26
|
+
onRotate: ((e: OnRotate) => void) & (({ target, rotate }: OnRotate) => void);
|
27
|
+
onRotateEnd: ((e: OnRotateEnd) => void) & tgtFunc;
|
28
|
+
onRotateGroupEnd: ((e: OnRotateGroupEnd) => void) & tgtsFunc;
|
28
29
|
onClick: (e: OnClick) => void;
|
29
30
|
};
|
30
31
|
declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<any>>;
|
@@ -4,7 +4,7 @@ declare const TemplateEditor: ({ template, size, onSaveTemplate, onChangeTemplat
|
|
4
4
|
font?: Record<string, {
|
5
5
|
fallback?: boolean | undefined;
|
6
6
|
subset?: boolean | undefined;
|
7
|
-
data: ArrayBuffer | Uint8Array;
|
7
|
+
data: string | ArrayBuffer | Uint8Array;
|
8
8
|
}> | undefined;
|
9
9
|
lang?: "en" | "ja" | undefined;
|
10
10
|
} | undefined;
|
package/dist/types/contexts.d.ts
CHANGED
@@ -3,5 +3,5 @@ export declare const I18nContext: import("react").Context<(key: "type" | "field"
|
|
3
3
|
export declare const FontContext: import("react").Context<Record<string, {
|
4
4
|
fallback?: boolean | undefined;
|
5
5
|
subset?: boolean | undefined;
|
6
|
-
data: ArrayBuffer | Uint8Array;
|
6
|
+
data: string | ArrayBuffer | Uint8Array;
|
7
7
|
}>>;
|
package/dist/types/helper.d.ts
CHANGED
@@ -19,7 +19,6 @@ 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;
|
23
22
|
export declare const getPdfPageSizes: (pdfBlob: Blob) => Promise<{
|
24
23
|
height: number;
|
25
24
|
width: number;
|
package/dist/types/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import Designer from './Designer';
|
2
2
|
import Form from './Form';
|
3
3
|
import Viewer from './Viewer';
|
4
|
-
|
5
|
-
|
6
|
-
export { BLANK_PDF, isTextSchema, isImageSchema, isBarcodeSchema, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, }
|
4
|
+
import { BLANK_PDF, HELVETICA, isTextSchema, isImageSchema, isBarcodeSchema, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput } from '@pdfme/common';
|
5
|
+
import type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps } from '@pdfme/common';
|
6
|
+
export { Designer, Viewer, Form, BLANK_PDF, HELVETICA, isTextSchema, isImageSchema, isBarcodeSchema, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, };
|
7
|
+
export type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, };
|
package/package.json
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
import React, { forwardRef, Ref } from 'react';
|
2
2
|
import Moveable, {
|
3
3
|
OnDrag,
|
4
|
-
OnResize,
|
5
4
|
OnDragEnd,
|
6
5
|
OnDragGroupEnd,
|
6
|
+
OnResize,
|
7
7
|
OnResizeEnd,
|
8
8
|
OnResizeGroupEnd,
|
9
|
+
OnRotate,
|
10
|
+
OnRotateEnd,
|
11
|
+
OnRotateGroupEnd,
|
9
12
|
OnClick,
|
10
13
|
} from 'react-moveable';
|
11
14
|
|
15
|
+
type tgtFunc = ({ target }: { target: HTMLElement | SVGElement }) => void;
|
16
|
+
type tgtsFunc = ({ targets }: { targets: (HTMLElement | SVGElement)[] }) => void;
|
17
|
+
|
12
18
|
type Props = {
|
13
19
|
target: HTMLElement[];
|
14
20
|
bounds: { left: number; top: number; bottom: number; right: number };
|
@@ -16,15 +22,15 @@ type Props = {
|
|
16
22
|
verticalGuidelines: number[];
|
17
23
|
keepRatio: boolean;
|
18
24
|
onDrag: ((e: OnDrag) => void) & (({ target, left, top }: OnDrag) => void);
|
19
|
-
onDragEnd: ((e: OnDragEnd) => void) &
|
20
|
-
|
21
|
-
onDragGroupEnd: ((e: OnDragGroupEnd) => void) &
|
22
|
-
(({ targets }: { targets: (HTMLElement | SVGElement)[] }) => void);
|
25
|
+
onDragEnd: ((e: OnDragEnd) => void) & tgtFunc;
|
26
|
+
onDragGroupEnd: ((e: OnDragGroupEnd) => void) & tgtsFunc;
|
23
27
|
onResize: ((e: OnResize) => void) & (({ target, width, height, direction }: OnResize) => void);
|
24
|
-
onResizeEnd: ((e: OnResizeEnd) => void) &
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
onResizeEnd: ((e: OnResizeEnd) => void) & tgtFunc;
|
29
|
+
onResizeGroupEnd: ((e: OnResizeGroupEnd) => void) & tgtsFunc;
|
30
|
+
onRotate: ((e: OnRotate) => void) & (({ target, rotate }: OnRotate) => void);
|
31
|
+
onRotateEnd: ((e: OnRotateEnd) => void) & tgtFunc;
|
32
|
+
onRotateGroupEnd: ((e: OnRotateGroupEnd) => void) & tgtsFunc;
|
33
|
+
|
28
34
|
onClick: (e: OnClick) => void;
|
29
35
|
};
|
30
36
|
|
@@ -41,6 +47,9 @@ const _Moveable = (
|
|
41
47
|
onResize,
|
42
48
|
onResizeEnd,
|
43
49
|
onResizeGroupEnd,
|
50
|
+
onRotate,
|
51
|
+
onRotateEnd,
|
52
|
+
onRotateGroupEnd,
|
44
53
|
onClick,
|
45
54
|
}: Props,
|
46
55
|
ref: Ref<any>
|
@@ -52,6 +61,9 @@ const _Moveable = (
|
|
52
61
|
snapCenter
|
53
62
|
draggable
|
54
63
|
resizable
|
64
|
+
rotatable
|
65
|
+
throttleRotate={0}
|
66
|
+
rotationPosition="top"
|
55
67
|
throttleDrag={1}
|
56
68
|
throttleResize={1}
|
57
69
|
ref={ref}
|
@@ -61,17 +73,17 @@ const _Moveable = (
|
|
61
73
|
verticalGuidelines={verticalGuidelines}
|
62
74
|
keepRatio={keepRatio}
|
63
75
|
onDrag={onDrag}
|
64
|
-
onDragGroup={({ events }) =>
|
65
|
-
events.forEach(onDrag);
|
66
|
-
}}
|
76
|
+
onDragGroup={({ events }) => events.forEach(onDrag)}
|
67
77
|
onDragEnd={onDragEnd}
|
68
78
|
onDragGroupEnd={onDragGroupEnd}
|
69
79
|
onResize={onResize}
|
70
|
-
onResizeGroup={({ events }) =>
|
71
|
-
events.forEach(onResize);
|
72
|
-
}}
|
80
|
+
onResizeGroup={({ events }) => events.forEach(onResize)}
|
73
81
|
onResizeEnd={onResizeEnd}
|
74
82
|
onResizeGroupEnd={onResizeGroupEnd}
|
83
|
+
onRotate={onRotate}
|
84
|
+
onRotateEnd={onRotateEnd}
|
85
|
+
onRotateGroup={({ events }) => events.forEach(onRotate)}
|
86
|
+
onRotateGroupEnd={onRotateGroupEnd}
|
75
87
|
onClick={onClick}
|
76
88
|
/>
|
77
89
|
);
|
@@ -7,8 +7,9 @@ import React, {
|
|
7
7
|
forwardRef,
|
8
8
|
useCallback,
|
9
9
|
} from 'react';
|
10
|
-
import { OnDrag, OnResize, OnClick } from 'react-moveable';
|
10
|
+
import { OnDrag, OnResize, OnRotate, OnClick } from 'react-moveable';
|
11
11
|
import { SchemaForUI, Size } from '@pdfme/common';
|
12
|
+
import { XMarkIcon } from '@heroicons/react/24/outline';
|
12
13
|
import { ZOOM, RULER_HEIGHT } from '../../../constants';
|
13
14
|
import { usePrevious } from '../../../hooks';
|
14
15
|
import { uuid, round, flatten } from '../../../helper';
|
@@ -20,13 +21,16 @@ import Guides from './Guides';
|
|
20
21
|
import Mask from './Mask';
|
21
22
|
|
22
23
|
const DELETE_BTN_ID = uuid();
|
23
|
-
const
|
24
|
-
const
|
24
|
+
const px2Num = (prop: string) => Number(prop.replace('px', ''));
|
25
|
+
const transformRotate2Num = (transform: string) =>
|
26
|
+
Number(transform.match(/rotate\(([^deg)]*)deg\)/)?.[1]) || 0;
|
27
|
+
const fmtPx = (prop: string) => round(px2Num(prop) / ZOOM, 2);
|
28
|
+
const fmtDeg = (prop: string) => round(transformRotate2Num(prop), 2);
|
25
29
|
const isTopLeftResize = (d: string) => d === '-1,-1' || d === '-1,0' || d === '0,-1';
|
26
30
|
|
27
31
|
const DeleteButton = ({ activeElements: aes }: { activeElements: HTMLElement[] }) => {
|
28
|
-
const top = Math.min(...aes.map(({ style }) =>
|
29
|
-
const left = Math.max(...aes.map(({ style }) =>
|
32
|
+
const top = Math.min(...aes.map(({ style }) => px2Num(style.top)));
|
33
|
+
const left = Math.max(...aes.map(({ style }) => px2Num(style.left) + px2Num(style.width))) + 10;
|
30
34
|
|
31
35
|
return (
|
32
36
|
<button
|
@@ -49,16 +53,7 @@ const DeleteButton = ({ activeElements: aes }: { activeElements: HTMLElement[] }
|
|
49
53
|
justifyContent: 'center',
|
50
54
|
}}
|
51
55
|
>
|
52
|
-
<
|
53
|
-
style={{ pointerEvents: 'none' }}
|
54
|
-
xmlns="http://www.w3.org/2000/svg"
|
55
|
-
fill="none"
|
56
|
-
viewBox="0 0 24 24"
|
57
|
-
strokeWidth="1.5"
|
58
|
-
stroke="currentColor"
|
59
|
-
>
|
60
|
-
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
61
|
-
</svg>
|
56
|
+
<XMarkIcon width={10} height={10} />
|
62
57
|
</button>
|
63
58
|
);
|
64
59
|
};
|
@@ -157,15 +152,15 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
157
152
|
const onDragEnd = ({ target }: { target: HTMLElement | SVGElement }) => {
|
158
153
|
const { top, left } = target.style;
|
159
154
|
changeSchemas([
|
160
|
-
{ key: 'position.y', value:
|
161
|
-
{ key: 'position.x', value:
|
155
|
+
{ key: 'position.y', value: fmtPx(top), schemaId: target.id },
|
156
|
+
{ key: 'position.x', value: fmtPx(left), schemaId: target.id },
|
162
157
|
]);
|
163
158
|
};
|
164
159
|
|
165
160
|
const onDragEnds = ({ targets }: { targets: (HTMLElement | SVGElement)[] }) => {
|
166
161
|
const arg = targets.map(({ style: { top, left }, id }) => [
|
167
|
-
{ key: 'position.y', value:
|
168
|
-
{ key: 'position.x', value:
|
162
|
+
{ key: 'position.y', value: fmtPx(top), schemaId: id },
|
163
|
+
{ key: 'position.x', value: fmtPx(left), schemaId: id },
|
169
164
|
]);
|
170
165
|
changeSchemas(flatten(arg));
|
171
166
|
};
|
@@ -174,19 +169,19 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
174
169
|
const { id, style } = target;
|
175
170
|
const { width, height, top, left } = style;
|
176
171
|
changeSchemas([
|
177
|
-
{ key: 'width', value:
|
178
|
-
{ key: 'height', value:
|
179
|
-
{ key: 'position.y', value:
|
180
|
-
{ key: 'position.x', value:
|
172
|
+
{ key: 'width', value: fmtPx(width), schemaId: id },
|
173
|
+
{ key: 'height', value: fmtPx(height), schemaId: id },
|
174
|
+
{ key: 'position.y', value: fmtPx(top), schemaId: id },
|
175
|
+
{ key: 'position.x', value: fmtPx(left), schemaId: id },
|
181
176
|
]);
|
182
177
|
};
|
183
178
|
|
184
179
|
const onResizeEnds = ({ targets }: { targets: (HTMLElement | SVGElement)[] }) => {
|
185
180
|
const arg = targets.map(({ style: { width, height, top, left }, id }) => [
|
186
|
-
{ key: 'width', value:
|
187
|
-
{ key: 'height', value:
|
188
|
-
{ key: 'position.y', value:
|
189
|
-
{ key: 'position.x', value:
|
181
|
+
{ key: 'width', value: fmtPx(width), schemaId: id },
|
182
|
+
{ key: 'height', value: fmtPx(height), schemaId: id },
|
183
|
+
{ key: 'position.y', value: fmtPx(top), schemaId: id },
|
184
|
+
{ key: 'position.x', value: fmtPx(left), schemaId: id },
|
190
185
|
]);
|
191
186
|
changeSchemas(flatten(arg));
|
192
187
|
};
|
@@ -194,8 +189,8 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
194
189
|
const onResize = ({ target, width, height, direction }: OnResize) => {
|
195
190
|
if (!target) return;
|
196
191
|
const s = target.style;
|
197
|
-
const newLeft =
|
198
|
-
const newTop =
|
192
|
+
const newLeft = px2Num(s.left) + (px2Num(s.width) - width);
|
193
|
+
const newTop = px2Num(s.top) + (px2Num(s.height) - height);
|
199
194
|
const obj: { top?: string; left?: string; width: string; height: string } = {
|
200
195
|
width: `${width}px`,
|
201
196
|
height: `${height}px`,
|
@@ -212,6 +207,25 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
212
207
|
Object.assign(s, obj);
|
213
208
|
};
|
214
209
|
|
210
|
+
const onRotate = ({ target, rotate }: OnRotate) => {
|
211
|
+
if (!target) return;
|
212
|
+
target.style.transform = `rotate(${rotate}deg)`;
|
213
|
+
};
|
214
|
+
|
215
|
+
const onRotateEnd = ({ target }: { target: HTMLElement | SVGElement }) => {
|
216
|
+
const { id, style } = target;
|
217
|
+
const { transform } = style;
|
218
|
+
changeSchemas([{ key: 'rotate', value: fmtDeg(transform), schemaId: id }]);
|
219
|
+
};
|
220
|
+
|
221
|
+
const onRotateEnds = ({ targets }: { targets: (HTMLElement | SVGElement)[] }) => {
|
222
|
+
const arg = targets.map(({ style: { transform }, id }) => [
|
223
|
+
{ key: 'rotate', value: fmtDeg(transform), schemaId: id },
|
224
|
+
{ key: 'rotate', value: fmtDeg(transform), schemaId: id },
|
225
|
+
]);
|
226
|
+
changeSchemas(flatten(arg));
|
227
|
+
};
|
228
|
+
|
215
229
|
const getGuideLines = (guides: GuidesInterface[], index: number) =>
|
216
230
|
guides[index] && guides[index].getGuides().map((g) => g * ZOOM);
|
217
231
|
|
@@ -308,6 +322,9 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
308
322
|
onResize={onResize}
|
309
323
|
onResizeEnd={onResizeEnd}
|
310
324
|
onResizeGroupEnd={onResizeEnds}
|
325
|
+
onRotate={onRotate}
|
326
|
+
onRotateEnd={onRotateEnd}
|
327
|
+
onRotateGroupEnd={onRotateEnds}
|
311
328
|
onClick={onClickMoveable}
|
312
329
|
/>
|
313
330
|
)
|
@@ -24,15 +24,15 @@ const ExampleInputEditor = (
|
|
24
24
|
top: 0,
|
25
25
|
left: 0,
|
26
26
|
display: 'flex',
|
27
|
-
justifyContent: 'center',
|
28
27
|
alignItems: 'center',
|
28
|
+
justifyContent: 'center',
|
29
29
|
color: '#333',
|
30
30
|
background: '#f2f2f2',
|
31
31
|
cursor: 'pointer',
|
32
32
|
borderRadius: 2,
|
33
33
|
border: '1px solid #767676',
|
34
|
-
height:
|
35
|
-
width:
|
34
|
+
height: 24,
|
35
|
+
width: 24,
|
36
36
|
}}
|
37
37
|
aria-label="close"
|
38
38
|
onClick={() =>
|
@@ -258,6 +258,19 @@ const PositionAndSizeEditor = (
|
|
258
258
|
<span style={{ fontSize: '0.6rem' }}>mm</span>
|
259
259
|
</div>
|
260
260
|
</div>
|
261
|
+
<div style={inputSetStyle}>
|
262
|
+
<label style={{ width: 44 }}>Rotate</label>
|
263
|
+
<input
|
264
|
+
style={inputStyle}
|
265
|
+
type="number"
|
266
|
+
onChange={(e) => {
|
267
|
+
const value = Number(e.target.value || 0);
|
268
|
+
changeSchemas([{ key: 'rotate', value, schemaId: activeSchema.id }]);
|
269
|
+
}}
|
270
|
+
value={activeSchema.rotate || 0}
|
271
|
+
/>
|
272
|
+
<span style={{ fontSize: '0.6rem' }}>deg</span>
|
273
|
+
</div>
|
261
274
|
</div>
|
262
275
|
);
|
263
276
|
};
|
@@ -53,8 +53,9 @@ const ColorInputSet = (props: {
|
|
53
53
|
onClick={onClear}
|
54
54
|
style={{
|
55
55
|
display: 'flex',
|
56
|
-
background: 'none',
|
57
56
|
alignItems: 'center',
|
57
|
+
justifyContent: 'center',
|
58
|
+
background: 'none',
|
58
59
|
borderRadius: 2,
|
59
60
|
border: '1px solid #767676',
|
60
61
|
cursor: 'pointer',
|
package/src/components/Root.tsx
CHANGED
@@ -9,19 +9,20 @@ const Root = ({ size, scale, children }: Props, ref: Ref<HTMLDivElement>) => {
|
|
9
9
|
const font = useContext(FontContext);
|
10
10
|
|
11
11
|
useEffect(() => {
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
if (!document || !document.fonts) return;
|
13
|
+
const fontFaces = Object.entries(font).map(
|
14
|
+
([key, { data }]) =>
|
15
|
+
new FontFace(key, typeof data === 'string' ? `url(${data})` : data, {
|
16
|
+
display: 'swap',
|
17
|
+
})
|
18
|
+
);
|
19
|
+
// @ts-ignore
|
20
|
+
const newFontFaces = fontFaces.filter((fontFace) => !document.fonts.has(fontFace));
|
15
21
|
|
16
|
-
|
17
|
-
});
|
18
|
-
Promise.all(fontFaces).then((loadedFontFaces) => {
|
22
|
+
Promise.all(newFontFaces.map((f) => f.load())).then((loadedFontFaces) => {
|
19
23
|
loadedFontFaces.forEach((loadedFontFace) => {
|
20
24
|
// @ts-ignore
|
21
|
-
|
22
|
-
// @ts-ignore
|
23
|
-
document.fonts.add(loadedFontFace);
|
24
|
-
}
|
25
|
+
document.fonts.add(loadedFontFace);
|
25
26
|
});
|
26
27
|
});
|
27
28
|
}, [font]);
|
package/src/helper.ts
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
// TODO そもそもこのpdfjs-distはtscでビルドできない
|
2
|
-
// 昔のpdfmeのソースからwebpackのビルドに戻す
|
3
|
-
// 多分tree-shakingは動かないかもしれないけど、とりあえず動くようにするべき
|
4
1
|
// @ts-ignore
|
5
2
|
import PDFJSWorker from 'pdfjs-dist/build/pdf.worker.entry.js';
|
6
3
|
import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist/legacy/build/pdf.js';
|
@@ -237,13 +234,6 @@ const pt2mm = (pt: number) => {
|
|
237
234
|
return parseFloat(String(pt)) * mmRatio;
|
238
235
|
};
|
239
236
|
|
240
|
-
export const px2mm = (px: number) => {
|
241
|
-
// http://www.unitconversion.org/typography/millimeters-to-pixels-y-conversion.html
|
242
|
-
const mmRatio = 0.264583333;
|
243
|
-
|
244
|
-
return parseFloat(String(px)) * mmRatio;
|
245
|
-
};
|
246
|
-
|
247
237
|
export const getPdfPageSizes = async (pdfBlob: Blob) => {
|
248
238
|
const url = URL.createObjectURL(pdfBlob);
|
249
239
|
const pdfDoc = await getDocument({ url }).promise;
|
package/src/index.ts
CHANGED
@@ -2,9 +2,21 @@ import Designer from './Designer';
|
|
2
2
|
import Form from './Form';
|
3
3
|
import Viewer from './Viewer';
|
4
4
|
|
5
|
-
|
5
|
+
import {
|
6
|
+
BLANK_PDF,
|
7
|
+
HELVETICA,
|
8
|
+
isTextSchema,
|
9
|
+
isImageSchema,
|
10
|
+
isBarcodeSchema,
|
11
|
+
checkTemplate,
|
12
|
+
checkUIProps,
|
13
|
+
checkPreviewProps,
|
14
|
+
checkDesignerProps,
|
15
|
+
checkGenerateProps,
|
16
|
+
validateBarcodeInput,
|
17
|
+
} from '@pdfme/common';
|
6
18
|
|
7
|
-
|
19
|
+
import type {
|
8
20
|
Lang,
|
9
21
|
Size,
|
10
22
|
Alignment,
|
@@ -28,7 +40,11 @@ export type {
|
|
28
40
|
} from '@pdfme/common';
|
29
41
|
|
30
42
|
export {
|
43
|
+
Designer,
|
44
|
+
Viewer,
|
45
|
+
Form,
|
31
46
|
BLANK_PDF,
|
47
|
+
HELVETICA,
|
32
48
|
isTextSchema,
|
33
49
|
isImageSchema,
|
34
50
|
isBarcodeSchema,
|
@@ -38,4 +54,27 @@ export {
|
|
38
54
|
checkDesignerProps,
|
39
55
|
checkGenerateProps,
|
40
56
|
validateBarcodeInput,
|
41
|
-
}
|
57
|
+
};
|
58
|
+
|
59
|
+
export type {
|
60
|
+
Lang,
|
61
|
+
Size,
|
62
|
+
Alignment,
|
63
|
+
SchemaType,
|
64
|
+
BarCodeType,
|
65
|
+
TextSchema,
|
66
|
+
ImageSchema,
|
67
|
+
BarcodeSchema,
|
68
|
+
Schema,
|
69
|
+
SchemaForUI,
|
70
|
+
Font,
|
71
|
+
BasePdf,
|
72
|
+
Template,
|
73
|
+
CommonProps,
|
74
|
+
GeneratorOptions,
|
75
|
+
GenerateProps,
|
76
|
+
UIOptions,
|
77
|
+
UIProps,
|
78
|
+
PreviewProps,
|
79
|
+
DesignerProps,
|
80
|
+
};
|
package/webpack.config.js
CHANGED
@@ -19,13 +19,8 @@ const config = {
|
|
19
19
|
},
|
20
20
|
plugins: [
|
21
21
|
// new BundleAnalyzerPlugin(),
|
22
|
-
new webpack.ProvidePlugin({
|
23
|
-
|
24
|
-
}),
|
25
|
-
new webpack.BannerPlugin({
|
26
|
-
banner: BANNER,
|
27
|
-
entryOnly: true,
|
28
|
-
}),
|
22
|
+
new webpack.ProvidePlugin({ process: 'process/browser' }),
|
23
|
+
new webpack.BannerPlugin({ banner: BANNER, entryOnly: true }),
|
29
24
|
],
|
30
25
|
devtool: 'source-map',
|
31
26
|
entry: './src/index.ts',
|
@@ -33,17 +28,8 @@ const config = {
|
|
33
28
|
path: path.resolve(__dirname, 'dist'),
|
34
29
|
filename: 'index.js',
|
35
30
|
globalObject: 'this',
|
36
|
-
library: {
|
37
|
-
type: 'umd',
|
38
|
-
},
|
39
|
-
},
|
40
|
-
module: {
|
41
|
-
rules: [
|
42
|
-
{
|
43
|
-
test: /\.tsx?$/,
|
44
|
-
use: 'ts-loader',
|
45
|
-
},
|
46
|
-
],
|
31
|
+
library: { type: 'umd' },
|
47
32
|
},
|
33
|
+
module: { rules: [{ test: /\.tsx?$/, use: 'ts-loader' }] },
|
48
34
|
};
|
49
35
|
module.exports = config;
|
package/vite.config.ts
DELETED
File without changes
|