@haklex/rich-renderer-mermaid 0.0.2 → 0.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.
Files changed (2) hide show
  1. package/dist/index.mjs +10 -1838
  2. package/package.json +7 -10
package/dist/index.mjs CHANGED
@@ -1,1837 +1,9 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useColorScheme } from "@haklex/rich-editor";
3
3
  import { usePortalTheme, presentDialog } from "@haklex/rich-editor-ui";
4
- import React, { forwardRef, createElement, useRef, useImperativeHandle, useEffect, useContext, useState, useId, useCallback } from "react";
5
- const mergeClasses = (...classes) => classes.filter((className, index, array) => {
6
- return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
7
- }).join(" ").trim();
8
- const toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
9
- const toCamelCase = (string) => string.replace(
10
- /^([A-Z])|[\s-_]+(\w)/g,
11
- (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase()
12
- );
13
- const toPascalCase = (string) => {
14
- const camelCase = toCamelCase(string);
15
- return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
16
- };
17
- var defaultAttributes = {
18
- xmlns: "http://www.w3.org/2000/svg",
19
- width: 24,
20
- height: 24,
21
- viewBox: "0 0 24 24",
22
- fill: "none",
23
- stroke: "currentColor",
24
- strokeWidth: 2,
25
- strokeLinecap: "round",
26
- strokeLinejoin: "round"
27
- };
28
- const hasA11yProp = (props) => {
29
- for (const prop in props) {
30
- if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
31
- return true;
32
- }
33
- }
34
- return false;
35
- };
36
- const Icon = forwardRef(
37
- ({
38
- color = "currentColor",
39
- size = 24,
40
- strokeWidth = 2,
41
- absoluteStrokeWidth,
42
- className = "",
43
- children,
44
- iconNode,
45
- ...rest
46
- }, ref) => createElement(
47
- "svg",
48
- {
49
- ref,
50
- ...defaultAttributes,
51
- width: size,
52
- height: size,
53
- stroke: color,
54
- strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
55
- className: mergeClasses("lucide", className),
56
- ...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
57
- ...rest
58
- },
59
- [
60
- ...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),
61
- ...Array.isArray(children) ? children : [children]
62
- ]
63
- )
64
- );
65
- const createLucideIcon = (iconName, iconNode) => {
66
- const Component = forwardRef(
67
- ({ className, ...props }, ref) => createElement(Icon, {
68
- ref,
69
- iconNode,
70
- className: mergeClasses(
71
- `lucide-${toKebabCase(toPascalCase(iconName))}`,
72
- `lucide-${iconName}`,
73
- className
74
- ),
75
- ...props
76
- })
77
- );
78
- Component.displayName = toPascalCase(iconName);
79
- return Component;
80
- };
81
- const __iconNode$b = [
82
- ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
83
- ["line", { x1: "12", x2: "12", y1: "8", y2: "12", key: "1pkeuh" }],
84
- ["line", { x1: "12", x2: "12.01", y1: "16", y2: "16", key: "4dfq90" }]
85
- ];
86
- const CircleAlert = createLucideIcon("circle-alert", __iconNode$b);
87
- const __iconNode$a = [
88
- ["path", { d: "m18 16 4-4-4-4", key: "1inbqp" }],
89
- ["path", { d: "m6 8-4 4 4 4", key: "15zrgr" }],
90
- ["path", { d: "m14.5 4-5 16", key: "e7oirm" }]
91
- ];
92
- const CodeXml = createLucideIcon("code-xml", __iconNode$a);
93
- const __iconNode$9 = [
94
- ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", key: "afitv7" }],
95
- ["path", { d: "M12 3v18", key: "108xh3" }]
96
- ];
97
- const Columns2 = createLucideIcon("columns-2", __iconNode$9);
98
- const __iconNode$8 = [
99
- ["rect", { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2", key: "17jyea" }],
100
- ["path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2", key: "zix9uf" }]
101
- ];
102
- const Copy = createLucideIcon("copy", __iconNode$8);
103
- const __iconNode$7 = [
104
- ["path", { d: "M12 15V3", key: "m9g1x1" }],
105
- ["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", key: "ih7n3h" }],
106
- ["path", { d: "m7 10 5 5 5-5", key: "brsn70" }]
107
- ];
108
- const Download = createLucideIcon("download", __iconNode$7);
109
- const __iconNode$6 = [
110
- [
111
- "path",
112
- {
113
- d: "M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",
114
- key: "1nclc0"
115
- }
116
- ],
117
- ["circle", { cx: "12", cy: "12", r: "3", key: "1v7zrd" }]
118
- ];
119
- const Eye = createLucideIcon("eye", __iconNode$6);
120
- const __iconNode$5 = [
121
- ["path", { d: "M2 16s9-15 20-4C11 23 2 8 2 8", key: "h4oh4o" }]
122
- ];
123
- const FishSymbol = createLucideIcon("fish-symbol", __iconNode$5);
124
- const __iconNode$4 = [
125
- ["path", { d: "M15 3h6v6", key: "1q9fwt" }],
126
- ["path", { d: "m21 3-7 7", key: "1l2asr" }],
127
- ["path", { d: "m3 21 7-7", key: "tjx5ai" }],
128
- ["path", { d: "M9 21H3v-6", key: "wtvkvv" }]
129
- ];
130
- const Maximize2 = createLucideIcon("maximize-2", __iconNode$4);
131
- const __iconNode$3 = [
132
- ["path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8", key: "1357e3" }],
133
- ["path", { d: "M3 3v5h5", key: "1xhq8a" }]
134
- ];
135
- const RotateCcw = createLucideIcon("rotate-ccw", __iconNode$3);
136
- const __iconNode$2 = [
137
- ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
138
- ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
139
- ];
140
- const X = createLucideIcon("x", __iconNode$2);
141
- const __iconNode$1 = [
142
- ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
143
- ["line", { x1: "21", x2: "16.65", y1: "21", y2: "16.65", key: "13gj7c" }],
144
- ["line", { x1: "11", x2: "11", y1: "8", y2: "14", key: "1vmskp" }],
145
- ["line", { x1: "8", x2: "14", y1: "11", y2: "11", key: "durymu" }]
146
- ];
147
- const ZoomIn = createLucideIcon("zoom-in", __iconNode$1);
148
- const __iconNode = [
149
- ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
150
- ["line", { x1: "21", x2: "16.65", y1: "21", y2: "16.65", key: "13gj7c" }],
151
- ["line", { x1: "8", x2: "14", y1: "11", y2: "11", key: "durymu" }]
152
- ];
153
- const ZoomOut = createLucideIcon("zoom-out", __iconNode);
154
- var roundNumber = function(num, decimal) {
155
- return Number(num.toFixed(decimal));
156
- };
157
- var checkIsNumber = function(num, defaultValue) {
158
- return defaultValue;
159
- };
160
- var handleCallback = function(context, event, callback) {
161
- if (callback && typeof callback === "function") {
162
- callback(context, event);
163
- }
164
- };
165
- var easeOut = function(t) {
166
- return -Math.cos(t * Math.PI) / 2 + 0.5;
167
- };
168
- var linear = function(t) {
169
- return t;
170
- };
171
- var easeInQuad = function(t) {
172
- return t * t;
173
- };
174
- var easeOutQuad = function(t) {
175
- return t * (2 - t);
176
- };
177
- var easeInOutQuad = function(t) {
178
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
179
- };
180
- var easeInCubic = function(t) {
181
- return t * t * t;
182
- };
183
- var easeOutCubic = function(t) {
184
- return --t * t * t + 1;
185
- };
186
- var easeInOutCubic = function(t) {
187
- return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
188
- };
189
- var easeInQuart = function(t) {
190
- return t * t * t * t;
191
- };
192
- var easeOutQuart = function(t) {
193
- return 1 - --t * t * t * t;
194
- };
195
- var easeInOutQuart = function(t) {
196
- return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
197
- };
198
- var easeInQuint = function(t) {
199
- return t * t * t * t * t;
200
- };
201
- var easeOutQuint = function(t) {
202
- return 1 + --t * t * t * t * t;
203
- };
204
- var easeInOutQuint = function(t) {
205
- return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
206
- };
207
- var animations = {
208
- easeOut,
209
- linear,
210
- easeInQuad,
211
- easeOutQuad,
212
- easeInOutQuad,
213
- easeInCubic,
214
- easeOutCubic,
215
- easeInOutCubic,
216
- easeInQuart,
217
- easeOutQuart,
218
- easeInOutQuart,
219
- easeInQuint,
220
- easeOutQuint,
221
- easeInOutQuint
222
- };
223
- var handleCancelAnimationFrame = function(animation) {
224
- if (typeof animation === "number") {
225
- cancelAnimationFrame(animation);
226
- }
227
- };
228
- var handleCancelAnimation = function(contextInstance) {
229
- if (!contextInstance.mounted)
230
- return;
231
- handleCancelAnimationFrame(contextInstance.animation);
232
- contextInstance.animate = false;
233
- contextInstance.animation = null;
234
- contextInstance.velocity = null;
235
- };
236
- function handleSetupAnimation(contextInstance, animationName, animationTime, callback) {
237
- if (!contextInstance.mounted)
238
- return;
239
- var startTime = (/* @__PURE__ */ new Date()).getTime();
240
- var lastStep = 1;
241
- handleCancelAnimation(contextInstance);
242
- contextInstance.animation = function() {
243
- if (!contextInstance.mounted) {
244
- return handleCancelAnimationFrame(contextInstance.animation);
245
- }
246
- var frameTime = (/* @__PURE__ */ new Date()).getTime() - startTime;
247
- var animationProgress = frameTime / animationTime;
248
- var animationType = animations[animationName];
249
- var step = animationType(animationProgress);
250
- if (frameTime >= animationTime) {
251
- callback(lastStep);
252
- contextInstance.animation = null;
253
- } else if (contextInstance.animation) {
254
- callback(step);
255
- requestAnimationFrame(contextInstance.animation);
256
- }
257
- };
258
- requestAnimationFrame(contextInstance.animation);
259
- }
260
- function isValidTargetState(targetState) {
261
- var scale = targetState.scale, positionX = targetState.positionX, positionY = targetState.positionY;
262
- if (Number.isNaN(scale) || Number.isNaN(positionX) || Number.isNaN(positionY)) {
263
- return false;
264
- }
265
- return true;
266
- }
267
- function animate(contextInstance, targetState, animationTime, animationName) {
268
- var isValid = isValidTargetState(targetState);
269
- if (!contextInstance.mounted || !isValid)
270
- return;
271
- var setTransformState = contextInstance.setTransformState;
272
- var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
273
- var scaleDiff = targetState.scale - scale;
274
- var positionXDiff = targetState.positionX - positionX;
275
- var positionYDiff = targetState.positionY - positionY;
276
- if (animationTime === 0) {
277
- setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
278
- } else {
279
- handleSetupAnimation(contextInstance, animationName, animationTime, function(step) {
280
- var newScale = scale + scaleDiff * step;
281
- var newPositionX = positionX + positionXDiff * step;
282
- var newPositionY = positionY + positionYDiff * step;
283
- setTransformState(newScale, newPositionX, newPositionY);
284
- });
285
- }
286
- }
287
- function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
288
- var wrapperWidth = wrapperComponent.offsetWidth;
289
- var wrapperHeight = wrapperComponent.offsetHeight;
290
- var contentWidth = contentComponent.offsetWidth;
291
- var contentHeight = contentComponent.offsetHeight;
292
- var newContentWidth = contentWidth * newScale;
293
- var newContentHeight = contentHeight * newScale;
294
- var newDiffWidth = wrapperWidth - newContentWidth;
295
- var newDiffHeight = wrapperHeight - newContentHeight;
296
- return {
297
- wrapperWidth,
298
- wrapperHeight,
299
- newContentWidth,
300
- newDiffWidth,
301
- newContentHeight,
302
- newDiffHeight
303
- };
304
- }
305
- var getBounds = function(wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight, centerZoomedOut) {
306
- var scaleWidthFactor = wrapperWidth > newContentWidth ? diffWidth * (centerZoomedOut ? 1 : 0.5) : 0;
307
- var scaleHeightFactor = wrapperHeight > newContentHeight ? diffHeight * (centerZoomedOut ? 1 : 0.5) : 0;
308
- var minPositionX = wrapperWidth - newContentWidth - scaleWidthFactor;
309
- var maxPositionX = scaleWidthFactor;
310
- var minPositionY = wrapperHeight - newContentHeight - scaleHeightFactor;
311
- var maxPositionY = scaleHeightFactor;
312
- return { minPositionX, maxPositionX, minPositionY, maxPositionY };
313
- };
314
- var calculateBounds = function(contextInstance, newScale) {
315
- var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
316
- var centerZoomedOut = contextInstance.setup.centerZoomedOut;
317
- if (!wrapperComponent || !contentComponent) {
318
- throw new Error("Components are not mounted");
319
- }
320
- var _a = getComponentsSizes(wrapperComponent, contentComponent, newScale), wrapperWidth = _a.wrapperWidth, wrapperHeight = _a.wrapperHeight, newContentWidth = _a.newContentWidth, newDiffWidth = _a.newDiffWidth, newContentHeight = _a.newContentHeight, newDiffHeight = _a.newDiffHeight;
321
- var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
322
- return bounds;
323
- };
324
- var boundLimiter = function(value, minBound, maxBound, isActive) {
325
- if (!isActive)
326
- return roundNumber(value, 2);
327
- if (value < minBound)
328
- return roundNumber(minBound, 2);
329
- if (value > maxBound)
330
- return roundNumber(maxBound, 2);
331
- return roundNumber(value, 2);
332
- };
333
- var handleCalculateBounds = function(contextInstance, newScale) {
334
- var bounds = calculateBounds(contextInstance, newScale);
335
- contextInstance.bounds = bounds;
336
- return bounds;
337
- };
338
- function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent) {
339
- var minPositionX = bounds.minPositionX, minPositionY = bounds.minPositionY, maxPositionX = bounds.maxPositionX, maxPositionY = bounds.maxPositionY;
340
- var paddingX = 0;
341
- var paddingY = 0;
342
- if (wrapperComponent) {
343
- paddingX = paddingValueX;
344
- paddingY = paddingValueY;
345
- }
346
- var x = boundLimiter(positionX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
347
- var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
348
- return { x, y };
349
- }
350
- function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds) {
351
- var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
352
- var scaleDifference = newScale - scale;
353
- if (typeof mouseX !== "number" || typeof mouseY !== "number") {
354
- console.error("Mouse X and Y position were not provided!");
355
- return { x: positionX, y: positionY };
356
- }
357
- var calculatedPositionX = positionX - mouseX * scaleDifference;
358
- var calculatedPositionY = positionY - mouseY * scaleDifference;
359
- var newPositions = getMouseBoundedPosition(calculatedPositionX, calculatedPositionY, bounds, limitToBounds, 0, 0, null);
360
- return newPositions;
361
- }
362
- function checkZoomBounds(zoom, minScale, maxScale, zoomPadding, enablePadding) {
363
- var scalePadding = enablePadding ? zoomPadding : 0;
364
- var minScaleWithPadding = minScale - scalePadding;
365
- if (!Number.isNaN(maxScale) && zoom >= maxScale)
366
- return maxScale;
367
- if (!Number.isNaN(minScale) && zoom <= minScaleWithPadding)
368
- return minScaleWithPadding;
369
- return zoom;
370
- }
371
- var isPanningStartAllowed = function(contextInstance, event) {
372
- var excluded = contextInstance.setup.panning.excluded;
373
- var isInitialized = contextInstance.isInitialized, wrapperComponent = contextInstance.wrapperComponent;
374
- var target = event.target;
375
- var targetIsShadowDom = "shadowRoot" in target && "composedPath" in event;
376
- var isWrapperChild = targetIsShadowDom ? event.composedPath().some(function(el) {
377
- if (!(el instanceof Element)) {
378
- return false;
379
- }
380
- return wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(el);
381
- }) : wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
382
- var isAllowed = isInitialized && target && isWrapperChild;
383
- if (!isAllowed)
384
- return false;
385
- var isExcluded = isExcludedNode(target, excluded);
386
- if (isExcluded)
387
- return false;
388
- return true;
389
- };
390
- var isPanningAllowed = function(contextInstance) {
391
- var isInitialized = contextInstance.isInitialized, isPanning = contextInstance.isPanning, setup = contextInstance.setup;
392
- var disabled = setup.panning.disabled;
393
- var isAllowed = isInitialized && isPanning && !disabled;
394
- if (!isAllowed)
395
- return false;
396
- return true;
397
- };
398
- var handlePanningSetup = function(contextInstance, event) {
399
- var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY;
400
- contextInstance.isPanning = true;
401
- var x = event.clientX;
402
- var y = event.clientY;
403
- contextInstance.startCoords = { x: x - positionX, y: y - positionY };
404
- };
405
- var handleTouchPanningSetup = function(contextInstance, event) {
406
- var touches = event.touches;
407
- var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY;
408
- contextInstance.isPanning = true;
409
- var oneFingerTouch = touches.length === 1;
410
- if (oneFingerTouch) {
411
- var x = touches[0].clientX;
412
- var y = touches[0].clientY;
413
- contextInstance.startCoords = { x: x - positionX, y: y - positionY };
414
- }
415
- };
416
- function handlePanToBounds(contextInstance) {
417
- var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
418
- var _b = contextInstance.setup, disabled = _b.disabled, limitToBounds = _b.limitToBounds, centerZoomedOut = _b.centerZoomedOut;
419
- var wrapperComponent = contextInstance.wrapperComponent;
420
- if (disabled || !wrapperComponent || !contextInstance.bounds)
421
- return;
422
- var _c = contextInstance.bounds, maxPositionX = _c.maxPositionX, minPositionX = _c.minPositionX, maxPositionY = _c.maxPositionY, minPositionY = _c.minPositionY;
423
- var xChanged = positionX > maxPositionX || positionX < minPositionX;
424
- var yChanged = positionY > maxPositionY || positionY < minPositionY;
425
- var mousePosX = positionX > maxPositionX ? wrapperComponent.offsetWidth : contextInstance.setup.minPositionX || 0;
426
- var mousePosY = positionY > maxPositionY ? wrapperComponent.offsetHeight : contextInstance.setup.minPositionY || 0;
427
- var _d = handleCalculateZoomPositions(contextInstance, mousePosX, mousePosY, scale, contextInstance.bounds, limitToBounds || centerZoomedOut), x = _d.x, y = _d.y;
428
- return {
429
- scale,
430
- positionX: xChanged ? x : positionX,
431
- positionY: yChanged ? y : positionY
432
- };
433
- }
434
- function handleNewPosition(contextInstance, newPositionX, newPositionY, paddingValueX, paddingValueY) {
435
- var limitToBounds = contextInstance.setup.limitToBounds;
436
- var wrapperComponent = contextInstance.wrapperComponent, bounds = contextInstance.bounds;
437
- var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
438
- if (wrapperComponent === null || bounds === null || newPositionX === positionX && newPositionY === positionY) {
439
- return;
440
- }
441
- var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent), x = _b.x, y = _b.y;
442
- contextInstance.setTransformState(scale, x, y);
443
- }
444
- var getPanningClientPosition = function(contextInstance, clientX, clientY) {
445
- var startCoords = contextInstance.startCoords, transformState = contextInstance.transformState;
446
- var panning = contextInstance.setup.panning;
447
- var lockAxisX = panning.lockAxisX, lockAxisY = panning.lockAxisY;
448
- var positionX = transformState.positionX, positionY = transformState.positionY;
449
- if (!startCoords) {
450
- return { x: positionX, y: positionY };
451
- }
452
- var mouseX = clientX - startCoords.x;
453
- var mouseY = clientY - startCoords.y;
454
- var newPositionX = lockAxisX ? positionX : mouseX;
455
- var newPositionY = lockAxisY ? positionY : mouseY;
456
- return { x: newPositionX, y: newPositionY };
457
- };
458
- var getPaddingValue = function(contextInstance, size) {
459
- var setup = contextInstance.setup, transformState = contextInstance.transformState;
460
- var scale = transformState.scale;
461
- var minScale = setup.minScale, disablePadding = setup.disablePadding;
462
- if (size > 0 && scale >= minScale && !disablePadding) {
463
- return size;
464
- }
465
- return 0;
466
- };
467
- var isVelocityCalculationAllowed = function(contextInstance) {
468
- var mounted = contextInstance.mounted;
469
- var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
470
- var scale = contextInstance.transformState.scale;
471
- var disabledVelocity = velocityAnimation.disabled;
472
- var isAllowed = !disabledVelocity || scale > 1 || !disabled || mounted;
473
- if (!isAllowed)
474
- return false;
475
- return true;
476
- };
477
- var isVelocityAllowed = function(contextInstance) {
478
- var mounted = contextInstance.mounted, velocity = contextInstance.velocity, bounds = contextInstance.bounds;
479
- var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
480
- var scale = contextInstance.transformState.scale;
481
- var disabledVelocity = velocityAnimation.disabled;
482
- var isAllowed = !disabledVelocity || scale > 1 || !disabled || mounted;
483
- if (!isAllowed)
484
- return false;
485
- if (!velocity || !bounds)
486
- return false;
487
- return true;
488
- };
489
- function getVelocityMoveTime(contextInstance, velocity) {
490
- var velocityAnimation = contextInstance.setup.velocityAnimation;
491
- var equalToMove = velocityAnimation.equalToMove, animationTime = velocityAnimation.animationTime, sensitivity = velocityAnimation.sensitivity;
492
- if (equalToMove) {
493
- return animationTime * velocity * sensitivity;
494
- }
495
- return animationTime;
496
- }
497
- function getVelocityPosition(newPosition, startPosition, currentPosition, isLocked, limitToBounds, minPosition, maxPosition, minTarget, maxTarget, step) {
498
- if (limitToBounds) {
499
- if (startPosition > maxPosition && currentPosition > maxPosition) {
500
- var calculatedPosition = maxPosition + (newPosition - maxPosition) * step;
501
- if (calculatedPosition > maxTarget)
502
- return maxTarget;
503
- if (calculatedPosition < maxPosition)
504
- return maxPosition;
505
- return calculatedPosition;
506
- }
507
- if (startPosition < minPosition && currentPosition < minPosition) {
508
- var calculatedPosition = minPosition + (newPosition - minPosition) * step;
509
- if (calculatedPosition < minTarget)
510
- return minTarget;
511
- if (calculatedPosition > minPosition)
512
- return minPosition;
513
- return calculatedPosition;
514
- }
515
- }
516
- if (isLocked)
517
- return startPosition;
518
- return boundLimiter(newPosition, minPosition, maxPosition, limitToBounds);
519
- }
520
- function getSizeMultiplier(wrapperComponent, equalToMove) {
521
- var defaultMultiplier = 1;
522
- if (equalToMove) {
523
- return Math.min(defaultMultiplier, wrapperComponent.offsetWidth / window.innerWidth);
524
- }
525
- return defaultMultiplier;
526
- }
527
- function handleCalculateVelocity(contextInstance, position) {
528
- var isAllowed = isVelocityCalculationAllowed(contextInstance);
529
- if (!isAllowed) {
530
- return;
531
- }
532
- var lastMousePosition = contextInstance.lastMousePosition, velocityTime = contextInstance.velocityTime, setup = contextInstance.setup;
533
- var wrapperComponent = contextInstance.wrapperComponent;
534
- var equalToMove = setup.velocityAnimation.equalToMove;
535
- var now = Date.now();
536
- if (lastMousePosition && velocityTime && wrapperComponent) {
537
- var sizeMultiplier = getSizeMultiplier(wrapperComponent, equalToMove);
538
- var distanceX = position.x - lastMousePosition.x;
539
- var distanceY = position.y - lastMousePosition.y;
540
- var velocityX = distanceX / sizeMultiplier;
541
- var velocityY = distanceY / sizeMultiplier;
542
- var interval = now - velocityTime;
543
- var speed = distanceX * distanceX + distanceY * distanceY;
544
- var velocity = Math.sqrt(speed) / interval;
545
- contextInstance.velocity = { velocityX, velocityY, total: velocity };
546
- }
547
- contextInstance.lastMousePosition = position;
548
- contextInstance.velocityTime = now;
549
- }
550
- function handleVelocityPanning(contextInstance) {
551
- var velocity = contextInstance.velocity, bounds = contextInstance.bounds, setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
552
- var isAllowed = isVelocityAllowed(contextInstance);
553
- if (!isAllowed || !velocity || !bounds || !wrapperComponent) {
554
- return;
555
- }
556
- var velocityX = velocity.velocityX, velocityY = velocity.velocityY, total = velocity.total;
557
- var maxPositionX = bounds.maxPositionX, minPositionX = bounds.minPositionX, maxPositionY = bounds.maxPositionY, minPositionY = bounds.minPositionY;
558
- var limitToBounds = setup.limitToBounds, alignmentAnimation = setup.alignmentAnimation;
559
- var zoomAnimation = setup.zoomAnimation, panning = setup.panning;
560
- var lockAxisY = panning.lockAxisY, lockAxisX = panning.lockAxisX;
561
- var animationType = zoomAnimation.animationType;
562
- var sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, velocityAlignmentTime = alignmentAnimation.velocityAlignmentTime;
563
- var alignAnimationTime = velocityAlignmentTime;
564
- var moveAnimationTime = getVelocityMoveTime(contextInstance, total);
565
- var finalAnimationTime = Math.max(moveAnimationTime, alignAnimationTime);
566
- var paddingValueX = getPaddingValue(contextInstance, sizeX);
567
- var paddingValueY = getPaddingValue(contextInstance, sizeY);
568
- var paddingX = paddingValueX * wrapperComponent.offsetWidth / 100;
569
- var paddingY = paddingValueY * wrapperComponent.offsetHeight / 100;
570
- var maxTargetX = maxPositionX + paddingX;
571
- var minTargetX = minPositionX - paddingX;
572
- var maxTargetY = maxPositionY + paddingY;
573
- var minTargetY = minPositionY - paddingY;
574
- var startState = contextInstance.transformState;
575
- var startTime = (/* @__PURE__ */ new Date()).getTime();
576
- handleSetupAnimation(contextInstance, animationType, finalAnimationTime, function(step) {
577
- var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
578
- var frameTime = (/* @__PURE__ */ new Date()).getTime() - startTime;
579
- var animationProgress = frameTime / alignAnimationTime;
580
- var alignAnimation = animations[alignmentAnimation.animationType];
581
- var alignStep = 1 - alignAnimation(Math.min(1, animationProgress));
582
- var customStep = 1 - step;
583
- var newPositionX = positionX + velocityX * customStep;
584
- var newPositionY = positionY + velocityY * customStep;
585
- var currentPositionX = getVelocityPosition(newPositionX, startState.positionX, positionX, lockAxisX, limitToBounds, minPositionX, maxPositionX, minTargetX, maxTargetX, alignStep);
586
- var currentPositionY = getVelocityPosition(newPositionY, startState.positionY, positionY, lockAxisY, limitToBounds, minPositionY, maxPositionY, minTargetY, maxTargetY, alignStep);
587
- if (positionX !== newPositionX || positionY !== newPositionY) {
588
- contextInstance.setTransformState(scale, currentPositionX, currentPositionY);
589
- }
590
- });
591
- }
592
- function handlePanningStart(contextInstance, event) {
593
- var scale = contextInstance.transformState.scale;
594
- handleCancelAnimation(contextInstance);
595
- handleCalculateBounds(contextInstance, scale);
596
- if (window.TouchEvent !== void 0 && event instanceof TouchEvent) {
597
- handleTouchPanningSetup(contextInstance, event);
598
- } else {
599
- handlePanningSetup(contextInstance, event);
600
- }
601
- }
602
- function handleAlignToBounds(contextInstance, customAnimationTime) {
603
- var scale = contextInstance.transformState.scale;
604
- var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
605
- var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
606
- var isDisabled = disabled || scale < minScale || !sizeX && !sizeY;
607
- if (isDisabled)
608
- return;
609
- var targetState = handlePanToBounds(contextInstance);
610
- if (targetState) {
611
- animate(contextInstance, targetState, customAnimationTime !== null && customAnimationTime !== void 0 ? customAnimationTime : animationTime, animationType);
612
- }
613
- }
614
- function handlePanning(contextInstance, clientX, clientY) {
615
- var startCoords = contextInstance.startCoords, setup = contextInstance.setup;
616
- var _a = setup.alignmentAnimation, sizeX = _a.sizeX, sizeY = _a.sizeY;
617
- if (!startCoords)
618
- return;
619
- var _b = getPanningClientPosition(contextInstance, clientX, clientY), x = _b.x, y = _b.y;
620
- var paddingValueX = getPaddingValue(contextInstance, sizeX);
621
- var paddingValueY = getPaddingValue(contextInstance, sizeY);
622
- handleCalculateVelocity(contextInstance, { x, y });
623
- handleNewPosition(contextInstance, x, y, paddingValueX, paddingValueY);
624
- }
625
- function handlePanningEnd(contextInstance) {
626
- if (contextInstance.isPanning) {
627
- var velocityDisabled = contextInstance.setup.panning.velocityDisabled;
628
- var velocity = contextInstance.velocity, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
629
- contextInstance.isPanning = false;
630
- contextInstance.animate = false;
631
- contextInstance.animation = null;
632
- var wrapperRect = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.getBoundingClientRect();
633
- var contentRect = contentComponent === null || contentComponent === void 0 ? void 0 : contentComponent.getBoundingClientRect();
634
- var wrapperWidth = (wrapperRect === null || wrapperRect === void 0 ? void 0 : wrapperRect.width) || 0;
635
- var wrapperHeight = (wrapperRect === null || wrapperRect === void 0 ? void 0 : wrapperRect.height) || 0;
636
- var contentWidth = (contentRect === null || contentRect === void 0 ? void 0 : contentRect.width) || 0;
637
- var contentHeight = (contentRect === null || contentRect === void 0 ? void 0 : contentRect.height) || 0;
638
- var isZoomed = wrapperWidth < contentWidth || wrapperHeight < contentHeight;
639
- var shouldAnimate = !velocityDisabled && velocity && (velocity === null || velocity === void 0 ? void 0 : velocity.total) > 0.1 && isZoomed;
640
- if (shouldAnimate) {
641
- handleVelocityPanning(contextInstance);
642
- } else {
643
- handleAlignToBounds(contextInstance);
644
- }
645
- }
646
- }
647
- function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
648
- var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds;
649
- var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, 0, false);
650
- var bounds = handleCalculateBounds(contextInstance, newScale);
651
- var _b = handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds), x = _b.x, y = _b.y;
652
- return { scale: newScale, positionX: x, positionY: y };
653
- }
654
- function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePositionY) {
655
- var scale = contextInstance.transformState.scale;
656
- var wrapperComponent = contextInstance.wrapperComponent;
657
- var _a = contextInstance.setup, minScale = _a.minScale, limitToBounds = _a.limitToBounds, zoomAnimation = _a.zoomAnimation;
658
- var disabled = zoomAnimation.disabled, animationTime = zoomAnimation.animationTime, animationType = zoomAnimation.animationType;
659
- var isDisabled = disabled || scale >= minScale;
660
- if (scale >= 1 || limitToBounds) {
661
- handleAlignToBounds(contextInstance);
662
- }
663
- if (isDisabled || !wrapperComponent || !contextInstance.mounted)
664
- return;
665
- var mouseX = mousePositionX || wrapperComponent.offsetWidth / 2;
666
- var mouseY = mousePositionY || wrapperComponent.offsetHeight / 2;
667
- var targetState = handleZoomToPoint(contextInstance, minScale, mouseX, mouseY);
668
- if (targetState) {
669
- animate(contextInstance, targetState, animationTime, animationType);
670
- }
671
- }
672
- var __assign = function() {
673
- __assign = Object.assign || function __assign2(t) {
674
- for (var s, i = 1, n = arguments.length; i < n; i++) {
675
- s = arguments[i];
676
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
677
- }
678
- return t;
679
- };
680
- return __assign.apply(this, arguments);
681
- };
682
- function __spreadArray(to, from, pack) {
683
- for (var i = 0, l = from.length, ar; i < l; i++) {
684
- if (ar || !(i in from)) {
685
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
686
- ar[i] = from[i];
687
- }
688
- }
689
- return to.concat(ar || Array.prototype.slice.call(from));
690
- }
691
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
692
- var e = new Error(message);
693
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
694
- };
695
- var initialState = {
696
- scale: 1,
697
- positionX: 0,
698
- positionY: 0
699
- };
700
- var initialSetup = {
701
- disabled: false,
702
- minPositionX: null,
703
- maxPositionX: null,
704
- minPositionY: null,
705
- maxPositionY: null,
706
- minScale: 1,
707
- maxScale: 8,
708
- limitToBounds: true,
709
- centerZoomedOut: false,
710
- centerOnInit: false,
711
- disablePadding: false,
712
- smooth: true,
713
- wheel: {
714
- step: 0.2,
715
- disabled: false,
716
- smoothStep: 1e-3,
717
- wheelDisabled: false,
718
- touchPadDisabled: false,
719
- activationKeys: [],
720
- excluded: []
721
- },
722
- panning: {
723
- disabled: false,
724
- velocityDisabled: false,
725
- lockAxisX: false,
726
- lockAxisY: false,
727
- allowLeftClickPan: true,
728
- allowMiddleClickPan: true,
729
- allowRightClickPan: true,
730
- wheelPanning: false,
731
- activationKeys: [],
732
- excluded: []
733
- },
734
- pinch: {
735
- step: 5,
736
- disabled: false,
737
- excluded: []
738
- },
739
- doubleClick: {
740
- disabled: false,
741
- step: 0.7,
742
- mode: "zoomIn",
743
- animationType: "easeOut",
744
- animationTime: 200,
745
- excluded: []
746
- },
747
- zoomAnimation: {
748
- disabled: false,
749
- size: 0.4,
750
- animationTime: 200,
751
- animationType: "easeOut"
752
- },
753
- alignmentAnimation: {
754
- disabled: false,
755
- sizeX: 100,
756
- sizeY: 100,
757
- animationTime: 200,
758
- velocityAlignmentTime: 400,
759
- animationType: "easeOut"
760
- },
761
- velocityAnimation: {
762
- disabled: false,
763
- sensitivity: 1,
764
- animationTime: 400,
765
- animationType: "easeOut",
766
- equalToMove: true
767
- }
768
- };
769
- var baseClasses = {
770
- wrapperClass: "react-transform-wrapper",
771
- contentClass: "react-transform-component"
772
- };
773
- var createState = function(props) {
774
- var _a, _b, _c, _d;
775
- return {
776
- previousScale: (_a = props.initialScale) !== null && _a !== void 0 ? _a : initialState.scale,
777
- scale: (_b = props.initialScale) !== null && _b !== void 0 ? _b : initialState.scale,
778
- positionX: (_c = props.initialPositionX) !== null && _c !== void 0 ? _c : initialState.positionX,
779
- positionY: (_d = props.initialPositionY) !== null && _d !== void 0 ? _d : initialState.positionY
780
- };
781
- };
782
- var createSetup = function(props) {
783
- var newSetup = __assign({}, initialSetup);
784
- Object.keys(props).forEach(function(key) {
785
- var validValue = typeof props[key] !== "undefined";
786
- var validParameter = typeof initialSetup[key] !== "undefined";
787
- if (validParameter && validValue) {
788
- var dataType = Object.prototype.toString.call(initialSetup[key]);
789
- var isObject = dataType === "[object Object]";
790
- var isArray = dataType === "[object Array]";
791
- if (isObject) {
792
- newSetup[key] = __assign(__assign({}, initialSetup[key]), props[key]);
793
- } else if (isArray) {
794
- newSetup[key] = __spreadArray(__spreadArray([], initialSetup[key], true), props[key]);
795
- } else {
796
- newSetup[key] = props[key];
797
- }
798
- }
799
- });
800
- return newSetup;
801
- };
802
- var handleCalculateButtonZoom = function(contextInstance, delta, step) {
803
- var scale = contextInstance.transformState.scale;
804
- var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
805
- var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, smooth = setup.smooth;
806
- var size = zoomAnimation.size;
807
- if (!wrapperComponent) {
808
- throw new Error("Wrapper is not mounted");
809
- }
810
- var targetScale = smooth ? scale * Math.exp(delta * step) : scale + delta * step;
811
- var newScale = checkZoomBounds(roundNumber(targetScale, 3), minScale, maxScale, size, false);
812
- return newScale;
813
- };
814
- function handleZoomToViewCenter(contextInstance, delta, step, animationTime, animationType) {
815
- var wrapperComponent = contextInstance.wrapperComponent;
816
- var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
817
- if (!wrapperComponent)
818
- return console.error("No WrapperComponent found");
819
- var wrapperWidth = wrapperComponent.offsetWidth;
820
- var wrapperHeight = wrapperComponent.offsetHeight;
821
- var mouseX = (wrapperWidth / 2 - positionX) / scale;
822
- var mouseY = (wrapperHeight / 2 - positionY) / scale;
823
- var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
824
- var targetState = handleZoomToPoint(contextInstance, newScale, mouseX, mouseY);
825
- if (!targetState) {
826
- return console.error("Error during zoom event. New transformation state was not calculated.");
827
- }
828
- animate(contextInstance, targetState, animationTime, animationType);
829
- }
830
- function resetTransformations(contextInstance, animationTime, animationType, onResetTransformation) {
831
- var setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
832
- var limitToBounds = setup.limitToBounds;
833
- var initialTransformation = createState(contextInstance.props);
834
- var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
835
- if (!wrapperComponent)
836
- return;
837
- var newBounds = calculateBounds(contextInstance, initialTransformation.scale);
838
- var boundedPositions = getMouseBoundedPosition(initialTransformation.positionX, initialTransformation.positionY, newBounds, limitToBounds, 0, 0, wrapperComponent);
839
- var newState = {
840
- scale: initialTransformation.scale,
841
- positionX: boundedPositions.x,
842
- positionY: boundedPositions.y
843
- };
844
- if (scale === initialTransformation.scale && positionX === initialTransformation.positionX && positionY === initialTransformation.positionY) {
845
- return;
846
- }
847
- onResetTransformation === null || onResetTransformation === void 0 ? void 0 : onResetTransformation();
848
- animate(contextInstance, newState, animationTime, animationType);
849
- }
850
- function getOffset(element, wrapper, content, state) {
851
- var offset = element.getBoundingClientRect();
852
- var wrapperOffset = wrapper.getBoundingClientRect();
853
- var contentOffset = content.getBoundingClientRect();
854
- var xOff = wrapperOffset.x * state.scale;
855
- var yOff = wrapperOffset.y * state.scale;
856
- return {
857
- x: (offset.x - contentOffset.x + xOff) / state.scale,
858
- y: (offset.y - contentOffset.y + yOff) / state.scale
859
- };
860
- }
861
- function calculateZoomToNode(contextInstance, node, customZoom) {
862
- var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent, transformState = contextInstance.transformState;
863
- var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
864
- if (!wrapperComponent || !contentComponent)
865
- return transformState;
866
- var wrapperRect = wrapperComponent.getBoundingClientRect();
867
- var nodeRect = node.getBoundingClientRect();
868
- var nodeOffset = getOffset(node, wrapperComponent, contentComponent, transformState);
869
- var nodeLeft = nodeOffset.x;
870
- var nodeTop = nodeOffset.y;
871
- var nodeWidth = nodeRect.width / transformState.scale;
872
- var nodeHeight = nodeRect.height / transformState.scale;
873
- var scaleX = wrapperComponent.offsetWidth / nodeWidth;
874
- var scaleY = wrapperComponent.offsetHeight / nodeHeight;
875
- var newScale = checkZoomBounds(customZoom || Math.min(scaleX, scaleY), minScale, maxScale, 0, false);
876
- var offsetX = (wrapperRect.width - nodeWidth * newScale) / 2;
877
- var offsetY = (wrapperRect.height - nodeHeight * newScale) / 2;
878
- var newPositionX = (wrapperRect.left - nodeLeft) * newScale + offsetX;
879
- var newPositionY = (wrapperRect.top - nodeTop) * newScale + offsetY;
880
- var bounds = calculateBounds(contextInstance, newScale);
881
- var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
882
- return { positionX: x, positionY: y, scale: newScale };
883
- }
884
- var zoomIn = function(contextInstance) {
885
- return function(step, animationTime, animationType) {
886
- if (step === void 0) {
887
- step = 0.5;
888
- }
889
- if (animationTime === void 0) {
890
- animationTime = 300;
891
- }
892
- if (animationType === void 0) {
893
- animationType = "easeOut";
894
- }
895
- handleZoomToViewCenter(contextInstance, 1, step, animationTime, animationType);
896
- };
897
- };
898
- var zoomOut = function(contextInstance) {
899
- return function(step, animationTime, animationType) {
900
- if (step === void 0) {
901
- step = 0.5;
902
- }
903
- if (animationTime === void 0) {
904
- animationTime = 300;
905
- }
906
- if (animationType === void 0) {
907
- animationType = "easeOut";
908
- }
909
- handleZoomToViewCenter(contextInstance, -1, step, animationTime, animationType);
910
- };
911
- };
912
- var setTransform = function(contextInstance) {
913
- return function(newPositionX, newPositionY, newScale, animationTime, animationType) {
914
- if (animationTime === void 0) {
915
- animationTime = 300;
916
- }
917
- if (animationType === void 0) {
918
- animationType = "easeOut";
919
- }
920
- var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
921
- var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
922
- var disabled = contextInstance.setup.disabled;
923
- if (disabled || !wrapperComponent || !contentComponent)
924
- return;
925
- var targetState = {
926
- positionX: Number.isNaN(newPositionX) ? positionX : newPositionX,
927
- positionY: Number.isNaN(newPositionY) ? positionY : newPositionY,
928
- scale: Number.isNaN(newScale) ? scale : newScale
929
- };
930
- animate(contextInstance, targetState, animationTime, animationType);
931
- };
932
- };
933
- var resetTransform = function(contextInstance) {
934
- return function(animationTime, animationType) {
935
- if (animationTime === void 0) {
936
- animationTime = 200;
937
- }
938
- if (animationType === void 0) {
939
- animationType = "easeOut";
940
- }
941
- resetTransformations(contextInstance, animationTime, animationType);
942
- };
943
- };
944
- var centerView = function(contextInstance) {
945
- return function(scale, animationTime, animationType) {
946
- if (animationTime === void 0) {
947
- animationTime = 200;
948
- }
949
- if (animationType === void 0) {
950
- animationType = "easeOut";
951
- }
952
- var transformState = contextInstance.transformState, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
953
- if (wrapperComponent && contentComponent) {
954
- var targetState = getCenterPosition(scale || transformState.scale, wrapperComponent, contentComponent);
955
- animate(contextInstance, targetState, animationTime, animationType);
956
- }
957
- };
958
- };
959
- var zoomToElement = function(contextInstance) {
960
- return function(node, scale, animationTime, animationType) {
961
- if (animationTime === void 0) {
962
- animationTime = 600;
963
- }
964
- if (animationType === void 0) {
965
- animationType = "easeOut";
966
- }
967
- handleCancelAnimation(contextInstance);
968
- var wrapperComponent = contextInstance.wrapperComponent;
969
- var target = typeof node === "string" ? document.getElementById(node) : node;
970
- if (wrapperComponent && target && wrapperComponent.contains(target)) {
971
- var targetState = calculateZoomToNode(contextInstance, target, scale);
972
- animate(contextInstance, targetState, animationTime, animationType);
973
- }
974
- };
975
- };
976
- var getControls = function(contextInstance) {
977
- return {
978
- instance: contextInstance,
979
- zoomIn: zoomIn(contextInstance),
980
- zoomOut: zoomOut(contextInstance),
981
- setTransform: setTransform(contextInstance),
982
- resetTransform: resetTransform(contextInstance),
983
- centerView: centerView(contextInstance),
984
- zoomToElement: zoomToElement(contextInstance)
985
- };
986
- };
987
- var getState = function(contextInstance) {
988
- return {
989
- instance: contextInstance,
990
- state: contextInstance.transformState
991
- };
992
- };
993
- var getContext = function(contextInstance) {
994
- var ref = {};
995
- Object.assign(ref, getState(contextInstance));
996
- Object.assign(ref, getControls(contextInstance));
997
- return ref;
998
- };
999
- var passiveSupported = false;
1000
- function makePassiveEventOption() {
1001
- try {
1002
- var options = {
1003
- get passive() {
1004
- passiveSupported = true;
1005
- return false;
1006
- }
1007
- };
1008
- return options;
1009
- } catch (err) {
1010
- passiveSupported = false;
1011
- return passiveSupported;
1012
- }
1013
- }
1014
- var matchPrefix = ".".concat(baseClasses.wrapperClass);
1015
- var isExcludedNode = function(node, excluded) {
1016
- return excluded.some(function(exclude) {
1017
- return node.matches("".concat(matchPrefix, " ").concat(exclude, ", ").concat(matchPrefix, " .").concat(exclude, ", ").concat(matchPrefix, " ").concat(exclude, " *, ").concat(matchPrefix, " .").concat(exclude, " *"));
1018
- });
1019
- };
1020
- var cancelTimeout = function(timeout) {
1021
- if (timeout) {
1022
- clearTimeout(timeout);
1023
- }
1024
- };
1025
- var getTransformStyles = function(x, y, scale) {
1026
- return "translate(".concat(x, "px, ").concat(y, "px) scale(").concat(scale, ")");
1027
- };
1028
- var getCenterPosition = function(scale, wrapperComponent, contentComponent) {
1029
- var contentWidth = contentComponent.offsetWidth * scale;
1030
- var contentHeight = contentComponent.offsetHeight * scale;
1031
- var centerPositionX = (wrapperComponent.offsetWidth - contentWidth) / 2;
1032
- var centerPositionY = (wrapperComponent.offsetHeight - contentHeight) / 2;
1033
- return {
1034
- scale,
1035
- positionX: centerPositionX,
1036
- positionY: centerPositionY
1037
- };
1038
- };
1039
- function mergeRefs(refs) {
1040
- return function(value) {
1041
- refs.forEach(function(ref) {
1042
- if (typeof ref === "function") {
1043
- ref(value);
1044
- } else if (ref != null) {
1045
- ref.current = value;
1046
- }
1047
- });
1048
- };
1049
- }
1050
- var isWheelAllowed = function(contextInstance, event) {
1051
- var _a = contextInstance.setup.wheel, disabled = _a.disabled, wheelDisabled = _a.wheelDisabled, touchPadDisabled = _a.touchPadDisabled, excluded = _a.excluded;
1052
- var isInitialized = contextInstance.isInitialized, isPanning = contextInstance.isPanning;
1053
- var target = event.target;
1054
- var isAllowed = isInitialized && !isPanning && !disabled && target;
1055
- if (!isAllowed)
1056
- return false;
1057
- if (wheelDisabled && !event.ctrlKey)
1058
- return false;
1059
- if (touchPadDisabled && event.ctrlKey)
1060
- return false;
1061
- var isExcluded = isExcludedNode(target, excluded);
1062
- if (isExcluded)
1063
- return false;
1064
- return true;
1065
- };
1066
- var getDeltaY = function(event) {
1067
- if (event) {
1068
- return event.deltaY < 0 ? 1 : -1;
1069
- }
1070
- return 0;
1071
- };
1072
- function getDelta(event, customDelta) {
1073
- var deltaY = getDeltaY(event);
1074
- var delta = checkIsNumber(customDelta, deltaY);
1075
- return delta;
1076
- }
1077
- function getMousePosition(event, contentComponent, scale) {
1078
- var contentRect = contentComponent.getBoundingClientRect();
1079
- var mouseX = 0;
1080
- var mouseY = 0;
1081
- if ("clientX" in event) {
1082
- mouseX = (event.clientX - contentRect.left) / scale;
1083
- mouseY = (event.clientY - contentRect.top) / scale;
1084
- } else {
1085
- var touch = event.touches[0];
1086
- mouseX = (touch.clientX - contentRect.left) / scale;
1087
- mouseY = (touch.clientY - contentRect.top) / scale;
1088
- }
1089
- if (Number.isNaN(mouseX) || Number.isNaN(mouseY))
1090
- console.error("No mouse or touch offset found");
1091
- return {
1092
- x: mouseX,
1093
- y: mouseY
1094
- };
1095
- }
1096
- var handleCalculateWheelZoom = function(contextInstance, delta, step, disable, getTarget) {
1097
- var scale = contextInstance.transformState.scale;
1098
- var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
1099
- var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, disablePadding = setup.disablePadding;
1100
- var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
1101
- if (!wrapperComponent) {
1102
- throw new Error("Wrapper is not mounted");
1103
- }
1104
- var targetScale = scale + delta * step;
1105
- var paddingEnabled = disable ? false : !disabled;
1106
- var newScale = checkZoomBounds(roundNumber(targetScale, 3), minScale, maxScale, size, paddingEnabled && !disablePadding);
1107
- return newScale;
1108
- };
1109
- var handleWheelZoomStop = function(contextInstance, event) {
1110
- var previousWheelEvent = contextInstance.previousWheelEvent;
1111
- var scale = contextInstance.transformState.scale;
1112
- var _a = contextInstance.setup, maxScale = _a.maxScale, minScale = _a.minScale;
1113
- if (!previousWheelEvent)
1114
- return false;
1115
- if (scale < maxScale || scale > minScale)
1116
- return true;
1117
- if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
1118
- return true;
1119
- if (previousWheelEvent.deltaY > 0 && previousWheelEvent.deltaY < event.deltaY)
1120
- return true;
1121
- if (previousWheelEvent.deltaY < 0 && previousWheelEvent.deltaY > event.deltaY)
1122
- return true;
1123
- if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
1124
- return true;
1125
- return false;
1126
- };
1127
- var isPinchStartAllowed = function(contextInstance, event) {
1128
- var _a = contextInstance.setup.pinch, disabled = _a.disabled, excluded = _a.excluded;
1129
- var isInitialized = contextInstance.isInitialized;
1130
- var target = event.target;
1131
- var isAllowed = isInitialized && !disabled && target;
1132
- if (!isAllowed)
1133
- return false;
1134
- var isExcluded = isExcludedNode(target, excluded);
1135
- if (isExcluded)
1136
- return false;
1137
- return true;
1138
- };
1139
- var isPinchAllowed = function(contextInstance) {
1140
- var disabled = contextInstance.setup.pinch.disabled;
1141
- var isInitialized = contextInstance.isInitialized, pinchStartDistance = contextInstance.pinchStartDistance;
1142
- var isAllowed = isInitialized && !disabled && pinchStartDistance;
1143
- if (!isAllowed)
1144
- return false;
1145
- return true;
1146
- };
1147
- var calculateTouchMidPoint = function(event, scale, contentComponent) {
1148
- var contentRect = contentComponent.getBoundingClientRect();
1149
- var touches = event.touches;
1150
- var firstPointX = roundNumber(touches[0].clientX - contentRect.left, 5);
1151
- var firstPointY = roundNumber(touches[0].clientY - contentRect.top, 5);
1152
- var secondPointX = roundNumber(touches[1].clientX - contentRect.left, 5);
1153
- var secondPointY = roundNumber(touches[1].clientY - contentRect.top, 5);
1154
- return {
1155
- x: (firstPointX + secondPointX) / 2 / scale,
1156
- y: (firstPointY + secondPointY) / 2 / scale
1157
- };
1158
- };
1159
- var getTouchDistance = function(event) {
1160
- return Math.sqrt(Math.pow(event.touches[0].pageX - event.touches[1].pageX, 2) + Math.pow(event.touches[0].pageY - event.touches[1].pageY, 2));
1161
- };
1162
- var calculatePinchZoom = function(contextInstance, currentDistance) {
1163
- var pinchStartScale = contextInstance.pinchStartScale, pinchStartDistance = contextInstance.pinchStartDistance, setup = contextInstance.setup;
1164
- var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, disablePadding = setup.disablePadding;
1165
- var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
1166
- if (!pinchStartScale || pinchStartDistance === null || !currentDistance) {
1167
- throw new Error("Pinch touches distance was not provided");
1168
- }
1169
- if (currentDistance < 0) {
1170
- return contextInstance.transformState.scale;
1171
- }
1172
- var touchProportion = currentDistance / pinchStartDistance;
1173
- var scaleDifference = touchProportion * pinchStartScale;
1174
- return checkZoomBounds(roundNumber(scaleDifference, 2), minScale, maxScale, size, !disabled && !disablePadding);
1175
- };
1176
- var wheelStopEventTime = 160;
1177
- var wheelAnimationTime = 100;
1178
- var handleWheelStart = function(contextInstance, event) {
1179
- var _a = contextInstance.props, onWheelStart = _a.onWheelStart, onZoomStart = _a.onZoomStart;
1180
- if (!contextInstance.wheelStopEventTimer) {
1181
- handleCancelAnimation(contextInstance);
1182
- handleCallback(getContext(contextInstance), event, onWheelStart);
1183
- handleCallback(getContext(contextInstance), event, onZoomStart);
1184
- }
1185
- };
1186
- var handleWheelZoom = function(contextInstance, event) {
1187
- var _a = contextInstance.props, onWheel = _a.onWheel, onZoom = _a.onZoom;
1188
- var contentComponent = contextInstance.contentComponent, setup = contextInstance.setup, transformState = contextInstance.transformState;
1189
- var scale = transformState.scale;
1190
- var limitToBounds = setup.limitToBounds, centerZoomedOut = setup.centerZoomedOut, zoomAnimation = setup.zoomAnimation, wheel = setup.wheel, disablePadding = setup.disablePadding, smooth = setup.smooth;
1191
- var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
1192
- var step = wheel.step, smoothStep = wheel.smoothStep;
1193
- if (!contentComponent) {
1194
- throw new Error("Component not mounted");
1195
- }
1196
- event.preventDefault();
1197
- event.stopPropagation();
1198
- var delta = getDelta(event, null);
1199
- var zoomStep = smooth ? smoothStep * Math.abs(event.deltaY) : step;
1200
- var newScale = handleCalculateWheelZoom(contextInstance, delta, zoomStep, !event.ctrlKey);
1201
- if (scale === newScale)
1202
- return;
1203
- var bounds = handleCalculateBounds(contextInstance, newScale);
1204
- var mousePosition = getMousePosition(event, contentComponent, scale);
1205
- var isPaddingDisabled = disabled || size === 0 || centerZoomedOut || disablePadding;
1206
- var isLimitedToBounds = limitToBounds && isPaddingDisabled;
1207
- var _b = handleCalculateZoomPositions(contextInstance, mousePosition.x, mousePosition.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
1208
- contextInstance.previousWheelEvent = event;
1209
- contextInstance.setTransformState(newScale, x, y);
1210
- handleCallback(getContext(contextInstance), event, onWheel);
1211
- handleCallback(getContext(contextInstance), event, onZoom);
1212
- };
1213
- var handleWheelStop = function(contextInstance, event) {
1214
- var _a = contextInstance.props, onWheelStop = _a.onWheelStop, onZoomStop = _a.onZoomStop;
1215
- cancelTimeout(contextInstance.wheelAnimationTimer);
1216
- contextInstance.wheelAnimationTimer = setTimeout(function() {
1217
- if (!contextInstance.mounted)
1218
- return;
1219
- handleAlignToScaleBounds(contextInstance, event.x, event.y);
1220
- contextInstance.wheelAnimationTimer = null;
1221
- }, wheelAnimationTime);
1222
- var hasStoppedZooming = handleWheelZoomStop(contextInstance, event);
1223
- if (hasStoppedZooming) {
1224
- cancelTimeout(contextInstance.wheelStopEventTimer);
1225
- contextInstance.wheelStopEventTimer = setTimeout(function() {
1226
- if (!contextInstance.mounted)
1227
- return;
1228
- contextInstance.wheelStopEventTimer = null;
1229
- handleCallback(getContext(contextInstance), event, onWheelStop);
1230
- handleCallback(getContext(contextInstance), event, onZoomStop);
1231
- }, wheelStopEventTime);
1232
- }
1233
- };
1234
- var getTouchCenter = function(event) {
1235
- var totalX = 0;
1236
- var totalY = 0;
1237
- for (var i = 0; i < 2; i += 1) {
1238
- totalX += event.touches[i].clientX;
1239
- totalY += event.touches[i].clientY;
1240
- }
1241
- var x = totalX / 2;
1242
- var y = totalY / 2;
1243
- return { x, y };
1244
- };
1245
- var handlePinchStart = function(contextInstance, event) {
1246
- var distance = getTouchDistance(event);
1247
- contextInstance.pinchStartDistance = distance;
1248
- contextInstance.lastDistance = distance;
1249
- contextInstance.pinchStartScale = contextInstance.transformState.scale;
1250
- contextInstance.isPanning = false;
1251
- var center = getTouchCenter(event);
1252
- contextInstance.pinchLastCenterX = center.x;
1253
- contextInstance.pinchLastCenterY = center.y;
1254
- handleCancelAnimation(contextInstance);
1255
- };
1256
- var handlePinchZoom = function(contextInstance, event) {
1257
- var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance, wrapperComponent = contextInstance.wrapperComponent;
1258
- var scale = contextInstance.transformState.scale;
1259
- var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, centerZoomedOut = _a.centerZoomedOut, zoomAnimation = _a.zoomAnimation, alignmentAnimation = _a.alignmentAnimation;
1260
- var disabled = zoomAnimation.disabled, size = zoomAnimation.size;
1261
- if (pinchStartDistance === null || !contentComponent)
1262
- return;
1263
- var midPoint = calculateTouchMidPoint(event, scale, contentComponent);
1264
- if (!Number.isFinite(midPoint.x) || !Number.isFinite(midPoint.y))
1265
- return;
1266
- var currentDistance = getTouchDistance(event);
1267
- var newScale = calculatePinchZoom(contextInstance, currentDistance);
1268
- var center = getTouchCenter(event);
1269
- var panX = center.x - (contextInstance.pinchLastCenterX || 0);
1270
- var panY = center.y - (contextInstance.pinchLastCenterY || 0);
1271
- if (newScale === scale && panX === 0 && panY === 0)
1272
- return;
1273
- contextInstance.pinchLastCenterX = center.x;
1274
- contextInstance.pinchLastCenterY = center.y;
1275
- var bounds = handleCalculateBounds(contextInstance, newScale);
1276
- var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
1277
- var isLimitedToBounds = limitToBounds && isPaddingDisabled;
1278
- var _b = handleCalculateZoomPositions(contextInstance, midPoint.x, midPoint.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
1279
- contextInstance.pinchMidpoint = midPoint;
1280
- contextInstance.lastDistance = currentDistance;
1281
- var sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY;
1282
- var paddingValueX = getPaddingValue(contextInstance, sizeX);
1283
- var paddingValueY = getPaddingValue(contextInstance, sizeY);
1284
- var newPositionX = x + panX;
1285
- var newPositionY = y + panY;
1286
- var _c = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent), finalX = _c.x, finalY = _c.y;
1287
- contextInstance.setTransformState(newScale, finalX, finalY);
1288
- };
1289
- var handlePinchStop = function(contextInstance) {
1290
- var pinchMidpoint = contextInstance.pinchMidpoint;
1291
- contextInstance.velocity = null;
1292
- contextInstance.lastDistance = null;
1293
- contextInstance.pinchMidpoint = null;
1294
- contextInstance.pinchStartScale = null;
1295
- contextInstance.pinchStartDistance = null;
1296
- handleAlignToScaleBounds(contextInstance, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.x, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.y);
1297
- };
1298
- var handleDoubleClickStop = function(contextInstance, event) {
1299
- var onZoomStop = contextInstance.props.onZoomStop;
1300
- var animationTime = contextInstance.setup.doubleClick.animationTime;
1301
- cancelTimeout(contextInstance.doubleClickStopEventTimer);
1302
- contextInstance.doubleClickStopEventTimer = setTimeout(function() {
1303
- contextInstance.doubleClickStopEventTimer = null;
1304
- handleCallback(getContext(contextInstance), event, onZoomStop);
1305
- }, animationTime);
1306
- };
1307
- var handleDoubleClickResetMode = function(contextInstance, event) {
1308
- var _a = contextInstance.props, onZoomStart = _a.onZoomStart, onZoom = _a.onZoom;
1309
- var _b = contextInstance.setup.doubleClick, animationTime = _b.animationTime, animationType = _b.animationType;
1310
- handleCallback(getContext(contextInstance), event, onZoomStart);
1311
- resetTransformations(contextInstance, animationTime, animationType, function() {
1312
- return handleCallback(getContext(contextInstance), event, onZoom);
1313
- });
1314
- handleDoubleClickStop(contextInstance, event);
1315
- };
1316
- function getDoubleClickScale(mode, scale) {
1317
- if (mode === "toggle") {
1318
- return scale === 1 ? 1 : -1;
1319
- }
1320
- return mode === "zoomOut" ? -1 : 1;
1321
- }
1322
- function handleDoubleClick(contextInstance, event) {
1323
- var setup = contextInstance.setup, doubleClickStopEventTimer = contextInstance.doubleClickStopEventTimer, transformState = contextInstance.transformState, contentComponent = contextInstance.contentComponent;
1324
- var scale = transformState.scale;
1325
- var _a = contextInstance.props, onZoomStart = _a.onZoomStart, onZoom = _a.onZoom;
1326
- var _b = setup.doubleClick, disabled = _b.disabled, mode = _b.mode, step = _b.step, animationTime = _b.animationTime, animationType = _b.animationType;
1327
- if (disabled)
1328
- return;
1329
- if (doubleClickStopEventTimer)
1330
- return;
1331
- if (mode === "reset") {
1332
- return handleDoubleClickResetMode(contextInstance, event);
1333
- }
1334
- if (!contentComponent)
1335
- return console.error("No ContentComponent found");
1336
- var delta = getDoubleClickScale(mode, contextInstance.transformState.scale);
1337
- var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
1338
- if (scale === newScale)
1339
- return;
1340
- handleCallback(getContext(contextInstance), event, onZoomStart);
1341
- var mousePosition = getMousePosition(event, contentComponent, scale);
1342
- var targetState = handleZoomToPoint(contextInstance, newScale, mousePosition.x, mousePosition.y);
1343
- if (!targetState) {
1344
- return console.error("Error during zoom event. New transformation state was not calculated.");
1345
- }
1346
- handleCallback(getContext(contextInstance), event, onZoom);
1347
- animate(contextInstance, targetState, animationTime, animationType);
1348
- handleDoubleClickStop(contextInstance, event);
1349
- }
1350
- var isDoubleClickAllowed = function(contextInstance, event) {
1351
- var isInitialized = contextInstance.isInitialized, setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
1352
- var _a = setup.doubleClick, disabled = _a.disabled, excluded = _a.excluded;
1353
- var target = event.target;
1354
- var isWrapperChild = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
1355
- var isAllowed = isInitialized && target && isWrapperChild && !disabled;
1356
- if (!isAllowed)
1357
- return false;
1358
- var isExcluded = isExcludedNode(target, excluded);
1359
- if (isExcluded)
1360
- return false;
1361
- return true;
1362
- };
1363
- var ZoomPanPinch = (
1364
- /** @class */
1365
- /* @__PURE__ */ (function() {
1366
- function ZoomPanPinch2(props) {
1367
- var _this = this;
1368
- this.mounted = true;
1369
- this.pinchLastCenterX = null;
1370
- this.pinchLastCenterY = null;
1371
- this.onChangeCallbacks = /* @__PURE__ */ new Set();
1372
- this.onInitCallbacks = /* @__PURE__ */ new Set();
1373
- this.wrapperComponent = null;
1374
- this.contentComponent = null;
1375
- this.isInitialized = false;
1376
- this.bounds = null;
1377
- this.previousWheelEvent = null;
1378
- this.wheelStopEventTimer = null;
1379
- this.wheelAnimationTimer = null;
1380
- this.isPanning = false;
1381
- this.isWheelPanning = false;
1382
- this.startCoords = null;
1383
- this.lastTouch = null;
1384
- this.distance = null;
1385
- this.lastDistance = null;
1386
- this.pinchStartDistance = null;
1387
- this.pinchStartScale = null;
1388
- this.pinchMidpoint = null;
1389
- this.doubleClickStopEventTimer = null;
1390
- this.velocity = null;
1391
- this.velocityTime = null;
1392
- this.lastMousePosition = null;
1393
- this.animate = false;
1394
- this.animation = null;
1395
- this.maxBounds = null;
1396
- this.pressedKeys = {};
1397
- this.mount = function() {
1398
- _this.initializeWindowEvents();
1399
- };
1400
- this.unmount = function() {
1401
- _this.cleanupWindowEvents();
1402
- };
1403
- this.update = function(newProps) {
1404
- _this.props = newProps;
1405
- handleCalculateBounds(_this, _this.transformState.scale);
1406
- _this.setup = createSetup(newProps);
1407
- };
1408
- this.initializeWindowEvents = function() {
1409
- var _a, _b;
1410
- var passive = makePassiveEventOption();
1411
- var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
1412
- var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
1413
- (_b = _this.wrapperComponent) === null || _b === void 0 ? void 0 : _b.addEventListener("wheel", _this.onWheelPanning, passive);
1414
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousedown", _this.onPanningStart, passive);
1415
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousemove", _this.onPanning, passive);
1416
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mouseup", _this.onPanningStop, passive);
1417
- currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.addEventListener("mouseleave", _this.clearPanning, passive);
1418
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keyup", _this.setKeyUnPressed, passive);
1419
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keydown", _this.setKeyPressed, passive);
1420
- };
1421
- this.cleanupWindowEvents = function() {
1422
- var _a, _b;
1423
- var passive = makePassiveEventOption();
1424
- var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
1425
- var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
1426
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("mousedown", _this.onPanningStart, passive);
1427
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("mousemove", _this.onPanning, passive);
1428
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("mouseup", _this.onPanningStop, passive);
1429
- currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.removeEventListener("mouseleave", _this.clearPanning, passive);
1430
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("keyup", _this.setKeyUnPressed, passive);
1431
- currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("keydown", _this.setKeyPressed, passive);
1432
- document.removeEventListener("mouseleave", _this.clearPanning, passive);
1433
- handleCancelAnimation(_this);
1434
- (_b = _this.observer) === null || _b === void 0 ? void 0 : _b.disconnect();
1435
- };
1436
- this.handleInitializeWrapperEvents = function(wrapper) {
1437
- var passive = makePassiveEventOption();
1438
- wrapper.addEventListener("wheel", _this.onWheelZoom, passive);
1439
- wrapper.addEventListener("dblclick", _this.onDoubleClick, passive);
1440
- wrapper.addEventListener("touchstart", _this.onTouchPanningStart, passive);
1441
- wrapper.addEventListener("touchmove", _this.onTouchPanning, passive);
1442
- wrapper.addEventListener("touchend", _this.onTouchPanningStop, passive);
1443
- };
1444
- this.handleInitialize = function(wrapper, contentComponent) {
1445
- var isCentered = false;
1446
- var centerOnInit = _this.setup.centerOnInit;
1447
- var hasTarget = function(entries, target) {
1448
- for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1449
- var entry = entries_1[_i];
1450
- if (entry.target === target) {
1451
- return true;
1452
- }
1453
- }
1454
- return false;
1455
- };
1456
- _this.applyTransformation();
1457
- _this.onInitCallbacks.forEach(function(callback) {
1458
- callback(getContext(_this));
1459
- });
1460
- _this.observer = new ResizeObserver(function(entries) {
1461
- if (hasTarget(entries, wrapper) || hasTarget(entries, contentComponent)) {
1462
- if (centerOnInit && !isCentered) {
1463
- var currentWidth = contentComponent.offsetWidth;
1464
- var currentHeight = contentComponent.offsetHeight;
1465
- if (currentWidth > 0 || currentHeight > 0) {
1466
- isCentered = true;
1467
- _this.setCenter();
1468
- }
1469
- } else {
1470
- handleCancelAnimation(_this);
1471
- handleCalculateBounds(_this, _this.transformState.scale);
1472
- handleAlignToBounds(_this, 0);
1473
- }
1474
- }
1475
- });
1476
- _this.observer.observe(wrapper);
1477
- _this.observer.observe(contentComponent);
1478
- };
1479
- this.onWheelZoom = function(event) {
1480
- var disabled = _this.setup.disabled;
1481
- if (disabled)
1482
- return;
1483
- var isAllowed = isWheelAllowed(_this, event);
1484
- if (!isAllowed)
1485
- return;
1486
- var keysPressed = _this.isPressingKeys(_this.setup.wheel.activationKeys);
1487
- if (!keysPressed)
1488
- return;
1489
- handleWheelStart(_this, event);
1490
- handleWheelZoom(_this, event);
1491
- handleWheelStop(_this, event);
1492
- };
1493
- this.onWheelPanning = function(event) {
1494
- var _a = _this.setup, disabled = _a.disabled, wheel = _a.wheel, panning = _a.panning;
1495
- if (!_this.wrapperComponent || !_this.contentComponent || disabled || !wheel.wheelDisabled || panning.disabled || !panning.wheelPanning || event.ctrlKey) {
1496
- return;
1497
- }
1498
- event.preventDefault();
1499
- event.stopPropagation();
1500
- var _b = _this.transformState, positionX = _b.positionX, positionY = _b.positionY;
1501
- var mouseX = positionX - event.deltaX;
1502
- var mouseY = positionY - event.deltaY;
1503
- var newPositionX = panning.lockAxisX ? positionX : mouseX;
1504
- var newPositionY = panning.lockAxisY ? positionY : mouseY;
1505
- var _c = _this.setup.alignmentAnimation, sizeX = _c.sizeX, sizeY = _c.sizeY;
1506
- var paddingValueX = getPaddingValue(_this, sizeX);
1507
- var paddingValueY = getPaddingValue(_this, sizeY);
1508
- if (newPositionX === positionX && newPositionY === positionY)
1509
- return;
1510
- handleNewPosition(_this, newPositionX, newPositionY, paddingValueX, paddingValueY);
1511
- };
1512
- this.onPanningStart = function(event) {
1513
- var disabled = _this.setup.disabled;
1514
- var onPanningStart = _this.props.onPanningStart;
1515
- if (disabled)
1516
- return;
1517
- var isAllowed = isPanningStartAllowed(_this, event);
1518
- if (!isAllowed)
1519
- return;
1520
- var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
1521
- if (!keysPressed)
1522
- return;
1523
- if (event.button === 0 && !_this.setup.panning.allowLeftClickPan)
1524
- return;
1525
- if (event.button === 1 && !_this.setup.panning.allowMiddleClickPan)
1526
- return;
1527
- if (event.button === 2 && !_this.setup.panning.allowRightClickPan)
1528
- return;
1529
- event.preventDefault();
1530
- event.stopPropagation();
1531
- handleCancelAnimation(_this);
1532
- handlePanningStart(_this, event);
1533
- handleCallback(getContext(_this), event, onPanningStart);
1534
- };
1535
- this.onPanning = function(event) {
1536
- var disabled = _this.setup.disabled;
1537
- var onPanning = _this.props.onPanning;
1538
- if (disabled)
1539
- return;
1540
- var isAllowed = isPanningAllowed(_this);
1541
- if (!isAllowed)
1542
- return;
1543
- var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
1544
- if (!keysPressed)
1545
- return;
1546
- event.preventDefault();
1547
- event.stopPropagation();
1548
- handlePanning(_this, event.clientX, event.clientY);
1549
- handleCallback(getContext(_this), event, onPanning);
1550
- };
1551
- this.onPanningStop = function(event) {
1552
- var onPanningStop = _this.props.onPanningStop;
1553
- if (_this.isPanning) {
1554
- handlePanningEnd(_this);
1555
- handleCallback(getContext(_this), event, onPanningStop);
1556
- }
1557
- };
1558
- this.onPinchStart = function(event) {
1559
- var disabled = _this.setup.disabled;
1560
- var _a = _this.props, onPinchingStart = _a.onPinchingStart, onZoomStart = _a.onZoomStart;
1561
- if (disabled)
1562
- return;
1563
- var isAllowed = isPinchStartAllowed(_this, event);
1564
- if (!isAllowed)
1565
- return;
1566
- handlePinchStart(_this, event);
1567
- handleCancelAnimation(_this);
1568
- handleCallback(getContext(_this), event, onPinchingStart);
1569
- handleCallback(getContext(_this), event, onZoomStart);
1570
- };
1571
- this.onPinch = function(event) {
1572
- var disabled = _this.setup.disabled;
1573
- var _a = _this.props, onPinching = _a.onPinching, onZoom = _a.onZoom;
1574
- if (disabled)
1575
- return;
1576
- var isAllowed = isPinchAllowed(_this);
1577
- if (!isAllowed)
1578
- return;
1579
- event.preventDefault();
1580
- event.stopPropagation();
1581
- handlePinchZoom(_this, event);
1582
- handleCallback(getContext(_this), event, onPinching);
1583
- handleCallback(getContext(_this), event, onZoom);
1584
- };
1585
- this.onPinchStop = function(event) {
1586
- var _a = _this.props, onPinchingStop = _a.onPinchingStop, onZoomStop = _a.onZoomStop;
1587
- if (_this.pinchStartScale) {
1588
- handlePinchStop(_this);
1589
- handleCallback(getContext(_this), event, onPinchingStop);
1590
- handleCallback(getContext(_this), event, onZoomStop);
1591
- }
1592
- };
1593
- this.onTouchPanningStart = function(event) {
1594
- var disabled = _this.setup.disabled;
1595
- var onPanningStart = _this.props.onPanningStart;
1596
- if (disabled)
1597
- return;
1598
- var isAllowed = isPanningStartAllowed(_this, event);
1599
- if (!isAllowed)
1600
- return;
1601
- var isDoubleTap = _this.lastTouch && +/* @__PURE__ */ new Date() - _this.lastTouch < 200 && event.touches.length === 1;
1602
- if (!isDoubleTap) {
1603
- _this.lastTouch = +/* @__PURE__ */ new Date();
1604
- handleCancelAnimation(_this);
1605
- var touches = event.touches;
1606
- var isPanningAction = touches.length === 1;
1607
- var isPinchAction = touches.length === 2;
1608
- if (isPanningAction) {
1609
- handleCancelAnimation(_this);
1610
- handlePanningStart(_this, event);
1611
- handleCallback(getContext(_this), event, onPanningStart);
1612
- }
1613
- if (isPinchAction) {
1614
- _this.onPinchStart(event);
1615
- }
1616
- }
1617
- };
1618
- this.onTouchPanning = function(event) {
1619
- var disabled = _this.setup.disabled;
1620
- var onPanning = _this.props.onPanning;
1621
- if (_this.isPanning && event.touches.length === 1) {
1622
- if (disabled)
1623
- return;
1624
- var isAllowed = isPanningAllowed(_this);
1625
- if (!isAllowed)
1626
- return;
1627
- event.preventDefault();
1628
- event.stopPropagation();
1629
- var touch = event.touches[0];
1630
- handlePanning(_this, touch.clientX, touch.clientY);
1631
- handleCallback(getContext(_this), event, onPanning);
1632
- } else if (event.touches.length > 1) {
1633
- _this.onPinch(event);
1634
- }
1635
- };
1636
- this.onTouchPanningStop = function(event) {
1637
- _this.onPanningStop(event);
1638
- _this.onPinchStop(event);
1639
- };
1640
- this.onDoubleClick = function(event) {
1641
- var disabled = _this.setup.disabled;
1642
- if (disabled)
1643
- return;
1644
- var isAllowed = isDoubleClickAllowed(_this, event);
1645
- if (!isAllowed)
1646
- return;
1647
- handleDoubleClick(_this, event);
1648
- };
1649
- this.clearPanning = function(event) {
1650
- if (_this.isPanning) {
1651
- _this.onPanningStop(event);
1652
- }
1653
- };
1654
- this.setKeyPressed = function(e) {
1655
- _this.pressedKeys[e.key] = true;
1656
- };
1657
- this.setKeyUnPressed = function(e) {
1658
- _this.pressedKeys[e.key] = false;
1659
- };
1660
- this.isPressingKeys = function(keys) {
1661
- if (!keys.length) {
1662
- return true;
1663
- }
1664
- return Boolean(keys.find(function(key) {
1665
- return _this.pressedKeys[key];
1666
- }));
1667
- };
1668
- this.setTransformState = function(scale, positionX, positionY) {
1669
- var onTransformed = _this.props.onTransformed;
1670
- if (!Number.isNaN(scale) && !Number.isNaN(positionX) && !Number.isNaN(positionY)) {
1671
- if (scale !== _this.transformState.scale) {
1672
- _this.transformState.previousScale = _this.transformState.scale;
1673
- _this.transformState.scale = scale;
1674
- }
1675
- _this.transformState.positionX = positionX;
1676
- _this.transformState.positionY = positionY;
1677
- _this.applyTransformation();
1678
- var ctx_1 = getContext(_this);
1679
- _this.onChangeCallbacks.forEach(function(callback) {
1680
- return callback(ctx_1);
1681
- });
1682
- handleCallback(ctx_1, { scale, positionX, positionY }, onTransformed);
1683
- } else {
1684
- console.error("Detected NaN set state values");
1685
- }
1686
- };
1687
- this.setCenter = function() {
1688
- if (_this.wrapperComponent && _this.contentComponent) {
1689
- var targetState = getCenterPosition(_this.transformState.scale, _this.wrapperComponent, _this.contentComponent);
1690
- _this.setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
1691
- }
1692
- };
1693
- this.handleTransformStyles = function(x, y, scale) {
1694
- if (_this.props.customTransform) {
1695
- return _this.props.customTransform(x, y, scale);
1696
- }
1697
- return getTransformStyles(x, y, scale);
1698
- };
1699
- this.applyTransformation = function() {
1700
- if (!_this.mounted || !_this.contentComponent)
1701
- return;
1702
- var _a = _this.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
1703
- var transform = _this.handleTransformStyles(positionX, positionY, scale);
1704
- _this.contentComponent.style.transform = transform;
1705
- };
1706
- this.getContext = function() {
1707
- return getContext(_this);
1708
- };
1709
- this.onChange = function(callback) {
1710
- if (!_this.onChangeCallbacks.has(callback)) {
1711
- _this.onChangeCallbacks.add(callback);
1712
- }
1713
- return function() {
1714
- _this.onChangeCallbacks.delete(callback);
1715
- };
1716
- };
1717
- this.onInit = function(callback) {
1718
- if (!_this.onInitCallbacks.has(callback)) {
1719
- _this.onInitCallbacks.add(callback);
1720
- }
1721
- return function() {
1722
- _this.onInitCallbacks.delete(callback);
1723
- };
1724
- };
1725
- this.init = function(wrapperComponent, contentComponent) {
1726
- _this.cleanupWindowEvents();
1727
- _this.wrapperComponent = wrapperComponent;
1728
- _this.contentComponent = contentComponent;
1729
- handleCalculateBounds(_this, _this.transformState.scale);
1730
- _this.handleInitializeWrapperEvents(wrapperComponent);
1731
- _this.handleInitialize(wrapperComponent, contentComponent);
1732
- _this.initializeWindowEvents();
1733
- _this.isInitialized = true;
1734
- var ctx = getContext(_this);
1735
- handleCallback(ctx, void 0, _this.props.onInit);
1736
- };
1737
- this.props = props;
1738
- this.setup = createSetup(this.props);
1739
- this.transformState = createState(this.props);
1740
- }
1741
- return ZoomPanPinch2;
1742
- })()
1743
- );
1744
- var Context = React.createContext(null);
1745
- var getContent = function(children, ctx) {
1746
- if (typeof children === "function") {
1747
- return children(ctx);
1748
- }
1749
- return children;
1750
- };
1751
- var TransformWrapper = React.forwardRef(function(props, ref) {
1752
- var instance = useRef(new ZoomPanPinch(props)).current;
1753
- var content = getContent(props.children, getControls(instance));
1754
- useImperativeHandle(ref, function() {
1755
- return getControls(instance);
1756
- }, [instance]);
1757
- useEffect(function() {
1758
- instance.update(props);
1759
- }, [instance, props]);
1760
- return React.createElement(Context.Provider, { value: instance }, content);
1761
- });
1762
- React.forwardRef(function(props, ref) {
1763
- var localRef = useRef(null);
1764
- var instance = useContext(Context);
1765
- useEffect(function() {
1766
- return instance.onChange(function(ctx) {
1767
- if (localRef.current) {
1768
- var positionX = 0;
1769
- var positionY = 0;
1770
- localRef.current.style.transform = instance.handleTransformStyles(positionX, positionY, 1 / ctx.instance.transformState.scale);
1771
- }
1772
- });
1773
- }, [instance]);
1774
- return React.createElement("div", __assign({}, props, { ref: mergeRefs([localRef, ref]) }));
1775
- });
1776
- function styleInject(css, ref) {
1777
- if (ref === void 0) ref = {};
1778
- var insertAt = ref.insertAt;
1779
- if (typeof document === "undefined") {
1780
- return;
1781
- }
1782
- var head = document.head || document.getElementsByTagName("head")[0];
1783
- var style = document.createElement("style");
1784
- style.type = "text/css";
1785
- if (insertAt === "top") {
1786
- if (head.firstChild) {
1787
- head.insertBefore(style, head.firstChild);
1788
- } else {
1789
- head.appendChild(style);
1790
- }
1791
- } else {
1792
- head.appendChild(style);
1793
- }
1794
- if (style.styleSheet) {
1795
- style.styleSheet.cssText = css;
1796
- } else {
1797
- style.appendChild(document.createTextNode(css));
1798
- }
1799
- }
1800
- var css_248z = ".transform-component-module_wrapper__SPB86 {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n transform: translate3d(0, 0, 0);\n}\n.transform-component-module_content__FBWxo {\n display: flex;\n flex-wrap: wrap;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.transform-component-module_content__FBWxo img {\n pointer-events: none;\n}\n";
1801
- var styles = { "wrapper": "transform-component-module_wrapper__SPB86", "content": "transform-component-module_content__FBWxo" };
1802
- styleInject(css_248z);
1803
- var TransformComponent = function(_a) {
1804
- var children = _a.children, _b = _a.wrapperClass, wrapperClass = _b === void 0 ? "" : _b, _c = _a.contentClass, contentClass = _c === void 0 ? "" : _c, wrapperStyle = _a.wrapperStyle, contentStyle = _a.contentStyle, _d = _a.wrapperProps, wrapperProps = _d === void 0 ? {} : _d, _e = _a.contentProps, contentProps = _e === void 0 ? {} : _e;
1805
- var _f = useContext(Context), init = _f.init, cleanupWindowEvents = _f.cleanupWindowEvents;
1806
- var wrapperRef = useRef(null);
1807
- var contentRef = useRef(null);
1808
- useEffect(function() {
1809
- var wrapper = wrapperRef.current;
1810
- var content = contentRef.current;
1811
- if (wrapper !== null && content !== null && init) {
1812
- init === null || init === void 0 ? void 0 : init(wrapper, content);
1813
- }
1814
- return function() {
1815
- cleanupWindowEvents === null || cleanupWindowEvents === void 0 ? void 0 : cleanupWindowEvents();
1816
- };
1817
- }, []);
1818
- return React.createElement(
1819
- "div",
1820
- __assign({}, wrapperProps, { ref: wrapperRef, className: "".concat(baseClasses.wrapperClass, " ").concat(styles.wrapper, " ").concat(wrapperClass), style: wrapperStyle }),
1821
- React.createElement("div", __assign({}, contentProps, { ref: contentRef, className: "".concat(baseClasses.contentClass, " ").concat(styles.content, " ").concat(contentClass), style: contentStyle }), children)
1822
- );
1823
- };
1824
- var useTransformContext = function() {
1825
- var libraryContext = useContext(Context);
1826
- if (!libraryContext) {
1827
- throw new Error("Transform context must be placed inside TransformWrapper");
1828
- }
1829
- return libraryContext;
1830
- };
1831
- var useControls = function() {
1832
- var libraryContext = useTransformContext();
1833
- return getControls(libraryContext);
1834
- };
4
+ import { FishSymbol, Copy, Download, RotateCcw, X, ZoomIn, ZoomOut, Maximize2, CircleAlert, Code2, Columns2, Eye } from "lucide-react";
5
+ import { useState, useId, useEffect, useCallback, useRef } from "react";
6
+ import { TransformWrapper, TransformComponent, useControls } from "react-zoom-pan-pinch";
1835
7
  var mermaidContainer = "_36yqie0";
