plotboilerplate 1.23.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.
- package/dist/index.esm.js +19 -4
- 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 +19 -4
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +3 -1
- package/src/cjs/PlotBoilerplate.d.ts +16 -3
- package/src/cjs/PlotBoilerplate.js +19 -4
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/interfaces/externals.d.ts +12 -0
- package/src/cjs/utils/InitializationObserver.d.ts +18 -0
- package/src/cjs/utils/InitializationObserver.js +56 -0
- package/src/cjs/utils/InitializationObserver.js.map +1 -0
- package/src/cjs/utils/creategui.js +319 -251
- package/src/cjs/utils/dat.gui.arrowbounce.polyfill.js +74 -73
- package/src/cjs/utils/dat.gui.title.polyfill.js +9 -7
- package/src/cjs/utils/dom/guiSizeToggler.d.ts +17 -0
- package/src/cjs/utils/dom/guiSizeToggler.js +42 -0
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -0
- package/src/cjs/utils/lil.gui.arrowbounce.polyfill.js +133 -0
- package/src/cjs/utils/lil.gui.title.polyfill.js +32 -0
- package/src/esm/PlotBoilerplate.d.ts +16 -3
- package/src/esm/PlotBoilerplate.js +19 -4
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/interfaces/externals.d.ts +12 -0
- package/src/esm/utils/InitializationObserver.d.ts +18 -0
- package/src/esm/utils/InitializationObserver.js +50 -0
- package/src/esm/utils/InitializationObserver.js.map +1 -0
- package/src/esm/utils/dom/guiSizeToggler.d.ts +17 -0
- package/src/esm/utils/dom/guiSizeToggler.js +38 -0
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -0
- package/src/ts/PlotBoilerplate.ts +38 -10
- package/src/ts/interfaces/externals.ts +16 -0
- package/src/ts/utils/InitializationObserver.ts +63 -0
- package/src/ts/utils/dom/guiSizeToggler.ts +45 -0
|
@@ -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,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @requires lil-gui
|
|
3
|
+
*
|
|
4
|
+
* @author Ikaros Kappler
|
|
5
|
+
* @date 2021-12-13
|
|
6
|
+
* @modified 2022-01-10
|
|
7
|
+
* @modified 2024-06-25 Ported to typescript and moved to utils/dom (was located inside demos before).
|
|
8
|
+
* @version 1.1.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { GUI } from "../../interfaces/externals";
|
|
12
|
+
|
|
13
|
+
interface ITogglerConfig {
|
|
14
|
+
guiDoubleSize?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {GUI} gui - The GUI (compatible with dat.gui and lil-gui).
|
|
19
|
+
* @param {boolean} guiDoubleSize - True or false.
|
|
20
|
+
* @param {Record<string,string>} cssProps - The CSS props to use.
|
|
21
|
+
*/
|
|
22
|
+
const applyGuiSize = (gui: GUI, guiDoubleSize: boolean, cssProps: Record<string, string>) => {
|
|
23
|
+
if (cssProps && cssProps.hasOwnProperty("transformOrigin")) {
|
|
24
|
+
gui.domElement.style["transform-origin"] = cssProps["transformOrigin"];
|
|
25
|
+
} else {
|
|
26
|
+
gui.domElement.style["transform-origin"] = "100% 0%";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const transform = cssProps && cssProps.hasOwnProperty("transform") ? cssProps["transform"] + " " : "";
|
|
30
|
+
|
|
31
|
+
console.log("transform", transform);
|
|
32
|
+
if (guiDoubleSize) {
|
|
33
|
+
gui.domElement.style["transform"] = transform + "scale(2.0)";
|
|
34
|
+
} else {
|
|
35
|
+
gui.domElement.style["transform"] = transform + "scale(1.0)";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const guiSizeToggler /* gst */ = (gui: GUI, config: ITogglerConfig, cssProps: Record<string, string>) => {
|
|
40
|
+
return {
|
|
41
|
+
update: function () {
|
|
42
|
+
applyGuiSize(gui, Boolean(config.guiDoubleSize), cssProps);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|