@panscale/react 0.3.1 → 0.3.2
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.d.ts +115 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +202 -0
- package/dist/index.js.map +1 -0
- package/package.json +5 -5
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
doubleTapZoom?: number;
|
|
13
|
+
onResize?: (size: {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}) => void;
|
|
17
|
+
}
|
|
18
|
+
interface UseScalerReturn {
|
|
19
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
20
|
+
values: ScalerValues;
|
|
21
|
+
scrollTo: (left: number, top: number, animate?: boolean) => void;
|
|
22
|
+
scrollBy: (dx: number, dy: number, animate?: boolean) => void;
|
|
23
|
+
zoomTo: (level: number, animate?: boolean, originX?: number, originY?: number) => void;
|
|
24
|
+
zoomBy: (factor: number, animate?: boolean, originX?: number, originY?: number) => void;
|
|
25
|
+
setContentSize: (width: number, height: number) => void;
|
|
26
|
+
fitToContent: (animate?: boolean) => void;
|
|
27
|
+
setZoomBounds: (min: number, max: number) => void;
|
|
28
|
+
}
|
|
29
|
+
declare function useScaler(options?: UseScalerOptions): UseScalerReturn;
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/scaler-view.d.ts
|
|
33
|
+
//# sourceMappingURL=use-scaler.d.ts.map
|
|
34
|
+
interface ScalerViewProps {
|
|
35
|
+
children?: ReactNode;
|
|
36
|
+
style?: CSSProperties;
|
|
37
|
+
className?: string;
|
|
38
|
+
options?: Partial<ScalerOptions>;
|
|
39
|
+
zooming?: boolean;
|
|
40
|
+
bouncing?: boolean;
|
|
41
|
+
paging?: boolean;
|
|
42
|
+
snapping?: boolean;
|
|
43
|
+
onValuesChange?: (values: ScalerValues) => void;
|
|
44
|
+
}
|
|
45
|
+
declare function ScalerView({
|
|
46
|
+
children,
|
|
47
|
+
style,
|
|
48
|
+
className,
|
|
49
|
+
options,
|
|
50
|
+
zooming,
|
|
51
|
+
bouncing,
|
|
52
|
+
paging,
|
|
53
|
+
snapping,
|
|
54
|
+
onValuesChange
|
|
55
|
+
}: ScalerViewProps): react_jsx_runtime1.JSX.Element;
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/ui/zoom-controls.d.ts
|
|
59
|
+
//# sourceMappingURL=scaler-view.d.ts.map
|
|
60
|
+
interface ZoomControlsProps {
|
|
61
|
+
zoom: number;
|
|
62
|
+
onZoomIn: () => void;
|
|
63
|
+
onZoomOut: () => void;
|
|
64
|
+
style?: CSSProperties;
|
|
65
|
+
className?: string;
|
|
66
|
+
}
|
|
67
|
+
declare function ZoomControls({
|
|
68
|
+
zoom,
|
|
69
|
+
onZoomIn,
|
|
70
|
+
onZoomOut,
|
|
71
|
+
style,
|
|
72
|
+
className
|
|
73
|
+
}: ZoomControlsProps): react_jsx_runtime2.JSX.Element;
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/ui/minimap.d.ts
|
|
77
|
+
//# sourceMappingURL=zoom-controls.d.ts.map
|
|
78
|
+
interface MinimapProps {
|
|
79
|
+
values: ScalerValues;
|
|
80
|
+
dimensions: Dimensions;
|
|
81
|
+
width?: number;
|
|
82
|
+
height?: number;
|
|
83
|
+
style?: CSSProperties;
|
|
84
|
+
className?: string;
|
|
85
|
+
}
|
|
86
|
+
declare function Minimap({
|
|
87
|
+
values,
|
|
88
|
+
dimensions,
|
|
89
|
+
width,
|
|
90
|
+
height,
|
|
91
|
+
style,
|
|
92
|
+
className
|
|
93
|
+
}: MinimapProps): react_jsx_runtime3.JSX.Element | null;
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/ui/reset-button.d.ts
|
|
97
|
+
//# sourceMappingURL=minimap.d.ts.map
|
|
98
|
+
interface ResetButtonProps {
|
|
99
|
+
onReset: () => void;
|
|
100
|
+
style?: CSSProperties;
|
|
101
|
+
className?: string;
|
|
102
|
+
label?: string;
|
|
103
|
+
}
|
|
104
|
+
declare function ResetButton({
|
|
105
|
+
onReset,
|
|
106
|
+
style,
|
|
107
|
+
className,
|
|
108
|
+
label
|
|
109
|
+
}: ResetButtonProps): react_jsx_runtime0.JSX.Element;
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//# sourceMappingURL=reset-button.d.ts.map
|
|
113
|
+
|
|
114
|
+
export { Minimap, MinimapProps, ResetButton, ResetButtonProps, ScalerView, ScalerViewProps, UseScalerOptions, UseScalerReturn, ZoomControls, ZoomControlsProps, useScaler };
|
|
115
|
+
//# 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;;;;;;;EAAjC,CAAA,EAAA,GAAA,IAAA;;AAAiC,UAOjC,eAAA,CAPiC;EAAa,GAArB,EAQnC,KAAA,CAAM,SAR6B,CAQnB,cARmB,GAAA,IAAA,CAAA;EAAO,MAAA,EASvC,YATuC;EA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A,CAAA,ODfc;;;;;UETf,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,202 @@
|
|
|
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
|
+
isInteracting: false
|
|
21
|
+
};
|
|
22
|
+
function useScaler(options) {
|
|
23
|
+
const ref = useRef(null);
|
|
24
|
+
const webScalerRef = useRef(null);
|
|
25
|
+
const [values, setValues] = useState(defaultValues);
|
|
26
|
+
const optionsRef = useRef(options);
|
|
27
|
+
optionsRef.current = options;
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const el = ref.current;
|
|
30
|
+
if (!el) return;
|
|
31
|
+
const opts = optionsRef.current;
|
|
32
|
+
const { contentWidth, contentHeight, doubleTapZoom, onResize,...scalerOpts } = opts ?? {};
|
|
33
|
+
const webScaler = createWebScaler(el, {
|
|
34
|
+
callback: setValues,
|
|
35
|
+
contentWidth,
|
|
36
|
+
contentHeight,
|
|
37
|
+
doubleTapZoom,
|
|
38
|
+
onResize,
|
|
39
|
+
...scalerOpts
|
|
40
|
+
});
|
|
41
|
+
webScalerRef.current = webScaler;
|
|
42
|
+
return () => {
|
|
43
|
+
webScaler.destroy();
|
|
44
|
+
webScalerRef.current = null;
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
const contentWidthOption = options?.contentWidth;
|
|
48
|
+
const contentHeightOption = options?.contentHeight;
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (contentWidthOption === void 0 || contentHeightOption === void 0) return;
|
|
51
|
+
webScalerRef.current?.updateContentSize(contentWidthOption, contentHeightOption);
|
|
52
|
+
}, [contentWidthOption, contentHeightOption]);
|
|
53
|
+
const scrollTo = useCallback((left, top, animate) => {
|
|
54
|
+
webScalerRef.current?.scaler.scrollTo(left, top, animate);
|
|
55
|
+
}, []);
|
|
56
|
+
const scrollBy = useCallback((dx, dy, animate) => {
|
|
57
|
+
webScalerRef.current?.scaler.scrollBy(dx, dy, animate);
|
|
58
|
+
}, []);
|
|
59
|
+
const zoomTo = useCallback((level, animate, originX, originY) => {
|
|
60
|
+
webScalerRef.current?.scaler.zoomTo(level, animate, originX, originY);
|
|
61
|
+
}, []);
|
|
62
|
+
const zoomBy = useCallback((factor, animate, originX, originY) => {
|
|
63
|
+
webScalerRef.current?.scaler.zoomBy(factor, animate, originX, originY);
|
|
64
|
+
}, []);
|
|
65
|
+
const setContentSize = useCallback((width, height) => {
|
|
66
|
+
webScalerRef.current?.updateContentSize(width, height);
|
|
67
|
+
}, []);
|
|
68
|
+
const fitToContent = useCallback((animate) => {
|
|
69
|
+
webScalerRef.current?.scaler.fitToContent(animate);
|
|
70
|
+
}, []);
|
|
71
|
+
const setZoomBounds = useCallback((min, max) => {
|
|
72
|
+
webScalerRef.current?.scaler.setZoomBounds(min, max);
|
|
73
|
+
}, []);
|
|
74
|
+
return {
|
|
75
|
+
ref,
|
|
76
|
+
values,
|
|
77
|
+
scrollTo,
|
|
78
|
+
scrollBy,
|
|
79
|
+
zoomTo,
|
|
80
|
+
zoomBy,
|
|
81
|
+
setContentSize,
|
|
82
|
+
fitToContent,
|
|
83
|
+
setZoomBounds
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/scaler-view.tsx
|
|
89
|
+
function ScalerView({ children, style, className, options, zooming, bouncing, paging, snapping, onValuesChange }) {
|
|
90
|
+
const mergedOptions = {
|
|
91
|
+
...options,
|
|
92
|
+
...zooming !== void 0 ? { zooming } : {},
|
|
93
|
+
...bouncing !== void 0 ? { bouncing } : {},
|
|
94
|
+
...paging !== void 0 ? { paging } : {},
|
|
95
|
+
...snapping !== void 0 ? { snapping } : {}
|
|
96
|
+
};
|
|
97
|
+
const { ref, values } = useScaler(mergedOptions);
|
|
98
|
+
const prevValuesRef = useRef(values);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (onValuesChange && values !== prevValuesRef.current) {
|
|
101
|
+
prevValuesRef.current = values;
|
|
102
|
+
onValuesChange(values);
|
|
103
|
+
}
|
|
104
|
+
}, [values, onValuesChange]);
|
|
105
|
+
return /* @__PURE__ */ jsx("div", {
|
|
106
|
+
ref,
|
|
107
|
+
style: {
|
|
108
|
+
overflow: "hidden",
|
|
109
|
+
position: "relative",
|
|
110
|
+
...style
|
|
111
|
+
},
|
|
112
|
+
className,
|
|
113
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
114
|
+
style: {
|
|
115
|
+
transform: `translate(${values.translateX}px, ${values.translateY}px) scale(${values.zoom})`,
|
|
116
|
+
transformOrigin: "0 0",
|
|
117
|
+
willChange: "transform"
|
|
118
|
+
},
|
|
119
|
+
children
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/ui/zoom-controls.tsx
|
|
126
|
+
function ZoomControls({ zoom, onZoomIn, onZoomOut, style, className }) {
|
|
127
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
128
|
+
style: {
|
|
129
|
+
display: "flex",
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
gap: 8,
|
|
132
|
+
...style
|
|
133
|
+
},
|
|
134
|
+
className,
|
|
135
|
+
children: [
|
|
136
|
+
/* @__PURE__ */ jsx("button", {
|
|
137
|
+
onClick: onZoomOut,
|
|
138
|
+
"aria-label": "Zoom out",
|
|
139
|
+
type: "button",
|
|
140
|
+
children: "−"
|
|
141
|
+
}),
|
|
142
|
+
/* @__PURE__ */ jsxs("span", { children: [Math.round(zoom * 100), "%"] }),
|
|
143
|
+
/* @__PURE__ */ jsx("button", {
|
|
144
|
+
onClick: onZoomIn,
|
|
145
|
+
"aria-label": "Zoom in",
|
|
146
|
+
type: "button",
|
|
147
|
+
children: "+"
|
|
148
|
+
})
|
|
149
|
+
]
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/ui/minimap.tsx
|
|
155
|
+
function Minimap({ values, dimensions, width = 150, height = 100, style, className }) {
|
|
156
|
+
if (dimensions.contentWidth === 0 || dimensions.contentHeight === 0) return null;
|
|
157
|
+
const scaleX = width / dimensions.contentWidth;
|
|
158
|
+
const scaleY = height / dimensions.contentHeight;
|
|
159
|
+
const s = Math.min(scaleX, scaleY);
|
|
160
|
+
const vpWidth = dimensions.clientWidth / values.zoom * s;
|
|
161
|
+
const vpHeight = dimensions.clientHeight / values.zoom * s;
|
|
162
|
+
const vpLeft = values.scrollLeft * s / values.zoom;
|
|
163
|
+
const vpTop = values.scrollTop * s / values.zoom;
|
|
164
|
+
return /* @__PURE__ */ jsx("div", {
|
|
165
|
+
style: {
|
|
166
|
+
position: "relative",
|
|
167
|
+
width,
|
|
168
|
+
height,
|
|
169
|
+
border: "1px solid #ccc",
|
|
170
|
+
background: "#f5f5f5",
|
|
171
|
+
...style
|
|
172
|
+
},
|
|
173
|
+
className,
|
|
174
|
+
children: /* @__PURE__ */ jsx("div", { style: {
|
|
175
|
+
position: "absolute",
|
|
176
|
+
left: vpLeft,
|
|
177
|
+
top: vpTop,
|
|
178
|
+
width: vpWidth,
|
|
179
|
+
height: vpHeight,
|
|
180
|
+
border: "2px solid #007bff",
|
|
181
|
+
background: "rgba(0, 123, 255, 0.1)",
|
|
182
|
+
pointerEvents: "none"
|
|
183
|
+
} })
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/ui/reset-button.tsx
|
|
189
|
+
function ResetButton({ onReset, style, className, label = "1:1" }) {
|
|
190
|
+
return /* @__PURE__ */ jsx("button", {
|
|
191
|
+
onClick: onReset,
|
|
192
|
+
style,
|
|
193
|
+
className,
|
|
194
|
+
"aria-label": "Reset zoom",
|
|
195
|
+
type: "button",
|
|
196
|
+
children: label
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
export { Minimap, ResetButton, ScalerView, ZoomControls, useScaler };
|
|
202
|
+
//# 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","min: number","max: 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 doubleTapZoom?: number;\n onResize?: (size: { width: number; height: number }) => void;\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 fitToContent: (animate?: boolean) => void;\n setZoomBounds: (min: number, max: 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 isInteracting: false\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, doubleTapZoom, onResize, ...scalerOpts } = opts ?? {};\n\n const webScaler = createWebScaler(el, {\n callback: setValues,\n contentWidth,\n contentHeight,\n doubleTapZoom,\n onResize,\n ...scalerOpts\n });\n webScalerRef.current = webScaler;\n\n return () => {\n webScaler.destroy();\n webScalerRef.current = null;\n };\n }, []);\n\n // A changed contentWidth/contentHeight option reaches the live scaler, not only\n // the one given at mount. The mount effect above runs first and already used\n // the initial values, so the first run of this effect repeats them harmlessly.\n const contentWidthOption = options?.contentWidth;\n const contentHeightOption = options?.contentHeight;\n useEffect(() => {\n if (contentWidthOption === undefined || contentHeightOption === undefined) return;\n webScalerRef.current?.updateContentSize(contentWidthOption, contentHeightOption);\n }, [contentWidthOption, contentHeightOption]);\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 const fitToContent = useCallback((animate?: boolean) => {\n webScalerRef.current?.scaler.fitToContent(animate);\n }, []);\n\n const setZoomBounds = useCallback((min: number, max: number) => {\n webScalerRef.current?.scaler.setZoomBounds(min, max);\n }, []);\n\n return { ref, values, scrollTo, scrollBy, zoomTo, zoomBy, setContentSize, fitToContent, setZoomBounds };\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":";;;;;AAuBA,MAAMA,gBAA8B;CAClC,QAAQ;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;EAAG,GAAG;CAAG;CAC9C,YAAY;CACZ,YAAY;CACZ,MAAM;CACN,YAAY;CACZ,WAAW;CACX,eAAe;AAChB;AAED,SAAgB,UAAUC,SAA6C;CACrE,MAAM,MAAM,OAA8B,KAAK;CAC/C,MAAM,eAAe,OAAyB,KAAK;CACnD,MAAM,CAAC,QAAQ,UAAU,GAAG,SAAuB,cAAc;CACjE,MAAM,aAAa,OAAO,QAAQ;AAClC,YAAW,UAAU;AAErB,WAAU,MAAM;EACd,MAAM,KAAK,IAAI;AACf,OAAK,GAAI;EAET,MAAM,OAAO,WAAW;EACxB,MAAM,EAAE,cAAc,eAAe,eAAe,SAAU,GAAG,YAAY,GAAG,QAAQ,CAAE;EAE1F,MAAM,YAAY,gBAAgB,IAAI;GACpC,UAAU;GACV;GACA;GACA;GACA;GACA,GAAG;EACJ,EAAC;AACF,eAAa,UAAU;AAEvB,SAAO,MAAM;AACX,aAAU,SAAS;AACnB,gBAAa,UAAU;EACxB;CACF,GAA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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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panscale/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^18.0.0 || ^19.0.0",
|
|
25
|
-
"@panscale/core": "0.3.
|
|
26
|
-
"@panscale/web": "0.3.
|
|
25
|
+
"@panscale/core": "0.3.2",
|
|
26
|
+
"@panscale/web": "0.3.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"tsdown": "^0.10.2",
|
|
34
34
|
"transformation-matrix": "^3.0.0",
|
|
35
35
|
"typescript": "^5.7.3",
|
|
36
|
-
"@panscale/core": "0.3.
|
|
37
|
-
"@panscale/web": "0.3.
|
|
36
|
+
"@panscale/core": "0.3.2",
|
|
37
|
+
"@panscale/web": "0.3.2"
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|