@startlibs/utils 1.1.2 → 1.2.0-rc.2

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 (107) hide show
  1. package/lib/ActionUtils.mjs +4 -4
  2. package/lib/ActionUtils.mjs.map +1 -1
  3. package/lib/FetchUtils.mjs.map +1 -1
  4. package/lib/animationKeyframes.mjs +11 -0
  5. package/lib/animationKeyframes.mjs.map +1 -0
  6. package/lib/createPressEvent.mjs +1 -1
  7. package/lib/createPressEvent.mjs.map +1 -1
  8. package/lib/fixMediaQuery.mjs +43 -17
  9. package/lib/fixMediaQuery.mjs.map +1 -1
  10. package/lib/fixMediaText.mjs +16 -0
  11. package/lib/fixMediaText.mjs.map +1 -0
  12. package/lib/formatDate.mjs.map +1 -1
  13. package/lib/formatUtils.mjs +2 -2
  14. package/lib/formatUtils.mjs.map +1 -1
  15. package/lib/getClosestOffsetScroll.mjs.map +1 -1
  16. package/lib/hooks/useEventListener.mjs.map +1 -1
  17. package/lib/index.cjs +311 -199
  18. package/lib/index.cjs.map +1 -1
  19. package/lib/index.mjs +5 -3
  20. package/lib/index.mjs.map +1 -1
  21. package/lib/insertKeyframes.mjs +68 -0
  22. package/lib/insertKeyframes.mjs.map +1 -0
  23. package/lib/lodashUtils.mjs +6 -6
  24. package/lib/lodashUtils.mjs.map +1 -1
  25. package/lib/promiseUtils.mjs.map +1 -1
  26. package/lib/reactUtils.mjs +1 -1
  27. package/lib/reactUtils.mjs.map +1 -1
  28. package/lib/reduceUtils.mjs.map +1 -1
  29. package/lib/smoothScroll.mjs.map +1 -1
  30. package/lib/styled.mjs +25 -144
  31. package/lib/styled.mjs.map +1 -1
  32. package/lib/styledShared.mjs +125 -0
  33. package/lib/styledShared.mjs.map +1 -0
  34. package/lib/timeUtils.mjs +1 -1
  35. package/lib/timeUtils.mjs.map +1 -1
  36. package/lib/timerUtils.mjs +0 -1
  37. package/lib/timerUtils.mjs.map +1 -1
  38. package/lib/utils.mjs +1 -1
  39. package/lib/utils.mjs.map +1 -1
  40. package/lib/wrapLazy.mjs +2 -2
  41. package/lib/wrapLazy.mjs.map +1 -1
  42. package/lib/yakDomTag.mjs +44 -0
  43. package/lib/yakDomTag.mjs.map +1 -0
  44. package/lib-yak/ActionUtils.mjs +117 -0
  45. package/lib-yak/ActionUtils.mjs.map +1 -0
  46. package/lib-yak/FetchUtils.mjs +100 -0
  47. package/lib-yak/FetchUtils.mjs.map +1 -0
  48. package/lib-yak/animationKeyframes.mjs +31 -0
  49. package/lib-yak/animationKeyframes.mjs.map +1 -0
  50. package/lib-yak/createPressEvent.mjs +74 -0
  51. package/lib-yak/createPressEvent.mjs.map +1 -0
  52. package/lib-yak/fixMediaQuery.mjs +90 -0
  53. package/lib-yak/fixMediaQuery.mjs.map +1 -0
  54. package/lib-yak/fixMediaText.mjs +16 -0
  55. package/lib-yak/fixMediaText.mjs.map +1 -0
  56. package/lib-yak/formatDate.mjs +110 -0
  57. package/lib-yak/formatDate.mjs.map +1 -0
  58. package/lib-yak/formatUtils.mjs +64 -0
  59. package/lib-yak/formatUtils.mjs.map +1 -0
  60. package/lib-yak/getClosestOffsetScroll.mjs +15 -0
  61. package/lib-yak/getClosestOffsetScroll.mjs.map +1 -0
  62. package/lib-yak/hooks/useEventListener.mjs +27 -0
  63. package/lib-yak/hooks/useEventListener.mjs.map +1 -0
  64. package/lib-yak/index.mjs +21 -0
  65. package/lib-yak/index.mjs.map +1 -0
  66. package/lib-yak/insertKeyframes.mjs +68 -0
  67. package/lib-yak/insertKeyframes.mjs.map +1 -0
  68. package/lib-yak/lodashUtils.mjs +131 -0
  69. package/lib-yak/lodashUtils.mjs.map +1 -0
  70. package/lib-yak/promiseUtils.mjs +92 -0
  71. package/lib-yak/promiseUtils.mjs.map +1 -0
  72. package/lib-yak/reactUtils.mjs +12 -0
  73. package/lib-yak/reactUtils.mjs.map +1 -0
  74. package/lib-yak/reduceUtils.mjs +14 -0
  75. package/lib-yak/reduceUtils.mjs.map +1 -0
  76. package/lib-yak/smoothScroll.mjs +59 -0
  77. package/lib-yak/smoothScroll.mjs.map +1 -0
  78. package/lib-yak/styled.mjs +23 -0
  79. package/lib-yak/styled.mjs.map +1 -0
  80. package/lib-yak/styledShared.mjs +129 -0
  81. package/lib-yak/styledShared.mjs.map +1 -0
  82. package/lib-yak/timeUtils.mjs +81 -0
  83. package/lib-yak/timeUtils.mjs.map +1 -0
  84. package/lib-yak/timerUtils.mjs +10 -0
  85. package/lib-yak/timerUtils.mjs.map +1 -0
  86. package/lib-yak/utils.mjs +386 -0
  87. package/lib-yak/utils.mjs.map +1 -0
  88. package/lib-yak/wrapLazy.mjs +132 -0
  89. package/lib-yak/wrapLazy.mjs.map +1 -0
  90. package/lib-yak/yakDomTag.mjs +44 -0
  91. package/lib-yak/yakDomTag.mjs.map +1 -0
  92. package/package.json +14 -3
  93. package/src/animationKeyframes.js +10 -0
  94. package/src/animationKeyframes.test.mjs +75 -0
  95. package/src/animationKeyframes.yak.js +30 -0
  96. package/src/fixMediaQuery.js +40 -19
  97. package/src/fixMediaText.js +18 -0
  98. package/src/fixMediaText.test.mjs +60 -0
  99. package/src/index.js +1 -0
  100. package/src/insertKeyframes.js +73 -0
  101. package/src/insertKeyframes.test.mjs +144 -0
  102. package/src/styled.js +5 -97
  103. package/src/styled.yak.js +30 -0
  104. package/src/styledShared.js +96 -0
  105. package/src/timerUtils.jsx +0 -2
  106. package/src/yakDomTag.jsx +42 -0
  107. package/src/yakDomTag.test.mjs +49 -0
