utils.js 1.2 KB

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