plotboilerplate 1.20.1 → 1.21.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 (141) hide show
  1. package/README.md +17 -1
  2. package/dist/index.esm.js +2065 -1397
  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 +1265 -584
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +2 -1
  11. package/src/cjs/BezierPath.d.ts +27 -49
  12. package/src/cjs/BezierPath.js +69 -237
  13. package/src/cjs/BezierPath.js.map +1 -1
  14. package/src/cjs/Bounds.d.ts +14 -1
  15. package/src/cjs/Bounds.js +21 -1
  16. package/src/cjs/Bounds.js.map +1 -1
  17. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  18. package/src/cjs/CubicBezierCurve.js +130 -12
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Line.d.ts +2 -1
  21. package/src/cjs/Line.js +1 -0
  22. package/src/cjs/Line.js.map +1 -1
  23. package/src/cjs/PBText.d.ts +2 -1
  24. package/src/cjs/PBText.js +10 -9
  25. package/src/cjs/PBText.js.map +1 -1
  26. package/src/cjs/PlotBoilerplate.d.ts +10 -13
  27. package/src/cjs/PlotBoilerplate.js +136 -47
  28. package/src/cjs/PlotBoilerplate.js.map +1 -1
  29. package/src/cjs/Polygon.d.ts +35 -1
  30. package/src/cjs/Polygon.js +87 -1
  31. package/src/cjs/Polygon.js.map +1 -1
  32. package/src/cjs/Triangle.js +1 -0
  33. package/src/cjs/Triangle.js.map +1 -1
  34. package/src/cjs/VEllipse.js +1 -1
  35. package/src/cjs/VEllipse.js.map +1 -1
  36. package/src/cjs/Vector.d.ts +4 -4
  37. package/src/cjs/Vector.js +2 -2
  38. package/src/cjs/Vector.js.map +1 -1
  39. package/src/cjs/VertTuple.d.ts +2 -1
  40. package/src/cjs/VertTuple.js +4 -3
  41. package/src/cjs/VertTuple.js.map +1 -1
  42. package/src/cjs/Vertex.d.ts +14 -3
  43. package/src/cjs/Vertex.js +18 -3
  44. package/src/cjs/Vertex.js.map +1 -1
  45. package/src/cjs/draw.d.ts +159 -79
  46. package/src/cjs/draw.js +311 -139
  47. package/src/cjs/draw.js.map +1 -1
  48. package/src/cjs/drawgl.d.ts +93 -55
  49. package/src/cjs/drawgl.js +90 -34
  50. package/src/cjs/drawgl.js.map +1 -1
  51. package/src/cjs/drawutilssvg.d.ts +233 -58
  52. package/src/cjs/drawutilssvg.js +384 -95
  53. package/src/cjs/drawutilssvg.js.map +1 -1
  54. package/src/cjs/interfaces/DrawLib.d.ts +161 -82
  55. package/src/cjs/interfaces/DrawLib.js +7 -0
  56. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  57. package/src/cjs/interfaces/core.d.ts +46 -32
  58. package/src/cjs/interfaces/core.js +2 -0
  59. package/src/cjs/interfaces/core.js.map +1 -1
  60. package/src/cjs/utils/creategui.js +16 -10
  61. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  62. package/src/cjs/utils/datastructures/Color.js +12 -1
  63. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  64. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  65. package/src/cjs/utils/detectDarkMode.js +32 -0
  66. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  67. package/src/cjs/utils/module.js +4 -2
  68. package/src/esm/BezierPath.d.ts +27 -49
  69. package/src/esm/BezierPath.js +69 -237
  70. package/src/esm/BezierPath.js.map +1 -1
  71. package/src/esm/Bounds.d.ts +14 -1
  72. package/src/esm/Bounds.js +19 -1
  73. package/src/esm/Bounds.js.map +1 -1
  74. package/src/esm/CubicBezierCurve.d.ts +70 -1
  75. package/src/esm/CubicBezierCurve.js +130 -12
  76. package/src/esm/CubicBezierCurve.js.map +1 -1
  77. package/src/esm/Line.d.ts +2 -1
  78. package/src/esm/Line.js +1 -0
  79. package/src/esm/Line.js.map +1 -1
  80. package/src/esm/PBText.d.ts +2 -1
  81. package/src/esm/PBText.js +10 -9
  82. package/src/esm/PBText.js.map +1 -1
  83. package/src/esm/PlotBoilerplate.d.ts +10 -13
  84. package/src/esm/PlotBoilerplate.js +136 -48
  85. package/src/esm/PlotBoilerplate.js.map +1 -1
  86. package/src/esm/Polygon.d.ts +35 -1
  87. package/src/esm/Polygon.js +85 -1
  88. package/src/esm/Polygon.js.map +1 -1
  89. package/src/esm/Triangle.js +1 -0
  90. package/src/esm/Triangle.js.map +1 -1
  91. package/src/esm/VEllipse.js +1 -1
  92. package/src/esm/VEllipse.js.map +1 -1
  93. package/src/esm/Vector.d.ts +4 -4
  94. package/src/esm/Vector.js +2 -2
  95. package/src/esm/Vector.js.map +1 -1
  96. package/src/esm/VertTuple.d.ts +2 -1
  97. package/src/esm/VertTuple.js +4 -3
  98. package/src/esm/VertTuple.js.map +1 -1
  99. package/src/esm/Vertex.d.ts +14 -3
  100. package/src/esm/Vertex.js +18 -3
  101. package/src/esm/Vertex.js.map +1 -1
  102. package/src/esm/draw.d.ts +159 -79
  103. package/src/esm/draw.js +307 -137
  104. package/src/esm/draw.js.map +1 -1
  105. package/src/esm/drawgl.d.ts +93 -55
  106. package/src/esm/drawgl.js +90 -34
  107. package/src/esm/drawgl.js.map +1 -1
  108. package/src/esm/drawutilssvg.d.ts +233 -58
  109. package/src/esm/drawutilssvg.js +379 -95
  110. package/src/esm/drawutilssvg.js.map +1 -1
  111. package/src/esm/interfaces/DrawLib.d.ts +161 -82
  112. package/src/esm/interfaces/DrawLib.js +7 -0
  113. package/src/esm/interfaces/DrawLib.js.map +1 -1
  114. package/src/esm/interfaces/core.d.ts +46 -32
  115. package/src/esm/interfaces/core.js +2 -0
  116. package/src/esm/interfaces/core.js.map +1 -1
  117. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  118. package/src/esm/utils/datastructures/Color.js +12 -1
  119. package/src/esm/utils/datastructures/Color.js.map +1 -1
  120. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  121. package/src/esm/utils/detectDarkMode.js +28 -0
  122. package/src/esm/utils/detectDarkMode.js.map +1 -0
  123. package/src/ts/BezierPath.ts +74 -244
  124. package/src/ts/Bounds.ts +25 -1
  125. package/src/ts/CubicBezierCurve.ts +139 -12
  126. package/src/ts/Line.ts +2 -1
  127. package/src/ts/PBText.ts +10 -9
  128. package/src/ts/PlotBoilerplate.ts +130 -50
  129. package/src/ts/Polygon.ts +91 -1
  130. package/src/ts/Triangle.ts +2 -1
  131. package/src/ts/VEllipse.ts +2 -2
  132. package/src/ts/Vector.ts +4 -4
  133. package/src/ts/VertTuple.ts +4 -3
  134. package/src/ts/Vertex.ts +20 -4
  135. package/src/ts/draw.ts +316 -119
  136. package/src/ts/drawgl.ts +141 -78
  137. package/src/ts/drawutilssvg.ts +562 -133
  138. package/src/ts/interfaces/DrawLib.ts +223 -86
  139. package/src/ts/interfaces/core.ts +47 -32
  140. package/src/ts/utils/datastructures/Color.ts +13 -1
  141. package/src/ts/utils/detectDarkMode.ts +30 -0
