css.js 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { hash } from './core/hash';
  2. import { compile } from './core/compile';
  3. import { getSheet } from './core/get-sheet';
  4. /**
  5. * css entry
  6. * @param {String|Object|Function} val
  7. */
  8. function css(val) {
  9. let ctx = this || {};
  10. let _val = val.call ? val(ctx.p) : val;
  11. return hash(
  12. _val.unshift
  13. ? _val.raw
  14. ? // Tagged templates
  15. compile(_val, [].slice.call(arguments, 1), ctx.p)
  16. : // Regular arrays
  17. _val.reduce((o, i) => (i ? Object.assign(o, i.call ? i(ctx.p) : i) : o), {})
  18. : _val,
  19. getSheet(ctx.target),
  20. ctx.g,
  21. ctx.o,
  22. ctx.k
  23. );
  24. }
  25. /**
  26. * CSS Global function to declare global styles
  27. * @type {Function}
  28. */
  29. let glob = css.bind({ g: 1 });
  30. /**
  31. * `keyframes` function for defining animations
  32. * @type {Function}
  33. */
  34. let keyframes = css.bind({ k: 1 });
  35. export { css, glob, keyframes };