@douyinfe/semi-foundation 2.67.3-alpha.0 → 2.68.0

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 (53) hide show
  1. package/datePicker/foundation.ts +1 -1
  2. package/hotKeys/foundation.ts +4 -5
  3. package/lib/cjs/datePicker/foundation.d.ts +1 -1
  4. package/lib/cjs/hotKeys/foundation.d.ts +2 -1
  5. package/lib/cjs/hotKeys/foundation.js +2 -4
  6. package/lib/cjs/overflowList/constants.d.ts +1 -1
  7. package/lib/cjs/resizable/constants.d.ts +5 -0
  8. package/lib/cjs/resizable/constants.js +11 -0
  9. package/lib/cjs/resizable/foundation.d.ts +4 -0
  10. package/lib/cjs/resizable/foundation.js +37 -0
  11. package/lib/cjs/resizable/group/index.d.ts +50 -0
  12. package/lib/cjs/resizable/group/index.js +271 -0
  13. package/lib/cjs/resizable/groupConstants.d.ts +16 -0
  14. package/lib/cjs/resizable/groupConstants.js +25 -0
  15. package/lib/cjs/resizable/resizable.css +34 -0
  16. package/lib/cjs/resizable/resizable.scss +39 -0
  17. package/lib/cjs/resizable/single/index.d.ts +70 -0
  18. package/lib/cjs/resizable/single/index.js +574 -0
  19. package/lib/cjs/resizable/singleConstants.d.ts +105 -0
  20. package/lib/cjs/resizable/singleConstants.js +67 -0
  21. package/lib/cjs/resizable/utils.d.ts +20 -0
  22. package/lib/cjs/resizable/utils.js +142 -0
  23. package/lib/cjs/tree/treeUtil.d.ts +1 -1
  24. package/lib/es/datePicker/foundation.d.ts +1 -1
  25. package/lib/es/hotKeys/foundation.d.ts +2 -1
  26. package/lib/es/hotKeys/foundation.js +2 -4
  27. package/lib/es/overflowList/constants.d.ts +1 -1
  28. package/lib/es/resizable/constants.d.ts +5 -0
  29. package/lib/es/resizable/constants.js +6 -0
  30. package/lib/es/resizable/foundation.d.ts +4 -0
  31. package/lib/es/resizable/foundation.js +4 -0
  32. package/lib/es/resizable/group/index.d.ts +50 -0
  33. package/lib/es/resizable/group/index.js +262 -0
  34. package/lib/es/resizable/groupConstants.d.ts +16 -0
  35. package/lib/es/resizable/groupConstants.js +19 -0
  36. package/lib/es/resizable/resizable.css +34 -0
  37. package/lib/es/resizable/resizable.scss +39 -0
  38. package/lib/es/resizable/single/index.d.ts +70 -0
  39. package/lib/es/resizable/single/index.js +565 -0
  40. package/lib/es/resizable/singleConstants.d.ts +105 -0
  41. package/lib/es/resizable/singleConstants.js +61 -0
  42. package/lib/es/resizable/utils.d.ts +20 -0
  43. package/lib/es/resizable/utils.js +124 -0
  44. package/lib/es/tree/treeUtil.d.ts +1 -1
  45. package/package.json +3 -3
  46. package/resizable/constants.ts +13 -0
  47. package/resizable/foundation.ts +31 -0
  48. package/resizable/group/index.ts +293 -0
  49. package/resizable/groupConstants.ts +25 -0
  50. package/resizable/resizable.scss +39 -0
  51. package/resizable/single/index.ts +629 -0
  52. package/resizable/singleConstants.ts +127 -0
  53. package/resizable/utils.ts +145 -0