@@ -17,6 +17,8 @@
17
17
  * @modified 2022-08-01 Added `title` param to the `PBParams` interface.
18
18
  * @modified 2022-10-25 Added `origin` param to the `DrawConfig` interface.
19
19
  * @modified 2022-11-23 Added `drawRaster` to the `Config` interface.
20
+ * @modified 2023-02-10 All non-function attributes of the `Config` interface are now mandatory.
21
+ * @modified 2023-09-29 Added the `randomPoint(...)` function declaration to the IBounds interface.
20
22
  **/
21
23
 
22
24
  import { Vertex } from "../Vertex";
@@ -66,6 +68,16 @@ export interface IBounds {
66
68
  min: XYCoords;
67
69
  max: XYCoords;
68
70
  getCenter(): Vertex;
71
+ /**
72
+ * Generate a random point inside this bounds object. Safe areas at the border to avoid
73
+ * included.
74
+ *
75
+ * @method randomPoint
76
+ * @param {horizontalSafeArea} - (optional) The horizonal (left and right) safe area. No vertex will be created here. Can be used as percent in (0.0 ... 0.1) interval.
77
+ * @param {verticalSafeArea} - (optional) The vertical (top and bottom) safe area. No vertex will be created here. Can be used as percent in (0.0 ... 0.1) interval
78
+ * @returns {Vertex} A pseudo random point inside these bounds.
79
+ */
80
+ randomPoint: (horizontalSafeArea?: number, verticalSafeArea?: number) => Vertex;
69
81
  }
70
82
 
71
83
  /**
@@ -100,42 +112,43 @@ export interface CanvasWrapper {
100
112
  /**
101
113
  * The config that's used by PB.
102
114
  */
