colorsbymax 0.1.0 → 0.2.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/CHANGELOG.md +38 -0
- package/README.md +199 -138
- package/THIRD_PARTY_NOTICES.md +47 -1
- package/dist/ThemeSwitcher-CnxUWdBP.js +4673 -0
- package/dist/auto.js +48 -0
- package/dist/index.js +1 -4201
- package/dist/pdf.js +9 -0
- package/package.json +51 -11
- package/types/auto.d.ts +10 -0
- package/types/index.d.ts +285 -0
- package/types/pdf.d.ts +7 -0
package/dist/auto.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { s as ThemeProvider, t as ThemeSwitcher } from "./ThemeSwitcher-CnxUWdBP.js";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
//#region src/auto.js
|
|
5
|
+
var root = null;
|
|
6
|
+
var container = null;
|
|
7
|
+
var pending = null;
|
|
8
|
+
/**
|
|
9
|
+
* Mounts the colour button and panel on its own, outside the site's app. Calling it again
|
|
10
|
+
* replaces the previous mount with the new config. Returns a function that removes it.
|
|
11
|
+
* @param {import('./ThemeProvider.jsx').ColorsByMaxConfig} [config]
|
|
12
|
+
*/
|
|
13
|
+
function autoMount(config = {}) {
|
|
14
|
+
cancelPending();
|
|
15
|
+
unmount();
|
|
16
|
+
container = document.createElement("div");
|
|
17
|
+
container.dataset.colorsbymax = "auto";
|
|
18
|
+
document.body.append(container);
|
|
19
|
+
root = createRoot(container);
|
|
20
|
+
root.render(createElement(ThemeProvider, { config }, createElement(ThemeSwitcher)));
|
|
21
|
+
return unmount;
|
|
22
|
+
}
|
|
23
|
+
function unmount() {
|
|
24
|
+
root?.unmount();
|
|
25
|
+
container?.remove();
|
|
26
|
+
root = container = null;
|
|
27
|
+
}
|
|
28
|
+
function cancelPending() {
|
|
29
|
+
if (pending) pending();
|
|
30
|
+
pending = null;
|
|
31
|
+
}
|
|
32
|
+
var MOUNT_DELAY = 50;
|
|
33
|
+
if (typeof window !== "undefined") {
|
|
34
|
+
let timer = 0;
|
|
35
|
+
const onLoad = () => {
|
|
36
|
+
timer = setTimeout(() => {
|
|
37
|
+
if (!root) autoMount();
|
|
38
|
+
}, MOUNT_DELAY);
|
|
39
|
+
};
|
|
40
|
+
pending = () => {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
window.removeEventListener("load", onLoad);
|
|
43
|
+
};
|
|
44
|
+
if (document.readyState === "complete") onLoad();
|
|
45
|
+
else window.addEventListener("load", onLoad);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { autoMount };
|