1836
8
  var mermaidEditHint = "_36yqie1";
1837
9
  var zoomControls = "_36yqie2";
@@ -2328,13 +500,13 @@ const MermaidEditorContent = ({ initialContent, onSave, dismiss, colorScheme })
2328
500
  onSave(code);
2329
501
  dismiss();
2330
502
  }, [code, onSave, dismiss]);
2331
- const viewBtn = (mode, Icon2) => /* @__PURE__ */ jsx(
503
+ const viewBtn = (mode, Icon) => /* @__PURE__ */ jsx(
2332
504
  "button",
2333
505
  {
2334
506
  type: "button",
2335
507
  className: `${editorViewItem}${activeView === mode ? ` ${editorViewItemActive}` : ""}`,
2336
508
  onClick: () => setActiveView(mode),
2337
- children: /* @__PURE__ */ jsx(Icon2, { size: 14 })
509
+ children: /* @__PURE__ */ jsx(Icon, { size: 14 })
2338
510
  }
2339
511
  );
2340
512
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -2358,7 +530,7 @@ const MermaidEditorContent = ({ initialContent, onSave, dismiss, colorScheme })
2358
530
  ] }),
2359
531
  /* @__PURE__ */ jsxs("div", { className: editorHeaderRight, children: [
2360
532
  /* @__PURE__ */ jsxs("div", { className: editorViewToggle, children: [
2361
- viewBtn("code", CodeXml),
533
+ viewBtn("code", Code2),
2362
534
  viewBtn("split", Columns2),
2363
535
  viewBtn("preview", Eye)
2364
536
  ] }),
@@ -2452,16 +624,16 @@ const MermaidEditorContent = ({ initialContent, onSave, dismiss, colorScheme })
2452
624
  ] });
