@embedpdf/utils 1.1.1 → 1.2.1

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.
Files changed (37) hide show
  1. package/dist/preact/adapter.d.ts +1 -0
  2. package/dist/preact/index.cjs +1 -1
  3. package/dist/preact/index.cjs.map +1 -1
  4. package/dist/preact/index.js +683 -2
  5. package/dist/preact/index.js.map +1 -1
  6. package/dist/react/adapter.d.ts +1 -0
  7. package/dist/react/index.cjs +1 -1
  8. package/dist/react/index.cjs.map +1 -1
  9. package/dist/react/index.js +683 -2
  10. package/dist/react/index.js.map +1 -1
  11. package/dist/shared-preact/hooks/index.d.ts +3 -0
  12. package/dist/shared-preact/hooks/use-double-press-props.d.ts +11 -0
  13. package/dist/shared-preact/hooks/use-drag-resize.d.ts +27 -0
  14. package/dist/shared-preact/hooks/use-interaction-handles.d.ts +33 -0
  15. package/dist/shared-preact/index.d.ts +1 -0
  16. package/dist/shared-preact/plugin-interaction-primitives/drag-resize-controller.d.ts +68 -0
  17. package/dist/shared-preact/plugin-interaction-primitives/index.d.ts +2 -0
  18. package/dist/shared-preact/plugin-interaction-primitives/utils.d.ts +22 -0
  19. package/dist/shared-react/hooks/index.d.ts +3 -0
  20. package/dist/shared-react/hooks/use-double-press-props.d.ts +11 -0
  21. package/dist/shared-react/hooks/use-drag-resize.d.ts +27 -0
  22. package/dist/shared-react/hooks/use-interaction-handles.d.ts +33 -0
  23. package/dist/shared-react/index.d.ts +1 -0
  24. package/dist/shared-react/plugin-interaction-primitives/drag-resize-controller.d.ts +68 -0
  25. package/dist/shared-react/plugin-interaction-primitives/index.d.ts +2 -0
  26. package/dist/shared-react/plugin-interaction-primitives/utils.d.ts +22 -0
  27. package/dist/shared-vue/plugin-interaction-primitives/drag-resize-controller.d.ts +68 -0
  28. package/dist/shared-vue/plugin-interaction-primitives/index.d.ts +2 -0
  29. package/dist/shared-vue/plugin-interaction-primitives/utils.d.ts +22 -0
  30. package/dist/vue/hooks/index.d.ts +1 -0
  31. package/dist/vue/hooks/use-drag-resize.d.ts +24 -0
  32. package/dist/vue/index.cjs +1 -1
  33. package/dist/vue/index.cjs.map +1 -1
  34. package/dist/vue/index.d.ts +1 -0
  35. package/dist/vue/index.js +478 -2
  36. package/dist/vue/index.js.map +1 -1
  37. package/package.json +2 -2
@@ -1,7 +1,8 @@
1
1
  import { jsx } from "preact/jsx-runtime";
2
2
  import { getCounterRotation } from "@embedpdf/utils";
3
3
  import { Fragment } from "preact";
4
- import "preact/hooks";
4
+ import { useRef, useEffect, useCallback, useMemo } from "preact/hooks";
5
+ const dblClickProp = "onDblClick";
5
6
  function CounterRotate({ children, ...props }) {
6
7
  const { rect, rotation } = props;
7
8
  const { matrix, width, height } = getCounterRotation(rect, rotation);
@@ -30,7 +31,687 @@ function CounterRotate({ children, ...props }) {
30
31
  }
31
32
  }) });
32
33
  }
