plotboilerplate 1.22.0 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/README.md +2 -0
  2. package/dist/index.esm.js +240 -79
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +510 -340
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +7 -4
  11. package/src/cjs/BezierPath.js.map +1 -1
  12. package/src/cjs/Bounds.js +1 -1
  13. package/src/cjs/Bounds.js.map +1 -1
  14. package/src/cjs/Circle.js.map +1 -1
  15. package/src/cjs/CircleSector.d.ts +64 -1
  16. package/src/cjs/CircleSector.js +121 -1
  17. package/src/cjs/CircleSector.js.map +1 -1
  18. package/src/cjs/CubicBezierCurve.js +2 -2
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Grid.js.map +1 -1
  21. package/src/cjs/KeyHandler.d.ts +1 -1
  22. package/src/cjs/KeyHandler.js +13 -13
  23. package/src/cjs/KeyHandler.js.map +1 -1
  24. package/src/cjs/Line.js +2 -0
  25. package/src/cjs/Line.js.map +1 -1
  26. package/src/cjs/MouseHandler.d.ts +2 -2
  27. package/src/cjs/MouseHandler.js +7 -5
  28. package/src/cjs/MouseHandler.js.map +1 -1
  29. package/src/cjs/PlotBoilerplate.d.ts +17 -4
  30. package/src/cjs/PlotBoilerplate.js +95 -66
  31. package/src/cjs/PlotBoilerplate.js.map +1 -1
  32. package/src/cjs/Polygon.js.map +1 -1
  33. package/src/cjs/Triangle.js +1 -1
  34. package/src/cjs/Triangle.js.map +1 -1
  35. package/src/cjs/UIDGenerator.js +1 -1
  36. package/src/cjs/UIDGenerator.js.map +1 -1
  37. package/src/cjs/VEllipse.js.map +1 -1
  38. package/src/cjs/VEllipseSector.js +1 -1
  39. package/src/cjs/VEllipseSector.js.map +1 -1
  40. package/src/cjs/Vector.js +2 -0
  41. package/src/cjs/Vector.js.map +1 -1
  42. package/src/cjs/VertTuple.js.map +1 -1
  43. package/src/cjs/Vertex.d.ts +3 -2
  44. package/src/cjs/Vertex.js +13 -7
  45. package/src/cjs/Vertex.js.map +1 -1
  46. package/src/cjs/VertexAttr.d.ts +2 -1
  47. package/src/cjs/VertexAttr.js +2 -1
  48. package/src/cjs/VertexAttr.js.map +1 -1
  49. package/src/cjs/VertexListeners.d.ts +1 -1
  50. package/src/cjs/VertexListeners.js.map +1 -1
  51. package/src/cjs/draw.js +1 -1
  52. package/src/cjs/draw.js.map +1 -1
  53. package/src/cjs/drawgl.js.map +1 -1
  54. package/src/cjs/drawutilssvg.d.ts +17 -3
  55. package/src/cjs/drawutilssvg.js +97 -91
  56. package/src/cjs/drawutilssvg.js.map +1 -1
  57. package/src/cjs/geomutils.js +2 -2
  58. package/src/cjs/geomutils.js.map +1 -1
  59. package/src/cjs/index.js +5 -1
  60. package/src/cjs/index.js.map +1 -1
  61. package/src/cjs/interfaces/DrawLib.d.ts +2 -2
  62. package/src/cjs/interfaces/core.d.ts +3 -3
  63. package/src/cjs/interfaces/externals.d.ts +12 -0
  64. package/src/cjs/interfaces/index.js +5 -1
  65. package/src/cjs/interfaces/index.js.map +1 -1
  66. package/src/cjs/utils/InitializationObserver.d.ts +18 -0
  67. package/src/cjs/utils/InitializationObserver.js +56 -0
  68. package/src/cjs/utils/InitializationObserver.js.map +1 -0
  69. package/src/cjs/utils/NGons.d.ts +13 -0
  70. package/src/cjs/utils/NGons.js +36 -0
  71. package/src/cjs/utils/NGons.js.map +1 -0
  72. package/src/cjs/utils/Params.js.map +1 -1
  73. package/src/cjs/utils/WebColors.js.map +1 -1
  74. package/src/cjs/utils/WebColorsContrast.js +1 -1
  75. package/src/cjs/utils/WebColorsContrast.js.map +1 -1
  76. package/src/cjs/utils/algorithms/CatmullRomPath.js.map +1 -1
  77. package/src/cjs/utils/algorithms/CircleIntersections.d.ts +3 -2
  78. package/src/cjs/utils/algorithms/CircleIntersections.js +12 -20
  79. package/src/cjs/utils/algorithms/CircleIntersections.js.map +1 -1
  80. package/src/cjs/utils/algorithms/ContourLineDetection.js +5 -5
  81. package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -1
  82. package/src/cjs/utils/algorithms/CubicSplinePath.js.map +1 -1
  83. package/src/cjs/utils/algorithms/HobbyPath.js.map +1 -1
  84. package/src/cjs/utils/algorithms/Metaballs.d.ts +30 -0
  85. package/src/cjs/utils/algorithms/Metaballs.js +114 -0
  86. package/src/cjs/utils/algorithms/Metaballs.js.map +1 -0
  87. package/src/cjs/utils/algorithms/arrayResize.d.ts +8 -0
  88. package/src/cjs/utils/algorithms/arrayResize.js +24 -0
  89. package/src/cjs/utils/algorithms/arrayResize.js.map +1 -0
  90. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  91. package/src/cjs/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  92. package/src/cjs/utils/algorithms/convexHull.js.map +1 -1
  93. package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  94. package/src/cjs/utils/algorithms/delaunay.js.map +1 -1
  95. package/src/cjs/utils/algorithms/delaunay2voronoi.js.map +1 -1
  96. package/src/cjs/utils/algorithms/detectPaths.js.map +1 -1
  97. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  98. package/src/cjs/utils/algorithms/matrixFill.js +1 -1
  99. package/src/cjs/utils/algorithms/matrixFill.js.map +1 -1
  100. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  101. package/src/cjs/utils/algorithms/sutherlandHodgman.js.map +1 -1
  102. package/src/cjs/utils/cloneVertexArray.js.map +1 -1
  103. package/src/cjs/utils/creategui.js +320 -244
  104. package/src/cjs/utils/dat.gui.arrowbounce.polyfill.js +74 -73
  105. package/src/cjs/utils/dat.gui.title.polyfill.js +9 -7
  106. package/src/cjs/utils/datastructures/CircularIntervalSet.js.map +1 -1
  107. package/src/cjs/utils/datastructures/Color.d.ts +2 -1
  108. package/src/cjs/utils/datastructures/Color.js +35 -16
  109. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  110. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +1 -1
  111. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +2 -2
  112. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +1 -1
  113. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  114. package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
  115. package/src/cjs/utils/datastructures/Girih.d.ts +3 -2
  116. package/src/cjs/utils/datastructures/Girih.js +2 -1
  117. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  118. package/src/cjs/utils/datastructures/GirihBowtie.js +2 -0
  119. package/src/cjs/utils/datastructures/GirihBowtie.js.map +1 -1
  120. package/src/cjs/utils/datastructures/GirihDecagon.js +2 -0
  121. package/src/cjs/utils/datastructures/GirihDecagon.js.map +1 -1
  122. package/src/cjs/utils/datastructures/GirihHexagon.js +2 -0
  123. package/src/cjs/utils/datastructures/GirihHexagon.js.map +1 -1
  124. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +3 -1
  125. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  126. package/src/cjs/utils/datastructures/GirihPentagon.js +2 -0
  127. package/src/cjs/utils/datastructures/GirihPentagon.js.map +1 -1
  128. package/src/cjs/utils/datastructures/GirihRhombus.js +2 -0
  129. package/src/cjs/utils/datastructures/GirihRhombus.js.map +1 -1
  130. package/src/cjs/utils/datastructures/GirihTile.js +4 -2
  131. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  132. package/src/cjs/utils/datastructures/Matrix4x4.js.map +1 -1
  133. package/src/cjs/utils/datastructures/VoronoiCell.js.map +1 -1
  134. package/src/cjs/utils/datastructures/interfaces.d.ts +3 -3
  135. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  136. package/src/cjs/utils/dom/getAvailableContainerSpace.js +1 -1
  137. package/src/cjs/utils/dom/getAvailableContainerSpace.js.map +1 -1
  138. package/src/cjs/utils/dom/guiSizeToggler.d.ts +17 -0
  139. package/src/cjs/utils/dom/guiSizeToggler.js +42 -0
  140. package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -0
  141. package/src/cjs/utils/findInVertexArray.js.map +1 -1
  142. package/src/cjs/utils/gup.d.ts +8 -0
  143. package/src/cjs/utils/gup.js +8 -0
  144. package/src/cjs/utils/gup.js.map +1 -1
  145. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  146. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +3 -2
  147. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  148. package/src/cjs/utils/helpers/CircleHelper.d.ts +38 -3
  149. package/src/cjs/utils/helpers/CircleHelper.js +51 -11
  150. package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
  151. package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +47 -1
  152. package/src/cjs/utils/helpers/CircleSectorHelper.js +85 -14
  153. package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
  154. package/src/cjs/utils/io/FileDrop.d.ts +3 -3
  155. package/src/cjs/utils/io/FileDrop.js.map +1 -1
  156. package/src/cjs/utils/lil.gui.arrowbounce.polyfill.js +133 -0
  157. package/src/cjs/utils/lil.gui.title.polyfill.js +32 -0
  158. package/src/cjs/utils/parsers/OBJParser.d.ts +2 -2
  159. package/src/cjs/utils/parsers/OBJParser.js.map +1 -1
  160. package/src/cjs/utils/parsers/STLParser.d.ts +4 -3
  161. package/src/cjs/utils/parsers/STLParser.js +62 -12
  162. package/src/cjs/utils/parsers/STLParser.js.map +1 -1
  163. package/src/cjs/utils/parsers/svg/parseSVGPathData.js +1 -1
  164. package/src/cjs/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  165. package/src/cjs/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  166. package/src/cjs/utils/parsers/svg/types.d.ts +13 -13
  167. package/src/createDemoDrawables.js +48 -3
  168. package/src/esm/BezierPath.js.map +1 -1
  169. package/src/esm/Bounds.js.map +1 -1
  170. package/src/esm/Circle.js.map +1 -1
  171. package/src/esm/CircleSector.d.ts +64 -1
  172. package/src/esm/CircleSector.js +121 -1
  173. package/src/esm/CircleSector.js.map +1 -1
  174. package/src/esm/CubicBezierCurve.js.map +1 -1
  175. package/src/esm/Grid.js.map +1 -1
  176. package/src/esm/KeyHandler.d.ts +1 -1
  177. package/src/esm/KeyHandler.js +13 -13
  178. package/src/esm/KeyHandler.js.map +1 -1
  179. package/src/esm/Line.js.map +1 -1
  180. package/src/esm/MouseHandler.d.ts +2 -2
  181. package/src/esm/MouseHandler.js +4 -4
  182. package/src/esm/MouseHandler.js.map +1 -1
  183. package/src/esm/PlotBoilerplate.d.ts +17 -4
  184. package/src/esm/PlotBoilerplate.js +61 -32
  185. package/src/esm/PlotBoilerplate.js.map +1 -1
  186. package/src/esm/Polygon.js.map +1 -1
  187. package/src/esm/Triangle.js.map +1 -1
  188. package/src/esm/VEllipse.js.map +1 -1
  189. package/src/esm/VEllipseSector.js +1 -1
  190. package/src/esm/VEllipseSector.js.map +1 -1
  191. package/src/esm/Vector.js.map +1 -1
  192. package/src/esm/VertTuple.js.map +1 -1
  193. package/src/esm/Vertex.d.ts +3 -2
  194. package/src/esm/Vertex.js +9 -3
  195. package/src/esm/Vertex.js.map +1 -1
  196. package/src/esm/VertexAttr.d.ts +2 -1
  197. package/src/esm/VertexAttr.js +2 -1
  198. package/src/esm/VertexAttr.js.map +1 -1
  199. package/src/esm/VertexListeners.d.ts +1 -1
  200. package/src/esm/VertexListeners.js.map +1 -1
  201. package/src/esm/draw.js.map +1 -1
  202. package/src/esm/drawgl.js.map +1 -1
  203. package/src/esm/drawutilssvg.d.ts +17 -3
  204. package/src/esm/drawutilssvg.js +28 -22
  205. package/src/esm/drawutilssvg.js.map +1 -1
  206. package/src/esm/geomutils.js +2 -2
  207. package/src/esm/geomutils.js.map +1 -1
  208. package/src/esm/interfaces/DrawLib.d.ts +2 -2
  209. package/src/esm/interfaces/core.d.ts +3 -3
  210. package/src/esm/interfaces/externals.d.ts +12 -0
  211. package/src/esm/utils/InitializationObserver.d.ts +18 -0
  212. package/src/esm/utils/InitializationObserver.js +50 -0
  213. package/src/esm/utils/InitializationObserver.js.map +1 -0
  214. package/src/esm/utils/NGons.d.ts +13 -0
  215. package/src/esm/utils/NGons.js +33 -0
  216. package/src/esm/utils/NGons.js.map +1 -0
  217. package/src/esm/utils/Params.js.map +1 -1
  218. package/src/esm/utils/WebColors.js.map +1 -1
  219. package/src/esm/utils/algorithms/CatmullRomPath.js.map +1 -1
  220. package/src/esm/utils/algorithms/CircleIntersections.d.ts +3 -2
  221. package/src/esm/utils/algorithms/CircleIntersections.js +11 -19
  222. package/src/esm/utils/algorithms/CircleIntersections.js.map +1 -1
  223. package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -1
  224. package/src/esm/utils/algorithms/CubicSplinePath.js.map +1 -1
  225. package/src/esm/utils/algorithms/HobbyPath.js.map +1 -1
  226. package/src/esm/utils/algorithms/Metaballs.d.ts +30 -0
  227. package/src/esm/utils/algorithms/Metaballs.js +109 -0
  228. package/src/esm/utils/algorithms/Metaballs.js.map +1 -0
  229. package/src/esm/utils/algorithms/arrayResize.d.ts +8 -0
  230. package/src/esm/utils/algorithms/arrayResize.js +20 -0
  231. package/src/esm/utils/algorithms/arrayResize.js.map +1 -0
  232. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  233. package/src/esm/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  234. package/src/esm/utils/algorithms/convexHull.js.map +1 -1
  235. package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  236. package/src/esm/utils/algorithms/delaunay.js.map +1 -1
  237. package/src/esm/utils/algorithms/delaunay2voronoi.js.map +1 -1
  238. package/src/esm/utils/algorithms/detectPaths.js.map +1 -1
  239. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  240. package/src/esm/utils/algorithms/matrixFill.js.map +1 -1
  241. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  242. package/src/esm/utils/algorithms/sutherlandHodgman.js.map +1 -1
  243. package/src/esm/utils/cloneVertexArray.js.map +1 -1
  244. package/src/esm/utils/datastructures/CircularIntervalSet.js.map +1 -1
  245. package/src/esm/utils/datastructures/Color.d.ts +2 -1
  246. package/src/esm/utils/datastructures/Color.js +33 -14
  247. package/src/esm/utils/datastructures/Color.js.map +1 -1
  248. package/src/esm/utils/datastructures/DataGrid2d.d.ts +1 -1
  249. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +2 -2
  250. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  251. package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
  252. package/src/esm/utils/datastructures/Girih.d.ts +3 -2
  253. package/src/esm/utils/datastructures/Girih.js +2 -1
  254. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  255. package/src/esm/utils/datastructures/GirihBowtie.js.map +1 -1
  256. package/src/esm/utils/datastructures/GirihDecagon.js.map +1 -1
  257. package/src/esm/utils/datastructures/GirihHexagon.js.map +1 -1
  258. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +1 -1
  259. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  260. package/src/esm/utils/datastructures/GirihPentagon.js.map +1 -1
  261. package/src/esm/utils/datastructures/GirihRhombus.js.map +1 -1
  262. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  263. package/src/esm/utils/datastructures/Matrix4x4.js.map +1 -1
  264. package/src/esm/utils/datastructures/VoronoiCell.js.map +1 -1
  265. package/src/esm/utils/datastructures/interfaces.d.ts +3 -3
  266. package/src/esm/utils/detectDarkMode.js.map +1 -1
  267. package/src/esm/utils/dom/guiSizeToggler.d.ts +17 -0
  268. package/src/esm/utils/dom/guiSizeToggler.js +38 -0
  269. package/src/esm/utils/dom/guiSizeToggler.js.map +1 -0
  270. package/src/esm/utils/findInVertexArray.js.map +1 -1
  271. package/src/esm/utils/gup.d.ts +8 -0
  272. package/src/esm/utils/gup.js +8 -0
  273. package/src/esm/utils/gup.js.map +1 -1
  274. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  275. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +3 -2
  276. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  277. package/src/esm/utils/helpers/CircleHelper.d.ts +38 -3
  278. package/src/esm/utils/helpers/CircleHelper.js +51 -11
  279. package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
  280. package/src/esm/utils/helpers/CircleSectorHelper.d.ts +47 -1
  281. package/src/esm/utils/helpers/CircleSectorHelper.js +85 -14
  282. package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
  283. package/src/esm/utils/io/FileDrop.d.ts +3 -3
  284. package/src/esm/utils/io/FileDrop.js.map +1 -1
  285. package/src/esm/utils/parsers/OBJParser.d.ts +2 -2
  286. package/src/esm/utils/parsers/OBJParser.js.map +1 -1
  287. package/src/esm/utils/parsers/STLParser.d.ts +4 -3
  288. package/src/esm/utils/parsers/STLParser.js +63 -13
  289. package/src/esm/utils/parsers/STLParser.js.map +1 -1
  290. package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  291. package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  292. package/src/esm/utils/parsers/svg/types.d.ts +13 -13
  293. package/src/index-gl.js +77 -85
  294. package/src/index.js +124 -129
  295. package/src/ts/CircleSector.ts +134 -3
  296. package/src/ts/PlotBoilerplate.ts +51 -14
  297. package/src/ts/Vertex.ts +8 -3
  298. package/src/ts/VertexAttr.ts +3 -2
  299. package/src/ts/drawutilssvg.ts +38 -25
  300. package/src/ts/geomutils.ts +60 -64
  301. package/src/ts/interfaces/DrawLib.ts +0 -15
  302. package/src/ts/interfaces/externals.ts +16 -0
  303. package/src/ts/utils/InitializationObserver.ts +63 -0
  304. package/src/ts/utils/NGons.ts +35 -0
  305. package/src/ts/utils/algorithms/CircleIntersections.ts +280 -288
  306. package/src/ts/utils/algorithms/Metaballs.ts +144 -0
  307. package/src/ts/utils/algorithms/arrayResize.ts +22 -0
  308. package/src/ts/utils/datastructures/Color.ts +39 -15
  309. package/src/ts/utils/datastructures/Girih.ts +9 -8
  310. package/src/ts/utils/dom/guiSizeToggler.ts +45 -0
  311. package/src/ts/utils/gup.ts +10 -2
  312. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +9 -8
  313. package/src/ts/utils/helpers/CircleHelper.ts +70 -22
  314. package/src/ts/utils/helpers/CircleSectorHelper.ts +101 -17
  315. package/src/ts/utils/parsers/STLParser.ts +50 -16