2453
625
  };
2454
626
  const ZoomControls = () => {
2455
- const { zoomIn: zoomIn2, zoomOut: zoomOut2, resetTransform: resetTransform2 } = useControls();
627
+ const { zoomIn, zoomOut, resetTransform } = useControls();
2456
628
  return /* @__PURE__ */ jsxs("div", { className: zoomControls, children: [
2457
- /* @__PURE__ */ jsx("button", { type: "button", className: zoomBtn, onClick: () => zoomIn2(), children: /* @__PURE__ */ jsx(ZoomIn, { size: 14 }) }),
2458
- /* @__PURE__ */ jsx("button", { type: "button", className: zoomBtn, onClick: () => zoomOut2(), children: /* @__PURE__ */ jsx(ZoomOut, { size: 14 }) }),
629
+ /* @__PURE__ */ jsx("button", { type: "button", className: zoomBtn, onClick: () => zoomIn(), children: /* @__PURE__ */ jsx(ZoomIn, { size: 14 }) }),
630
+ /* @__PURE__ */ jsx("button", { type: "button", className: zoomBtn, onClick: () => zoomOut(), children: /* @__PURE__ */ jsx(ZoomOut, { size: 14 }) }),
2459
631
  /* @__PURE__ */ jsx(
2460
632
  "button",
2461
633
  {
2462
634
  type: "button",
2463
635
  className: zoomBtn,
2464
- onClick: () => resetTransform2(),
636
+ onClick: () => resetTransform(),
2465
637
  children: /* @__PURE__ */ jsx(Maximize2, { size: 14 })
2466
638
  }
2467
639
  )