34
+ class DragResizeController {
35
+ constructor(config, onUpdate) {
36
+ this.config = config;
37
+ this.onUpdate = onUpdate;
38
+ this.state = "idle";
39
+ this.startPoint = null;
40
+ this.startElement = null;
41
+ this.activeHandle = null;
42
+ this.currentPosition = null;
43
+ this.activeVertexIndex = null;
44
+ this.startVertices = [];
45
+ this.currentVertices = [];
46
+ this.currentVertices = config.vertices || [];
47
+ }
48
+ updateConfig(config) {
49
+ this.config = { ...this.config, ...config };
50
+ this.currentVertices = config.vertices || [];
51
+ }
52
+ startDrag(clientX, clientY) {
53
+ this.state = "dragging";
54
+ this.startPoint = { x: clientX, y: clientY };
55
+ this.startElement = { ...this.config.element };
56
+ this.currentPosition = { ...this.config.element };
57
+ this.onUpdate({
58
+ state: "start",
59
+ transformData: {
60
+ type: "move",
61
+ changes: {
62
+ rect: this.startElement
63
+ }
64
+ }
65
+ });
66
+ }
67
+ startResize(handle, clientX, clientY) {
68
+ this.state = "resizing";
69
+ this.activeHandle = handle;
70
+ this.startPoint = { x: clientX, y: clientY };
71
+ this.startElement = { ...this.config.element };
72
+ this.currentPosition = { ...this.config.element };
73
+ this.onUpdate({
74
+ state: "start",
75
+ transformData: {
76
+ type: "resize",
77
+ changes: {
78
+ rect: this.startElement
79
+ },
80
+ metadata: {
81
+ handle: this.activeHandle,
82
+ maintainAspectRatio: this.config.maintainAspectRatio
83
+ }
84
+ }
85
+ });
86
+ }
87
+ startVertexEdit(vertexIndex, clientX, clientY) {
88
+ this.currentVertices = [...this.config.vertices ?? this.currentVertices];
89
+ if (vertexIndex < 0 || vertexIndex >= this.currentVertices.length) return;
90
+ this.state = "vertex-editing";
91
+ this.activeVertexIndex = vertexIndex;
92
+ this.startPoint = { x: clientX, y: clientY };
93
+ this.startVertices = [...this.currentVertices];
94
+ this.onUpdate({
95
+ state: "start",
96
+ transformData: {
97
+ type: "vertex-edit",
98
+ changes: {
99
+ vertices: this.startVertices
100
+ },
101
+ metadata: {
102
+ vertexIndex
103
+ }
104
+ }
105
+ });
106
+ }
107
+ move(clientX, clientY) {
108
+ if (this.state === "idle" || !this.startPoint) return;
109
+ if (this.state === "dragging" && this.startElement) {
110
+ const delta = this.calculateDelta(clientX, clientY);
111
+ const position = this.calculateDragPosition(delta);
112
+ this.currentPosition = position;
113
+ this.onUpdate({
114
+ state: "move",
115
+ transformData: {
116
+ type: "move",
117
+ changes: {
118
+ rect: position
119
+ }
120
+ }
121
+ });
122
+ } else if (this.state === "resizing" && this.activeHandle && this.startElement) {
123
+ const delta = this.calculateDelta(clientX, clientY);
124
+ const position = this.calculateResizePosition(delta, this.activeHandle);
125
+ this.currentPosition = position;
126
+ this.onUpdate({
127
+ state: "move",
128
+ transformData: {
129
+ type: "resize",
130
+ changes: {
131
+ rect: position
132
+ },
133
+ metadata: {
134
+ handle: this.activeHandle,
135
+ maintainAspectRatio: this.config.maintainAspectRatio
136
+ }
137
+ }
138
+ });
139
+ } else if (this.state === "vertex-editing" && this.activeVertexIndex !== null) {
140
+ const vertices = this.calculateVertexPosition(clientX, clientY);
141
+ this.currentVertices = vertices;
142
+ this.onUpdate({
143
+ state: "move",
144
+ transformData: {
145
+ type: "vertex-edit",
146
+ changes: {
147
+ vertices
148
+ },
149
+ metadata: {
150
+ vertexIndex: this.activeVertexIndex
151
+ }
152
+ }
153
+ });
154
+ }
155
+ }
156
+ end() {
157
+ if (this.state === "idle") return;
158
+ const wasState = this.state;
159
+ const handle = this.activeHandle;
160
+ const vertexIndex = this.activeVertexIndex;
161
+ if (wasState === "vertex-editing") {
162
+ this.onUpdate({
163
+ state: "end",
164
+ transformData: {
165
+ type: "vertex-edit",
166
+ changes: {
167
+ vertices: this.currentVertices
168
+ },
169
+ metadata: {
170
+ vertexIndex: vertexIndex || void 0
171
+ }
172
+ }
173
+ });
174
+ } else {
175
+ const finalPosition = this.getCurrentPosition();
176
+ this.onUpdate({
177
+ state: "end",
178
+ transformData: {
179
+ type: wasState === "dragging" ? "move" : "resize",
180
+ changes: {
181
+ rect: finalPosition
182
+ },
183
+ metadata: wasState === "dragging" ? void 0 : {
184
+ handle: handle || void 0,
185
+ maintainAspectRatio: this.config.maintainAspectRatio
186
+ }
187
+ }
188
+ });
189
+ }
190
+ this.reset();
191
+ }
192
+ cancel() {
193
+ if (this.state === "idle") return;
194
+ if (this.state === "vertex-editing") {
195
+ this.onUpdate({
196
+ state: "end",
197
+ transformData: {
198
+ type: "vertex-edit",
199
+ changes: {
200
+ vertices: this.startVertices
201
+ },
202
+ metadata: {
203
+ vertexIndex: this.activeVertexIndex || void 0
204
+ }
205
+ }
206
+ });
207
+ } else if (this.startElement) {
208
+ this.onUpdate({
209
+ state: "end",
210
+ transformData: {
211
+ type: this.state === "dragging" ? "move" : "resize",
212
+ changes: {
213
+ rect: this.startElement
214
+ },
215
+ metadata: this.state === "dragging" ? void 0 : {
216
+ handle: this.activeHandle || void 0,
217
+ maintainAspectRatio: this.config.maintainAspectRatio
218
+ }
219
+ }
220
+ });
221
+ }
222
+ this.reset();
223
+ }
224
+ reset() {
225
+ this.state = "idle";
226
+ this.startPoint = null;
227
+ this.startElement = null;
228
+ this.activeHandle = null;
229
+ this.currentPosition = null;
230
+ this.activeVertexIndex = null;
231
+ this.startVertices = [];
232
+ }
233
+ getCurrentPosition() {
234
+ return this.currentPosition || this.config.element;
235
+ }
236
+ calculateDelta(clientX, clientY) {
237
+ if (!this.startPoint) return { x: 0, y: 0 };
238
+ const rawDelta = {
239
+ x: clientX - this.startPoint.x,
240
+ y: clientY - this.startPoint.y
241
+ };
242
+ return this.transformDelta(rawDelta);
243
+ }
244
+ transformDelta(delta) {
245
+ const { pageRotation = 0, scale = 1 } = this.config;
246
+ const rad = pageRotation * Math.PI / 2;
247
+ const cos = Math.cos(rad);
248
+ const sin = Math.sin(rad);
249
+ const scaledX = delta.x / scale;
250
+ const scaledY = delta.y / scale;
251
+ return {
252
+ x: cos * scaledX + sin * scaledY,
253
+ y: -sin * scaledX + cos * scaledY
254
+ };
255
+ }
256
+ clampPoint(p) {
257
+ var _a;
258
+ const bbox = (_a = this.config.constraints) == null ? void 0 : _a.boundingBox;
259
+ if (!bbox) return p;
260
+ return {
261
+ x: Math.max(0, Math.min(p.x, bbox.width)),
262
+ y: Math.max(0, Math.min(p.y, bbox.height))
263
+ };
264
+ }
265
+ calculateVertexPosition(clientX, clientY) {
266
+ if (this.activeVertexIndex === null) return this.startVertices;
267
+ const delta = this.calculateDelta(clientX, clientY);
268
+ const newVertices = [...this.startVertices];
269
+ const currentVertex = newVertices[this.activeVertexIndex];
270
+ const moved = {
271
+ x: currentVertex.x + delta.x,
272
+ y: currentVertex.y + delta.y
273
+ };
274
+ newVertices[this.activeVertexIndex] = this.clampPoint(moved);
275
+ return newVertices;
276
+ }
277
+ calculateDragPosition(delta) {
278
+ if (!this.startElement) return this.config.element;
279
+ const position = {
280
+ origin: {
281
+ x: this.startElement.origin.x + delta.x,
282
+ y: this.startElement.origin.y + delta.y
283
+ },
284
+ size: {
285
+ width: this.startElement.size.width,
286
+ height: this.startElement.size.height
287
+ }
288
+ };
289
+ return this.applyConstraints(position);
290
+ }
291
+ calculateResizePosition(delta, handle) {
292
+ var _a;
293
+ if (!this.startElement) return this.config.element;
294
+ let {
295
+ origin: { x, y },
296
+ size: { width, height }
297
+ } = this.startElement;
298
+ switch (handle) {
299
+ case "se":
300
+ width += delta.x;
301
+ height += delta.y;
302
+ break;
303
+ case "sw":
304
+ x += delta.x;
305
+ width -= delta.x;
306
+ height += delta.y;
307
+ break;
308
+ case "ne":
309
+ width += delta.x;
310
+ y += delta.y;
311
+ height -= delta.y;
312
+ break;
313
+ case "nw":
314
+ x += delta.x;
315
+ width -= delta.x;
316
+ y += delta.y;
317
+ height -= delta.y;
318
+ break;
319
+ case "n":
320
+ y += delta.y;
321
+ height -= delta.y;
322
+ break;
323
+ case "s":
324
+ height += delta.y;
325
+ break;
326
+ case "e":
327
+ width += delta.x;
328
+ break;
329
+ case "w":
330
+ x += delta.x;
331
+ width -= delta.x;
332
+ break;
333
+ }
334
+ if (this.config.maintainAspectRatio && this.startElement) {
335
+ const aspectRatio = this.startElement.size.width / this.startElement.size.height;
336
+ if (["n", "s", "e", "w"].includes(handle)) {
337
+ if (handle === "n" || handle === "s") {
338
+ const newWidth = height * aspectRatio;
339
+ const widthDiff = newWidth - width;
340
+ width = newWidth;
341
+ x -= widthDiff / 2;
342
+ } else {
343
+ const newHeight = width / aspectRatio;
344
+ const heightDiff = newHeight - height;
345
+ height = newHeight;
346
+ if (handle === "w") {
347
+ x = this.startElement.origin.x + this.startElement.size.width - width;
348
+ }
349
+ y -= heightDiff / 2;
350
+ }
351
+ } else {
352
+ const widthChange = Math.abs(width - this.startElement.size.width);
353
+ const heightChange = Math.abs(height - this.startElement.size.height);
354
+ if (widthChange > heightChange) {
355
+ height = width / aspectRatio;
356
+ } else {
357
+ width = height * aspectRatio;
358
+ }
359
+ if (handle.includes("w")) {
360
+ x = this.startElement.origin.x + this.startElement.size.width - width;
361
+ }
362
+ if (handle.includes("n")) {
363
+ y = this.startElement.origin.y + this.startElement.size.height - height;
364
+ }
365
+ }
366
+ }
367
+ const bbox = (_a = this.config.constraints) == null ? void 0 : _a.boundingBox;
368
+ if (bbox) {
369
+ switch (handle) {
370
+ case "e":
371
+ width = Math.min(width, bbox.width - x);
372
+ break;
373
+ case "s":
374
+ height = Math.min(height, bbox.height - y);
375
+ break;
376
+ case "se":
377
+ width = Math.min(width, bbox.width - x);
378
+ height = Math.min(height, bbox.height - y);
379
+ break;
380
+ case "w":
381
+ if (x < 0) {
382
+ width += x;
383
+ x = 0;
384
+ }
385
+ break;
386
+ case "n":
387
+ if (y < 0) {
388
+ height += y;
389
+ y = 0;
390
+ }
391
+ break;
392
+ case "sw":
393
+ if (x < 0) {
394
+ width += x;
395
+ x = 0;
396
+ }
397
+ height = Math.min(height, bbox.height - y);
398
+ break;
399
+ case "nw":
400
+ if (x < 0) {
401
+ width += x;
402
+ x = 0;
403
+ }
404
+ if (y < 0) {
405
+ height += y;
406
+ y = 0;
407
+ }
408
+ break;
409
+ case "ne":
410
+ width = Math.min(width, bbox.width - x);
411
+ if (y < 0) {
412
+ height += y;
413
+ y = 0;
414
+ }
415
+ break;
416
+ }
417
+ }
418
+ return this.applyConstraints({ origin: { x, y }, size: { width, height } });
419
+ }
420
+ applyConstraints(position) {
421
+ const { constraints } = this.config;
422
+ if (!constraints) return position;
423
+ let {
424
+ origin: { x, y },
425
+ size: { width, height }
426
+ } = position;
427
+ width = Math.max(constraints.minWidth || 1, width);
428
+ height = Math.max(constraints.minHeight || 1, height);
429
+ if (constraints.maxWidth) width = Math.min(constraints.maxWidth, width);
430
+ if (constraints.maxHeight) height = Math.min(constraints.maxHeight, height);
431
+ if (constraints.boundingBox) {
432
+ x = Math.max(0, Math.min(x, constraints.boundingBox.width - width));
433
+ y = Math.max(0, Math.min(y, constraints.boundingBox.height - height));
434
+ }
435
+ return { origin: { x, y }, size: { width, height } };
436
+ }
437
+ }
438
+ function diagonalCursor(handle, rot) {
439
+ const diag0 = {
440
+ nw: "nwse-resize",
441
+ ne: "nesw-resize",
442
+ sw: "nesw-resize",
443
+ se: "nwse-resize"
444
+ };
445
+ if (handle === "n" || handle === "s") return "ns-resize";
446
+ if (handle === "e" || handle === "w") return "ew-resize";
447
+ if (rot % 2 === 0) return diag0[handle];
448
+ return { nw: "nesw-resize", ne: "nwse-resize", sw: "nwse-resize", se: "nesw-resize" }[handle];
449
+ }
450
+ function edgeOffset(k, spacing, mode) {
451
+ const base = -k / 2;
452
+ if (mode === "center") return base;
453
+ return mode === "outside" ? base - spacing : base + spacing;
454
+ }
455
+ function describeResizeFromConfig(cfg, ui = {}) {
456
+ const {
457
+ handleSize = 8,
458
+ spacing = 1,
459
+ offsetMode = "outside",
460
+ includeSides = false,
461
+ zIndex = 3,
462
+ rotationAwareCursor = true
463
+ } = ui;
464
+ const rotation = (cfg.pageRotation ?? 0) % 4;
465
+ const off = (edge) => ({
466
+ [edge]: edgeOffset(handleSize, spacing, offsetMode)
467
+ });
468
+ const corners = [
469
+ ["nw", { ...off("top"), ...off("left") }],
470
+ ["ne", { ...off("top"), ...off("right") }],
471
+ ["sw", { ...off("bottom"), ...off("left") }],
472
+ ["se", { ...off("bottom"), ...off("right") }]
473
+ ];
474
+ const sides = includeSides ? [
475
+ ["n", { ...off("top"), left: `calc(50% - ${handleSize / 2}px)` }],
476
+ ["s", { ...off("bottom"), left: `calc(50% - ${handleSize / 2}px)` }],
477
+ ["w", { ...off("left"), top: `calc(50% - ${handleSize / 2}px)` }],
478
+ ["e", { ...off("right"), top: `calc(50% - ${handleSize / 2}px)` }]
479
+ ] : [];
480
+ const all = [...corners, ...sides];
481
+ return all.map(([handle, pos]) => ({
482
+ handle,
483
+ style: {
484
+ position: "absolute",
485
+ width: handleSize,
486
+ height: handleSize,
487
+ borderRadius: "50%",
488
+ zIndex,
489
+ cursor: rotationAwareCursor ? diagonalCursor(handle, rotation) : "default",
490
+ touchAction: "none",
491
+ ...pos
492
+ },
493
+ attrs: { "data-epdf-handle": handle }
494
+ }));
495
+ }
496
+ function describeVerticesFromConfig(cfg, ui = {}, liveVertices) {
497
+ const { vertexSize = 12, zIndex = 4 } = ui;
498
+ const rect = cfg.element;
499
+ const scale = cfg.scale ?? 1;
500
+ const verts = liveVertices ?? cfg.vertices ?? [];
501
+ return verts.map((v, i) => {
502
+ const left = (v.x - rect.origin.x) * scale - vertexSize / 2;
503
+ const top = (v.y - rect.origin.y) * scale - vertexSize / 2;
504
+ return {
505
+ handle: "nw",
506
+ // not used; kept for type
507
+ style: {
508
+ position: "absolute",
509
+ left,
510
+ top,
511
+ width: vertexSize,
512
+ height: vertexSize,
513
+ borderRadius: "50%",
514
+ cursor: "pointer",
515
+ zIndex,
516
+ touchAction: "none"
517
+ },
518
+ attrs: { "data-epdf-vertex": i }
519
+ };
520
+ });
521
+ }
522
+ function useDragResize(options) {
523
+ const { onUpdate, enabled = true, ...config } = options;
524
+ const controllerRef = useRef(null);
525
+ const onUpdateRef = useRef(onUpdate);
526
+ useEffect(() => {
527
+ onUpdateRef.current = onUpdate;
528
+ }, [onUpdate]);
529
+ useEffect(() => {
530
+ if (!controllerRef.current) {
531
+ controllerRef.current = new DragResizeController(
532
+ config,
533
+ (event) => {
534
+ var _a;
535
+ return (_a = onUpdateRef.current) == null ? void 0 : _a.call(onUpdateRef, event);
536
+ }
537
+ );
538
+ } else {
539
+ controllerRef.current.updateConfig(config);
540
+ }
541
+ }, [
542
+ config.element,
543
+ config.constraints,
544
+ config.maintainAspectRatio,
545
+ config.pageRotation,
546
+ config.scale,
547
+ config.vertices
548
+ ]);
549
+ const handleDragStart = useCallback(
550
+ (e) => {
551
+ var _a;
552
+ if (!enabled) return;
553
+ e.preventDefault();
554
+ e.stopPropagation();
555
+ (_a = controllerRef.current) == null ? void 0 : _a.startDrag(e.clientX, e.clientY);
556
+ e.currentTarget.setPointerCapture(e.pointerId);
557
+ },
558
+ [enabled]
559
+ );
560
+ const handleMove = useCallback((e) => {
561
+ var _a;
562
+ e.preventDefault();
563
+ e.stopPropagation();
564
+ (_a = controllerRef.current) == null ? void 0 : _a.move(e.clientX, e.clientY);
565
+ }, []);
566
+ const handleEnd = useCallback((e) => {
567
+ var _a, _b, _c;
568
+ e.preventDefault();
569
+ e.stopPropagation();
570
+ (_a = controllerRef.current) == null ? void 0 : _a.end();
571
+ (_c = (_b = e.currentTarget).releasePointerCapture) == null ? void 0 : _c.call(_b, e.pointerId);
572
+ }, []);
573
+ const createResizeHandler = useCallback(
574
+ (handle) => ({
575
+ onPointerDown: (e) => {
576
+ var _a;
577
+ if (!enabled) return;
578
+ e.preventDefault();
579
+ e.stopPropagation();
580
+ (_a = controllerRef.current) == null ? void 0 : _a.startResize(handle, e.clientX, e.clientY);
581
+ e.currentTarget.setPointerCapture(e.pointerId);
582
+ },
583
+ onPointerMove: handleMove,
584
+ onPointerUp: handleEnd,
585
+ onPointerCancel: handleEnd
586
+ }),
587
+ [enabled, handleMove, handleEnd]
588
+ );
589
+ const createVertexHandler = useCallback(
590
+ (vertexIndex) => ({
591
+ onPointerDown: (e) => {
592
+ var _a;
593
+ if (!enabled) return;
594
+ e.preventDefault();
595
+ e.stopPropagation();
596
+ (_a = controllerRef.current) == null ? void 0 : _a.startVertexEdit(vertexIndex, e.clientX, e.clientY);
597
+ e.currentTarget.setPointerCapture(e.pointerId);
598
+ },
599
+ onPointerMove: handleMove,
600
+ onPointerUp: handleEnd,
601
+ onPointerCancel: handleEnd
602
+ }),
603
+ [enabled, handleMove, handleEnd]
604
+ );
605
+ return {
606
+ dragProps: enabled ? {
607
+ onPointerDown: handleDragStart,
608
+ onPointerMove: handleMove,
609
+ onPointerUp: handleEnd,
610
+ onPointerCancel: handleEnd
611
+ } : {},
612
+ createResizeProps: createResizeHandler,
613
+ createVertexProps: createVertexHandler
614
+ };
615
+ }
616
+ function useInteractionHandles(opts) {
617
+ const {
618
+ controller,
619
+ resizeUI,
620
+ vertexUI,
621
+ includeVertices = false,
622
+ handleAttrs,
623
+ vertexAttrs
624
+ } = opts;
625
+ const { dragProps, createResizeProps, createVertexProps } = useDragResize(controller);
626
+ const resize = useMemo(() => {
627
+ const desc = describeResizeFromConfig(controller, resizeUI);
628
+ return desc.map((d) => {
629
+ var _a;
630
+ return {
631
+ key: (_a = d.attrs) == null ? void 0 : _a["data-epdf-handle"],
632
+ style: d.style,
633
+ ...createResizeProps(d.handle),
634
+ ...d.attrs ?? {},
635
+ ...(handleAttrs == null ? void 0 : handleAttrs(d.handle)) ?? {}
636
+ };
637
+ });
638
+ }, [
639
+ controller.element.origin.x,
640
+ controller.element.origin.y,
641
+ controller.element.size.width,
642
+ controller.element.size.height,
643
+ controller.scale,
644
+ controller.pageRotation,
645
+ controller.maintainAspectRatio,
646
+ resizeUI == null ? void 0 : resizeUI.handleSize,
647
+ resizeUI == null ? void 0 : resizeUI.spacing,
648
+ resizeUI == null ? void 0 : resizeUI.offsetMode,
649
+ resizeUI == null ? void 0 : resizeUI.includeSides,
650
+ resizeUI == null ? void 0 : resizeUI.zIndex,
651
+ resizeUI == null ? void 0 : resizeUI.rotationAwareCursor,
652
+ createResizeProps,
653
+ handleAttrs
654
+ ]);
655
+ const vertices = useMemo(() => {
656
+ if (!includeVertices) return [];
657
+ const desc = describeVerticesFromConfig(controller, vertexUI, controller.vertices);
658
+ return desc.map((d, i) => ({
659
+ key: i,
660
+ style: d.style,
661
+ ...createVertexProps(i),
662
+ ...d.attrs ?? {},
663
+ ...(vertexAttrs == null ? void 0 : vertexAttrs(i)) ?? {}
664
+ }));
665
+ }, [
666
+ includeVertices,
667
+ controller.element.origin.x,
668
+ controller.element.origin.y,
669
+ controller.element.size.width,
670
+ controller.element.size.height,
671
+ controller.scale,
672
+ controller.vertices,
673
+ // identity/content drives recalculation
674
+ vertexUI == null ? void 0 : vertexUI.vertexSize,
675
+ vertexUI == null ? void 0 : vertexUI.zIndex,
676
+ createVertexProps,
677
+ vertexAttrs
678
+ ]);
679
+ return { dragProps, resize, vertices };
680
+ }
681
+ function useDoublePressProps(onDouble, { delay = 300, tolerancePx = 18 } = {}) {
682
+ const last = useRef({ t: 0, x: 0, y: 0 });
683
+ const handlePointerUp = useCallback(
684
+ (e) => {
685
+ if (!onDouble) return;
686
+ if (e.pointerType === "mouse" || e.isPrimary === false) return;
687
+ const now = performance.now();
688
+ const x = e.clientX;
689
+ const y = e.clientY;
690
+ const withinTime = now - last.current.t <= delay;
691
+ const dx = x - last.current.x;
692
+ const dy = y - last.current.y;
693
+ const withinDist = dx * dx + dy * dy <= tolerancePx * tolerancePx;
694
+ if (withinTime && withinDist) onDouble == null ? void 0 : onDouble(e);
695
+ last.current = { t: now, x, y };
696
+ },
697
+ [onDouble, delay, tolerancePx]
698
+ );
699
+ const handleDouble = useCallback(
700
+ (e) => {
701
+ onDouble == null ? void 0 : onDouble(e);
702
+ },
703
+ [onDouble]
704
+ );
705
+ return onDouble ? {
706
+ // Computed property uses the framework’s name ('onDoubleClick' or 'onDblClick')
707
+ [dblClickProp]: handleDouble,
708
+ onPointerUpCapture: handlePointerUp
709
+ } : {};
710
+ }
33
711
  export {
34
- CounterRotate
712
+ CounterRotate,
713
+ useDoublePressProps,
714
+ useDragResize,
715
+ useInteractionHandles
35
716
  };
36
717
  //# sourceMappingURL=index.js.map