@panscale/react-native 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 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.
@@ -0,0 +1,65 @@
1
+ import * as react_native3 from "react-native";
2
+ import { ViewStyle } from "react-native";
3
+ import { Scaler, ScalerOptions, ScalerValues } from "@panscale/core";
4
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
5
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
6
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
7
+
8
+ //#region src/native-adapter.d.ts
9
+ declare function createNativeAdapter(scaler: Scaler): react_native3.PanResponderInstance;
10
+
11
+ //#endregion
12
+ //#region src/scaler-view.d.ts
13
+ //# sourceMappingURL=native-adapter.d.ts.map
14
+ interface NativeScalerViewProps {
15
+ children?: React.ReactNode;
16
+ style?: ViewStyle;
17
+ contentWidth: number;
18
+ contentHeight: number;
19
+ options?: Partial<ScalerOptions>;
20
+ onValuesChange?: (values: ScalerValues) => void;
21
+ }
22
+ declare function ScalerView({
23
+ children,
24
+ style,
25
+ contentWidth,
26
+ contentHeight,
27
+ options,
28
+ onValuesChange
29
+ }: NativeScalerViewProps): react_jsx_runtime1.JSX.Element;
30
+
31
+ //#endregion
32
+ //#region src/ui/zoom-controls.d.ts
33
+ //# sourceMappingURL=scaler-view.d.ts.map
34
+ interface ZoomControlsProps {
35
+ zoom: number;
36
+ onZoomIn: () => void;
37
+ onZoomOut: () => void;
38
+ style?: ViewStyle;
39
+ }
40
+ declare function ZoomControls({
41
+ zoom,
42
+ onZoomIn,
43
+ onZoomOut,
44
+ style
45
+ }: ZoomControlsProps): react_jsx_runtime2.JSX.Element;
46
+
47
+ //#endregion
48
+ //#region src/ui/reset-button.d.ts
49
+ //# sourceMappingURL=zoom-controls.d.ts.map
50
+ interface ResetButtonProps {
51
+ onReset: () => void;
52
+ style?: ViewStyle;
53
+ label?: string;
54
+ }
55
+ declare function ResetButton({
56
+ onReset,
57
+ style,
58
+ label
59
+ }: ResetButtonProps): react_jsx_runtime0.JSX.Element;
60
+
61
+ //#endregion
62
+ //# sourceMappingURL=reset-button.d.ts.map
63
+
64
+ export { NativeScalerViewProps, ResetButton, ResetButtonProps, ScalerView, ZoomControls, ZoomControlsProps, createNativeAdapter };
65
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/native-adapter.ts","../src/scaler-view.tsx","../src/ui/zoom-controls.tsx","../src/ui/reset-button.tsx"],"sourcesContent":null,"mappings":";;;;;;;;iBAegB,mBAAA,SAA4B,SAAM,aAAA,CAAA;;;;;UCVjC,qBAAA;aACJ,KAAA,CAAM;UACT;;;YAGE,QAAQ;EDKJ,cAAA,CAAA,EAAA,CAAA,MAAmB,ECJP,YDIO,EAAA,GAAA,IAAA;;AAAS,iBCD5B,UAAA,CDC4B;EAAA,QAAA;EAAA,KAAA;EAAA,YAAA;EAAA,aAAA;EAAA,OAAA;EAAA;AAAA,CAAA,ECMzC,qBDNyC,CAAA,ECMpB,kBAAA,CAAA,GAAA,CAAA,ODNoB;;;;;UEb3B,iBAAA;;;;UAIP;;iBAGM,YAAA;;;;;GAAmD,oBAAiB,kBAAA,CAAA,GAAA,CAAA;;;;AFMpF;UGbiB,gBAAA;;UAEP;;;iBAIM,WAAA;;;;GAA+C,mBAAgB,kBAAA,CAAA,GAAA,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,129 @@
1
+ import { Animated, PanResponder, Text, TouchableOpacity, View } from "react-native";
2
+ import { useCallback, useEffect, useRef } from "react";
3
+ import { Scaler } from "@panscale/core";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+
6
+ //#region src/native-adapter.ts
7
+ function nativeTouchesToScaler(event) {
8
+ const touches = event.nativeEvent.touches;
9
+ if (!touches || touches.length === 0) return [{
10
+ pageX: event.nativeEvent.pageX,
11
+ pageY: event.nativeEvent.pageY
12
+ }];
13
+ return Array.from(touches).map((t) => ({
14
+ pageX: t.pageX,
15
+ pageY: t.pageY
16
+ }));
17
+ }
18
+ function createNativeAdapter(scaler) {
19
+ const panResponder = PanResponder.create({
20
+ onStartShouldSetPanResponder: () => true,
21
+ onMoveShouldSetPanResponder: () => true,
22
+ onPanResponderGrant: (e) => {
23
+ scaler.doTouchStart(nativeTouchesToScaler(e), e.nativeEvent.timestamp);
24
+ },
25
+ onPanResponderMove: (e) => {
26
+ scaler.doTouchMove(nativeTouchesToScaler(e), e.nativeEvent.timestamp);
27
+ },
28
+ onPanResponderRelease: (e) => {
29
+ scaler.doTouchEnd(e.nativeEvent.timestamp);
30
+ },
31
+ onPanResponderTerminate: (e) => {
32
+ scaler.doTouchEnd(e.nativeEvent.timestamp);
33
+ }
34
+ });
35
+ return panResponder;
36
+ }
37
+
38
+ //#endregion
39
+ //#region src/scaler-view.tsx
40
+ function ScalerView({ children, style, contentWidth, contentHeight, options, onValuesChange }) {
41
+ const transformRef = useRef(new Animated.ValueXY({
42
+ x: 0,
43
+ y: 0
44
+ }));
45
+ const scaleRef = useRef(new Animated.Value(1));
46
+ const scalerRef = useRef(null);
47
+ const callback = useCallback((values) => {
48
+ transformRef.current.setValue({
49
+ x: values.translateX,
50
+ y: values.translateY
51
+ });
52
+ scaleRef.current.setValue(values.zoom);
53
+ onValuesChange?.(values);
54
+ }, [onValuesChange]);
55
+ if (!scalerRef.current) scalerRef.current = new Scaler(callback, {
56
+ zooming: true,
57
+ ...options
58
+ });
59
+ const panResponder = useRef(createNativeAdapter(scalerRef.current));
60
+ const onLayout = useCallback((event) => {
61
+ const { width, height } = event.nativeEvent.layout;
62
+ scalerRef.current?.setDimensions(width, height, contentWidth, contentHeight);
63
+ }, [contentWidth, contentHeight]);
64
+ useEffect(() => {
65
+ return () => {
66
+ scalerRef.current?.destroy();
67
+ };
68
+ }, []);
69
+ const animatedStyle = { transform: [
70
+ { translateX: transformRef.current.x },
71
+ { translateY: transformRef.current.y },
72
+ { scale: scaleRef.current }
73
+ ] };
74
+ return /* @__PURE__ */ jsx(View, {
75
+ style: [{ overflow: "hidden" }, style],
76
+ onLayout,
77
+ ...panResponder.current.panHandlers,
78
+ children: /* @__PURE__ */ jsx(Animated.View, {
79
+ style: animatedStyle,
80
+ children
81
+ })
82
+ });
83
+ }
84
+
85
+ //#endregion
86
+ //#region src/ui/zoom-controls.tsx
87
+ function ZoomControls({ zoom, onZoomIn, onZoomOut, style }) {
88
+ return /* @__PURE__ */ jsxs(View, {
89
+ style: [{
90
+ flexDirection: "row",
91
+ alignItems: "center",
92
+ gap: 8
93
+ }, style],
94
+ children: [
95
+ /* @__PURE__ */ jsx(TouchableOpacity, {
96
+ onPress: onZoomOut,
97
+ accessibilityLabel: "Zoom out",
98
+ children: /* @__PURE__ */ jsx(Text, {
99
+ style: { fontSize: 20 },
100
+ children: "−"
101
+ })
102
+ }),
103
+ /* @__PURE__ */ jsxs(Text, { children: [Math.round(zoom * 100), "%"] }),
104
+ /* @__PURE__ */ jsx(TouchableOpacity, {
105
+ onPress: onZoomIn,
106
+ accessibilityLabel: "Zoom in",
107
+ children: /* @__PURE__ */ jsx(Text, {
108
+ style: { fontSize: 20 },
109
+ children: "+"
110
+ })
111
+ })
112
+ ]
113
+ });
114
+ }
115
+
116
+ //#endregion
117
+ //#region src/ui/reset-button.tsx
118
+ function ResetButton({ onReset, style, label = "1:1" }) {
119
+ return /* @__PURE__ */ jsx(TouchableOpacity, {
120
+ onPress: onReset,
121
+ style,
122
+ accessibilityLabel: "Reset zoom",
123
+ children: /* @__PURE__ */ jsx(Text, { children: label })
124
+ });
125
+ }
126
+
127
+ //#endregion
128
+ export { ResetButton, ScalerView, ZoomControls, createNativeAdapter };
129
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["event: GestureResponderEvent","scaler: Scaler","values: ScalerValues","event: LayoutChangeEvent"],"sources":["../src/native-adapter.ts","../src/scaler-view.tsx","../src/ui/zoom-controls.tsx","../src/ui/reset-button.tsx"],"sourcesContent":["import { useRef, useMemo } from \"react\";\nimport { PanResponder, type GestureResponderEvent, type PanResponderGestureState } from \"react-native\";\nimport { Scaler, type ScalerOptions, type ScalerTouch } from \"@panscale/core\";\n\nfunction nativeTouchesToScaler(event: GestureResponderEvent): ScalerTouch[] {\n const touches = event.nativeEvent.touches;\n if (!touches || touches.length === 0) {\n return [{ pageX: event.nativeEvent.pageX, pageY: event.nativeEvent.pageY }];\n }\n return Array.from(touches).map((t) => ({\n pageX: t.pageX,\n pageY: t.pageY\n }));\n}\n\nexport function createNativeAdapter(scaler: Scaler) {\n const panResponder = PanResponder.create({\n onStartShouldSetPanResponder: () => true,\n onMoveShouldSetPanResponder: () => true,\n onPanResponderGrant: (e) => {\n scaler.doTouchStart(nativeTouchesToScaler(e), e.nativeEvent.timestamp);\n },\n onPanResponderMove: (e) => {\n scaler.doTouchMove(nativeTouchesToScaler(e), e.nativeEvent.timestamp);\n },\n onPanResponderRelease: (e) => {\n scaler.doTouchEnd(e.nativeEvent.timestamp);\n },\n onPanResponderTerminate: (e) => {\n scaler.doTouchEnd(e.nativeEvent.timestamp);\n }\n });\n\n return panResponder;\n}\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { Animated, View, type ViewStyle, type LayoutChangeEvent } from \"react-native\";\nimport { Scaler, type ScalerOptions, type ScalerValues } from \"@panscale/core\";\nimport { createNativeAdapter } from \"./native-adapter\";\n\nexport interface NativeScalerViewProps {\n children?: React.ReactNode;\n style?: ViewStyle;\n contentWidth: number;\n contentHeight: number;\n options?: Partial<ScalerOptions>;\n onValuesChange?: (values: ScalerValues) => void;\n}\n\nexport function ScalerView({\n children,\n style,\n contentWidth,\n contentHeight,\n options,\n onValuesChange\n}: NativeScalerViewProps) {\n const transformRef = useRef(new Animated.ValueXY({ x: 0, y: 0 }));\n const scaleRef = useRef(new Animated.Value(1));\n const scalerRef = useRef<Scaler | null>(null);\n\n const callback = useCallback((values: ScalerValues) => {\n transformRef.current.setValue({ x: values.translateX, y: values.translateY });\n scaleRef.current.setValue(values.zoom);\n onValuesChange?.(values);\n }, [onValuesChange]);\n\n if (!scalerRef.current) {\n scalerRef.current = new Scaler(callback, { zooming: true, ...options });\n }\n\n const panResponder = useRef(createNativeAdapter(scalerRef.current));\n\n const onLayout = useCallback((event: LayoutChangeEvent) => {\n const { width, height } = event.nativeEvent.layout;\n scalerRef.current?.setDimensions(width, height, contentWidth, contentHeight);\n }, [contentWidth, contentHeight]);\n\n useEffect(() => {\n return () => {\n scalerRef.current?.destroy();\n };\n }, []);\n\n const animatedStyle = {\n transform: [\n { translateX: transformRef.current.x },\n { translateY: transformRef.current.y },\n { scale: scaleRef.current }\n ]\n };\n\n return (\n <View style={[{ overflow: \"hidden\" }, style]} onLayout={onLayout} {...panResponder.current.panHandlers}>\n <Animated.View style={animatedStyle}>\n {children}\n </Animated.View>\n </View>\n );\n}\n","import { View, Text, TouchableOpacity, type ViewStyle } from \"react-native\";\n\nexport interface ZoomControlsProps {\n zoom: number;\n onZoomIn: () => void;\n onZoomOut: () => void;\n style?: ViewStyle;\n}\n\nexport function ZoomControls({ zoom, onZoomIn, onZoomOut, style }: ZoomControlsProps) {\n return (\n <View style={[{ flexDirection: \"row\", alignItems: \"center\", gap: 8 }, style]}>\n <TouchableOpacity onPress={onZoomOut} accessibilityLabel=\"Zoom out\">\n <Text style={{ fontSize: 20 }}>−</Text>\n </TouchableOpacity>\n <Text>{Math.round(zoom * 100)}%</Text>\n <TouchableOpacity onPress={onZoomIn} accessibilityLabel=\"Zoom in\">\n <Text style={{ fontSize: 20 }}>+</Text>\n </TouchableOpacity>\n </View>\n );\n}\n","import { TouchableOpacity, Text, type ViewStyle } from \"react-native\";\n\nexport interface ResetButtonProps {\n onReset: () => void;\n style?: ViewStyle;\n label?: string;\n}\n\nexport function ResetButton({ onReset, style, label = \"1:1\" }: ResetButtonProps) {\n return (\n <TouchableOpacity onPress={onReset} style={style} accessibilityLabel=\"Reset zoom\">\n <Text>{label}</Text>\n </TouchableOpacity>\n );\n}\n"],"mappings":";;;;;;AAIA,SAAS,sBAAsBA,OAA6C;CAC1E,MAAM,UAAU,MAAM,YAAY;AAClC,MAAK,WAAW,QAAQ,WAAW,EACjC,QAAO,CAAC;EAAE,OAAO,MAAM,YAAY;EAAO,OAAO,MAAM,YAAY;CAAQ,CAAA;AAE7E,QAAO,MAAM,KAAK,QAAQ,CAAC,IAAI,CAAC,OAAO;EACrC,OAAO,EAAE;EACT,OAAO,EAAE;CACV,GAAE;AACJ;AAED,SAAgB,oBAAoBC,QAAgB;CAClD,MAAM,eAAe,aAAa,OAAO;EACvC,8BAA8B,MAAM;EACpC,6BAA6B,MAAM;EACnC,qBAAqB,CAAC,MAAM;AAC1B,UAAO,aAAa,sBAAsB,EAAE,EAAE,EAAE,YAAY,UAAU;EAC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EACF;AAED,wBACE,IAAC,MAAA;EAAK,OAAO,CAAC,EAAE,UAAU,SAAU,GAAE,KAAM;EAAY;EAAU,GAAI,aAAa,QAAQ;4BACzF,IAAC,SAAS,MAAA;GAAK,OAAO;GACnB;IACa;GACX;AAEV;;;;ACvDD,SAAgB,aAAa,EAAE,MAAM,UAAU,WAAW,OAA0B,EAAE;AACpF,wBACE,KAAC,MAAA;EAAK,OAAO,CAAC;GAAE,eAAe;GAAO,YAAY;GAAU,KAAK;EAAG,GAAE,KAAM;;mBAC1E,IAAC,kBAAA;IAAiB,SAAS;IAAW,oBAAmB;8BACvD,IAAC,MAAA;KAAK,OAAO,EAAE,UAAU,GAAI;eAAE;MAAQ;KACtB;mBACnB,KAAC,MAAA,EAAA,UAAA,CAAM,KAAK,MAAM,OAAO,IAAI,EAAC,GAAA,EAAA,EAAQ;mBACtC,IAAC,kBAAA;IAAiB,SAAS;IAAU,oBAAmB;8BACtD,IAAC,MAAA;KAAK,OAAO,EAAE,UAAU,GAAI;eAAE;MAAQ;KACtB;;GACd;AAEV;;;;ACbD,SAAgB,YAAY,EAAE,SAAS,OAAO,QAAQ,OAAyB,EAAE;AAC/E,wBACE,IAAC,kBAAA;EAAiB,SAAS;EAAgB;EAAO,oBAAmB;4BACnE,IAAC,MAAA,EAAA,UAAM,MAAA,EAAa;GACH;AAEtB"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@panscale/react-native",
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
+ "react-native": ">=0.71.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
+ },
38
+ "scripts": {
39
+ "build": "tsdown",
40
+ "check": "pnpm build && publint && attw --pack . --ignore-rules cjs-resolves-to-esm"
41
+ }
42
+ }