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.
- package/CHANGELOG.md +1624 -0
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/build/@types/index.d.ts +14078 -0
- package/build/BMCodeEditor/BMCodeEditor.js +707 -0
- package/build/BMCollectionView/BMCollectionView.js +5861 -0
- package/build/BMCollectionView/BMCollectionViewCell.js +688 -0
- package/build/BMCollectionView/BMCollectionViewFlowLayout.js +4467 -0
- package/build/BMCollectionView/BMCollectionViewLayout.js +830 -0
- package/build/BMCollectionView/BMCollectionViewLayoutAttributes.js +673 -0
- package/build/BMCollectionView/BMCollectionViewMasonryLayout.js +491 -0
- package/build/BMCollectionView/BMCollectionViewStackLayout.js +634 -0
- package/build/BMCollectionView/BMCollectionViewTileLayout.js +1121 -0
- package/build/BMCoreUI.css +2833 -0
- package/build/BMView/BMAttributedLabelView.js +310 -0
- package/build/BMView/BMLayoutConstraint_v2.5.js +1813 -0
- package/build/BMView/BMLayoutGuide.js +192 -0
- package/build/BMView/BMLayoutSizeClass.js +466 -0
- package/build/BMView/BMMenu.js +574 -0
- package/build/BMView/BMScrollView.js +247 -0
- package/build/BMView/BMTextField.js +512 -0
- package/build/BMView/BMTextFieldDelegate.js +71 -0
- package/build/BMView/BMView_v2.5.js +3572 -0
- package/build/BMView/BMViewport.js +221 -0
- package/build/BMViewLayoutEditor/BMLayoutEditor.js +6117 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorConstraintSettings.js +417 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorDelegate.js +59 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingCells.js +1653 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettings.js +1480 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingsComplexCells.js +431 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingsDelegate.js +46 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorVariablesController.js +460 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorViewGroupSettings.js +293 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorViewSettings.js +382 -0
- package/build/BMViewLayoutEditor/BMLayoutVariableProvider.js +202 -0
- package/build/BMWindow/BMConfirmationPopup.js +477 -0
- package/build/BMWindow/BMKeyboardShortcut.js +151 -0
- package/build/BMWindow/BMPopover/BMPopover.js +492 -0
- package/build/BMWindow/BMToolWindow.js +71 -0
- package/build/BMWindow/BMWindow.js +2000 -0
- package/build/Core/BMAnimationContext.js +1181 -0
- package/build/Core/BMColor.js +991 -0
- package/build/Core/BMCoreUI.js +470 -0
- package/build/Core/BMFunctionCollection.js +110 -0
- package/build/Core/BMIndexPath.js +165 -0
- package/build/Core/BMInset.js +138 -0
- package/build/Core/BMKeyPath.js +100 -0
- package/build/Core/BMPoint.js +291 -0
- package/build/Core/BMRect.js +556 -0
- package/build/Core/BMSize.js +137 -0
- package/build/iScroll/LICENSE +22 -0
- package/build/iScroll/iscroll-probe.js +2154 -0
- package/build/images/AlignBottom.png +0 -0
- package/build/images/AlignCenterX.png +0 -0
- package/build/images/AlignCenterY.png +0 -0
- package/build/images/AlignLeading.png +0 -0
- package/build/images/AlignTop.png +0 -0
- package/build/images/AlignTrailing.png +0 -0
- package/build/images/AllConstraints.png +0 -0
- package/build/images/BottomConstraint.png +0 -0
- package/build/images/CenterXConstraint.png +0 -0
- package/build/images/CenterYConstraint.png +0 -0
- package/build/images/CoreUI2.png +0 -0
- package/build/images/CoreUI2@2x.png +0 -0
- package/build/images/Desktop.png +0 -0
- package/build/images/DesktopMini.png +0 -0
- package/build/images/EqualHeight.png +0 -0
- package/build/images/EqualHorizontalSpacing.png +0 -0
- package/build/images/EqualHorizontalSpacingInSuperview.png +0 -0
- package/build/images/EqualVerticalSpacing.png +0 -0
- package/build/images/EqualVerticalSpacingInSuperview.png +0 -0
- package/build/images/EqualWidth.png +0 -0
- package/build/images/HeightConstraint.png +0 -0
- package/build/images/InactiveConstraints.png +0 -0
- package/build/images/Layout.png +0 -0
- package/build/images/LayoutVariables.png +0 -0
- package/build/images/LeftConstraint.png +0 -0
- package/build/images/OwnConstraints.png +0 -0
- package/build/images/Phone.png +0 -0
- package/build/images/PhoneLandscape.png +0 -0
- package/build/images/PhoneLandscapeMini.png +0 -0
- package/build/images/PhoneMini.png +0 -0
- package/build/images/PhonePortrait.png +0 -0
- package/build/images/PhonePortraitMini.png +0 -0
- package/build/images/Properties.png +0 -0
- package/build/images/RightConstraint.png +0 -0
- package/build/images/SubviewConstraints.png +0 -0
- package/build/images/Tablet.png +0 -0
- package/build/images/TabletLandscape.png +0 -0
- package/build/images/TabletLandscapeMini.png +0 -0
- package/build/images/TabletMini.png +0 -0
- package/build/images/TabletPortrait.png +0 -0
- package/build/images/TabletPortraitMini.png +0 -0
- package/build/images/TopConstraint.png +0 -0
- package/build/images/WidthConstraint.png +0 -0
- package/build/index.js +40 -0
- package/lib/@types/BMCoreUI.min.d.ts +14078 -0
- package/lib/BMCoreUI.min.js +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {YES, NO} from './BMCoreUI'
|
|
4
|
+
|
|
5
|
+
// @type BMIndexPath<T = any>
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
****************************************************************************************************************************************************************
|
|
9
|
+
BMIndexPath
|
|
10
|
+
****************************************************************************************************************************************************************
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A BMIndexPath object manages the mapping between an object and its position within a data set.
|
|
15
|
+
* It represents an ordered list of indexes that should be traversed within a data set to reach a given object.
|
|
16
|
+
*
|
|
17
|
+
* Optionally, and index path may also contain a reference to the object to which its indexes point.
|
|
18
|
+
*
|
|
19
|
+
* Index paths should be created using one of the `BMIndexPathMake` functions rather than using the constructor.
|
|
20
|
+
*/
|
|
21
|
+
export function BMIndexPath() {} // <constructor>
|
|
22
|
+
|
|
23
|
+
BMIndexPath.prototype = {
|
|
24
|
+
/**
|
|
25
|
+
* The object.
|
|
26
|
+
*/
|
|
27
|
+
object: undefined, // <T, nullable>
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The ordered list of indexes.
|
|
31
|
+
*/
|
|
32
|
+
indexes: undefined, // <[Int]>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initializes this index path by copying the values of the given index path.
|
|
36
|
+
* @param indexPath <BMIndexPath<T>> The index path to copy.
|
|
37
|
+
* @return <BMIndexPath<T>> This index path.
|
|
38
|
+
*/
|
|
39
|
+
initWithIndexPath(indexPath) {
|
|
40
|
+
this.object = indexPath.object;
|
|
41
|
+
this.indexes = indexPath.indexes.slice();
|
|
42
|
+
return this;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The object's row. This corresponds to the second index.
|
|
47
|
+
*/
|
|
48
|
+
get row() { // <Int>
|
|
49
|
+
return this.indexes[1];
|
|
50
|
+
},
|
|
51
|
+
set row(row) {
|
|
52
|
+
this.indexes[1] = row;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The object's section. This corresponds to the first index.
|
|
57
|
+
*/
|
|
58
|
+
get section() { // <Int>
|
|
59
|
+
return this.indexes[0];
|
|
60
|
+
},
|
|
61
|
+
set section(section) {
|
|
62
|
+
this.indexes[0] = section;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Creates and returns a new <code>BMIndexPath</code> instance with the same property values
|
|
67
|
+
* as this index path.
|
|
68
|
+
* @return <BMIndexPath<T>> An index path.
|
|
69
|
+
*/
|
|
70
|
+
copy: function () {
|
|
71
|
+
var result = new BMIndexPath();
|
|
72
|
+
result.object = this.object;
|
|
73
|
+
result.indexes = this.indexes.slice();
|
|
74
|
+
return result;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Used to test if two index paths are strictly equal.
|
|
79
|
+
* Two index paths are strictly equal if the contain the same indexes and point to the same object.
|
|
80
|
+
* @param indexPath <BMIndexPath, nullable> The index path. If undefined, this method returns NO.
|
|
81
|
+
* {
|
|
82
|
+
* @param usingComparator <Boolean ^ (Object, Object)> The comparator used to compare the pointed object.
|
|
83
|
+
* }
|
|
84
|
+
* @return <Boolean> YES if the index paths are strictly equal, NO otherwise.
|
|
85
|
+
*/
|
|
86
|
+
isEqualToIndexPath: function (indexPath, options) {
|
|
87
|
+
if (!indexPath || indexPath == BMIndexPathNone) return NO;
|
|
88
|
+
|
|
89
|
+
if (indexPath.indexes.length != this.indexes.length) return NO;
|
|
90
|
+
for (var i = 0; i < this.indexes.length; i++) {
|
|
91
|
+
if (this.indexes[i] != indexPath.indexes[i]) return NO;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return options.usingComparator(this.object, indexPath.object);
|
|
95
|
+
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Used to test if two index paths represent the same element, even if they have a different position in the data set.
|
|
100
|
+
* Two index paths are loosely equal if they refer to the same object or if they both refer to no object but have equal indexes.
|
|
101
|
+
* @param indexPath <BMIndexPath, nullable> The index path. If undefined, this method returns NO.
|
|
102
|
+
* {
|
|
103
|
+
* @param usingComparator <Boolean ^ (Object, Object)> The comparator used to compare the pointed object.
|
|
104
|
+
* }
|
|
105
|
+
* @return <Boolean> YES if the index paths are loosely equal, NO otherwise.
|
|
106
|
+
*/
|
|
107
|
+
isLooselyEqualToIndexPath: function (indexPath, options) {
|
|
108
|
+
if (!indexPath || indexPath == BMIndexPathNone) return NO;
|
|
109
|
+
|
|
110
|
+
if (indexPath.object === undefined && this.object === undefined) {
|
|
111
|
+
if (indexPath.indexes.length != this.indexes.length) return NO;
|
|
112
|
+
for (var i = 0; i < this.indexes.length; i++) {
|
|
113
|
+
if (this.indexes[i] != indexPath.indexes[i]) return NO;
|
|
114
|
+
}
|
|
115
|
+
return YES;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return options.usingComparator(this.object, indexPath.object);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* An index path that points to no object.
|
|
126
|
+
* This index path will return NO when tested for equality, even against itself.
|
|
127
|
+
*/
|
|
128
|
+
export var BMIndexPathNone = BMIndexPathMakeWithRow(NaN, {section: NaN, forObject: NaN}); // <BMIndexPath<any>>
|
|
129
|
+
BMIndexPathNone.section = NaN;
|
|
130
|
+
BMIndexPathNone.isEqualToIndexPath = function () { return NO; };
|
|
131
|
+
BMIndexPathNone.isLooselyEqualToIndexPath = function () { return NO; };
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Constructs and returns a new BMIndexPath object initialized to the given row and section.
|
|
135
|
+
* @param row <Int> The row number.
|
|
136
|
+
* {
|
|
137
|
+
* @param section <Int, nullable> Defaults to 0. The section number.
|
|
138
|
+
* @param forObject <Object, nullable> The object.
|
|
139
|
+
* }
|
|
140
|
+
* @return <BMIndexPath> An index path.
|
|
141
|
+
*/
|
|
142
|
+
export function BMIndexPathMakeWithRow(row, options) {
|
|
143
|
+
var indexPath = new BMIndexPath();
|
|
144
|
+
indexPath.indexes = [(options && options.section) || 0, row];
|
|
145
|
+
indexPath.object = (options && options.forObject);
|
|
146
|
+
return indexPath;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Constructs and returns a new BMIndexPath object initialized to the given indexes.
|
|
152
|
+
* @param indexes <[Int]> The indexes.
|
|
153
|
+
* {
|
|
154
|
+
* @param forObject <Object, nullable> Optional. The object.
|
|
155
|
+
* }
|
|
156
|
+
* @return <BMIndexPath> An index path.
|
|
157
|
+
*/
|
|
158
|
+
export function BMIndexPathMakeWithIndexes(indexes, options) {
|
|
159
|
+
var indexPath = new BMIndexPath();
|
|
160
|
+
indexPath.indexes = indexes;
|
|
161
|
+
indexPath.object = options ? options.forObject : undefined;
|
|
162
|
+
return indexPath;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// @endtype
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
// @type BMInset
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
****************************************************************************************************************************************************************
|
|
7
|
+
BMInset
|
|
8
|
+
****************************************************************************************************************************************************************
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A struct which represents the insets which may be applied to a rect such a view's frame.
|
|
13
|
+
* An inset is represented by four numbers, each representing the amount by which each rect's edge should be inset.
|
|
14
|
+
* If an inset is positive, the rect edge will be inset (move towards the center) by that amount,
|
|
15
|
+
* if it is negative, the rect edge will be outset (move away from the center) by that amount.
|
|
16
|
+
*/
|
|
17
|
+
export function BMInset(left, top, right, bottom) { // <constructor>
|
|
18
|
+
this.left = left || 0;
|
|
19
|
+
this.top = top || 0;
|
|
20
|
+
this.right = right || 0;
|
|
21
|
+
this.bottom = bottom || 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
BMInset.prototype = {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The left edge inset.
|
|
28
|
+
*/
|
|
29
|
+
left: 0, // <Number>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The top edge inset.
|
|
33
|
+
*/
|
|
34
|
+
top: 0, // <Number>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The right edge inset.
|
|
38
|
+
*/
|
|
39
|
+
right: 0, // <Number>
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The bottom edge inset.
|
|
43
|
+
*/
|
|
44
|
+
bottom: 0, // <Number>
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Initializes this inset with the values of the given inset object.
|
|
48
|
+
* @param inset <BMInset> The inset to copy.
|
|
49
|
+
* @return <BMInset> This inset.
|
|
50
|
+
*/
|
|
51
|
+
initWithInset(inset) {
|
|
52
|
+
this.left = inset.left;
|
|
53
|
+
this.top = inset.top;
|
|
54
|
+
this.right = inset.right;
|
|
55
|
+
this.bottom = inset.bottom;
|
|
56
|
+
|
|
57
|
+
return this;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Tests whether this inset is equal to the given inset.
|
|
62
|
+
* The two insets are equal if their components are all equal.
|
|
63
|
+
* @param inset <BMInset> The inset to test against.
|
|
64
|
+
* @return <Boolean> `YES` if the two insets are equal, `NO` otherwise.
|
|
65
|
+
*/
|
|
66
|
+
isEqualToInset(inset) {
|
|
67
|
+
return (this.left === inset.left && this.top === inset.top && this.right === inset.right && this.bottom === inset.bottom);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates and returns a copy of this BMInset object.
|
|
72
|
+
* @return <BMInset> An inset object.
|
|
73
|
+
*/
|
|
74
|
+
copy: function () {
|
|
75
|
+
return new BMInset(this.left, this.top, this.right, this.bottom);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Constructs and returns a new inset with all four edges having the same value.
|
|
82
|
+
* @param insets <Number, nullable> Defaults to 0. The inset value to use for all four edges.
|
|
83
|
+
* @return <BMInset> An inset.
|
|
84
|
+
*/
|
|
85
|
+
export function BMInsetMakeWithEqualInsets(insets) {
|
|
86
|
+
insets = insets || 0;
|
|
87
|
+
return BMInsetMake(insets, insets, insets, insets);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Constructs and returns a new inset with all four edges having the same value.
|
|
93
|
+
* @param insets <Number, nullable> Defaults to 0. The inset value to use for all four edges.
|
|
94
|
+
* @return <BMInset> An inset.
|
|
95
|
+
*/
|
|
96
|
+
BMInset.insetWithEqualInsets = BMInsetMakeWithEqualInsets;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates and returns an inset object.
|
|
100
|
+
* @param left <Number, nullable> Defaults to 0. The left inset.
|
|
101
|
+
* @param top <Number, nullable> Defaults to 0. The top inset.
|
|
102
|
+
* @param right <Number, nullable> Defaults to 0. The right inset.
|
|
103
|
+
* @param bottom <Number, nullable> Defaults to 0. The bottom inset.
|
|
104
|
+
* @return <BMInset> An insets object.
|
|
105
|
+
*/
|
|
106
|
+
export function BMInsetMake(left, top, right, bottom) {
|
|
107
|
+
return new BMInset(left, top, right, bottom);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Creates and returns an inset object.
|
|
112
|
+
* @param left <Number, nullable> Defaults to 0. The left inset.
|
|
113
|
+
* {
|
|
114
|
+
* @param top <Number, nullable> Defaults to 0. The top inset.
|
|
115
|
+
* @param right <Number, nullable> Defaults to 0. The right inset.
|
|
116
|
+
* @param bottom <Number, nullable> Defaults to 0. The bottom inset.
|
|
117
|
+
* }
|
|
118
|
+
* @return <BMInset> An insets object.
|
|
119
|
+
*/
|
|
120
|
+
export function BMInsetMakeWithLeft(left, args) {
|
|
121
|
+
args = args || {};
|
|
122
|
+
return new BMInset(left || 0, args.top || 0, args.right || 0, args.bottom || 0);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates and returns an inset object.
|
|
128
|
+
* @param left <Number, nullable> Defaults to 0. The left inset.
|
|
129
|
+
* {
|
|
130
|
+
* @param top <Number, nullable> Defaults to 0. The top inset.
|
|
131
|
+
* @param right <Number, nullable> Defaults to 0. The right inset.
|
|
132
|
+
* @param bottom <Number, nullable> Defaults to 0. The bottom inset.
|
|
133
|
+
* }
|
|
134
|
+
* @return <BMInset> An insets object.
|
|
135
|
+
*/
|
|
136
|
+
BMInset.insetWithLeft = BMInsetMakeWithLeft;
|
|
137
|
+
|
|
138
|
+
// @endtype
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
// @type BMKeyPath
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
****************************************************************************************************************************************************************
|
|
7
|
+
BMKeyPath
|
|
8
|
+
****************************************************************************************************************************************************************
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A BMKeyPath object represents an ordered list of key names that should be traversed within a data set to reach a given object.
|
|
14
|
+
* Key paths should be created using one of the `BMKeyPathMake` functions rather than using the constructor.
|
|
15
|
+
*/
|
|
16
|
+
export function BMKeyPath() {}; // <constructor>
|
|
17
|
+
|
|
18
|
+
BMKeyPath.prototype = {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The list of keys which should be traversed by this key path.
|
|
22
|
+
*/
|
|
23
|
+
_components: undefined, // <[String]>
|
|
24
|
+
|
|
25
|
+
get components() {
|
|
26
|
+
return this._components.slice();
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Initializes this key path by parsing the given string.
|
|
31
|
+
* The key path components should be separated by periods. If a key contains a period in its name
|
|
32
|
+
* that period should be escaped using the '\' character.
|
|
33
|
+
* @param string <String> The string which represents the key path.
|
|
34
|
+
*/
|
|
35
|
+
initWithString: function (string) {
|
|
36
|
+
// TODO escaped periods
|
|
37
|
+
this._components = string.split('.');
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Initializes this key path using the specified list of ordered key names.
|
|
42
|
+
* @param components <[String]> The array of keys.
|
|
43
|
+
*/
|
|
44
|
+
initWithComponents: function (components) {
|
|
45
|
+
this._components = components.slice();
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Traverses this key path on the given object, returning the value for the last key.
|
|
50
|
+
* If any of the intermediary objects are undefined, this method will return undefined.
|
|
51
|
+
* @param object <AnyObject> The object which should be traversed.
|
|
52
|
+
* {
|
|
53
|
+
* @param withLimit <Number, nullable> Defaults to this key path's length. The number of keys to use when traversing.
|
|
54
|
+
* }
|
|
55
|
+
* @return <AnyObject, nullable> The value at the end of this key path, or undefined if the object could not be traversed
|
|
56
|
+
* for the entire key path.
|
|
57
|
+
*/
|
|
58
|
+
valueForObject: function (object, args) {
|
|
59
|
+
var value = object;
|
|
60
|
+
var length = Math.min(this._components.length, (args && args.withLimit) || this._components.length);
|
|
61
|
+
|
|
62
|
+
for (var i = 0; i < length; i++) {
|
|
63
|
+
value = value[this._components[i]];
|
|
64
|
+
|
|
65
|
+
if (typeof value === 'undefined') return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return value;
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Constructs and returns a new key path by parsing the given string.
|
|
77
|
+
* The key path components should be separated by periods. If a key contains a period in its name
|
|
78
|
+
* that period should be escaped using the '\' character.
|
|
79
|
+
* @param string <String> The string which represents the key path.
|
|
80
|
+
* @return <BMKeyPath> A key path.
|
|
81
|
+
*/
|
|
82
|
+
export function BMKeyPathMakeWithString(string) {
|
|
83
|
+
|
|
84
|
+
return (new BMKeyPath).initWithString(string);
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Constructs and returns a new key path using the specified list of ordered key names.
|
|
91
|
+
* @param components <[String]> The array of keys.
|
|
92
|
+
* @return <BMKeyPath> A key path.
|
|
93
|
+
*/
|
|
94
|
+
export function BMKeyPathMakeWithComponents(components) {
|
|
95
|
+
|
|
96
|
+
return (new BMKeyPath).initWithComponents(components);
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// @endtype
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {BMNumberByInterpolatingNumbersWithFraction, BMExtend} from './BMCoreUI'
|
|
4
|
+
|
|
5
|
+
// @type BMPoint implements BMAnimating
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
****************************************************************************************************************************************************************
|
|
9
|
+
BMPoint
|
|
10
|
+
****************************************************************************************************************************************************************
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A struct which represents a point in two dimensions.
|
|
15
|
+
* @param x <Number, nullable> Defaults to 0. The x coordinate.
|
|
16
|
+
* @param y <Number, nullable> Defaults to 0. The y coordinate.
|
|
17
|
+
*/
|
|
18
|
+
export function BMPoint(x, y) { // <constructor>
|
|
19
|
+
x = x || 0;
|
|
20
|
+
y = y || 0;
|
|
21
|
+
|
|
22
|
+
this.x = x;
|
|
23
|
+
this.y = y;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
BMPoint.prototype = {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The point's X coordinate.
|
|
30
|
+
*/
|
|
31
|
+
x: 0, // <Number>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The point's Y coordinate.
|
|
35
|
+
*/
|
|
36
|
+
y: 0, // <Number>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The point's polar radius coordinate.
|
|
40
|
+
*/
|
|
41
|
+
get r() { // <Number>
|
|
42
|
+
return BMDistanceBetweenPoints(this, BMOriginPoint);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
set r(r) {
|
|
46
|
+
const t = this.t;
|
|
47
|
+
|
|
48
|
+
this.x = r * Math.cos(t);
|
|
49
|
+
this.y = r * Math.sin(t);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The point's polar angle coordinate.
|
|
54
|
+
*/
|
|
55
|
+
get t() { // <Number>
|
|
56
|
+
return BMSlopeAngleBetweenPoints(BMOriginPoint, this);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
set t(t) {
|
|
60
|
+
const r = this.r;
|
|
61
|
+
|
|
62
|
+
this.x = r * Math.cos(t);
|
|
63
|
+
this.y = r * Math.sin(t);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Initializes this point by copying the values of the given point.
|
|
68
|
+
* @param point <BMPoint> The point to copy.
|
|
69
|
+
* @return <BMPoint> This point.
|
|
70
|
+
*/
|
|
71
|
+
initWithPoint(point) {
|
|
72
|
+
this.x = point.x;
|
|
73
|
+
this.y = point.y;
|
|
74
|
+
return this;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns a string representation of this point.
|
|
79
|
+
*/
|
|
80
|
+
get stringValue() {
|
|
81
|
+
return this.x + ',' + this.y;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns a string representation of this point.
|
|
86
|
+
* This property removes the fractional part of the components in the serialized representation.
|
|
87
|
+
*/
|
|
88
|
+
get integerStringValue() {
|
|
89
|
+
return (this.x | 0) + ',' + (this.y | 0);
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Returns a point with the same coordinates as this point, but without their fractional parts.
|
|
94
|
+
*/
|
|
95
|
+
get integerPointValue() {
|
|
96
|
+
return BMPointMake(this.x | 0, this.y | 0);
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns a point with the same coordinates as this point, but without their fractional parts.
|
|
101
|
+
*/
|
|
102
|
+
get integralPoint() {
|
|
103
|
+
return this.integerPointValue;
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Tests whether this point is equal to the given point.
|
|
108
|
+
* @param point <BMPoint> The point.
|
|
109
|
+
* @return <Boolean> YES if the points are equal, NO otherwise.
|
|
110
|
+
*/
|
|
111
|
+
isEqualToPoint: function (point) {
|
|
112
|
+
return this.x == point.x && this.y == point.y;
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Returns a copy of this point.
|
|
117
|
+
* @return <BMPoint> A point.
|
|
118
|
+
*/
|
|
119
|
+
copy: function () {
|
|
120
|
+
return BMPointMake(this.x, this.y);
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Multiplies all of this point's components by the given scalar.
|
|
125
|
+
* @param scalar <Number> The scalar by which to multiply this point's components.
|
|
126
|
+
*/
|
|
127
|
+
multiplyWithScalar(scalar) {
|
|
128
|
+
this.x *= scalar;
|
|
129
|
+
this.y *= scalar;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns a copy of this point whose components are multiplied by the given scalar.
|
|
134
|
+
* @param scalar <Number> The scalar by which to multiply the point's components.
|
|
135
|
+
* @return <BMPoint> A point.
|
|
136
|
+
*/
|
|
137
|
+
pointByMultiplyingWithScalar(scalar) {
|
|
138
|
+
const point = this.copy();
|
|
139
|
+
point.multiplyWithScalar(scalar);
|
|
140
|
+
return point;
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Constructs and returns a point that represents the sum of the components of this point and the given point.
|
|
145
|
+
* @param point <BMPoint> The point.
|
|
146
|
+
* @return <BMPoint> A point.
|
|
147
|
+
*/
|
|
148
|
+
pointByAddingPoint(point) {
|
|
149
|
+
return BMPointMake(this.x + point.x, this.y + point.y);
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Constructs and returns a point that represents the difference of the components of this point and the given point.
|
|
154
|
+
* @param point <BMPoint> The point.
|
|
155
|
+
* @return <BMPoint> A point.
|
|
156
|
+
*/
|
|
157
|
+
pointBySubtractingPoint(point) {
|
|
158
|
+
return BMPointMake(this.x - point.x, this.y - point.y);
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Computes and returns the distance from this point to the given point.
|
|
163
|
+
* @param point <BMPoint> A point.
|
|
164
|
+
* @return <Number> The distance.
|
|
165
|
+
*/
|
|
166
|
+
distanceToPoint: function (point) {
|
|
167
|
+
return BMDistanceBetweenPoints(this, point);
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Computes and returns the slope angle, in radians, of the line between this point and the given point.
|
|
172
|
+
* @param point <BMPoint> A point.
|
|
173
|
+
* @return <Number> The angle in radians.
|
|
174
|
+
*/
|
|
175
|
+
slopeAngleToPoint: function (point) {
|
|
176
|
+
return BMSlopeAngleBetweenPoints(this, point);
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Invoked by the CoreUI animation engine to obtain an interpolated
|
|
181
|
+
* value between this object and the target object.
|
|
182
|
+
* @param fraction <Number> The animation fraction.
|
|
183
|
+
* {
|
|
184
|
+
* @param toValue <BMPoint> The object to which to interpolate.
|
|
185
|
+
* }
|
|
186
|
+
* @return <BMPoint> A point.
|
|
187
|
+
*/
|
|
188
|
+
interpolatedValueWithFraction(fraction, args) {
|
|
189
|
+
var target = args.toValue;
|
|
190
|
+
return BMPointMake(
|
|
191
|
+
BMNumberByInterpolatingNumbersWithFraction(this.x, target.x, fraction),
|
|
192
|
+
BMNumberByInterpolatingNumbersWithFraction(this.y, target.y, fraction)
|
|
193
|
+
);
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Returns a string representation of this point.
|
|
198
|
+
* @return <String> A string.
|
|
199
|
+
*/
|
|
200
|
+
toString() {
|
|
201
|
+
return `(${this.x}:${this.y})`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Constructs and returns a new point with the given coordinates.
|
|
208
|
+
* @param x <Number, nullable> Defaults to 0. The x coordinate.
|
|
209
|
+
* @param y <Number, nullable> Defaults to 0. The y coordinate.
|
|
210
|
+
* @return <BMPoint> A Point.
|
|
211
|
+
*/
|
|
212
|
+
export function BMPointMake(x, y) {
|
|
213
|
+
return new BMPoint(x, y);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Constructs and returns a new point with the given cartesian coordinates.
|
|
218
|
+
* @param x <Number, nullable> Defaults to 0. The x coordinate.
|
|
219
|
+
* {
|
|
220
|
+
* @param y <Number, nullable> Defaults to 0. The y coordinate.
|
|
221
|
+
* }
|
|
222
|
+
* @return <BMPoint> A Point.
|
|
223
|
+
*/
|
|
224
|
+
export function BMPointMakeWithX(x, args) {
|
|
225
|
+
return new BMPoint(x || 0, (args && args.y) || 0);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Constructs and returns a new point with the given cartesian coordinates.
|
|
231
|
+
* @param x <Number, nullable> Defaults to 0. The x coordinate.
|
|
232
|
+
* {
|
|
233
|
+
* @param y <Number, nullable> Defaults to 0. The y coordinate.
|
|
234
|
+
* }
|
|
235
|
+
* @return <BMPoint> A Point.
|
|
236
|
+
*/
|
|
237
|
+
BMPoint.pointWithX = BMPointMakeWithX;
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Constructs and returns a new point with the given polar coordinates.
|
|
242
|
+
* @param radius <Number, nullable> Defaults to 0. The polar radius coordinate.
|
|
243
|
+
* {
|
|
244
|
+
* @param angle <Number, nullable> Defaults to 0. The polar angle coordinate in radians.
|
|
245
|
+
* }
|
|
246
|
+
* @return <BMPoint> A Point.
|
|
247
|
+
*/
|
|
248
|
+
export function BMPointMakeWithRadius(radius = 0, {angle = 0} = {angle: 0}) {
|
|
249
|
+
return BMPointMake(
|
|
250
|
+
radius * Math.cos(angle),
|
|
251
|
+
radius * Math.sin(angle)
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Constructs and returns a new point with the given polar coordinates.
|
|
258
|
+
* @param radius <Number, nullable> Defaults to 0. The polar radius coordinate.
|
|
259
|
+
* {
|
|
260
|
+
* @param angle <Number, nullable> Defaults to 0. The polar angle coordinate in radians.
|
|
261
|
+
* }
|
|
262
|
+
* @return <BMPoint> A Point.
|
|
263
|
+
*/
|
|
264
|
+
BMPoint.pointWithRadius = BMPointMakeWithRadius;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Computes and returns the absolute distance between the two given points.
|
|
268
|
+
* @param fromPoint <BMPoint> The first point.
|
|
269
|
+
* @param toPoint <BMPoint> The second point.
|
|
270
|
+
* @return <Number> The distance between the two points.
|
|
271
|
+
*/
|
|
272
|
+
export function BMDistanceBetweenPoints(fromPoint, toPoint) {
|
|
273
|
+
return Math.sqrt(Math.pow(toPoint.x - fromPoint.x, 2) + Math.pow(toPoint.y - fromPoint.y, 2));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Computes and returns the slope angle, in radians, between the two given points.
|
|
278
|
+
* @param fromPoint <BMPoint> The first point.
|
|
279
|
+
* @param toPoint <BMPoint> The second point.
|
|
280
|
+
* @return <Number> The angle in radians.
|
|
281
|
+
*/
|
|
282
|
+
export function BMSlopeAngleBetweenPoints(fromPoint, toPoint) {
|
|
283
|
+
return Math.atan2(toPoint.y - fromPoint.y, toPoint.x - fromPoint.x);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Represents the origin point.
|
|
288
|
+
*/
|
|
289
|
+
export const BMOriginPoint = BMPointMake(0, 0);
|
|
290
|
+
|
|
291
|
+
// @endtype
|