Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

generate.ts 861B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 Ray from "./ray"
  7. import Line from "./line"
  8. import Vector from "./vector"
  9. import Utils from "./utils"
  10. import { codeShapes } from "./index"
  11. const scope = {
  12. Dot,
  13. Circle,
  14. Ellipse,
  15. Ray,
  16. Line,
  17. Polyline,
  18. Rectangle,
  19. Vector,
  20. Utils,
  21. }
  22. /**
  23. * Evaluate code, collecting generated shapes in the shape set. Return the
  24. * collected shapes as an array.
  25. * @param code
  26. */
  27. export function getShapesFromCode(code: string) {
  28. codeShapes.clear()
  29. new Function(...Object.keys(scope), `${code}`)(...Object.values(scope))
  30. const generatedShapes = Array.from(codeShapes.values()).map((instance) => {
  31. instance.shape.isGenerated = true
  32. return instance.shape
  33. })
  34. return generatedShapes
  35. }