@pdfme/ui 1.1.6 → 1.1.9
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/components/Designer/Main/Moveable.d.ts +13 -14
- package/dist/types/helper.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/Designer/Main/Moveable.tsx +15 -27
- package/src/components/Designer/Main/index.tsx +19 -44
- package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +0 -13
- package/src/components/Root.tsx +5 -3
- package/src/components/Schemas/SchemaUI.tsx +0 -1
- package/src/helper.ts +10 -0
@@ -1,11 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { OnDrag, OnDragEnd, OnDragGroupEnd,
|
3
|
-
declare type tgtFunc = ({ target }: {
|
4
|
-
target: HTMLElement | SVGElement;
|
5
|
-
}) => void;
|
6
|
-
declare type tgtsFunc = ({ targets }: {
|
7
|
-
targets: (HTMLElement | SVGElement)[];
|
8
|
-
}) => void;
|
2
|
+
import { OnDrag, OnResize, OnDragEnd, OnDragGroupEnd, OnResizeEnd, OnResizeGroupEnd, OnClick } from 'react-moveable';
|
9
3
|
declare type Props = {
|
10
4
|
target: HTMLElement[];
|
11
5
|
bounds: {
|
@@ -18,14 +12,19 @@ declare type Props = {
|
|
18
12
|
verticalGuidelines: number[];
|
19
13
|
keepRatio: boolean;
|
20
14
|
onDrag: ((e: OnDrag) => void) & (({ target, left, top }: OnDrag) => void);
|
21
|
-
onDragEnd: ((e: OnDragEnd) => void) &
|
22
|
-
|
15
|
+
onDragEnd: ((e: OnDragEnd) => void) & (({ target }: {
|
16
|
+
target: HTMLElement | SVGElement;
|
17
|
+
}) => void);
|
18
|
+
onDragGroupEnd: ((e: OnDragGroupEnd) => void) & (({ targets }: {
|
19
|
+
targets: (HTMLElement | SVGElement)[];
|
20
|
+
}) => void);
|
23
21
|
onResize: ((e: OnResize) => void) & (({ target, width, height, direction }: OnResize) => void);
|
24
|
-
onResizeEnd: ((e: OnResizeEnd) => void) &
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
onResizeEnd: ((e: OnResizeEnd) => void) & (({ target }: {
|
23
|
+
target: HTMLElement | SVGElement;
|
24
|
+
}) => void);
|
25
|
+
onResizeGroupEnd: ((e: OnResizeGroupEnd) => void) & (({ targets }: {
|
26
|
+
targets: (HTMLElement | SVGElement)[];
|
27
|
+
}) => void);
|
29
28
|
onClick: (e: OnClick) => void;
|
30
29
|
};
|
31
30
|
declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<any>>;
|
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,20 +1,14 @@
|
|
1
1
|
import React, { forwardRef, Ref } from 'react';
|
2
2
|
import Moveable, {
|
3
3
|
OnDrag,
|
4
|
+
OnResize,
|
4
5
|
OnDragEnd,
|
5
6
|
OnDragGroupEnd,
|
6
|
-
OnResize,
|
7
7
|
OnResizeEnd,
|
8
8
|
OnResizeGroupEnd,
|
9
|
-
OnRotate,
|
10
|
-
OnRotateEnd,
|
11
|
-
OnRotateGroupEnd,
|
12
9
|
OnClick,
|
13
10
|
} from 'react-moveable';
|
14
11
|
|
15
|
-
type tgtFunc = ({ target }: { target: HTMLElement | SVGElement }) => void;
|
16
|
-
type tgtsFunc = ({ targets }: { targets: (HTMLElement | SVGElement)[] }) => void;
|
17
|
-
|
18
12
|
type Props = {
|
19
13
|
target: HTMLElement[];
|
20
14
|
bounds: { left: number; top: number; bottom: number; right: number };
|
@@ -22,15 +16,15 @@ type Props = {
|
|
22
16
|
verticalGuidelines: number[];
|
23
17
|
keepRatio: boolean;
|
24
18
|
onDrag: ((e: OnDrag) => void) & (({ target, left, top }: OnDrag) => void);
|
25
|
-
onDragEnd: ((e: OnDragEnd) => void) &
|
26
|
-
|
19
|
+
onDragEnd: ((e: OnDragEnd) => void) &
|
20
|
+
(({ target }: { target: HTMLElement | SVGElement }) => void);
|
21
|
+
onDragGroupEnd: ((e: OnDragGroupEnd) => void) &
|
22
|
+
(({ targets }: { targets: (HTMLElement | SVGElement)[] }) => void);
|
27
23
|
onResize: ((e: OnResize) => void) & (({ target, width, height, direction }: OnResize) => void);
|
28
|
-
onResizeEnd: ((e: OnResizeEnd) => void) &
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
onRotateGroupEnd: ((e: OnRotateGroupEnd) => void) & tgtsFunc;
|
33
|
-
|
24
|
+
onResizeEnd: ((e: OnResizeEnd) => void) &
|
25
|
+
(({ target }: { target: HTMLElement | SVGElement }) => void);
|
26
|
+
onResizeGroupEnd: ((e: OnResizeGroupEnd) => void) &
|
27
|
+
(({ targets }: { targets: (HTMLElement | SVGElement)[] }) => void);
|
34
28
|
onClick: (e: OnClick) => void;
|
35
29
|
};
|
36
30
|
|
@@ -47,9 +41,6 @@ const _Moveable = (
|
|
47
41
|
onResize,
|
48
42
|
onResizeEnd,
|
49
43
|
onResizeGroupEnd,
|
50
|
-
onRotate,
|
51
|
-
onRotateEnd,
|
52
|
-
onRotateGroupEnd,
|
53
44
|
onClick,
|
54
45
|
}: Props,
|
55
46
|
ref: Ref<any>
|
@@ -61,9 +52,6 @@ const _Moveable = (
|
|
61
52
|
snapCenter
|
62
53
|
draggable
|
63
54
|
resizable
|
64
|
-
rotatable
|
65
|
-
throttleRotate={0}
|
66
|
-
rotationPosition="top"
|
67
55
|
throttleDrag={1}
|
68
56
|
throttleResize={1}
|
69
57
|
ref={ref}
|
@@ -73,17 +61,17 @@ const _Moveable = (
|
|
73
61
|
verticalGuidelines={verticalGuidelines}
|
74
62
|
keepRatio={keepRatio}
|
75
63
|
onDrag={onDrag}
|
76
|
-
onDragGroup={({ events }) =>
|
64
|
+
onDragGroup={({ events }) => {
|
65
|
+
events.forEach(onDrag);
|
66
|
+
}}
|
77
67
|
onDragEnd={onDragEnd}
|
78
68
|
onDragGroupEnd={onDragGroupEnd}
|
79
69
|
onResize={onResize}
|
80
|
-
onResizeGroup={({ events }) =>
|
70
|
+
onResizeGroup={({ events }) => {
|
71
|
+
events.forEach(onResize);
|
72
|
+
}}
|
81
73
|
onResizeEnd={onResizeEnd}
|
82
74
|
onResizeGroupEnd={onResizeGroupEnd}
|
83
|
-
onRotate={onRotate}
|
84
|
-
onRotateEnd={onRotateEnd}
|
85
|
-
onRotateGroup={({ events }) => events.forEach(onRotate)}
|
86
|
-
onRotateGroupEnd={onRotateGroupEnd}
|
87
75
|
onClick={onClick}
|
88
76
|
/>
|
89
77
|
);
|
@@ -7,7 +7,7 @@ import React, {
|
|
7
7
|
forwardRef,
|
8
8
|
useCallback,
|
9
9
|
} from 'react';
|
10
|
-
import { OnDrag, OnResize,
|
10
|
+
import { OnDrag, OnResize, OnClick } from 'react-moveable';
|
11
11
|
import { SchemaForUI, Size } from '@pdfme/common';
|
12
12
|
import { XMarkIcon } from '@heroicons/react/24/outline';
|
13
13
|
import { ZOOM, RULER_HEIGHT } from '../../../constants';
|
@@ -21,16 +21,13 @@ import Guides from './Guides';
|
|
21
21
|
import Mask from './Mask';
|
22
22
|
|
23
23
|
const DELETE_BTN_ID = uuid();
|
24
|
-
const
|
25
|
-
const
|
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);
|
24
|
+
const fmt4Num = (prop: string) => Number(prop.replace('px', ''));
|
25
|
+
const fmt = (prop: string) => round(fmt4Num(prop) / ZOOM, 2);
|
29
26
|
const isTopLeftResize = (d: string) => d === '-1,-1' || d === '-1,0' || d === '0,-1';
|
30
27
|
|
31
28
|
const DeleteButton = ({ activeElements: aes }: { activeElements: HTMLElement[] }) => {
|
32
|
-
const top = Math.min(...aes.map(({ style }) =>
|
33
|
-
const left = Math.max(...aes.map(({ style }) =>
|
29
|
+
const top = Math.min(...aes.map(({ style }) => fmt4Num(style.top)));
|
30
|
+
const left = Math.max(...aes.map(({ style }) => fmt4Num(style.left) + fmt4Num(style.width))) + 10;
|
34
31
|
|
35
32
|
return (
|
36
33
|
<button
|
@@ -152,15 +149,15 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
152
149
|
const onDragEnd = ({ target }: { target: HTMLElement | SVGElement }) => {
|
153
150
|
const { top, left } = target.style;
|
154
151
|
changeSchemas([
|
155
|
-
{ key: 'position.y', value:
|
156
|
-
{ key: 'position.x', value:
|
152
|
+
{ key: 'position.y', value: fmt(top), schemaId: target.id },
|
153
|
+
{ key: 'position.x', value: fmt(left), schemaId: target.id },
|
157
154
|
]);
|
158
155
|
};
|
159
156
|
|
160
157
|
const onDragEnds = ({ targets }: { targets: (HTMLElement | SVGElement)[] }) => {
|
161
158
|
const arg = targets.map(({ style: { top, left }, id }) => [
|
162
|
-
{ key: 'position.y', value:
|
163
|
-
{ key: 'position.x', value:
|
159
|
+
{ key: 'position.y', value: fmt(top), schemaId: id },
|
160
|
+
{ key: 'position.x', value: fmt(left), schemaId: id },
|
164
161
|
]);
|
165
162
|
changeSchemas(flatten(arg));
|
166
163
|
};
|
@@ -169,19 +166,19 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
169
166
|
const { id, style } = target;
|
170
167
|
const { width, height, top, left } = style;
|
171
168
|
changeSchemas([
|
172
|
-
{ key: 'width', value:
|
173
|
-
{ key: 'height', value:
|
174
|
-
{ key: 'position.y', value:
|
175
|
-
{ key: 'position.x', value:
|
169
|
+
{ key: 'width', value: fmt(width), schemaId: id },
|
170
|
+
{ key: 'height', value: fmt(height), schemaId: id },
|
171
|
+
{ key: 'position.y', value: fmt(top), schemaId: id },
|
172
|
+
{ key: 'position.x', value: fmt(left), schemaId: id },
|
176
173
|
]);
|
177
174
|
};
|
178
175
|
|
179
176
|
const onResizeEnds = ({ targets }: { targets: (HTMLElement | SVGElement)[] }) => {
|
180
177
|
const arg = targets.map(({ style: { width, height, top, left }, id }) => [
|
181
|
-
{ key: 'width', value:
|
182
|
-
{ key: 'height', value:
|
183
|
-
{ key: 'position.y', value:
|
184
|
-
{ key: 'position.x', value:
|
178
|
+
{ key: 'width', value: fmt(width), schemaId: id },
|
179
|
+
{ key: 'height', value: fmt(height), schemaId: id },
|
180
|
+
{ key: 'position.y', value: fmt(top), schemaId: id },
|
181
|
+
{ key: 'position.x', value: fmt(left), schemaId: id },
|
185
182
|
]);
|
186
183
|
changeSchemas(flatten(arg));
|
187
184
|
};
|
@@ -189,8 +186,8 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
189
186
|
const onResize = ({ target, width, height, direction }: OnResize) => {
|
190
187
|
if (!target) return;
|
191
188
|
const s = target.style;
|
192
|
-
const newLeft =
|
193
|
-
const newTop =
|
189
|
+
const newLeft = fmt4Num(s.left) + (fmt4Num(s.width) - width);
|
190
|
+
const newTop = fmt4Num(s.top) + (fmt4Num(s.height) - height);
|
194
191
|
const obj: { top?: string; left?: string; width: string; height: string } = {
|
195
192
|
width: `${width}px`,
|
196
193
|
height: `${height}px`,
|
@@ -207,25 +204,6 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
207
204
|
Object.assign(s, obj);
|
208
205
|
};
|
209
206
|
|
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
|
-
|
229
207
|
const getGuideLines = (guides: GuidesInterface[], index: number) =>
|
230
208
|
guides[index] && guides[index].getGuides().map((g) => g * ZOOM);
|
231
209
|
|
@@ -322,9 +300,6 @@ const Main = (props: Props, ref: Ref<HTMLDivElement>) => {
|
|
322
300
|
onResize={onResize}
|
323
301
|
onResizeEnd={onResizeEnd}
|
324
302
|
onResizeGroupEnd={onResizeEnds}
|
325
|
-
onRotate={onRotate}
|
326
|
-
onRotateEnd={onRotateEnd}
|
327
|
-
onRotateGroupEnd={onRotateEnds}
|
328
303
|
onClick={onClickMoveable}
|
329
304
|
/>
|
330
305
|
)
|
@@ -258,19 +258,6 @@ 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>
|
274
261
|
</div>
|
275
262
|
);
|
276
263
|
};
|
package/src/components/Root.tsx
CHANGED
@@ -19,10 +19,12 @@ const Root = ({ size, scale, children }: Props, ref: Ref<HTMLDivElement>) => {
|
|
19
19
|
// @ts-ignore
|
20
20
|
const newFontFaces = fontFaces.filter((fontFace) => !document.fonts.has(fontFace));
|
21
21
|
|
22
|
-
Promise.
|
22
|
+
Promise.allSettled(newFontFaces.map((f) => f.load())).then((loadedFontFaces) => {
|
23
23
|
loadedFontFaces.forEach((loadedFontFace) => {
|
24
|
-
|
25
|
-
|
24
|
+
if (loadedFontFace.status === 'fulfilled') {
|
25
|
+
// @ts-ignore
|
26
|
+
document.fonts.add(loadedFontFace.value);
|
27
|
+
}
|
26
28
|
});
|
27
29
|
});
|
28
30
|
}, [font]);
|
package/src/helper.ts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
// TODO そもそもこのpdfjs-distはtscでビルドできない
|
2
|
+
// 昔のpdfmeのソースからwebpackのビルドに戻す
|
3
|
+
// 多分tree-shakingは動かないかもしれないけど、とりあえず動くようにするべき
|
1
4
|
// @ts-ignore
|
2
5
|
import PDFJSWorker from 'pdfjs-dist/build/pdf.worker.entry.js';
|
3
6
|
import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist/legacy/build/pdf.js';
|
@@ -234,6 +237,13 @@ const pt2mm = (pt: number) => {
|
|
234
237
|
return parseFloat(String(pt)) * mmRatio;
|
235
238
|
};
|
236
239
|
|
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
|
+
|
237
247
|
export const getPdfPageSizes = async (pdfBlob: Blob) => {
|
238
248
|
const url = URL.createObjectURL(pdfBlob);
|
239
249
|
const pdfDoc = await getDocument({ url }).promise;
|