@pdfme/ui 1.1.6 → 1.1.7

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.
@@ -1,11 +1,5 @@
1
1
  import React from 'react';
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;
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) & tgtFunc;
22
- onDragGroupEnd: ((e: OnDragGroupEnd) => void) & tgtsFunc;
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) & 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;
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>>;
@@ -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.1.6",
3
+ "version": "1.1.7",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
@@ -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) & tgtFunc;
26
- onDragGroupEnd: ((e: OnDragGroupEnd) => void) & tgtsFunc;
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) & 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
-
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 }) => events.forEach(onDrag)}
64
+ onDragGroup={({ events }) => {
65
+ events.forEach(onDrag);
66
+ }}
77
67
  onDragEnd={onDragEnd}
78
68
  onDragGroupEnd={onDragGroupEnd}
79
69
  onResize={onResize}
80
- onResizeGroup={({ events }) => events.forEach(onResize)}
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, OnRotate, OnClick } from 'react-moveable';
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 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);
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 }) => px2Num(style.top)));
33
- const left = Math.max(...aes.map(({ style }) => px2Num(style.left) + px2Num(style.width))) + 10;
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: fmtPx(top), schemaId: target.id },
156
- { key: 'position.x', value: fmtPx(left), schemaId: target.id },
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: fmtPx(top), schemaId: id },
163
- { key: 'position.x', value: fmtPx(left), schemaId: id },
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: 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 },
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: 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 },
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 = px2Num(s.left) + (px2Num(s.width) - width);
193
- const newTop = px2Num(s.top) + (px2Num(s.height) - height);
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
  };
@@ -37,7 +37,6 @@ const Wrapper = ({
37
37
  width: schema.width * ZOOM,
38
38
  top: schema.position.y * ZOOM,
39
39
  left: schema.position.x * ZOOM,
40
- transform: `rotate(${schema.rotate || 0}deg)`,
41
40
  border,
42
41
  }}
43
42
  >
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;