bm-core-ui 2.7.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 (99) hide show
  1. package/CHANGELOG.md +1624 -0
  2. package/LICENSE +21 -0
  3. package/README.md +145 -0
  4. package/build/@types/index.d.ts +14078 -0
  5. package/build/BMCodeEditor/BMCodeEditor.js +707 -0
  6. package/build/BMCollectionView/BMCollectionView.js +5861 -0
  7. package/build/BMCollectionView/BMCollectionViewCell.js +688 -0
  8. package/build/BMCollectionView/BMCollectionViewFlowLayout.js +4467 -0
  9. package/build/BMCollectionView/BMCollectionViewLayout.js +830 -0
  10. package/build/BMCollectionView/BMCollectionViewLayoutAttributes.js +673 -0
  11. package/build/BMCollectionView/BMCollectionViewMasonryLayout.js +491 -0
  12. package/build/BMCollectionView/BMCollectionViewStackLayout.js +634 -0
  13. package/build/BMCollectionView/BMCollectionViewTileLayout.js +1121 -0
  14. package/build/BMCoreUI.css +2833 -0
  15. package/build/BMView/BMAttributedLabelView.js +310 -0
  16. package/build/BMView/BMLayoutConstraint_v2.5.js +1813 -0
  17. package/build/BMView/BMLayoutGuide.js +192 -0
  18. package/build/BMView/BMLayoutSizeClass.js +466 -0
  19. package/build/BMView/BMMenu.js +574 -0
  20. package/build/BMView/BMScrollView.js +247 -0
  21. package/build/BMView/BMTextField.js +512 -0
  22. package/build/BMView/BMTextFieldDelegate.js +71 -0
  23. package/build/BMView/BMView_v2.5.js +3572 -0
  24. package/build/BMView/BMViewport.js +221 -0
  25. package/build/BMViewLayoutEditor/BMLayoutEditor.js +6117 -0
  26. package/build/BMViewLayoutEditor/BMLayoutEditorConstraintSettings.js +417 -0
  27. package/build/BMViewLayoutEditor/BMLayoutEditorDelegate.js +59 -0
  28. package/build/BMViewLayoutEditor/BMLayoutEditorSettingCells.js +1653 -0
  29. package/build/BMViewLayoutEditor/BMLayoutEditorSettings.js +1480 -0
  30. package/build/BMViewLayoutEditor/BMLayoutEditorSettingsComplexCells.js +431 -0
  31. package/build/BMViewLayoutEditor/BMLayoutEditorSettingsDelegate.js +46 -0
  32. package/build/BMViewLayoutEditor/BMLayoutEditorVariablesController.js +460 -0
  33. package/build/BMViewLayoutEditor/BMLayoutEditorViewGroupSettings.js +293 -0
  34. package/build/BMViewLayoutEditor/BMLayoutEditorViewSettings.js +382 -0
  35. package/build/BMViewLayoutEditor/BMLayoutVariableProvider.js +202 -0
  36. package/build/BMWindow/BMConfirmationPopup.js +477 -0
  37. package/build/BMWindow/BMKeyboardShortcut.js +151 -0
  38. package/build/BMWindow/BMPopover/BMPopover.js +492 -0
  39. package/build/BMWindow/BMToolWindow.js +71 -0
  40. package/build/BMWindow/BMWindow.js +2000 -0
  41. package/build/Core/BMAnimationContext.js +1181 -0
  42. package/build/Core/BMColor.js +991 -0
  43. package/build/Core/BMCoreUI.js +470 -0
  44. package/build/Core/BMFunctionCollection.js +110 -0
  45. package/build/Core/BMIndexPath.js +165 -0
  46. package/build/Core/BMInset.js +138 -0
  47. package/build/Core/BMKeyPath.js +100 -0
  48. package/build/Core/BMPoint.js +291 -0
  49. package/build/Core/BMRect.js +556 -0
  50. package/build/Core/BMSize.js +137 -0
  51. package/build/iScroll/LICENSE +22 -0
  52. package/build/iScroll/iscroll-probe.js +2154 -0
  53. package/build/images/AlignBottom.png +0 -0
  54. package/build/images/AlignCenterX.png +0 -0
  55. package/build/images/AlignCenterY.png +0 -0
  56. package/build/images/AlignLeading.png +0 -0
  57. package/build/images/AlignTop.png +0 -0
  58. package/build/images/AlignTrailing.png +0 -0
  59. package/build/images/AllConstraints.png +0 -0
  60. package/build/images/BottomConstraint.png +0 -0
  61. package/build/images/CenterXConstraint.png +0 -0
  62. package/build/images/CenterYConstraint.png +0 -0
  63. package/build/images/CoreUI2.png +0 -0
  64. package/build/images/CoreUI2@2x.png +0 -0
  65. package/build/images/Desktop.png +0 -0
  66. package/build/images/DesktopMini.png +0 -0
  67. package/build/images/EqualHeight.png +0 -0
  68. package/build/images/EqualHorizontalSpacing.png +0 -0
  69. package/build/images/EqualHorizontalSpacingInSuperview.png +0 -0
  70. package/build/images/EqualVerticalSpacing.png +0 -0
  71. package/build/images/EqualVerticalSpacingInSuperview.png +0 -0
  72. package/build/images/EqualWidth.png +0 -0
  73. package/build/images/HeightConstraint.png +0 -0
  74. package/build/images/InactiveConstraints.png +0 -0
  75. package/build/images/Layout.png +0 -0
  76. package/build/images/LayoutVariables.png +0 -0
  77. package/build/images/LeftConstraint.png +0 -0
  78. package/build/images/OwnConstraints.png +0 -0
  79. package/build/images/Phone.png +0 -0
  80. package/build/images/PhoneLandscape.png +0 -0
  81. package/build/images/PhoneLandscapeMini.png +0 -0
  82. package/build/images/PhoneMini.png +0 -0
  83. package/build/images/PhonePortrait.png +0 -0
  84. package/build/images/PhonePortraitMini.png +0 -0
  85. package/build/images/Properties.png +0 -0
  86. package/build/images/RightConstraint.png +0 -0
  87. package/build/images/SubviewConstraints.png +0 -0
  88. package/build/images/Tablet.png +0 -0
  89. package/build/images/TabletLandscape.png +0 -0
  90. package/build/images/TabletLandscapeMini.png +0 -0
  91. package/build/images/TabletMini.png +0 -0
  92. package/build/images/TabletPortrait.png +0 -0
  93. package/build/images/TabletPortraitMini.png +0 -0
  94. package/build/images/TopConstraint.png +0 -0
  95. package/build/images/WidthConstraint.png +0 -0
  96. package/build/index.js +40 -0
  97. package/lib/@types/BMCoreUI.min.d.ts +14078 -0
  98. package/lib/BMCoreUI.min.js +1 -0
  99. package/package.json +58 -0
