@startlibs/utils 1.0.0-alpha-7b → 1.0.0-alpha-7f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +311 -73
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -13,12 +13,14 @@ var _objectSpread = require('@babel/runtime/helpers/objectSpread');
13
13
  var _isPlainObject = require('lodash/fp/isPlainObject');
14
14
  var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
15
15
  var _fromPairs = require('lodash/fp/fromPairs');
16
+ var _isFinite = require('lodash/fp/isFinite');
16
17
  var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
17
18
  var _typeof = require('@babel/runtime/helpers/typeof');
18
19
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
19
- var _isFunction = require('lodash/fp/isFunction');
20
20
  var _find = require('lodash/fp/find');
21
21
  var _reverse = require('lodash/fp/reverse');
22
+ var _isEqual = require('lodash/fp/isEqual');
23
+ var _isFunction = require('lodash/fp/isFunction');
22
24
  var _get = require('lodash/fp/get');
23
25
  var _unset = require('lodash/fp/unset');
24
26
  var polished = require('polished');
@@ -37,7 +39,6 @@ var _toPath = require('lodash/fp/toPath');
37
39
  var _pullAt = require('lodash/fp/pullAt');
38
40
  var _curry = require('lodash/fp/curry');
39
41
  var _last = require('lodash/fp/last');
40
- var _isEqual = require('lodash/fp/isEqual');
41
42
 
42
43
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
43
44
 
@@ -52,12 +53,14 @@ var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
52
53
  var _isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(_isPlainObject);
53
54
  var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
54
55
  var _fromPairs__default = /*#__PURE__*/_interopDefaultLegacy(_fromPairs);
56
+ var _isFinite__default = /*#__PURE__*/_interopDefaultLegacy(_isFinite);
55
57
  var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultLegacy(_taggedTemplateLiteral);
56
58
  var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
57
59
  var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
58
- var _isFunction__default = /*#__PURE__*/_interopDefaultLegacy(_isFunction);
59
60
  var _find__default = /*#__PURE__*/_interopDefaultLegacy(_find);
60
61
  var _reverse__default = /*#__PURE__*/_interopDefaultLegacy(_reverse);
62
+ var _isEqual__default = /*#__PURE__*/_interopDefaultLegacy(_isEqual);
63
+ var _isFunction__default = /*#__PURE__*/_interopDefaultLegacy(_isFunction);
61
64
  var _get__default = /*#__PURE__*/_interopDefaultLegacy(_get);
62
65
  var _unset__default = /*#__PURE__*/_interopDefaultLegacy(_unset);
63
66
  var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
@@ -73,7 +76,6 @@ var _toPath__default = /*#__PURE__*/_interopDefaultLegacy(_toPath);
73
76
  var _pullAt__default = /*#__PURE__*/_interopDefaultLegacy(_pullAt);
74
77
  var _curry__default = /*#__PURE__*/_interopDefaultLegacy(_curry);
75
78
  var _last__default = /*#__PURE__*/_interopDefaultLegacy(_last);
76
- var _isEqual__default = /*#__PURE__*/_interopDefaultLegacy(_isEqual);
77
79
 
78
80
  function createSinglePromiseQueue() {
79
81
  return _createSinglePromiseQueue.apply(this, arguments);
@@ -496,14 +498,35 @@ var intToHour = function intToHour(hour) {
496
498
 
497
499
  if (hour === 0) {
498
500
  return "00:00";
499
- }
501
+ } //const [h,m] = ('000' + hour.toString().replace(":","")).slice(-4).replace(/(\d\d)(\d\d)/, '$1:$2').split(":")
502
+
500
503
 
501
- if (autoFill) return ('000' + hour.toString().replace(":", "")).slice(-4).replace(/(\d\d)(\d\d)/, '$1:$2');
502
504
  var h = hour.toString().replace(":", "").slice(-4, -2);
503
505
  var m = hour.toString().replace(":", "").slice(-2);
506
+
507
+ if (callIfFunction(autoFill, hour)) {
508
+ return ('000' + (h ? parseInt(h, 10) % 24 : '') + m).slice(-4).replace(/(\d\d)(\d\d)/, '$1:$2');
509
+ }
510
+
504
511
  if (h) return (parseInt(h, 10) > 23 ? h.slice(1) : h) + ':' + m;
505
512
  return m;
506
513
  };
