hamzus-ui 0.0.193 → 0.0.194
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/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/components/hamzus-ui/SvgLine/SvgLine.svelte +31 -0
- package/src/utils/svg.js +105 -0
package/index.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ export * as Sidebar from "./src/layout/Sidebar"
|
|
|
64
64
|
|
|
65
65
|
// special
|
|
66
66
|
export { default as Portal } from "./src/components/hamzus-ui/Portal/Portal.svelte"
|
|
67
|
+
export { default as SvgLine } from "./src/components/hamzus-ui/SvgLine/SvgLine.svelte"
|
|
67
68
|
|
|
68
69
|
// utils
|
|
69
70
|
export { config, init } from "./src/utils/hamzus.config.js";
|
package/index.js
CHANGED
|
@@ -61,6 +61,7 @@ export * as Sidebar from "./src/layout/Sidebar"
|
|
|
61
61
|
|
|
62
62
|
// special
|
|
63
63
|
export { default as Portal } from "./src/components/hamzus-ui/Portal/Portal.svelte"
|
|
64
|
+
export { default as SvgLine } from "./src/components/hamzus-ui/SvgLine/SvgLine.svelte"
|
|
64
65
|
|
|
65
66
|
// utils
|
|
66
67
|
export { config, init } from "./src/utils/hamzus.config.js";
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { generatePathWithRoundedCorners } from "../../../utils/svg";
|
|
3
|
+
|
|
4
|
+
export let steps = {
|
|
5
|
+
dir: "up" | "down" | "left" | "right",
|
|
6
|
+
distance: 0
|
|
7
|
+
}
|
|
8
|
+
export let radius = 10
|
|
9
|
+
export let strokeWidth = 5
|
|
10
|
+
export let startX = 0
|
|
11
|
+
export let startY = 0
|
|
12
|
+
export let color = "var(--accent-b)"
|
|
13
|
+
|
|
14
|
+
$: data = generatePathWithRoundedCorners(steps, radius, strokeWidth, startX, startY)
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<svg
|
|
18
|
+
width={data.width}
|
|
19
|
+
height={data.height}
|
|
20
|
+
viewBox="0 0 {data.width} {data.height}"
|
|
21
|
+
style="transform:translate({data.startX}px, {data.startY}px);"
|
|
22
|
+
>
|
|
23
|
+
<path
|
|
24
|
+
d={data.d}
|
|
25
|
+
stroke="{color}"
|
|
26
|
+
fill="transparent"
|
|
27
|
+
stroke-width={data.strokeWidth}
|
|
28
|
+
stroke-linecap="butt"
|
|
29
|
+
stroke-linejoin="round"
|
|
30
|
+
/>
|
|
31
|
+
</svg>
|
package/src/utils/svg.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function generatePathWithRoundedCorners(
|
|
5
|
+
steps = {
|
|
6
|
+
dir: "up" | "down" | "left" | "right",
|
|
7
|
+
distance: 0
|
|
8
|
+
},
|
|
9
|
+
radius = 10,
|
|
10
|
+
strokeWidth = 5,
|
|
11
|
+
startX = 0,
|
|
12
|
+
startY = 0
|
|
13
|
+
) {
|
|
14
|
+
if (!steps || steps.length === 0) return "";
|
|
15
|
+
|
|
16
|
+
const halfStroke = strokeWidth / 2;
|
|
17
|
+
|
|
18
|
+
// --- Génération des points ---
|
|
19
|
+
let x = startX;
|
|
20
|
+
let y = startY;
|
|
21
|
+
const points = [{ x, y }];
|
|
22
|
+
|
|
23
|
+
for (const step of steps) {
|
|
24
|
+
switch (step.dir.toLowerCase()) {
|
|
25
|
+
case "right": x += step.distance; break;
|
|
26
|
+
case "left": x -= step.distance; break;
|
|
27
|
+
case "down": y += step.distance; break;
|
|
28
|
+
case "up": y -= step.distance; break;
|
|
29
|
+
}
|
|
30
|
+
points.push({ x, y });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// --- Bounding box ---
|
|
34
|
+
const xs = points.map(p => p.x);
|
|
35
|
+
const ys = points.map(p => p.y);
|
|
36
|
+
const minX = Math.min(...xs) - halfStroke;
|
|
37
|
+
const minY = Math.min(...ys) - halfStroke;
|
|
38
|
+
const maxX = Math.max(...xs) + halfStroke;
|
|
39
|
+
const maxY = Math.max(...ys) + halfStroke;
|
|
40
|
+
const width = maxX - minX;
|
|
41
|
+
const height = maxY - minY;
|
|
42
|
+
|
|
43
|
+
// --- Transformation SVG ---
|
|
44
|
+
const transformed = points.map(p => ({ x: p.x - minX, y: p.y - minY }));
|
|
45
|
+
|
|
46
|
+
// --- Path avec arrondis ---
|
|
47
|
+
let d = `M ${transformed[0].x} ${transformed[0].y} `;
|
|
48
|
+
|
|
49
|
+
for (let i = 1; i < transformed.length - 1; i++) {
|
|
50
|
+
const p0 = transformed[i - 1];
|
|
51
|
+
const p1 = transformed[i];
|
|
52
|
+
const p2 = transformed[i + 1];
|
|
53
|
+
|
|
54
|
+
// Si coin
|
|
55
|
+
const isCorner =
|
|
56
|
+
(p0.x !== p1.x || p0.y !== p1.y) &&
|
|
57
|
+
(p1.x !== p2.x || p1.y !== p2.y) &&
|
|
58
|
+
!(p0.x === p2.x && p0.y === p2.y);
|
|
59
|
+
|
|
60
|
+
if (isCorner) {
|
|
61
|
+
// Vecteur p0->p1
|
|
62
|
+
let dx1 = p1.x - p0.x;
|
|
63
|
+
let dy1 = p1.y - p0.y;
|
|
64
|
+
const len1 = Math.hypot(dx1, dy1);
|
|
65
|
+
dx1 /= len1;
|
|
66
|
+
dy1 /= len1;
|
|
67
|
+
|
|
68
|
+
// Vecteur p1->p2
|
|
69
|
+
let dx2 = p2.x - p1.x;
|
|
70
|
+
let dy2 = p2.y - p1.y;
|
|
71
|
+
const len2 = Math.hypot(dx2, dy2);
|
|
72
|
+
dx2 /= len2;
|
|
73
|
+
dy2 /= len2;
|
|
74
|
+
|
|
75
|
+
const r = Math.min(radius, len1 / 2, len2 / 2);
|
|
76
|
+
|
|
77
|
+
const startX = p1.x - dx1 * r;
|
|
78
|
+
const startY = p1.y - dy1 * r;
|
|
79
|
+
const endX = p1.x + dx2 * r;
|
|
80
|
+
const endY = p1.y + dy2 * r;
|
|
81
|
+
|
|
82
|
+
d += `L ${startX} ${startY} `;
|
|
83
|
+
d += `Q ${p1.x} ${p1.y} ${endX} ${endY} `;
|
|
84
|
+
} else {
|
|
85
|
+
d += `L ${p1.x} ${p1.y} `;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Dernier point
|
|
90
|
+
const last = transformed[transformed.length - 1];
|
|
91
|
+
d += `L ${last.x} ${last.y}`;
|
|
92
|
+
|
|
93
|
+
// calculer la position du svg en fonction du point de depart
|
|
94
|
+
let posX = transformed[0].x
|
|
95
|
+
let posY = transformed[0].y
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
width,
|
|
99
|
+
height,
|
|
100
|
+
d,
|
|
101
|
+
strokeWidth,
|
|
102
|
+
startX: -posX,
|
|
103
|
+
startY: -posY
|
|
104
|
+
};
|
|
105
|
+
}
|