@@ -0,0 +1,556 @@
1
+ // @ts-check
2
+
3
+ import {YES, NO, BMNumberByInterpolatingNumbersWithFraction} from './BMCoreUI'
4
+ import {BMSize} from './BMSize'
5
+ import {BMPoint} from './BMPoint'
6
+
7
+ // @type BMRect implements BMAnimating
8
+
9
+ /*
10
+ ****************************************************************************************************************************************************************
11
+ BMRect
12
+ ****************************************************************************************************************************************************************
13
+ */
14
+
15
+ /**
16
+ * A struct which represents a rectangle in two dimensions.
17
+ * It is defined by the origin of the rectangle and its size.
18
+ * @param origin <BMPoint, nullable> Defaults to (0, 0). The origin point.
19
+ * @param size <BMSize, nullable> Defaults to (0:0). The rect's size.
20
+ */
21
+ export function BMRect(origin, size) { // <constructor>
22
+ origin = origin || new BMPoint();
23
+ size = size || new BMSize();
24
+
25
+ this.origin = origin;
26
+ this.size = size;
27
+ };
28
+
29
+ BMRect.prototype = {
30
+
31
+ /**
32
+ * The rect's origin point.
33
+ */
34
+ origin: undefined, // <BMPoint>
35
+
36
+ /**
37
+ * The rect's size.
38
+ */
39
+ size: undefined, // <BMSize>
40
+
41
+ /**
42
+ * The X coordinate of this rect's right edge.
43
+ */
44
+ get right() { // <Number>
45
+ return this.origin.x + this.size.width
46
+ },
47
+
48
+ /**
49
+ * The Y coordinate of this rect's bottom edge.
50
+ */
51
+ get bottom() { // <Number>
52
+ return this.origin.y + this.size.height
53
+ },
54
+
55
+ /**
56
+ * The X coordinate of this rect's origin point.
57
+ */
58
+ get left() { // <Number>
59
+ return this.origin.x
60
+ },
61
+
62
+ /**
63
+ * The Y coordinate of this rect's origin point.
64
+ */
65
+ get top() { // <Number>
66
+ return this.origin.y
67
+ },
68
+
69
+ /**
70
+ * The rect's width.
71
+ */
72
+ get width() { // <Number>
73
+ return this.size.width;
74
+ },
75
+
76
+ /**
77
+ * The rect's height.
78
+ */
79
+ get height() { // <Number>
80
+ return this.size.height;
81
+ },
82
+
83
+ /**
84
+ * The rect's center point.
85
+ */
86
+ get center() { // <BMPoint>
87
+ return new BMPoint(this.origin.x + this.size.width / 2, this.origin.y + this.size.height / 2);
88
+ },
89
+ set center(center) {
90
+ var currentCenter = this.center;
91
+
92
+ this.offset(center.x - currentCenter.x, center.y - currentCenter.y);
93
+ },
94
+
95
+ /**
96
+ * Returns a rect that represents a copy of this rect by removing decimal values from both the origin point and the size components.
97
+ */
98
+ get integralRect() { // <BMRect>
99
+ return BMRectMake(this.origin.x | 0, this.origin.y | 0, this.size.width | 0, this.size.height | 0);
100
+ },
101
+
102
+ /**
103
+ * Initializes this rect by copying the values of the specified rect.
104
+ * @param rect <BMRect> The rect to copy.
105
+ * @return <BMRect> This rect.
106
+ */
107
+ initWithRect(rect) {
108
+ this.origin = rect.origin.copy();
109
+ this.size = rect.size.copy();
110
+ return this;
111
+ },
112
+
113
+
114
+ /**
115
+ * Determines whether this rect is equal to the target rect.
116
+ * @param rect <BMRect> The rect to check for equality.
117
+ * @return <Boolean> True if the rects are equal, false otherwise.
118
+ */
119
+ isEqualToRect: function (rect) {
120
+ return (rect.origin.x == this.origin.x && rect.origin.y == this.origin.y && this.size.width == rect.size.width && this.size.height == rect.size.height);
121
+ },
122
+
123
+ /**
124
+ * Determines whether this rect intersects the target rect in any point.
125
+ * @param rect <BMRect> The rect to check for intersection.
126
+ * @return <Boolean> YES if the rects intersect, NO otherwise.
127
+ */
128
+ intersectsRect: function (rect) {
129
+ if (this.isEqualToRect(rect)) return YES;
130
+
131
+ return !(rect.left > this.right ||
132
+ rect.right < this.left ||
133
+ rect.top > this.bottom ||
134
+ rect.bottom < this.top);
135
+ },
136
+
137
+ /**
138
+ * Determines whether this rect intersects the target rect in any point except the edges.
139
+ * @param rect <BMRect> The rect to check for intersection.
140
+ * @return <Boolean> YES if the rects intersect, NO otherwise.
141
+ */
142
+ intersectsContentOfRect: function (rect) {
143
+ if (this.isEqualToRect(rect)) return YES;
144
+
145
+ return !(rect.left >= this.right ||
146
+ rect.right <= this.left ||
147
+ rect.top >= this.bottom ||
148
+ rect.bottom <= this.top);
149
+ },
150
+
151
+ /**
152
+ * Creates and returns a new rect that represents the intersection between this rect and the target rect.
153
+ * If the rects do not intersect, the resulting rect will be undefiend.
154
+ * @param rect <BMRect> The rect.
155
+ * @return <BMRect, nullable> A rect.
156
+ */
157
+ rectByIntersectingWithRect: function (rect) {
158
+ var origin = new BMPoint(Math.max(this.left, rect.left), Math.max(this.top, rect.top));
159
+
160
+ var size = new BMSize(
161
+ Math.min(this.right, rect.right) - origin.x,
162
+ Math.min(this.bottom, rect.bottom) - origin.y
163
+ );
164
+
165
+ // If any of the sizes are negative, the rects do not intersect
166
+ if (size.width <= 0 || size.height <= 0) return undefined;
167
+
168
+ return new BMRect(origin, size);
169
+ },
170
+
171
+ /**
172
+ * Creates and returns a new rect that represents the union between this rect and the target rect.
173
+ * @param rect <BMRect> The rect.
174
+ * @return <BMRect> A rect.
175
+ */
176
+ rectByUnionWithRect(rect) {
177
+ let x = Math.min(this.origin.x, rect.origin.x);
178
+ let y = Math.min(this.origin.y, rect.origin.y);
179
+ let right = Math.max(this.right, rect.right);
180
+ let bottom = Math.max(this.bottom, rect.bottom);
181
+
182
+ return BMRectMake(x, y, right - x, bottom - y);
183
+ },
184
+
185
+ /**
186
+ * Creates and returns up to 4 rects which reprent the areas of this rect and the target rect that do not intersect.
187
+ * The resulting rects will first cover any horionztal area and then the vertical area.
188
+ * @return <AnyObject> The list of rects. Some of these rects may be missing, indicating that the two rects fit either vertically or horizontally.
189
+ */
190
+ rectsByExclusiveOrWithRect: function (rect) {
191
+ // TODO
192
+ throw new Error('This method is not available.')
193
+ },
194
+
195
+ /**
196
+ * Returns up to two rects that together make up the difference between this rect and the supplied rect.
197
+ * If the rects are identical or the target rect contains this rect, this function will return nothing.
198
+ * If the rects do not intersect, this function will return this rect.
199
+ * @param rect <BMRect> The rect.
200
+ * @return <[BMRect], nullable> A list of rects or undefined if the intersection is identical to either rect.
201
+ */
202
+ rectsWithDifferenceFromRect: function (rect) {
203
+ if (this.isEqualToRect(rect)) return undefined;
204
+
205
+ var intersection = this.rectByIntersectingWithRect(rect);
206
+
207
+ if (!intersection) return [this];
208
+
209
+ if (intersection.isEqualToRect(this)) return undefined;
210
+
211
+ // If the intersection rect has the same width or height as this rect, only one rect is the difference
212
+ if (intersection.size.height == this.size.height) {
213
+ return [BMRectMake(intersection.origin.x == this.origin.x ? intersection.right : this.origin.x,
214
+ this.origin.y,
215
+ this.size.width - intersection.size.width, this.size.height)];
216
+ }
217
+
218
+ if (intersection.size.width == this.size.width) {
219
+ return [BMRectMake(this.origin.x,
220
+ intersection.origin.y == this.origin.y ? intersection.bottom : this.origin.y,
221
+ this.size.width, this.size.height - intersection.size.height)];
222
+ }
223
+
224
+ // Otherwise two rects should be returned
225
+ var result = [];
226
+
227
+ // The first rect is a tall horizontal strip from one horizontal edge of this rect to the opposite horiztonal edge of the intersection
228
+ var firstRect = BMRectMake(intersection.origin.x == this.origin.x ? intersection.right : this.origin.x,
229
+ this.origin.y,
230
+ this.size.width - intersection.size.width, this.size.height)
231
+
232
+ // The second is the remaining shorter horiztonal strip
233
+ var secondRect = BMRectMake(firstRect.origin.x == this.origin.x ? firstRect.right : this.origin.x,
234
+ intersection.origin.y == this.origin.y ? intersection.bottom : this.origin.y,
235
+ this.size.width - firstRect.size.width, this.size.height - intersection.size.height);
236
+
237
+ return [firstRect, secondRect];
238
+
239
+ },
240
+
241
+ /**
242
+ * Determines if the target rect is completely included in this rect.
243
+ * The given rect will be considered to be contained within this rect even if they have equal positionining and sizing.
244
+ * @param rect <BMRect> The rect to check.
245
+ * @return <Boolean> YES if the rect is contained, NO otherwise. If the target rect is not valid, the result is undefined.
246
+ */
247
+ containsRect: function (rect) {
248
+ return (rect.left >= this.left &&
249
+ rect.top >= this.top &&
250
+ rect.right <= this.right &&
251
+ rect.bottom <= this.bottom);
252
+ },
253
+
254
+ /**
255
+ * Determines if the target point is strictly contained in this rect.
256
+ * @param point <BMPoint> The point to check.
257
+ * @return <Boolean> YES if the point is contained within this rect, NO if it is outside or on the edge of this rect.
258
+ */
259
+ containsPoint: function (point) {
260
+ return (point.x > this.left && point.x < this.right && point.y > this.top && point.y < this.bottom);
261
+ },
262
+
263
+ /**
264
+ * Determines if the target point is strictly contained in this rect or any of its edges.
265
+ * @param point <BMPoint> The point to check.
266
+ * @return <Boolean> YES if the point is contained within this rect or its edges, NO otherwise.
267
+ */
268
+ intersectsPoint: function (point) {
269
+ return (point.x >= this.left && point.x <= this.right && point.y >= this.top && point.y <= this.bottom);
270
+ },
271
+
272
+ /**
273
+ * Moves this rect in place by the specified positions.
274
+ * @param x <Number> The x amount.
275
+ * @param y <Number> The y amount.
276
+ */
277
+ offset: function (x, y) {
278
+ this.origin.x += x;
279
+ this.origin.y += y;
280
+ },
281
+
282
+ /**
283
+ * Moves this rect in place by the specified positions.
284
+ * @param x <Number, nullable> Defaults to 0. The x amount.
285
+ * {
286
+ * @param y <Number, nullable> Defaults to 0. The y amount.
287
+ * }
288
+ */
289
+ offsetWithX: function (x, args) {
290
+ this.origin.x += x || 0;
291
+ this.origin.y += (args && args.y) || 0;
292
+ },
293
+
294
+ /**
295
+ * Multiplies all of this rect's components by the given scalar.
296
+ * @param scalar <Number> The scalar by which to multiply this rect's components.
297
+ */
298
+ multiplyWithScalar(scalar) {
299
+ this.origin.x *= scalar;
300
+ this.origin.y *= scalar;
301
+ this.size.width *= scalar;
302
+ this.size.height *= scalar;
303
+ },
304
+
305
+ /**
306
+ * Returns a copy of this rect whose components are multiplied by the given scalar.
307
+ * @param scalar <Number> The scalar by which to multiply the rect's components.
308
+ * @return <BMRect> A rect.
309
+ */
310
+ rectByMultiplyingWithScalar(scalar) {
311
+ const rect = this.copy();
312
+ rect.multiplyWithScalar(scalar);
313
+ return rect;
314
+ },
315
+
316
+ /**
317
+ * Scales this rect by the given factor. The scale will be centered around the given
318
+ * point.
319
+ * @param factor <Number> The amount by which to scale the rect.
320
+ * {
321
+ * @param aroundPoint <BMPoint, nullable> Defaults to the rect's center point. The point around which to perform the scaling.
322
+ * }
323
+ */
324
+ scaleWithFactor(factor, args) {
325
+ const point = args && args.aroundPoint || this.center;
326
+
327
+ // The scaling is performed in such a way that the given point, expressed in terms
328
+ // of percentages of the rect's width and height remains constant after the scaling operation
329
+
330
+ // The percentage point is obtained by first converting the given point's coordinates to be relative to the
331
+ // rect's origin, then obtaining the percentage values
332
+ const percentagePoint = BMPointMake((point.x - this.origin.x) / this.size.width, (point.y - this.origin.y) / this.size.height);
333
+
334
+ // Scale the dimensions
335
+ this.size.width *= factor;
336
+ this.size.height *= factor;
337
+
338
+ // Move the origin point so that the ratio to the given point remains constant; this is essentially solving the equation at the
339
+ // beginning of this method for the origin point components
340
+ this.origin.x = point.x - percentagePoint.x * this.size.width;
341
+ this.origin.y = point.y - percentagePoint.y * this.size.height;
342
+ },
343
+
344
+ /**
345
+ * Returns a copy of this rect that is scaled by the given factor. The scale will be centered around the given
346
+ * point.
347
+ * @param factor <Number> The amount by which to scale the rect.
348
+ * {
349
+ * @param aroundPoint <BMPoint, nullable> Defaults to the rect's center point. The point around which to perform the scaling.
350
+ * }
351
+ * @return <BMRect> A rect.
352
+ */
353
+ rectByScalingWithFactor(factor, args) {
354
+ const rect = this.copy();
355
+ rect.scaleWithFactor(factor, args);
356
+ return rect;
357
+ },
358
+
359
+ /**
360
+ * @deprecated Use either `insetWithWidth(_, {height})` or `insetWithInset(_)`.
361
+ * --------------------------------------------------
362
+ * Contracts or expands this rect in place by the specified sizes. If the sizes are positive, the rect is inset, otherwise it is expanded.
363
+ * This method may be invoked in two ways:
364
+ * --------------------------------------------------
365
+ * @param width <Number> The horizontal amount.
366
+ * @param height <Number> The vertical amount.
367
+ * --------------------------------------------------
368
+ * @param insets <BMInset> The insets.
369
+ */
370
+ inset: function (width, height) {
371
+ if (height === undefined) {
372
+ this.origin.x += width.left;
373
+ this.origin.y += width.top;
374
+
375
+ this.size.width -= width.left + width.right;
376
+ this.size.height -= width.top + width.bottom;
377
+ }
378
+ else {
379
+ this.origin.x += width;
380
+ this.origin.y += height;
381
+
382
+ this.size.width -= 2 * width;
383
+ this.size.height -= 2 * height;
384
+ }
385
+ },
386
+
387
+ /**
388
+ * Contracts or expands this rect in place by the specified sizes. If the sizes are positive, the rect is inset, otherwise it is expanded.
389
+ * @param width <Number> The horizontal amount.
390
+ * {
391
+ * @param height <Number> The vertical amount.
392
+ * }
393
+ */
394
+ insetWithWidth: function (width, args) {
395
+ var height = args.height;
396
+ this.origin.x += width;
397
+ this.origin.y += height;
398
+
399
+ this.size.width -= 2 * width;
400
+ this.size.height -= 2 * height;
401
+ },
402
+
403
+ /**
404
+ * Contracts or expands this rect in place by the specified sizes. If the sizes are positive, the rect is inset, otherwise it is expanded.
405
+ * @param inset <BMInset> The inset to apply.
406
+ */
407
+ insetWithInset: function (inset) {
408
+ this.origin.x += inset.left;
409
+ this.origin.y += inset.top;
410
+
411
+ this.size.width -= inset.left + inset.right;
412
+ this.size.height -= inset.top + inset.bottom;
413
+ },
414
+
415
+ /**
416
+ * Constructs and returns a new rect that represents the rect that would be obtained by applying the given insets to this rect.
417
+ * @param inset <BMInset> The inset to apply.
418
+ * @return <BMRect> A new rect after applying the insets.
419
+ */
420
+ rectWithInset: function (inset) {
421
+ var rect = this.copy();
422
+ rect.insetWithInset(inset);
423
+ return rect;
424
+ },
425
+
426
+ /**
427
+ * Constructs and returns a new rect that represents the transform that should be applied to this rect
428
+ * for it to be identical to the given rect.
429
+ * The new rect's size represents the X and Y scales that should be applied to this rect, while the origin represents the translation.
430
+ * To achieve the correct results, the translation should be applied first and the scaling the second.
431
+ * @param rect <BMRect> The rect towards which to transform.
432
+ * @return <BMRect> The transformation rect.
433
+ */
434
+ rectWithTransformToRect: function (rect) {
435
+ var transformRect = BMRectMake();
436
+
437
+ transformRect.size.width = rect.size.width / this.size.width;
438
+ transformRect.size.height = rect.size.height / this.size.height;
439
+
440
+ var deltaX = rect.center.x - this.center.x;
441
+ var deltaY = rect.center.y - this.center.y;
442
+
443
+ transformRect.origin.x = deltaX;
444
+ transformRect.origin.y = deltaY;
445
+
446
+ return transformRect;
447
+ },
448
+
449
+ /**
450
+ * Creates a deep copy of this rect.
451
+ * @return <BMRect> A rect.
452
+ */
453
+ copy: function () {
454
+ var rect = new BMRect();
455
+ rect.origin.x = this.origin.x;
456
+ rect.origin.y = this.origin.y;
457
+
458
+ rect.size.width = this.size.width;
459
+ rect.size.height = this.size.height;
460
+ return rect;
461
+ },
462
+
463
+ /**
464
+ * Invoked by the CoreUI animation engine to obtain an interpolated
465
+ * value between this object and the target object.
466
+ * @param fraction <Number> The animation fraction.
467
+ * {
468
+ * @param toValue <BMRect> The object to which to interpolate.
469
+ * }
470
+ * @return <BMRect> A rect.
471
+ */
472
+ interpolatedValueWithFraction(fraction, args) {
473
+ var target = args.toValue;
474
+ return BMRectByInterpolatingRect(this, {toRect: target, withFraction: fraction});
475
+ },
476
+
477
+ toString() {
478
+ return `(${this.origin.x}:${this.origin.y})=>[${this.size.width}:${this.size.height}]`;
479
+ }
480
+
481
+ };
482
+
483
+ /**
484
+ * Creates and returns a rectangle that represents the interpolation between two rects with a given fraction.
485
+ * @param sourceRect <BMRect> The source rect.
486
+ * {
487
+ * @param toRect <BMRect> The target rect.
488
+ * @param withFraction <Number> The amount by which to interpolate. The fraction should be a number between 0 and 1, but going past these values is supported.
489
+ * Negative values will overshoot the source rect and values greater than 1 will overshoot the target rect.
490
+ * }
491
+ * @return <BMRect> A rect.
492
+ */
493
+ export function BMRectByInterpolatingRect(sourceRect, options) {
494
+ var targetRect = options.toRect;
495
+ var fraction = options.withFraction;
496
+
497
+ return BMRectMake(
498
+ BMNumberByInterpolatingNumbersWithFraction(sourceRect.origin.x, targetRect.origin.x, fraction),
499
+ BMNumberByInterpolatingNumbersWithFraction(sourceRect.origin.y, targetRect.origin.y, fraction),
500
+ BMNumberByInterpolatingNumbersWithFraction(sourceRect.size.width, targetRect.size.width, fraction),
501
+ BMNumberByInterpolatingNumbersWithFraction(sourceRect.size.height, targetRect.size.height, fraction)
502
+ );
503
+ }
504
+
505
+ /**
506
+ * Creates and returns a rectangle with the specified properties.
507
+ * @param x <Number, nullable> Defaults to 0. The rect's left origin.
508
+ * @param y <Number, nullable> Defaults to 0. The rect's top origin.
509
+ * @param width <Number, nullable> Defaults to 0. The rect's width.
510
+ * @param height <Number, nullable> Defaults to 0. The rect's height.
511
+ * @return <BMRect> A rect.
512
+ */
513
+ export function BMRectMake(x, y, width, height) {
514
+ return new BMRect(new BMPoint(x, y), new BMSize(width, height));
515
+ }
516
+
517
+
518
+ /**
519
+ * Creates and returns a rectangle with the specified properties.
520
+ * @param x <Number, nullable> Defaults to 0. The rect's left origin.
521
+ * {
522
+ * @param y <Number, nullable> Defaults to 0. The rect's top origin.
523
+ * @param width <Number, nullable> Defaults to 0. The rect's width.
524
+ * @param height <Number, nullable> Defaults to 0. The rect's height.
525
+ * }
526
+ * @return <BMRect> A rect.
527
+ */
528
+ export function BMRectMakeWithX(x, args) {
529
+ return new BMRect(new BMPoint(x, args && args.y), new BMSize(args && args.width, args && args.height));
530
+ }
531
+
532
+ /**
533
+ * Creates and returns a rectangle with the specified properties.
534
+ * @param origin <BMPoint, nullable> Defaults to (0, 0). The rect's origin point.
535
+ * {
536
+ * @param size <BMSize, nullable> Defaults to [0, 0]. The rect's size.
537
+ * }
538
+ * @return <BMRect> A rect.
539
+ */
540
+ export function BMRectMakeWithOrigin(origin, args) {
541
+ return new BMRect(origin || new BMPoint(), (args && args.size) || new BMSize());
542
+ }
543
+
544
+ /**
545
+ * Creates and returns a rectangle that represents the area of the document currently occupied by the given DOM node.
546
+ * The coordinates will be relative to the viewport and will take into account the current document scroll position.
547
+ * @param DOMNode <DOMNode> The node whose frame to get.
548
+ * @return <BMRect> A rect.
549
+ */
550
+ export function BMRectMakeWithNodeFrame(DOMNode) {
551
+ var boundingClientRect = DOMNode.getBoundingClientRect();
552
+
553
+ return new BMRect(new BMPoint(boundingClientRect.left, boundingClientRect.top), new BMSize(boundingClientRect.width, boundingClientRect.height));
554
+ }
555
+
556
+ // @endtype
@@ -0,0 +1,137 @@
1
+ // @ts-check
2
+
3
+ import {BMNumberByInterpolatingNumbersWithFraction} from './BMCoreUI'
4
+ import {BMPoint} from './BMPoint'
5
+ import {BMRect} from './BMRect'
6
+
7
+ // @type BMSize implements BMAnimating
8
+
9
+ /*
10
+ ****************************************************************************************************************************************************************
11
+ BMSize
12
+ ****************************************************************************************************************************************************************
13
+ */
14
+
15
+ /**
16
+ * A struct which represents a size in two dimensions
17
+ * @param width <Number, nullable> Defaults to 0. The width.
18
+ * @param height <Number, nullable> Defaults to 0. The height.
19
+ */
20
+ export function BMSize(width, height) { // <constructor>
21
+ width = width || 0;
22
+ height = height || 0;
23
+
24
+ this.width = width;
25
+ this.height = height;
26
+ };
27
+
28
+ BMSize.prototype = {
29
+
30
+ /**
31
+ * The size's width component.
32
+ */
33
+ width: 0, // <Number>
34
+
35
+ /**
36
+ * The size's height component.
37
+ */
38
+ height: 0, // <Number>
39
+
40
+ /**
41
+ * Initializes this size by copying the values of the specified size.
42
+ * @param size <BMSize> The size to copy.
43
+ * @return <BMSize> This size.
44
+ */
45
+ initWithSize(size) {
46
+ this.width = size.width;
47
+ this.height = size.height;
48
+ return this;
49
+ },
50
+
51
+ /**
52
+ * Creates a new rect with its origin at (0, 0) with this size.
53
+ * @return <BMRect> A rect.
54
+ */
55
+ newRectWithSize: function () {
56
+ return new BMRect(new BMPoint(), this);
57
+ },
58
+
59
+ /**
60
+ * Creates and returns a new size with the same attributes as this size.
61
+ * @return <BMSize> A size.
62
+ */
63
+ copy: function () {
64
+ return new BMSize(this.width, this.height);
65
+ },
66
+
67
+ /**
68
+ * Tests whether this size is identical to the given size.
69
+ * @param size <BMSize> A size.
70
+ * @return <Boolean> YES if the sizes are identical, NO otherwise.
71
+ */
72
+ isEqualToSize: function (size) {
73
+ return size.width === this.width && size.height === this.height;
74
+ },
75
+
76
+ /**
77
+ * Tests whether this size is greater than or equal to the given size. The size
78
+ * is considered to be greater than or equal if both of its dimensions are each greater than or equal
79
+ * to the given size.
80
+ * @param size <BMSize> The size to test against.
81
+ * @return <Boolean> `YES` if this size is greater than or equal than the given size, `NO` otherwise.
82
+ */
83
+ isGreaterThanSize: function (size) {
84
+ return this.width >= size.width && this.height >= size.height;
85
+ },
86
+
87
+ /**
88
+ * Tests whether this size is less than or equal to the given size. The size
89
+ * is considered to be less than or equal if both of its dimensions are each less than or equal
90
+ * to the given size.
91
+ * @param size <BMSize> The size to test against.
92
+ * @return <Boolean> `YES` if this size is less than or equal than the given size, `NO` otherwise.
93
+ */
94
+ isLessThanSize: function (size) {
95
+ return this.width <= size.width && this.height <= size.height;
96
+ },
97
+
98
+ /**
99
+ * Invoked by the CoreUI animation engine to obtain an interpolated
100
+ * value between this object and the target object.
101
+ * @param fraction <Number> The animation fraction.
102
+ * {
103
+ * @param toValue <BMSize> The object to which to interpolate.
104
+ * }
105
+ * @return <BMSize> A size.
106
+ */
107
+ interpolatedValueWithFraction(fraction, args) {
108
+ var target = args.toValue;
109
+ return BMSizeMake(
110
+ BMNumberByInterpolatingNumbersWithFraction(this.width, target.width, fraction),
111
+ BMNumberByInterpolatingNumbersWithFraction(this.height, target.height, fraction)
112
+ );
113
+ },
114
+
115
+
116
+ /**
117
+ * Returns a string representation of this size.
118
+ * @return <String> A string.
119
+ */
120
+ toString() {
121
+ return `[${this.width}:${this.height}]`;
122
+ }
123
+
124
+ }
125
+
126
+
127
+ /**
128
+ * Creates and returns a new size.
129
+ * @param width <Number, nullable> Defaults to 0. The width.
130
+ * @param height <Number, nullable> Defaults to 0. The height.
131
+ * @return <BMSize> A size.
132
+ */
133
+ export function BMSizeMake(width, height) {
134
+ return new BMSize(width, height);
135
+ }
136
+
137
+ // @endtype