@@ -0,0 +1,59 @@
1
+ // Get the top position of an element in the document
2
+ const getTop = function (element, start) {
3
+ // return value of html.getBoundingClientRect().top ... IE : 0, other browsers : -pageYOffset
4
+ if (!element || element.nodeName === 'HTML') return -start;
5
+ return element.getBoundingClientRect().top + start;
6
+ };
7
+ // ease in out function thanks to:
8
+ // http://blog.greweb.fr/2012/02/bezier-curve-based-easing-functions-from-concept-to-implementation/
9
+ const easeInOutCubic = function (t) {
10
+ return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
11
+ };
12
+
13
+ // calculate the scroll position we should be in
14
+ // given the start and end point of the scroll
15
+ // the time elapsed from the beginning of the scroll
16
+ // and the total duration of the scroll (default 500ms)
17
+ const position = function (start, end, elapsed, duration) {
18
+ if (elapsed > duration) return end;
19
+ return start + (end - start) * easeInOutCubic(elapsed / duration); // <-- you can change the easing funtion there
20
+ // return start + (end - start) * (elapsed / duration); // <-- this would give a linear scroll
21
+ };
22
+
23
+ // we use requestAnimationFrame to be called by the browser before every repaint
24
+ // if the first argument is an element then scroll to the top of this element
25
+ // if the first argument is numeric then scroll to this location
26
+ // if the callback exist, it is called when the scrolling is finished
27
+ // if context is set then scroll that element, else scroll window
28
+ const smoothScroll = function (el) {
29
+ let duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
30
+ let callback = arguments.length > 2 ? arguments[2] : undefined;
31
+ let ctx = arguments.length > 3 ? arguments[3] : undefined;
32
+ const context = ctx || window;
33
+ const start = context.scrollTop || window.pageYOffset;
34
+ const offset = el instanceof HTMLElement ? 0 : el.offset || 0;
35
+ const end = offset + (typeof el === 'number' ? Math.round(el) : el instanceof HTMLElement ? getTop(el, start) : getTop(el.target, start));
36
+ const clock = Date.now();
37
+ const requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || function (fn) {
38
+ window.setTimeout(fn, 15);
39
+ };
40
+ const step = () => {
41
+ const elapsed = Date.now() - clock;
42
+ if (context !== window) {
43
+ context.scrollTop = position(start, end, elapsed, duration);
44
+ } else {
45
+ window.scroll(window.pageXOffset, position(start, end, elapsed, duration));
46
+ }
47
+ if (elapsed > duration) {
48
+ if (typeof callback === 'function') {
49
+ callback(el);
50
+ }
51
+ } else {
52
+ requestAnimationFrame(step);
53
+ }
54
+ };
55
+ step();
56
+ };
57
+
58
+ export { smoothScroll };
59
+ //# sourceMappingURL=smoothScroll.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoothScroll.mjs","sources":["../src/smoothScroll.js"],"sourcesContent":["// @flow\n// Get the top position of an element in the document\nconst getTop = function(element, start) {\n // return value of html.getBoundingClientRect().top ... IE : 0, other browsers : -pageYOffset\n if(!element || element.nodeName === 'HTML') return -start\n return element.getBoundingClientRect().top + start\n}\n// ease in out function thanks to:\n// http://blog.greweb.fr/2012/02/bezier-curve-based-easing-functions-from-concept-to-implementation/\nconst easeInOutCubic = function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 }\n\n// calculate the scroll position we should be in\n// given the start and end point of the scroll\n// the time elapsed from the beginning of the scroll\n// and the total duration of the scroll (default 500ms)\nconst position = function(start, end, elapsed, duration) {\n if (elapsed > duration) return end;\n return start + (end - start) * easeInOutCubic(elapsed / duration); // <-- you can change the easing funtion there\n // return start + (end - start) * (elapsed / duration); // <-- this would give a linear scroll\n}\n\n// we use requestAnimationFrame to be called by the browser before every repaint\n// if the first argument is an element then scroll to the top of this element\n// if the first argument is numeric then scroll to this location\n// if the callback exist, it is called when the scrolling is finished\n// if context is set then scroll that element, else scroll window\nexport const smoothScroll = (el, duration = 500, callback, ctx) => {\n const context = ctx || window;\n const start = context.scrollTop || window.pageYOffset;\n const offset = el instanceof HTMLElement ? 0 : el.offset||0\n\n const end = offset + (typeof el === 'number' ? Math.round(el) :\n el instanceof HTMLElement ? getTop(el, start) : getTop(el.target,start))\n\n const clock = Date.now();\n const requestAnimationFrame = window.requestAnimationFrame ||\n window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||\n function(fn){window.setTimeout(fn, 15);};\n\n const step = () => {\n const elapsed = Date.now() - clock;\n if (context !== window) {\n context.scrollTop = position(start, end, elapsed, duration);\n }\n else {\n window.scroll(window.pageXOffset, position(start, end, elapsed, duration));\n }\n\n if (elapsed > duration) {\n if (typeof callback === 'function') {\n callback(el);\n }\n } else {\n requestAnimationFrame(step);\n }\n }\n step();\n}"],"names":["getTop","element","start","nodeName","getBoundingClientRect","top","easeInOutCubic","t","position","end","elapsed","duration","smoothScroll","el","arguments","length","undefined","callback","ctx","context","window","scrollTop","pageYOffset","offset","HTMLElement","Math","round","target","clock","Date","now","requestAnimationFrame","mozRequestAnimationFrame","webkitRequestAnimationFrame","fn","setTimeout","step","scroll","pageXOffset"],"mappings":"AACA;AACA,MAAMA,MAAM,GAAG,UAASC,OAAO,EAAEC,KAAK,EAAE;AACtC;EACA,IAAG,CAACD,OAAO,IAAIA,OAAO,CAACE,QAAQ,KAAK,MAAM,EAAE,OAAO,CAACD,KAAK,CAAA;EACzD,OAAOD,OAAO,CAACG,qBAAqB,EAAE,CAACC,GAAG,GAAGH,KAAK,CAAA;AACpD,CAAC,CAAA;AACD;AACA;AACA,MAAMI,cAAc,GAAG,UAAUC,CAAC,EAAE;AAAE,EAAA,OAAOA,CAAC,GAAC,EAAE,GAAG,CAAC,GAACA,CAAC,GAACA,CAAC,GAACA,CAAC,GAAG,CAACA,CAAC,GAAC,CAAC,KAAG,CAAC,GAACA,CAAC,GAAC,CAAC,CAAC,IAAE,CAAC,GAACA,CAAC,GAAC,CAAC,CAAC,GAAC,CAAC,CAAA;AAAC,CAAC,CAAA;;AAEvF;AACA;AACA;AACA;AACA,MAAMC,QAAQ,GAAG,UAASN,KAAK,EAAEO,GAAG,EAAEC,OAAO,EAAEC,QAAQ,EAAE;AACvD,EAAA,IAAID,OAAO,GAAGC,QAAQ,EAAE,OAAOF,GAAG,CAAA;AAClC,EAAA,OAAOP,KAAK,GAAG,CAACO,GAAG,GAAGP,KAAK,IAAII,cAAc,CAACI,OAAO,GAAGC,QAAQ,CAAC,CAAC;AAClE;AACF,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;MACaC,YAAY,GAAG,UAACC,EAAE,EAAoC;AAAA,EAAA,IAAlCF,QAAQ,GAAAG,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,C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,EAAEC,QAAQ,CAAC,CAAA;AAC7D,KAAC,MACI;AACHS,MAAAA,MAAM,CAACiB,MAAM,CAACjB,MAAM,CAACkB,WAAW,EAAE9B,QAAQ,CAACN,KAAK,EAAEO,GAAG,EAAEC,OAAO,EAAEC,QAAQ,CAAC,CAAC,CAAA;AAC5E,KAAA;IAEA,IAAID,OAAO,GAAGC,QAAQ,EAAE;AACtB,MAAA,IAAI,OAAOM,QAAQ,KAAK,UAAU,EAAE;QAClCA,QAAQ,CAACJ,EAAE,CAAC,CAAA;AACd,OAAA;AACF,KAAC,MAAM;MACLkB,qBAAqB,CAACK,IAAI,CAAC,CAAA;AAC7B,KAAA;GACD,CAAA;AACDA,EAAAA,IAAI,EAAE,CAAA;AACR;;;;"}
@@ -0,0 +1,23 @@
1
+ import _isEqual from 'lodash/fp/isEqual';
2
+ import _isFunction from 'lodash/fp/isFunction';
3
+ import { ifPropValue } from './styledShared.mjs';
4
+ export { animationTiming, customTheme, getColor, getMargin, identityOpacityFrames, identityTranslateFrames, oneWayAnimation, prop, twoWayAnimation, vheight } from './styledShared.mjs';
5
+
6
+ const notInYak = (name, instead) => () => {
7
+ throw new Error(`@startlibs/utils: ${name} usa styled-components e não existe no modo yak. Use ${instead}.`);
8
+ };
9
+ const ifProp = (path, pass, fail) => pass && !_isFunction(pass) ? ifPropValue(path, pass, fail) : notInYak('ifProp com template', 'uma função de props com css`` do @yak/react');
10
+ const ifPropEquals = (path, str) => ifProp(path, _isEqual(str));
11
+ const ifNotProp = path => ifProp(path, v => !v);
12
+ const media = () => notInYak('media', '@media no próprio CSS');
13
+ media.mobile = media();
14
+ media.between = media;
15
+ media.max = media;
16
+ media.min = media;
17
+ media.desktop = media();
18
+ const styledExtend = notInYak('styledExtend', 'styled(Componente)');
19
+ const printerMedia = notInYak('printerMedia', '@media print');
20
+ const notPrinterMedia = notInYak('notPrinterMedia', '@media screen');
21
+
22
+ export { ifNotProp, ifProp, ifPropEquals, media, notPrinterMedia, printerMedia, styledExtend };
23
+ //# sourceMappingURL=styled.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styled.mjs","sources":["../src/styled.yak.js"],"sourcesContent":["// Saída yak (lib-yak/) de styled.js, sem styled-components: o runtime dele não vai para o bundle.\n// O plugin startlibs-to-yak reduz ifProp (template), media, styledExtend e printerMedia a CSS\n// estático no build da startlibs. No app em modo yak, esses helpers não têm como funcionar em\n// runtime: falham com uma mensagem clara em vez de gerar CSS errado.\nimport _ from 'lodash/fp'\nimport {ifPropValue} from './styledShared'\n\nexport {getColor, getMargin, prop, customTheme, vheight, oneWayAnimation, twoWayAnimation, animationTiming, identityTranslateFrames, identityOpacityFrames} from './styledShared'\n\nconst notInYak = (name, instead) => () => {\n throw new Error(`@startlibs/utils: ${name} usa styled-components e não existe no modo yak. Use ${instead}.`)\n}\n\nexport const ifProp = (path, pass, fail) =>\n pass && !_.isFunction(pass)\n ? ifPropValue(path, pass, fail)\n : notInYak('ifProp com template', 'uma função de props com css`` do @yak/react')\nexport const ifPropEquals = (path,str) => ifProp(path,_.isEqual(str))\nexport const ifNotProp = (path) => ifProp(path,v => !v)\n\nexport const media = () => notInYak('media', '@media no próprio CSS')\nmedia.mobile = media()\nmedia.between = media\nmedia.max = media\nmedia.min = media\nmedia.desktop = media()\n\nexport const styledExtend = notInYak('styledExtend', 'styled(Componente)')\nexport const printerMedia = notInYak('printerMedia', '@media print')\nexport const notPrinterMedia = notInYak('notPrinterMedia', '@media screen')\n"],"names":["notInYak","name","instead","Error","ifProp","path","pass","fail","_isFunction","ifPropValue","ifPropEquals","str","_isEqual","ifNotProp","v","media","mobile","between","max","min","desktop","styledExtend","printerMedia","notPrinterMedia"],"mappings":";;;;;AASA,MAAMA,QAAQ,GAAGA,CAACC,IAAI,EAAEC,OAAO,KAAK,MAAM;EACxC,MAAM,IAAIC,KAAK,CAAC,CAAA,kBAAA,EAAqBF,IAAI,CAAwDC,qDAAAA,EAAAA,OAAO,GAAG,CAAC,CAAA;AAC9G,CAAC,CAAA;AAEYE,MAAAA,MAAM,GAAGA,CAACC,IAAI,EAAEC,IAAI,EAAEC,IAAI,KACrCD,IAAI,IAAI,CAACE,WAAA,CAAaF,IAAI,CAAC,GACvBG,WAAW,CAACJ,IAAI,EAAEC,IAAI,EAAEC,IAAI,CAAC,GAC7BP,QAAQ,CAAC,qBAAqB,EAAE,6CAA6C,EAAC;MACvEU,YAAY,GAAGA,CAACL,IAAI,EAACM,GAAG,KAAKP,MAAM,CAACC,IAAI,EAACO,QAAA,CAAUD,GAAG,CAAC,EAAC;AACxDE,MAAAA,SAAS,GAAIR,IAAI,IAAKD,MAAM,CAACC,IAAI,EAACS,CAAC,IAAI,CAACA,CAAC,EAAC;AAEhD,MAAMC,KAAK,GAAGA,MAAMf,QAAQ,CAAC,OAAO,EAAE,uBAAuB,EAAC;AACrEe,KAAK,CAACC,MAAM,GAAGD,KAAK,EAAE,CAAA;AACtBA,KAAK,CAACE,OAAO,GAAGF,KAAK,CAAA;AACrBA,KAAK,CAACG,GAAG,GAAGH,KAAK,CAAA;AACjBA,KAAK,CAACI,GAAG,GAAGJ,KAAK,CAAA;AACjBA,KAAK,CAACK,OAAO,GAAGL,KAAK,EAAE,CAAA;AAEhB,MAAMM,YAAY,GAAGrB,QAAQ,CAAC,cAAc,EAAE,oBAAoB,EAAC;AACnE,MAAMsB,YAAY,GAAGtB,QAAQ,CAAC,cAAc,EAAE,cAAc,EAAC;AAC7D,MAAMuB,eAAe,GAAGvB,QAAQ,CAAC,iBAAiB,EAAE,eAAe;;;;"}
@@ -0,0 +1,129 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
+ import _reverse from 'lodash/fp/reverse';
5
+ import _get from 'lodash/fp/get';
6
+ import _unset from 'lodash/fp/unset';
7
+ import { darken } from 'polished';
8
+ import { animationKeyframes } from './animationKeyframes.mjs';
9
+ import { _s } from './lodashUtils.mjs';
10
+
11
+ const _excluded = ["theme"];
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ const getColor = (propsOrColor, hover) => {
15
+ if (propsOrColor === undefined) {
16
+ return _ref => {
17
+ let theme = _ref.theme;
18
+ return theme.colors.gray150;
19
+ };
20
+ }
21
+ if (typeof propsOrColor === 'string') {
22
+ return _ref2 => {
23
+ let theme = _ref2.theme;
24
+ return theme.colors[propsOrColor] || propsOrColor;
25
+ };
26
+ }
27
+ const theme = propsOrColor.theme,
28
+ props = _objectWithoutProperties(propsOrColor, _excluded);
29
+ if (props.dark) {
30
+ return darken(0.1, getColor(_objectSpread({
31
+ theme
32
+ }, _unset('dark', props))));
33
+ } else if (hover && props.hover) {
34
+ return getColor({
35
+ theme,
36
+ color: props.hover
37
+ });
38
+ } else if (props.color) {
39
+ return theme.colors[props.color] || props.color;
40
+ } else if (props.highlight) {
41
+ return theme.colors.main;
42
+ } else if (props.alert) {
43
+ return theme.colors.alert;
44
+ } else if (props.success) {
45
+ return theme.colors.success;
46
+ } else {
47
+ return theme.colors.gray150;
48
+ }
49
+ };
50
+ const getMargin = enumeratedMargins => props => enumeratedMargins[props.margin] || props.margin || enumeratedMargins['default'] || 0;
51
+
52
+ /**
53
+ * Returns the value of `props[path]` or `defaultValue`
54
+ * @example
55
+ * const Button = styled.button`
56
+ * color: ${prop('color', 'red')};
57
+ * `
58
+ */
59
+ const prop = (path, defaultValue) => function () {
60
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
61
+ return _get(path.trim(), props) || defaultValue;
62
+ };
63
+ const customTheme = type => function () {
64
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
65
+ return _get(["theme", "startlibs", type], props) || '';
66
+ };
67
+ const vheight = (strings, size) => {
68
+ const propType = strings[0];
69
+ const calc = (strings[1] || "").replace(";", "").trim();
70
+ return `
71
+ ${propType} ${calc ? `calc(${size}vh ${calc})` : `${size}vh`};
72
+ ${propType} ${calc ? `calc(calc(var(--vh, 1vh) * ${size}) ${calc})` : `calc(var(--vh, 1vh) * ${size})`};
73
+ `;
74
+ };
75
+ const getFrameOffset = (i, total) => Math.round(i * 100 / (total - 1));
76
+ const oneWayAnimation = function () {
77
+ for (var _len = arguments.length, frames = new Array(_len), _key = 0; _key < _len; _key++) {
78
+ frames[_key] = arguments[_key];
79
+ }
80
+ return animationKeyframes`
81
+ ${frames.map((frame, i) => !frame ? '' : `${getFrameOffset(i, frames.length)}% {
82
+ ${frame}
83
+ }`)}`;
84
+ };
85
+ const twoWayAnimation = function () {
86
+ for (var _len2 = arguments.length, frames = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
87
+ frames[_key2] = arguments[_key2];
88
+ }
89
+ return [frames, _reverse(frames)].map(frames => oneWayAnimation(...frames));
90
+ };
91
+ const animationTiming = props => function () {
92
+ for (var _len3 = arguments.length, animations = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
93
+ animations[_key3] = arguments[_key3];
94
+ }
95
+ return animations.filter(_ => _).map(_ => _ + ' ' + props).join(',');
96
+ };
97
+ const identityTranslateFrames = oneWayAnimation('transform: translateY(0);', 'transform: translateY(0);');
98
+ const identityOpacityFrames = oneWayAnimation('opacity: 1;', 'opacity:1;');
99
+ function testSinglePath(props, path) {
100
+ if (typeof path === 'string') {
101
+ return !!_s.get(path, props);
102
+ } else if (typeof path === 'number') {
103
+ return !!props[path];
104
+ } else {
105
+ return false;
106
+ }
107
+ }
108
+
109
+ // ifProp na forma antiga (valor pronto, não template): devolve pass ou fail
110
+ const ifPropValue = (path, pass, fail) => function () {
111
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
112
+ let result = false;
113
+ if (Array.isArray(path)) {
114
+ result = path.every(p => testSinglePath(props, p));
115
+ } else if (typeof path === 'object') {
116
+ result = !Object.entries(path).find(_ref3 => {
117
+ let _ref4 = _slicedToArray(_ref3, 2),
118
+ k = _ref4[0],
119
+ v = _ref4[1];
120
+ return props[k] !== v;
121
+ });
122
+ } else {
123
+ result = testSinglePath(props, path);
124
+ }
125
+ return result ? pass : fail;
126
+ };
127
+
128
+ export { animationTiming, customTheme, getColor, getMargin, identityOpacityFrames, identityTranslateFrames, ifPropValue, oneWayAnimation, prop, twoWayAnimation, vheight };
129
+ //# sourceMappingURL=styledShared.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styledShared.mjs","sources":["../src/styledShared.js"],"sourcesContent":["// Helpers de estilo que não dependem de styled-components: valem na lib/ e na lib-yak/.\nimport _ from 'lodash/fp'\nimport {darken} from 'polished'\nimport {animationKeyframes} from './animationKeyframes'\nimport {_s} from './lodashUtils'\n\nexport const getColor = (propsOrColor, hover) => {\n if (propsOrColor === undefined) {\n return ({theme})=>theme.colors.gray150\n }\n if (typeof propsOrColor==='string') {\n return ({theme})=>theme.colors[propsOrColor] || propsOrColor\n }\n const {theme,...props} = propsOrColor\n if (props.dark) {\n return darken(0.1, getColor({theme, ..._.unset( 'dark', props)}))\n } else if (hover && props.hover) {\n return getColor({theme, color: props.hover})\n } else if (props.color) {\n return theme.colors[props.color] || props.color\n } else if (props.highlight) {\n return theme.colors.main\n } else if (props.alert) {\n return theme.colors.alert\n } else if (props.success) {\n return theme.colors.success\n } else {\n return theme.colors.gray150\n }\n}\n\nexport const getMargin = (enumeratedMargins) => (props) => enumeratedMargins[props.margin] || props.margin || enumeratedMargins['default'] || 0\n\n/**\n * Returns the value of `props[path]` or `defaultValue`\n * @example\n * const Button = styled.button`\n * color: ${prop('color', 'red')};\n * `\n */\nexport const prop = (path,defaultValue) =>\n (props = {}) => _.get(path.trim(), props) || defaultValue\n\nexport const customTheme = (type) =>\n (props = {}) => _.get([\"theme\",\"startlibs\",type], props) || ''\n\nexport const vheight = (strings,size) => {\n const propType = strings[0]\n const calc = (strings[1]||\"\").replace(\";\",\"\").trim()\n return `\n ${propType} ${calc ? `calc(${size}vh ${calc})` : `${size}vh`};\n ${propType} ${calc ? `calc(calc(var(--vh, 1vh) * ${size}) ${calc})` : `calc(var(--vh, 1vh) * ${size})`};\n `\n}\n\nconst getFrameOffset = (i,total) => Math.round(i*100/(total-1))\n\n\nexport const oneWayAnimation = (...frames) => {\n return animationKeyframes`\n ${frames.map((frame,i) =>\n !frame ? '' : `${getFrameOffset(i,frames.length)}% {\n ${frame}\n }`\n )}`\n}\n\nexport const twoWayAnimation = (...frames) => [frames,_.reverse(frames)].map((frames)=>oneWayAnimation(...frames))\n\nexport const animationTiming = (props) => (...animations) => animations.filter(_=>_).map(_=>_+' '+props).join(',')\n\nexport const identityTranslateFrames = oneWayAnimation('transform: translateY(0);', 'transform: translateY(0);')\nexport const identityOpacityFrames = oneWayAnimation('opacity: 1;', 'opacity:1;')\n\nfunction testSinglePath(props,path) {\n if (typeof path === 'string') {\n return !!_s.get(path, props)\n } else if (typeof path === 'number') {\n return !!props[path]\n } else {\n return false\n }\n}\n\n// ifProp na forma antiga (valor pronto, não template): devolve pass ou fail\nexport const ifPropValue = (path, pass, fail) => (props = {}) => {\n let result = false\n if (Array.isArray(path)) {\n result = path.every(p=> testSinglePath(props,p))\n } else if (typeof path === 'object') {\n result = !Object.entries(path).find(([k,v])=>props[k]!==v)\n } else {\n result = testSinglePath(props,path)\n }\n return result ? pass : fail\n}\n"],"names":["_excluded","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","getColor","propsOrColor","hover","undefined","_ref","theme","colors","gray150","_ref2","props","_objectWithoutProperties","dark","darken","_unset","color","highlight","main","alert","success","getMargin","enumeratedMargins","margin","prop","path","defaultValue","_get","trim","customTheme","type","vheight","strings","size","propType","calc","replace","getFrameOffset","i","total","Math","round","oneWayAnimation","_len","frames","Array","_key","animationKeyframes","map","frame","twoWayAnimation","_len2","_key2","_reverse","animationTiming","_len3","animations","_key3","_","join","identityTranslateFrames","identityOpacityFrames","testSinglePath","_s","get","ifPropValue","pass","fail","result","isArray","every","p","entries","find","_ref3","_ref4","_slicedToArray","k","v"],"mappings":";;;;;;;;;;AAAA,MAAAA,SAAA,GAAA,CAAA,OAAA,CAAA,CAAA;AAAA,SAAAC,OAAAA,CAAAC,CAAA,EAAAC,CAAA,EAAA,EAAA,IAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,EAAA,EAAA,IAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,CAAA,CAAA,CAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,CAAAN,UAAAA,CAAA,EAAAE,EAAAA,OAAAA,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,CAAA,EAAA,CAAA,CAAA,EAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,CAAA,CAAA,EAAA,CAAA,OAAAJ,CAAA,CAAA,EAAA;AAAA,SAAAU,cAAAZ,CAAA,EAAA,EAAA,KAAA,IAAAC,CAAA,GAAAA,CAAAA,EAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,EAAAC,EAAAA,EAAAA,IAAAA,CAAA,WAAAW,SAAA,CAAAZ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,CAAA,CAAA,GAAG,EAAE,CAAA;EAC1D,IAAIyE,MAAM,GAAG,KAAK,CAAA;AAClB,EAAA,IAAIvB,KAAK,CAACwB,OAAO,CAAC5C,IAAI,CAAC,EAAE;AACvB2C,IAAAA,MAAM,GAAG3C,IAAI,CAAC6C,KAAK,CAACC,CAAC,IAAGT,cAAc,CAACnD,KAAK,EAAC4D,CAAC,CAAC,CAAC,CAAA;AAClD,GAAC,MAAM,IAAI,OAAO9C,IAAI,KAAK,QAAQ,EAAE;IACnC2C,MAAM,GAAG,CAACnF,MAAM,CAACuF,OAAO,CAAC/C,IAAI,CAAC,CAACgD,IAAI,CAACC,KAAA,IAAA;AAAA,MAAA,IAAAC,KAAA,GAAAC,cAAA,CAAAF,KAAA,EAAA,CAAA,CAAA;AAAEG,QAAAA,CAAC,GAAAF,KAAA,CAAA,CAAA,CAAA;AAACG,QAAAA,CAAC,GAAAH,KAAA,CAAA,CAAA,CAAA,CAAA;AAAA,MAAA,OAAIhE,KAAK,CAACkE,CAAC,CAAC,KAAGC,CAAC,CAAA;KAAC,CAAA,CAAA;AAC5D,GAAC,MAAM;AACLV,IAAAA,MAAM,GAAGN,cAAc,CAACnD,KAAK,EAACc,IAAI,CAAC,CAAA;AACrC,GAAA;AACA,EAAA,OAAO2C,MAAM,GAAGF,IAAI,GAAGC,IAAI,CAAA;AAC7B;;;;"}
@@ -0,0 +1,81 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import 'react';
3
+
4
+ const SECOND = 1000;
5
+ const MINUTE = SECOND * 60;
6
+ const HOUR = MINUTE * 60;
7
+ const DAY = HOUR * 24;
8
+ const WEEK = DAY * 7;
9
+ const MONTH = DAY * 31;
10
+ const YEAR = DAY * 366;
11
+ const getStartOfDay = function (d) {
12
+ let utc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
13
+ const date = new Date(d);
14
+ if (utc) {
15
+ date.setUTCHours(0, 0, 0, 0);
16
+ } else {
17
+ date.setHours(0, 0, 0, 0);
18
+ }
19
+ return date;
20
+ };
21
+ const isSameDay = function (a, b) {
22
+ let utc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
23
+ return getStartOfDay(a, utc).getTime() === getStartOfDay(b, utc).getTime();
24
+ };
25
+ const intervalsIntersect = (_ref, _ref2) => {
26
+ let _ref3 = _slicedToArray(_ref, 2),
27
+ a1 = _ref3[0],
28
+ a2 = _ref3[1];
29
+ let _ref4 = _slicedToArray(_ref2, 2),
30
+ b1 = _ref4[0],
31
+ b2 = _ref4[1];
32
+ return b2 >= a1 && b1 <= a2;
33
+ };
34
+ const intervalsIntersectExclusive = (_ref5, _ref6) => {
35
+ let _ref7 = _slicedToArray(_ref5, 2),
36
+ a1 = _ref7[0],
37
+ a2 = _ref7[1];
38
+ let _ref8 = _slicedToArray(_ref6, 2),
39
+ b1 = _ref8[0],
40
+ b2 = _ref8[1];
41
+ return b2 > a1 && b1 < a2;
42
+ };
43
+ const intervalsIntersection = (a, b) => {
44
+ if (!intervalsIntersect(a, b)) {
45
+ return [];
46
+ }
47
+ return [[Math.max(a[0], b[0]), Math.min(a[1], b[1])]];
48
+ };
49
+ const diffIntervals = (_ref9, _ref0) => {
50
+ let _ref1 = _slicedToArray(_ref9, 2),
51
+ a1 = _ref1[0],
52
+ a2 = _ref1[1];
53
+ let _ref10 = _slicedToArray(_ref0, 2),
54
+ b1 = _ref10[0],
55
+ b2 = _ref10[1];
56
+ if (a1 >= b2 ||
57
+ // a after b
58
+ b1 >= a2 // a before b
59
+ ) {
60
+ return [[a1, a2]];
61
+ } else if (a1 > b1 && a2 < b2) {
62
+ // a inside b
63
+ return [];
64
+ }
65
+ if (b1 > a1 && b2 < a2) {
66
+ // b inside a
67
+ return [[a1, b1], [b2, a2]];
68
+ }
69
+ if (b1 <= a1) {
70
+ // b intersecting left of a
71
+ return [[b2, a2]];
72
+ } else {
73
+ // b intersecting right of a
74
+ return [[a1, b1]];
75
+ }
76
+ };
77
+ const blockDiffIntervals = (a, b) => intervalsIntersect(a, b) ? [] : [a];
78
+ const startBlockDiffIntervals = (a, b) => intervalsIntersectExclusive(a, b) && a[0] >= b[0] ? [] : [a];
79
+
80
+ export { DAY, HOUR, MINUTE, MONTH, SECOND, WEEK, YEAR, blockDiffIntervals, diffIntervals, getStartOfDay, intervalsIntersect, intervalsIntersectExclusive, intervalsIntersection, isSameDay, startBlockDiffIntervals };
81
+ //# sourceMappingURL=timeUtils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeUtils.mjs","sources":["../src/timeUtils.jsx"],"sourcesContent":["import React from 'react'\n\nexport const SECOND = 1000\nexport const MINUTE = SECOND * 60\nexport const HOUR = MINUTE * 60\nexport const DAY = HOUR * 24\nexport const WEEK = DAY * 7\nexport const MONTH = DAY * 31\nexport const YEAR = DAY * 366\n\nexport const getStartOfDay = (d,utc = false) => {\n const date = new Date(d)\n if (utc) {\n date.setUTCHours(0,0,0,0)\n } else {\n date.setHours(0,0,0,0)\n }\n return date\n}\nexport const isSameDay = (a,b,utc = false) => getStartOfDay(a,utc).getTime() === getStartOfDay(b,utc).getTime()\n\n\n\nexport const intervalsIntersect = ([a1, a2], [b1, b2]) =>\n (b2 >= a1) && (b1 <= a2)\n\nexport const intervalsIntersectExclusive = ([a1, a2], [b1, b2]) =>\n (b2 > a1) && (b1 < a2)\n\nexport const intervalsIntersection = (a, b) => {\n if (!intervalsIntersect(a,b)) {\n return []\n }\n return [[Math.max(a[0], b[0]), Math.min(a[1], b[1])]]\n}\n\nexport const diffIntervals = ([a1, a2], [b1, b2]) => {\n if (\n a1 >= b2 || // a after b\n b1 >= a2 // a before b\n ) {\n return [[a1, a2]]\n } else if (a1 > b1 && a2 < b2) { // a inside b\n return []\n }\n if (b1 > a1 && b2 < a2) { // b inside a\n return [[a1, b1], [b2, a2]]\n }\n if (b1 <= a1) { // b intersecting left of a\n return [[b2, a2]]\n } else { // b intersecting right of a\n return [[a1, b1]]\n }\n}\n\nexport const blockDiffIntervals = (a, b) => intervalsIntersect(a, b) ? [] : [a]\nexport const startBlockDiffIntervals = (a, b) => intervalsIntersectExclusive(a, b) && a[0] >= b[0] ? [] : [a]\n"],"names":["SECOND","MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getStartOfDay","d","utc","arguments","length","undefined","date","Date","setUTCHours","setHours","isSameDay","a","b","getTime","intervalsIntersect","_ref","_ref2","_ref3","_slicedToArray","a1","a2","_ref4","b1","b2","intervalsIntersectExclusive","_ref5","_ref6","_ref7","_ref8","intervalsIntersection","Math","max","min","diffIntervals","_ref9","_ref0","_ref1","_ref10","blockDiffIntervals","startBlockDiffIntervals"],"mappings":";;;AAEO,MAAMA,MAAM,GAAG,KAAI;AACbC,MAAAA,MAAM,GAAGD,MAAM,GAAG,GAAE;AACpBE,MAAAA,IAAI,GAAGD,MAAM,GAAG,GAAE;AAClBE,MAAAA,GAAG,GAAGD,IAAI,GAAG,GAAE;AACfE,MAAAA,IAAI,GAAGD,GAAG,GAAG,EAAC;AACdE,MAAAA,KAAK,GAAGF,GAAG,GAAG,GAAE;AAChBG,MAAAA,IAAI,GAAGH,GAAG,GAAG,IAAG;MAEhBI,aAAa,GAAG,UAACC,CAAC,EAAiB;AAAA,EAAA,IAAhBC,GAAG,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,KAAK,CAAA;AACzC,EAAA,MAAMG,IAAI,GAAG,IAAIC,IAAI,CAACN,CAAC,CAAC,CAAA;AACxB,EAAA,IAAIC,GAAG,EAAE;IACPI,IAAI,CAACE,WAAW,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,CAAA;AAC3B,GAAC,MAAM;IACLF,IAAI,CAACG,QAAQ,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,CAAA;AACxB,GAAA;AACA,EAAA,OAAOH,IAAI,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,IAAID,EAAE,GAAGH,EAAE,IAAII,EAAE,GAAGH,EAAE,EAAE;AAAE;AACxB,IAAA,OAAO,CAAC,CAACD,EAAE,EAAEG,EAAE,CAAC,EAAE,CAACC,EAAE,EAAEH,EAAE,CAAC,CAAC,CAAA;AAC7B,GAAA;EACA,IAAIE,EAAE,IAAIH,EAAE,EAAE;AAAE;AACd,IAAA,OAAO,CAAC,CAACI,EAAE,EAAEH,EAAE,CAAC,CAAC,CAAA;AACnB,GAAC,MAAM;AAAE;AACP,IAAA,OAAO,CAAC,CAACD,EAAE,EAAEG,EAAE,CAAC,CAAC,CAAA;AACnB,GAAA;AACF,EAAC;MAEYgB,kBAAkB,GAAGA,CAAC3B,CAAC,EAAEC,CAAC,KAAKE,kBAAkB,CAACH,CAAC,EAAEC,CAAC,CAAC,GAAG,EAAE,GAAG,CAACD,CAAC,EAAC;AAClE4B,MAAAA,uBAAuB,GAAGA,CAAC5B,CAAC,EAAEC,CAAC,KAAKY,2BAA2B,CAACb,CAAC,EAAEC,CAAC,CAAC,IAAID,CAAC,CAAC,CAAC,CAAC,IAAIC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAACD,CAAC;;;;"}
@@ -0,0 +1,10 @@
1
+ import 'react';
2
+
3
+ const timerPromise = time => new Promise(res => setTimeout(res, time));
4
+ const cancelableTimer = (res, time) => {
5
+ const v = setTimeout(res, time);
6
+ return () => clearTimeout(v);
7
+ };
8
+
9
+ export { cancelableTimer, timerPromise };
10
+ //# sourceMappingURL=timerUtils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timerUtils.mjs","sources":["../src/timerUtils.jsx"],"sourcesContent":["import React from 'react'\n\nexport const timerPromise = (time) => new Promise((res) => setTimeout(res,time))\n\nexport const cancelableTimer = (res,time) => {\n const v = setTimeout(res,time)\n return () => clearTimeout(v)\n}\n"],"names":["timerPromise","time","Promise","res","setTimeout","cancelableTimer","v","clearTimeout"],"mappings":";;MAEaA,YAAY,GAAIC,IAAI,IAAK,IAAIC,OAAO,CAAEC,GAAG,IAAKC,UAAU,CAACD,GAAG,EAACF,IAAI,CAAC,EAAC;MAEnEI,eAAe,GAAGA,CAACF,GAAG,EAACF,IAAI,KAAK;AAC3C,EAAA,MAAMK,CAAC,GAAGF,UAAU,CAACD,GAAG,EAACF,IAAI,CAAC,CAAA;AAC9B,EAAA,OAAO,MAAMM,YAAY,CAACD,CAAC,CAAC,CAAA;AAC9B;;;;"}