@hunterchen/canvas 0.7.0 → 0.9.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 +196 -8
- package/dist/components/canvas/backgrounds.d.ts +4 -4
- package/dist/components/canvas/backgrounds.d.ts.map +1 -1
- package/dist/components/canvas/backgrounds.js +68 -39
- package/dist/components/canvas/backgrounds.js.map +1 -1
- package/dist/components/canvas/canvas.d.ts +3 -1
- package/dist/components/canvas/canvas.d.ts.map +1 -1
- package/dist/components/canvas/canvas.js +451 -387
- package/dist/components/canvas/canvas.js.map +1 -1
- package/dist/components/canvas/component.js +108 -174
- package/dist/components/canvas/component.js.map +1 -1
- package/dist/components/canvas/draggable.js +168 -151
- package/dist/components/canvas/draggable.js.map +1 -1
- package/dist/components/canvas/navbar/index.d.ts +4 -2
- package/dist/components/canvas/navbar/index.d.ts.map +1 -1
- package/dist/components/canvas/navbar/index.js +168 -101
- package/dist/components/canvas/navbar/index.js.map +1 -1
- package/dist/components/canvas/navbar/single-button.d.ts +10 -1
- package/dist/components/canvas/navbar/single-button.d.ts.map +1 -1
- package/dist/components/canvas/navbar/single-button.js +176 -69
- package/dist/components/canvas/navbar/single-button.js.map +1 -1
- package/dist/components/canvas/toolbar.js +121 -82
- package/dist/components/canvas/toolbar.js.map +1 -1
- package/dist/components/canvas/wrapper.js +127 -99
- package/dist/components/canvas/wrapper.js.map +1 -1
- package/dist/contexts/CanvasContext.js +25 -17
- package/dist/contexts/CanvasContext.js.map +1 -1
- package/dist/contexts/PerformanceContext.js +51 -50
- package/dist/contexts/PerformanceContext.js.map +1 -1
- package/dist/hooks/usePerformanceMode.js +36 -37
- package/dist/hooks/usePerformanceMode.js.map +1 -1
- package/dist/hooks/useWindowDimensions.js +22 -18
- package/dist/hooks/useWindowDimensions.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -21
- package/dist/lib/canvas.js +65 -72
- package/dist/lib/canvas.js.map +1 -1
- package/dist/lib/constants.js +78 -92
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/utils.js +10 -5
- package/dist/lib/utils.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/index.d.ts +69 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/performance.js +18 -23
- package/dist/utils/performance.js.map +1 -1
- package/package.json +7 -21
- package/src/components/canvas/backgrounds.tsx +7 -7
- package/src/components/canvas/canvas.tsx +9 -2
- package/src/components/canvas/navbar/index.tsx +91 -15
- package/src/components/canvas/navbar/single-button.tsx +210 -56
- package/src/index.ts +5 -0
- package/src/styles.css +15 -13
- package/src/types/index.ts +91 -0
- package/dist/components/canvas/offest.js +0 -12
- package/dist/components/canvas/offest.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import useWindowDimensions_default from "../hooks/useWindowDimensions.js";
|
|
2
|
+
import { isIOS, isMobile, prefersReducedMotion } from "../utils/performance.js";
|
|
3
|
+
import React, { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/contexts/PerformanceContext.tsx
|
|
5
7
|
const defaultConfig = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
mode: "high",
|
|
9
|
+
isIOS: false,
|
|
10
|
+
isMobile: false,
|
|
11
|
+
prefersReducedMotion: false,
|
|
12
|
+
enableComplexShadows: true
|
|
11
13
|
};
|
|
12
14
|
const PerformanceContext = createContext(defaultConfig);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const usePerformanceMode = usePerformance;
|
|
15
|
+
const usePerformance = () => useContext(PerformanceContext);
|
|
16
|
+
const usePerformanceMode = usePerformance;
|
|
16
17
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
}, [width]);
|
|
54
|
-
return (_jsx(PerformanceContext.Provider, { value: config, children: children }));
|
|
18
|
+
* Performance Provider - Centralized performance mode detection
|
|
19
|
+
*
|
|
20
|
+
* Detects device capabilities and user preferences once at the top level,
|
|
21
|
+
* avoiding redundant device detection across multiple components.
|
|
22
|
+
*
|
|
23
|
+
* Usage:
|
|
24
|
+
* <PerformanceProvider>
|
|
25
|
+
* <App />
|
|
26
|
+
* </PerformanceProvider>
|
|
27
|
+
*
|
|
28
|
+
* Then in components:
|
|
29
|
+
* const { mode, isIOS, enableComplexShadows } = usePerformance();
|
|
30
|
+
*/
|
|
31
|
+
const PerformanceProvider = ({ children }) => {
|
|
32
|
+
const [config, setConfig] = useState(defaultConfig);
|
|
33
|
+
const { width } = useWindowDimensions_default();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const isIOSDevice = isIOS();
|
|
36
|
+
const isMobileDevice = isMobile();
|
|
37
|
+
const reducedMotion = prefersReducedMotion();
|
|
38
|
+
let mode = "high";
|
|
39
|
+
if (isIOSDevice || reducedMotion || width < 768) mode = "low";
|
|
40
|
+
else if (isMobileDevice || width < 1024) mode = "medium";
|
|
41
|
+
setConfig({
|
|
42
|
+
mode,
|
|
43
|
+
isIOS: isIOSDevice,
|
|
44
|
+
isMobile: isMobileDevice,
|
|
45
|
+
prefersReducedMotion: reducedMotion,
|
|
46
|
+
enableComplexShadows: mode !== "low"
|
|
47
|
+
});
|
|
48
|
+
}, [width]);
|
|
49
|
+
return /* @__PURE__ */ jsx(PerformanceContext.Provider, {
|
|
50
|
+
value: config,
|
|
51
|
+
children
|
|
52
|
+
});
|
|
55
53
|
};
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { PerformanceProvider, usePerformance, usePerformanceMode };
|
|
56
57
|
//# sourceMappingURL=PerformanceContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PerformanceContext.js","
|
|
1
|
+
{"version":3,"file":"PerformanceContext.js","names":["useWindowDimensions"],"sources":["../../src/contexts/PerformanceContext.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useState, type ReactNode } from \"react\";\nimport useWindowDimensions from \"../hooks/useWindowDimensions\";\nimport { isIOS, isMobile, prefersReducedMotion } from \"../utils/performance\";\n\nexport type PerformanceMode = \"high\" | \"medium\" | \"low\";\n\nexport interface PerformanceConfig {\n mode: PerformanceMode;\n isIOS: boolean;\n isMobile: boolean;\n prefersReducedMotion: boolean;\n enableComplexShadows: boolean;\n}\n\nconst defaultConfig: PerformanceConfig = {\n mode: \"high\",\n isIOS: false,\n isMobile: false,\n prefersReducedMotion: false,\n enableComplexShadows: true,\n};\n\nconst PerformanceContext = createContext<PerformanceConfig>(defaultConfig);\n\nexport const usePerformance = () => useContext(PerformanceContext);\n\n// Backward compatibility alias\nexport const usePerformanceMode = usePerformance;\n\ninterface PerformanceProviderProps {\n children: ReactNode;\n}\n\n/**\n * Performance Provider - Centralized performance mode detection\n * \n * Detects device capabilities and user preferences once at the top level,\n * avoiding redundant device detection across multiple components.\n * \n * Usage:\n * <PerformanceProvider>\n * <App />\n * </PerformanceProvider>\n * \n * Then in components:\n * const { mode, isIOS, enableComplexShadows } = usePerformance();\n */\nexport const PerformanceProvider: React.FC<PerformanceProviderProps> = ({ children }) => {\n const [config, setConfig] = useState<PerformanceConfig>(defaultConfig);\n const { width } = useWindowDimensions();\n\n useEffect(() => {\n const isIOSDevice = isIOS();\n const isMobileDevice = isMobile();\n const reducedMotion = prefersReducedMotion();\n\n let mode: PerformanceMode = \"high\";\n\n // Determine performance mode based on device and screen size\n if (isIOSDevice || reducedMotion || width < 768) {\n mode = \"low\";\n } else if (isMobileDevice || width < 1024) {\n mode = \"medium\";\n }\n\n setConfig({\n mode,\n isIOS: isIOSDevice,\n isMobile: isMobileDevice,\n prefersReducedMotion: reducedMotion,\n // Use simpler shadows on iOS and low-end devices for better performance\n enableComplexShadows: mode !== \"low\",\n });\n }, [width]);\n\n return (\n <PerformanceContext.Provider value={config}>\n {children}\n </PerformanceContext.Provider>\n );\n};\n"],"mappings":";;;;;;AAcA,MAAM,gBAAmC;CACrC,MAAM;CACN,OAAO;CACP,UAAU;CACV,sBAAsB;CACtB,sBAAsB;CACzB;AAED,MAAM,qBAAqB,cAAiC,cAAc;AAE1E,MAAa,uBAAuB,WAAW,mBAAmB;AAGlE,MAAa,qBAAqB;;;;;;;;;;;;;;;AAoBlC,MAAa,uBAA2D,EAAE,eAAe;CACrF,MAAM,CAAC,QAAQ,aAAa,SAA4B,cAAc;CACtE,MAAM,EAAE,UAAUA,6BAAqB;AAEvC,iBAAgB;EACZ,MAAM,cAAc,OAAO;EAC3B,MAAM,iBAAiB,UAAU;EACjC,MAAM,gBAAgB,sBAAsB;EAE5C,IAAI,OAAwB;AAG5B,MAAI,eAAe,iBAAiB,QAAQ,IACxC,QAAO;WACA,kBAAkB,QAAQ,KACjC,QAAO;AAGX,YAAU;GACN;GACA,OAAO;GACP,UAAU;GACV,sBAAsB;GAEtB,sBAAsB,SAAS;GAClC,CAAC;IACH,CAAC,MAAM,CAAC;AAEX,QACI,oBAAC,mBAAmB;EAAS,OAAO;EAC/B;GACyB"}
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isIOS, isMobile, prefersReducedMotion } from "../utils/performance";
|
|
3
|
-
import
|
|
1
|
+
import useWindowDimensions_default from "./useWindowDimensions.js";
|
|
2
|
+
import { isIOS, isMobile, prefersReducedMotion } from "../utils/performance.js";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/usePerformanceMode.ts
|
|
4
6
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
prefersReducedMotion: reducedMotion,
|
|
34
|
-
// Use simpler shadows on iOS for better performance
|
|
35
|
-
enableComplexShadows: mode !== "low",
|
|
36
|
-
});
|
|
37
|
-
}, []);
|
|
38
|
-
return config;
|
|
7
|
+
* Hook to determine optimal performance settings based on device capabilities
|
|
8
|
+
* Does not disable any animations - only provides info for optimization
|
|
9
|
+
*/
|
|
10
|
+
const usePerformanceMode = () => {
|
|
11
|
+
const [config, setConfig] = useState({
|
|
12
|
+
mode: "high",
|
|
13
|
+
isIOS: false,
|
|
14
|
+
isMobile: false,
|
|
15
|
+
prefersReducedMotion: false,
|
|
16
|
+
enableComplexShadows: true
|
|
17
|
+
});
|
|
18
|
+
const { width } = useWindowDimensions_default();
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const isIOSDevice = isIOS();
|
|
21
|
+
const isMobileDevice = isMobile();
|
|
22
|
+
const reducedMotion = prefersReducedMotion();
|
|
23
|
+
let mode = "high";
|
|
24
|
+
if (isIOSDevice || reducedMotion || width < 768) mode = "low";
|
|
25
|
+
else if (isMobileDevice || width < 1024) mode = "medium";
|
|
26
|
+
setConfig({
|
|
27
|
+
mode,
|
|
28
|
+
isIOS: isIOSDevice,
|
|
29
|
+
isMobile: isMobileDevice,
|
|
30
|
+
prefersReducedMotion: reducedMotion,
|
|
31
|
+
enableComplexShadows: mode !== "low"
|
|
32
|
+
});
|
|
33
|
+
}, []);
|
|
34
|
+
return config;
|
|
39
35
|
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { usePerformanceMode };
|
|
40
39
|
//# sourceMappingURL=usePerformanceMode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePerformanceMode.js","
|
|
1
|
+
{"version":3,"file":"usePerformanceMode.js","names":["useWindowDimensions"],"sources":["../../src/hooks/usePerformanceMode.ts"],"sourcesContent":["import { useState, useEffect } from \"react\";\nimport { isIOS, isMobile, prefersReducedMotion } from \"../utils/performance\";\nimport useWindowDimensions from \"./useWindowDimensions\";\n\nexport type PerformanceMode = \"high\" | \"medium\" | \"low\";\n\nexport interface PerformanceConfig {\n mode: PerformanceMode;\n isIOS: boolean;\n isMobile: boolean;\n prefersReducedMotion: boolean;\n enableComplexShadows: boolean;\n}\n\n/**\n * Hook to determine optimal performance settings based on device capabilities\n * Does not disable any animations - only provides info for optimization\n */\nexport const usePerformanceMode = (): PerformanceConfig => {\n const [config, setConfig] = useState<PerformanceConfig>({\n mode: \"high\",\n isIOS: false,\n isMobile: false,\n prefersReducedMotion: false,\n enableComplexShadows: true,\n });\n\n const { width } = useWindowDimensions();\n\n useEffect(() => {\n const isIOSDevice = isIOS();\n const isMobileDevice = isMobile();\n const reducedMotion = prefersReducedMotion();\n\n let mode: PerformanceMode = \"high\";\n\n // Determine performance mode\n if (isIOSDevice || reducedMotion || width < 768) {\n mode = \"low\";\n } else if (isMobileDevice || width < 1024) {\n mode = \"medium\";\n }\n\n setConfig({\n mode,\n isIOS: isIOSDevice,\n isMobile: isMobileDevice,\n prefersReducedMotion: reducedMotion,\n // Use simpler shadows on iOS for better performance\n enableComplexShadows: mode !== \"low\",\n });\n }, []);\n\n return config;\n};\n"],"mappings":";;;;;;;;;AAkBA,MAAa,2BAA8C;CACzD,MAAM,CAAC,QAAQ,aAAa,SAA4B;EACtD,MAAM;EACN,OAAO;EACP,UAAU;EACV,sBAAsB;EACtB,sBAAsB;EACvB,CAAC;CAEF,MAAM,EAAE,UAAUA,6BAAqB;AAEvC,iBAAgB;EACd,MAAM,cAAc,OAAO;EAC3B,MAAM,iBAAiB,UAAU;EACjC,MAAM,gBAAgB,sBAAsB;EAE5C,IAAI,OAAwB;AAG5B,MAAI,eAAe,iBAAiB,QAAQ,IAC1C,QAAO;WACE,kBAAkB,QAAQ,KACnC,QAAO;AAGT,YAAU;GACR;GACA,OAAO;GACP,UAAU;GACV,sBAAsB;GAEtB,sBAAsB,SAAS;GAChC,CAAC;IACD,EAAE,CAAC;AAEN,QAAO"}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/useWindowDimensions.ts
|
|
2
4
|
const useWindowDimensions = () => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return windowDimensions;
|
|
5
|
+
const [windowDimensions, setWindowDimensions] = useState({
|
|
6
|
+
width: typeof window !== "undefined" ? window.innerWidth : 1200,
|
|
7
|
+
height: typeof window !== "undefined" ? window.innerHeight : 800
|
|
8
|
+
});
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
function handleResize() {
|
|
11
|
+
setWindowDimensions({
|
|
12
|
+
width: window.innerWidth,
|
|
13
|
+
height: window.innerHeight
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
handleResize();
|
|
17
|
+
window.addEventListener("resize", handleResize);
|
|
18
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
19
|
+
}, []);
|
|
20
|
+
return windowDimensions;
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
+
var useWindowDimensions_default = useWindowDimensions;
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useWindowDimensions_default as default };
|
|
22
26
|
//# sourceMappingURL=useWindowDimensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowDimensions.js","
|
|
1
|
+
{"version":3,"file":"useWindowDimensions.js","names":[],"sources":["../../src/hooks/useWindowDimensions.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\ntype WindowDimentions = {\n width: number;\n height: number;\n};\n\nconst useWindowDimensions = (): WindowDimentions => {\n const [windowDimensions, setWindowDimensions] = useState<WindowDimentions>({\n width: typeof window !== \"undefined\" ? window.innerWidth : 1200,\n height: typeof window !== \"undefined\" ? window.innerHeight : 800,\n });\n\n useEffect(() => {\n function handleResize(): void {\n setWindowDimensions({\n width: window.innerWidth,\n height: window.innerHeight,\n });\n }\n\n // Set initial dimensions on mount\n handleResize();\n\n window.addEventListener(\"resize\", handleResize);\n return (): void => window.removeEventListener(\"resize\", handleResize);\n }, []); // Empty array ensures that effect is only run on mount\n\n return windowDimensions;\n};\n\nexport default useWindowDimensions;\n"],"mappings":";;;AAOA,MAAM,4BAA8C;CAClD,MAAM,CAAC,kBAAkB,uBAAuB,SAA2B;EACzE,OAAO,OAAO,WAAW,cAAc,OAAO,aAAa;EAC3D,QAAQ,OAAO,WAAW,cAAc,OAAO,cAAc;EAC9D,CAAC;AAEF,iBAAgB;EACd,SAAS,eAAqB;AAC5B,uBAAoB;IAClB,OAAO,OAAO;IACd,QAAQ,OAAO;IAChB,CAAC;;AAIJ,gBAAc;AAEd,SAAO,iBAAiB,UAAU,aAAa;AAC/C,eAAmB,OAAO,oBAAoB,UAAU,aAAa;IACpE,EAAE,CAAC;AAEN,QAAO;;AAGT,kCAAe"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export * from "./lib/canvas";
|
|
|
16
16
|
export * from "./lib/constants";
|
|
17
17
|
export * from "./lib/utils";
|
|
18
18
|
export * from "./utils/performance";
|
|
19
|
-
export type { SectionCoordinates, NavItem, CanvasSection, ToolbarConfig, ToolbarPosition, ToolbarDisplayMode, } from "./types";
|
|
19
|
+
export type { SectionCoordinates, NavItem, CanvasSection, ToolbarConfig, ToolbarPosition, ToolbarDisplayMode, NavbarConfig, NavbarPosition, NavbarDisplayMode, NavbarButtonConfig, NavbarTooltipConfig, } from "./types";
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAGrE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACL,aAAa,EACb,cAAc,EACd,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,+BAA+B,CAAC;AACvC,YAAY,EACV,eAAe,EACf,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,kBAAkB,IAAI,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAG5F,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AAGpC,YAAY,EACV,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,aAAa,EACb,eAAe,EACf,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAGrE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACL,aAAa,EACb,cAAc,EACd,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,+BAA+B,CAAC;AACvC,YAAY,EACV,eAAe,EACf,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,kBAAkB,IAAI,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAG5F,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AAGpC,YAAY,EACV,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export
|
|
18
|
-
export * from "./lib/constants";
|
|
19
|
-
export * from "./lib/utils";
|
|
20
|
-
export * from "./utils/performance";
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { CanvasContext, CanvasProvider, useCanvasContext } from "./contexts/CanvasContext.js";
|
|
2
|
+
import { BLUR_TRANSITION, DEFAULT_CANVAS_HEIGHT, DEFAULT_CANVAS_WIDTH, GROW_TRANSITION, IMAGE_FALLBACK_WIDTH_THRESHOLD, INTERACTIVE_SELECTOR, INTRO_ASPECT_RATIO, MAX_DIM_RATIO, MAX_ZOOM, MIN_ZOOMS, MOUSE_WHEEL_ZOOM_SENSITIVITY, NAVBAR_DEBOUNCE_MS, PAN_SPRING, RESPONSIVE_ZOOM_MAP, STAGE2_TRANSITION, ScreenSizeEnum, TOOLBAR_OPACITY_POS_EPS, TOOLBAR_OPACITY_SCALE_EPS, TRACKPAD_ZOOM_SENSITIVITY, VIEWPORT_HYSTERESIS_BUFFER, ZOOM_BOUND } from "./lib/constants.js";
|
|
3
|
+
import { calcInitialBoxWidth, canvasHeight, canvasWidth, getDistance, getMidpoint, getScreenSizeEnum, getSectionPanCoordinates, panToOffsetScene, useMemoPoint } from "./lib/canvas.js";
|
|
4
|
+
import useWindowDimensions_default from "./hooks/useWindowDimensions.js";
|
|
5
|
+
import { cn } from "./lib/utils.js";
|
|
6
|
+
import { getWillChange, isIOS, isMobile, prefersReducedMotion } from "./utils/performance.js";
|
|
7
|
+
import { usePerformanceMode as usePerformanceMode$1 } from "./hooks/usePerformanceMode.js";
|
|
8
|
+
import Navbar from "./components/canvas/navbar/index.js";
|
|
9
|
+
import toolbar_default from "./components/canvas/toolbar.js";
|
|
10
|
+
import { CanvasWrapper } from "./components/canvas/wrapper.js";
|
|
11
|
+
import { DEFAULT_CANVAS_BOX_GRADIENT, DEFAULT_CANVAS_GRADIENT, DEFAULT_INTRO_GRADIENT, DefaultCanvasBackground, DefaultIntroContent, DefaultWrapperBackground } from "./components/canvas/backgrounds.js";
|
|
12
|
+
import canvas_default from "./components/canvas/canvas.js";
|
|
13
|
+
import { CanvasComponent } from "./components/canvas/component.js";
|
|
14
|
+
import { Draggable, DraggableImage } from "./components/canvas/draggable.js";
|
|
15
|
+
import { PerformanceProvider, usePerformance, usePerformanceMode } from "./contexts/PerformanceContext.js";
|
|
16
|
+
|
|
17
|
+
export { BLUR_TRANSITION, canvas_default as Canvas, CanvasComponent, CanvasContext, Navbar as CanvasNavbar, CanvasProvider, toolbar_default as CanvasToolbar, CanvasWrapper, DEFAULT_CANVAS_BOX_GRADIENT, DEFAULT_CANVAS_GRADIENT, DEFAULT_CANVAS_HEIGHT, DEFAULT_CANVAS_WIDTH, DEFAULT_INTRO_GRADIENT, DefaultCanvasBackground, DefaultIntroContent, DefaultWrapperBackground, Draggable, DraggableImage, GROW_TRANSITION, IMAGE_FALLBACK_WIDTH_THRESHOLD, INTERACTIVE_SELECTOR, INTRO_ASPECT_RATIO, MAX_DIM_RATIO, MAX_ZOOM, MIN_ZOOMS, MOUSE_WHEEL_ZOOM_SENSITIVITY, NAVBAR_DEBOUNCE_MS, PAN_SPRING, PerformanceProvider, RESPONSIVE_ZOOM_MAP, STAGE2_TRANSITION, ScreenSizeEnum, TOOLBAR_OPACITY_POS_EPS, TOOLBAR_OPACITY_SCALE_EPS, TRACKPAD_ZOOM_SENSITIVITY, VIEWPORT_HYSTERESIS_BUFFER, ZOOM_BOUND, calcInitialBoxWidth, canvasHeight, canvasWidth, cn, getDistance, getMidpoint, getScreenSizeEnum, getSectionPanCoordinates, getWillChange, GROW_TRANSITION as growTransition, isIOS, isMobile, panToOffsetScene, prefersReducedMotion, useCanvasContext, useMemoPoint, usePerformance, usePerformanceMode, usePerformanceMode$1 as usePerformanceModeLegacy, useWindowDimensions_default as useWindowDimensions };
|
package/dist/lib/canvas.js
CHANGED
|
@@ -1,82 +1,75 @@
|
|
|
1
|
+
import { DEFAULT_CANVAS_HEIGHT, DEFAULT_CANVAS_WIDTH, INTERACTIVE_SELECTOR, INTRO_ASPECT_RATIO, MAX_DIM_RATIO, MAX_ZOOM, MIN_ZOOMS, PAN_SPRING, ScreenSizeEnum, ZOOM_BOUND } from "./constants.js";
|
|
1
2
|
import { animate } from "framer-motion";
|
|
2
3
|
import { useMemo } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/lib/canvas.ts
|
|
6
|
+
const canvasWidth = DEFAULT_CANVAS_WIDTH;
|
|
7
|
+
const canvasHeight = DEFAULT_CANVAS_HEIGHT;
|
|
8
|
+
const useMemoPoint = (x, y) => {
|
|
9
|
+
return useMemo(() => ({
|
|
10
|
+
x,
|
|
11
|
+
y
|
|
12
|
+
}), [x, y]);
|
|
10
13
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const getDistance = (p1, p2) => {
|
|
15
|
+
const dx = p1.clientX - p2.clientX;
|
|
16
|
+
const dy = p1.clientY - p2.clientY;
|
|
17
|
+
return Math.sqrt(dx ** 2 + dy ** 2);
|
|
15
18
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const getMidpoint = (p1, p2) => {
|
|
20
|
+
return {
|
|
21
|
+
x: (p1.clientX + p2.clientX) / 2,
|
|
22
|
+
y: (p1.clientY + p2.clientY) / 2
|
|
23
|
+
};
|
|
21
24
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (width < 1920)
|
|
31
|
-
return ScreenSizeEnum.SMALL_DESKTOP;
|
|
32
|
-
if (width < 2560)
|
|
33
|
-
return ScreenSizeEnum.MEDIUM_DESKTOP;
|
|
34
|
-
if (width <= 3440)
|
|
35
|
-
return ScreenSizeEnum.LARGE_DESKTOP;
|
|
36
|
-
return ScreenSizeEnum.HUGE_DESKTOP;
|
|
25
|
+
const getScreenSizeEnum = (width) => {
|
|
26
|
+
if (width < 400) return ScreenSizeEnum.SMALL_MOBILE;
|
|
27
|
+
if (width < 768) return ScreenSizeEnum.MOBILE;
|
|
28
|
+
if (width < 1440) return ScreenSizeEnum.TABLET;
|
|
29
|
+
if (width < 1920) return ScreenSizeEnum.SMALL_DESKTOP;
|
|
30
|
+
if (width < 2560) return ScreenSizeEnum.MEDIUM_DESKTOP;
|
|
31
|
+
if (width <= 3440) return ScreenSizeEnum.LARGE_DESKTOP;
|
|
32
|
+
return ScreenSizeEnum.HUGE_DESKTOP;
|
|
37
33
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
x: targetX,
|
|
54
|
-
y: targetY,
|
|
55
|
-
};
|
|
34
|
+
function getSectionPanCoordinates({ windowDimensions, coords, targetZoom, negative }) {
|
|
35
|
+
const { width, height } = windowDimensions;
|
|
36
|
+
const sectionCenterX = coords.x + coords.width / 2;
|
|
37
|
+
const sectionCenterY = coords.y + coords.height / 2;
|
|
38
|
+
const targetX = width / 2 - sectionCenterX * targetZoom;
|
|
39
|
+
const targetY = height / 2 - sectionCenterY * targetZoom;
|
|
40
|
+
if (negative) return {
|
|
41
|
+
x: -targetX,
|
|
42
|
+
y: -targetY
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
x: targetX,
|
|
46
|
+
y: targetY
|
|
47
|
+
};
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
async function panToOffsetScene(offset, x, y, scale, newZoom) {
|
|
50
|
+
const animX = animate(x, offset.x, PAN_SPRING);
|
|
51
|
+
const animY = animate(y, offset.y, PAN_SPRING);
|
|
52
|
+
const animScale = animate(scale, newZoom ?? 1, PAN_SPRING);
|
|
53
|
+
await Promise.all([
|
|
54
|
+
animScale,
|
|
55
|
+
animX,
|
|
56
|
+
animY
|
|
57
|
+
]);
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
// scale so the canvas fits inside the computed 3:2 box
|
|
77
|
-
return Math.min(boxWidth / canvasWidth, boxHeight / canvasHeight);
|
|
59
|
+
const calcInitialBoxWidth = (windowWidth, windowHeight) => {
|
|
60
|
+
const maxWidth = windowWidth * MAX_DIM_RATIO.width;
|
|
61
|
+
const maxHeight = windowHeight * MAX_DIM_RATIO.height;
|
|
62
|
+
let boxWidth, boxHeight;
|
|
63
|
+
if (maxWidth / INTRO_ASPECT_RATIO <= maxHeight) {
|
|
64
|
+
boxWidth = maxWidth;
|
|
65
|
+
boxHeight = boxWidth / INTRO_ASPECT_RATIO;
|
|
66
|
+
} else {
|
|
67
|
+
boxHeight = maxHeight;
|
|
68
|
+
boxWidth = boxHeight * INTRO_ASPECT_RATIO;
|
|
69
|
+
}
|
|
70
|
+
return Math.min(boxWidth / canvasWidth, boxHeight / canvasHeight);
|
|
78
71
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export {
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { calcInitialBoxWidth, canvasHeight, canvasWidth, getDistance, getMidpoint, getScreenSizeEnum, getSectionPanCoordinates, panToOffsetScene, useMemoPoint };
|
|
82
75
|
//# sourceMappingURL=canvas.js.map
|
package/dist/lib/canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","
|
|
1
|
+
{"version":3,"file":"canvas.js","names":[],"sources":["../../src/lib/canvas.ts"],"sourcesContent":["import { animate, type MotionValue, type Point } from \"framer-motion\";\nimport { useMemo } from \"react\";\nimport {\n DEFAULT_CANVAS_WIDTH,\n DEFAULT_CANVAS_HEIGHT,\n MAX_DIM_RATIO,\n INTRO_ASPECT_RATIO,\n PAN_SPRING,\n ScreenSizeEnum,\n} from \"./constants\";\n\nexport const canvasWidth = DEFAULT_CANVAS_WIDTH;\nexport const canvasHeight = DEFAULT_CANVAS_HEIGHT;\n\n// Re-export ScreenSizeEnum for backward compatibility\nexport { ScreenSizeEnum } from \"./constants\";\n\nexport const useMemoPoint = (x: number, y: number): Point => {\n return useMemo(() => ({ x, y }), [x, y]);\n};\n\nexport interface MinimalPointerInput {\n clientX: number;\n clientY: number;\n}\n\nexport const getDistance = (\n p1: MinimalPointerInput,\n p2: MinimalPointerInput,\n) => {\n const dx = p1.clientX - p2.clientX;\n const dy = p1.clientY - p2.clientY;\n return Math.sqrt(dx ** 2 + dy ** 2);\n};\n\nexport const getMidpoint = (\n p1: MinimalPointerInput,\n p2: MinimalPointerInput,\n): Point => {\n return {\n x: (p1.clientX + p2.clientX) / 2,\n y: (p1.clientY + p2.clientY) / 2,\n };\n};\n\nexport const getScreenSizeEnum = (width: number): ScreenSizeEnum => {\n // iphone 12 pro is 390px, iphone 14 pro max is 430px, SE 3rd gen is 375px\n if (width < 400) return ScreenSizeEnum.SMALL_MOBILE;\n if (width < 768) return ScreenSizeEnum.MOBILE;\n if (width < 1440) return ScreenSizeEnum.TABLET;\n if (width < 1920) return ScreenSizeEnum.SMALL_DESKTOP;\n if (width < 2560) return ScreenSizeEnum.MEDIUM_DESKTOP;\n if (width <= 3440) return ScreenSizeEnum.LARGE_DESKTOP;\n return ScreenSizeEnum.HUGE_DESKTOP;\n};\n\nexport function getSectionPanCoordinates({\n windowDimensions,\n coords,\n targetZoom,\n negative,\n}: {\n windowDimensions: { width: number; height: number };\n coords: { x: number; y: number; width: number; height: number };\n targetZoom: number;\n negative?: boolean;\n}) {\n const { width, height } = windowDimensions;\n // Calculate the center of the section\n const sectionCenterX = coords.x + coords.width / 2;\n const sectionCenterY = coords.y + coords.height / 2;\n\n // Calculate the required pan offset to center the section in the viewport\n const targetX = width / 2 - sectionCenterX * targetZoom;\n const targetY = height / 2 - sectionCenterY * targetZoom;\n\n if (negative) {\n return {\n x: -targetX,\n y: -targetY,\n };\n }\n\n return {\n x: targetX,\n y: targetY,\n };\n}\n\nexport async function panToOffsetScene(\n offset: Point,\n x: MotionValue<number>,\n y: MotionValue<number>,\n scale: MotionValue<number>,\n newZoom?: number,\n): Promise<void> {\n const animX = animate(x, offset.x, PAN_SPRING);\n const animY = animate(y, offset.y, PAN_SPRING);\n const animScale = animate(scale, newZoom ?? 1, PAN_SPRING);\n await Promise.all([animScale, animX, animY]);\n}\n\nexport const calcInitialBoxWidth = (\n windowWidth: number,\n windowHeight: number,\n) => {\n // math CanvasWrapper's bounding box size and compute scale s.t. canvas fits entirely within\n const maxWidth = windowWidth * MAX_DIM_RATIO.width;\n const maxHeight = windowHeight * MAX_DIM_RATIO.height;\n\n let boxWidth, boxHeight;\n\n if (maxWidth / INTRO_ASPECT_RATIO <= maxHeight) {\n boxWidth = maxWidth;\n boxHeight = boxWidth / INTRO_ASPECT_RATIO;\n } else {\n boxHeight = maxHeight;\n boxWidth = boxHeight * INTRO_ASPECT_RATIO;\n }\n\n // scale so the canvas fits inside the computed 3:2 box\n return Math.min(boxWidth / canvasWidth, boxHeight / canvasHeight);\n};\n\n// Re-export commonly used constants for backward compatibility\nexport { MAX_DIM_RATIO } from \"./constants\";\nexport {\n INTERACTIVE_SELECTOR,\n ZOOM_BOUND,\n MAX_ZOOM,\n MIN_ZOOMS,\n} from \"./constants\";\n"],"mappings":";;;;;AAWA,MAAa,cAAc;AAC3B,MAAa,eAAe;AAK5B,MAAa,gBAAgB,GAAW,MAAqB;AAC3D,QAAO,eAAe;EAAE;EAAG;EAAG,GAAG,CAAC,GAAG,EAAE,CAAC;;AAQ1C,MAAa,eACX,IACA,OACG;CACH,MAAM,KAAK,GAAG,UAAU,GAAG;CAC3B,MAAM,KAAK,GAAG,UAAU,GAAG;AAC3B,QAAO,KAAK,KAAK,MAAM,IAAI,MAAM,EAAE;;AAGrC,MAAa,eACX,IACA,OACU;AACV,QAAO;EACL,IAAI,GAAG,UAAU,GAAG,WAAW;EAC/B,IAAI,GAAG,UAAU,GAAG,WAAW;EAChC;;AAGH,MAAa,qBAAqB,UAAkC;AAElE,KAAI,QAAQ,IAAK,QAAO,eAAe;AACvC,KAAI,QAAQ,IAAK,QAAO,eAAe;AACvC,KAAI,QAAQ,KAAM,QAAO,eAAe;AACxC,KAAI,QAAQ,KAAM,QAAO,eAAe;AACxC,KAAI,QAAQ,KAAM,QAAO,eAAe;AACxC,KAAI,SAAS,KAAM,QAAO,eAAe;AACzC,QAAO,eAAe;;AAGxB,SAAgB,yBAAyB,EACvC,kBACA,QACA,YACA,YAMC;CACD,MAAM,EAAE,OAAO,WAAW;CAE1B,MAAM,iBAAiB,OAAO,IAAI,OAAO,QAAQ;CACjD,MAAM,iBAAiB,OAAO,IAAI,OAAO,SAAS;CAGlD,MAAM,UAAU,QAAQ,IAAI,iBAAiB;CAC7C,MAAM,UAAU,SAAS,IAAI,iBAAiB;AAE9C,KAAI,SACF,QAAO;EACL,GAAG,CAAC;EACJ,GAAG,CAAC;EACL;AAGH,QAAO;EACL,GAAG;EACH,GAAG;EACJ;;AAGH,eAAsB,iBACpB,QACA,GACA,GACA,OACA,SACe;CACf,MAAM,QAAQ,QAAQ,GAAG,OAAO,GAAG,WAAW;CAC9C,MAAM,QAAQ,QAAQ,GAAG,OAAO,GAAG,WAAW;CAC9C,MAAM,YAAY,QAAQ,OAAO,WAAW,GAAG,WAAW;AAC1D,OAAM,QAAQ,IAAI;EAAC;EAAW;EAAO;EAAM,CAAC;;AAG9C,MAAa,uBACX,aACA,iBACG;CAEH,MAAM,WAAW,cAAc,cAAc;CAC7C,MAAM,YAAY,eAAe,cAAc;CAE/C,IAAI,UAAU;AAEd,KAAI,WAAW,sBAAsB,WAAW;AAC9C,aAAW;AACX,cAAY,WAAW;QAClB;AACL,cAAY;AACZ,aAAW,YAAY;;AAIzB,QAAO,KAAK,IAAI,WAAW,aAAa,YAAY,aAAa"}
|