103
- export interface Config {
104
- canvas: HTMLCanvasElement | string; // Your canvas element in the DOM (required).
105
- fullSize?: boolean; // If set to true the canvas will gain full window size.
106
- fitToParent?: boolean; // If set to true the canvas will gain the size of its parent container (overrides fullSize).
107
- scaleX?: number; // The initial x-zoom. Default is 1.0.
108
- scaleY?: number; // The initial y-zoom. Default is 1.0.
109
- offsetX?: number; // The initial x-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
110
- offsetY?: number; // The initial y-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
111
- rasterGrid?: boolean; // If set to true the background grid will be drawn rastered.
112
- drawRaster?: boolean; // If set to false, no raster or grid will be drawn at all.
113
- rasterScaleX?: number; // Define the default horizontal raster scale (default=1.0).
114
- rasterScaleY?: number; // Define the default vertical raster scale (default=1.0).
115
- rasterAdjustFactor?: number; // The exponential limit for wrapping down the grid. (2.0 means: halve the grid each 2.0*n zoom step).
116
- drawOrigin?: boolean; // Draw a crosshair at (0,0).
117
- autoAdjustOffset?: boolean; // When set to true then the origin of the XY plane will
115
+ export interface Config
116
+ extends Record<string, boolean | number | string | Function | HTMLCanvasElement | SVGElement | undefined> {
117
+ canvas: HTMLCanvasElement | SVGElement | string; // Your canvas element in the DOM (required).
118
+ fullSize: boolean; // If set to true the canvas will gain full window size.
119
+ fitToParent: boolean; // If set to true the canvas will gain the size of its parent container (overrides fullSize).
120
+ scaleX: number; // The initial x-zoom. Default is 1.0.
121
+ scaleY: number; // The initial y-zoom. Default is 1.0.
122
+ offsetX: number; // The initial x-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
123
+ offsetY: number; // The initial y-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
124
+ rasterGrid: boolean; // If set to true the background grid will be drawn rastered.
125
+ drawRaster: boolean; // If set to false, no raster or grid will be drawn at all.
126
+ rasterScaleX: number; // Define the default horizontal raster scale (default=1.0).
127
+ rasterScaleY: number; // Define the default vertical raster scale (default=1.0).
128
+ rasterAdjustFactor: number; // The exponential limit for wrapping down the grid. (2.0 means: halve the grid each 2.0*n zoom step).
129
+ drawOrigin: boolean; // Draw a crosshair at (0,0).
130
+ autoAdjustOffset: boolean; // When set to true then the origin of the XY plane will
118
131
  // be re-adjusted automatically (see the params
119
132
  // offsetAdjust{X,Y}Percent for more).
120
- offsetAdjustXPercent?: number; // The x-fallback position for the origin after
133
+ offsetAdjustXPercent: number; // The x-fallback position for the origin after
121
134
  // resizing the canvas.
122
- offsetAdjustYPercent?: number; // The y-fallback position for the origin after
135
+ offsetAdjustYPercent: number; // The y-fallback position for the origin after
123
136
  // resizing the canvas.
124
- defaultCanvasWidth?: number; // The canvas size fallback (width) if no automatic resizing
137
+ defaultCanvasWidth: number; // The canvas size fallback (width) if no automatic resizing
125
138
  // is switched on.
126
- defaultCanvasHeight?: number; // The canvas size fallback (height) if no automatic resizing
139
+ defaultCanvasHeight: number; // The canvas size fallback (height) if no automatic resizing
127
140
  // is switched on.
128
- canvasWidthFactor?: number; // Scaling factor (width) upon the canvas size.
141
+ canvasWidthFactor: number; // Scaling factor (width) upon the canvas size.
129
142
  // In combination with cssScale{X,Y} this can be used to obtain
130
143
  // sub pixel resolutions for retina displays.
131
- canvasHeightFactor?: number; // Scaling factor (height) upon the canvas size.
144
+ canvasHeightFactor: number; // Scaling factor (height) upon the canvas size.
132
145
  // In combination with cssScale{X,Y} this can be used to obtain
133
146
  // sub pixel resolutions for retina displays.
134
- cssScaleX?: number; // Visually resize the canvas (horizontally) using CSS transforms (scale).
135
- cssScaleY?: number; // Visually resize the canvas (vertically) using CSS transforms (scale).
136
- cssUniformScale?: boolean; // CSS scale x and y obtaining aspect ratio.
137
- backgroundColor?: string; // The backround color.
138
- redrawOnResize?: boolean; // Switch auto-redrawing on resize on/off (some applications
147
+ cssScaleX: number; // Visually resize the canvas (horizontally) using CSS transforms (scale).
148
+ cssScaleY: number; // Visually resize the canvas (vertically) using CSS transforms (scale).
149
+ cssUniformScale: boolean; // CSS scale x and y obtaining aspect ratio.
150
+ backgroundColor: string; // The backround color.
151
+ redrawOnResize: boolean; // Switch auto-redrawing on resize on/off (some applications
139
152
  // might want to prevent automatic redrawing to avoid data loss from the draw buffer).
140
153
  preClear?: () => void; // A callback function that will be triggered just before the
141
154
  // draw function clears the canvas (before anything else was drawn).
@@ -143,17 +156,19 @@ export interface Config {
143
156
  // function starts.
144
157
  postDraw?: (draw: DrawLib<any>, fill: DrawLib<any>) => void; // A callback function that will be triggered right after the drawing
145
158
  // process finished.
146
- enableMouse?: boolean; // Indicates if the application should handle mouse events for you.
147
- enableTouch?: boolean; // Indicates if the application should handle touch events for you.
148
- enableKeys?: boolean; // Indicates if the application should handle key events for you.
149
- enableMouseWheel?: boolean; // Indicates if the application should handle mouse wheel events for you.
159
+ enableMouse: boolean; // Indicates if the application should handle mouse events for you.
160
+ enableTouch: boolean; // Indicates if the application should handle touch events for you.
161
+ enableKeys: boolean; // Indicates if the application should handle key events for you.
162
+ enableMouseWheel: boolean; // Indicates if the application should handle mouse wheel events for you.
163
+ enableZoom: boolean; // default=true
164
+ enablePan: boolean; // default=true
150
165
  enableGL?: boolean; // Indicates if the application should use the experimental WebGL features (not recommended).
151
- enableSVGExport?: boolean; // Indicates if the SVG export should be enabled (default is true).
166
+ enableSVGExport: boolean; // Indicates if the SVG export should be enabled (default is true).
152
167
  // Note that changes from the postDraw hook might not be visible in the export.
153
168
  saveFile?: () => void; // When called the save-file dialog will be triggered.
154
169
  setToRetina?: () => void; // When called the resolution will be set to retina.
155
170
 
156
- autoDetectRetina?: boolean; // When set to true (default) the canvas will try to use the display's pixel ratio.
171
+ autoDetectRetina: boolean; // When set to true (default) the canvas will try to use the display's pixel ratio.
157
172
  }
158
173
 
159
174
  /**
@@ -16,7 +16,8 @@
16
16
  * @modified 2021-11-07 Added setRed, setGreen, setBlue, setHue, setSaturation, setLiminance functions.
17
17
  * @modified 2022-05-11 Modified the `clone` function by just copying the numeric calues, not re-calculating the whole color.
18
18
  * @modified 2022-05-11 Fixed the `interpolate` function.
19
- * @version 0.0.11
19
+ * @modified 2023-01-23 Added `Color.set(Color)` function to set all values (r,g,b,h,s,l,a) simultanoeusly.
20
+ * @version 0.0.12
20
21
  **/
21
22
 
22
23
  /**
@@ -155,6 +156,17 @@ export class Color {
155
156
  return this.b;
156
157
  }
157
158
 
159
+ set(color: Color): Color {
160
+ this.r = color.r;
161
+ this.g = color.g;
162
+ this.b = color.b;
163
+ this.a = color.a;
164
+ this.h = color.h;
165
+ this.s = color.s;
166
+ this.l = color.l;
167
+ return this;
168
+ }
169
+
158
170
  setRed(r: number) {
159
171
  this.r = r;
160
172
  return this;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @author Ikaros Kappler
3
+ * @date 2021-11-07
4
+ * @modified 2023-09-25 Ported to Typescript and added system darkmode detection.
5
+ * @version 1.1.0
6
+ *
7
+ * @param {Record<string,string>} GUP
8
+ * @returns {boolean}
9
+ */
10
+
11
+ import PlotBoilerplate from "../PlotBoilerplate";
12
+
13
+ export const detectDarkMode = (GUP?: Record<string, string>) => {
14
+ // Respect overrides
15
+ if (typeof GUP !== "undefined" && GUP.hasOwnProperty("darkmode") && GUP["darkmode"]) {
16
+ // const overrideValue = PlotBoilerplate.utils.fetch.bool(GUP, "darkmode", null);
17
+ const overrideValue = !!JSON.parse(GUP["darkmode"]);
18
+ if (overrideValue !== null) {
19
+ return overrideValue;
20
+ }
21
+ }
22
+ if (globalThis.matchMedia && globalThis.matchMedia("(prefers-color-scheme: dark)").matches) {
23
+ // dark mode by system
24
+ return true;
25
+ }
26
+ // else: dark mode by daytime
27
+ const hours = new Date().getHours();
28
+ const isDayTime = hours > 6 && hours < 18;
29
+ return !isDayTime;
30
+ };