@kne/react-pdf-sign 1.0.1 → 1.0.3

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 CHANGED
@@ -73,24 +73,26 @@ const BaseExample = () => {
73
73
  }}
74
74
  />
75
75
  </Button>
76
- <Button
77
- onClick={() => {
78
- const { size } = ref.current.getLocation();
79
- signatureModal({
80
- mask: (
81
- <Flex justify="flex-end" align="flex-end" style={{ height: '100%', width: '100%', padding: '10px', boxSizing: 'border-box' }}>
82
- 签字日期: {new Date().toLocaleDateString()}
83
- </Flex>
84
- ),
85
- width: size.width,
86
- height: size.height,
87
- onSuccess: file => {
88
- setSign(URL.createObjectURL(file));
89
- }
90
- });
91
- }}>
92
- 添加签名
93
- </Button>
76
+ {pdfFile && (
77
+ <Button
78
+ onClick={() => {
79
+ const { size } = ref.current.getLocation();
80
+ signatureModal({
81
+ mask: (
82
+ <Flex justify="flex-end" align="flex-end" style={{ height: '100%', width: '100%', padding: '10px', boxSizing: 'border-box' }}>
83
+ 签字日期: {new Date().toLocaleDateString()}
84
+ </Flex>
85
+ ),
86
+ width: size.width,
87
+ height: size.height,
88
+ onSuccess: file => {
89
+ setSign(URL.createObjectURL(file));
90
+ }
91
+ });
92
+ }}>
93
+ 添加签名
94
+ </Button>
95
+ )}
94
96
  {pdfFile && sign && (
95
97
  <Button
96
98
  onClick={async () => {
@@ -187,15 +189,15 @@ const BaseExample = () => {
187
189
  onClick={() => {
188
190
  ref.current.setLocation({
189
191
  size: {
190
- width: 200,
191
- height: 50,
192
- x: 240,
193
- y: 47
192
+ width: 390,
193
+ height: 156,
194
+ x: 163,
195
+ y: 8
194
196
  },
195
- scaleX: 1,
196
- scaleY: 1,
197
- x: 240,
198
- y: 47
197
+ scaleX: 1.95,
198
+ scaleY: 1.95,
199
+ x: 163,
200
+ y: 8
199
201
  });
200
202
  }}>
201
203
  设置签名位置
package/dist/index.js CHANGED
@@ -199,7 +199,6 @@ const LocationLayer = withLocale(p => {
199
199
  const [signatureImage] = useImage__default["default"](signature);
200
200
  const groupRef = react.useRef();
201
201
  const signRef = react.useRef();
202
- const targetRef = react.useRef();
203
202
  const transformerRef = react.useRef();
204
203
  const computedSignLocation = () => {
205
204
  const absolutePosition = signRef.current.absolutePosition();
@@ -211,8 +210,8 @@ const LocationLayer = withLocale(p => {
211
210
  x: Math.round(absolutePosition.x),
212
211
  y: Math.round(absolutePosition.y)
213
212
  },
214
- scaleX: Number(transformerRef.current.attrs.scaleX.toFixed(2)),
215
- scaleY: Number(transformerRef.current.attrs.scaleY.toFixed(2)),
213
+ scaleX: Number(groupRef.current.attrs.scaleX.toFixed(2)),
214
+ scaleY: Number(groupRef.current.attrs.scaleY.toFixed(2)),
216
215
  x: Math.round(groupRef.current.attrs.x),
217
216
  y: Math.round(groupRef.current.attrs.y)
218
217
  });
@@ -231,8 +230,8 @@ const LocationLayer = withLocale(p => {
231
230
  y: Math.round((stageHeight - height) / 2)
232
231
  }
233
232
  });
234
- setIsInit(true);
235
233
  }
234
+ setIsInit(true);
236
235
  });
237
236
  const themeColor = react.useMemo(() => {
238
237
  const el = document.createElement('div');
@@ -247,7 +246,7 @@ const LocationLayer = withLocale(p => {
247
246
  }, []);
248
247
  react.useEffect(() => {
249
248
  if (isInit) {
250
- transformerRef.current.nodes([targetRef.current]);
249
+ transformerRef.current.nodes([groupRef.current]);
251
250
  }
252
251
  }, [isInit]);
253
252
  if (!(isInit && value)) {
@@ -263,22 +262,21 @@ const LocationLayer = withLocale(p => {
263
262
  draggable: true,
264
263
  ref: groupRef,
265
264
  onDragEnd: computedSignLocation,
266
- children: [/*#__PURE__*/jsxRuntime.jsx(reactKonva.Group, {
267
- ref: targetRef,
268
- onTransformEnd: computedSignLocation,
269
- children: signatureImage ? /*#__PURE__*/jsxRuntime.jsx(reactKonva.Image, {
270
- width: width,
271
- height: height,
272
- image: signatureImage,
273
- cornerRadius: 8,
274
- ref: signRef
275
- }) : /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
276
- width: width,
277
- height: height,
278
- fill: "#f0f0f0",
279
- cornerRadius: 8,
280
- ref: signRef
281
- })
265
+ scaleX: value.scaleX,
266
+ scaleY: value.scaleY,
267
+ onTransformEnd: computedSignLocation,
268
+ children: [signatureImage ? /*#__PURE__*/jsxRuntime.jsx(reactKonva.Image, {
269
+ width: width,
270
+ height: height,
271
+ image: signatureImage,
272
+ cornerRadius: 8,
273
+ ref: signRef
274
+ }) : /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
275
+ width: width,
276
+ height: height,
277
+ fill: "#f0f0f0",
278
+ cornerRadius: 8,
279
+ ref: signRef
282
280
  }), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Text, {
283
281
  text: signatureImage ? '' : placeholder,
284
282
  fontSize: 16,
@@ -290,9 +288,6 @@ const LocationLayer = withLocale(p => {
290
288
  height: height
291
289
  })]
292
290
  }), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Transformer, {
293
- scaleX: value.scaleX,
294
- scaleY: value.scaleY,
295
- centeredScaling: true,
296
291
  ref: transformerRef,
297
292
  keepRatio: true,
298
293
  flipEnabled: false,