plotboilerplate 1.21.0 → 1.23.0

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 (325) hide show
  1. package/README.md +2 -0
  2. package/dist/index.esm.js +252 -77
  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 +522 -338
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +7 -5
  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 +1 -1
  30. package/src/cjs/PlotBoilerplate.js +77 -63
  31. package/src/cjs/PlotBoilerplate.js.map +1 -1
  32. package/src/cjs/Polygon.d.ts +13 -1
  33. package/src/cjs/Polygon.js +30 -1
  34. package/src/cjs/Polygon.js.map +1 -1
  35. package/src/cjs/Triangle.js +1 -1
  36. package/src/cjs/Triangle.js.map +1 -1
  37. package/src/cjs/UIDGenerator.js +1 -1
  38. package/src/cjs/UIDGenerator.js.map +1 -1
  39. package/src/cjs/VEllipse.js.map +1 -1
  40. package/src/cjs/VEllipseSector.js +1 -1
  41. package/src/cjs/VEllipseSector.js.map +1 -1
  42. package/src/cjs/Vector.js +2 -0
  43. package/src/cjs/Vector.js.map +1 -1
  44. package/src/cjs/VertTuple.js.map +1 -1
  45. package/src/cjs/Vertex.d.ts +3 -2
  46. package/src/cjs/Vertex.js +13 -7
  47. package/src/cjs/Vertex.js.map +1 -1
  48. package/src/cjs/VertexAttr.d.ts +2 -1
  49. package/src/cjs/VertexAttr.js +2 -1
  50. package/src/cjs/VertexAttr.js.map +1 -1
  51. package/src/cjs/VertexListeners.d.ts +1 -1
  52. package/src/cjs/VertexListeners.js.map +1 -1
  53. package/src/cjs/draw.js +1 -1
  54. package/src/cjs/draw.js.map +1 -1
  55. package/src/cjs/drawgl.js.map +1 -1
  56. package/src/cjs/drawutilssvg.d.ts +17 -3
  57. package/src/cjs/drawutilssvg.js +97 -91
  58. package/src/cjs/drawutilssvg.js.map +1 -1
  59. package/src/cjs/geomutils.js +2 -2
  60. package/src/cjs/geomutils.js.map +1 -1
  61. package/src/cjs/index.js +5 -1
  62. package/src/cjs/index.js.map +1 -1
  63. package/src/cjs/interfaces/DrawLib.d.ts +2 -2
  64. package/src/cjs/interfaces/core.d.ts +3 -3
  65. package/src/cjs/interfaces/index.js +5 -1
  66. package/src/cjs/interfaces/index.js.map +1 -1
  67. package/src/cjs/utils/NGons.d.ts +13 -0
  68. package/src/cjs/utils/NGons.js +36 -0
  69. package/src/cjs/utils/NGons.js.map +1 -0
  70. package/src/cjs/utils/Params.d.ts +15 -0
  71. package/src/cjs/utils/Params.js +49 -0
  72. package/src/cjs/utils/Params.js.map +1 -0
  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.d.ts +150 -0
  81. package/src/cjs/utils/algorithms/ContourLineDetection.js +367 -0
  82. package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -0
  83. package/src/cjs/utils/algorithms/CubicSplinePath.js.map +1 -1
  84. package/src/cjs/utils/algorithms/HobbyPath.js.map +1 -1
  85. package/src/cjs/utils/algorithms/Metaballs.d.ts +30 -0
  86. package/src/cjs/utils/algorithms/Metaballs.js +114 -0
  87. package/src/cjs/utils/algorithms/Metaballs.js.map +1 -0
  88. package/src/cjs/utils/algorithms/arrayResize.d.ts +8 -0
  89. package/src/cjs/utils/algorithms/arrayResize.js +24 -0
  90. package/src/cjs/utils/algorithms/arrayResize.js.map +1 -0
  91. package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  92. package/src/cjs/utils/algorithms/clearDuplicateVertices.js +48 -0
  93. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  94. package/src/cjs/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  95. package/src/cjs/utils/algorithms/convexHull.js.map +1 -1
  96. package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  97. package/src/cjs/utils/algorithms/delaunay.js.map +1 -1
  98. package/src/cjs/utils/algorithms/delaunay2voronoi.js.map +1 -1
  99. package/src/cjs/utils/algorithms/detectPaths.js.map +1 -1
  100. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  101. package/src/cjs/utils/algorithms/matrixFill.js +1 -1
  102. package/src/cjs/utils/algorithms/matrixFill.js.map +1 -1
  103. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  104. package/src/cjs/utils/algorithms/sutherlandHodgman.js.map +1 -1
  105. package/src/cjs/utils/cloneVertexArray.js.map +1 -1
  106. package/src/cjs/utils/creategui.js +20 -12
  107. package/src/cjs/utils/datastructures/CircularIntervalSet.js.map +1 -1
  108. package/src/cjs/utils/datastructures/Color.d.ts +2 -1
  109. package/src/cjs/utils/datastructures/Color.js +35 -16
  110. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  111. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +47 -0
  112. package/src/cjs/utils/datastructures/DataGrid2d.js +20 -0
  113. package/src/cjs/utils/datastructures/DataGrid2d.js.map +1 -0
  114. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  115. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +84 -0
  116. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  117. package/src/cjs/utils/datastructures/GenericPath.d.ts +14 -3
  118. package/src/cjs/utils/datastructures/GenericPath.js +20 -3
  119. package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
  120. package/src/cjs/utils/datastructures/Girih.d.ts +3 -2
  121. package/src/cjs/utils/datastructures/Girih.js +2 -1
  122. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  123. package/src/cjs/utils/datastructures/GirihBowtie.js +2 -0
  124. package/src/cjs/utils/datastructures/GirihBowtie.js.map +1 -1
  125. package/src/cjs/utils/datastructures/GirihDecagon.js +2 -0
  126. package/src/cjs/utils/datastructures/GirihDecagon.js.map +1 -1
  127. package/src/cjs/utils/datastructures/GirihHexagon.js +2 -0
  128. package/src/cjs/utils/datastructures/GirihHexagon.js.map +1 -1
  129. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +3 -1
  130. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  131. package/src/cjs/utils/datastructures/GirihPentagon.js +2 -0
  132. package/src/cjs/utils/datastructures/GirihPentagon.js.map +1 -1
  133. package/src/cjs/utils/datastructures/GirihRhombus.js +2 -0
  134. package/src/cjs/utils/datastructures/GirihRhombus.js.map +1 -1
  135. package/src/cjs/utils/datastructures/GirihTile.js +4 -2
  136. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  137. package/src/cjs/utils/datastructures/Matrix4x4.js.map +1 -1
  138. package/src/cjs/utils/datastructures/VoronoiCell.js.map +1 -1
  139. package/src/cjs/utils/datastructures/interfaces.d.ts +3 -3
  140. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  141. package/src/cjs/utils/dom/getAvailableContainerSpace.js +1 -1
  142. package/src/cjs/utils/dom/getAvailableContainerSpace.js.map +1 -1
  143. package/src/cjs/utils/findInVertexArray.js.map +1 -1
  144. package/src/cjs/utils/gup.d.ts +8 -0
  145. package/src/cjs/utils/gup.js +8 -0
  146. package/src/cjs/utils/gup.js.map +1 -1
  147. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  148. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +3 -2
  149. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  150. package/src/cjs/utils/helpers/CircleHelper.d.ts +38 -3
  151. package/src/cjs/utils/helpers/CircleHelper.js +51 -11
  152. package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
  153. package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +47 -1
  154. package/src/cjs/utils/helpers/CircleSectorHelper.js +85 -14
  155. package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
  156. package/src/cjs/utils/io/FileDrop.d.ts +3 -3
  157. package/src/cjs/utils/io/FileDrop.js.map +1 -1
  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 +1 -1
  184. package/src/esm/PlotBoilerplate.js +43 -29
  185. package/src/esm/PlotBoilerplate.js.map +1 -1
  186. package/src/esm/Polygon.d.ts +13 -1
  187. package/src/esm/Polygon.js +30 -1
  188. package/src/esm/Polygon.js.map +1 -1
  189. package/src/esm/Triangle.js.map +1 -1
  190. package/src/esm/VEllipse.js.map +1 -1
  191. package/src/esm/VEllipseSector.js +1 -1
  192. package/src/esm/VEllipseSector.js.map +1 -1
  193. package/src/esm/Vector.js.map +1 -1
  194. package/src/esm/VertTuple.js.map +1 -1
  195. package/src/esm/Vertex.d.ts +3 -2
  196. package/src/esm/Vertex.js +9 -3
  197. package/src/esm/Vertex.js.map +1 -1
  198. package/src/esm/VertexAttr.d.ts +2 -1
  199. package/src/esm/VertexAttr.js +2 -1
  200. package/src/esm/VertexAttr.js.map +1 -1
  201. package/src/esm/VertexListeners.d.ts +1 -1
  202. package/src/esm/VertexListeners.js.map +1 -1
  203. package/src/esm/draw.js.map +1 -1
  204. package/src/esm/drawgl.js.map +1 -1
  205. package/src/esm/drawutilssvg.d.ts +17 -3
  206. package/src/esm/drawutilssvg.js +28 -22
  207. package/src/esm/drawutilssvg.js.map +1 -1
  208. package/src/esm/geomutils.js +2 -2
  209. package/src/esm/geomutils.js.map +1 -1
  210. package/src/esm/interfaces/DrawLib.d.ts +2 -2
  211. package/src/esm/interfaces/core.d.ts +3 -3
  212. package/src/esm/utils/NGons.d.ts +13 -0
  213. package/src/esm/utils/NGons.js +33 -0
  214. package/src/esm/utils/NGons.js.map +1 -0
  215. package/src/esm/utils/Params.d.ts +15 -0
  216. package/src/esm/utils/Params.js +44 -0
  217. package/src/esm/utils/Params.js.map +1 -0
  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.d.ts +150 -0
  224. package/src/esm/utils/algorithms/ContourLineDetection.js +362 -0
  225. package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -0
  226. package/src/esm/utils/algorithms/CubicSplinePath.js.map +1 -1
  227. package/src/esm/utils/algorithms/HobbyPath.js.map +1 -1
  228. package/src/esm/utils/algorithms/Metaballs.d.ts +30 -0
  229. package/src/esm/utils/algorithms/Metaballs.js +109 -0
  230. package/src/esm/utils/algorithms/Metaballs.js.map +1 -0
  231. package/src/esm/utils/algorithms/arrayResize.d.ts +8 -0
  232. package/src/esm/utils/algorithms/arrayResize.js +20 -0
  233. package/src/esm/utils/algorithms/arrayResize.js.map +1 -0
  234. package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  235. package/src/esm/utils/algorithms/clearDuplicateVertices.js +44 -0
  236. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  237. package/src/esm/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  238. package/src/esm/utils/algorithms/convexHull.js.map +1 -1
  239. package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  240. package/src/esm/utils/algorithms/delaunay.js.map +1 -1
  241. package/src/esm/utils/algorithms/delaunay2voronoi.js.map +1 -1
  242. package/src/esm/utils/algorithms/detectPaths.js.map +1 -1
  243. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  244. package/src/esm/utils/algorithms/matrixFill.js.map +1 -1
  245. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  246. package/src/esm/utils/algorithms/sutherlandHodgman.js.map +1 -1
  247. package/src/esm/utils/cloneVertexArray.js.map +1 -1
  248. package/src/esm/utils/datastructures/CircularIntervalSet.js.map +1 -1
  249. package/src/esm/utils/datastructures/Color.d.ts +2 -1
  250. package/src/esm/utils/datastructures/Color.js +33 -14
  251. package/src/esm/utils/datastructures/Color.js.map +1 -1
  252. package/src/esm/utils/datastructures/DataGrid2d.d.ts +47 -0
  253. package/src/esm/utils/datastructures/DataGrid2d.js +19 -0
  254. package/src/esm/utils/datastructures/DataGrid2d.js.map +1 -0
  255. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  256. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +79 -0
  257. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  258. package/src/esm/utils/datastructures/GenericPath.d.ts +14 -3
  259. package/src/esm/utils/datastructures/GenericPath.js +20 -3
  260. package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
  261. package/src/esm/utils/datastructures/Girih.d.ts +3 -2
  262. package/src/esm/utils/datastructures/Girih.js +2 -1
  263. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  264. package/src/esm/utils/datastructures/GirihBowtie.js.map +1 -1
  265. package/src/esm/utils/datastructures/GirihDecagon.js.map +1 -1
  266. package/src/esm/utils/datastructures/GirihHexagon.js.map +1 -1
  267. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +1 -1
  268. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  269. package/src/esm/utils/datastructures/GirihPentagon.js.map +1 -1
  270. package/src/esm/utils/datastructures/GirihRhombus.js.map +1 -1
  271. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  272. package/src/esm/utils/datastructures/Matrix4x4.js.map +1 -1
  273. package/src/esm/utils/datastructures/VoronoiCell.js.map +1 -1
  274. package/src/esm/utils/datastructures/interfaces.d.ts +3 -3
  275. package/src/esm/utils/detectDarkMode.js.map +1 -1
  276. package/src/esm/utils/findInVertexArray.js.map +1 -1
  277. package/src/esm/utils/gup.d.ts +8 -0
  278. package/src/esm/utils/gup.js +8 -0
  279. package/src/esm/utils/gup.js.map +1 -1
  280. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  281. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +3 -2
  282. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  283. package/src/esm/utils/helpers/CircleHelper.d.ts +38 -3
  284. package/src/esm/utils/helpers/CircleHelper.js +51 -11
  285. package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
  286. package/src/esm/utils/helpers/CircleSectorHelper.d.ts +47 -1
  287. package/src/esm/utils/helpers/CircleSectorHelper.js +85 -14
  288. package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
  289. package/src/esm/utils/io/FileDrop.d.ts +3 -3
  290. package/src/esm/utils/io/FileDrop.js.map +1 -1
  291. package/src/esm/utils/parsers/OBJParser.d.ts +2 -2
  292. package/src/esm/utils/parsers/OBJParser.js.map +1 -1
  293. package/src/esm/utils/parsers/STLParser.d.ts +4 -3
  294. package/src/esm/utils/parsers/STLParser.js +63 -13
  295. package/src/esm/utils/parsers/STLParser.js.map +1 -1
  296. package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  297. package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  298. package/src/esm/utils/parsers/svg/types.d.ts +13 -13
  299. package/src/index-gl.js +77 -85
  300. package/src/index.js +124 -129
  301. package/src/ts/CircleSector.ts +134 -3
  302. package/src/ts/PlotBoilerplate.ts +20 -11
  303. package/src/ts/Polygon.ts +31 -1
  304. package/src/ts/Vertex.ts +8 -3
  305. package/src/ts/VertexAttr.ts +3 -2
  306. package/src/ts/drawutilssvg.ts +38 -25
  307. package/src/ts/geomutils.ts +60 -64
  308. package/src/ts/interfaces/DrawLib.ts +0 -15
  309. package/src/ts/utils/NGons.ts +35 -0
  310. package/src/ts/utils/Params.ts +47 -0
  311. package/src/ts/utils/algorithms/CircleIntersections.ts +280 -288
  312. package/src/ts/utils/algorithms/ContourLineDetection.ts +485 -0
  313. package/src/ts/utils/algorithms/Metaballs.ts +144 -0
  314. package/src/ts/utils/algorithms/arrayResize.ts +22 -0
  315. package/src/ts/utils/algorithms/clearDuplicateVertices.ts +49 -0
  316. package/src/ts/utils/datastructures/Color.ts +39 -15
  317. package/src/ts/utils/datastructures/DataGrid2d.ts +54 -0
  318. package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +121 -0
  319. package/src/ts/utils/datastructures/GenericPath.ts +21 -3
  320. package/src/ts/utils/datastructures/Girih.ts +9 -8
  321. package/src/ts/utils/gup.ts +10 -2
  322. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +9 -8
  323. package/src/ts/utils/helpers/CircleHelper.ts +70 -22
  324. package/src/ts/utils/helpers/CircleSectorHelper.ts +101 -17
  325. package/src/ts/utils/parsers/STLParser.ts +50 -16
