utils.js 968 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Container } from '../utils/container';
  2. export function effectTiming(defaults, value, options) {
  3. return Container.of({})
  4. .call(assignDefined, defaults)
  5. .call(assignDefined, value)
  6. .call(assignDefined, options)
  7. .value();
  8. }
  9. function assignDefined(target, source) {
  10. for (const [key, value] of Object.entries(source)) {
  11. if (value !== undefined) {
  12. target[key] = source[key];
  13. }
  14. }
  15. return target;
  16. }
  17. // TODO: Add more attributes need to be transform.
  18. // TODO: Opacity transform unexpectedly.
  19. export function attributeOf(shape, keys) {
  20. const attribute = {};
  21. for (const key of keys) {
  22. const value = shape.style[key];
  23. if (value) {
  24. attribute[key] = value;
  25. }
  26. }
  27. return attribute;
  28. }
  29. export const attributeKeys = [
  30. 'fill',
  31. 'stroke',
  32. 'fillOpacity',
  33. 'strokeOpacity',
  34. 'opacity',
  35. 'lineWidth',
  36. ];
  37. //# sourceMappingURL=utils.js.map