@@ -0,0 +1,574 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ResizableHandlerFoundation = exports.ResizableFoundation = void 0;
7
+ var _foundation = _interopRequireDefault(require("../../base/foundation"));
8
+ var _singleConstants = require("../singleConstants");
9
+ var _utils = require("../utils");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ class ResizableHandlerFoundation extends _foundation.default {
12
+ constructor(adapter) {
13
+ super(Object.assign({}, adapter));
14
+ this.onMouseDown = e => {
15
+ this.getProp('onResizeStart')(e, this.getProp('direction'));
16
+ };
17
+ }
18
+ init() {
19
+ this._adapter.registerEvent();
20
+ }
21
+ destroy() {
22
+ this._adapter.unregisterEvent();
23
+ }
24
+ }
25
+ exports.ResizableHandlerFoundation = ResizableHandlerFoundation;
26
+ class ResizableFoundation extends _foundation.default {
27
+ constructor(adapter) {
28
+ super(Object.assign({}, adapter));
29
+ this.lockAspectRatio = 1;
30
+ this.resizable = null;
31
+ this.parentLeft = 0;
32
+ this.parentTop = 0;
33
+ this.boundaryLeft = 0;
34
+ this.boundaryRight = 0;
35
+ this.boundaryTop = 0;
36
+ this.boundaryBottom = 0;
37
+ this.targetLeft = 0;
38
+ this.targetTop = 0;
39
+ this.onResizeStart = (e, direction) => {
40
+ this.resizable = this._adapter.getResizable();
41
+ if (!this.resizable || !this.window) {
42
+ return;
43
+ }
44
+ const {
45
+ clientX,
46
+ clientY
47
+ } = e;
48
+ const props = this.getProps();
49
+ const states = this.getStates();
50
+ // Call onResizeStart callback if defined
51
+ if (props.onResizeStart) {
52
+ const shouldContinue = props.onResizeStart(e, direction);
53
+ if (shouldContinue === false) {
54
+ return;
55
+ }
56
+ }
57
+ // Update state with new size if defined
58
+ const {
59
+ size
60
+ } = props;
61
+ if (size) {
62
+ const {
63
+ height,
64
+ width
65
+ } = size;
66
+ const {
67
+ height: currentHeight,
68
+ width: currentWidth
69
+ } = states;
70
+ if (height !== undefined && height !== currentHeight) {
71
+ this.setState({
72
+ height
73
+ });
74
+ }
75
+ if (width !== undefined && width !== currentWidth) {
76
+ this.setState({
77
+ width
78
+ });
79
+ }
80
+ }
81
+ // Handle aspect ratio locking
82
+ this.lockAspectRatio = typeof props.lockAspectRatio === 'number' ? props.lockAspectRatio : this.size.width / this.size.height;
83
+ // Determine flexBasis if applicable
84
+ let flexBasis;
85
+ const computedStyle = this.window.getComputedStyle(this.resizable);
86
+ if (computedStyle.flexBasis !== 'auto') {
87
+ const parent = this.parent;
88
+ if (parent) {
89
+ const parentStyle = this.window.getComputedStyle(parent);
90
+ this.flexDirection = parentStyle.flexDirection.startsWith('row') ? 'row' : 'column';
91
+ flexBasis = computedStyle.flexBasis;
92
+ }
93
+ }
94
+ // Set bounding rectangle and register events
95
+ this.setBoundary();
96
+ this.registerEvents();
97
+ // Update state with initial resize values
98
+ const state = {
99
+ original: {
100
+ x: clientX,
101
+ y: clientY,
102
+ width: this.size.width,
103
+ height: this.size.height
104
+ },
105
+ isResizing: true,
106
+ backgroundStyle: Object.assign(Object.assign({}, states.backgroundStyle), {
107
+ cursor: this.window.getComputedStyle(e.target).cursor || 'auto'
108
+ }),
109
+ direction,
110
+ flexBasis
111
+ };
112
+ this.setState(state);
113
+ };
114
+ this.onMouseMove = event => {
115
+ var _a, _b;
116
+ const states = this.getStates();
117
+ const props = this.getProps();
118
+ if (!states.isResizing || !this.resizable || !this.window) {
119
+ return;
120
+ }
121
+ const {
122
+ clientX,
123
+ clientY
124
+ } = event;
125
+ const {
126
+ direction,
127
+ original,
128
+ width,
129
+ height
130
+ } = states;
131
+ const parentSize = this.getParentSize();
132
+ let {
133
+ maxWidth,
134
+ maxHeight,
135
+ minWidth,
136
+ minHeight
137
+ } = props;
138
+ // Calculate max and min dimensions
139
+ const maxBounds = (0, _utils.calculateNewMax)(parentSize, this.window.innerWidth, this.window.innerHeight, maxWidth, maxHeight, minWidth, minHeight);
140
+ maxWidth = maxBounds.maxWidth;
141
+ maxHeight = maxBounds.maxHeight;
142
+ minWidth = maxBounds.minWidth;
143
+ minHeight = maxBounds.minHeight;
144
+ // Calculate new size based on direction
145
+ let {
146
+ newWidth,
147
+ newHeight
148
+ } = this.calDirectionSize(clientX, clientY);
149
+ // Apply boundary constraints
150
+ const boundaryMax = this.calBoundaryMax(maxWidth, maxHeight);
151
+ newWidth = (0, _utils.getNumberSize)(newWidth, parentSize.width, this.window.innerWidth, this.window.innerHeight);
152
+ newHeight = (0, _utils.getNumberSize)(newHeight, parentSize.height, this.window.innerWidth, this.window.innerHeight);
153
+ // Apply snapping
154
+ if (props.snap) {
155
+ if (props.snap.x) {
156
+ newWidth = (0, _utils.findNextSnap)(newWidth, props.snap.x, props.snapGap);
157
+ }
158
+ if (props.snap.y) {
159
+ newHeight = (0, _utils.findNextSnap)(newHeight, props.snap.y, props.snapGap);
160
+ }
161
+ }
162
+ // Adjust size based on aspect ratio
163
+ const sizeFromAspectRatio = this.calAspectRatioSize(newWidth, newHeight, {
164
+ width: boundaryMax.maxWidth,
165
+ height: boundaryMax.maxHeight
166
+ }, {
167
+ width: minWidth,
168
+ height: minHeight
169
+ });
170
+ newWidth = sizeFromAspectRatio.newWidth;
171
+ newHeight = sizeFromAspectRatio.newHeight;
172
+ // Apply grid snapping if defined
173
+ if (props.grid) {
174
+ const [gridW, gridH] = Array.isArray(props.grid) ? props.grid : [props.grid, props.grid];
175
+ const gap = props.snapGap || 0;
176
+ const newGridWidth = (0, _utils.snap)(newWidth, gridW);
177
+ const newGridHeight = (0, _utils.snap)(newHeight, gridH);
178
+ newWidth = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth;
179
+ newHeight = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight;
180
+ }
181
+ // Convert width and height to CSS units if needed
182
+ const convertToCssUnit = (size, originalSize, unit) => {
183
+ if (unit.endsWith('%')) {
184
+ return `${size / originalSize * 100}%`;
185
+ } else if (unit.endsWith('vw')) {
186
+ return `${size / this.window.innerWidth * 100}vw`;
187
+ } else if (unit.endsWith('vh')) {
188
+ return `${size / this.window.innerHeight * 100}vh`;
189
+ }
190
+ return size;
191
+ };
192
+ if (typeof width === 'string') {
193
+ newWidth = convertToCssUnit(newWidth, parentSize.width, width || '');
194
+ }
195
+ if (typeof height === 'string') {
196
+ newHeight = convertToCssUnit(newHeight, parentSize.height, height || '');
197
+ }
198
+ // Create new state
199
+ const newState = {
200
+ width: this.getCssPropertySize(newWidth, 'width'),
201
+ height: this.getCssPropertySize(newHeight, 'height')
202
+ };
203
+ if (this.flexDirection === 'row') {
204
+ newState.flexBasis = newState.width;
205
+ } else if (this.flexDirection === 'column') {
206
+ newState.flexBasis = newState.height;
207
+ }
208
+ // Check for changes
209
+ const widthChanged = states.width !== newState.width;
210
+ const heightChanged = states.height !== newState.height;
211
+ const flexBaseChanged = states.flexBasis !== newState.flexBasis;
212
+ const hasChanges = widthChanged || heightChanged || flexBaseChanged;
213
+ if (hasChanges) {
214
+ this.setState(newState);
215
+ // Call onChange callback if defined
216
+ if (props.onChange) {
217
+ let newSize = {
218
+ width: newState.width,
219
+ height: newState.height
220
+ };
221
+ props.onChange(newSize, event, direction);
222
+ }
223
+ const size = props.size;
224
+ if (size) {
225
+ this.setState({
226
+ width: (_a = size.width) !== null && _a !== void 0 ? _a : 'auto',
227
+ height: (_b = size.height) !== null && _b !== void 0 ? _b : 'auto'
228
+ });
229
+ }
230
+ }
231
+ };
232
+ this.onMouseUp = event => {
233
+ var _a, _b;
234
+ const {
235
+ isResizing,
236
+ direction,
237
+ original
238
+ } = this.getStates();
239
+ if (!isResizing || !this.resizable) {
240
+ return;
241
+ }
242
+ const {
243
+ width: currentWidth,
244
+ height: currentHeight
245
+ } = this.size;
246
+ const delta = {
247
+ width: currentWidth - original.width,
248
+ height: currentHeight - original.height
249
+ };
250
+ const {
251
+ onResizeEnd,
252
+ size
253
+ } = this.getProps();
254
+ // Call onResizeEnd callback if defined
255
+ if (onResizeEnd) {
256
+ onResizeEnd(this.size, event, direction);
257
+ }
258
+ // Update state with new size if provided
259
+ if (size) {
260
+ this.setState({
261
+ width: (_a = size.width) !== null && _a !== void 0 ? _a : 'auto',
262
+ height: (_b = size.height) !== null && _b !== void 0 ? _b : 'auto'
263
+ });
264
+ }
265
+ // Unregister events and update state
266
+ this.unregisterEvents();
267
+ this.setState({
268
+ isResizing: false,
269
+ backgroundStyle: Object.assign(Object.assign({}, this.getStates().backgroundStyle), {
270
+ cursor: 'auto'
271
+ })
272
+ });
273
+ };
274
+ }
275
+ init() {
276
+ if (!this.resizable || !this.window) {
277
+ return;
278
+ }
279
+ const flexBasis = this.window.getComputedStyle(this.resizable).flexBasis;
280
+ this.setState({
281
+ width: this.propSize.width,
282
+ height: this.propSize.height,
283
+ flexBasis: flexBasis !== 'auto' ? flexBasis : undefined
284
+ });
285
+ this.onResizeStart = this.onResizeStart.bind(this);
286
+ this.onMouseMove = this.onMouseMove.bind(this);
287
+ this.onMouseUp = this.onMouseUp.bind(this);
288
+ }
289
+ get parent() {
290
+ if (!this.resizable) {
291
+ return null;
292
+ }
293
+ return this.resizable.parentNode;
294
+ }
295
+ get window() {
296
+ if (!this.resizable) {
297
+ return null;
298
+ }
299
+ if (!this.resizable.ownerDocument) {
300
+ return null;
301
+ }
302
+ return this.resizable.ownerDocument.defaultView;
303
+ }
304
+ get propSize() {
305
+ const porps = this.getProps();
306
+ return porps.size || porps.defaultSize || _singleConstants.DEFAULT_SIZE;
307
+ }
308
+ get size() {
309
+ let width = 0;
310
+ let height = 0;
311
+ if (this.resizable && this.window) {
312
+ width = this.resizable.offsetWidth;
313
+ height = this.resizable.offsetHeight;
314
+ }
315
+ return {
316
+ width,
317
+ height
318
+ };
319
+ }
320
+ get sizeStyle() {
321
+ const size = this.getProp('size');
322
+ const getSize = property => {
323
+ var _a;
324
+ const value = this.getStates()[property];
325
+ if (typeof value === 'undefined' || value === 'auto') {
326
+ return 'auto';
327
+ }
328
+ const propSizeValue = (_a = this.propSize) === null || _a === void 0 ? void 0 : _a[property];
329
+ if (propSizeValue === null || propSizeValue === void 0 ? void 0 : propSizeValue.toString().endsWith('%')) {
330
+ if (value.toString().endsWith('%')) {
331
+ return value.toString();
332
+ }
333
+ const parentSize = this.getParentSize();
334
+ const numberValue = Number(value.toString().replace('px', ''));
335
+ const percentValue = numberValue / parentSize[property] * 100;
336
+ return `${percentValue}%`;
337
+ }
338
+ return (0, _utils.getStringSize)(value);
339
+ };
340
+ const isResizing = this.getStates().isResizing;
341
+ const width = size && typeof size.width !== 'undefined' && !isResizing ? (0, _utils.getStringSize)(size.width) : getSize('width');
342
+ const height = size && typeof size.height !== 'undefined' && !isResizing ? (0, _utils.getStringSize)(size.height) : getSize('height');
343
+ return {
344
+ width,
345
+ height
346
+ };
347
+ }
348
+ getParentSize() {
349
+ const appendPseudo = () => {
350
+ if (!this.resizable || !this.window) {
351
+ return null;
352
+ }
353
+ const parent = this.parent;
354
+ if (!parent) {
355
+ return null;
356
+ }
357
+ const pseudoEle = this.window.document.createElement('div');
358
+ pseudoEle.style.width = '100%';
359
+ pseudoEle.style.height = '100%';
360
+ pseudoEle.style.position = 'absolute';
361
+ pseudoEle.style.transform = 'scale(0, 0)';
362
+ pseudoEle.style.left = '0';
363
+ pseudoEle.style.flex = '0 0 100%';
364
+ parent.appendChild(pseudoEle);
365
+ return pseudoEle;
366
+ };
367
+ const removePseudo = pseudo => {
368
+ const parent = this.parent;
369
+ if (!parent) {
370
+ return;
371
+ }
372
+ parent.removeChild(pseudo);
373
+ };
374
+ if (!this.parent) {
375
+ if (!this.window) {
376
+ return {
377
+ width: 0,
378
+ height: 0
379
+ };
380
+ }
381
+ return {
382
+ width: this.window.innerWidth,
383
+ height: this.window.innerHeight
384
+ };
385
+ }
386
+ const pseudoElement = appendPseudo();
387
+ if (!pseudoElement) {
388
+ return {
389
+ width: 0,
390
+ height: 0
391
+ };
392
+ }
393
+ let flexWrapChanged = false;
394
+ const originalFlexWrap = this.parent.style.flexWrap;
395
+ if (originalFlexWrap !== 'wrap') {
396
+ flexWrapChanged = true;
397
+ this.parent.style.flexWrap = 'wrap';
398
+ }
399
+ pseudoElement.style.position = 'relative';
400
+ pseudoElement.style.minWidth = '100%';
401
+ pseudoElement.style.minHeight = '100%';
402
+ const size = {
403
+ width: pseudoElement.offsetWidth,
404
+ height: pseudoElement.offsetHeight
405
+ };
406
+ if (flexWrapChanged) {
407
+ this.parent.style.flexWrap = originalFlexWrap;
408
+ }
409
+ removePseudo(pseudoElement);
410
+ return size;
411
+ }
412
+ registerEvents() {
413
+ this._adapter.registerEvent();
414
+ }
415
+ unregisterEvents() {
416
+ this._adapter.unregisterEvent();
417
+ }
418
+ getCssPropertySize(newSize, property) {
419
+ var _a;
420
+ const propSizeValue = (_a = this.propSize) === null || _a === void 0 ? void 0 : _a[property];
421
+ const state = this.getStates();
422
+ const isAutoSize = state[property] === 'auto' && state.original[property] === newSize && (typeof propSizeValue === 'undefined' || propSizeValue === 'auto');
423
+ return isAutoSize ? 'auto' : newSize;
424
+ }
425
+ calBoundaryMax(maxWidth, maxHeight) {
426
+ const {
427
+ boundsByDirection
428
+ } = this.getProps();
429
+ const {
430
+ direction
431
+ } = this.getStates();
432
+ const isWidthConstrained = boundsByDirection && (0, _utils.has)('left', direction);
433
+ const isHeightConstrained = boundsByDirection && (0, _utils.has)('top', direction);
434
+ let maxWidthConstraint;
435
+ let maxHeightConstraint;
436
+ const props = this.getProps();
437
+ if (props.boundElement === 'parent') {
438
+ const parentElement = this.parent;
439
+ if (parentElement) {
440
+ maxWidthConstraint = isWidthConstrained ? this.boundaryRight - this.parentLeft : parentElement.offsetWidth + (this.parentLeft - this.boundaryLeft);
441
+ maxHeightConstraint = isHeightConstrained ? this.boundaryBottom - this.parentTop : parentElement.offsetHeight + (this.parentTop - this.boundaryTop);
442
+ }
443
+ } else if (props.boundElement === 'window' && this.window) {
444
+ maxWidthConstraint = isWidthConstrained ? this.boundaryRight : this.window.innerWidth - this.boundaryLeft;
445
+ maxHeightConstraint = isHeightConstrained ? this.boundaryBottom : this.window.innerHeight - this.boundaryTop;
446
+ } else if (props.boundElement) {
447
+ const boundary = props.boundElement;
448
+ maxWidthConstraint = isWidthConstrained ? this.boundaryRight - this.targetLeft : boundary.offsetWidth + (this.targetLeft - this.boundaryLeft);
449
+ maxHeightConstraint = isHeightConstrained ? this.boundaryBottom - this.targetTop : boundary.offsetHeight + (this.targetTop - this.boundaryTop);
450
+ }
451
+ if (maxWidthConstraint && Number.isFinite(maxWidthConstraint)) {
452
+ maxWidth = maxWidth && maxWidth < maxWidthConstraint ? maxWidth : maxWidthConstraint;
453
+ }
454
+ if (maxHeightConstraint && Number.isFinite(maxHeightConstraint)) {
455
+ maxHeight = maxHeight && maxHeight < maxHeightConstraint ? maxHeight : maxHeightConstraint;
456
+ }
457
+ return {
458
+ maxWidth,
459
+ maxHeight
460
+ };
461
+ }
462
+ calDirectionSize(clientX, clientY) {
463
+ const props = this.getProps();
464
+ const scale = props.scale || 1;
465
+ let aspectRatio = props.ratio;
466
+ const [resizeRatioX, resizeRatioY] = Array.isArray(aspectRatio) ? aspectRatio : [aspectRatio, aspectRatio];
467
+ const {
468
+ direction,
469
+ original
470
+ } = this.getStates();
471
+ const {
472
+ lockAspectRatio,
473
+ lockAspectRatioExtraHeight = 0,
474
+ lockAspectRatioExtraWidth = 0
475
+ } = props;
476
+ let newWidth = original.width;
477
+ let newHeight = original.height;
478
+ const calculateNewWidth = deltaX => original.width + deltaX * resizeRatioX / scale;
479
+ const calculateNewHeight = deltaY => original.height + deltaY * resizeRatioY / scale;
480
+ if ((0, _utils.has)('top', direction)) {
481
+ newHeight = calculateNewHeight(original.y - clientY);
482
+ if (lockAspectRatio) {
483
+ newWidth = (newHeight - lockAspectRatioExtraHeight) * this.lockAspectRatio + lockAspectRatioExtraWidth;
484
+ }
485
+ }
486
+ if ((0, _utils.has)('bottom', direction)) {
487
+ newHeight = calculateNewHeight(clientY - original.y);
488
+ if (lockAspectRatio) {
489
+ newWidth = (newHeight - lockAspectRatioExtraHeight) * this.lockAspectRatio + lockAspectRatioExtraWidth;
490
+ }
491
+ }
492
+ if ((0, _utils.has)('right', direction)) {
493
+ newWidth = calculateNewWidth(clientX - original.x);
494
+ if (lockAspectRatio) {
495
+ newHeight = (newWidth - lockAspectRatioExtraWidth) / this.lockAspectRatio + lockAspectRatioExtraHeight;
496
+ }
497
+ }
498
+ if ((0, _utils.has)('left', direction)) {
499
+ newWidth = calculateNewWidth(original.x - clientX);
500
+ if (lockAspectRatio) {
501
+ newHeight = (newWidth - lockAspectRatioExtraWidth) / this.lockAspectRatio + lockAspectRatioExtraHeight;
502
+ }
503
+ }
504
+ return {
505
+ newWidth,
506
+ newHeight
507
+ };
508
+ }
509
+ calAspectRatioSize(newWidth, newHeight, max, min) {
510
+ const {
511
+ lockAspectRatio,
512
+ lockAspectRatioExtraHeight = 0,
513
+ lockAspectRatioExtraWidth = 0
514
+ } = this.getProps();
515
+ const minWidth = typeof min.width === 'undefined' ? 10 : min.width;
516
+ const maxWidth = typeof max.width === 'undefined' || max.width < 0 ? newWidth : max.width;
517
+ const minHeight = typeof min.height === 'undefined' ? 10 : min.height;
518
+ const maxHeight = typeof max.height === 'undefined' || max.height < 0 ? newHeight : max.height;
519
+ if (lockAspectRatio) {
520
+ const adjustedMinWidth = (minHeight - lockAspectRatioExtraHeight) * this.lockAspectRatio + lockAspectRatioExtraWidth;
521
+ const adjustedMaxWidth = (maxHeight - lockAspectRatioExtraHeight) * this.lockAspectRatio + lockAspectRatioExtraWidth;
522
+ const adjustedMinHeight = (minWidth - lockAspectRatioExtraWidth) / this.lockAspectRatio + lockAspectRatioExtraHeight;
523
+ const adjustedMaxHeight = (maxWidth - lockAspectRatioExtraWidth) / this.lockAspectRatio + lockAspectRatioExtraHeight;
524
+ const lockedMinWidth = Math.max(minWidth, adjustedMinWidth);
525
+ const lockedMaxWidth = Math.min(maxWidth, adjustedMaxWidth);
526
+ const lockedMinHeight = Math.max(minHeight, adjustedMinHeight);
527
+ const lockedMaxHeight = Math.min(maxHeight, adjustedMaxHeight);
528
+ newWidth = (0, _utils.clamp)(newWidth, lockedMinWidth, lockedMaxWidth);
529
+ newHeight = (0, _utils.clamp)(newHeight, lockedMinHeight, lockedMaxHeight);
530
+ } else {
531
+ newWidth = (0, _utils.clamp)(newWidth, minWidth, maxWidth);
532
+ newHeight = (0, _utils.clamp)(newHeight, minHeight, maxHeight);
533
+ }
534
+ return {
535
+ newWidth,
536
+ newHeight
537
+ };
538
+ }
539
+ setBoundary() {
540
+ const props = this.getProps();
541
+ // Set parent boundary
542
+ if (props.boundElement === 'parent') {
543
+ const parentElement = this.parent;
544
+ if (parentElement) {
545
+ const parentRect = parentElement.getBoundingClientRect();
546
+ this.parentLeft = parentRect.left;
547
+ this.parentTop = parentRect.top;
548
+ }
549
+ }
550
+ // Set target (HTML element) boundary
551
+ if (props.boundElement && typeof props.boundElement !== 'string') {
552
+ const targetRect = props.boundElement.getBoundingClientRect();
553
+ this.targetLeft = targetRect.left;
554
+ this.targetTop = targetRect.top;
555
+ }
556
+ // Set resizable boundary
557
+ if (this.resizable) {
558
+ const {
559
+ left,
560
+ top,
561
+ right,
562
+ bottom
563
+ } = this.resizable.getBoundingClientRect();
564
+ this.boundaryLeft = left;
565
+ this.boundaryRight = right;
566
+ this.boundaryTop = top;
567
+ this.boundaryBottom = bottom;
568
+ }
569
+ }
570
+ destroy() {
571
+ this.unregisterEvents();
572
+ }
573
+ }
574
+ exports.ResizableFoundation = ResizableFoundation;
@@ -0,0 +1,105 @@
1
+ export declare const directions: readonly ["top", "right", "bottom", "left", "topRight", "bottomRight", "bottomLeft", "topLeft"];
2
+ export declare const directionStyles: {
3
+ readonly top: {
4
+ readonly top: "-5px";
5
+ readonly width: "100%";
6
+ readonly height: "10px";
7
+ readonly left: "0px";
8
+ readonly cursor: "row-resize";
9
+ };
10
+ readonly right: {
11
+ readonly left: any;
12
+ readonly right: "-5px";
13
+ readonly width: "10px";
14
+ readonly height: "100%";
15
+ readonly top: "0px";
16
+ readonly cursor: "col-resize";
17
+ };
18
+ readonly bottom: {
19
+ readonly top: any;
20
+ readonly bottom: "-5px";
21
+ readonly width: "100%";
22
+ readonly height: "10px";
23
+ readonly left: "0px";
24
+ readonly cursor: "row-resize";
25
+ };
26
+ readonly left: {
27
+ readonly left: "-5px";
28
+ readonly width: "10px";
29
+ readonly height: "100%";
30
+ readonly top: "0px";
31
+ readonly cursor: "col-resize";
32
+ };
33
+ readonly topRight: {
34
+ readonly right: "-10px";
35
+ readonly top: "-10px";
36
+ readonly cursor: "ne-resize";
37
+ readonly width: "20px";
38
+ readonly height: "20px";
39
+ readonly position: "absolute";
40
+ };
41
+ readonly bottomRight: {
42
+ readonly right: "-10px";
43
+ readonly bottom: "-10px";
44
+ readonly cursor: "se-resize";
45
+ readonly width: "20px";
46
+ readonly height: "20px";
47
+ readonly position: "absolute";
48
+ };
49
+ readonly bottomLeft: {
50
+ readonly left: "-10px";
51
+ readonly bottom: "-10px";
52
+ readonly cursor: "sw-resize";
53
+ readonly width: "20px";
54
+ readonly height: "20px";
55
+ readonly position: "absolute";
56
+ };
57
+ readonly topLeft: {
58
+ readonly left: "-10px";
59
+ readonly top: "-10px";
60
+ readonly cursor: "nw-resize";
61
+ readonly width: "20px";
62
+ readonly height: "20px";
63
+ readonly position: "absolute";
64
+ };
65
+ };
66
+ export type Direction = 'top' | 'right' | 'bottom' | 'left' | 'topRight' | 'bottomRight' | 'bottomLeft' | 'topLeft';
67
+ export interface HandleClassName {
68
+ top?: string;
69
+ right?: string;
70
+ bottom?: string;
71
+ left?: string;
72
+ topRight?: string;
73
+ bottomRight?: string;
74
+ bottomLeft?: string;
75
+ topLeft?: string;
76
+ }
77
+ export type HandlerCallback = (e: MouseEvent, direction: Direction) => void;
78
+ export interface Enable {
79
+ top?: boolean;
80
+ right?: boolean;
81
+ bottom?: boolean;
82
+ left?: boolean;
83
+ topRight?: boolean;
84
+ bottomRight?: boolean;
85
+ bottomLeft?: boolean;
86
+ topLeft?: boolean;
87
+ }
88
+ export interface Size {
89
+ width?: string | number;
90
+ height?: string | number;
91
+ }
92
+ export interface NumberSize {
93
+ width: number;
94
+ height: number;
95
+ }
96
+ export interface NewSize {
97
+ newHeight: number | string;
98
+ newWidth: number | string;
99
+ }
100
+ export declare const DEFAULT_SIZE: {
101
+ width: string;
102
+ height: string;
103
+ };
104
+ export type ResizeCallback = (size: Size, event: MouseEvent, direction: Direction) => void;
105
+ export type ResizeStartCallback = (e: MouseEvent, dir: Direction) => void | boolean;