@@ -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.
@@ -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
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Wraps a Record<string,string> and adds type conversion methods (developed this in
3
+ * some other project) and added this here (2023-10-28).
4
+ *
5
+ * @author Ikars Kappler
6
+ * @version 1.0.0
7
+ * @date 2023-03-13
8
+ */
9
+
10
+ export class Params {
11
+ baseParams: Record<string, string>;
12
+
13
+ constructor(baseParams: Record<string, string>) {
14
+ this.baseParams = baseParams;
15
+ }
16
+
17
+ getString(name: string, fallback: string): string {
18
+ let value = this.baseParams[name];
19
+ if (typeof value === "undefined" || !value || (value = value.trim()).length === 0) {
20
+ return fallback;
21
+ }
22
+ return value;
23
+ }
24
+
25
+ getNumber(name: string, fallback: number): number {
26
+ let value = this.baseParams[name];
27
+ if (typeof value === "undefined" || !value || (value = value.trim()).length === 0) {
28
+ return fallback;
29
+ }
30
+ return Number(value);
31
+ }
32
+
33
+ getBoolean(name: string, fallback: boolean): boolean {
34
+ let value = this.baseParams[name];
35
+ if (typeof value === "undefined" || !value || (value = value.trim()).length === 0) {
36
+ return fallback;
37
+ }
38
+ value = value.toLocaleLowerCase();
39
+ if (value === "1" || value === "on" || value === "yes" || value === "y" || value === "hi" || value == "high") {
40
+ return true;
41
+ } else if (value === "0" || value === "off" || value === "no" || value === "n" || value === "lo" || value == "low") {
42
+ return false;
43
+ } else {
44
+ return Boolean(value);
45
+ }
46
+ }
47
+ }