514
+ var formatHour = function formatHour() {
515
+ var hour = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
516
+
517
+ if (!hour) {
518
+ return "";
519
+ }
520
+
521
+ var h = hour.toString().replace(":", "").slice(-4, -2);
522
+ var m = hour.toString().replace(":", "").slice(-2);
523
+
524
+ if (!h && parseInt(m) < 24 && !_isFinite__default['default'](hour)) {
525
+ return m + ":00";
526
+ }
527
+
528
+ return ('000' + hour.toString().replace(":", "")).slice(-4).replace(/(\d\d)(\d\d)/, '$1:$2');
529
+ };
507
530
  var willRafThrottle = function willRafThrottle() {
508
531
  var ticking = false;
509
532
  return function (fn) {
@@ -649,16 +672,76 @@ var normalizeTouch = function normalizeTouch(fn, endFn) {
649
672
  return function (e) {
650
673
  var touch = e.touches[0];
651
674
 
652
- if (e.touches.length > 1) {
653
- endFn();
675
+ if (e.touches.length > 1 && e.type !== 'touchend') {
676
+ callIfFunction(endFn, e, touch);
677
+ } else {
678
+ callIfFunction(fn, e, touch);
679
+ }
680
+ };
681
+ };
682
+ var normalizeMouse = function normalizeMouse(fn, endFn) {
683
+ return function (e) {
684
+ if (e.buttons > 1 && e.type !== 'mouseup') {
685
+ callIfFunction(endFn, e, e);
654
686
  } else {
655
- fn(e.currentTarget, touch.pageX, touch.pageY, touch.clientX, touch.clientY, e);
687
+ callIfFunction(fn, e, e);
656
688
  }
657
689
  };
658
690
  };
659
- var normalizeMouse = function normalizeMouse(fn) {
691
+ var normalizePress = function normalizePress(fn, endFn) {
660
692
  return function (e) {
661
- fn(e.currentTarget, e.pageX, e.pageY, e.clientX, e.clientY, e);
693
+ if (e.touches) {
694
+ normalizeTouch(fn, endFn)(e);
695
+ } else {
696
+ normalizeMouse(fn, endFn)(e);
697
+ }
698
+ };
699
+ };
700
+ var touchClick = function touchClick(cb) {
701
+ var sensibility = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
702
+ return function (e) {
703
+ var _e$touches;
704
+
705
+ if (((_e$touches = e.touches) === null || _e$touches === void 0 ? void 0 : _e$touches.length) !== 1) {
706
+ return;
707
+ }
708
+
709
+ var target = e.target;
710
+ var originalX = e.touches[0].screenX;
711
+ var originalY = e.touches[0].screenY;
712
+
713
+ var isInsideBounds = function isInsideBounds(touch) {
714
+ return Math.sqrt(Math.pow(originalX - touch.screenX, 2) + Math.pow(originalY - touch.screenY, 2)) < sensibility;
715
+ };
716
+
717
+ var checkBounds = function checkBounds(e) {
718
+ if (e.touches.length !== 1) {
719
+ return;
720
+ }
721
+
722
+ if (!isInsideBounds(e.changedTouches[0])) {
723
+ maybeClick();
724
+ }
725
+ };
726
+
727
+ var maybeClick = function maybeClick(e) {
728
+ var _e$changedTouches;
729
+
730
+ target.removeEventListener('touchend', maybeClick);
731
+ target.removeEventListener('touchmove', checkBounds);
732
+
733
+ if ((e === null || e === void 0 ? void 0 : (_e$changedTouches = e.changedTouches) === null || _e$changedTouches === void 0 ? void 0 : _e$changedTouches.length) !== 1) {
734
+ return;
735
+ }
736
+
737
+ if (isInsideBounds(e.changedTouches[0])) {
738
+ e.preventDefault();
739
+ cb(e);
740
+ }
741
+ };
742
+
743
+ target.addEventListener('touchend', maybeClick);
744
+ target.addEventListener('touchmove', checkBounds);
662
745
  };
663
746
  };
664
747
  var isEmptyHtml = function isEmptyHtml() {
@@ -828,6 +911,11 @@ var addQueryString = function addQueryString() {
828
911
 
829
912
  return onlyUrl + '?' + paramsStr;
830
913
  };
914
+
915
+ var cleanNulls = function cleanNulls(str) {
916
+ return str.replace(/\0/g, '');
917
+ };
918
+
831
919
  var postFetcherWithResponse =
832
920
  /*#__PURE__*/
833
921
  function () {
@@ -843,7 +931,7 @@ function () {
843
931
  fetchOptions = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
844
932
  return _context3.abrupt("return", innerFetcher(url, _objectSpread__default['default']({
845
933
  method: 'POST',
846
- body: typeof jsonOrForm === 'string' ? jsonOrForm : !jsonOrForm || jsonOrForm.constructor === window.FormData ? jsonOrForm : JSON.stringify(jsonOrForm)
934
+ body: typeof jsonOrForm === 'string' ? jsonOrForm : !jsonOrForm || jsonOrForm.constructor === window.FormData ? jsonOrForm : cleanNulls(JSON.stringify(jsonOrForm))
847
935
  }, fetchOptions, {
848
936
  headers: _isPlainObject__default['default'](fetchOptions.headers) || !fetchOptions.headers ? _objectSpread__default['default']({}, jsonOrForm && (typeof jsonOrForm === 'string' || jsonOrForm.constructor === window.FormData) ? {} : {
849
937
  'Content-Type': 'application/json; charset=UTF-8'
@@ -1131,10 +1219,10 @@ var getMargin = function getMargin(enumeratedMargins) {
1131
1219
  * `
1132
1220
  */
1133
1221
 
1134
- var getProp = function getProp(path, defaultValue) {
1222
+ var prop = function prop(path, defaultValue) {
1135
1223
  return function () {
1136
1224
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1137
- return get([].concat(path), props) || defaultValue;
1225
+ return _get__default['default'](path.trim(), props) || defaultValue;
1138
1226
  };
1139
1227
  };
1140
1228
  var customTheme = function customTheme(type) {
@@ -1159,36 +1247,71 @@ var customTheme = function customTheme(type) {
1159
1247
  */
1160
1248
 
1161
1249
  var ifProp = function ifProp(path, pass, fail) {
1162
- return function () {
1163
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1164
- var result = false;
1250
+ if (pass && !_isFunction__default['default'](pass)) {
1251
+ // old version
1252
+ return function () {
1253
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1254
+ var result = false;
1165
1255
 
1166
- if (Array.isArray(path)) {
1167
- result = path.every(function (p) {
1168
- return testSinglePath(props, p);
1169
- });
1170
- } else if (_typeof__default['default'](path) === 'object') {
1171
- result = !Object.entries(path).find(function (_ref2) {
1172
- var _ref3 = _slicedToArray__default['default'](_ref2, 2),
1173
- k = _ref3[0],
1174
- v = _ref3[1];
1256
+ if (Array.isArray(path)) {
1257
+ result = path.every(function (p) {
1258
+ return testSinglePath(props, p);
1259
+ });
1260
+ } else if (_typeof__default['default'](path) === 'object') {
1261
+ result = !Object.entries(path).find(function (_ref2) {
1262
+ var _ref3 = _slicedToArray__default['default'](_ref2, 2),
1263
+ k = _ref3[0],
1264
+ v = _ref3[1];
1175
1265
 
1176
- return props[k] !== v;
1177
- });
1178
- } else {
1179
- result = testSinglePath(props, path);
1180
- }
1266
+ return props[k] !== v;
1267
+ });
1268
+ } else {
1269
+ result = testSinglePath(props, path);
1270
+ }
1181
1271
 
1182
- return result ? pass : fail;
1183
- };
1272
+ return result ? pass : fail;
1273
+ };
1274
+ } else {
1275
+ return function () {
1276
+ for (var _len = arguments.length, argsTrue = new Array(_len), _key = 0; _key < _len; _key++) {
1277
+ argsTrue[_key] = arguments[_key];
1278
+ }
1279
+
1280
+ var check = pass || _identity__default['default'];
1281
+
1282
+ var fn = function fn(props) {
1283
+ return check(_get__default['default'](path, props)) ? styled.css.apply(void 0, argsTrue) : '';
1284
+ };
1285
+
1286
+ fn.orElse = function () {
1287
+ for (var _len2 = arguments.length, argsFalse = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1288
+ argsFalse[_key2] = arguments[_key2];
1289
+ }
1290
+
1291
+ return function (props) {
1292
+ return check(_get__default['default'](path, props)) ? styled.css.apply(void 0, argsTrue) : styled.css.apply(void 0, argsFalse);
1293
+ };
1294
+ };
1295
+
1296
+ return fn;
1297
+ };
1298
+ }
1299
+ };
1300
+ var ifPropEquals = function ifPropEquals(path, str) {
1301
+ return ifProp(path, _isEqual__default['default'](str));
1302
+ };
1303
+ var ifNotProp = function ifNotProp(path) {
1304
+ return ifProp(path, function (v) {
1305
+ return !v;
1306
+ });
1184
1307
  };
1185
1308
  var media = function media() {
1186
- for (var _len = arguments.length, sizePairs = new Array(_len), _key = 0; _key < _len; _key++) {
1187
- sizePairs[_key] = arguments[_key];
1309
+ for (var _len3 = arguments.length, sizePairs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1310
+ sizePairs[_key3] = arguments[_key3];
1188
1311
  }
1189
1312
 
1190
1313
  return function () {
1191
- return styled.css(["@media screen and ", "{", "}"], sizePairs.map(function (_ref4) {
1314
+ return styled.css(["@media ", "{", "}"], sizePairs.map(function (_ref4) {
1192
1315
  var _ref5 = _slicedToArray__default['default'](_ref4, 2),
1193
1316
  size = _ref5[0],
1194
1317
  type = _ref5[1];
@@ -1212,6 +1335,11 @@ media.min = function (n) {
1212
1335
  };
1213
1336
 
1214
1337
  media.desktop = media([601, 'min-width']);
1338
+ var vheight = function vheight(strings, size) {
1339
+ var propType = strings[0];
1340
+ var calc = (strings[1] || "").replace(";", "").trim();
1341
+ return "\n ".concat(propType, " ").concat(calc ? "calc(".concat(size, "vh ").concat(calc, ")") : "".concat(size, "vh"), ";\n ").concat(propType, " ").concat(calc ? "calc(calc(var(--vh, 1vh) * ".concat(size, ") ").concat(calc, ")") : "calc(var(--vh, 1vh) * ".concat(size, ")"), ";\n ");
1342
+ };
1215
1343
 
1216
1344
  function testSinglePath(props, path) {
1217
1345
  if (typeof path === 'string') {
@@ -1228,8 +1356,8 @@ var getFrameOffset = function getFrameOffset(i, total) {
1228
1356
  };
1229
1357
 
1230
1358
  var oneWayAnimation = function oneWayAnimation() {
1231
- for (var _len2 = arguments.length, frames = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1232
- frames[_key2] = arguments[_key2];
1359
+ for (var _len4 = arguments.length, frames = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1360
+ frames[_key4] = arguments[_key4];
1233
1361
  }
1234
1362
 
1235
1363
  return emotion.keyframes(_templateObject(), frames.map(function (frame, i) {
@@ -1237,8 +1365,8 @@ var oneWayAnimation = function oneWayAnimation() {
1237
1365
  }));
1238
1366
  };
1239
1367
  var twoWayAnimation = function twoWayAnimation() {
1240
- for (var _len3 = arguments.length, frames = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1241
- frames[_key3] = arguments[_key3];
1368
+ for (var _len5 = arguments.length, frames = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1369
+ frames[_key5] = arguments[_key5];
1242
1370
  }
1243
1371
 
1244
1372
  return [frames, _reverse__default['default'](frames)].map(function (frames) {
@@ -1247,8 +1375,8 @@ var twoWayAnimation = function twoWayAnimation() {
1247
1375
  };
1248
1376
  var animationTiming = function animationTiming(props) {
1249
1377
  return function () {
1250
- for (var _len4 = arguments.length, animations = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1251
- animations[_key4] = arguments[_key4];
1378
+ for (var _len6 = arguments.length, animations = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1379
+ animations[_key6] = arguments[_key6];
1252
1380
  }
1253
1381
 
1254
1382
  return animations.filter(function (_) {
@@ -1272,7 +1400,7 @@ var styledExtend = function styledExtend(_ref6) {
1272
1400
  };
1273
1401
 
1274
1402
  var escapedValidParts = /(^|[^\\])(dd?|DD?|mm?|LL?|hh?|MM?|yy(?:yy)?)/g;
1275
- var validParts = /(dd?|DD?|mm?|LL?|hh?|MM?|yy(?:yy))$/;
1403
+ var validParts = /(dd?|DD?|mm?|LL?|hh?|MM?|yy(?:yy)|yy)$/;
1276
1404
 
1277
1405
  var addZero = function addZero(v) {
1278
1406
  return (v < 10 ? '0' : '') + v;
@@ -1288,29 +1416,30 @@ var getSet = function getSet(index, ttype) {
1288
1416
  };
1289
1417
  return [function (date, _, noUTC) {
1290
1418
  return format((typeof date === 'number' ? new Date(date) : date)['get' + (noUTC ? '' : 'UTC') + ttype]() + plus);
1291
- }, function (unformatedStr, date, _, failOnFormat) {
1419
+ }, function (unformatedStr, date, _, failOnFormat, noUTC) {
1292
1420
  var str = parse(unformatedStr, date, failOnFormat);
1293
1421
  if (str === '' || isNaN(date.getTime())) return date;
1294
1422
  if (str === '\0') return date.setTime(NaN);
1423
+ var utcSTR = noUTC ? '' : 'UTC';
1295
1424
  var v = parseInt(str, 10) - plus;
1296
- var prevDay = date.getUTCDate();
1425
+ var prevDay = date['get' + utcSTR + 'Date']();
1297
1426
 
1298
1427
  if (ttype !== 'Date') {
1299
- date.setUTCDate(1);
1428
+ date['set' + utcSTR + 'Date'](1);
1300
1429
  }
1301
1430
 
1302
- date['setUTC' + ttype](v);
1431
+ date['set' + utcSTR + ttype](v);
1303
1432
 
1304
- if (date['getUTC' + ttype]() !== v) {
1305
- date['setUTC' + ttype](NaN);
1433
+ if (date['get' + utcSTR + ttype]() !== v) {
1434
+ date['set' + utcSTR + ttype](NaN);
1306
1435
  return date;
1307
1436
  }
1308
1437
 
1309
1438
  if (ttype !== 'Date') {
1310
- date.setUTCDate(prevDay);
1439
+ date['set' + utcSTR + 'Date'](prevDay);
1311
1440
 
1312
- if (date['getUTC' + ttype]() !== v) {
1313
- date.setUTCDate(0);
1441
+ if (date['get' + utcSTR + ttype]() !== v) {
1442
+ date['set' + utcSTR + 'Date'](0);
1314
1443
  return date;
1315
1444
  }
1316
1445
  }
@@ -1326,23 +1455,28 @@ var getText = function getText(type, total) {
1326
1455
  }];
1327
1456
  };
1328
1457
 
1329
- var val = {
1330
- yyyy: getSet(0, 'FullYear', 0, function (v) {
1331
- return v;
1332
- }, function (y, date, failOnFormat) {
1333
- var formattedY = y.length === 2 && y !== '20' ? '20' + y : y.length === 4 ? y : '';
1458
+ var yearParse = function yearParse(y, date, failOnFormat) {
1459
+ var formattedY = y.length === 2 && y !== '20' ? '20' + y : y.length === 4 ? y : '';
1334
1460
 
1335
- if (formattedY === '') {
1336
- if (failOnFormat) {
1337
- var found = date.getUTCFullYear().toString().indexOf(y);
1338
- return found === 0 || found === 2 ? date.getUTCFullYear() : '\0';
1339
- } else {
1340
- return date.getUTCFullYear();
1341
- }
1461
+ if (formattedY === '') {
1462
+ if (failOnFormat) {
1463
+ var found = date.getUTCFullYear().toString().indexOf(y);
1464
+ return found === 0 || found === 2 ? date.getUTCFullYear() : '\0';
1342
1465
  } else {
1343
- return formattedY;
1466
+ return date.getUTCFullYear();
1344
1467
  }
1345
- }),
1468
+ } else {
1469
+ return formattedY;
1470
+ }
1471
+ };
1472
+
1473
+ var val = {
1474
+ yyyy: getSet(0, 'FullYear', 0, function (v) {
1475
+ return v;
1476
+ }, yearParse),
1477
+ yy: getSet(0, 'FullYear', 0, function (v) {
1478
+ return (v + "").slice(2, 4);
1479
+ }, yearParse),
1346
1480
  M: getSet(1, 'Month', 1),
1347
1481
  MM: getSet(1, 'Month', 1, addZero),
1348
1482
  L: getText('Month', 12, 3),
@@ -1375,7 +1509,7 @@ var now = function now() {
1375
1509
  return new Date();
1376
1510
  };
1377
1511
 
1378
- function parseDate(str, possibleDate, format, messages, failOnFormat) {
1512
+ function parseDate(str, possibleDate, format, messages, failOnFormat, noUTC) {
1379
1513
  if (!str) return possibleDate;
1380
1514
  var separators = format.replace(escapedValidParts, '\0').split('\0');
1381
1515
  var parts = format.match(escapedValidParts);
@@ -1400,7 +1534,7 @@ function parseDate(str, possibleDate, format, messages, failOnFormat) {
1400
1534
  setter = _ref2[0],
1401
1535
  text = _ref2[1];
1402
1536
 
1403
- return setter(text, date, messages, failOnFormat);
1537
+ return setter(text, date, messages, failOnFormat, noUTC);
1404
1538
  });
1405
1539
  return date;
1406
1540
  }
@@ -1589,6 +1723,91 @@ var useEventListenerFor = function useEventListenerFor(element, eventName, callb
1589
1723
  }, deps.concat(element));
1590
1724
  };
1591
1725
 
1726
+ var disableSelect = function disableSelect(e) {
1727
+ e.preventDefault();
1728
+ };
1729
+
1730
+ var createPressEvent = function createPressEvent(onStart) {
1731
+ return normalizePress(function (startEvent, info) {
1732
+ var onEnd = onStart(startEvent, info);
1733
+ var finish = normalizePress(function (e, info) {
1734
+ callIfFunction(onEnd, e, info);
1735
+ window.removeEventListener('selectstart', disableSelect);
1736
+ window.removeEventListener('touchend', finish);
1737
+ window.removeEventListener('mouseup', finish);
1738
+ });
1739
+ window.addEventListener('selectstart', disableSelect);
1740
+
1741
+ if (startEvent.touches) {
1742
+ window.addEventListener('touchend', finish);
1743
+ } else {
1744
+ window.addEventListener("mouseup", finish);
1745
+ }
1746
+ });
1747
+ };
1748
+ var createPressAndHoldEvent = function createPressAndHoldEvent(onStart, interval) {
1749
+ return createPressEvent(function (startEvent, info) {
1750
+ var _concat = [].concat(onStart(startEvent, info)),
1751
+ _concat2 = _slicedToArray__default['default'](_concat, 2),
1752
+ onInterval = _concat2[0],
1753
+ onEnd = _concat2[1];
1754
+
1755
+ var i = 0;
1756
+
1757
+ if (interval) {
1758
+ var intervalId = setInterval(function () {
1759
+ onInterval(i++);
1760
+ }, interval);
1761
+ return normalizePress(function (e, info) {
1762
+ callIfFunction(onEnd, e, info);
1763
+ clearInterval(intervalId);
1764
+ });
1765
+ } else {
1766
+ var running = true;
1767
+
1768
+ var run = function run() {
1769
+ return window.requestAnimationFrame(function () {
1770
+ if (running) {
1771
+ onInterval(i++);
1772
+ run();
1773
+ }
1774
+ });
1775
+ };
1776
+
1777
+ run();
1778
+ return normalizePress(function (e, info) {
1779
+ callIfFunction(onEnd, e, info);
1780
+ running = false;
1781
+ });
1782
+ }
1783
+ });
1784
+ };
1785
+ var createPressAndMoveEvent = function createPressAndMoveEvent(onStart) {
1786
+ return createPressEvent(function (startEvent, info) {
1787
+ var _concat3 = [].concat(onStart(startEvent, info)),
1788
+ _concat4 = _slicedToArray__default['default'](_concat3, 2),
1789
+ onMove = _concat4[0],
1790
+ onEnd = _concat4[1];
1791
+
1792
+ var finish = normalizePress(function (e, info) {
1793
+ callIfFunction(onEnd, e, info);
1794
+ window.removeEventListener('touchmove', move);
1795
+ window.removeEventListener('mousemove', move);
1796
+ });
1797
+ var move = normalizePress(onMove, finish);
1798
+
1799
+ if (startEvent.touches) {
1800
+ window.addEventListener('touchmove', move, {
1801
+ passive: false
1802
+ });
1803
+ } else {
1804
+ window.addEventListener("mousemove", move);
1805
+ }
1806
+
1807
+ return finish;
1808
+ });
1809
+ };
1810
+
1592
1811
  // a contract like this to integrate with React.
1593
1812
  // Real implementations can be significantly more complex.
1594
1813
  // Don't copy-paste this into your project!
@@ -1605,6 +1824,7 @@ var innerWrapLazy = function innerWrapLazy(refreshCallback) {
1605
1824
  var status;
1606
1825
  var lazyResolver;
1607
1826
  var lazyPromise;
1827
+ var checker = _isEqual__default['default'];
1608
1828
  var lazyArgs = EMPTY_ARGS;
1609
1829
 
1610
1830
  var _uid = Math.random().toString() + Date.now();
@@ -1633,12 +1853,13 @@ var innerWrapLazy = function innerWrapLazy(refreshCallback) {
1633
1853
  result = r;
1634
1854
  return r;
1635
1855
  }, function (e) {
1636
- if (returnedPromise === suspender) {
1856
+ if (returnedPromise !== suspender) {
1637
1857
  return suspender;
1638
1858
  }
1639
1859
 
1640
1860
  status = "error";
1641
1861
  result = e;
1862
+ return Promise.reject(e);
1642
1863
  });
1643
1864
  });
1644
1865
  return returnedPromise;
@@ -1654,7 +1875,7 @@ var innerWrapLazy = function innerWrapLazy(refreshCallback) {
1654
1875
  } else if (status === "error") {
1655
1876
  throw result;
1656
1877
  } else if (status === "success") {
1657
- return result;
1878
+ return currentValue;
1658
1879
  }
1659
1880
  },
1660
1881
  promise: function promise() {
@@ -1672,14 +1893,14 @@ var innerWrapLazy = function innerWrapLazy(refreshCallback) {
1672
1893
  args[_key3] = arguments[_key3];
1673
1894
  }
1674
1895
 
1675
- return wrapLazy.apply(void 0, [promise].concat(rootArgs, args));
1896
+ return wrapLazy.apply(void 0, [promise].concat(rootArgs, args)).checkWith(checker);
1676
1897
  },
1677
1898
  use: function use() {
1678
1899
  for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1679
1900
  args[_key4] = arguments[_key4];
1680
1901
  }
1681
1902
 
1682
- if (!_isEqual__default['default'](args, lazyArgs)) {
1903
+ if (!checker(args, lazyArgs)) {
1683
1904
  if (lazyArgs !== EMPTY_ARGS) {
1684
1905
  _uid = Math.random().toString() + Date.now();
1685
1906
  }
@@ -1694,6 +1915,14 @@ var innerWrapLazy = function innerWrapLazy(refreshCallback) {
1694
1915
  return currentValue;
1695
1916
  },
1696
1917
  and: function and(lazy) {},
1918
+ checkWith: function checkWith(isEqual) {
1919
+ checker = isEqual;
1920
+ return this;
1921
+ },
1922
+ localUpdate: function localUpdate(updater) {
1923
+ currentValue = callIfFunction(updater, currentValue);
1924
+ return this;
1925
+ },
1697
1926
  uid: function uid() {
1698
1927
  return _uid;
1699
1928
  }
@@ -1789,6 +2018,9 @@ exports.callMany = callMany;
1789
2018
  exports.compareBest = compareBest;
1790
2019
  exports.concatSelectors = concatSelectors;
1791
2020
  exports.constrainEvent = constrainEvent;
2021
+ exports.createPressAndHoldEvent = createPressAndHoldEvent;
2022
+ exports.createPressAndMoveEvent = createPressAndMoveEvent;
2023
+ exports.createPressEvent = createPressEvent;
1792
2024
  exports.createPromiseQueue = createPromiseQueue;
1793
2025
  exports.customTheme = customTheme;
1794
2026
  exports.digitsToPattern = digitsToPattern;
@@ -1798,6 +2030,7 @@ exports.formFetch = formFetch;
1798
2030
  exports.formFetchWithResponse = formFetchWithResponse;
1799
2031
  exports.formatDate = formatDate;
1800
2032
  exports.formatDateToPattern = formatDateToPattern;
2033
+ exports.formatHour = formatHour;
1801
2034
  exports.formatPath = formatPath;
1802
2035
  exports.getClosestOffsetScroll = getClosestOffsetScroll;
1803
2036
  exports.getColor = getColor;
@@ -1806,14 +2039,15 @@ exports.getFetcherWithResponse = getFetcherWithResponse;
1806
2039
  exports.getMargin = getMargin;
1807
2040
  exports.getNumberInputType = getNumberInputType;
1808
2041
  exports.getNumberInputType2 = getNumberInputType2;
1809
- exports.getProp = getProp;
1810
2042
  exports.getScrollParent = getScrollParent;
1811
2043
  exports.getUID = getUID;
1812
2044
  exports.getUrlParams = getUrlParams;
1813
2045
  exports.identityFn = identityFn;
1814
2046
  exports.identityOpacityFrames = identityOpacityFrames;
1815
2047
  exports.identityTranslateFrames = identityTranslateFrames;
2048
+ exports.ifNotProp = ifNotProp;
1816
2049
  exports.ifProp = ifProp;
2050
+ exports.ifPropEquals = ifPropEquals;
1817
2051
  exports.ifUndefined = ifUndefined;
1818
2052
  exports.intToHour = intToHour;
1819
2053
  exports.intsToHour = intsToHour;
@@ -1830,12 +2064,14 @@ exports.linkRegex = linkRegex;
1830
2064
  exports.mapGetOrSet = mapGetOrSet;
1831
2065
  exports.media = media;
1832
2066
  exports.normalizeMouse = normalizeMouse;
2067
+ exports.normalizePress = normalizePress;
1833
2068
  exports.normalizeTouch = normalizeTouch;
1834
2069
  exports.oneWayAnimation = oneWayAnimation;
1835
2070
  exports.parseDate = parseDate;
1836
2071
  exports.postFetcher = postFetcher;
1837
2072
  exports.postFetcherWithResponse = postFetcherWithResponse;
1838
2073
  exports.preventDefault = preventDefault;
2074
+ exports.prop = prop;
1839
2075
  exports.rafThrottle = rafThrottle;
1840
2076
  exports.safeNewLineToBr = safeNewLineToBr;
1841
2077
  exports.scrollIntoViewWithOffset = scrollIntoViewWithOffset;
@@ -1847,11 +2083,13 @@ exports.styledExtend = styledExtend;
1847
2083
  exports.timerPromise = timerPromise;
1848
2084
  exports.toHighest = toHighest;
1849
2085
  exports.toLowest = toLowest;
2086
+ exports.touchClick = touchClick;
1850
2087
  exports.twoWayAnimation = twoWayAnimation;
1851
2088
  exports.unWill = unWill;
1852
2089
  exports.useEventListener = useEventListener;
1853
2090
  exports.useEventListenerFor = useEventListenerFor;
1854
2091
  exports.using = using;
2092
+ exports.vheight = vheight;
1855
2093
  exports.will = will;
1856
2094
  exports.willRafThrottle = willRafThrottle;
1857
2095
  exports.willUseAutoLazy = willUseAutoLazy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startlibs/utils",
3
- "version": "1.0.0-alpha-7b",
3
+ "version": "1.0.0-alpha-7f",
4
4
  "description": "Startlibs Utils",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,