@raex-ui/thread-unravel 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.
@@ -0,0 +1,9 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Props {
4
+ value: number;
5
+ size: number;
6
+ }
7
+ declare function ThreadUnravel({ value, size }: Props): react_jsx_runtime.JSX.Element;
8
+
9
+ export { ThreadUnravel };
@@ -0,0 +1,9 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Props {
4
+ value: number;
5
+ size: number;
6
+ }
7
+ declare function ThreadUnravel({ value, size }: Props): react_jsx_runtime.JSX.Element;
8
+
9
+ export { ThreadUnravel };
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
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
+ ThreadUnravel: () => ThreadUnravel
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/thread-unravel.tsx
29
+ var import_react = require("react");
30
+ var import_framer_motion = require("framer-motion");
31
+
32
+ // src/digit-paths.ts
33
+ var DIGIT_STROKE_PATHS = {
34
+ 0: "M32,8 L48,8 C54,8 56,14 56,20 L56,76 C56,82 54,88 48,88 L16,88 C10,88 8,82 8,76 L8,20 C8,14 10,8 16,8 L32,8",
35
+ 1: "M20,20 L32,8 L32,88 M22,88 L42,88",
36
+ 2: "M8,20 C8,14 10,8 16,8 L48,8 C54,8 56,14 56,20 L56,40 C56,46 54,48 48,48 L16,48 C10,48 8,54 8,60 L8,76 C8,82 8,88 8,88 L56,88",
37
+ 3: "M8,16 L48,8 C54,8 56,14 56,20 L56,36 C56,42 54,44 48,44 L28,44 L48,44 C54,44 56,50 56,56 L56,76 C56,82 54,88 48,88 L16,88 C10,88 8,82 8,80",
38
+ 4: "M8,8 L8,48 L56,48 M44,8 L44,88",
39
+ 5: "M56,8 L8,8 L8,44 L48,44 C54,44 56,50 56,56 L56,76 C56,82 54,88 48,88 L16,88 C10,88 8,82 8,76",
40
+ 6: "M48,8 L16,8 C10,8 8,14 8,20 L8,76 C8,82 10,88 16,88 L48,88 C54,88 56,82 56,76 L56,52 C56,46 54,44 48,44 L8,44",
41
+ 7: "M8,8 L56,8 L28,88",
42
+ 8: "M32,44 L16,44 C10,44 8,38 8,32 L8,20 C8,14 10,8 16,8 L48,8 C54,8 56,14 56,20 L56,32 C56,38 54,44 48,44 L32,44 L16,44 C10,44 8,50 8,56 L8,76 C8,82 10,88 16,88 L48,88 C54,88 56,82 56,76 L56,56 C56,50 54,44 48,44",
43
+ 9: "M8,76 L48,88 C54,88 56,82 56,76 L56,20 C56,14 54,8 48,8 L16,8 C10,8 8,14 8,20 L8,44 C8,50 10,52 16,52 L56,52"
44
+ };
45
+
46
+ // src/thread-unravel.tsx
47
+ var import_jsx_runtime = require("react/jsx-runtime");
48
+ function ThreadUnravel({ value, size }) {
49
+ const width = size;
50
+ const height = size * 1.5;
51
+ const [displayPath, setDisplayPath] = (0, import_react.useState)(DIGIT_STROKE_PATHS[value]);
52
+ const prevValue = (0, import_react.useRef)(value);
53
+ const progress = (0, import_framer_motion.useMotionValue)(1);
54
+ const pathRef = (0, import_react.useRef)(null);
55
+ const [pathLength, setPathLength] = (0, import_react.useState)(300);
56
+ (0, import_react.useEffect)(() => {
57
+ if (pathRef.current) {
58
+ setPathLength(pathRef.current.getTotalLength());
59
+ }
60
+ }, [displayPath]);
61
+ (0, import_react.useEffect)(() => {
62
+ if (prevValue.current === value) return;
63
+ prevValue.current = value;
64
+ (0, import_framer_motion.animate)(progress, 0, {
65
+ duration: 0.25,
66
+ ease: "easeIn",
67
+ onComplete: () => {
68
+ setDisplayPath(DIGIT_STROKE_PATHS[value]);
69
+ progress.set(0);
70
+ (0, import_framer_motion.animate)(progress, 1, {
71
+ duration: 0.35,
72
+ ease: "easeOut"
73
+ });
74
+ }
75
+ });
76
+ }, [value, progress]);
77
+ const dashOffset = (0, import_framer_motion.useTransform)(progress, [0, 1], [pathLength, 0]);
78
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width, height, viewBox: "0 0 64 96", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
79
+ import_framer_motion.motion.path,
80
+ {
81
+ ref: pathRef,
82
+ d: displayPath,
83
+ fill: "none",
84
+ stroke: "#38bdf8",
85
+ strokeWidth: 4,
86
+ strokeLinecap: "round",
87
+ strokeLinejoin: "round",
88
+ strokeDasharray: pathLength,
89
+ style: { strokeDashoffset: dashOffset }
90
+ }
91
+ ) });
92
+ }
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ ThreadUnravel
96
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,70 @@
1
+ "use client";
2
+
3
+ // src/thread-unravel.tsx
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { motion, useMotionValue, useTransform, animate } from "framer-motion";
6
+
7
+ // src/digit-paths.ts
8
+ var DIGIT_STROKE_PATHS = {
9
+ 0: "M32,8 L48,8 C54,8 56,14 56,20 L56,76 C56,82 54,88 48,88 L16,88 C10,88 8,82 8,76 L8,20 C8,14 10,8 16,8 L32,8",
10
+ 1: "M20,20 L32,8 L32,88 M22,88 L42,88",
11
+ 2: "M8,20 C8,14 10,8 16,8 L48,8 C54,8 56,14 56,20 L56,40 C56,46 54,48 48,48 L16,48 C10,48 8,54 8,60 L8,76 C8,82 8,88 8,88 L56,88",
12
+ 3: "M8,16 L48,8 C54,8 56,14 56,20 L56,36 C56,42 54,44 48,44 L28,44 L48,44 C54,44 56,50 56,56 L56,76 C56,82 54,88 48,88 L16,88 C10,88 8,82 8,80",
13
+ 4: "M8,8 L8,48 L56,48 M44,8 L44,88",
14
+ 5: "M56,8 L8,8 L8,44 L48,44 C54,44 56,50 56,56 L56,76 C56,82 54,88 48,88 L16,88 C10,88 8,82 8,76",
15
+ 6: "M48,8 L16,8 C10,8 8,14 8,20 L8,76 C8,82 10,88 16,88 L48,88 C54,88 56,82 56,76 L56,52 C56,46 54,44 48,44 L8,44",
16
+ 7: "M8,8 L56,8 L28,88",
17
+ 8: "M32,44 L16,44 C10,44 8,38 8,32 L8,20 C8,14 10,8 16,8 L48,8 C54,8 56,14 56,20 L56,32 C56,38 54,44 48,44 L32,44 L16,44 C10,44 8,50 8,56 L8,76 C8,82 10,88 16,88 L48,88 C54,88 56,82 56,76 L56,56 C56,50 54,44 48,44",
18
+ 9: "M8,76 L48,88 C54,88 56,82 56,76 L56,20 C56,14 54,8 48,8 L16,8 C10,8 8,14 8,20 L8,44 C8,50 10,52 16,52 L56,52"
19
+ };
20
+
21
+ // src/thread-unravel.tsx
22
+ import { jsx } from "react/jsx-runtime";
23
+ function ThreadUnravel({ value, size }) {
24
+ const width = size;
25
+ const height = size * 1.5;
26
+ const [displayPath, setDisplayPath] = useState(DIGIT_STROKE_PATHS[value]);
27
+ const prevValue = useRef(value);
28
+ const progress = useMotionValue(1);
29
+ const pathRef = useRef(null);
30
+ const [pathLength, setPathLength] = useState(300);
31
+ useEffect(() => {
32
+ if (pathRef.current) {
33
+ setPathLength(pathRef.current.getTotalLength());
34
+ }
35
+ }, [displayPath]);
36
+ useEffect(() => {
37
+ if (prevValue.current === value) return;
38
+ prevValue.current = value;
39
+ animate(progress, 0, {
40
+ duration: 0.25,
41
+ ease: "easeIn",
42
+ onComplete: () => {
43
+ setDisplayPath(DIGIT_STROKE_PATHS[value]);
44
+ progress.set(0);
45
+ animate(progress, 1, {
46
+ duration: 0.35,
47
+ ease: "easeOut"
48
+ });
49
+ }
50
+ });
51
+ }, [value, progress]);
52
+ const dashOffset = useTransform(progress, [0, 1], [pathLength, 0]);
53
+ return /* @__PURE__ */ jsx("svg", { width, height, viewBox: "0 0 64 96", children: /* @__PURE__ */ jsx(
54
+ motion.path,
55
+ {
56
+ ref: pathRef,
57
+ d: displayPath,
58
+ fill: "none",
59
+ stroke: "#38bdf8",
60
+ strokeWidth: 4,
61
+ strokeLinecap: "round",
62
+ strokeLinejoin: "round",
63
+ strokeDasharray: pathLength,
64
+ style: { strokeDashoffset: dashOffset }
65
+ }
66
+ ) });
67
+ }
68
+ export {
69
+ ThreadUnravel
70
+ };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@raex-ui/thread-unravel",
3
+ "version": "0.1.0",
4
+ "description": "Single continuous stroke path that unravels and restitches to form each digit. 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", "thread"],
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
+ }