@@ -83,7 +83,9 @@
83
83
  * @modified 2023-02-10 Cleaning up most type errors in the main class (mostly null checks).
84
84
  * @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
85
85
  * @modified 2023-09-29 Adding proper dicionary key and value types to the params of `PlotBoilerplate.utils.safeMergeByKeys` (was `object` before).
86
- * @version 1.17.3
86
+ * @modified 2024-07-08 Adding `PlotBoilerplate.getGUI()` to retrieve the GUI instance.
87
+ *
88
+ * @version 1.18.0
87
89
  *
88
90
  * @file PlotBoilerplate
89
91
  * @fileoverview The main class.
@@ -126,7 +128,8 @@ import {
126
128
  SVGPathParams,
127
129
  XYCoords,
128
130
  XYDimension,
129
- DatGuiProps
131
+ DatGuiProps, // DEPRECATED. Please do not use any more.
132
+ LilGuiProps
130
133
  } from "./interfaces";
131
134
  import { PBText } from "./PBText";
132
135
  import { AlloyFingerOptions } from "alloyfinger-typescript/src/cjs/alloy_finger";
@@ -326,6 +329,11 @@ export class PlotBoilerplate {
326
329
  */
327
330
  private renderTime: number = 0;
328
331
 
332
+ /**
333
+ * A storage variable for retrieving the GUI instance once it was created.
334
+ */
335
+ private _gui: GUI | null = null;
336
+
329
337
  /**
330
338
  * The constructor.
331
339
  *
@@ -389,7 +397,7 @@ export class PlotBoilerplate {
389
397
  * Note that changes from the postDraw hook might not be visible in the export.
390
398
  * @param {string=} [config.title=null] - Specify any hover tile here. It will be attached as a `title` attribute to the most elevated element.
391
399
  */
392
- constructor(config: PBParams) {
400
+ constructor(config: PBParams, drawConfig: DrawConfig) {
393
401
  // This should be in some static block ...
394
402
  VertexAttr.model = {
395
403
  bezierAutoAdjust: false,
@@ -703,9 +711,13 @@ export class PlotBoilerplate {
703
711
  var blob = new Blob(['<?xml version="1.0" encoding="utf-8"?>\n' + svgCode], { type: "image/svg;charset=utf-8" });
704
712
  // See documentation for FileSaver.js for usage.
705
713
  // https://github.com/eligrey/FileSaver.js
706
- if (typeof globalThis["saveAs"] !== "function")
714
+ if (typeof globalThis["saveAs" as keyof Object] !== "function") {
707
715
  throw "Cannot save file; did you load the ./utils/savefile helper function and the eligrey/SaveFile library?";
708
- var _saveAs = globalThis["saveAs"];
716
+ }
717
+ var _saveAs: (blob: Blob, filename: string) => void = globalThis["saveAs" as keyof Object] as (
718
+ blob: Blob,
719
+ filename: string
720
+ ) => void;
709
721
  _saveAs(blob, "plotboilerplate.svg");
710
722
  }
711
723
 
@@ -2023,7 +2035,10 @@ export class PlotBoilerplate {
2023
2035
  };
2024
2036
 
2025
2037
  // Make PB work together with both, AlloyFinger as a esm module or a commonjs function.
2026
- if (typeof globalThis["AlloyFinger"] === "function" || typeof globalThis["createAlloyFinger"] === "function") {
2038
+ if (
2039
+ typeof globalThis["AlloyFinger" as keyof Object] === "function" ||
2040
+ typeof globalThis["createAlloyFinger" as keyof Object] === "function"
2041
+ ) {
2027
2042
  try {
2028
2043
  var touchMovePos: Vertex | undefined | null = null;
2029
2044
  var touchDownPos: Vertex | undefined | null = null;
@@ -2159,8 +2174,13 @@ export class PlotBoilerplate {
2159
2174
  _self.redraw();
2160
2175
  }
2161
2176
  } as unknown as AlloyFingerOptions; // END afProps
2162
- if (window["createAlloyFinger"]) {
2163
- window["createAlloyFinger"](this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
2177
+ if (window["createAlloyFinger" as keyof Object]) {
2178
+ // window["createAlloyFinger"](this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
2179
+ const createAlloyFinger = window["createAlloyFinger" as keyof Object] as (
2180
+ elem: HTMLElement | SVGElement,
2181
+ afProps: AlloyFingerOptions
2182
+ ) => void;
2183
+ createAlloyFinger(this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
2164
2184
  } else {
2165
2185
  /* tslint:disable-next-line */
2166
2186
  new AlloyFinger(this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
@@ -2169,7 +2189,7 @@ export class PlotBoilerplate {
2169
2189
  console.error("Failed to initialize AlloyFinger!");
2170
2190
  console.error(e);
2171
2191
  }
2172
- } else if (globalThis["Touchy"] && typeof globalThis["Touchy"] == "function") {
2192
+ } else if (globalThis["Touchy" as keyof Object] && typeof globalThis["Touchy" as keyof Object] == "function") {
2173
2193
  console.error("[Deprecation] Found Touchy which is not supported any more. Please use AlloyFinger instead.");
2174
2194
  // Convert absolute touch positions to relative DOM element position (relative to canvas)
2175
2195
  } else {
@@ -2211,12 +2231,28 @@ export class PlotBoilerplate {
2211
2231
  * @memberof PlotBoilerplate
2212
2232
  * @return {dat.gui.GUI}
2213
2233
  **/
2214
- createGUI(props?: DatGuiProps): GUI {
2234
+ createGUI(props?: DatGuiProps | LilGuiProps): GUI {
2215
2235
  // This function moved to the helper utils.
2216
2236
  // We do not want to include the whole dat.GUI package.
2217
- if (globalThis["utils"] && typeof globalThis["utils"].createGUI == "function")
2218
- return globalThis["utils"].createGUI(this, props);
2219
- else throw "Cannot create dat.GUI instance; did you load the ./utils/creategui helper function an the dat.GUI library?";
2237
+ const utils: { createGUI?: (pb: PlotBoilerplate, props: DatGuiProps | undefined) => GUI } | undefined = globalThis[
2238
+ "utils" as keyof Object
2239
+ ] as any as { createGUI?: (pb: PlotBoilerplate, props: DatGuiProps | undefined) => GUI } | undefined;
2240
+ // if (globalThis["utils"] && typeof globalThis["utils"].createGUI == "function") {
2241
+ // return (globalThis["utils" as keyof Object] as any as ({createGUI : (pb:PlotBoilerplate,props:DatGuiProps|undefined)=>GUI })).createGUI(this, props);
2242
+ if (utils && typeof utils.createGUI === "function") {
2243
+ return (this._gui = utils.createGUI(this, props));
2244
+ } else {
2245
+ throw "Cannot create dat.GUI or lil-gui instance; did you load the ./utils/creategui helper function an the dat.GUI/lil-gui library?";
2246
+ }
2247
+ }
2248
+
2249
+ /**
2250
+ * Retriebe the GUI once it was created. If the `createGUI` method was not called or failed to create any
2251
+ * GUI then null is returned.
2252
+ * @returns {GUI | null}
2253
+ */
2254
+ getGUI(): GUI | null {
2255
+ return this._gui;
2220
2256
  }
2221
2257
 
2222
2258
  /**
@@ -2301,7 +2337,8 @@ export class PlotBoilerplate {
2301
2337
  * @return {void}
2302
2338
  **/
2303
2339
  setCSSscale: (element: HTMLElement | SVGElement, scaleX: number, scaleY: number): void => {
2304
- element.style["transform-origin"] = "0 0";
2340
+ // element.style["transform-origin"] = "0 0";
2341
+ element.style.transformOrigin = "0 0";
2305
2342
  if (scaleX == 1.0 && scaleY == 1.0) {
2306
2343
  // element.style.transform = null;
2307
2344
  element.style.removeProperty("transform");
package/src/ts/Vertex.ts CHANGED
@@ -31,7 +31,8 @@
31
31
  * @modified 2022-11-28 Added the `subXY`, `subX` and `subY` methods to the `Vertex` class.
32
32
  * @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
33
33
  * @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
34
- * @version 2.8.0
34
+ * @modified 2024-03-08 Added the optional `precision` param to the `toString` method.
35
+ * @version 2.9.0
35
36
  *
36
37
  * @file Vertex
37
38
  * @public
@@ -631,8 +632,12 @@ export class Vertex implements XYCoords, SVGSerializable {
631
632
  * @instance
632
633
  * @memberof Vertex
633
634
  **/
634
- toString(): string {
635
- return "(" + this.x + "," + this.y + ")";
635
+ toString(precision?: number): string {
636
+ if (typeof precision === "undefined") {
637
+ return "(" + this.x + "," + this.y + ")";
638
+ } else {
639
+ return "(" + this.x.toFixed(precision) + "," + this.y.toFixed(precision) + ")";
640
+ }
636
641
  }
637
642
 
638
643
  /**
@@ -6,7 +6,8 @@
6
6
  * @modified 2019-03-20 Added JSDoc tags.
7
7
  * @modified 2020-02-29 Added the 'selectable' attribute.
8
8
  * @modified 2020-03-23 Ported to Typescript from JS.
9
- * @version 1.1.1
9
+ * @modified 2024-03-10 Fixed some types for Typescript 5 compatibility.
10
+ * @version 1.1.2
10
11
  *
11
12
  * @file VertexAttr
12
13
  * @public
@@ -76,7 +77,7 @@ export class VertexAttr implements IVertexAttr {
76
77
  this.visible = true;
77
78
 
78
79
  for( var key in VertexAttr.model )
79
- this[key] = VertexAttr.model[key];
80
+ this[key as keyof VertexAttr] = VertexAttr.model[key as keyof IVertexAttr] as any as boolean;
80
81
  };
81
82
 
82
83
 
@@ -44,8 +44,9 @@
44
44
  * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
45
45
  * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
46
46
  * @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
47
- *
48
- * @version 1.6.7
47
+ * @modified 2024-01-30 Fixing an issue with immutable style sets; changes to the global draw config did not reflect here (do now).
48
+ * @modified 2024-03-10 Fixing some types for Typescript 5 compatibility.
49
+ * @version 1.6.9
49
50
  **/
50
51
 
51
52
  import { CircleSector } from "./CircleSector";
@@ -196,6 +197,16 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
196
197
  */
197
198
  private isSecondary: boolean;
198
199
 
200
+ /**
201
+ * Keep the initial draw config to rebuild styles on each render loop.
202
+ */
203
+ private drawConfig: DrawConfig;
204
+
205
+ /**
206
+ * Passed from primary to secondary instance.
207
+ */
208
+ //private nodeStyle: SVGStyleElement;
209
+
199
210
  /**
200
211
  * The constructor.
201
212
  *
@@ -221,13 +232,15 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
221
232
  gNode?: SVGGElement,
222
233
  bufferGNode?: SVGGElement,
223
234
  nodeDefs?: SVGDefsElement,
224
- bufferNodeDefs?: SVGDefsElement
235
+ bufferNodeDefs?: SVGDefsElement,
236
+ nodeStyle?: SVGStyleElement
225
237
  ) {
226
238
  this.svgNode = svgNode;
227
239
  this.offset = new Vertex(0, 0).set(offset);
228
240
  this.scale = new Vertex(1, 1).set(scale);
229
241
  this.fillShapes = fillShapes;
230
242
  this.isSecondary = Boolean(isSecondary);
243
+ this.drawConfig = drawConfig;
231
244
 
232
245
  this.drawlibConfiguration = {} as DrawLibConfiguration;
233
246
  this.cache = new Map<UID, SVGElement>();
@@ -240,6 +253,9 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
240
253
  this.bufferGNode = bufferGNode;
241
254
  this.nodeDefs = nodeDefs;
242
255
  this.bufferedNodeDefs = bufferNodeDefs;
256
+ if (nodeStyle) {
257
+ this.nodeStyle = nodeStyle;
258
+ }
243
259
  } else {
244
260
  this.addStyleDefs(drawConfig);
245
261
  this.addDefsNode();
@@ -258,12 +274,20 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
258
274
  private addStyleDefs(drawConfig: DrawConfig) {
259
275
  this.nodeStyle = this.createSVGNode("style") as SVGStyleElement;
260
276
  this.svgNode.appendChild(this.nodeStyle);
277
+ this.rebuildStyleDefs(drawConfig);
278
+ }
261
279
 
280
+ /**
281
+ * This method is required to re-define the global style defs. It is needed
282
+ * if any value in the DrawConfig changed in the meantime.
283
+ * @param drawConfig
284
+ */
285
+ private rebuildStyleDefs(drawConfig: DrawConfig) {
262
286
  // Which default styles to add? -> All from the DrawConfig.
263
287
  // Compare with DrawConfig interface
264
288
  const keys = {
265
- // "bezier": "CubicBezierCurve", // TODO: is this correct?
266
- "bezierPath": "BezierPath",
289
+ "bezier": "CubicBezierCurve",
290
+ //"bezierPath": "BezierPath", // TODO: is this correct?
267
291
  "polygon": "Polygon",
268
292
  "triangle": "Triangle",
269
293
  "ellipse": "Ellipse",
@@ -278,9 +302,10 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
278
302
  };
279
303
  // Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
280
304
  const rules: Array<string> = [];
305
+ // console.log("drawConfig", drawConfig);
281
306
  for (var k in keys) {
282
- const className: string = keys[k];
283
- const drawSettings: DrawSettings | undefined = drawConfig[k];
307
+ const className: string = keys[k as keyof Object] as any as string;
308
+ const drawSettings: DrawSettings | undefined = drawConfig[k as keyof Object] as any as DrawSettings | undefined;
284
309
  if (drawSettings) {
285
310
  rules.push(`.${className} { fill : none; stroke: ${drawSettings.color}; stroke-width: ${drawSettings.lineWidth}px }`);
286
311
  } else {
@@ -380,7 +405,8 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
380
405
  node = this.createSVGNode(nodeName);
381
406
  }
382
407
  if (this.drawlibConfiguration.blendMode) {
383
- node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
408
+ // node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
409
+ node.style["mix-blend-mode" as keyof Object](this.drawlibConfiguration.blendMode);
384
410
  }
385
411
  // if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
386
412
  // node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
@@ -504,12 +530,13 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
504
530
  this.scale,
505
531
  this.canvasSize,
506
532
  fillShapes,
507
- null as any as DrawConfig, // no DrawConfig – this will work as long as `isSecondary===true`
533
+ this.drawConfig, // null as any as DrawConfig, // no DrawConfig – this will work as long as `isSecondary===true`
508
534
  true, // isSecondary
509
535
  this.gNode,
510
536
  this.bufferGNode,
511
537
  this.nodeDefs,
512
- this.bufferedNodeDefs
538
+ this.bufferedNodeDefs,
539
+ this.nodeStyle
513
540
  );
514
541
  return copy;
515
542
  }
@@ -525,21 +552,6 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
525
552
  this.drawlibConfiguration = configuration;
526
553
  }
527
554
 
528
- // /**
529
- // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
530
- // *
531
- // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
532
- // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
533
- // * for how line dashes work.
534
- // *
535
- // * @method
536
- // * @param {Array<number> lineDashes - The line-dash array configuration.
537
- // * @returns {void}
538
- // */
539
- // setLineDash(lineDashes: Array<number>) {
540
- // this.lineDash = lineDashes;
541
- // }
542
-
543
555
  /**
544
556
  * This method shouled be called each time the currently drawn `Drawable` changes.
545
557
  * It is used by some libraries for identifying elemente on re-renders.
@@ -603,6 +615,7 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
603
615
  * @instance
604
616
  **/
605
617
  endDrawCycle(renderTime: number) {
618
+ this.rebuildStyleDefs(this.drawConfig);
606
619
  if (!this.isSecondary) {
607
620
  // All elements are drawn into the buffer; they are NOT yet visible, not did the browser perform any
608
621
  // layout updates.
@@ -5,7 +5,6 @@
5
5
  * @version 1.1.0
6
6
  **/
7
7
 
8
-
9
8
  import { Line } from "./Line";
10
9
  import { Triangle } from "./Triangle";
11
10
  import { Vertex } from "./Vertex";
@@ -16,71 +15,68 @@ import { Vertex } from "./Vertex";
16
15
  * @global
17
16
  **/
18
17
  export const geomutils = {
18
+ /**
19
+ * Compute the n-section of the angle – described as a triangle (A,B,C) – in point A.
20
+ *
21
+ * @param {Vertex} pA - The first triangle point.
22
+ * @param {Vertex} pB - The second triangle point.
23
+ * @param {Vertex} pC - The third triangle point.
24
+ * @param {number} n - The number of desired angle sections (example: 2 means the angle will be divided into two sections,
25
+ * means an returned array with length 1, the middle line).
26
+ *
27
+ * @return {Line[]} An array of n-1 lines secting the given angle in point A into n equal sized angle sections. The lines' first vertex is A.
28
+ */
29
+ nsectAngle(pA: Vertex, pB: Vertex, pC: Vertex, n: number): Array<Line> {
30
+ const triangle: Triangle = new Triangle(pA, pB, pC);
31
+ const lineAB: Line = new Line(pA, pB);
32
+ const lineAC: Line = new Line(pA, pC);
33
+ // Compute the difference; this is the angle between AB and AC
34
+ var insideAngle: number = lineAB.angle(lineAC);
35
+ // We want the inner angles of the triangle, not the outer angle;
36
+ // which one is which depends on the triangle 'direction'
37
+ const clockwise: boolean = triangle.determinant() > 0;
38
+
39
+ // For convenience convert the angle [-PI,PI] to [0,2*PI]
40
+ if (insideAngle < 0) insideAngle = 2 * Math.PI + insideAngle;
41
+ if (!clockwise) insideAngle = (2 * Math.PI - insideAngle) * -1;
19
42
 
20
- /**
21
- * Compute the n-section of the angle – described as a triangle (A,B,C) – in point A.
22
- *
23
- * @param {Vertex} pA - The first triangle point.
24
- * @param {Vertex} pB - The second triangle point.
25
- * @param {Vertex} pC - The third triangle point.
26
- * @param {number} n - The number of desired angle sections (example: 2 means the angle will be divided into two sections,
27
- * means an returned array with length 1, the middle line).
28
- *
29
- * @return {Line[]} An array of n-1 lines secting the given angle in point A into n equal sized angle sections. The lines' first vertex is A.
30
- */
31
- nsectAngle( pA:Vertex, pB:Vertex, pC:Vertex, n:number ) : Array<Line> {
32
- const triangle : Triangle = new Triangle( pA, pB, pC );
33
- const lineAB : Line = new Line( pA, pB );
34
- const lineAC : Line = new Line( pA, pC );
35
- // Compute the difference; this is the angle between AB and AC
36
- var insideAngle : number = lineAB.angle( lineAC );
37
- // We want the inner angles of the triangle, not the outer angle;
38
- // which one is which depends on the triangle 'direction'
39
- const clockwise : boolean = triangle.determinant() > 0;
40
-
41
- // For convenience convert the angle [-PI,PI] to [0,2*PI]
42
- if( insideAngle < 0 )
43
- insideAngle = 2*Math.PI + insideAngle;
44
- if( !clockwise )
45
- insideAngle = (2*Math.PI - insideAngle) * (-1);
43
+ // Scale the rotated lines to the max leg length (looks better)
44
+ const lineLength: number = Math.max(lineAB.length(), lineAC.length());
45
+ const scaleFactor: number = lineLength / lineAB.length();
46
46
 
47
- // Scale the rotated lines to the max leg length (looks better)
48
- const lineLength : number = Math.max( lineAB.length(), lineAC.length() );
49
- const scaleFactor : number = lineLength/lineAB.length();
47
+ var result: Array<Line> = [];
48
+ for (var i = 1; i < n; i++) {
49
+ // Compute the i-th inner sector line
50
+ result.push(new Line(pA, pB.clone().rotate(-i * (insideAngle / n), pA)).scale(scaleFactor) as Line);
51
+ }
52
+ return result;
53
+ },
50
54
 
51
- var result : Array<Line> = [];
52
- for( var i = 1; i < n; i++ ) {
53
- // Compute the i-th inner sector line
54
- result.push( new Line( pA, pB.clone().rotate((-i*(insideAngle/n)), pA) ).scale(scaleFactor) as Line );
55
- }
56
- return result;
57
- },
55
+ /**
56
+ * Wrap the value (e.g. an angle) into the given range of [0,max).
57
+ *
58
+ * @name wrapMax
59
+ * @param {number} x - The value to wrap.
60
+ * @param {number} max - The max bound to use for the range.
61
+ * @return {number} The wrapped value inside the range [0,max).
62
+ */
63
+ wrapMax(x: number, max: number): number {
64
+ // Found at
65
+ // https://stackoverflow.com/questions/4633177/c-how-to-wrap-a-float-to-the-interval-pi-pi
66
+ return (max + (x % max)) % max;
67
+ },
58
68
 
59
- /**
60
- * Wrap the value (e.g. an angle) into the given range of [0,max).
61
- *
62
- * @name wrapMax
63
- * @param {number} x - The value to wrap.
64
- * @param {number} max - The max bound to use for the range.
65
- * @return {number} The wrapped value inside the range [0,max).
66
- */
67
- wrapMax( x:number, max:number ) : number {
68
- // Found at
69
- // https://stackoverflow.com/questions/4633177/c-how-to-wrap-a-float-to-the-interval-pi-pi
70
- return (max + (x%max)) % max;
71
- },
72
-
73
- /**
74
- * Wrap the value (e.g. an angle) into the given range of [min,max).
75
- *
76
- * @name wrapMinMax
77
- * @param {number} x - The value to wrap.
78
- * @param {number} min - The min bound to use for the range.
79
- * @param {number} max - The max bound to use for the range.
80
- * @return {number} The wrapped value inside the range [min,max).
81
- */
82
- // Currently un-used
83
- wrapMinMax( x:number, min:number, max:number ) : number {
84
- return min + geomutils.wrapMax( x - min, max - min );
85
- }
69
+ /**
70
+ * Wrap the value (e.g. an angle) into the given range of [min,max).
71
+ *
72
+ * @name wrapMinMax
73
+ * @param {number} x - The value to wrap.
74
+ * @param {number} min - The min bound to use for the range.
75
+ * @param {number} max - The max bound to use for the range.
76
+ * @return {number} The wrapped value inside the range [min,max).
77
+ */
78
+ // Currently un-used
79
+ wrapMinMax(x: number, min: number, max: number): number {
80
+ return min + geomutils.wrapMax(x - min, max - min);
81
+ }
86
82
  };
@@ -92,21 +92,6 @@ export interface DrawLib<R> {
92
92
  */
93
93
  setConfiguration: (configuration: DrawLibConfiguration) => void;
94
94
 
95
- // /**
96
- // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
97
- // *
98
- // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
99
- // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
100
- // * for how line dashes work.
101
- // *
102
- // * Setting line-dash to empty array `[]` resets the dashing.
103
- // *
104
- // * @method
105
- // * @param {Array<number> lineDashes - The line-dash array configuration.
106
- // * @returns {void}
107
- // */
108
- // setLineDash: (lineDashes: Array<number>) => void;
109
-
110
95
  /**
111
96
  * This method shouled be called each time the currently drawn `Drawable` changes.
112
97
  * It is used by some libraries for identifying elemente on re-renders.
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  // https://www.npmjs.com/package/@types/dat.gui
8
+ // @DEPRECATED Dat.GUI is replaced by lil-gui.
8
9
  export interface DatGuiProps {
9
10
  name?: string;
10
11
  load?: object;
@@ -14,3 +15,18 @@ export interface DatGuiProps {
14
15
  closed?: boolean;
15
16
  closeOnTop?: boolean;
16
17
  }
18
+
19
+ // Compatible with dat.gui and lil-gui.
20
+ export interface GUI {
21
+ domElement: HTMLElement;
22
+ }
23
+
24
+ export interface LilGuiProps {
25
+ name?: string;
26
+ load?: object;
27
+ parent?: dat.GUI;
28
+ autoPlace?: boolean;
29
+ hideable?: boolean;
30
+ closed?: boolean;
31
+ closeOnTop?: boolean;
32
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Approach to observe objects from other scripts to be initialized.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2024-07-08
6
+ * @version 1.0.0
7
+ */
8
+
9
+ interface IAccepptRejectPair<T, E> {
10
+ accept: (value: T) => void;
11
+ reject: (error: E | null) => void;
12
+ }
13
+
14
+ export class InitializationObserver<T, E> {
15
+ private _acceptRejectPairs: Array<IAccepptRejectPair<T, E | null>>;
16
+ private _timeoutMessage: E | null;
17
+ private _initializedValue: T;
18
+ private _isInitialized: boolean;
19
+
20
+ constructor(timeout: number, timeoutMessage?: E) {
21
+ this._acceptRejectPairs = [];
22
+ this._timeoutMessage = timeoutMessage ?? null;
23
+
24
+ globalThis.setTimeout(() => {
25
+ if (!this._timeoutMessage) {
26
+ console.warn("Failed to initialize object. Reason unknown.");
27
+ }
28
+ this._fireReject(this._timeoutMessage ?? null);
29
+ }, timeout);
30
+ }
31
+
32
+ public accept(value: T): void {
33
+ this._isInitialized = true;
34
+ this._initializedValue = value;
35
+ this._fireAccept(value);
36
+ }
37
+
38
+ private _fireAccept(value: T) {
39
+ this._acceptRejectPairs.forEach(pair => {
40
+ pair.accept(value);
41
+ });
42
+ }
43
+
44
+ private _fireReject(error: E | null) {
45
+ this._acceptRejectPairs.forEach(pair => {
46
+ pair.reject(error);
47
+ });
48
+ }
49
+
50
+ waitForInitialized(): Promise<T> {
51
+ const _self = this;
52
+ // If the value is already present, then accept immediately
53
+ if (_self._isInitialized) {
54
+ return new Promise<T>((accept: (value: T) => void, reject: (error: E | null) => void) => {
55
+ accept(_self._initializedValue);
56
+ });
57
+ } else {
58
+ return new Promise<T>((accept: (value: T) => void, reject: (error: E | null) => void) => {
59
+ _self._acceptRejectPairs.push({ accept, reject });
60
+ });
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Generate regular polygons (N-Gons) and stars (N-Stars).
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2023-11-24 (plain Javascript)
6
+ * @modified 2024-01-29 Ported to Typescript.
7
+ * @version 1.0.0
8
+ */
9
+
10
+ import { Polygon } from "../Polygon";
11
+ import { Vertex } from "../Vertex";
12
+
13
+ export const NGons = {
14
+ ngon: (n: number, radius: number) => {
15
+ const center = new Vertex(0, 0);
16
+ const verts: Array<Vertex> = [];
17
+ for (var i = 0; i < n; i++) {
18
+ var vert = new Vertex(radius, 0);
19
+ vert.rotate(((Math.PI * 2) / n) * i, center);
20
+ verts.push(vert);
21
+ }
22
+ return new Polygon(verts);
23
+ },
24
+
25
+ nstar: (n: number, radiusA: number, radiusB: number) => {
26
+ const center = new Vertex(0, 0);
27
+ const verts: Array<Vertex> = [];
28
+ for (var i = 0; i < n; i++) {
29
+ var vert = new Vertex(i % 2 === 0 ? radiusA : radiusB, 0);
30
+ vert.rotate(((Math.PI * 2) / n) * i, center);
31
+ verts.push(vert);
32
+ }
33
+ return new Polygon(verts);
34
+ }
35
+ };