@raex-ui/flip-dot 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/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +206 -0
- package/dist/index.mjs +180 -0
- package/package.json +33 -0
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
FlipDot: () => FlipDot
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/flip-dot.tsx
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var import_framer_motion = require("framer-motion");
|
|
31
|
+
|
|
32
|
+
// src/digit-paths.ts
|
|
33
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
77
|
+
[0, 0, 0, 1, 0]
|
|
78
|
+
],
|
|
79
|
+
5: [
|
|
80
|
+
[1, 1, 1, 1, 1],
|
|
81
|
+
[1, 0, 0, 0, 0],
|
|
82
|
+
[1, 1, 1, 1, 0],
|
|
83
|
+
[0, 0, 0, 0, 1],
|
|
84
|
+
[0, 0, 0, 0, 1],
|
|
85
|
+
[1, 0, 0, 0, 1],
|
|
86
|
+
[0, 1, 1, 1, 0]
|
|
87
|
+
],
|
|
88
|
+
6: [
|
|
89
|
+
[0, 1, 1, 1, 0],
|
|
90
|
+
[1, 0, 0, 0, 0],
|
|
91
|
+
[1, 0, 0, 0, 0],
|
|
92
|
+
[1, 1, 1, 1, 0],
|
|
93
|
+
[1, 0, 0, 0, 1],
|
|
94
|
+
[1, 0, 0, 0, 1],
|
|
95
|
+
[0, 1, 1, 1, 0]
|
|
96
|
+
],
|
|
97
|
+
7: [
|
|
98
|
+
[1, 1, 1, 1, 1],
|
|
99
|
+
[0, 0, 0, 0, 1],
|
|
100
|
+
[0, 0, 0, 1, 0],
|
|
101
|
+
[0, 0, 1, 0, 0],
|
|
102
|
+
[0, 0, 1, 0, 0],
|
|
103
|
+
[0, 0, 1, 0, 0],
|
|
104
|
+
[0, 0, 1, 0, 0]
|
|
105
|
+
],
|
|
106
|
+
8: [
|
|
107
|
+
[0, 1, 1, 1, 0],
|
|
108
|
+
[1, 0, 0, 0, 1],
|
|
109
|
+
[1, 0, 0, 0, 1],
|
|
110
|
+
[0, 1, 1, 1, 0],
|
|
111
|
+
[1, 0, 0, 0, 1],
|
|
112
|
+
[1, 0, 0, 0, 1],
|
|
113
|
+
[0, 1, 1, 1, 0]
|
|
114
|
+
],
|
|
115
|
+
9: [
|
|
116
|
+
[0, 1, 1, 1, 0],
|
|
117
|
+
[1, 0, 0, 0, 1],
|
|
118
|
+
[1, 0, 0, 0, 1],
|
|
119
|
+
[0, 1, 1, 1, 1],
|
|
120
|
+
[0, 0, 0, 0, 1],
|
|
121
|
+
[0, 0, 0, 0, 1],
|
|
122
|
+
[0, 1, 1, 1, 0]
|
|
123
|
+
]
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/flip-dot.tsx
|
|
127
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
128
|
+
var ROWS = 7;
|
|
129
|
+
var COLS = 5;
|
|
130
|
+
function FlipDot({ value, size }) {
|
|
131
|
+
const width = size;
|
|
132
|
+
const height = size * 1.5;
|
|
133
|
+
const cellW = width / COLS;
|
|
134
|
+
const cellH = height / ROWS;
|
|
135
|
+
const dotRadius = Math.min(cellW, cellH) * 0.35;
|
|
136
|
+
const matrix = DIGIT_MATRIX[value];
|
|
137
|
+
const dots = (0, import_react.useMemo)(() => {
|
|
138
|
+
const d = [];
|
|
139
|
+
for (let r = 0; r < ROWS; r++) {
|
|
140
|
+
for (let c = 0; c < COLS; c++) {
|
|
141
|
+
d.push({
|
|
142
|
+
x: c * cellW + cellW / 2,
|
|
143
|
+
y: r * cellH + cellH / 2,
|
|
144
|
+
active: matrix[r][c] === 1,
|
|
145
|
+
delay: (r + c) * 0.025
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return d;
|
|
150
|
+
}, [value, cellW, cellH, matrix]);
|
|
151
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
152
|
+
"svg",
|
|
153
|
+
{
|
|
154
|
+
width,
|
|
155
|
+
height,
|
|
156
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
157
|
+
style: { perspective: "200px" },
|
|
158
|
+
children: dots.map((dot, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
159
|
+
import_framer_motion.motion.g,
|
|
160
|
+
{
|
|
161
|
+
initial: false,
|
|
162
|
+
animate: {
|
|
163
|
+
rotateY: dot.active ? 0 : 180
|
|
164
|
+
},
|
|
165
|
+
transition: {
|
|
166
|
+
type: "spring",
|
|
167
|
+
stiffness: 400,
|
|
168
|
+
damping: 30,
|
|
169
|
+
delay: dot.delay
|
|
170
|
+
},
|
|
171
|
+
style: {
|
|
172
|
+
transformOrigin: `${dot.x}px ${dot.y}px`
|
|
173
|
+
},
|
|
174
|
+
children: [
|
|
175
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
176
|
+
"circle",
|
|
177
|
+
{
|
|
178
|
+
cx: dot.x,
|
|
179
|
+
cy: dot.y,
|
|
180
|
+
r: dotRadius,
|
|
181
|
+
fill: dot.active ? "#fbbf24" : "#292524",
|
|
182
|
+
stroke: "#44403c",
|
|
183
|
+
strokeWidth: 0.5
|
|
184
|
+
}
|
|
185
|
+
),
|
|
186
|
+
dot.active && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
187
|
+
"circle",
|
|
188
|
+
{
|
|
189
|
+
cx: dot.x,
|
|
190
|
+
cy: dot.y,
|
|
191
|
+
r: dotRadius * 0.5,
|
|
192
|
+
fill: "#fde68a",
|
|
193
|
+
opacity: 0.4
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
]
|
|
197
|
+
},
|
|
198
|
+
i
|
|
199
|
+
))
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
FlipDot
|
|
206
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/flip-dot.tsx
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { motion } from "framer-motion";
|
|
6
|
+
|
|
7
|
+
// src/digit-paths.ts
|
|
8
|
+
var DIGIT_MATRIX = {
|
|
9
|
+
0: [
|
|
10
|
+
[0, 1, 1, 1, 0],
|
|
11
|
+
[1, 0, 0, 0, 1],
|
|
12
|
+
[1, 0, 0, 1, 1],
|
|
13
|
+
[1, 0, 1, 0, 1],
|
|
14
|
+
[1, 1, 0, 0, 1],
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[0, 0, 0, 0, 1],
|
|
60
|
+
[1, 0, 0, 0, 1],
|
|
61
|
+
[0, 1, 1, 1, 0]
|
|
62
|
+
],
|
|
63
|
+
6: [
|
|
64
|
+
[0, 1, 1, 1, 0],
|
|
65
|
+
[1, 0, 0, 0, 0],
|
|
66
|
+
[1, 0, 0, 0, 0],
|
|
67
|
+
[1, 1, 1, 1, 0],
|
|
68
|
+
[1, 0, 0, 0, 1],
|
|
69
|
+
[1, 0, 0, 0, 1],
|
|
70
|
+
[0, 1, 1, 1, 0]
|
|
71
|
+
],
|
|
72
|
+
7: [
|
|
73
|
+
[1, 1, 1, 1, 1],
|
|
74
|
+
[0, 0, 0, 0, 1],
|
|
75
|
+
[0, 0, 0, 1, 0],
|
|
76
|
+
[0, 0, 1, 0, 0],
|
|
77
|
+
[0, 0, 1, 0, 0],
|
|
78
|
+
[0, 0, 1, 0, 0],
|
|
79
|
+
[0, 0, 1, 0, 0]
|
|
80
|
+
],
|
|
81
|
+
8: [
|
|
82
|
+
[0, 1, 1, 1, 0],
|
|
83
|
+
[1, 0, 0, 0, 1],
|
|
84
|
+
[1, 0, 0, 0, 1],
|
|
85
|
+
[0, 1, 1, 1, 0],
|
|
86
|
+
[1, 0, 0, 0, 1],
|
|
87
|
+
[1, 0, 0, 0, 1],
|
|
88
|
+
[0, 1, 1, 1, 0]
|
|
89
|
+
],
|
|
90
|
+
9: [
|
|
91
|
+
[0, 1, 1, 1, 0],
|
|
92
|
+
[1, 0, 0, 0, 1],
|
|
93
|
+
[1, 0, 0, 0, 1],
|
|
94
|
+
[0, 1, 1, 1, 1],
|
|
95
|
+
[0, 0, 0, 0, 1],
|
|
96
|
+
[0, 0, 0, 0, 1],
|
|
97
|
+
[0, 1, 1, 1, 0]
|
|
98
|
+
]
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/flip-dot.tsx
|
|
102
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
103
|
+
var ROWS = 7;
|
|
104
|
+
var COLS = 5;
|
|
105
|
+
function FlipDot({ value, size }) {
|
|
106
|
+
const width = size;
|
|
107
|
+
const height = size * 1.5;
|
|
108
|
+
const cellW = width / COLS;
|
|
109
|
+
const cellH = height / ROWS;
|
|
110
|
+
const dotRadius = Math.min(cellW, cellH) * 0.35;
|
|
111
|
+
const matrix = DIGIT_MATRIX[value];
|
|
112
|
+
const dots = useMemo(() => {
|
|
113
|
+
const d = [];
|
|
114
|
+
for (let r = 0; r < ROWS; r++) {
|
|
115
|
+
for (let c = 0; c < COLS; c++) {
|
|
116
|
+
d.push({
|
|
117
|
+
x: c * cellW + cellW / 2,
|
|
118
|
+
y: r * cellH + cellH / 2,
|
|
119
|
+
active: matrix[r][c] === 1,
|
|
120
|
+
delay: (r + c) * 0.025
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return d;
|
|
125
|
+
}, [value, cellW, cellH, matrix]);
|
|
126
|
+
return /* @__PURE__ */ jsx(
|
|
127
|
+
"svg",
|
|
128
|
+
{
|
|
129
|
+
width,
|
|
130
|
+
height,
|
|
131
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
132
|
+
style: { perspective: "200px" },
|
|
133
|
+
children: dots.map((dot, i) => /* @__PURE__ */ jsxs(
|
|
134
|
+
motion.g,
|
|
135
|
+
{
|
|
136
|
+
initial: false,
|
|
137
|
+
animate: {
|
|
138
|
+
rotateY: dot.active ? 0 : 180
|
|
139
|
+
},
|
|
140
|
+
transition: {
|
|
141
|
+
type: "spring",
|
|
142
|
+
stiffness: 400,
|
|
143
|
+
damping: 30,
|
|
144
|
+
delay: dot.delay
|
|
145
|
+
},
|
|
146
|
+
style: {
|
|
147
|
+
transformOrigin: `${dot.x}px ${dot.y}px`
|
|
148
|
+
},
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ jsx(
|
|
151
|
+
"circle",
|
|
152
|
+
{
|
|
153
|
+
cx: dot.x,
|
|
154
|
+
cy: dot.y,
|
|
155
|
+
r: dotRadius,
|
|
156
|
+
fill: dot.active ? "#fbbf24" : "#292524",
|
|
157
|
+
stroke: "#44403c",
|
|
158
|
+
strokeWidth: 0.5
|
|
159
|
+
}
|
|
160
|
+
),
|
|
161
|
+
dot.active && /* @__PURE__ */ jsx(
|
|
162
|
+
"circle",
|
|
163
|
+
{
|
|
164
|
+
cx: dot.x,
|
|
165
|
+
cy: dot.y,
|
|
166
|
+
r: dotRadius * 0.5,
|
|
167
|
+
fill: "#fde68a",
|
|
168
|
+
opacity: 0.4
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
i
|
|
174
|
+
))
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
FlipDot
|
|
180
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@raex-ui/flip-dot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cascading dot-flip grid that simulates a physical flip-dot display. Animated digit transition component for React.",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"keywords": ["react", "animation", "digit", "transition", "framer-motion", "svg", "flip", "dot"],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=18",
|
|
21
|
+
"react-dom": ">=18",
|
|
22
|
+
"framer-motion": ">=10"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "^8.5.1",
|
|
26
|
+
"typescript": "^5",
|
|
27
|
+
"react": "^19",
|
|
28
|
+
"@types/react": "^19"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup"
|
|
32
|
+
}
|
|
33
|
+
}
|