You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate.ts 813B

1234567891011121314151617181920212223242526272829
  1. import Rectangle from "./rectangle"
  2. import Circle from "./circle"
  3. import Ellipse from "./ellipse"
  4. import Polyline from "./polyline"
  5. import Dot from "./dot"
  6. import Line from "./line"
  7. import Vector from "./vector"
  8. import Utils from "./utils"
  9. import { codeShapes } from "./index"
  10. const scope = { Dot, Circle, Ellipse, Line, Polyline, Rectangle, Vector, Utils }
  11. /**
  12. * Evaluate code, collecting generated shapes in the shape set. Return the
  13. * collected shapes as an array.
  14. * @param code
  15. */
  16. export function getShapesFromCode(code: string) {
  17. codeShapes.clear()
  18. new Function(...Object.keys(scope), `${code}`)(...Object.values(scope))
  19. const generatedShapes = Array.from(codeShapes.values()).map((instance) => {
  20. instance.shape.isGenerated = true
  21. return instance.shape
  22. })
  23. return generatedShapes
  24. }