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,470 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
// @type CoreUI
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The CoreUI package contains reusable generic functions and structures, usable as basic building blocks in different types of projects.
|
|
7
|
+
* It includes basic objects such as point, size, rect, indexPath and color, as well as several globally defined functions.
|
|
8
|
+
*
|
|
9
|
+
* Most objects defined here are copyable through the copy() method. The copy method will return a functionally identical object,
|
|
10
|
+
* with the same property values as the source object, however only the properties defined in the source prototype are copied.
|
|
11
|
+
* Other developer-added properties will not exist in the copied object.
|
|
12
|
+
*/
|
|
13
|
+
export var BMCoreUI = '2.5.0'; // <String>
|
|
14
|
+
|
|
15
|
+
export var YES = true;
|
|
16
|
+
export var NO = false;
|
|
17
|
+
|
|
18
|
+
// This resolves an incompatbility with MS Edge
|
|
19
|
+
if (!('remove' in Element.prototype)) {
|
|
20
|
+
/** @type {Object} */ const proto = Element.prototype;
|
|
21
|
+
proto.remove = function() {
|
|
22
|
+
if (this.parentNode) {
|
|
23
|
+
this.parentNode.removeChild(this);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Is set to YES if the current device is a touch device, otherwise it is set to NO.
|
|
30
|
+
*/
|
|
31
|
+
export var BMIsTouchDevice = !!('ontouchstart' in window || navigator.maxTouchPoints); // <Boolean>
|
|
32
|
+
|
|
33
|
+
// The cached scrollbar size.
|
|
34
|
+
var _BMScrollBarSize; // <Number>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns the scrollbar size for the current platform.
|
|
38
|
+
* @return <Number> The scrollbar size.
|
|
39
|
+
*/
|
|
40
|
+
export function BMScrollBarGetSize() {
|
|
41
|
+
// Return the cached size if it is available
|
|
42
|
+
if (_BMScrollBarSize !== undefined) return _BMScrollBarSize;
|
|
43
|
+
|
|
44
|
+
// Otherwise create a helper element to measure the scrollbar
|
|
45
|
+
var helper = document.createElement('div');
|
|
46
|
+
helper.style.cssText = 'width: 100px; height: 100px; overflow: scroll; position: absolute; top: -9999px;';
|
|
47
|
+
document.body.appendChild(helper);
|
|
48
|
+
|
|
49
|
+
_BMScrollBarSize = helper.offsetWidth - helper.clientWidth;
|
|
50
|
+
|
|
51
|
+
// Remove the helper after measuring the scrollbar
|
|
52
|
+
helper.remove();
|
|
53
|
+
|
|
54
|
+
return _BMScrollBarSize;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns a CSS rule string from the given object.
|
|
59
|
+
* @param selector <String> The rule's selector.
|
|
60
|
+
* {
|
|
61
|
+
* @param important <Boolean, nullable> Defaults to `NO`. If set to `YES`, the rules will be made important.
|
|
62
|
+
* @param properties <AnyObject> The object containing the CSS rules.
|
|
63
|
+
* }
|
|
64
|
+
* @return <String> A string.
|
|
65
|
+
*/
|
|
66
|
+
export function BMCSSRuleWithSelector(selector, args) {
|
|
67
|
+
let properties = args.properties;
|
|
68
|
+
let CSSRule = selector + ' {\n';
|
|
69
|
+
Object.keys(properties).forEach(rule => {
|
|
70
|
+
CSSRule += rule + ': ' + properties[rule] + (args.important ? ' !important' : '') + ';\n';
|
|
71
|
+
});
|
|
72
|
+
CSSRule += '\n}\n';
|
|
73
|
+
|
|
74
|
+
return CSSRule;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Adds an interaction to the target node that smoothly animates wheel events.
|
|
79
|
+
* @param node <DOMNode> The node for which to add the interaction.
|
|
80
|
+
* {
|
|
81
|
+
* @param withDeceleration <Number, nullable> Defaults to 3. Measured in pixels/frame (or pixels/16ms).
|
|
82
|
+
* The speed with which the scroll speed decreases over time.
|
|
83
|
+
* @param baseAcceleration <Number, nullable> Defaults to 6. Measured in pixels/frame (or pixels/16ms).
|
|
84
|
+
* The acceleration with which the scrolling begins. This decreases
|
|
85
|
+
* over time after the first scroll event fires.
|
|
86
|
+
* @param speedIncrement <Number, nullable> Defaults to 20. Measured in pixels/frame (or pixels/16ms).
|
|
87
|
+
* The speed to add for successive scroll events.
|
|
88
|
+
* }
|
|
89
|
+
*/
|
|
90
|
+
export function BMAddSmoothMousewheelInteractionToNode(node, args) {
|
|
91
|
+
// Set to yes if the current sequence of wheel events is considered to be
|
|
92
|
+
// a smooth trackpad gesture
|
|
93
|
+
let isTrackpadEvent = NO;
|
|
94
|
+
let trackpadTimeout;
|
|
95
|
+
|
|
96
|
+
args = args || {};
|
|
97
|
+
|
|
98
|
+
let speedX = 0; // In pixels per frame
|
|
99
|
+
let speedY = 0; // In pixels per frame
|
|
100
|
+
let deceleration = args.withDeceleration || 3; // In pixels/frame
|
|
101
|
+
let accelerationX = 0;
|
|
102
|
+
let accelerationY = 0;
|
|
103
|
+
let lastEvent;
|
|
104
|
+
|
|
105
|
+
let baseAcceleration = args.baseAcceleration || 6;
|
|
106
|
+
let speedIncrement = args.speedIncrement || 20;
|
|
107
|
+
|
|
108
|
+
// A listener attached to the mouse down event.
|
|
109
|
+
// This stops the scrolling in its tracks by resetting the speeds to 0
|
|
110
|
+
function mouseDownListener() {
|
|
111
|
+
speedX = 0;
|
|
112
|
+
speedY = 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The wheel event generator generates wheel events that slowly decelerate over time
|
|
116
|
+
function wheelEventGenerator() {
|
|
117
|
+
let initialXSign = Math.sign(speedX);
|
|
118
|
+
let initialYSign = Math.sign(speedY);
|
|
119
|
+
|
|
120
|
+
// The speed is first decreased by its deceleration rate
|
|
121
|
+
if (speedX) speedX -= initialXSign * deceleration;
|
|
122
|
+
if (speedY) speedY -= initialYSign * deceleration;
|
|
123
|
+
|
|
124
|
+
// Then increased by its acceleration rate
|
|
125
|
+
if (speedX) speedX += initialXSign * accelerationX;
|
|
126
|
+
if (speedY) speedY += initialYSign * accelerationY;
|
|
127
|
+
|
|
128
|
+
// Acceleration decreases at every step
|
|
129
|
+
if (accelerationX) accelerationX -= .5;
|
|
130
|
+
if (accelerationY) accelerationY -= .5;
|
|
131
|
+
|
|
132
|
+
// If either speeds overshoots 0, scrolling for that axis stops
|
|
133
|
+
if (Math.sign(speedX) != initialXSign) {
|
|
134
|
+
speedX = 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (Math.sign(speedY) != initialYSign) {
|
|
138
|
+
speedY = 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Otherwise, a new event is scheduled
|
|
142
|
+
if (speedY || speedX) {
|
|
143
|
+
requestAnimationFrame(wheelEventGenerator);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!speedX && !speedY) return;
|
|
147
|
+
|
|
148
|
+
let event = new WheelEvent('wheel', {
|
|
149
|
+
deltaX: speedX,
|
|
150
|
+
deltaY: speedY,
|
|
151
|
+
deltaZ: 0,
|
|
152
|
+
deltaMode: 0,
|
|
153
|
+
clientX: lastEvent.clientX,
|
|
154
|
+
cientY: lastEvent.clientY,
|
|
155
|
+
offsetX: lastEvent.offsetX,
|
|
156
|
+
offsetY: lastEvent.offsetY,
|
|
157
|
+
layerX: lastEvent.layerX,
|
|
158
|
+
layerY: lastEvent.layerY,
|
|
159
|
+
target: lastEvent.target,
|
|
160
|
+
altKey: lastEvent.altKey,
|
|
161
|
+
ctrlKey: lastEvent.ctrlKey,
|
|
162
|
+
metaKey: lastEvent.metaKey,
|
|
163
|
+
shiftKey: lastEvent.shiftKey
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
event._BMIsCustomScrollEvent = YES;
|
|
167
|
+
|
|
168
|
+
node.dispatchEvent(event);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
node.addEventListener('mousedown', mouseDownListener);
|
|
172
|
+
|
|
173
|
+
node.addEventListener('wheel', function (event) {
|
|
174
|
+
if (trackpadTimeout) window.clearTimeout(trackpadTimeout);
|
|
175
|
+
trackpadTimeout = window.setTimeout(_ => { trackpadTimeout = undefined, isTrackpadEvent = NO }, 200);
|
|
176
|
+
|
|
177
|
+
// If this is already a smooth trackpad event, don't do anything
|
|
178
|
+
if (event._BMIsCustomScrollEvent || isTrackpadEvent) return;
|
|
179
|
+
|
|
180
|
+
// On Safari, mouse wheel events are differentiated by having fractional values; on other browsers, wheel events have higher deltas
|
|
181
|
+
if (event.deltaMode == 0 && ((Math.abs(event.deltaX) < 50 && Math.abs(event.deltaY) < 50) && (Math.floor(event.deltaY) - event.deltaY == 0))) {
|
|
182
|
+
isTrackpadEvent = YES;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
lastEvent = event;
|
|
187
|
+
|
|
188
|
+
// Prevent the original event from going through
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
event.stopPropagation();
|
|
191
|
+
event.stopImmediatePropagation();
|
|
192
|
+
|
|
193
|
+
// When starting from a stopped state, reset the deceleration to 0
|
|
194
|
+
if (speedX == 0 && speedY == 0) {
|
|
195
|
+
deceleration = 0;
|
|
196
|
+
requestAnimationFrame(wheelEventGenerator);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Add to the speed of the current event if there is one
|
|
200
|
+
if (Math.sign(event.deltaX) != Math.sign(speedX) || speedX == 0) {
|
|
201
|
+
speedX = baseAcceleration * Math.sign(event.deltaX);
|
|
202
|
+
accelerationX = baseAcceleration;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
//accelerationX += 6;
|
|
206
|
+
speedX += event.deltaX ? Math.sign(event.deltaX) * speedIncrement : 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (Math.sign(event.deltaY) != Math.sign(speedY) || speedY == 0) {
|
|
210
|
+
speedY = baseAcceleration * Math.sign(event.deltaY);
|
|
211
|
+
accelerationY = baseAcceleration;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
//accelerationY += 6;
|
|
215
|
+
speedY += event.deltaY ? Math.sign(event.deltaY) * speedIncrement : 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Add to the deceleration to prevent the scroll from taking too long to finish
|
|
219
|
+
if (deceleration) {
|
|
220
|
+
deceleration += (args.withDeceleration || 3) / 3;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
deceleration += args.withDeceleration || 3;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Generate the initial event
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Copies the properties and their definitions from all objects given as paramters to the first object given as a parameter.
|
|
232
|
+
* Unlike jQuery's <code>$.extend</code> or <code>Object.assign</code>, this function will also copy getters and setters.
|
|
233
|
+
* The property descriptors will be copied in the order in which the parameters are specified. For example, if the third parameter has a property
|
|
234
|
+
* with the same name as the second parameter, the target object will have the third parameter's definition of that property.
|
|
235
|
+
* @param target <AnyObject, nullable> The object to which properties will be copied. May be set to undefined, in which case a new object will be created.
|
|
236
|
+
* @param ... <[AnyObject], nullable> Additional objects may be specified. The property descriptors will be copied over to the target object.
|
|
237
|
+
* @return <AnyObject> The target object.
|
|
238
|
+
*/
|
|
239
|
+
export function BMExtend(target) {
|
|
240
|
+
if (target === undefined) target = {};
|
|
241
|
+
|
|
242
|
+
// Iterate through the sources and copy their property descriptors.
|
|
243
|
+
var sources = arguments.length;
|
|
244
|
+
|
|
245
|
+
if (typeof Object.getOwnPropertyDescriptors == 'function') {
|
|
246
|
+
// If getOwnPropertyDescriptors is available, use it to copy all of the property descriptors in bulk
|
|
247
|
+
for (var i = 1; i < sources; i++) {
|
|
248
|
+
|
|
249
|
+
var properties = Object.getOwnPropertyDescriptors(arguments[i]);
|
|
250
|
+
Object.defineProperties(target, properties);
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// Otherwise fall back to iterating through each property descriptor
|
|
256
|
+
for (var i = 1; i < sources; i++) {
|
|
257
|
+
var propertyNames = Object.getOwnPropertyNames(arguments[i]);
|
|
258
|
+
for (var j = 0; j < propertyNames.length; j++) {
|
|
259
|
+
var descriptor = Object.getOwnPropertyDescriptor(arguments[i], propertyNames[j]);
|
|
260
|
+
if (descriptor) {
|
|
261
|
+
Object.defineProperty(target, propertyNames[j], descriptor);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return target;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Copies the property values from all objects given as paramters to the first object given as a parameter. Only own properties will be copied.
|
|
273
|
+
* The property values will be copied in the order in which the parameters are specified. For example, if the third parameter has a property
|
|
274
|
+
* with the same name as the second parameter, the target object will have the third parameter's value for that property.
|
|
275
|
+
* This will not redefine or reconfigure existing properties on the target object. For example, if any readonly property on the target object also exists on any of the
|
|
276
|
+
* other objects, the target object's value for that property will not change.
|
|
277
|
+
* @param target <AnyObject, nullable> The object to which properties will be copied. May be set to undefined, in which case a new object will be created.
|
|
278
|
+
* @param ... <[AnyObject], nullable> Additional objects may be specified. The property values will be copied over to the target object.
|
|
279
|
+
* @return <AnyObject> The target object.
|
|
280
|
+
*/
|
|
281
|
+
export function BMCopyProperties(target) {
|
|
282
|
+
var numberOfSources = arguments.length;
|
|
283
|
+
var sources = arguments;
|
|
284
|
+
|
|
285
|
+
// Initialize target to an empty object if it is not specified.
|
|
286
|
+
if (target === undefined) target = {};
|
|
287
|
+
|
|
288
|
+
for (var i = 1; i < numberOfSources; i++) {
|
|
289
|
+
Object.getOwnPropertyNames(arguments[i]).forEach(function (property) {
|
|
290
|
+
target[property] = sources[i][property];
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return target;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Creates and returns a string that represents the box-shadow to apply to an item to obtain
|
|
300
|
+
* a material design-like box shadow for the given elevation.
|
|
301
|
+
* Optionally, the shadow may also include a 1-pixel outline.
|
|
302
|
+
* @param elevation <Number> The elevation for which to generate the box-shadow.
|
|
303
|
+
* {
|
|
304
|
+
* @param drawOutline <Boolean, nullable> Defaults to NO. If set to YES, the box shadow will include an outline.
|
|
305
|
+
* @param opacity <Number, nullable> Defaults to 0.1. The opacity with which to draw the box-shadow.
|
|
306
|
+
* }
|
|
307
|
+
* @return <String> The box-shadow string.
|
|
308
|
+
*/
|
|
309
|
+
export function BMShadowForElevation(elevation, options) {
|
|
310
|
+
options = options || {};
|
|
311
|
+
var opacity = options.opacity === undefined ? .1 : options.opacity;
|
|
312
|
+
var outline = options.drawOutline || NO;
|
|
313
|
+
|
|
314
|
+
var accentShadowSize = '0px ' + (4 * elevation) + 'px ' + (6 * elevation) + 'px';
|
|
315
|
+
var diffShadowSize = '0px ' + (8 * elevation) + 'px ' + (12 * elevation) + 'px';
|
|
316
|
+
var outlineBoxShadow = outline ? ', 0px 0px 1px 1px rgba(0, 0, 0, ' + opacity + ')' : '';
|
|
317
|
+
|
|
318
|
+
return accentShadowSize + ' rgba(0, 0, 0, ' + opacity + '), ' + diffShadowSize + ' rgba(0, 0, 0, ' + opacity + ')' + outlineBoxShadow;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Returns a number that represents the linear interpolation of two numbers using a fraction.
|
|
323
|
+
* @param source <Number> The source number.
|
|
324
|
+
* @param target <Number> The target number.
|
|
325
|
+
* @param fraction <Number> The amount by which to interpolate. The fraction should be a number between 0 and 1, but going past these values is supported.
|
|
326
|
+
* Negative values will overshoot the source number and values greater than 1 will overshoot the target number.
|
|
327
|
+
* @return <Number> The interpolated number.
|
|
328
|
+
*/
|
|
329
|
+
export function BMNumberByInterpolatingNumbersWithFraction(source, target, fraction) {
|
|
330
|
+
return (target - source) * fraction + source;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Returns the target value or either of the specified interval bounds if the value overshoots any bound.
|
|
336
|
+
* If the value is greater than the low bound and less than the high bound, the value is returned.
|
|
337
|
+
* If the value is less than the low bound, the low bound is returned.
|
|
338
|
+
* Otherwise, if the value is greater than the high bound, the high bound is returned.
|
|
339
|
+
* @param value <Number> The target value.
|
|
340
|
+
* @param low <Number> The low bound.
|
|
341
|
+
* @param high <Number> The high bound.
|
|
342
|
+
* @return <Number> A number.
|
|
343
|
+
*/
|
|
344
|
+
export function BMNumberByConstrainingNumberToBounds(value, low, high) {
|
|
345
|
+
return Math.max(low, Math.min(value, high));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Returns a copy of the given string that has the first letter uppercased.
|
|
350
|
+
* @param string <String> The string to capitalize.
|
|
351
|
+
* @return <String> The capitalized string.
|
|
352
|
+
*/
|
|
353
|
+
export function BMStringByCapitalizingString(string) {
|
|
354
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Returns an array that contains all of the given object's keys that contain the given value.
|
|
359
|
+
* If no key contains the given value, an empty array will be returned.
|
|
360
|
+
* The object must not be null or undefined.
|
|
361
|
+
* @param value <AnyObject, nullable> The value to look for.
|
|
362
|
+
* {
|
|
363
|
+
* @param inObject <Object> The object in which to find keys.
|
|
364
|
+
* }
|
|
365
|
+
* @return <[String]> An array of keys that match the given value.
|
|
366
|
+
*/
|
|
367
|
+
export function BMKeysForValue(value, args) {
|
|
368
|
+
var keys = [];
|
|
369
|
+
Object.getOwnPropertyNames(args.inObject).forEach(function (key) {
|
|
370
|
+
if (args.inObject[key] == value) keys.push(key);
|
|
371
|
+
});
|
|
372
|
+
return keys;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Creates and returns an UUID string.
|
|
377
|
+
* @return <String> An UUID.
|
|
378
|
+
*/
|
|
379
|
+
export function BMUUIDMake() {
|
|
380
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
381
|
+
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
382
|
+
return v.toString(16);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// @endtype
|
|
387
|
+
|
|
388
|
+
// @type BMHTMLEntity
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* An enum containing HTML entities for various commonly used symbols.
|
|
392
|
+
*/
|
|
393
|
+
export var BMHTMLEntity = Object.freeze({ // <enum>
|
|
394
|
+
/**
|
|
395
|
+
* The HTML entity representing the bowen knot Command symbol.
|
|
396
|
+
*/
|
|
397
|
+
Command: '⌘', // <enum>
|
|
398
|
+
/**
|
|
399
|
+
* The HTML entity representing the Option symbol.
|
|
400
|
+
*/
|
|
401
|
+
Option: '⌥', // <enum>
|
|
402
|
+
/**
|
|
403
|
+
* The HTML entity representing the Shift symbol.
|
|
404
|
+
*/
|
|
405
|
+
Shift: '⇧', // <enum>
|
|
406
|
+
/**
|
|
407
|
+
* The HTML entity representing the Caps-Lock symbol.
|
|
408
|
+
*/
|
|
409
|
+
CapsLock: '⇪', // <enum>
|
|
410
|
+
/**
|
|
411
|
+
* The HTML entity representing the Backspace delete symbol.
|
|
412
|
+
*/
|
|
413
|
+
Delete: '⌫', // <enum>
|
|
414
|
+
/**
|
|
415
|
+
* The HTML entity representing the Return symbol.
|
|
416
|
+
*/
|
|
417
|
+
Return: '⏎' // <enum>
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
// @endtype
|
|
421
|
+
|
|
422
|
+
// @type BMScrollingDirectionVertical
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Contains constants representing the terminal vertical direction of a scrolling operation.
|
|
426
|
+
*/
|
|
427
|
+
export var BMScrollingDirectionVertical = Object.freeze({
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Indicates that the scroll operation was stationary on the vertical axis.
|
|
431
|
+
*/
|
|
432
|
+
Stationary: 0, // <enum>
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Indicates that the scroll operation was moving towards the beginning of the content.
|
|
436
|
+
*/
|
|
437
|
+
Top: 1, // <enum>
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Indicates that the scroll operation was moving towards the end of the content.
|
|
441
|
+
*/
|
|
442
|
+
Bottom: -1 // <enum>
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// @endtype
|
|
446
|
+
|
|
447
|
+
// @type BMScrollingDirectionHorizontal
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Contains constants representing the terminal horizontal direction of a scrolling operation.
|
|
451
|
+
*/
|
|
452
|
+
export var BMScrollingDirectionHorizontal = Object.freeze({
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Indicates that the scroll operation was stationary on the horizontal axis.
|
|
456
|
+
*/
|
|
457
|
+
Stationary: 0, // <enum>
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Indicates that the scroll operation was moving towards the beginning of the content.
|
|
461
|
+
*/
|
|
462
|
+
Left: 1, // <enum>
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Indicates that the scroll operation was moving towards the end of the content.
|
|
466
|
+
*/
|
|
467
|
+
Right: -1 // <enum>
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// @endtype
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {YES, BMExtend} from './BMCoreUI'
|
|
4
|
+
|
|
5
|
+
// @type interface BMFunctionCollection extends Function, Array<Function>
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
****************************************************************************************************************************************************************
|
|
9
|
+
BMFunctionCollection
|
|
10
|
+
****************************************************************************************************************************************************************
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Constructs and returns a function collection.
|
|
15
|
+
*
|
|
16
|
+
* A function collection is an array-like object that can only contain functions.
|
|
17
|
+
* It also behaves as a function that, when invoked, will invoke all other functions it contains, passing in
|
|
18
|
+
* its context and argument.
|
|
19
|
+
*
|
|
20
|
+
* It is intended to be an easy way to add multiple callbacks in cases where a single callback is expected.
|
|
21
|
+
*
|
|
22
|
+
* Note that while it supports all of Array's methods, it does not support numbered properties.
|
|
23
|
+
* To access or set values at specific indexes, use the <code>functionAtIndex(_)</code> and
|
|
24
|
+
* <code>setFunction(_, {atIndex})</code> methods.
|
|
25
|
+
*
|
|
26
|
+
* When invoked, the function collection will return the value returned by the last function it contains.
|
|
27
|
+
*
|
|
28
|
+
* @return <BMFunctionCollection> A function collection.
|
|
29
|
+
*/
|
|
30
|
+
export function BMFunctionCollectionMake() {
|
|
31
|
+
var array = [];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A function collection is an array-like object that can only contain functions.
|
|
35
|
+
* It also behaves as a function that, when invoked, will invoke all other functions it contains, passing in
|
|
36
|
+
* its context and argument.
|
|
37
|
+
*
|
|
38
|
+
* Note that while it supports all of Array's methods, it does not support numbered properties.
|
|
39
|
+
* To access or set values at specific indexes, use the <code>functionAtIndex(_)</code> and
|
|
40
|
+
* <code>setFunction(_, {atIndex})</code> methods.
|
|
41
|
+
*
|
|
42
|
+
* When invoked, the function collection will return the value returned by the last function it contains.
|
|
43
|
+
*
|
|
44
|
+
* Function collections cannot be instantiated using the constructor, they can only be created using the
|
|
45
|
+
* `BMFunctionCOllectionMake()` function.
|
|
46
|
+
*/
|
|
47
|
+
// function BMFunctionCollection() {} // <constructor>
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Represents the number of functions within this function collection.
|
|
51
|
+
*/
|
|
52
|
+
// length: undefined, // <Number>
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Puts the given function at the specified index within this function collection.
|
|
56
|
+
* If the given index is out of bounds, the function collection will be resized to accomodate
|
|
57
|
+
* the given index.
|
|
58
|
+
* @param f <Function, nullable> The function to set.
|
|
59
|
+
* {
|
|
60
|
+
* @param atIndex <Number> The index.
|
|
61
|
+
* }
|
|
62
|
+
*/
|
|
63
|
+
// setFunction: function (f, args) {
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the function at the given index.
|
|
68
|
+
* @param index <Number> The index.
|
|
69
|
+
* @return <Function, nullable> A function, or `undefined` if there is no function at the specified index.
|
|
70
|
+
*/
|
|
71
|
+
// functionAtIndex: function (index) {
|
|
72
|
+
|
|
73
|
+
var collection = function () {
|
|
74
|
+
var self = this;
|
|
75
|
+
var returnValue;
|
|
76
|
+
array.forEach((func) => (returnValue = func.apply(self, arguments)))
|
|
77
|
+
return returnValue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Copy over array methods
|
|
81
|
+
Object.getOwnPropertyNames(Array.prototype).forEach(function (key) {
|
|
82
|
+
if (!(key in collection)) collection[key] = function () {
|
|
83
|
+
return array[key].apply(array, arguments);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Add own methods
|
|
88
|
+
BMExtend(collection, {
|
|
89
|
+
get length() {
|
|
90
|
+
return array.length;
|
|
91
|
+
},
|
|
92
|
+
set length(length) {
|
|
93
|
+
array.length = length;
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
functionAtIndex(index) {
|
|
97
|
+
return array[index];
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
setfunction(func, args) {
|
|
101
|
+
return (array[args.atIndex] = func);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
_isFunctionCollection: YES
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return collection;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// @endtype
|