@panscale/react 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +185 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PanScale
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode } from "react";
|
|
2
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
3
|
+
import * as react_jsx_runtime2 from "react/jsx-runtime";
|
|
4
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
5
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
|
+
import { Dimensions, ScalerOptions, ScalerValues } from "@panscale/core";
|
|
7
|
+
|
|
8
|
+
//#region src/use-scaler.d.ts
|
|
9
|
+
interface UseScalerOptions extends Partial<ScalerOptions> {
|
|
10
|
+
contentWidth?: number;
|
|
11
|
+
contentHeight?: number;
|
|
12
|
+
}
|
|
13
|
+
interface UseScalerReturn {
|
|
14
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
15
|
+
values: ScalerValues;
|
|
16
|
+
scrollTo: (left: number, top: number, animate?: boolean) => void;
|
|
17
|
+
scrollBy: (dx: number, dy: number, animate?: boolean) => void;
|
|
18
|
+
zoomTo: (level: number, animate?: boolean, originX?: number, originY?: number) => void;
|
|
19
|
+
zoomBy: (factor: number, animate?: boolean, originX?: number, originY?: number) => void;
|
|
20
|
+
setContentSize: (width: number, height: number) => void;
|
|
21
|
+
}
|
|
22
|
+
declare function useScaler(options?: UseScalerOptions): UseScalerReturn;
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/scaler-view.d.ts
|
|
26
|
+
//# sourceMappingURL=use-scaler.d.ts.map
|
|
27
|
+
interface ScalerViewProps {
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
style?: CSSProperties;
|
|
30
|
+
className?: string;
|
|
31
|
+
options?: Partial<ScalerOptions>;
|
|
32
|
+
zooming?: boolean;
|
|
33
|
+
bouncing?: boolean;
|
|
34
|
+
paging?: boolean;
|
|
35
|
+
snapping?: boolean;
|
|
36
|
+
onValuesChange?: (values: ScalerValues) => void;
|
|
37
|
+
}
|
|
38
|
+
declare function ScalerView({
|
|
39
|
+
children,
|
|
40
|
+
style,
|
|
41
|
+
className,
|
|
42
|
+
options,
|
|
43
|
+
zooming,
|
|
44
|
+
bouncing,
|
|
45
|
+
paging,
|
|
46
|
+
snapping,
|
|
47
|
+
onValuesChange
|
|
48
|
+
}: ScalerViewProps): react_jsx_runtime1.JSX.Element;
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/ui/zoom-controls.d.ts
|
|
52
|
+
//# sourceMappingURL=scaler-view.d.ts.map
|
|
53
|
+
interface ZoomControlsProps {
|
|
54
|
+
zoom: number;
|
|
55
|
+
onZoomIn: () => void;
|
|
56
|
+
onZoomOut: () => void;
|
|
57
|
+
style?: CSSProperties;
|
|
58
|
+
className?: string;
|
|
59
|
+
}
|
|
60
|
+
declare function ZoomControls({
|
|
61
|
+
zoom,
|
|
62
|
+
onZoomIn,
|
|
63
|
+
onZoomOut,
|
|
64
|
+
style,
|
|
65
|
+
className
|
|
66
|
+
}: ZoomControlsProps): react_jsx_runtime2.JSX.Element;
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/ui/minimap.d.ts
|
|
70
|
+
//# sourceMappingURL=zoom-controls.d.ts.map
|
|
71
|
+
interface MinimapProps {
|
|
72
|
+
values: ScalerValues;
|
|
73
|
+
dimensions: Dimensions;
|
|
74
|
+
width?: number;
|
|
75
|
+
height?: number;
|
|
76
|
+
style?: CSSProperties;
|
|
77
|
+
className?: string;
|
|
78
|
+
}
|
|
79
|
+
declare function Minimap({
|
|
80
|
+
values,
|
|
81
|
+
dimensions,
|
|
82
|
+
width,
|
|
83
|
+
height,
|
|
84
|
+
style,
|
|
85
|
+
className
|
|
86
|
+
}: MinimapProps): react_jsx_runtime3.JSX.Element | null;
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/ui/reset-button.d.ts
|
|
90
|
+
//# sourceMappingURL=minimap.d.ts.map
|
|
91
|
+
interface ResetButtonProps {
|
|
92
|
+
onReset: () => void;
|
|
93
|
+
style?: CSSProperties;
|
|
94
|
+
className?: string;
|
|
95
|
+
label?: string;
|
|
96
|
+
}
|
|
97
|
+
declare function ResetButton({
|
|
98
|
+
onReset,
|
|
99
|
+
style,
|
|
100
|
+
className,
|
|
101
|
+
label
|
|
102
|
+
}: ResetButtonProps): react_jsx_runtime0.JSX.Element;
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//# sourceMappingURL=reset-button.d.ts.map
|
|
106
|
+
|
|
107
|
+
export { Minimap, MinimapProps, ResetButton, ResetButtonProps, ScalerView, ScalerViewProps, UseScalerOptions, UseScalerReturn, ZoomControls, ZoomControlsProps, useScaler };
|
|
108
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/use-scaler.ts","../src/scaler-view.tsx","../src/ui/zoom-controls.tsx","../src/ui/minimap.tsx","../src/ui/reset-button.tsx"],"sourcesContent":null,"mappings":";;;;;;;;UAIiB,gBAAA,SAAyB,QAAQ;;;;UAKjC,eAAA;OACV,KAAA,CAAM,UAAU;UACb;EAPO,QAAA,EAAA,CAAA,IAAA,EAAA,MAAiB,EAAA,GAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,EAAA,GAAA,IAAA;EAAA,QAAA,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,EAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,EAAA,GAAA,IAAA;EAAA,MAAgB,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,GAAA,IAAA;EAAa,MAArB,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,EAAA,GAAA,IAAA;EAAO,cAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,GAAA,IAAA;AAKjD;AAAgC,iBAmBhB,SAAA,CAnBgB,OAAA,CAAA,EAmBI,gBAnBJ,CAAA,EAmBuB,eAnBvB;;;;;UCLf,eAAA;aACJ;UACH;;YAEE,QAAQ;;EDJH,QAAA,CAAA,EAAA,OAAA;EAAiB,MAAA,CAAA,EAAA,OAAA;EAAA,QAAgB,CAAA,EAAA,OAAA;EAAa,cAArB,CAAA,EAAA,CAAA,MAAA,ECSd,YDTc,EAAA,GAAA,IAAA;AAAO;AAKhC,iBCOD,UAAA,CDPgB;EAAA,QAAA;EAAA,KAAA;EAAA,SAAA;EAAA,OAAA;EAAA,OAAA;EAAA,QAAA;EAAA,MAAA;EAAA,QAAA;EAAA;AAAA,CAAA,ECiB7B,eDjB6B,CAAA,ECiBd,kBAAA,CAAA,GAAA,CAAA,ODjBc;;;;;UEPf,iBAAA;;;;UAIP;;;AFFO,iBEMD,YAAA,CFNkB;EAAA,IAAA;EAAA,QAAA;EAAA,SAAA;EAAA,KAAA;EAAA;AAAA,CAAA,EEM4C,iBFN5C,CAAA,EEM6D,kBAAA,CAAA,GAAA,CAAA,OFN7D;;;;;UGDjB,YAAA;UACP;cACI;;;UAGJ;EHJO,SAAA,CAAA,EAAA,MAAA;;AAAiC,iBGQlC,OAAA,CHRkC;EAAA,MAAA;EAAA,UAAA;EAAA,KAAA;EAAA,MAAA;EAAA,KAAA;EAAA;AAAA,CAAA,EGe/C,YHf+C,CAAA,EGenC,kBAAA,CAAA,GAAA,CAAA,OAAA,GHfmC,IAAA;;;;;UIFjC,gBAAA;;UAEP;;;;iBAKM,WAAA;;;;;GAA0D,mBAAgB,kBAAA,CAAA,GAAA,CAAA;;;AJL1F"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { createWebScaler } from "@panscale/web";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/use-scaler.ts
|
|
6
|
+
const defaultValues = {
|
|
7
|
+
matrix: {
|
|
8
|
+
a: 1,
|
|
9
|
+
b: 0,
|
|
10
|
+
c: 0,
|
|
11
|
+
d: 1,
|
|
12
|
+
e: 0,
|
|
13
|
+
f: 0
|
|
14
|
+
},
|
|
15
|
+
translateX: 0,
|
|
16
|
+
translateY: 0,
|
|
17
|
+
zoom: 1,
|
|
18
|
+
scrollLeft: 0,
|
|
19
|
+
scrollTop: 0
|
|
20
|
+
};
|
|
21
|
+
function useScaler(options) {
|
|
22
|
+
const ref = useRef(null);
|
|
23
|
+
const webScalerRef = useRef(null);
|
|
24
|
+
const [values, setValues] = useState(defaultValues);
|
|
25
|
+
const optionsRef = useRef(options);
|
|
26
|
+
optionsRef.current = options;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const el = ref.current;
|
|
29
|
+
if (!el) return;
|
|
30
|
+
const opts = optionsRef.current;
|
|
31
|
+
const { contentWidth, contentHeight,...scalerOpts } = opts ?? {};
|
|
32
|
+
const webScaler = createWebScaler(el, {
|
|
33
|
+
callback: setValues,
|
|
34
|
+
contentWidth,
|
|
35
|
+
contentHeight,
|
|
36
|
+
...scalerOpts
|
|
37
|
+
});
|
|
38
|
+
webScalerRef.current = webScaler;
|
|
39
|
+
return () => {
|
|
40
|
+
webScaler.destroy();
|
|
41
|
+
webScalerRef.current = null;
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
const scrollTo = useCallback((left, top, animate) => {
|
|
45
|
+
webScalerRef.current?.scaler.scrollTo(left, top, animate);
|
|
46
|
+
}, []);
|
|
47
|
+
const scrollBy = useCallback((dx, dy, animate) => {
|
|
48
|
+
webScalerRef.current?.scaler.scrollBy(dx, dy, animate);
|
|
49
|
+
}, []);
|
|
50
|
+
const zoomTo = useCallback((level, animate, originX, originY) => {
|
|
51
|
+
webScalerRef.current?.scaler.zoomTo(level, animate, originX, originY);
|
|
52
|
+
}, []);
|
|
53
|
+
const zoomBy = useCallback((factor, animate, originX, originY) => {
|
|
54
|
+
webScalerRef.current?.scaler.zoomBy(factor, animate, originX, originY);
|
|
55
|
+
}, []);
|
|
56
|
+
const setContentSize = useCallback((width, height) => {
|
|
57
|
+
webScalerRef.current?.updateContentSize(width, height);
|
|
58
|
+
}, []);
|
|
59
|
+
return {
|
|
60
|
+
ref,
|
|
61
|
+
values,
|
|
62
|
+
scrollTo,
|
|
63
|
+
scrollBy,
|
|
64
|
+
zoomTo,
|
|
65
|
+
zoomBy,
|
|
66
|
+
setContentSize
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/scaler-view.tsx
|
|
72
|
+
function ScalerView({ children, style, className, options, zooming, bouncing, paging, snapping, onValuesChange }) {
|
|
73
|
+
const mergedOptions = {
|
|
74
|
+
...options,
|
|
75
|
+
...zooming !== void 0 ? { zooming } : {},
|
|
76
|
+
...bouncing !== void 0 ? { bouncing } : {},
|
|
77
|
+
...paging !== void 0 ? { paging } : {},
|
|
78
|
+
...snapping !== void 0 ? { snapping } : {}
|
|
79
|
+
};
|
|
80
|
+
const { ref, values } = useScaler(mergedOptions);
|
|
81
|
+
const prevValuesRef = useRef(values);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (onValuesChange && values !== prevValuesRef.current) {
|
|
84
|
+
prevValuesRef.current = values;
|
|
85
|
+
onValuesChange(values);
|
|
86
|
+
}
|
|
87
|
+
}, [values, onValuesChange]);
|
|
88
|
+
return /* @__PURE__ */ jsx("div", {
|
|
89
|
+
ref,
|
|
90
|
+
style: {
|
|
91
|
+
overflow: "hidden",
|
|
92
|
+
position: "relative",
|
|
93
|
+
...style
|
|
94
|
+
},
|
|
95
|
+
className,
|
|
96
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
97
|
+
style: {
|
|
98
|
+
transform: `translate(${values.translateX}px, ${values.translateY}px) scale(${values.zoom})`,
|
|
99
|
+
transformOrigin: "0 0",
|
|
100
|
+
willChange: "transform"
|
|
101
|
+
},
|
|
102
|
+
children
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/ui/zoom-controls.tsx
|
|
109
|
+
function ZoomControls({ zoom, onZoomIn, onZoomOut, style, className }) {
|
|
110
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
111
|
+
style: {
|
|
112
|
+
display: "flex",
|
|
113
|
+
alignItems: "center",
|
|
114
|
+
gap: 8,
|
|
115
|
+
...style
|
|
116
|
+
},
|
|
117
|
+
className,
|
|
118
|
+
children: [
|
|
119
|
+
/* @__PURE__ */ jsx("button", {
|
|
120
|
+
onClick: onZoomOut,
|
|
121
|
+
"aria-label": "Zoom out",
|
|
122
|
+
type: "button",
|
|
123
|
+
children: "−"
|
|
124
|
+
}),
|
|
125
|
+
/* @__PURE__ */ jsxs("span", { children: [Math.round(zoom * 100), "%"] }),
|
|
126
|
+
/* @__PURE__ */ jsx("button", {
|
|
127
|
+
onClick: onZoomIn,
|
|
128
|
+
"aria-label": "Zoom in",
|
|
129
|
+
type: "button",
|
|
130
|
+
children: "+"
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/ui/minimap.tsx
|
|
138
|
+
function Minimap({ values, dimensions, width = 150, height = 100, style, className }) {
|
|
139
|
+
if (dimensions.contentWidth === 0 || dimensions.contentHeight === 0) return null;
|
|
140
|
+
const scaleX = width / dimensions.contentWidth;
|
|
141
|
+
const scaleY = height / dimensions.contentHeight;
|
|
142
|
+
const s = Math.min(scaleX, scaleY);
|
|
143
|
+
const vpWidth = dimensions.clientWidth / values.zoom * s;
|
|
144
|
+
const vpHeight = dimensions.clientHeight / values.zoom * s;
|
|
145
|
+
const vpLeft = values.scrollLeft * s / values.zoom;
|
|
146
|
+
const vpTop = values.scrollTop * s / values.zoom;
|
|
147
|
+
return /* @__PURE__ */ jsx("div", {
|
|
148
|
+
style: {
|
|
149
|
+
position: "relative",
|
|
150
|
+
width,
|
|
151
|
+
height,
|
|
152
|
+
border: "1px solid #ccc",
|
|
153
|
+
background: "#f5f5f5",
|
|
154
|
+
...style
|
|
155
|
+
},
|
|
156
|
+
className,
|
|
157
|
+
children: /* @__PURE__ */ jsx("div", { style: {
|
|
158
|
+
position: "absolute",
|
|
159
|
+
left: vpLeft,
|
|
160
|
+
top: vpTop,
|
|
161
|
+
width: vpWidth,
|
|
162
|
+
height: vpHeight,
|
|
163
|
+
border: "2px solid #007bff",
|
|
164
|
+
background: "rgba(0, 123, 255, 0.1)",
|
|
165
|
+
pointerEvents: "none"
|
|
166
|
+
} })
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/ui/reset-button.tsx
|
|
172
|
+
function ResetButton({ onReset, style, className, label = "1:1" }) {
|
|
173
|
+
return /* @__PURE__ */ jsx("button", {
|
|
174
|
+
onClick: onReset,
|
|
175
|
+
style,
|
|
176
|
+
className,
|
|
177
|
+
"aria-label": "Reset zoom",
|
|
178
|
+
type: "button",
|
|
179
|
+
children: label
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
export { Minimap, ResetButton, ScalerView, ZoomControls, useScaler };
|
|
185
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["defaultValues: ScalerValues","options?: UseScalerOptions","left: number","top: number","animate?: boolean","dx: number","dy: number","level: number","originX?: number","originY?: number","factor: number","width: number","height: number","mergedOptions: Partial<ScalerOptions>"],"sources":["../src/use-scaler.ts","../src/scaler-view.tsx","../src/ui/zoom-controls.tsx","../src/ui/minimap.tsx","../src/ui/reset-button.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { Scaler, type ScalerOptions, type ScalerValues } from \"@panscale/core\";\nimport { createWebScaler, type WebScaler } from \"@panscale/web\";\n\nexport interface UseScalerOptions extends Partial<ScalerOptions> {\n contentWidth?: number;\n contentHeight?: number;\n}\n\nexport interface UseScalerReturn {\n ref: React.RefObject<HTMLDivElement | null>;\n values: ScalerValues;\n scrollTo: (left: number, top: number, animate?: boolean) => void;\n scrollBy: (dx: number, dy: number, animate?: boolean) => void;\n zoomTo: (level: number, animate?: boolean, originX?: number, originY?: number) => void;\n zoomBy: (factor: number, animate?: boolean, originX?: number, originY?: number) => void;\n setContentSize: (width: number, height: number) => void;\n}\n\nconst defaultValues: ScalerValues = {\n matrix: { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 },\n translateX: 0,\n translateY: 0,\n zoom: 1,\n scrollLeft: 0,\n scrollTop: 0\n};\n\nexport function useScaler(options?: UseScalerOptions): UseScalerReturn {\n const ref = useRef<HTMLDivElement | null>(null);\n const webScalerRef = useRef<WebScaler | null>(null);\n const [values, setValues] = useState<ScalerValues>(defaultValues);\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const opts = optionsRef.current;\n const { contentWidth, contentHeight, ...scalerOpts } = opts ?? {};\n\n const webScaler = createWebScaler(el, {\n callback: setValues,\n contentWidth,\n contentHeight,\n ...scalerOpts\n });\n webScalerRef.current = webScaler;\n\n return () => {\n webScaler.destroy();\n webScalerRef.current = null;\n };\n }, []);\n\n const scrollTo = useCallback((left: number, top: number, animate?: boolean) => {\n webScalerRef.current?.scaler.scrollTo(left, top, animate);\n }, []);\n\n const scrollBy = useCallback((dx: number, dy: number, animate?: boolean) => {\n webScalerRef.current?.scaler.scrollBy(dx, dy, animate);\n }, []);\n\n const zoomTo = useCallback((level: number, animate?: boolean, originX?: number, originY?: number) => {\n webScalerRef.current?.scaler.zoomTo(level, animate, originX, originY);\n }, []);\n\n const zoomBy = useCallback((factor: number, animate?: boolean, originX?: number, originY?: number) => {\n webScalerRef.current?.scaler.zoomBy(factor, animate, originX, originY);\n }, []);\n\n const setContentSize = useCallback((width: number, height: number) => {\n webScalerRef.current?.updateContentSize(width, height);\n }, []);\n\n return { ref, values, scrollTo, scrollBy, zoomTo, zoomBy, setContentSize };\n}\n","import { type CSSProperties, type ReactNode, useCallback, useEffect, useRef } from \"react\";\nimport type { ScalerOptions, ScalerValues } from \"@panscale/core\";\nimport { useScaler } from \"./use-scaler\";\n\nexport interface ScalerViewProps {\n children?: ReactNode;\n style?: CSSProperties;\n className?: string;\n options?: Partial<ScalerOptions>;\n zooming?: boolean;\n bouncing?: boolean;\n paging?: boolean;\n snapping?: boolean;\n onValuesChange?: (values: ScalerValues) => void;\n}\n\nexport function ScalerView({\n children,\n style,\n className,\n options,\n zooming,\n bouncing,\n paging,\n snapping,\n onValuesChange\n}: ScalerViewProps) {\n const mergedOptions: Partial<ScalerOptions> = {\n ...options,\n ...(zooming !== undefined ? { zooming } : {}),\n ...(bouncing !== undefined ? { bouncing } : {}),\n ...(paging !== undefined ? { paging } : {}),\n ...(snapping !== undefined ? { snapping } : {})\n };\n\n const { ref, values } = useScaler(mergedOptions);\n const prevValuesRef = useRef(values);\n\n useEffect(() => {\n if (onValuesChange && values !== prevValuesRef.current) {\n prevValuesRef.current = values;\n onValuesChange(values);\n }\n }, [values, onValuesChange]);\n\n return (\n <div\n ref={ref}\n style={{ overflow: \"hidden\", position: \"relative\", ...style }}\n className={className}\n >\n <div\n style={{\n transform: `translate(${values.translateX}px, ${values.translateY}px) scale(${values.zoom})`,\n transformOrigin: \"0 0\",\n willChange: \"transform\"\n }}\n >\n {children}\n </div>\n </div>\n );\n}\n","import type { CSSProperties } from \"react\";\n\nexport interface ZoomControlsProps {\n zoom: number;\n onZoomIn: () => void;\n onZoomOut: () => void;\n style?: CSSProperties;\n className?: string;\n}\n\nexport function ZoomControls({ zoom, onZoomIn, onZoomOut, style, className }: ZoomControlsProps) {\n return (\n <div\n style={{ display: \"flex\", alignItems: \"center\", gap: 8, ...style }}\n className={className}\n >\n <button onClick={onZoomOut} aria-label=\"Zoom out\" type=\"button\">\n −\n </button>\n <span>{Math.round(zoom * 100)}%</span>\n <button onClick={onZoomIn} aria-label=\"Zoom in\" type=\"button\">\n +\n </button>\n </div>\n );\n}\n","import type { CSSProperties } from \"react\";\nimport type { ScalerValues, Dimensions } from \"@panscale/core\";\n\nexport interface MinimapProps {\n values: ScalerValues;\n dimensions: Dimensions;\n width?: number;\n height?: number;\n style?: CSSProperties;\n className?: string;\n}\n\nexport function Minimap({\n values,\n dimensions,\n width = 150,\n height = 100,\n style,\n className\n}: MinimapProps) {\n if (dimensions.contentWidth === 0 || dimensions.contentHeight === 0) return null;\n\n const scaleX = width / dimensions.contentWidth;\n const scaleY = height / dimensions.contentHeight;\n const s = Math.min(scaleX, scaleY);\n\n const vpWidth = (dimensions.clientWidth / values.zoom) * s;\n const vpHeight = (dimensions.clientHeight / values.zoom) * s;\n const vpLeft = values.scrollLeft * s / values.zoom;\n const vpTop = values.scrollTop * s / values.zoom;\n\n return (\n <div\n style={{\n position: \"relative\",\n width,\n height,\n border: \"1px solid #ccc\",\n background: \"#f5f5f5\",\n ...style\n }}\n className={className}\n >\n <div\n style={{\n position: \"absolute\",\n left: vpLeft,\n top: vpTop,\n width: vpWidth,\n height: vpHeight,\n border: \"2px solid #007bff\",\n background: \"rgba(0, 123, 255, 0.1)\",\n pointerEvents: \"none\"\n }}\n />\n </div>\n );\n}\n","import type { CSSProperties } from \"react\";\n\nexport interface ResetButtonProps {\n onReset: () => void;\n style?: CSSProperties;\n className?: string;\n label?: string;\n}\n\nexport function ResetButton({ onReset, style, className, label = \"1:1\" }: ResetButtonProps) {\n return (\n <button\n onClick={onReset}\n style={style}\n className={className}\n aria-label=\"Reset zoom\"\n type=\"button\"\n >\n {label}\n </button>\n );\n}\n"],"mappings":";;;;;AAmBA,MAAMA,gBAA8B;CAClC,QAAQ;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;CAAG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D,SAAgB,QAAQ,EACtB,QACA,YACA,QAAQ,KACR,SAAS,KACT,OACA,WACa,EAAE;AACf,KAAI,WAAW,iBAAiB,KAAK,WAAW,kBAAkB,EAAG,QAAO;CAE5E,MAAM,SAAS,QAAQ,WAAW;CAClC,MAAM,SAAS,SAAS,WAAW;CACnC,MAAM,IAAI,KAAK,IAAI,QAAQ,OAAO;CAElC,MAAM,UAAW,WAAW,cAAc,OAAO,OAAQ;CACzD,MAAM,WAAY,WAAW,eAAe,OAAO,OAAQ;CAC3D,MAAM,SAAS,OAAO,aAAa,IAAI,OAAO;CAC9C,MAAM,QAAQ,OAAO,YAAY,IAAI,OAAO;AAE5C,wBACE,IAAC,OAAA;EACC,OAAO;GACL,UAAU;GACV;GACA;GACA,QAAQ;GACR,YAAY;GACZ,GAAG;EACJ;EACU;4BAEX,IAAC,OAAA,EACC,OAAO;GACL,UAAU;GACV,MAAM;GACN,KAAK;GACL,OAAO;GACP,QAAQ;GACR,QAAQ;GACR,YAAY;GACZ,eAAe;EAChB,EAAA,EACD;GACE;AAET;;;;AChDD,SAAgB,YAAY,EAAE,SAAS,OAAO,WAAW,QAAQ,OAAyB,EAAE;AAC1F,wBACE,IAAC,UAAA;EACC,SAAS;EACF;EACI;EACX,cAAW;EACX,MAAK;YAEJ;GACM;AAEZ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@panscale/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
25
|
+
"@panscale/web": "0.1.0",
|
|
26
|
+
"@panscale/core": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
30
|
+
"@types/react": "^19.0.0",
|
|
31
|
+
"publint": "^0.3.8",
|
|
32
|
+
"react": "^19.0.0",
|
|
33
|
+
"tsdown": "^0.10.2",
|
|
34
|
+
"transformation-matrix": "^3.0.0",
|
|
35
|
+
"typescript": "^5.7.3",
|
|
36
|
+
"@panscale/core": "0.1.0",
|
|
37
|
+
"@panscale/web": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsdown",
|
|
41
|
+
"check": "pnpm build && publint && attw --pack . --ignore-rules cjs-resolves-to-esm"
|
|
42
|
+
}
|
|
43
|
+
}
|