@caseparts-org/caseblocks 0.0.9 → 0.0.10

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.
@@ -0,0 +1,20 @@
1
+ import { default as React, CSSProperties, ComponentType } from 'react';
2
+ type SpinZoom360Props = {
3
+ images: string[];
4
+ defaultIndex?: number;
5
+ disableSpin?: boolean;
6
+ disableZoom?: boolean;
7
+ clickZoomFactor?: number;
8
+ scrollZoomFactor?: number;
9
+ maxZoomLevel?: number;
10
+ spinOverlayComponent?: ComponentType<{
11
+ style?: CSSProperties;
12
+ }>;
13
+ rotationSpeedThreshold?: number;
14
+ onImageChange?: (_info: {
15
+ index: number;
16
+ src: string;
17
+ }) => void;
18
+ };
19
+ declare const SpinZoomViewer: React.FC<SpinZoom360Props>;
20
+ export default SpinZoomViewer;
@@ -0,0 +1,292 @@
1
+ import { jsxs as rt, jsx as k } from "react/jsx-runtime";
2
+ import { useState as f, useRef as x, useEffect as G } from "react";
3
+ import { Text as lt } from "../../atoms/Text/Text.js";
4
+ const ut = 4, dt = ({
5
+ images: Y,
6
+ defaultIndex: M = 0,
7
+ disableSpin: w = !1,
8
+ disableZoom: P = !1,
9
+ clickZoomFactor: D = 1.5,
10
+ scrollZoomFactor: B = 1.1,
11
+ maxZoomLevel: m = 5,
12
+ spinOverlayComponent: U,
13
+ rotationSpeedThreshold: O = 15,
14
+ onImageChange: H = () => {
15
+ }
16
+ }) => {
17
+ const [J, tt] = f(!1), [X, N] = f(M), [S, L] = f(!1), [Q, R] = f(!1), [Z, T] = f(!1), [c, h] = f(!1), [l, p] = f(1), [d, a] = f({
18
+ top: 0,
19
+ left: 0
20
+ }), [C, et] = f(!1), u = x(null), q = x(0), b = x({ x: 0, y: 0 }), V = x({
21
+ initialPosition: 0,
22
+ centerX: 0,
23
+ centerY: 0
24
+ }), y = x({
25
+ x: 0,
26
+ y: 0,
27
+ isZoomIn: !1
28
+ }), W = x({ x: 0, y: 0 });
29
+ G(() => {
30
+ const t = u.current;
31
+ return t && t.addEventListener("wheel", A, {
32
+ passive: !1
33
+ }), () => {
34
+ t && t.removeEventListener(
35
+ "wheel",
36
+ A,
37
+ { passive: !1 }
38
+ );
39
+ };
40
+ }, []), G(() => {
41
+ H == null || H({ index: X, src: Y[X] });
42
+ }, [X]);
43
+ function K(t) {
44
+ if (!P && "touches" in t && t.touches && t.touches.length > 1) {
45
+ T(!0), h(!0), R(!1), L(!1);
46
+ const o = t.touches[0].clientX - t.touches[1].clientX, i = t.touches[0].clientY - t.touches[1].clientY;
47
+ V.current.initialPosition = Math.sqrt(o * o + i * i);
48
+ } else c ? R(!0) : w || L(!0);
49
+ const e = "type" in t && t.type === "mousedown" ? t.clientX : t.touches[0].clientX, n = "type" in t && t.type === "mousedown" ? t.clientY : t.touches[0].clientY;
50
+ q.current = e, b.current = { x: e, y: n }, W.current = { x: e, y: n };
51
+ }
52
+ function F(t) {
53
+ if (!P && "touches" in t && t.touches && t.touches.length > 1) {
54
+ const o = t.touches[0].clientX - t.touches[1].clientX, i = t.touches[0].clientY - t.touches[1].clientY, r = Math.sqrt(o * o + i * i), I = r / V.current.initialPosition;
55
+ let s = l * I;
56
+ if (p((g) => (s = g * I, s < 1.001 ? (h(!1), a({ top: 0, left: 0 }), 1) : s >= m ? g : s)), s < m) {
57
+ const g = (t.touches[0].clientX + t.touches[1].clientX) / 2, E = (t.touches[0].clientY + t.touches[1].clientY) / 2, v = u.current.getBoundingClientRect();
58
+ a((_) => {
59
+ const { relX: st, relY: ct } = z(
60
+ g,
61
+ E,
62
+ v.left,
63
+ v.top
64
+ );
65
+ return j(
66
+ !0,
67
+ st,
68
+ ct,
69
+ _.left,
70
+ _.top,
71
+ I
72
+ );
73
+ });
74
+ }
75
+ V.current.initialPosition = r;
76
+ }
77
+ const e = "type" in t && t.type === "mousemove" ? t.clientX : t.touches[0].clientX, n = "type" in t && t.type === "mousemove" ? t.clientY : t.touches[0].clientY;
78
+ if (S) {
79
+ et(!0);
80
+ const o = e - q.current;
81
+ Math.abs(o) > O && (o > 0 ? N(
82
+ (i) => (i - 1 + Y.length) % Y.length
83
+ ) : N((i) => (i + 1) % Y.length), q.current = e);
84
+ }
85
+ if (Q) {
86
+ const o = e - b.current.x, i = n - b.current.y;
87
+ a({
88
+ top: d.top + i,
89
+ left: d.left + o
90
+ }), b.current = { x: e, y: n };
91
+ }
92
+ }
93
+ function $(t) {
94
+ L(!1), T(!1);
95
+ let e, n, o = 0;
96
+ if ("type" in t && (t.type === "mouseup" || t.type === "mouseleave"))
97
+ e = t.clientX, n = t.clientY, o = t.button;
98
+ else {
99
+ const s = t.changedTouches[0];
100
+ e = s.clientX, n = s.clientY;
101
+ }
102
+ const i = e - W.current.x, r = n - W.current.y, I = Math.hypot(i, r);
103
+ if (!P && Math.abs(I) < ut) {
104
+ if (o === 0)
105
+ if (l >= m)
106
+ h(!1), p(1), a({ top: 0, left: 0 });
107
+ else {
108
+ const s = u.current.getBoundingClientRect(), { relX: g, relY: E } = z(
109
+ e,
110
+ n,
111
+ s.left,
112
+ s.top
113
+ ), v = j(
114
+ !0,
115
+ g,
116
+ E,
117
+ d.left,
118
+ d.top,
119
+ D
120
+ );
121
+ a(v), p(l * D), h(!0);
122
+ }
123
+ else if (o === 1)
124
+ if (l / D <= 1)
125
+ h(!1), p(1), a({ top: 0, left: 0 });
126
+ else {
127
+ const s = u.current.getBoundingClientRect(), { relX: g, relY: E } = z(
128
+ e,
129
+ n,
130
+ s.left,
131
+ s.top
132
+ ), v = j(
133
+ !1,
134
+ g,
135
+ E,
136
+ d.left,
137
+ d.top,
138
+ D
139
+ );
140
+ a(v), p(l / D), h(!0);
141
+ }
142
+ }
143
+ R(!1);
144
+ }
145
+ function A(t) {
146
+ if (P)
147
+ return;
148
+ t.preventDefault(), h(!0);
149
+ const e = t.deltaY < 0;
150
+ p(e ? (n) => {
151
+ const o = n * B;
152
+ return o >= m ? m : o;
153
+ } : (n) => {
154
+ const o = n / B;
155
+ return o <= 1 ? (h(!1), p(1), a({ top: 0, left: 0 }), 1) : o;
156
+ }), y.current = {
157
+ x: t.clientX,
158
+ y: t.clientY,
159
+ isZoomIn: e,
160
+ isScrolling: !0
161
+ };
162
+ }
163
+ G(() => {
164
+ var e;
165
+ const t = (e = u.current) == null ? void 0 : e.getBoundingClientRect();
166
+ l !== 1 && l !== m && y.current.isScrolling && t && (y.current = {
167
+ ...y.current,
168
+ isScrolling: !1
169
+ }, a((n) => {
170
+ const { relX: o, relY: i } = z(
171
+ y.current.x,
172
+ y.current.y,
173
+ t.left,
174
+ t.top
175
+ );
176
+ return j(
177
+ y.current.isZoomIn,
178
+ o,
179
+ i,
180
+ n.left,
181
+ n.top,
182
+ B
183
+ );
184
+ }));
185
+ }, [l]);
186
+ function nt(t) {
187
+ t.preventDefault();
188
+ }
189
+ function z(t, e, n, o) {
190
+ const i = t - n, r = e - o;
191
+ return { relX: i, relY: r };
192
+ }
193
+ function j(t, e, n, o, i, r) {
194
+ return t ? {
195
+ top: n - (n - i) * r,
196
+ left: e - (e - o) * r
197
+ } : {
198
+ top: n - (n - i) / r,
199
+ left: e - (e - o) / r
200
+ };
201
+ }
202
+ function ot() {
203
+ return w && P ? "default" : c && l >= m ? "zoom-out" : S ? "grabbing" : Q ? "move" : c || w ? "zoom-in" : "grab";
204
+ }
205
+ const it = {
206
+ height: c && u.current ? u.current.offsetHeight * l + "px" : "100%",
207
+ width: c && u.current ? u.current.offsetWidth * l + "px" : "100%",
208
+ position: c ? "absolute" : "static",
209
+ top: c ? `${d.top}px` : "0",
210
+ left: c ? `${d.left}px` : "0",
211
+ objectFit: "contain",
212
+ touchAction: c || Z ? "none" : "auto"
213
+ };
214
+ return /* @__PURE__ */ rt(
215
+ "div",
216
+ {
217
+ onTouchStart: K,
218
+ onTouchMove: F,
219
+ onTouchEnd: $,
220
+ onMouseDown: K,
221
+ onMouseMove: F,
222
+ onMouseUp: $,
223
+ onMouseLeave: $,
224
+ onDragStart: nt,
225
+ onContextMenu: (t) => t.preventDefault(),
226
+ ref: u,
227
+ style: {
228
+ cursor: ot(),
229
+ width: "100%",
230
+ height: "100%",
231
+ position: "relative",
232
+ overflow: "hidden",
233
+ touchAction: c || Z ? "none" : "auto"
234
+ },
235
+ children: [
236
+ Y.map((t, e) => /* @__PURE__ */ k(
237
+ "img",
238
+ {
239
+ style: {
240
+ display: e === X ? "block" : "none",
241
+ ...e === X ? it : {}
242
+ },
243
+ src: t,
244
+ alt: "",
245
+ onContextMenu: (n) => n.preventDefault(),
246
+ onLoad: e === M ? () => tt(!0) : void 0
247
+ },
248
+ t
249
+ )),
250
+ U ? /* @__PURE__ */ k(
251
+ U,
252
+ {
253
+ style: {
254
+ position: "absolute",
255
+ opacity: S || c || C || !J || w ? "0" : ".7",
256
+ transition: "opacity .3s ease-in",
257
+ pointerEvents: "none",
258
+ left: "50%",
259
+ top: "50%",
260
+ transform: "translate(-50%, -50%)"
261
+ }
262
+ }
263
+ ) : /* @__PURE__ */ k(
264
+ "div",
265
+ {
266
+ style: {
267
+ backgroundColor: "#393939",
268
+ color: "white",
269
+ display: "flex",
270
+ flexDirection: "row",
271
+ alignItems: "center",
272
+ justifyContent: "center",
273
+ height: "max-content",
274
+ width: "max-content",
275
+ padding: "8px 16px",
276
+ left: "50%",
277
+ top: "50%",
278
+ transform: "translate(-50%, -50%)",
279
+ position: "absolute",
280
+ transition: "opacity .3s ease-in",
281
+ opacity: S || c || C || !J || w ? "0" : "0.7"
282
+ },
283
+ children: /* @__PURE__ */ k(lt, { size: "sm", children: "Drag to spin" })
284
+ }
285
+ )
286
+ ]
287
+ }
288
+ );
289
+ };
290
+ export {
291
+ dt as default
292
+ };
@@ -0,0 +1,6 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import { default as SpinZoomViewer } from './SpinZoomViewer';
3
+ declare const meta: Meta<typeof SpinZoomViewer>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof SpinZoomViewer>;
6
+ export declare const Default: Story;
@@ -0,0 +1,24 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import r from "./SpinZoomViewer.js";
3
+ const o = "1092-01", a = `https://dev.caseparts.com/graphics/ortery/web%20spin/${o}/${o}/images/lv1/`, s = [];
4
+ for (let e = 0; e < 20; e++)
5
+ s.push(`${a}img${(e + 1).toString().padStart(2, "0")}.webp`);
6
+ const n = {
7
+ title: "Case Parts/Organisms/SpinZoomViewer",
8
+ component: r,
9
+ tags: ["autodocs"],
10
+ parameters: {
11
+ layout: "centered"
12
+ }
13
+ }, p = {
14
+ render: (e) => /* @__PURE__ */ t("div", { style: { height: "500px", width: "500px" }, children: /* @__PURE__ */ t(r, { ...e }) }),
15
+ args: {
16
+ defaultIndex: 3,
17
+ images: s,
18
+ maxZoomLevel: 5
19
+ }
20
+ };
21
+ export {
22
+ p as Default,
23
+ n as default
24
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@caseparts-org/caseblocks",
3
3
  "private": false,
4
- "version": "0.0.9",
4
+ "version": "0.0.10",
5
5
  "type": "module",
6
6
  "module": "dist/main.js",
7
7
  "types": "dist/main.d.ts",