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.
- package/README.md +17 -1
- package/dist/index.esm.js +2065 -1397
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1265 -584
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +2 -1
- package/src/cjs/BezierPath.d.ts +27 -49
- package/src/cjs/BezierPath.js +69 -237
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +14 -1
- package/src/cjs/Bounds.js +21 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +70 -1
- package/src/cjs/CubicBezierCurve.js +130 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +1 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PBText.d.ts +2 -1
- package/src/cjs/PBText.js +10 -9
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +10 -13
- package/src/cjs/PlotBoilerplate.js +136 -47
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +35 -1
- package/src/cjs/Polygon.js +87 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.js +1 -0
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.js +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/Vector.d.ts +4 -4
- package/src/cjs/Vector.js +2 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +2 -1
- package/src/cjs/VertTuple.js +4 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +14 -3
- package/src/cjs/Vertex.js +18 -3
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +159 -79
- package/src/cjs/draw.js +311 -139
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +93 -55
- package/src/cjs/drawgl.js +90 -34
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +233 -58
- package/src/cjs/drawutilssvg.js +384 -95
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +161 -82
- package/src/cjs/interfaces/DrawLib.js +7 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +46 -32
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +16 -10
- package/src/cjs/utils/datastructures/Color.d.ts +3 -1
- package/src/cjs/utils/datastructures/Color.js +12 -1
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.d.ts +10 -0
- package/src/cjs/utils/detectDarkMode.js +32 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -0
- package/src/cjs/utils/module.js +4 -2
- package/src/esm/BezierPath.d.ts +27 -49
- package/src/esm/BezierPath.js +69 -237
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +14 -1
- package/src/esm/Bounds.js +19 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +70 -1
- package/src/esm/CubicBezierCurve.js +130 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +1 -0
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PBText.d.ts +2 -1
- package/src/esm/PBText.js +10 -9
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +10 -13
- package/src/esm/PlotBoilerplate.js +136 -48
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +35 -1
- package/src/esm/Polygon.js +85 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.js +1 -0
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.js +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/Vector.d.ts +4 -4
- package/src/esm/Vector.js +2 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +2 -1
- package/src/esm/VertTuple.js +4 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +14 -3
- package/src/esm/Vertex.js +18 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +159 -79
- package/src/esm/draw.js +307 -137
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +93 -55
- package/src/esm/drawgl.js +90 -34
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +233 -58
- package/src/esm/drawutilssvg.js +379 -95
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +161 -82
- package/src/esm/interfaces/DrawLib.js +7 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +46 -32
- package/src/esm/interfaces/core.js +2 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/datastructures/Color.d.ts +3 -1
- package/src/esm/utils/datastructures/Color.js +12 -1
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/detectDarkMode.d.ts +10 -0
- package/src/esm/utils/detectDarkMode.js +28 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -0
- package/src/ts/BezierPath.ts +74 -244
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/CubicBezierCurve.ts +139 -12
- package/src/ts/Line.ts +2 -1
- package/src/ts/PBText.ts +10 -9
- package/src/ts/PlotBoilerplate.ts +130 -50
- package/src/ts/Polygon.ts +91 -1
- package/src/ts/Triangle.ts +2 -1
- package/src/ts/VEllipse.ts +2 -2
- package/src/ts/Vector.ts +4 -4
- package/src/ts/VertTuple.ts +4 -3
- package/src/ts/Vertex.ts +20 -4
- package/src/ts/draw.ts +316 -119
- package/src/ts/drawgl.ts +141 -78
- package/src/ts/drawutilssvg.ts +562 -133
- package/src/ts/interfaces/DrawLib.ts +223 -86
- package/src/ts/interfaces/core.ts +47 -32
- package/src/ts/utils/datastructures/Color.ts +13 -1
- 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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
|
133
|
+
offsetAdjustXPercent: number; // The x-fallback position for the origin after
|
|
121
134
|
// resizing the canvas.
|
|
122
|
-
offsetAdjustYPercent
|
|
135
|
+
offsetAdjustYPercent: number; // The y-fallback position for the origin after
|
|
123
136
|
// resizing the canvas.
|
|
124
|
-
defaultCanvasWidth
|
|
137
|
+
defaultCanvasWidth: number; // The canvas size fallback (width) if no automatic resizing
|
|
125
138
|
// is switched on.
|
|
126
|
-
defaultCanvasHeight
|
|
139
|
+
defaultCanvasHeight: number; // The canvas size fallback (height) if no automatic resizing
|
|
127
140
|
// is switched on.
|
|
128
|
-
canvasWidthFactor
|
|
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
|
|
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
|
|
135
|
-
cssScaleY
|
|
136
|
-
cssUniformScale
|
|
137
|
-
backgroundColor
|
|
138
|
-
redrawOnResize
|
|
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
|
|
147
|
-
enableTouch
|
|
148
|
-
enableKeys
|
|
149
|
-
enableMouseWheel
|
|
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
|
|
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
|
|
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
|
-
* @
|
|
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
|
+
};
|